mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Rename ConnectionTimeout -> DisconnectTimeout
ICE has two distinct states `Disconnected` and `Failed`. We need to split out these arguments so that we can control (and test) both. Relates to #190
This commit is contained in:
@@ -25,8 +25,11 @@ const (
|
||||
// keepaliveInterval used to keep candidates alive
|
||||
defaultKeepaliveInterval = 10 * time.Second
|
||||
|
||||
// defaultConnectionTimeout used to declare a connection dead
|
||||
defaultConnectionTimeout = 30 * time.Second
|
||||
// defaultDisconnectTimeout is the default time till an Agent transitions disconnected
|
||||
defaultDisconnectTimeout = 5 * time.Second
|
||||
|
||||
// defaultFailureTimeout is the default time till an Agent transitions to failed
|
||||
defaultFailureTimeout = 25 * time.Second //nolint
|
||||
|
||||
// timeout for candidate selection, after this time, the best candidate is used
|
||||
defaultCandidateSelectionTimeout = 10 * time.Second
|
||||
@@ -112,9 +115,13 @@ type Agent struct {
|
||||
|
||||
candidateTypes []CandidateType
|
||||
|
||||
// How long should a pair stay quiet before we declare it dead?
|
||||
// 0 means never timeout
|
||||
connectionTimeout time.Duration
|
||||
// How long connectivity checks can fail before the ICE Agent
|
||||
// goes to disconnected
|
||||
disconnectTimeout time.Duration
|
||||
|
||||
// How long connectivity checks can fail before the ICE Agent
|
||||
// goes to failed
|
||||
failedTimeout time.Duration //nolint
|
||||
|
||||
// How often should we send keepalive packets?
|
||||
// 0 means never
|
||||
@@ -230,9 +237,14 @@ type AgentConfig struct {
|
||||
// MulticastDNSHostName controls the hostname for this agent. If none is specified a random one will be generated
|
||||
MulticastDNSHostName string
|
||||
|
||||
// ConnectionTimeout defaults to 30 seconds when this property is nil.
|
||||
// If the duration is 0, we will never timeout this connection.
|
||||
ConnectionTimeout *time.Duration
|
||||
// DisconnectTimeout defaults to 5 seconds when this property is nil.
|
||||
// If the duration is 0, the ICE Agent will never go to disconnected
|
||||
DisconnectTimeout *time.Duration
|
||||
|
||||
// FailedTimeout defaults to 25 seconds when this property is nil.
|
||||
// If the duration is 0, we will never go to failed.
|
||||
FailedTimeout *time.Duration
|
||||
|
||||
// KeepaliveInterval determines how often should we send ICE
|
||||
// keepalives (should be less then connectiontimeout above)
|
||||
// when this is nil, it defaults to 10 seconds.
|
||||
@@ -489,11 +501,10 @@ func (a *Agent) initWithDefaults(config *AgentConfig) {
|
||||
a.relayAcceptanceMinWait = *config.RelayAcceptanceMinWait
|
||||
}
|
||||
|
||||
// connectionTimeout used to declare a connection dead
|
||||
if config.ConnectionTimeout == nil {
|
||||
a.connectionTimeout = defaultConnectionTimeout
|
||||
if config.DisconnectTimeout == nil {
|
||||
a.disconnectTimeout = defaultDisconnectTimeout
|
||||
} else {
|
||||
a.connectionTimeout = *config.ConnectionTimeout
|
||||
a.disconnectTimeout = *config.DisconnectTimeout
|
||||
}
|
||||
|
||||
if config.KeepaliveInterval == nil {
|
||||
@@ -753,7 +764,7 @@ func (a *Agent) validateSelectedPair() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if (a.connectionTimeout != 0) && (time.Since(selectedPair.remote.LastReceived()) > a.connectionTimeout) {
|
||||
if (a.disconnectTimeout != 0) && (time.Since(selectedPair.remote.LastReceived()) > a.disconnectTimeout) {
|
||||
a.updateConnectionState(ConnectionStateDisconnected)
|
||||
} else {
|
||||
a.updateConnectionState(ConnectionStateConnected)
|
||||
|
||||
+2
-2
@@ -702,13 +702,13 @@ func TestConnectionStateCallback(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
timeoutDuration := time.Second
|
||||
disconnectDuration := time.Second
|
||||
KeepaliveInterval := time.Duration(0)
|
||||
cfg := &AgentConfig{
|
||||
Urls: []*URL{},
|
||||
Trickle: true,
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
ConnectionTimeout: &timeoutDuration,
|
||||
DisconnectTimeout: &disconnectDuration,
|
||||
KeepaliveInterval: &KeepaliveInterval,
|
||||
taskLoopInterval: 500 * time.Millisecond,
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
|
||||
connectionTimeout := time.Second
|
||||
disconnectTimeout := time.Second
|
||||
keepaliveInterval := time.Millisecond * 20
|
||||
|
||||
// Create two agents and connect them
|
||||
@@ -520,7 +520,7 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
MulticastDNSMode: MulticastDNSModeDisabled,
|
||||
Net: net0,
|
||||
ConnectionTimeout: &connectionTimeout,
|
||||
DisconnectTimeout: &disconnectTimeout,
|
||||
KeepaliveInterval: &keepaliveInterval,
|
||||
taskLoopInterval: keepaliveInterval,
|
||||
})
|
||||
@@ -530,7 +530,7 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
MulticastDNSMode: MulticastDNSModeDisabled,
|
||||
Net: net1,
|
||||
ConnectionTimeout: &connectionTimeout,
|
||||
DisconnectTimeout: &disconnectTimeout,
|
||||
KeepaliveInterval: &keepaliveInterval,
|
||||
taskLoopInterval: keepaliveInterval,
|
||||
})
|
||||
|
||||
+3
-3
@@ -72,7 +72,7 @@ func TestTimeout(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
testTimeout(t, ca, defaultConnectionTimeout)
|
||||
testTimeout(t, ca, defaultDisconnectTimeout)
|
||||
|
||||
ca, cb = pipeWithTimeout(5*time.Second, 3*time.Second)
|
||||
err = cb.Close()
|
||||
@@ -261,7 +261,7 @@ func pipe() (*Conn, *Conn) {
|
||||
return aConn, bConn
|
||||
}
|
||||
|
||||
func pipeWithTimeout(iceTimeout time.Duration, iceKeepalive time.Duration) (*Conn, *Conn) {
|
||||
func pipeWithTimeout(disconnectTimeout time.Duration, iceKeepalive time.Duration) (*Conn, *Conn) {
|
||||
var urls []*URL
|
||||
|
||||
aNotifier, aConnected := onConnected()
|
||||
@@ -273,7 +273,7 @@ func pipeWithTimeout(iceTimeout time.Duration, iceKeepalive time.Duration) (*Con
|
||||
cfg := &AgentConfig{
|
||||
Urls: urls,
|
||||
Trickle: true,
|
||||
ConnectionTimeout: &iceTimeout,
|
||||
DisconnectTimeout: &disconnectTimeout,
|
||||
KeepaliveInterval: &iceKeepalive,
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user