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
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

simple_run.go 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package cli
  2. import (
  3. "fmt"
  4. "net"
  5. "strconv"
  6. "time"
  7. "github.com/9seconds/mtg/v2/internal/config"
  8. )
  9. type SimpleRun struct {
  10. BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
  11. Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
  12. Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"` // nolint: lll
  13. Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"` // nolint: lll
  14. TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"` // nolint: lll
  15. PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"` // nolint: lll
  16. DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"` // nolint: lll
  17. DOHIP net.IP `kong:"name='doh-ip',short='n',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"` // nolint: lll
  18. Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"` // nolint: lll
  19. AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"` // nolint: lll
  20. }
  21. func (s *SimpleRun) Run(cli *CLI, version string) error { // nolint: cyclop
  22. conf := &config.Config{}
  23. if err := conf.BindTo.Set(s.BindTo); err != nil {
  24. return fmt.Errorf("incorrect bind-to parameter: %w", err)
  25. }
  26. if err := conf.Secret.Set(s.Secret); err != nil {
  27. return fmt.Errorf("incorrect secret: %w", err)
  28. }
  29. if err := conf.Concurrency.Set(strconv.FormatUint(s.Concurrency, 10)); err != nil {
  30. return fmt.Errorf("incorrect concurrency: %w", err)
  31. }
  32. if err := conf.TCPBuffer.Set(s.TCPBuffer); err != nil {
  33. return fmt.Errorf("incorrect tcp-buffer: %w", err)
  34. }
  35. if err := conf.PreferIP.Set(s.PreferIP); err != nil {
  36. return fmt.Errorf("incorrect prefer-ip: %w", err)
  37. }
  38. if err := conf.DomainFrontingPort.Set(strconv.FormatUint(s.DomainFrontingPort, 10)); err != nil {
  39. return fmt.Errorf("incorrect domain-fronting-port: %w", err)
  40. }
  41. if err := conf.Network.DOHIP.Set(s.DOHIP.String()); err != nil {
  42. return fmt.Errorf("incorrect doh-ip: %w", err)
  43. }
  44. if err := conf.Network.Timeout.TCP.Set(s.Timeout.String()); err != nil {
  45. return fmt.Errorf("incorrect timeout: %w", err)
  46. }
  47. if err := conf.Network.Timeout.HTTP.Set(s.Timeout.String()); err != nil {
  48. return fmt.Errorf("incorrect timeout: %w", err)
  49. }
  50. if err := conf.Network.Timeout.Idle.Set(s.Timeout.String()); err != nil {
  51. return fmt.Errorf("incorrect timeout: %w", err)
  52. }
  53. if err := conf.Defense.AntiReplay.MaxSize.Set(s.AntiReplayCacheSize); err != nil {
  54. return fmt.Errorf("incorrect antireplay-cache-size: %w", err)
  55. }
  56. conf.Debug.Value = s.Debug
  57. conf.Defense.AntiReplay.Enabled.Value = true
  58. conf.Defense.Blocklist.Enabled.Value = false
  59. conf.Stats.StatsD.Enabled.Value = false
  60. conf.Stats.Prometheus.Enabled.Value = false
  61. if err := conf.Validate(); err != nil {
  62. return fmt.Errorf("invalid result configuration: %w", err)
  63. }
  64. return runProxy(conf, version)
  65. }