Commit 6be81d34 authored by vyzo's avatar vyzo
Browse files

basic_host: take base context as parameter in NewHost

parent fd23cf6f
......@@ -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
......
......@@ -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
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment