Browse Source

Reconfigure idle timeouts and keep alives

Rod Hynes 7 years ago
parent
commit
0c1a5b0e77
1 changed files with 9 additions and 6 deletions
  1. 9 6
      psiphon/common/quic/quic.go

+ 9 - 6
psiphon/common/quic/quic.go

@@ -33,6 +33,10 @@ accepts a Context input which may be used to cancel the dial.
 
 Conns mask or translate qerr.PeerGoingAway to io.EOF as appropriate.
 
+QUIC idle timeouts and keep alives are tuned to mitigate aggressive UDP NAT
+timeouts on mobile data networks while accounting for the fact that mobile
+devices in standby/sleep may not be able to initiate the keep alive.
+
 */
 package quic
 
@@ -53,6 +57,7 @@ import (
 const (
 	SERVER_HANDSHAKE_TIMEOUT = 30 * time.Second
 	SERVER_IDLE_TIMEOUT      = 5 * time.Minute
+	CLIENT_IDLE_TIMEOUT      = 30 * time.Second
 )
 
 // Listener is a net.Listener.
@@ -84,7 +89,7 @@ func Listen(addr string) (*Listener, error) {
 		IdleTimeout:           SERVER_IDLE_TIMEOUT,
 		MaxIncomingStreams:    1,
 		MaxIncomingUniStreams: -1,
-		KeepAlive:             false,
+		KeepAlive:             true,
 	}
 
 	quicListener, err := quic_go.ListenAddr(
@@ -139,12 +144,10 @@ func Dial(
 
 	go func() {
 
-		maxDuration := time.Duration(1<<63 - 1)
-
 		quicConfig := &quic_go.Config{
-			HandshakeTimeout: maxDuration,
-			IdleTimeout:      maxDuration,
-			KeepAlive:        false,
+			HandshakeTimeout: time.Duration(1<<63 - 1),
+			IdleTimeout:      CLIENT_IDLE_TIMEOUT,
+			KeepAlive:        true,
 		}
 
 		deadline, ok := ctx.Deadline()