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
6be81d34
Commit
6be81d34
authored
Aug 02, 2017
by
vyzo
Browse files
basic_host: take base context as parameter in NewHost
parent
fd23cf6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
6be81d34
...
...
@@ -107,7 +107,7 @@ type HostOpts struct {
}
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func
NewHost
(
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
func
NewHost
(
ctx
context
.
Context
,
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
...
...
@@ -167,7 +167,7 @@ func NewHost(net inet.Network, opts *HostOpts) (*BasicHost, error) {
net
.
SetStreamHandler
(
h
.
newStreamHandler
)
if
opts
.
EnableRelay
{
relayCtx
,
relayCancel
=
context
.
WithCancel
(
c
ontext
.
Background
()
)
relayCtx
,
relayCancel
=
context
.
WithCancel
(
c
tx
)
err
:=
circuit
.
AddRelayTransport
(
relayCtx
,
h
,
opts
.
RelayOpts
...
)
if
err
!=
nil
{
h
.
Close
()
...
...
@@ -200,7 +200,7 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
}
h
,
err
:=
NewHost
(
net
,
hostopts
)
h
,
err
:=
NewHost
(
context
.
Background
(),
net
,
hostopts
)
if
err
!=
nil
{
// this cannot happen with legacy options
// plus we want to keep the (deprecated) legacy interface unchanged
...
...
p2p/net/mock/mock_net.go
View file @
6be81d34
...
...
@@ -88,7 +88,7 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
NegotiationTimeout
:
-
1
,
}
h
,
err
:=
bhost
.
NewHost
(
n
,
opts
)
h
,
err
:=
bhost
.
NewHost
(
mn
.
ctx
,
n
,
opts
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
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