Skip to content

Commit

Permalink
Expose stunGatherTimeout in Agent struct (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrotolante committed Apr 3, 2024
1 parent a12f670 commit edaa25e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Agent struct {
srflxAcceptanceMinWait time.Duration
prflxAcceptanceMinWait time.Duration
relayAcceptanceMinWait time.Duration
stunGatherTimeout time.Duration

tcpPriorityOffset uint16
disableActiveTCP bool
Expand Down
11 changes: 11 additions & 0 deletions agent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/netip"
"reflect"
"sync"
"time"

"github.com/pion/dtls/v2"
"github.com/pion/ice/v3/internal/fakenet"
Expand All @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit edaa25e

Please sign in to comment.