Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
e44e538a
Commit
e44e538a
authored
7 years ago
by
vyzo
Committed by
GitHub
7 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #210 from libp2p/feat/circuit-relay
Circuit Relay integration with basic_host
parents
77af18a9
6be81d34
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
p2p/host/basic/basic_host.go
+32
-3
p2p/host/basic/basic_host.go
p2p/net/mock/mock_net.go
+5
-1
p2p/net/mock/mock_net.go
package.json
+6
-0
package.json
with
43 additions
and
4 deletions
+43
-4
p2p/host/basic/basic_host.go
View file @
e44e538a
...
...
@@ -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,10 +98,16 @@ type HostOpts struct {
// ConnManager is a libp2p connection manager
ConnManager
connmgr
.
ConnManager
// Relay indicates whether the host should use circuit relay transport
EnableRelay
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.
func
NewHost
(
net
inet
.
Network
,
opts
*
HostOpts
)
*
BasicHost
{
func
NewHost
(
ctx
context
.
Context
,
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
...
...
@@ -143,17 +150,32 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
h
.
cmgr
=
opts
.
ConnManager
}
var
relayCtx
context
.
Context
var
relayCancel
func
()
h
.
proc
=
goprocess
.
WithTeardown
(
func
()
error
{
if
h
.
natmgr
!=
nil
{
h
.
natmgr
.
Close
()
}
if
relayCancel
!=
nil
{
relayCancel
()
}
return
h
.
Network
()
.
Close
()
})
net
.
SetConnHandler
(
h
.
newConnHandler
)
net
.
SetStreamHandler
(
h
.
newStreamHandler
)
return
h
if
opts
.
EnableRelay
{
relayCtx
,
relayCancel
=
context
.
WithCancel
(
ctx
)
err
:=
circuit
.
AddRelayTransport
(
relayCtx
,
h
,
opts
.
RelayOpts
...
)
if
err
!=
nil
{
h
.
Close
()
return
nil
,
err
}
}
return
h
,
nil
}
// New constructs and sets up a new *BasicHost with given Network and options.
...
...
@@ -178,7 +200,14 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
}
return
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
panic
(
err
)
}
return
h
}
// newConnHandler is the remote-opened conn handler for inet.Network
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_net.go
View file @
e44e538a
...
...
@@ -87,7 +87,11 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
opts
:=
&
bhost
.
HostOpts
{
NegotiationTimeout
:
-
1
,
}
h
:=
bhost
.
NewHost
(
n
,
opts
)
h
,
err
:=
bhost
.
NewHost
(
mn
.
ctx
,
n
,
opts
)
if
err
!=
nil
{
return
nil
,
err
}
mn
.
proc
.
AddChild
(
n
.
proc
)
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
e44e538a
...
...
@@ -268,6 +268,12 @@
"hash"
:
"QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB"
,
"name"
:
"go-libp2p-peer"
,
"version"
:
"2.2.0"
},
{
"author"
:
"vyzo"
,
"hash"
:
"QmYv8PxtikjeL6AfsheUiJfoFRzKvx8hdwRf4odBWH7mQx"
,
"name"
:
"go-libp2p-circuit"
,
"version"
:
"1.1.3"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help