mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Set defaultKeepaliveInterval to 2 seconds
This should be lower then defaultDisconnectTimeout otherwise we are going to enter disconnected. Also rename defaultDisconnectTimeout -> defaultDisconnectedTimeout to make the tense consistent with other options Resolves #190
This commit is contained in:
@@ -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)
|
||||
|
||||
+8
-8
@@ -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 {
|
||||
|
||||
+19
-19
@@ -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())
|
||||
|
||||
+12
-12
@@ -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)
|
||||
|
||||
|
||||
+6
-6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user