From 9c2dc05df1a735adc4ab8ec19fc6371c528817c2 Mon Sep 17 00:00:00 2001 From: Misha Bragin Date: Sun, 31 Mar 2024 19:39:52 +0200 Subject: [PATCH] Eval/higher timeouts (#1776) --- client/internal/peer/conn.go | 28 ++++++++++++++++------------ client/internal/peer/env_config.go | 27 ++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index c180e8f032b..ce8cc4b9779 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -26,6 +26,8 @@ import ( const ( iceKeepAliveDefault = 4 * time.Second iceDisconnectedTimeoutDefault = 6 * time.Second + // iceRelayAcceptanceMinWaitDefault is the same as in the Pion ICE package + iceRelayAcceptanceMinWaitDefault = 2 * time.Second defaultWgKeepAlive = 25 * time.Second ) @@ -196,20 +198,22 @@ func (conn *Conn) reCreateAgent() error { iceKeepAlive := iceKeepAlive() iceDisconnectedTimeout := iceDisconnectedTimeout() + iceRelayAcceptanceMinWait := iceRelayAcceptanceMinWait() agentConfig := &ice.AgentConfig{ - MulticastDNSMode: ice.MulticastDNSModeDisabled, - NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4, ice.NetworkTypeUDP6}, - Urls: conn.config.StunTurn, - CandidateTypes: conn.candidateTypes(), - FailedTimeout: &failedTimeout, - InterfaceFilter: stdnet.InterfaceFilter(conn.config.InterfaceBlackList), - UDPMux: conn.config.UDPMux, - UDPMuxSrflx: conn.config.UDPMuxSrflx, - NAT1To1IPs: conn.config.NATExternalIPs, - Net: transportNet, - DisconnectedTimeout: &iceDisconnectedTimeout, - KeepaliveInterval: &iceKeepAlive, + MulticastDNSMode: ice.MulticastDNSModeDisabled, + NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4, ice.NetworkTypeUDP6}, + Urls: conn.config.StunTurn, + CandidateTypes: conn.candidateTypes(), + FailedTimeout: &failedTimeout, + InterfaceFilter: stdnet.InterfaceFilter(conn.config.InterfaceBlackList), + UDPMux: conn.config.UDPMux, + UDPMuxSrflx: conn.config.UDPMuxSrflx, + NAT1To1IPs: conn.config.NATExternalIPs, + Net: transportNet, + DisconnectedTimeout: &iceDisconnectedTimeout, + KeepaliveInterval: &iceKeepAlive, + RelayAcceptanceMinWait: &iceRelayAcceptanceMinWait, } if conn.config.DisableIPv6Discovery { diff --git a/client/internal/peer/env_config.go b/client/internal/peer/env_config.go index 540bc413ea7..87b626df763 100644 --- a/client/internal/peer/env_config.go +++ b/client/internal/peer/env_config.go @@ -10,9 +10,10 @@ import ( ) const ( - envICEKeepAliveIntervalSec = "NB_ICE_KEEP_ALIVE_INTERVAL_SEC" - envICEDisconnectedTimeoutSec = "NB_ICE_DISCONNECTED_TIMEOUT_SEC" - envICEForceRelayConn = "NB_ICE_FORCE_RELAY_CONN" + envICEKeepAliveIntervalSec = "NB_ICE_KEEP_ALIVE_INTERVAL_SEC" + envICEDisconnectedTimeoutSec = "NB_ICE_DISCONNECTED_TIMEOUT_SEC" + envICERelayAcceptanceMinWaitSec = "NB_ICE_RELAY_ACCEPTANCE_MIN_WAIT_SEC" + envICEForceRelayConn = "NB_ICE_FORCE_RELAY_CONN" ) func iceKeepAlive() time.Duration { @@ -21,7 +22,7 @@ func iceKeepAlive() time.Duration { return iceKeepAliveDefault } - log.Debugf("setting ICE keep alive interval to %s seconds", keepAliveEnv) + log.Infof("setting ICE keep alive interval to %s seconds", keepAliveEnv) keepAliveEnvSec, err := strconv.Atoi(keepAliveEnv) if err != nil { log.Warnf("invalid value %s set for %s, using default %v", keepAliveEnv, envICEKeepAliveIntervalSec, iceKeepAliveDefault) @@ -37,7 +38,7 @@ func iceDisconnectedTimeout() time.Duration { return iceDisconnectedTimeoutDefault } - log.Debugf("setting ICE disconnected timeout to %s seconds", disconnectedTimeoutEnv) + log.Infof("setting ICE disconnected timeout to %s seconds", disconnectedTimeoutEnv) disconnectedTimeoutSec, err := strconv.Atoi(disconnectedTimeoutEnv) if err != nil { log.Warnf("invalid value %s set for %s, using default %v", disconnectedTimeoutEnv, envICEDisconnectedTimeoutSec, iceDisconnectedTimeoutDefault) @@ -47,6 +48,22 @@ func iceDisconnectedTimeout() time.Duration { return time.Duration(disconnectedTimeoutSec) * time.Second } +func iceRelayAcceptanceMinWait() time.Duration { + iceRelayAcceptanceMinWaitEnv := os.Getenv(envICERelayAcceptanceMinWaitSec) + if iceRelayAcceptanceMinWaitEnv == "" { + return iceRelayAcceptanceMinWaitDefault + } + + log.Infof("setting ICE relay acceptance min wait to %s seconds", iceRelayAcceptanceMinWaitEnv) + disconnectedTimeoutSec, err := strconv.Atoi(iceRelayAcceptanceMinWaitEnv) + if err != nil { + log.Warnf("invalid value %s set for %s, using default %v", iceRelayAcceptanceMinWaitEnv, envICERelayAcceptanceMinWaitSec, iceRelayAcceptanceMinWaitDefault) + return iceRelayAcceptanceMinWaitDefault + } + + return time.Duration(disconnectedTimeoutSec) * time.Second +} + func hasICEForceRelayConn() bool { disconnectedTimeoutEnv := os.Getenv(envICEForceRelayConn) return strings.ToLower(disconnectedTimeoutEnv) == "true"