From 6be81d34c1016ec8b2ac9143893a1908ae997c08 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 2 Aug 2017 11:04:59 +0300 Subject: [PATCH] basic_host: take base context as parameter in NewHost --- p2p/host/basic/basic_host.go | 6 +++--- p2p/net/mock/mock_net.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index dde575b..a7992d0 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -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(context.Background()) + relayCtx, relayCancel = context.WithCancel(ctx) 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 diff --git a/p2p/net/mock/mock_net.go b/p2p/net/mock/mock_net.go index b670c8f..898292a 100644 --- a/p2p/net/mock/mock_net.go +++ b/p2p/net/mock/mock_net.go @@ -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 } -- GitLab