-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
120 lines (100 loc) · 2.55 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package hub
import (
"time"
"github.com/eclesh/welford"
)
// Hub maintains the set of active clients and
// broadcasts messages to the clients.
// From gorilla/websocket chat
type Hub struct {
// Registered clients.
Clients map[string]map[*Client]bool
// Inbound messages from the clients.
Broadcast chan Message
// Register requests from the clients.
Register chan *Client
// Unregister requests from clients.
Unregister chan *Client
Stats HubStats
}
type HubStats struct {
Started time.Time
Last time.Time
Audience *welford.Stats
Bytes *welford.Stats
Latency *welford.Stats
Dt *welford.Stats
}
// Stats that we report externally
type HubReport struct {
Started string `json:"started"`
Last string `json:"last"`
Audience WelfordStats `json:"audience"`
Bytes WelfordStats `json:"bytes"`
Latency WelfordStats `json:"latency"`
Dt WelfordStats `json:"dt"`
}
type WelfordStats struct {
Count uint64 `json:"count"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Stddev float64 `json:"stddev"`
Variance float64 `json:"variance"`
}
// messages will be wrapped in this struct for muxing
type Message struct {
Data []byte //text data are converted to/from bytes as needed
Sender Client
Sent time.Time //when sent
Type int
}
// Client is a middleperson between the hub and whatever is sending/receiving messages on it
type Client struct {
Hub *Hub
Name string //for filtering who to send messages to
Send chan Message // for outbound messages to client
Stats *ClientStats
Topic string // message broadcast scope is restricted to a single topic
Done chan struct{}
}
// Stats that we keep internally
type ClientStats struct {
ConnectedAt time.Time
Rx *Frames
Tx *Frames
}
type Frames struct {
Last time.Time
Size *welford.Stats
Dt *welford.Stats
}
// Stats that we report externally
type ClientReport struct {
Topic string `json:"topic"`
Connected string `json:"connected"`
Stats ClientRxTx `json:"stats"`
}
type ClientRxTx struct {
Tx ChannelStats `json:"tx"`
Rx ChannelStats `json:"rx"`
}
type ChannelStats struct {
Last string `json:"last"` //how many seconds ago...
Bytes float64 `json:"bytes"`
Dt float64 `json:"dt"` //Messages per second
}
/* These seem superfluous
type summaryStats struct {
topic map[string]topicStats
}
type topicStats struct {
audience *welford.Stats
size *welford.Stats
rx map[string]int
}
type messageStats struct {
topic string
rx []string
size int
}*/