@@ -165,44 +165,49 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
165165
166166 switch network {
167167 case tcp :
168- if a .tcpMux == nil {
169- continue
170- }
171-
172- // Handle ICE TCP passive mode
173- var muxConns []net.PacketConn
174- if multi , ok := a .tcpMux .(AllConnsGetter ); ok {
175- a .log .Debugf ("GetAllConns by ufrag: %s" , a .localUfrag )
176- muxConns , err = multi .GetAllConns (a .localUfrag , mappedIP .To4 () == nil , ip )
177- if err != nil {
178- a .log .Warnf ("Failed to get all TCP connections by ufrag: %s %s %s" , network , ip , a .localUfrag )
179- continue
180- }
168+ if a .ActiveTCP {
169+ conns = append (conns , connAndPort {nil , 0 })
170+ tcpType = TCPTypeActive
181171 } else {
182- a .log .Debugf ("GetConn by ufrag: %s" , a .localUfrag )
183- conn , err := a .tcpMux .GetConnByUfrag (a .localUfrag , mappedIP .To4 () == nil , ip )
184- if err != nil {
185- a .log .Warnf ("Failed to get TCP connections by ufrag: %s %s %s" , network , ip , a .localUfrag )
172+ // Handle ICE TCP passive mode
173+ if a .tcpMux == nil {
186174 continue
187175 }
188- muxConns = []net.PacketConn {conn }
189- }
190176
191- // Extract the port for each PacketConn we got.
192- for _ , conn := range muxConns {
193- if tcpConn , ok := conn .LocalAddr ().(* net.TCPAddr ); ok {
194- conns = append (conns , connAndPort {conn , tcpConn .Port })
177+ var muxConns []net.PacketConn
178+ if multi , ok := a .tcpMux .(AllConnsGetter ); ok {
179+ a .log .Debugf ("GetAllConns by ufrag: %s" , a .localUfrag )
180+ muxConns , err = multi .GetAllConns (a .localUfrag , mappedIP .To4 () == nil , ip )
181+ if err != nil {
182+ a .log .Warnf ("Failed to get all TCP connections by ufrag: %s %s %s" , network , ip , a .localUfrag )
183+ continue
184+ }
195185 } else {
196- a .log .Warnf ("Failed to get port of connection from TCPMux: %s %s %s" , network , ip , a .localUfrag )
186+ a .log .Debugf ("GetConn by ufrag: %s" , a .localUfrag )
187+ conn , err := a .tcpMux .GetConnByUfrag (a .localUfrag , mappedIP .To4 () == nil , ip )
188+ if err != nil {
189+ a .log .Warnf ("Failed to get TCP connections by ufrag: %s %s %s" , network , ip , a .localUfrag )
190+ continue
191+ }
192+ muxConns = []net.PacketConn {conn }
197193 }
194+
195+ // Extract the port for each PacketConn we got.
196+ for _ , conn := range muxConns {
197+ if tcpConn , ok := conn .LocalAddr ().(* net.TCPAddr ); ok {
198+ conns = append (conns , connAndPort {conn , tcpConn .Port })
199+ } else {
200+ a .log .Warnf ("Failed to get port of connection from TCPMux: %s %s %s" , network , ip , a .localUfrag )
201+ }
202+ }
203+ if len (conns ) == 0 {
204+ // Didn't succeed with any, try the next network.
205+ continue
206+ }
207+ tcpType = TCPTypePassive
208+ // Is there a way to verify that the listen address is even
209+ // accessible from the current interface.
198210 }
199- if len (conns ) == 0 {
200- // Didn't succeed with any, try the next network.
201- continue
202- }
203- tcpType = TCPTypePassive
204- // Is there a way to verify that the listen address is even
205- // accessible from the current interface.
206211 case udp :
207212 conn , err := listenUDPInPortRange (a .net , a .log , int (a .portMax ), int (a .portMin ), network , & net.UDPAddr {IP : ip , Port : 0 })
208213 if err != nil {
0 commit comments