diff --git a/p2p/test/basichost/basic_host_test.go b/p2p/test/basichost/basic_host_test.go index 870a882358..0197387b1b 100644 --- a/p2p/test/basichost/basic_host_test.go +++ b/p2p/test/basichost/basic_host_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strings" - "sync" "testing" "time" @@ -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() @@ -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() diff --git a/p2p/transport/webrtc/listener.go b/p2p/transport/webrtc/listener.go index c3e2f29799..2d92b41911 100644 --- a/p2p/transport/webrtc/listener.go +++ b/p2p/transport/webrtc/listener.go @@ -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 { @@ -126,7 +126,7 @@ func (l *listener) listen() { } return } - + fmt.Println("pending handshakes", len(inFlightSemaphore)) go func() { defer func() { <-inFlightSemaphore }() diff --git a/p2p/transport/webrtc/transport.go b/p2p/transport/webrtc/transport.go index c4c16fd402..f51ff1d8ae 100644 --- a/p2p/transport/webrtc/transport.go +++ b/p2p/transport/webrtc/transport.go @@ -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