Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

init.go 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.
  17. package events
  18. import "github.com/9seconds/mtg/v2/mtglib"
  19. // Observer is an instance that listens for the incoming events.
  20. //
  21. // As it is said in the package description, the default event stream
  22. // guarantees that all events with the same StreamID are going to be
  23. // routed to the same instance of the observer. So, there is no need
  24. // to synchronize information about streams between many observers
  25. // instances, they can have their local storage.
  26. type Observer interface {
  27. // EventStart reacts on incoming mtglib.EventStart event.
  28. EventStart(mtglib.EventStart)
  29. // EventFinish reacts on incoming mtglib.EventFinish event.
  30. EventFinish(mtglib.EventFinish)
  31. // EventConnectedToDC reacts on incoming mtglib.EventConnectedToDC
  32. // event.
  33. EventConnectedToDC(mtglib.EventConnectedToDC)
  34. // EventDomainFronting reacts on incoming mtglib.EventDomainFronting
  35. // event.
  36. EventDomainFronting(mtglib.EventDomainFronting)
  37. // EventTraffic reacts on incoming mtglib.EventTraffic event.
  38. EventTraffic(mtglib.EventTraffic)
  39. // EventConcurrencyLimited reacts on incoming
  40. // mtglib.EventConcurrencyLimited event.
  41. EventConcurrencyLimited(mtglib.EventConcurrencyLimited)
  42. // EventIPBlocklisted reacts on incoming mtglib.EventIPBlocklisted event.
  43. EventIPBlocklisted(mtglib.EventIPBlocklisted)
  44. // EventReplayAttack reacts on incoming mtglib.EventReplayAttack event.
  45. EventReplayAttack(mtglib.EventReplayAttack)
  46. // EventIPListSize reacts on incoming mtglib.EventIPListSize
  47. EventIPListSize(mtglib.EventIPListSize)
  48. // Shutdown stop observer. Default event stream guarantees:
  49. // 1. If shutdown is executed, it is executed only once
  50. // 2. Observer won't receieve any new message after this
  51. // function call.
  52. Shutdown()
  53. }
  54. // ObserverFactory creates a new instance of the observer.
  55. //
  56. // Default event stream creates a small set of goroutines to manage
  57. // incoming messages. Each message is routed to an appropriate observer
  58. // based on a sharding key, stream id. So, it is possible that an
  59. // instance of mtg will have many observer instances, not a single one.
  60. type ObserverFactory func() Observer