From 41e743e735f6c240a5020f49d27fd5f0064571c7 Mon Sep 17 00:00:00 2001 From: Michael Ira Krufky Date: Fri, 25 Jan 2019 14:56:58 -0500 Subject: [PATCH] conn.(*net.TCPConn).SetKeepAlive(true) on non TLS connections --- proxy/stratum.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxy/stratum.go b/proxy/stratum.go index 837928937..1c8753bd6 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -22,6 +22,7 @@ func (s *ProxyServer) ListenTCP() { var err error var server net.Listener + setKeepAlive := func(net.Conn) {} if s.config.Proxy.Stratum.TLS { var cert tls.Certificate cert, err = tls.LoadX509KeyPair(s.config.Proxy.Stratum.CertFile, s.config.Proxy.Stratum.KeyFile) @@ -32,6 +33,9 @@ func (s *ProxyServer) ListenTCP() { server, err = tls.Listen("tcp", s.config.Proxy.Stratum.Listen, tlsCfg) } else { server, err = net.Listen("tcp", s.config.Proxy.Stratum.Listen) + setKeepAlive = func(conn net.Conn) { + conn.(*net.TCPConn).SetKeepAlive(true) + } } if err != nil { log.Fatalf("Error: %v", err) @@ -47,6 +51,8 @@ func (s *ProxyServer) ListenTCP() { if err != nil { continue } + setKeepAlive(conn) + ip, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) if s.policy.IsBanned(ip) || !s.policy.ApplyLimitPolicy(ip) {