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ů.

sockopts.go 752B

1234567891011121314151617181920212223242526272829303132
  1. package network
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. func setCommonSocketOptions(conn *net.TCPConn) error {
  7. if err := conn.SetKeepAliveConfig(net.KeepAliveConfig{
  8. Enable: true,
  9. Idle: DefaultKeepAliveIdle,
  10. Interval: DefaultKeepAliveInterval,
  11. Count: DefaultKeepAliveCount,
  12. }); err != nil {
  13. return fmt.Errorf("cannot configure TCP keepalive: %w", err)
  14. }
  15. if err := conn.SetLinger(tcpLingerTimeout); err != nil {
  16. return fmt.Errorf("cannot set TCP linger timeout: %w", err)
  17. }
  18. rawConn, err := conn.SyscallConn()
  19. if err != nil {
  20. return fmt.Errorf("cannot get underlying raw connection: %w", err)
  21. }
  22. if err := setSocketReuseAddrPort(rawConn); err != nil {
  23. return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
  24. }
  25. return nil
  26. }