@@ -163,14 +163,14 @@ func (a *Agent) gatherCandidatesLocal() {
163
163
for _ , network := range supportedNetworks {
164
164
conn , err := a .listenUDP (network , & net.UDPAddr {IP : ip , Port : 0 })
165
165
if err != nil {
166
- fmt . Printf ("could not listen %s %s\n " , network , ip )
166
+ iceLog . Warningf ("could not listen %s %s\n " , network , ip )
167
167
continue
168
168
}
169
169
170
170
port := conn .LocalAddr ().(* net.UDPAddr ).Port
171
171
c , err := NewCandidateHost (network , ip , port )
172
172
if err != nil {
173
- fmt . Printf ("Failed to create host candidate: %s %s %d: %v\n " , network , ip , port , err )
173
+ iceLog . Warningf ("Failed to create host candidate: %s %s %d: %v\n " , network , ip , port , err )
174
174
continue
175
175
}
176
176
@@ -192,12 +192,12 @@ func (a *Agent) gatherCandidatesReflective(urls []*URL) {
192
192
case SchemeTypeSTUN :
193
193
laddr , xoraddr , err := allocateUDP (network , url )
194
194
if err != nil {
195
- fmt . Printf ("could not allocate %s %s: %v\n " , network , url , err )
195
+ iceLog . Warningf ("could not allocate %s %s: %v\n " , network , url , err )
196
196
continue
197
197
}
198
198
conn , err := net .ListenUDP (network , laddr )
199
199
if err != nil {
200
- fmt . Printf ("could not listen %s %s: %v\n " , network , laddr , err )
200
+ iceLog . Warningf ("could not listen %s %s: %v\n " , network , laddr , err )
201
201
}
202
202
203
203
ip := xoraddr .IP
@@ -206,7 +206,7 @@ func (a *Agent) gatherCandidatesReflective(urls []*URL) {
206
206
relPort := laddr .Port
207
207
c , err := NewCandidateServerReflexive (network , ip , port , relIP , relPort )
208
208
if err != nil {
209
- fmt . Printf ("Failed to create server reflexive candidate: %s %s %d: %v\n " , network , ip , port , err )
209
+ iceLog . Warningf ("Failed to create server reflexive candidate: %s %s %d: %v\n " , network , ip , port , err )
210
210
continue
211
211
}
212
212
@@ -218,7 +218,7 @@ func (a *Agent) gatherCandidatesReflective(urls []*URL) {
218
218
c .start (a , conn )
219
219
220
220
default :
221
- fmt . Printf ("scheme %s is not implemented\n " , url .Scheme . String () )
221
+ iceLog . Warningf ("scheme %s is not implemented\n " , url .Scheme )
222
222
continue
223
223
}
224
224
}
@@ -266,6 +266,7 @@ func (a *Agent) startConnectivityChecks(isControlling bool, remoteUfrag, remoteP
266
266
} else if remotePwd == "" {
267
267
return errors .Errorf ("remotePwd is empty" )
268
268
}
269
+ iceLog .Debugf ("Started agent: isControlling? %t, remoteUfrag: %q, remotePwd: %q" , isControlling , remoteUfrag , remotePwd )
269
270
270
271
return a .run (func (agent * Agent ) {
271
272
agent .isControlling = isControlling
@@ -314,7 +315,7 @@ func (a *Agent) pingCandidate(local, remote *Candidate) {
314
315
}
315
316
316
317
if err != nil {
317
- fmt . Println (err )
318
+ iceLog . Debug (err . Error () )
318
319
return
319
320
}
320
321
@@ -335,6 +336,7 @@ func (a *Agent) updateConnectionState(newState ConnectionState) {
335
336
func (a * Agent ) setValidPair (local , remote * Candidate , selected bool ) {
336
337
// TODO: avoid duplicates
337
338
p := newCandidatePair (local , remote )
339
+ iceLog .Debugf ("Found valid candidate pair: %s <-> %s (selected? %t)" , local , remote , selected )
338
340
339
341
if selected {
340
342
a .selectedPair = p
@@ -374,8 +376,10 @@ func (a *Agent) taskLoop() {
374
376
select {
375
377
case <- a .connectivityChan :
376
378
if a .validateSelectedPair () {
379
+ iceLog .Trace ("checking keepalive" )
377
380
a .checkKeepalive ()
378
381
} else {
382
+ iceLog .Trace ("pinging all candidates" )
379
383
a .pingAllCandidates ()
380
384
}
381
385
@@ -490,7 +494,7 @@ func (a *Agent) Close() error {
490
494
for _ , c := range cs {
491
495
err := c .close ()
492
496
if err != nil {
493
- fmt . Printf ("Failed to close candidate %s: %v" , c , err )
497
+ iceLog . Warningf ("Failed to close candidate %s: %v" , c , err )
494
498
}
495
499
}
496
500
delete (agent .localCandidates , net )
@@ -499,7 +503,7 @@ func (a *Agent) Close() error {
499
503
for _ , c := range cs {
500
504
err := c .close ()
501
505
if err != nil {
502
- fmt . Printf ("Failed to close candidate %s: %v" , c , err )
506
+ iceLog . Warningf ("Failed to close candidate %s: %v" , c , err )
503
507
}
504
508
}
505
509
delete (agent .remoteCandidates , net )
@@ -526,7 +530,7 @@ func (a *Agent) findRemoteCandidate(networkType NetworkType, addr net.Addr) *Can
526
530
ip = a .IP
527
531
port = a .Port
528
532
default :
529
- fmt . Printf ("unsupported address type %T" , a )
533
+ iceLog . Warningf ("unsupported address type %T" , a )
530
534
return nil
531
535
}
532
536
@@ -555,20 +559,21 @@ func (a *Agent) sendBindingSuccess(m *stun.Message, local, remote *Candidate) {
555
559
},
556
560
& stun.Fingerprint {},
557
561
); err != nil {
558
- fmt . Printf ("Failed to handle inbound ICE from: %s to: %s error: %s" , local . String () , remote . String () , err . Error () )
562
+ iceLog . Warningf ("Failed to handle inbound ICE from: %s to: %s error: %s" , local , remote , err )
559
563
} else {
560
564
a .sendSTUN (out , local , remote )
561
565
}
562
566
}
563
567
564
568
func (a * Agent ) handleInboundControlled (m * stun.Message , localCandidate , remoteCandidate * Candidate ) {
565
569
if _ , isControlled := m .GetOneAttribute (stun .AttrIceControlled ); isControlled && ! a .isControlling {
566
- fmt . Println ("inbound isControlled && a.isControlling == false" )
570
+ iceLog . Debug ("inbound isControlled && a.isControlling == false" )
567
571
return
568
572
}
569
573
570
574
successResponse := m .Method == stun .MethodBinding && m .Class == stun .ClassSuccessResponse
571
575
_ , usepair := m .GetOneAttribute (stun .AttrUseCandidate )
576
+ iceLog .Debugf ("got controlled message (success? %t, usepair? %t)" , successResponse , usepair )
572
577
// Remember the working pair and select it when marked with usepair
573
578
a .setValidPair (localCandidate , remoteCandidate , usepair )
574
579
@@ -580,12 +585,13 @@ func (a *Agent) handleInboundControlled(m *stun.Message, localCandidate, remoteC
580
585
581
586
func (a * Agent ) handleInboundControlling (m * stun.Message , localCandidate , remoteCandidate * Candidate ) {
582
587
if _ , isControlling := m .GetOneAttribute (stun .AttrIceControlling ); isControlling && a .isControlling {
583
- fmt . Println ("inbound isControlling && a.isControlling == true" )
588
+ iceLog . Debug ("inbound isControlling && a.isControlling == true" )
584
589
return
585
590
} else if _ , useCandidate := m .GetOneAttribute (stun .AttrUseCandidate ); useCandidate && a .isControlling {
586
- fmt . Println ("useCandidate && a.isControlling == true" )
591
+ iceLog . Debug ("useCandidate && a.isControlling == true" )
587
592
return
588
593
}
594
+ iceLog .Debugf ("got controlling message: %#v" , m )
589
595
590
596
successResponse := m .Method == stun .MethodBinding && m .Class == stun .ClassSuccessResponse
591
597
// Remember the working pair and select it when receiving a success response
@@ -604,8 +610,7 @@ func (a *Agent) handleInboundControlling(m *stun.Message, localCandidate, remote
604
610
func (a * Agent ) handleInbound (m * stun.Message , local * Candidate , remote net.Addr ) {
605
611
remoteCandidate := a .findRemoteCandidate (local .NetworkType , remote )
606
612
if remoteCandidate == nil {
607
- // TODO debug
608
- // fmt.Printf("Could not find remote candidate for %s:%d ", remote.IP.String(), remote.Port)
613
+ iceLog .Debugf ("Could not find remote candidate for %s " , remote )
609
614
return
610
615
}
611
616
0 commit comments