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
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

sockopts_linux.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //go:build linux
  2. package network
  3. import (
  4. "net"
  5. "syscall"
  6. "time"
  7. "golang.org/x/sys/unix"
  8. )
  9. // Go runtime defaults for KeepAliveConfig when fields are zero.
  10. const (
  11. goDefaultKeepAliveIdle = 15 * time.Second
  12. goDefaultKeepAliveInterval = 15 * time.Second
  13. goDefaultKeepAliveCount = 9
  14. )
  15. // setTCPUserTimeout sets TCP_USER_TIMEOUT on a socket. If transmitted
  16. // data remains unacknowledged for this long, the kernel closes the
  17. // connection. As recommended by Cloudflare
  18. // (https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die/),
  19. // the value is computed as: keepidle + keepintvl * keepcnt. This
  20. // ensures TCP_USER_TIMEOUT and keepalives agree on when to give up.
  21. // Best-effort: silently ignored if unsupported.
  22. func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {
  23. idle := cfg.Idle
  24. if idle == 0 {
  25. idle = goDefaultKeepAliveIdle
  26. }
  27. interval := cfg.Interval
  28. if interval == 0 {
  29. interval = goDefaultKeepAliveInterval
  30. }
  31. count := cfg.Count
  32. if count == 0 {
  33. count = goDefaultKeepAliveCount
  34. }
  35. timeout := idle + interval*time.Duration(count)
  36. conn.Control(func(fd uintptr) { //nolint: errcheck
  37. unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout.Milliseconds())) //nolint: errcheck
  38. })
  39. }
  40. func setCongestionControl(conn syscall.RawConn) {
  41. conn.Control(func(fd uintptr) { //nolint: errcheck
  42. // BBR provides better throughput over lossy and high-latency links compared
  43. // to the default cubic, which is especially beneficial for mobile and
  44. // home internet clients. This is best-effort: silently ignored if the
  45. // kernel does not have tcp_bbr available.
  46. unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
  47. })
  48. }