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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Network contains a default implementation of the network.
  2. //
  3. // Please see [mtglib.Network] interface to get some basic idea behind this
  4. // abstraction.
  5. //
  6. // This implementation is more simple that v1 because life shows that all
  7. // this complexity, especially around circuit breakers and DoH is not really
  8. // required. There is no chance that if DNS address is spoofed, that real
  9. // IP would work as expected.
  10. package network
  11. import (
  12. "errors"
  13. "net"
  14. "time"
  15. )
  16. const (
  17. // DefaultTimeout is a default timeout for establishing TCP connection.
  18. DefaultTimeout = 10 * time.Second
  19. // DefaultHTTPTimeout defines a default timeout for making HTTP request.
  20. DefaultHTTPTimeout = 10 * time.Second
  21. // DefaultIdleTimeout defines a timeout for idle HTTP connections
  22. DefaultIdleTimeout = time.Minute
  23. // DefaultTCPKeepAlivePeriod defines a time period between 2 consecuitive
  24. // probes.
  25. //
  26. // Deprecated: use DefaultKeepAliveConfig
  27. DefaultTCPKeepAlivePeriod = 10 * time.Second
  28. // DefaultKeepAliveIdle is the time a connection must be idle before
  29. // the first keepalive probe is sent.
  30. //
  31. // Deprecated: use DefaultKeepAliveConfig
  32. DefaultKeepAliveIdle = 30 * time.Second
  33. // DefaultKeepAliveInterval is the time between consecutive keepalive
  34. // probes.
  35. //
  36. // Deprecated: use DefaultKeepAliveConfig
  37. DefaultKeepAliveInterval = 10 * time.Second
  38. // DefaultKeepAliveCount is the number of unacknowledged probes before
  39. // the connection is considered dead.
  40. //
  41. // Deprecated: use DefaultKeepAliveConfig
  42. DefaultKeepAliveCount = 3
  43. // User Agent to use in HTTP client.
  44. UserAgent = "curl/8.5.0"
  45. // tcpLingerTimeout defines a number of seconds to wait for sending
  46. // unacknowledged data.
  47. tcpLingerTimeout = 1
  48. // tcpNotSentLowat limits the amount of unsent data queued in the
  49. // kernel write buffer per socket. When the unsent data drops below
  50. // this threshold, the socket becomes writable again. This reduces
  51. // per-connection memory usage and bufferbloat by applying
  52. // back-pressure to the relay loop instead of piling up data in
  53. // kernel buffers.
  54. tcpNotSentLowat = 128 * 1024
  55. )
  56. var (
  57. ErrCannotDial = errors.New("cannot dial to any address")
  58. // DefaultKeepAliveConfig defines a default configuration for
  59. // keep alive settings. As per official documentation, if keep alive
  60. // is enabled, then:
  61. //
  62. // Idle = 15 * time.Second
  63. // Interval = 15 * time.Second
  64. // Count = 9
  65. DefaultKeepAliveConfig = net.KeepAliveConfig{
  66. Enable: true,
  67. }
  68. )