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
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Events has a default implementations of EventStream for mtglib.
  2. //
  3. // Please see documentation for [mtglib.EventStream] interface to get an idea
  4. // of such an abstraction. This package has implementations for the default
  5. // event stream.
  6. //
  7. // Default event stream has a list of its own concepts. First, all it does is a
  8. // routing of messages to known observers. It takes an event, defines its type
  9. // and pass this message to a method of the observer.
  10. //
  11. // There might be many observers, but default event stream has a guarantee
  12. // though. It uses StreamID as a sharding key and guarantees that a message
  13. // with the same StreamID will be devlivered to the same observer instance. So,
  14. // each producer is guarateed to get all relevant messages related to the same
  15. // session. It is not possible that it will get EventFinish if it has not seen
  16. // 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 routed to
  23. // the same instance of the observer. So, there is no need to synchronize
  24. // information about streams between many observers instances, they can have
  25. // 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 incoming
  57. // messages. Each message is routed to an appropriate observer based on a
  58. // sharding key, stream id. So, it is possible that an instance of mtg will
  59. // have many observer instances, not a single one.
  60. type ObserverFactory func() Observer