From 73ce477e348138e80b9865cc344834bccc21c210 Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 19 Jun 2024 16:01:11 +0530 Subject: [PATCH] libp2p: use rcmgr for autonat dials --- config/config.go | 1 + p2p/transport/webrtc/transport_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/config/config.go b/config/config.go index cc689baf7b..c1a29057d3 100644 --- a/config/config.go +++ b/config/config.go @@ -487,6 +487,7 @@ func (cfg *Config) addAutoNAT(h *bhost.BasicHost) error { PeerKey: autonatPrivKey, Peerstore: ps, DialRanker: swarm.NoDelayDialRanker, + ResourceManager: cfg.ResourceManager, SwarmOpts: []swarm.Option{ // It is better to disable black hole detection and just attempt a dial for autonat swarm.WithUDPBlackHoleConfig(false, 0, 0), diff --git a/p2p/transport/webrtc/transport_test.go b/p2p/transport/webrtc/transport_test.go index b618ec85df..48d7dd3eb0 100644 --- a/p2p/transport/webrtc/transport_test.go +++ b/p2p/transport/webrtc/transport_test.go @@ -42,6 +42,27 @@ func getTransport(t *testing.T, opts ...Option) (*WebRTCTransport, peer.ID) { return transport, peerID } +func TestNullRcmgrTransport(t *testing.T) { + privKey, _, err := crypto.GenerateKeyPair(crypto.Ed25519, -1) + require.NoError(t, err) + transport, err := New(privKey, nil, nil, nil) + require.NoError(t, err) + + listenTransport, pid := getTransport(t) + ln, err := listenTransport.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct")) + require.NoError(t, err) + go func() { + c, err := ln.Accept() + if !assert.NoError(t, err) { + t.Error(err) + } + c.Close() + }() + c, err := transport.Dial(context.Background(), ln.Multiaddr(), pid) + require.NoError(t, err) + c.Close() +} + func TestIsWebRTCDirectMultiaddr(t *testing.T) { invalid := []string{ "/ip4/1.2.3.4/tcp/10/",