Browse Source

basic_host: take base context as parameter in NewHost

pull/210/head
vyzo 7 years ago
parent
commit
6be81d34c1
  1. 6
      p2p/host/basic/basic_host.go
  2. 2
      p2p/net/mock/mock_net.go

6
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. // 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{ h := &BasicHost{
network: net, network: net,
mux: msmux.NewMultistreamMuxer(), mux: msmux.NewMultistreamMuxer(),
@ -167,7 +167,7 @@ func NewHost(net inet.Network, opts *HostOpts) (*BasicHost, error) {
net.SetStreamHandler(h.newStreamHandler) net.SetStreamHandler(h.newStreamHandler)
if opts.EnableRelay { if opts.EnableRelay {
relayCtx, relayCancel = context.WithCancel(context.Background()) relayCtx, relayCancel = context.WithCancel(ctx)
err := circuit.AddRelayTransport(relayCtx, h, opts.RelayOpts...) err := circuit.AddRelayTransport(relayCtx, h, opts.RelayOpts...)
if err != nil { if err != nil {
h.Close() 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 { if err != nil {
// this cannot happen with legacy options // this cannot happen with legacy options
// plus we want to keep the (deprecated) legacy interface unchanged // plus we want to keep the (deprecated) legacy interface unchanged

2
p2p/net/mock/mock_net.go

@ -88,7 +88,7 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
NegotiationTimeout: -1, NegotiationTimeout: -1,
} }
h, err := bhost.NewHost(n, opts) h, err := bhost.NewHost(mn.ctx, n, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save