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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

init.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. TCPBufferSize() int
  27. }
  28. type AntiReplayCache interface {
  29. SeenBefore(data []byte) bool
  30. Shutdown()
  31. }
  32. type IPBlocklist interface {
  33. Contains(net.IP) bool
  34. Shutdown()
  35. }
  36. type Event interface {
  37. StreamID() string
  38. }
  39. type EventStream interface {
  40. Send(context.Context, Event)
  41. Shutdown()
  42. }
  43. type Logger interface {
  44. Named(name string) Logger
  45. BindInt(name string, value int) Logger
  46. BindStr(name, value string) Logger
  47. Info(msg string)
  48. InfoError(msg string, err error)
  49. Warning(msg string)
  50. WarningError(msg string, err error)
  51. Debug(msg string)
  52. DebugError(msg string, err error)
  53. }