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.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. DefaultBufferSize = 16 * 1024 // 16 kib
  21. DefaultCloakPort = 443
  22. DefaultIdleTimeout = time.Minute
  23. DefaultPreferIP = "prefer-ipv6"
  24. )
  25. type Network interface {
  26. Dial(network, address string) (net.Conn, error)
  27. DialContext(ctx context.Context, network, address string) (net.Conn, error)
  28. MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
  29. }
  30. type AntiReplayCache interface {
  31. SeenBefore(data []byte) bool
  32. Shutdown()
  33. }
  34. type IPBlocklist interface {
  35. Contains(net.IP) bool
  36. Shutdown()
  37. }
  38. type Event interface {
  39. StreamID() string
  40. }
  41. type EventStream interface {
  42. Send(context.Context, Event)
  43. Shutdown()
  44. }
  45. type TimeAttackDetector interface {
  46. Valid(time.Time) error
  47. }
  48. type Logger interface {
  49. Named(name string) Logger
  50. BindInt(name string, value int) Logger
  51. BindStr(name, value string) Logger
  52. Printf(format string, args ...interface{})
  53. Info(msg string)
  54. InfoError(msg string, err error)
  55. Warning(msg string)
  56. WarningError(msg string, err error)
  57. Debug(msg string)
  58. DebugError(msg string, err error)
  59. }