From 94972be20a547e97e87c507d459a08035fdaf76c Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Mon, 25 Nov 2024 12:07:27 -0800 Subject: [PATCH] fix: check after we split for empty multiaddr --- 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) {