Skip to content

Commit

Permalink
basic_host: take base context as parameter in NewHost
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Aug 2, 2017
1 parent fd23cf6 commit 6be81d3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -167,7 +167,7 @@ func NewHost(net inet.Network, opts *HostOpts) (*BasicHost, error) {
net.SetStreamHandler(h.newStreamHandler)

if opts.EnableRelay {
relayCtx, relayCancel = context.WithCancel(context.Background())
relayCtx, relayCancel = context.WithCancel(ctx)
err := circuit.AddRelayTransport(relayCtx, h, opts.RelayOpts...)
if err != nil {
h.Close()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/mock/mock_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6be81d3

Please sign in to comment.