Browse Source

Add doc strings to mtglib events

tags/v2.0.0-rc1
9seconds 5 years ago
parent
commit
611583ba88
1 changed files with 43 additions and 2 deletions
  1. 43
    2
      mtglib/events.go

+ 43
- 2
mtglib/events.go View File

10
 	timestamp time.Time
10
 	timestamp time.Time
11
 }
11
 }
12
 
12
 
13
+// StreamID returns a ID of the stream this event belongs to.
13
 func (e eventBase) StreamID() string {
14
 func (e eventBase) StreamID() string {
14
 	return e.streamID
15
 	return e.streamID
15
 }
16
 }
16
 
17
 
18
+// Timestamp return a time when this event was generated.
17
 func (e eventBase) Timestamp() time.Time {
19
 func (e eventBase) Timestamp() time.Time {
18
 	return e.timestamp
20
 	return e.timestamp
19
 }
21
 }
20
 
22
 
23
+// EventStart is emitted when mtg proxy starts to process a new
24
+// connection.
21
 type EventStart struct {
25
 type EventStart struct {
22
 	eventBase
26
 	eventBase
23
 
27
 
28
+	// RemoteIP is an IP address of the client.
24
 	RemoteIP net.IP
29
 	RemoteIP net.IP
25
 }
30
 }
26
 
31
 
32
+// EventConnectedToDC is emitted when mtg proxy has connected to a
33
+// Telegram server.
27
 type EventConnectedToDC struct {
34
 type EventConnectedToDC struct {
28
 	eventBase
35
 	eventBase
29
 
36
 
37
+	// RemoteIP is an IP address of the Telegram server proxy has been
38
+	// connected to.
30
 	RemoteIP net.IP
39
 	RemoteIP net.IP
31
-	DC       int
40
+
41
+	// DC is an index of the datacenter proxy has been connected to.
42
+	DC int
32
 }
43
 }
33
 
44
 
45
+// EventTraffic is emitted when we read/write some bytes on a connection.
34
 type EventTraffic struct {
46
 type EventTraffic struct {
35
 	eventBase
47
 	eventBase
36
 
48
 
49
+	// Traffic is a count of bytes which were transmitted.
37
 	Traffic uint
50
 	Traffic uint
38
-	IsRead  bool
51
+
52
+	// IsRead defines if we _read_ or _write_ to connection. A rule of
53
+	// thumb is simple: EventTraffic is bound to a remote connection. Not
54
+	// to a client one, but either to Telegram or front domain one.
55
+	//
56
+	// In the case of Telegram, isRead means that we've fetched some bytes
57
+	// from Telegram to send it to a client.
58
+	//
59
+	// In the case of the front domain, it means that we've fetched some
60
+	// bytes from this domain to send it to a client.
61
+	IsRead bool
39
 }
62
 }
40
 
63
 
64
+// EventFinish is emitted when we stop to manage a connection.
41
 type EventFinish struct {
65
 type EventFinish struct {
42
 	eventBase
66
 	eventBase
43
 }
67
 }
44
 
68
 
69
+// EventDomainFronting is emitted when we connect to a front domain
70
+// instead of Telegram server.
45
 type EventDomainFronting struct {
71
 type EventDomainFronting struct {
46
 	eventBase
72
 	eventBase
47
 }
73
 }
48
 
74
 
75
+// EventConcurrencyLimited is emitted when connection was declined
76
+// because of the concurrency limit of the worker pool.
49
 type EventConcurrencyLimited struct {
77
 type EventConcurrencyLimited struct {
50
 	eventBase
78
 	eventBase
51
 }
79
 }
52
 
80
 
81
+// EventIPBlocklisted is emitted when connection was declined because
82
+// IP address was found in IP blocklist.
53
 type EventIPBlocklisted struct {
83
 type EventIPBlocklisted struct {
54
 	eventBase
84
 	eventBase
55
 
85
 
56
 	RemoteIP net.IP
86
 	RemoteIP net.IP
57
 }
87
 }
58
 
88
 
89
+// EventReplayAttack is emitted when mtg detects a replay attack on a
90
+// connection.
59
 type EventReplayAttack struct {
91
 type EventReplayAttack struct {
60
 	eventBase
92
 	eventBase
61
 }
93
 }
62
 
94
 
95
+// NewEventStart creates a new EventStart event.
63
 func NewEventStart(streamID string, remoteIP net.IP) EventStart {
96
 func NewEventStart(streamID string, remoteIP net.IP) EventStart {
64
 	return EventStart{
97
 	return EventStart{
65
 		eventBase: eventBase{
98
 		eventBase: eventBase{
70
 	}
103
 	}
71
 }
104
 }
72
 
105
 
106
+// NewEventConnectedToDC creates a new EventConnectedToDC event.
73
 func NewEventConnectedToDC(streamID string, remoteIP net.IP, dc int) EventConnectedToDC {
107
 func NewEventConnectedToDC(streamID string, remoteIP net.IP, dc int) EventConnectedToDC {
74
 	return EventConnectedToDC{
108
 	return EventConnectedToDC{
75
 		eventBase: eventBase{
109
 		eventBase: eventBase{
81
 	}
115
 	}
82
 }
116
 }
83
 
117
 
118
+// NewEventTraffic creates a new EventTraffic event.
84
 func NewEventTraffic(streamID string, traffic uint, isRead bool) EventTraffic {
119
 func NewEventTraffic(streamID string, traffic uint, isRead bool) EventTraffic {
85
 	return EventTraffic{
120
 	return EventTraffic{
86
 		eventBase: eventBase{
121
 		eventBase: eventBase{
92
 	}
127
 	}
93
 }
128
 }
94
 
129
 
130
+// NewEventFinish creates a new EventFinish event.
95
 func NewEventFinish(streamID string) EventFinish {
131
 func NewEventFinish(streamID string) EventFinish {
96
 	return EventFinish{
132
 	return EventFinish{
97
 		eventBase: eventBase{
133
 		eventBase: eventBase{
101
 	}
137
 	}
102
 }
138
 }
103
 
139
 
140
+// NewEventDomainFronting creates a new EventDomainFronting event.
104
 func NewEventDomainFronting(streamID string) EventDomainFronting {
141
 func NewEventDomainFronting(streamID string) EventDomainFronting {
105
 	return EventDomainFronting{
142
 	return EventDomainFronting{
106
 		eventBase: eventBase{
143
 		eventBase: eventBase{
110
 	}
147
 	}
111
 }
148
 }
112
 
149
 
150
+// NewEventConcurrencyLimited creates a new EventConcurrencyLimited
151
+// event.
113
 func NewEventConcurrencyLimited() EventConcurrencyLimited {
152
 func NewEventConcurrencyLimited() EventConcurrencyLimited {
114
 	return EventConcurrencyLimited{
153
 	return EventConcurrencyLimited{
115
 		eventBase: eventBase{
154
 		eventBase: eventBase{
118
 	}
157
 	}
119
 }
158
 }
120
 
159
 
160
+// NewEventIPBlocklisted creates a new EventIPBlocklisted event.
121
 func NewEventIPBlocklisted(remoteIP net.IP) EventIPBlocklisted {
161
 func NewEventIPBlocklisted(remoteIP net.IP) EventIPBlocklisted {
122
 	return EventIPBlocklisted{
162
 	return EventIPBlocklisted{
123
 		eventBase: eventBase{
163
 		eventBase: eventBase{
127
 	}
167
 	}
128
 }
168
 }
129
 
169
 
170
+// NewEventReplayAttack creates a new EventReplayAttack event.
130
 func NewEventReplayAttack(streamID string) EventReplayAttack {
171
 func NewEventReplayAttack(streamID string) EventReplayAttack {
131
 	return EventReplayAttack{
172
 	return EventReplayAttack{
132
 		eventBase: eventBase{
173
 		eventBase: eventBase{

Loading…
Cancel
Save