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
25f5c198
Commit
25f5c198
authored
Apr 22, 2017
by
Jeromy
Browse files
WIP: relay integration
parent
74390ca5
Changes
4
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
25f5c198
...
...
@@ -9,6 +9,7 @@ import (
logging
"github.com/ipfs/go-log"
goprocess
"github.com/jbenet/goprocess"
circuit
"github.com/libp2p/go-libp2p-circuit"
metrics
"github.com/libp2p/go-libp2p-metrics"
mstream
"github.com/libp2p/go-libp2p-metrics/stream"
inet
"github.com/libp2p/go-libp2p-net"
...
...
@@ -51,10 +52,12 @@ type BasicHost struct {
proc
goprocess
.
Process
bwc
metrics
.
Reporter
relay
*
circuit
.
Relay
}
// New constructs and sets up a new *BasicHost with given Network
func
New
(
net
inet
.
Network
,
opts
...
interface
{})
*
BasicHost
{
func
New
(
net
inet
.
Network
,
opts
...
interface
{})
(
*
BasicHost
,
error
)
{
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
...
...
@@ -81,6 +84,14 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
case
metrics
.
Reporter
:
h
.
bwc
=
o
case
*
circuit
.
Relay
:
net
.
AddDialer
(
o
.
Dialer
())
list
:=
o
.
Listener
()
err
:=
net
.
AddListener
(
list
)
if
err
!=
nil
{
return
nil
,
err
}
}
}
...
...
@@ -89,7 +100,7 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
net
.
SetConnHandler
(
h
.
newConnHandler
)
net
.
SetStreamHandler
(
h
.
newStreamHandler
)
return
h
return
h
,
nil
}
// newConnHandler is the remote-opened conn handler for inet.Network
...
...
p2p/host/basic/basic_host_test.go
View file @
25f5c198
...
...
@@ -16,8 +16,8 @@ import (
func
TestHostSimple
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
h1
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h1
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
defer
h1
.
Close
()
defer
h2
.
Close
()
...
...
@@ -64,8 +64,8 @@ func TestHostSimple(t *testing.T) {
}
func
getHostPair
(
ctx
context
.
Context
,
t
*
testing
.
T
)
(
host
.
Host
,
host
.
Host
)
{
h1
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h1
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
...
...
@@ -170,8 +170,8 @@ func TestHostProtoPreknowledge(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h1
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h1
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
,
_
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
conn
:=
make
(
chan
protocol
.
ID
)
handler
:=
func
(
s
inet
.
Stream
)
{
...
...
p2p/net/mock/mock_net.go
View file @
25f5c198
...
...
@@ -84,7 +84,7 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
return
nil
,
err
}
h
:=
bhost
.
New
(
n
)
h
,
_
:=
bhost
.
New
(
n
)
h
.
NegotiateTimeout
=
0
mn
.
proc
.
AddChild
(
n
.
proc
)
...
...
p2p/net/mock/mock_peernet.go
View file @
25f5c198
...
...
@@ -8,9 +8,11 @@ import (
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
iconn
"github.com/libp2p/go-libp2p-interface-conn"
inet
"github.com/libp2p/go-libp2p-net"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
tpt
"github.com/libp2p/go-libp2p-transport"
ma
"github.com/multiformats/go-multiaddr"
)
...
...
@@ -220,6 +222,14 @@ func (pn *peernet) LocalPeer() peer.ID {
return
pn
.
peer
}
func
(
pn
*
peernet
)
AddDialer
(
d
iconn
.
SingleDialer
)
{
panic
(
"mocknet doesnt support adding dialers"
)
}
func
(
pn
*
peernet
)
AddListener
(
l
tpt
.
Listener
)
error
{
return
fmt
.
Errorf
(
"mocknet doesnt support adding listeners"
)
}
// Peers returns the connected peers
func
(
pn
*
peernet
)
Peers
()
[]
peer
.
ID
{
pn
.
RLock
()
...
...
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