Skip to content

Commit

Permalink
- add candidate manually for active tcp agent
Browse files Browse the repository at this point in the history
- do not start candidate in addCandidate for active tcp (it is started in addPair)
  • Loading branch information
ashellunts committed Feb 4, 2023
1 parent 9e9f7f1 commit 278b539
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
4 changes: 3 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net
}
}

c.start(a, candidateConn, a.startedCh)
if !a.activeTCP {
c.start(a, candidateConn, a.startedCh)
}

set = append(set, c)
a.localCandidates[c.NetworkType()] = set
Expand Down
44 changes: 32 additions & 12 deletions gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,53 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
}
}

for _, connAndPort := range conns {
if a.activeTCP {
hostConfig := CandidateHostConfig{
Network: network,
Address: address,
Port: connAndPort.port,
Port: 0,
Component: ComponentRTP,
TCPType: tcpType,
}

c, err := NewCandidateHost(&hostConfig)
if err != nil {
closeConnAndLog(connAndPort.conn, a.log, fmt.Sprintf("Failed to create host candidate: %s %s %d: %v", network, mappedIP, connAndPort.port, err))
continue
panic(1)
}
if err := a.addCandidate(ctx, c, nil); err != nil {
if closeErr := c.close(); closeErr != nil {
a.log.Warnf("Failed to close candidate: %v", closeErr)
}
panic(2)
}
} else {
for _, connAndPort := range conns {
hostConfig := CandidateHostConfig{
Network: network,
Address: address,
Port: connAndPort.port,
Component: ComponentRTP,
TCPType: tcpType,
}

if a.mDNSMode == MulticastDNSModeQueryAndGather {
if err = c.setIP(ip); err != nil {
c, err := NewCandidateHost(&hostConfig)
if err != nil {
closeConnAndLog(connAndPort.conn, a.log, fmt.Sprintf("Failed to create host candidate: %s %s %d: %v", network, mappedIP, connAndPort.port, err))
continue
}
}

if err := a.addCandidate(ctx, c, connAndPort.conn); err != nil {
if closeErr := c.close(); closeErr != nil {
a.log.Warnf("Failed to close candidate: %v", closeErr)
if a.mDNSMode == MulticastDNSModeQueryAndGather {
if err = c.setIP(ip); err != nil {
closeConnAndLog(connAndPort.conn, a.log, fmt.Sprintf("Failed to create host candidate: %s %s %d: %v", network, mappedIP, connAndPort.port, err))
continue
}
}

if err := a.addCandidate(ctx, c, connAndPort.conn); err != nil {
if closeErr := c.close(); closeErr != nil {
a.log.Warnf("Failed to close candidate: %v", closeErr)
}
a.log.Warnf("Failed to append to localCandidates and run onCandidateHdlr: %v", err)
}
a.log.Warnf("Failed to append to localCandidates and run onCandidateHdlr: %v", err)
}
}
}
Expand Down

0 comments on commit 278b539

Please sign in to comment.