Commit fd23cf6f authored by vyzo's avatar vyzo
Browse files

basic_host: add the relay after the host construction is complete

parent b97f1c5f
......@@ -100,7 +100,7 @@ type HostOpts struct {
ConnManager connmgr.ConnManager
// Relay indicates whether the host should use circuit relay transport
Relay bool
EnableRelay bool
// RelayOpts are options for the relay transport; only meaningful when Relay=true
RelayOpts []circuit.RelayOpt
......@@ -152,13 +152,6 @@ func NewHost(net inet.Network, opts *HostOpts) (*BasicHost, error) {
var relayCtx context.Context
var relayCancel func()
if opts.Relay {
relayCtx, relayCancel = context.WithCancel(context.Background())
err := circuit.AddRelayTransport(relayCtx, h, opts.RelayOpts...)
if err != nil {
return nil, err
}
}
h.proc = goprocess.WithTeardown(func() error {
if h.natmgr != nil {
......@@ -173,6 +166,15 @@ func NewHost(net inet.Network, opts *HostOpts) (*BasicHost, error) {
net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler)
if opts.EnableRelay {
relayCtx, relayCancel = context.WithCancel(context.Background())
err := circuit.AddRelayTransport(relayCtx, h, opts.RelayOpts...)
if err != nil {
h.Close()
return nil, err
}
}
return h, nil
}
......
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