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 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package mtglib
  2. import (
  3. "context"
  4. "errors"
  5. "net"
  6. "net/http"
  7. "time"
  8. )
  9. var (
  10. ErrSecretEmpty = errors.New("secret is empty")
  11. ErrSecretInvalid = errors.New("secret is invalid")
  12. ErrNetworkIsNotDefined = errors.New("network is not defined")
  13. ErrAntiReplayCacheIsNotDefined = errors.New("anti-replay cache is not defined")
  14. ErrIPBlocklistIsNotDefined = errors.New("ip blocklist is not defined")
  15. ErrEventStreamIsNotDefined = errors.New("event stream is not defined")
  16. ErrLoggerIsNotDefined = errors.New("logger is not defined")
  17. )
  18. const (
  19. DefaultConcurrency = 4096
  20. )
  21. type Network interface {
  22. Dial(network, address string) (net.Conn, error)
  23. DialContext(ctx context.Context, network, address string) (net.Conn, error)
  24. MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
  25. IdleTimeout() time.Duration
  26. }
  27. type AntiReplayCache interface {
  28. SeenBefore(data []byte) bool
  29. Shutdown()
  30. }
  31. type IPBlocklist interface {
  32. Contains(net.IP) bool
  33. Shutdown()
  34. }
  35. type Event interface {
  36. StreamID() string
  37. }
  38. type EventStream interface {
  39. Send(context.Context, Event)
  40. Shutdown()
  41. }
  42. type Logger interface {
  43. Named(name string) Logger
  44. BindInt(name string, value int) Logger
  45. BindStr(name, value string) Logger
  46. Info(msg string)
  47. InfoError(msg string, err error)
  48. Warning(msg string)
  49. WarningError(msg string, err error)
  50. Debug(msg string)
  51. DebugError(msg string, err error)
  52. }