From 27bbad143309359a33f01448078a5393bd07c9d6 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 26 Nov 2024 05:19:47 -0800 Subject: [PATCH] fix(swarm): check after we split for empty multiaddr (#3063) --- p2p/net/swarm/swarm_transport.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/p2p/net/swarm/swarm_transport.go b/p2p/net/swarm/swarm_transport.go index 28324c27f2..3aaa335cbc 100644 --- a/p2p/net/swarm/swarm_transport.go +++ b/p2p/net/swarm/swarm_transport.go @@ -13,6 +13,9 @@ import ( // TransportForDialing retrieves the appropriate transport for dialing the given // multiaddr. func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport { + if a == nil { + return nil + } protocols := a.Protocols() if len(protocols) == 0 { return nil @@ -34,6 +37,9 @@ func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport { if id, _ := peer.IDFromP2PAddr(a); id != "" { // This addr has a p2p component. Drop it so we can check transport. a, _ = ma.SplitLast(a) + if a == nil { + return nil + } } for _, t := range s.transports.m { if t.CanDial(a) {