mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Configure Agent only via AgentConfig
Update GatherCandidates to not accept any arguments, it pulls everything from AgentConfig instead Relates to #51
This commit is contained in:
@@ -103,6 +103,9 @@ type Agent struct {
|
||||
selectedPair *candidatePair
|
||||
validPairs candidatePairs
|
||||
|
||||
urls []*URL
|
||||
networkTypes []NetworkType
|
||||
|
||||
buffer *packetio.Buffer
|
||||
|
||||
// LRU of outbound Binding request Transaction IDs
|
||||
@@ -188,6 +191,8 @@ func NewAgent(config *AgentConfig) (*Agent, error) {
|
||||
localCandidates: make(map[NetworkType][]Candidate),
|
||||
remoteCandidates: make(map[NetworkType][]Candidate),
|
||||
pendingBindingRequests: make([]bindingRequest, 0, maxPendingBindingRequests),
|
||||
urls: config.Urls,
|
||||
networkTypes: config.NetworkTypes,
|
||||
|
||||
localUfrag: randSeq(16),
|
||||
localPwd: randSeq(32),
|
||||
@@ -232,7 +237,7 @@ func NewAgent(config *AgentConfig) (*Agent, error) {
|
||||
|
||||
// Initialize local candidates
|
||||
if !a.trickle {
|
||||
a.gatherCandidates(config)
|
||||
a.gatherCandidates()
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -541,7 +541,7 @@ func TestConnectionStateCallback(t *testing.T) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = aAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = aAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -558,7 +558,7 @@ func TestConnectionStateCallback(t *testing.T) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = bAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = bAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -91,24 +91,20 @@ func listenUDP(portMax, portMin int, network string, laddr *net.UDPAddr) (*net.U
|
||||
}
|
||||
|
||||
// GatherCandidates initiates the trickle based gathering process.
|
||||
func (a *Agent) GatherCandidates(urls []*URL, networkTypes []NetworkType) error {
|
||||
return a.run(func(agent *Agent) {
|
||||
func (a *Agent) GatherCandidates() error {
|
||||
if a.gatheringState == GatheringStateGathering {
|
||||
a.log.Warnf("Attempting to gather candidates during gathering state\n")
|
||||
return
|
||||
}
|
||||
|
||||
go a.gatherCandidates(&AgentConfig{
|
||||
Urls: urls,
|
||||
NetworkTypes: networkTypes,
|
||||
})
|
||||
go a.gatherCandidates()
|
||||
})
|
||||
}
|
||||
|
||||
func (a *Agent) gatherCandidates(config *AgentConfig) {
|
||||
func (a *Agent) gatherCandidates() {
|
||||
a.gatheringState = GatheringStateGathering
|
||||
a.gatherCandidatesLocal(config.NetworkTypes)
|
||||
a.gatherCandidatesSrflx(config.Urls, config.NetworkTypes)
|
||||
a.gatherCandidatesLocal(a.networkTypes)
|
||||
a.gatherCandidatesSrflx(a.urls, a.networkTypes)
|
||||
if err := a.run(func(agent *Agent) {
|
||||
if a.onCandidateHdlr != nil {
|
||||
go a.onCandidateHdlr(nil)
|
||||
|
||||
+4
-4
@@ -222,7 +222,7 @@ func pipe() (*Conn, *Conn) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = aAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = aAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func pipe() (*Conn, *Conn) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = bAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = bAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func pipeWithTimeout(iceTimeout time.Duration, iceKeepalive time.Duration) (*Con
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = aAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = aAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func pipeWithTimeout(iceTimeout time.Duration, iceKeepalive time.Duration) (*Con
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = bAgent.GatherCandidates(cfg.Urls, cfg.NetworkTypes)
|
||||
err = bAgent.GatherCandidates()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user