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
master
2018-Q4-OKR
feat/protobuf
feat/udp
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
No related merge requests found
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