mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-29 22:31:50 +02:00
Add force relay conn env var for debug purpose (#904)
Add force relay conn env var for debug purpose. Move another conn related env settings into a common go file.
This commit is contained in:
parent
3bebbe0409
commit
460cb34d80
@ -4,8 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -23,9 +21,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
envICEKeepAliveIntervalSec = "NB_ICE_KEEP_ALIVE_INTERVAL_SEC"
|
|
||||||
envICEDisconnectedTimeoutSec = "NB_ICE_DISCONNECTED_TIMEOUT_SEC"
|
|
||||||
|
|
||||||
iceKeepAliveDefault = 4 * time.Second
|
iceKeepAliveDefault = 4 * time.Second
|
||||||
iceDisconnectedTimeoutDefault = 6 * time.Second
|
iceDisconnectedTimeoutDefault = 6 * time.Second
|
||||||
)
|
)
|
||||||
@ -161,13 +156,14 @@ func (conn *Conn) reCreateAgent() error {
|
|||||||
log.Errorf("failed to create pion's stdnet: %s", err)
|
log.Errorf("failed to create pion's stdnet: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
iceKeepAlive, iceDisconnectedTimeout := readICEAgentConfigProperties()
|
iceKeepAlive := iceKeepAlive()
|
||||||
|
iceDisconnectedTimeout := iceDisconnectedTimeout()
|
||||||
|
|
||||||
agentConfig := &ice.AgentConfig{
|
agentConfig := &ice.AgentConfig{
|
||||||
MulticastDNSMode: ice.MulticastDNSModeDisabled,
|
MulticastDNSMode: ice.MulticastDNSModeDisabled,
|
||||||
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4, ice.NetworkTypeUDP6},
|
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4, ice.NetworkTypeUDP6},
|
||||||
Urls: conn.config.StunTurn,
|
Urls: conn.config.StunTurn,
|
||||||
CandidateTypes: []ice.CandidateType{ice.CandidateTypeHost, ice.CandidateTypeServerReflexive, ice.CandidateTypeRelay},
|
CandidateTypes: conn.candidateTypes(),
|
||||||
FailedTimeout: &failedTimeout,
|
FailedTimeout: &failedTimeout,
|
||||||
InterfaceFilter: stdnet.InterfaceFilter(conn.config.InterfaceBlackList),
|
InterfaceFilter: stdnet.InterfaceFilter(conn.config.InterfaceBlackList),
|
||||||
UDPMux: conn.config.UDPMux,
|
UDPMux: conn.config.UDPMux,
|
||||||
@ -206,32 +202,11 @@ func (conn *Conn) reCreateAgent() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readICEAgentConfigProperties() (time.Duration, time.Duration) {
|
func (conn *Conn) candidateTypes() []ice.CandidateType {
|
||||||
iceKeepAlive := iceKeepAliveDefault
|
if hasICEForceRelayConn() {
|
||||||
iceDisconnectedTimeout := iceDisconnectedTimeoutDefault
|
return []ice.CandidateType{ice.CandidateTypeRelay}
|
||||||
|
|
||||||
keepAliveEnv := os.Getenv(envICEKeepAliveIntervalSec)
|
|
||||||
if keepAliveEnv != "" {
|
|
||||||
log.Debugf("setting ICE keep alive interval to %s seconds", keepAliveEnv)
|
|
||||||
keepAliveEnvSec, err := strconv.Atoi(keepAliveEnv)
|
|
||||||
if err == nil {
|
|
||||||
iceKeepAlive = time.Duration(keepAliveEnvSec) * time.Second
|
|
||||||
} else {
|
|
||||||
log.Warnf("invalid value %s set for %s, using default %v", keepAliveEnv, envICEKeepAliveIntervalSec, iceKeepAlive)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return []ice.CandidateType{ice.CandidateTypeHost, ice.CandidateTypeServerReflexive, ice.CandidateTypeRelay}
|
||||||
disconnectedTimeoutEnv := os.Getenv(envICEDisconnectedTimeoutSec)
|
|
||||||
if disconnectedTimeoutEnv != "" {
|
|
||||||
log.Debugf("setting ICE disconnected timeout to %s seconds", disconnectedTimeoutEnv)
|
|
||||||
disconnectedTimeoutSec, err := strconv.Atoi(disconnectedTimeoutEnv)
|
|
||||||
if err == nil {
|
|
||||||
iceDisconnectedTimeout = time.Duration(disconnectedTimeoutSec) * time.Second
|
|
||||||
} else {
|
|
||||||
log.Warnf("invalid value %s set for %s, using default %v", disconnectedTimeoutEnv, envICEDisconnectedTimeoutSec, iceDisconnectedTimeout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return iceKeepAlive, iceDisconnectedTimeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens connection to the remote peer starting ICE candidate gathering process.
|
// Open opens connection to the remote peer starting ICE candidate gathering process.
|
||||||
|
53
client/internal/peer/env_config.go
Normal file
53
client/internal/peer/env_config.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package peer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
envICEKeepAliveIntervalSec = "NB_ICE_KEEP_ALIVE_INTERVAL_SEC"
|
||||||
|
envICEDisconnectedTimeoutSec = "NB_ICE_DISCONNECTED_TIMEOUT_SEC"
|
||||||
|
envICEForceRelayConn = "NB_ICE_FORCE_RELAY_CONN"
|
||||||
|
)
|
||||||
|
|
||||||
|
func iceKeepAlive() time.Duration {
|
||||||
|
keepAliveEnv := os.Getenv(envICEKeepAliveIntervalSec)
|
||||||
|
if keepAliveEnv == "" {
|
||||||
|
return iceKeepAliveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("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)
|
||||||
|
return iceKeepAliveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Duration(keepAliveEnvSec) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
func iceDisconnectedTimeout() time.Duration {
|
||||||
|
disconnectedTimeoutEnv := os.Getenv(envICEDisconnectedTimeoutSec)
|
||||||
|
if disconnectedTimeoutEnv == "" {
|
||||||
|
return iceDisconnectedTimeoutDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("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)
|
||||||
|
return iceDisconnectedTimeoutDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Duration(disconnectedTimeoutSec) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasICEForceRelayConn() bool {
|
||||||
|
disconnectedTimeoutEnv := os.Getenv(envICEForceRelayConn)
|
||||||
|
return strings.ToLower(disconnectedTimeoutEnv) == "true"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user