From b460537e5d8fa50fb3bc575acd65b5ca2d0c3b70 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Wed, 24 Apr 2024 16:31:51 -0400 Subject: [PATCH 1/2] Disable Keep-Alive --- outline/device/stream_dialer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/outline/device/stream_dialer.go b/outline/device/stream_dialer.go index b837bbc443..56617350bf 100644 --- a/outline/device/stream_dialer.go +++ b/outline/device/stream_dialer.go @@ -15,13 +15,17 @@ package device import ( + "net" + "github.com/Jigsaw-Code/outline-sdk/transport" "github.com/Jigsaw-Code/outline-sdk/transport/shadowsocks" ) // newOutlineStreamDialer creates a [transport.StreamDialer] that connects to the remote proxy using `config`. func newOutlineStreamDialer(config *transportConfig) (transport.StreamDialer, error) { - dialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: config.RemoteAddress}, config.CryptoKey) + // We disable Keep-Alive as per https://datatracker.ietf.org/doc/html/rfc1122#page-101, which states that it should only be + // enabled in server applications. This prevents the device from unnecessarily waking up to send keep alives. + dialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: config.RemoteAddress, Dialer: net.Dialer{KeepAlive: -1}}, config.CryptoKey) if err != nil { return nil, err } From 0bd00f51d4bce3342e9035e92dc815d8f2f85b63 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Wed, 24 Apr 2024 17:26:29 -0400 Subject: [PATCH 2/2] Real fix --- client/src/tun2socks/outline/shadowsocks/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/tun2socks/outline/shadowsocks/client.go b/client/src/tun2socks/outline/shadowsocks/client.go index bacbc2c82b..1b1cc7018e 100644 --- a/client/src/tun2socks/outline/shadowsocks/client.go +++ b/client/src/tun2socks/outline/shadowsocks/client.go @@ -81,7 +81,9 @@ func newShadowsocksClient(host string, port int, cipherName, password string, pr return nil, fmt.Errorf("failed to create Shadowsocks cipher: %w", err) } - streamDialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: proxyAddress}, cryptoKey) + // We disable Keep-Alive as per https://datatracker.ietf.org/doc/html/rfc1122#page-101, which states that it should only be + // enabled in server applications. This prevents the device from unnecessarily waking up to send keep alives. + streamDialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: proxyAddress, Dialer: net.Dialer{KeepAlive: -1}}, cryptoKey) if err != nil { return nil, fmt.Errorf("failed to create StreamDialer: %w", err) }