|
|
@@ -1,18 +1,69 @@
|
|
|
1
|
+// Events has a default implementations of EventStream for mtglib.
|
|
|
2
|
+//
|
|
|
3
|
+// Please see documentation for mtglib.EventStream interface to get an
|
|
|
4
|
+// idea of such an abstraction. This package has implementations for the
|
|
|
5
|
+// default event stream.
|
|
|
6
|
+//
|
|
|
7
|
+// Default event stream has a list of its own concepts. First, all it
|
|
|
8
|
+// does is a routing of messages to known observers. It takes an event,
|
|
|
9
|
+// defines its type and pass this message to a method of the observer.
|
|
|
10
|
+//
|
|
|
11
|
+// There might be many observers, but default event stream has a
|
|
|
12
|
+// guarantee though. It uses StreamID as a sharding key and guarantees
|
|
|
13
|
+// that a message with the same StreamID will be devlivered to the same
|
|
|
14
|
+// observer instance. So, each producer is guarateed to get all relevant
|
|
|
15
|
+// messages related to the same session. It is not possible that it will
|
|
|
16
|
+// get EventFinish if it has not seen EventStart for that session yet.
|
|
1
|
17
|
package events
|
|
2
|
18
|
|
|
3
|
19
|
import "github.com/9seconds/mtg/v2/mtglib"
|
|
4
|
20
|
|
|
|
21
|
+// Observer is an instance that listens for the incoming events.
|
|
|
22
|
+//
|
|
|
23
|
+// As it is said in the package description, the default event stream
|
|
|
24
|
+// guarantees that all events with the same StreamID are going to be
|
|
|
25
|
+// routed to the same instance of the observer. So, there is no need
|
|
|
26
|
+// to synchronize information about streams between many observers
|
|
|
27
|
+// instances, they can have their local storage.
|
|
5
|
28
|
type Observer interface {
|
|
|
29
|
+ // EventStart reacts on incoming mtglib.EventStart event.
|
|
6
|
30
|
EventStart(mtglib.EventStart)
|
|
|
31
|
+
|
|
|
32
|
+ // EventFinish reacts on incoming mtglib.EventFinish event.
|
|
7
|
33
|
EventFinish(mtglib.EventFinish)
|
|
|
34
|
+
|
|
|
35
|
+ // EventConnectedToDC reacts on incoming mtglib.EventConnectedToDC
|
|
|
36
|
+ // event.
|
|
8
|
37
|
EventConnectedToDC(mtglib.EventConnectedToDC)
|
|
|
38
|
+
|
|
|
39
|
+ // EventDomainFronting reacts on incoming mtglib.EventDomainFronting
|
|
|
40
|
+ // event.
|
|
9
|
41
|
EventDomainFronting(mtglib.EventDomainFronting)
|
|
|
42
|
+
|
|
|
43
|
+ // EventTraffic reacts on incoming mtglib.EventTraffic event.
|
|
10
|
44
|
EventTraffic(mtglib.EventTraffic)
|
|
|
45
|
+
|
|
|
46
|
+ // EventConcurrencyLimited reacts on incoming
|
|
|
47
|
+ // mtglib.EventConcurrencyLimited event.
|
|
11
|
48
|
EventConcurrencyLimited(mtglib.EventConcurrencyLimited)
|
|
|
49
|
+
|
|
|
50
|
+ // EventIPBlocklisted reacts on incoming mtglib.EventIPBlocklisted event.
|
|
12
|
51
|
EventIPBlocklisted(mtglib.EventIPBlocklisted)
|
|
|
52
|
+
|
|
|
53
|
+ // EventReplayAttack reacts on incoming mtglib.EventReplayAttack event.
|
|
13
|
54
|
EventReplayAttack(mtglib.EventReplayAttack)
|
|
14
|
55
|
|
|
|
56
|
+ // Shutdown stop observer. Default event stream guarantees:
|
|
|
57
|
+ // 1. If shutdown is executed, it is executed only once
|
|
|
58
|
+ // 2. Observer won't receieve any new message after this
|
|
|
59
|
+ // function call.
|
|
15
|
60
|
Shutdown()
|
|
16
|
61
|
}
|
|
17
|
62
|
|
|
|
63
|
+// ObserverFactory creates a new instance of the observer.
|
|
|
64
|
+//
|
|
|
65
|
+// Default event stream creates a small set of goroutines to manage
|
|
|
66
|
+// incoming messages. Each message is routed to an appropriate observer
|
|
|
67
|
+// based on a sharding key, stream id. So, it is possible that an
|
|
|
68
|
+// instance of mtg will have many observer instances, not a single one.
|
|
18
|
69
|
type ObserverFactory func() Observer
|