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