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
3b6d6112
Commit
3b6d6112
authored
Jul 24, 2017
by
vyzo
Browse files
basic_host: integrate circuit relay as a transport with an option
parent
77af18a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
3b6d6112
...
...
@@ -9,6 +9,7 @@ import (
logging
"github.com/ipfs/go-log"
goprocess
"github.com/jbenet/goprocess"
circuit
"github.com/libp2p/go-libp2p-circuit"
connmgr
"github.com/libp2p/go-libp2p-connmgr"
metrics
"github.com/libp2p/go-libp2p-metrics"
mstream
"github.com/libp2p/go-libp2p-metrics/stream"
...
...
@@ -97,6 +98,12 @@ type HostOpts struct {
// ConnManager is a libp2p connection manager
ConnManager
connmgr
.
ConnManager
// Relay indicates whether the host should use circuit relay transport
Relay
bool
// RelayOpts are options for the relay transport; only meaningful when Relay=true
RelayOpts
[]
circuit
.
RelayOpt
}
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
...
...
@@ -143,10 +150,25 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
h
.
cmgr
=
opts
.
ConnManager
}
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
{
// perhaps inappropriate, but otherwise we have to change the interface
// to return an error, which will nost likely lead to a fatality anyway
panic
(
err
)
}
}
h
.
proc
=
goprocess
.
WithTeardown
(
func
()
error
{
if
h
.
natmgr
!=
nil
{
h
.
natmgr
.
Close
()
}
if
relayCancel
!=
nil
{
relayCancel
()
}
return
h
.
Network
()
.
Close
()
})
...
...
package.json
View file @
3b6d6112
...
...
@@ -268,6 +268,12 @@
"hash"
:
"QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB"
,
"name"
:
"go-libp2p-peer"
,
"version"
:
"2.2.0"
},
{
"author"
:
"vyzo"
,
"hash"
:
"QmP8i7FhM3jjciE34U9MZTnyD21BpxTinTzTcmVkvfM6tv"
,
"name"
:
"go-libp2p-circuit"
,
"version"
:
"1.0.0"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
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