4
4
"bytes"
5
5
"context"
6
6
"crypto/rand"
7
+ "crypto/sha256"
7
8
"io"
8
9
"sync"
9
10
"time"
@@ -311,15 +312,22 @@ func (c *Conn) negotiate() {
311
312
c .pendingCandidatesMutex .Lock ()
312
313
defer c .pendingCandidatesMutex .Unlock ()
313
314
for _ , pendingCandidate := range c .pendingRemoteCandidates {
314
- c .opts .Logger .Debug (context .Background (), "flushing remote candidate" )
315
+ hash := sha256 .Sum224 ([]byte (pendingCandidate .Candidate ))
316
+ c .opts .Logger .Debug (context .Background (), "flushing buffered remote candidate" ,
317
+ slog .F ("hash" , hash ),
318
+ slog .F ("length" , len (pendingCandidate .Candidate )),
319
+ )
315
320
err := c .rtc .AddICECandidate (pendingCandidate )
316
321
if err != nil {
317
- _ = c .CloseWithError (xerrors .Errorf ("flush pending candidates : %w" , err ))
322
+ _ = c .CloseWithError (xerrors .Errorf ("flush pending remote candidate : %w" , err ))
318
323
return
319
324
}
320
325
}
326
+ c .opts .Logger .Debug (context .Background (), "flushed buffered remote candidates" ,
327
+ slog .F ("count" , len (c .pendingRemoteCandidates )),
328
+ )
321
329
c .pendingCandidatesFlushed = true
322
- c .opts . Logger . Debug ( context . Background (), "flushed remote candidates" )
330
+ c .pendingRemoteCandidates = make ([]webrtc. ICECandidateInit , 0 )
323
331
}
324
332
325
333
// LocalCandidate returns a channel that emits when a local candidate
@@ -332,12 +340,16 @@ func (c *Conn) LocalCandidate() <-chan webrtc.ICECandidateInit {
332
340
func (c * Conn ) AddRemoteCandidate (i webrtc.ICECandidateInit ) error {
333
341
c .pendingCandidatesMutex .Lock ()
334
342
defer c .pendingCandidatesMutex .Unlock ()
343
+ fields := []slog.Field {
344
+ slog .F ("hash" , sha256 .Sum224 ([]byte (i .Candidate ))),
345
+ slog .F ("length" , len (i .Candidate )),
346
+ }
335
347
if ! c .pendingCandidatesFlushed {
336
- c .opts .Logger .Debug (context .Background (), "adding remote candidate to buffer" )
348
+ c .opts .Logger .Debug (context .Background (), "bufferring remote candidate" , fields ... )
337
349
c .pendingRemoteCandidates = append (c .pendingRemoteCandidates , i )
338
350
return nil
339
351
}
340
- c .opts .Logger .Debug (context .Background (), "adding remote candidate" )
352
+ c .opts .Logger .Debug (context .Background (), "adding remote candidate" , fields ... )
341
353
return c .rtc .AddICECandidate (i )
342
354
}
343
355
0 commit comments