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

default.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package network
  2. import (
  3. "context"
  4. "fmt"
  5. "net"
  6. "time"
  7. )
  8. type defaultDialer struct {
  9. net.Dialer
  10. }
  11. func (d *defaultDialer) Dial(network, address string) (net.Conn, error) {
  12. return d.DialContext(context.Background(), network, address)
  13. }
  14. func (d *defaultDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
  15. switch network {
  16. case "tcp", "tcp4", "tcp6": // nolint: goconst
  17. default:
  18. return nil, fmt.Errorf("unsupported network %s", network)
  19. }
  20. conn, err := d.Dialer.DialContext(ctx, network, address)
  21. if err != nil {
  22. return nil, fmt.Errorf("cannot dial to %s: %w", address, err)
  23. }
  24. // we do not need to call to end user. End users call us.
  25. if err := SetServerSocketOptions(conn, 0); err != nil {
  26. conn.Close()
  27. return nil, fmt.Errorf("cannot set socket options: %w", err)
  28. }
  29. return conn, nil
  30. }
  31. // NewDefaultDialer build a new dialer which dials bypassing proxies
  32. // etc.
  33. //
  34. // The most default one you can imagine. But it has tunes TCP
  35. // connections and setups SO_REUSEPORT.
  36. //
  37. // bufferSize is deprecated and ignored. It is kept here for backward
  38. // compatibility.
  39. func NewDefaultDialer(timeout time.Duration, bufferSize int) (Dialer, error) {
  40. switch {
  41. case timeout < 0:
  42. return nil, fmt.Errorf("timeout %v should be positive number", timeout)
  43. case timeout == 0:
  44. timeout = DefaultTimeout
  45. }
  46. return &defaultDialer{
  47. Dialer: net.Dialer{
  48. Timeout: timeout,
  49. },
  50. }, nil
  51. }