Skip to content

Commit 6fa87f6

Browse files
MarcoPolosukunrt
authored andcommitted
fix(swarm): check after we split for empty multiaddr (#3063)
1 parent 75538ef commit 6fa87f6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

p2p/net/swarm/swarm_transport.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
// TransportForDialing retrieves the appropriate transport for dialing the given
1414
// multiaddr.
1515
func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport {
16+
if a == nil {
17+
return nil
18+
}
1619
protocols := a.Protocols()
1720
if len(protocols) == 0 {
1821
return nil
@@ -34,6 +37,9 @@ func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport {
3437
if id, _ := peer.IDFromP2PAddr(a); id != "" {
3538
// This addr has a p2p component. Drop it so we can check transport.
3639
a, _ = ma.SplitLast(a)
40+
if a == nil {
41+
return nil
42+
}
3743
}
3844
for _, t := range s.transports.m {
3945
if t.CanDial(a) {

0 commit comments

Comments
 (0)