Skip to content

Commit

Permalink
add log for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Dec 5, 2024
1 parent 35c4bdb commit 427770a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
25 changes: 8 additions & 17 deletions p2p/test/basichost/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -235,6 +234,7 @@ func TestWebRTCWithQUICManyConnections(t *testing.T) {
libp2p.Transport(libp2pwebrtc.New),
libp2p.ListenAddrStrings("/ip4/0.0.0.0/udp/0/quic-v1"),
libp2p.ListenAddrStrings("/ip4/0.0.0.0/udp/0/webrtc-direct"),
libp2p.ResourceManager(&network.NullResourceManager{}),
)
require.NoError(t, err)
defer h.Close()
Expand All @@ -252,24 +252,15 @@ func TestWebRTCWithQUICManyConnections(t *testing.T) {
require.NoError(t, err)
defer d.Close()

startDial := make(chan struct{})
var wg sync.WaitGroup
wg.Add(N)
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
<-startDial
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// With happy eyeballs these dialers will connect over only /quic-v1
// and not stall the /webrtc-direct handshake goroutines.
// it is fine if the dial fails, we just want to ensure that there's space
// in the /webrtc-direct listen queue
_ = dialers[i].Connect(ctx, peer.AddrInfo{ID: h.ID(), Addrs: h.Addrs()})
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// With happy eyeballs these dialers will connect over only /quic-v1
// and not stall the /webrtc-direct handshake goroutines.
// it is fine if the dial fails, we just want to ensure that there's space
// in the /webrtc-direct listen queue
_ = dialers[i].Connect(ctx, peer.AddrInfo{ID: h.ID(), Addrs: h.Addrs()})
}
close(startDial)
wg.Wait()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions p2p/transport/webrtc/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
// sending the initial connection request message(STUN Binding request). Such peers take up a goroutine
// till connection timeout. As the number of handshakes in parallel is still guarded by the resource
// manager, this higher number is okay.
DefaultMaxInFlightConnections = 128
DefaultMaxInFlightConnections = 10
)

type listener struct {
Expand Down Expand Up @@ -126,7 +126,7 @@ func (l *listener) listen() {
}
return
}

fmt.Println("pending handshakes", len(inFlightSemaphore))
go func() {
defer func() { <-inFlightSemaphore }()

Expand Down
2 changes: 2 additions & 0 deletions p2p/transport/webrtc/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ func (t *WebRTCTransport) dial(ctx context.Context, scope network.ConnManagement
return nil, fmt.Errorf("resolve udp address: %w", err)
}

fmt.Println("dialing", remoteMultiaddr)

// Instead of encoding the local fingerprint we
// generate a random UUID as the connection ufrag.
// The only requirement here is that the ufrag and password
Expand Down

0 comments on commit 427770a

Please sign in to comment.