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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sockopts.go 688B

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