Expose stunGatherTimeout in Agent struct (#668)

This commit is contained in:
Stephan Rotolante
2024-04-02 23:17:51 -04:00
committed by GitHub
parent a12f670c79
commit edaa25e409
3 changed files with 14 additions and 7 deletions
+1
View File
@@ -69,6 +69,7 @@ type Agent struct {
srflxAcceptanceMinWait time.Duration
prflxAcceptanceMinWait time.Duration
relayAcceptanceMinWait time.Duration
stunGatherTimeout time.Duration
tcpPriorityOffset uint16
disableActiveTCP bool
+11
View File
@@ -38,6 +38,9 @@ const (
// defaultRelayAcceptanceMinWait is the wait time before nominating a relay candidate
defaultRelayAcceptanceMinWait = 2000 * time.Millisecond
// defaultStunGatherTimeout is the wait time for STUN responses
defaultStunGatherTimeout = 5 * time.Second
// defaultMaxBindingRequests is the maximum number of binding requests before considering a pair failed
defaultMaxBindingRequests = 7
@@ -136,6 +139,8 @@ type AgentConfig struct {
PrflxAcceptanceMinWait *time.Duration
// HostAcceptanceMinWait specify a minimum wait time before selecting relay candidates
RelayAcceptanceMinWait *time.Duration
// StunGatherTimeout specify a minimum wait time for STUN responses
StunGatherTimeout *time.Duration
// Net is the our abstracted network interface for internal development purpose only
// (see https://github.com/pion/transport)
@@ -222,6 +227,12 @@ func (config *AgentConfig) initWithDefaults(a *Agent) {
a.relayAcceptanceMinWait = *config.RelayAcceptanceMinWait
}
if config.StunGatherTimeout == nil {
a.stunGatherTimeout = defaultStunGatherTimeout
} else {
a.stunGatherTimeout = *config.StunGatherTimeout
}
if config.TCPPriorityOffset == nil {
a.tcpPriorityOffset = defaultTCPPriorityOffset
} else {
+2 -7
View File
@@ -12,7 +12,6 @@ import (
"net/netip"
"reflect"
"sync"
"time"
"github.com/pion/dtls/v2"
"github.com/pion/ice/v3/internal/fakenet"
@@ -22,10 +21,6 @@ import (
"github.com/pion/turn/v3"
)
const (
stunGatherTimeout = time.Second * 5
)
// Close a net.Conn and log if we have a failure
func closeConnAndLog(c io.Closer, log logging.LeveledLogger, msg string, args ...interface{}) {
if c == nil || (reflect.ValueOf(c).Kind() == reflect.Ptr && reflect.ValueOf(c).IsNil()) {
@@ -479,7 +474,7 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*stun.UR
return
}
xorAddr, err := a.udpMuxSrflx.GetXORMappedAddr(serverAddr, stunGatherTimeout)
xorAddr, err := a.udpMuxSrflx.GetXORMappedAddr(serverAddr, a.stunGatherTimeout)
if err != nil {
a.log.Warnf("Failed get server reflexive address %s %s: %v", network, url, err)
return
@@ -564,7 +559,7 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*stun.URI, net
}
}()
xorAddr, err := stunx.GetXORMappedAddr(conn, serverAddr, stunGatherTimeout)
xorAddr, err := stunx.GetXORMappedAddr(conn, serverAddr, a.stunGatherTimeout)
if err != nil {
closeConnAndLog(conn, a.log, "failed to get server reflexive address %s %s: %v", network, url, err)
return