Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
2f5a29e6
Unverified
Commit
2f5a29e6
authored
Oct 18, 2018
by
vyzo
Committed by
GitHub
Oct 18, 2018
Browse files
Merge pull request #449 from libp2p/fix/issue-448
fix relay-specific address dialing in routed host
parents
0126c421
1536433f
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/host/routed/routed.go
View file @
2f5a29e6
...
...
@@ -8,6 +8,7 @@ import (
host
"github.com/libp2p/go-libp2p-host"
logging
"github.com/ipfs/go-log"
circuit
"github.com/libp2p/go-libp2p-circuit"
ifconnmgr
"github.com/libp2p/go-libp2p-interface-connmgr"
lgbl
"github.com/libp2p/go-libp2p-loggables"
inet
"github.com/libp2p/go-libp2p-net"
...
...
@@ -67,6 +68,43 @@ func (rh *RoutedHost) Connect(ctx context.Context, pi pstore.PeerInfo) error {
}
}
// Issue 448: if our address set includes routed specific relay addrs,
// we need to make sure the relay's addr itself is in the peerstore or else
// we wont be able to dial it.
for
_
,
addr
:=
range
addrs
{
_
,
err
:=
addr
.
ValueForProtocol
(
circuit
.
P_CIRCUIT
)
if
err
!=
nil
{
// not a relay address
continue
}
if
addr
.
Protocols
()[
0
]
.
Code
!=
ma
.
P_P2P
{
// not a routed relay specific address
continue
}
relay
,
_
:=
addr
.
ValueForProtocol
(
ma
.
P_P2P
)
relayID
,
err
:=
peer
.
IDFromString
(
relay
)
if
err
!=
nil
{
log
.
Debugf
(
"failed to parse relay ID in address %s: %s"
,
relay
,
err
)
continue
}
if
len
(
rh
.
Peerstore
()
.
Addrs
(
relayID
))
>
0
{
// we already have addrs for this relay
continue
}
relayAddrs
,
err
:=
rh
.
findPeerAddrs
(
ctx
,
relayID
)
if
err
!=
nil
{
log
.
Debugf
(
"failed to find relay %s: %s"
,
relay
,
err
)
continue
}
rh
.
Peerstore
()
.
AddAddrs
(
relayID
,
relayAddrs
,
pstore
.
TempAddrTTL
)
}
// if we're here, we got some addrs. let's use our wrapped host to connect.
pi
.
Addrs
=
addrs
return
rh
.
host
.
Connect
(
ctx
,
pi
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment