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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

init.go 1.4KB

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