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
3b2f4641
Commit
3b2f4641
authored
Jul 22, 2017
by
vyzo
Browse files
RoutedHost: use Connect directly in NewStream
parent
daaf97b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/host/routed/routed.go
View file @
3b2f4641
...
...
@@ -128,13 +128,12 @@ func (rh *RoutedHost) RemoveStreamHandler(pid protocol.ID) {
}
func
(
rh
*
RoutedHost
)
NewStream
(
ctx
context
.
Context
,
p
peer
.
ID
,
pids
...
protocol
.
ID
)
(
inet
.
Stream
,
error
)
{
// check if we need to find some addresses for the peer through the routing system
if
len
(
rh
.
Network
()
.
ConnsToPeer
(
p
))
==
0
&&
len
(
rh
.
Peerstore
()
.
Addrs
(
p
))
==
0
{
addrs
,
err
:=
rh
.
findPeerAddrs
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
rh
.
Peerstore
()
.
AddAddrs
(
p
,
addrs
,
pstore
.
TempAddrTTL
)
// Ensure we have a connection, with peer addresses resolved by the routing system (#207)
// It is not sufficient to let the underlying host connect, it will most likely not have
// any addresses for the peer without any prior connections.
err
:=
rh
.
Connect
(
ctx
,
pstore
.
PeerInfo
{
ID
:
p
})
if
err
!=
nil
{
return
nil
,
err
}
return
rh
.
host
.
NewStream
(
ctx
,
p
,
pids
...
)
...
...
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