diff --git a/agent.go b/agent.go index 56bd9fe..ada07af 100644 --- a/agent.go +++ b/agent.go @@ -75,7 +75,7 @@ type Agent struct { // How long connectivity checks can fail before the ICE Agent // goes to disconnected - disconnectTimeout time.Duration + disconnectedTimeout time.Duration // How long connectivity checks can fail before the ICE Agent // goes to failed @@ -392,7 +392,7 @@ func (a *Agent) connectivityChecks() { } // We have been in checking longer then Disconnect+Failed timeout, set the connection to Failed - if time.Since(checkingDuration) > a.disconnectTimeout+a.failedTimeout { + if time.Since(checkingDuration) > a.disconnectedTimeout+a.failedTimeout { a.updateConnectionState(ConnectionStateFailed) return } @@ -536,13 +536,13 @@ func (a *Agent) validateSelectedPair() bool { // Only allow transitions to failed if a.failedTimeout is non-zero totalTimeToFailure := a.failedTimeout if totalTimeToFailure != 0 { - totalTimeToFailure += a.disconnectTimeout + totalTimeToFailure += a.disconnectedTimeout } switch { case totalTimeToFailure != 0 && disconnectedTime > totalTimeToFailure: a.updateConnectionState(ConnectionStateFailed) - case a.disconnectTimeout != 0 && disconnectedTime > a.disconnectTimeout: + case a.disconnectedTimeout != 0 && disconnectedTime > a.disconnectedTimeout: a.updateConnectionState(ConnectionStateDisconnected) default: a.updateConnectionState(ConnectionStateConnected) diff --git a/agent_config.go b/agent_config.go index 69bd215..2b89711 100644 --- a/agent_config.go +++ b/agent_config.go @@ -12,10 +12,10 @@ const ( defaultTaskLoopInterval = 2 * time.Second // keepaliveInterval used to keep candidates alive - defaultKeepaliveInterval = 10 * time.Second + defaultKeepaliveInterval = 2 * time.Second - // defaultDisconnectTimeout is the default time till an Agent transitions disconnected - defaultDisconnectTimeout = 5 * time.Second + // defaultDisconnectedTimeout is the default time till an Agent transitions disconnected + defaultDisconnectedTimeout = 5 * time.Second // defaultFailedTimeout is the default time till an Agent transitions to failed after disconnected defaultFailedTimeout = 25 * time.Second @@ -75,9 +75,9 @@ type AgentConfig struct { // MulticastDNSHostName controls the hostname for this agent. If none is specified a random one will be generated MulticastDNSHostName string - // DisconnectTimeout defaults to 5 seconds when this property is nil. + // DisconnectedTimeout 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 + DisconnectedTimeout *time.Duration // FailedTimeout defaults to 25 seconds when this property is nil. // If the duration is 0, we will never go to failed. @@ -191,10 +191,10 @@ func (config *AgentConfig) initWithDefaults(a *Agent) { a.relayAcceptanceMinWait = *config.RelayAcceptanceMinWait } - if config.DisconnectTimeout == nil { - a.disconnectTimeout = defaultDisconnectTimeout + if config.DisconnectedTimeout == nil { + a.disconnectedTimeout = defaultDisconnectedTimeout } else { - a.disconnectTimeout = *config.DisconnectTimeout + a.disconnectedTimeout = *config.DisconnectedTimeout } if config.FailedTimeout == nil { diff --git a/agent_test.go b/agent_test.go index 75cfbec..2393e03 100644 --- a/agent_test.go +++ b/agent_test.go @@ -708,18 +708,18 @@ func TestConnectionStateCallback(t *testing.T) { var wg sync.WaitGroup wg.Add(2) - disconnectDuration := time.Second + disconnectedDuration := time.Second failedDuration := time.Second KeepaliveInterval := time.Duration(0) cfg := &AgentConfig{ - Urls: []*URL{}, - Trickle: true, - NetworkTypes: supportedNetworkTypes, - DisconnectTimeout: &disconnectDuration, - FailedTimeout: &failedDuration, - KeepaliveInterval: &KeepaliveInterval, - taskLoopInterval: 500 * time.Millisecond, + Urls: []*URL{}, + Trickle: true, + NetworkTypes: supportedNetworkTypes, + DisconnectedTimeout: &disconnectedDuration, + FailedTimeout: &failedDuration, + KeepaliveInterval: &KeepaliveInterval, + taskLoopInterval: 500 * time.Millisecond, } aAgent, err := NewAgent(cfg) @@ -1288,11 +1288,11 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) { KeepaliveInterval := time.Duration(0) cfg := &AgentConfig{ - NetworkTypes: supportedNetworkTypes, - DisconnectTimeout: &oneSecond, - FailedTimeout: &oneSecond, - KeepaliveInterval: &KeepaliveInterval, - taskLoopInterval: 250 * time.Millisecond, + NetworkTypes: supportedNetworkTypes, + DisconnectedTimeout: &oneSecond, + FailedTimeout: &oneSecond, + KeepaliveInterval: &KeepaliveInterval, + taskLoopInterval: 250 * time.Millisecond, } aAgent, err := NewAgent(cfg) @@ -1335,10 +1335,10 @@ func TestConnectionStateConnectingToFailed(t *testing.T) { KeepaliveInterval := time.Duration(0) cfg := &AgentConfig{ - DisconnectTimeout: &oneSecond, - FailedTimeout: &oneSecond, - KeepaliveInterval: &KeepaliveInterval, - taskLoopInterval: 250 * time.Millisecond, + DisconnectedTimeout: &oneSecond, + FailedTimeout: &oneSecond, + KeepaliveInterval: &KeepaliveInterval, + taskLoopInterval: 250 * time.Millisecond, } aAgent, err := NewAgent(cfg) @@ -1413,8 +1413,8 @@ func TestAgentRestart(t *testing.T) { t.Run("Restart One Side", func(t *testing.T) { oneSecond := time.Second connA, connB := pipe(&AgentConfig{ - DisconnectTimeout: &oneSecond, - FailedTimeout: &oneSecond, + DisconnectedTimeout: &oneSecond, + FailedTimeout: &oneSecond, }) ctx, cancel := context.WithCancel(context.Background()) diff --git a/connectivity_vnet_test.go b/connectivity_vnet_test.go index 84aee34..798c816 100644 --- a/connectivity_vnet_test.go +++ b/connectivity_vnet_test.go @@ -517,22 +517,22 @@ func TestDisconnectedToConnected(t *testing.T) { // Create two agents and connect them controllingAgent, err := NewAgent(&AgentConfig{ - NetworkTypes: supportedNetworkTypes, - MulticastDNSMode: MulticastDNSModeDisabled, - Net: net0, - DisconnectTimeout: &disconnectTimeout, - KeepaliveInterval: &keepaliveInterval, - taskLoopInterval: keepaliveInterval, + NetworkTypes: supportedNetworkTypes, + MulticastDNSMode: MulticastDNSModeDisabled, + Net: net0, + DisconnectedTimeout: &disconnectTimeout, + KeepaliveInterval: &keepaliveInterval, + taskLoopInterval: keepaliveInterval, }) assert.NoError(t, err) controlledAgent, err := NewAgent(&AgentConfig{ - NetworkTypes: supportedNetworkTypes, - MulticastDNSMode: MulticastDNSModeDisabled, - Net: net1, - DisconnectTimeout: &disconnectTimeout, - KeepaliveInterval: &keepaliveInterval, - taskLoopInterval: keepaliveInterval, + NetworkTypes: supportedNetworkTypes, + MulticastDNSMode: MulticastDNSModeDisabled, + Net: net1, + DisconnectedTimeout: &disconnectTimeout, + KeepaliveInterval: &keepaliveInterval, + taskLoopInterval: keepaliveInterval, }) assert.NoError(t, err) diff --git a/transport_test.go b/transport_test.go index f79944b..0206f03 100644 --- a/transport_test.go +++ b/transport_test.go @@ -72,7 +72,7 @@ func TestTimeout(t *testing.T) { panic(err) } - testTimeout(t, ca, defaultDisconnectTimeout) + testTimeout(t, ca, defaultDisconnectedTimeout) ca, cb = pipeWithTimeout(5*time.Second, 3*time.Second) err = cb.Close() @@ -274,11 +274,11 @@ func pipeWithTimeout(disconnectTimeout time.Duration, iceKeepalive time.Duration wg.Add(2) cfg := &AgentConfig{ - Urls: urls, - Trickle: true, - DisconnectTimeout: &disconnectTimeout, - KeepaliveInterval: &iceKeepalive, - NetworkTypes: supportedNetworkTypes, + Urls: urls, + Trickle: true, + DisconnectedTimeout: &disconnectTimeout, + KeepaliveInterval: &iceKeepalive, + NetworkTypes: supportedNetworkTypes, } aAgent, err := NewAgent(cfg)