Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
fd23cf6f
Commit
fd23cf6f
authored
Aug 02, 2017
by
vyzo
Browse files
basic_host: add the relay after the host construction is complete
parent
b97f1c5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
fd23cf6f
...
...
@@ -100,7 +100,7 @@ type HostOpts struct {
ConnManager
connmgr
.
ConnManager
// Relay indicates whether the host should use circuit relay transport
Relay
bool
Enable
Relay
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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment