From 0df12d6c627fbe2815c739480c0f22a14849653d Mon Sep 17 00:00:00 2001 From: sukun Date: Tue, 3 Dec 2024 23:21:29 +0530 Subject: [PATCH] add a basic host test that only webrtc dials aren't delayed --- p2p/net/swarm/dial_ranker_test.go | 7 +++++++ p2p/test/basichost/basic_host_test.go | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/p2p/net/swarm/dial_ranker_test.go b/p2p/net/swarm/dial_ranker_test.go index 81ceb28b82..f7a6172122 100644 --- a/p2p/net/swarm/dial_ranker_test.go +++ b/p2p/net/swarm/dial_ranker_test.go @@ -329,6 +329,13 @@ func TestDelayRankerOtherTransportDelay(t *testing.T) { {Addr: onion1, Delay: 2*PublicQUICDelay + 2*PublicOtherDelay}, }, }, + { + name: "only-non-ip-addr", + addrs: []ma.Multiaddr{onion1}, + output: []network.AddrDelay{ + {Addr: onion1, Delay: PublicOtherDelay}, + }, + }, } for _, tc := range testCase { t.Run(tc.name, func(t *testing.T) { diff --git a/p2p/test/basichost/basic_host_test.go b/p2p/test/basichost/basic_host_test.go index 9cd442dbf0..ca7018d588 100644 --- a/p2p/test/basichost/basic_host_test.go +++ b/p2p/test/basichost/basic_host_test.go @@ -11,6 +11,7 @@ import ( "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/libp2p/go-libp2p/p2p/net/swarm" "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay" libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" @@ -199,3 +200,25 @@ func TestAddrFactorCertHashAppend(t *testing.T) { return hasWebRTC && hasWebTransport }, 5*time.Second, 100*time.Millisecond) } + +func TestWebRTCDirectDialDelay(t *testing.T) { + // This tests that only webrtc-direct dials are dialled immediately + + h1, err := libp2p.New( + libp2p.Transport(libp2pwebrtc.New), + libp2p.ListenAddrStrings( + "/ip4/0.0.0.0/udp/0/webrtc-direct", + ), + ) + require.NoError(t, err) + h2, err := libp2p.New( + libp2p.Transport(libp2pwebrtc.New), + libp2p.NoListenAddrs, + ) + require.NoError(t, err) + + ctx, cancel := context.WithTimeout(context.Background(), swarm.PrivateOtherDelay) + defer cancel() + err = h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: h1.Addrs()}) + require.NoError(t, err) +}