13 Commits
Author SHA1 Message Date
appolimp 5f81ae3743 Improve TCP keepalive and idle timeout for mobile clients
TCP keepalive was configured (SetKeepAlivePeriod) but never actually
enabled (SO_KEEPALIVE) on accepted client connections. Go 1.26's
SetKeepAlivePeriod only sets TCP_KEEPIDLE — it does not call
setsockopt(SO_KEEPALIVE, 1). Without SO_KEEPALIVE the kernel never
sends probe packets, so dead connections from sleeping mobile clients
linger until the idle timeout fires.

Replace SetKeepAlive + SetKeepAlivePeriod with net.KeepAliveConfig
(available since Go 1.24) for explicit per-socket control:

  Idle:     30s   (time before first probe)
  Interval: 10s   (between probes)
  Count:    3     (failed probes to declare dead)

This detects dead connections in ~60s instead of relying on system
defaults (tcp_keepalive_intvl=75s, probes=9 → up to 11 minutes).

Increase the default idle timeout from 1 minute to 5 minutes.
MTProto clients send ping_delay_disconnect every ~60s, which resets
the idle timer. The previous 1-minute default created a race: if a
ping arrived even 1–2 seconds late the relay was killed. A 5-minute
window also survives typical mobile sleep periods (phone idle 2–5 min)
where the NAT mapping is still alive and the connection can resume
without reconnection.

Ref: #132
2026-04-04 12:01:33 +03:00
9seconds 36546cec2f Change default DOH to cloudflarte 2026-02-16 17:18:31 +01:00
9seconds 6a19ded78e Update docs 2022-08-04 18:39:00 +03:00
9seconds ffad717829 Use CloseRead and CloseWrites 2021-12-01 10:37:31 +03:00
9seconds d19cfb1df4 Deprecate bufferSize 2021-11-28 17:58:14 +03:00
9seconds 456ed5b051 Change algorithm of TCP relaying 2021-08-27 17:22:36 +03:00
9seconds e1864377c2 Update golangci-lint to 1.40.1 2021-05-17 15:26:16 +03:00
9seconds 372c703ad6 Add documentation for network 2021-04-05 18:46:15 +03:00
9seconds 657a74a5c2 Add defaults for proxy opts 2021-03-18 11:16:08 +03:00
9seconds f21ee40baf Remove idle timeout from network 2021-03-17 22:08:47 +03:00
9seconds adf4ab1a35 Revert "Add new TCPBufferSize parameter to network"
This reverts commit 57cb1b5aa0.
2021-03-17 22:03:36 +03:00
9seconds 57cb1b5aa0 Add new TCPBufferSize parameter to network 2021-03-17 21:44:42 +03:00
9seconds f8ad90c845 Refactor network to a top-level module 2021-03-14 21:43:30 +03:00