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
ebbd3bc7
Unverified
Commit
ebbd3bc7
authored
Nov 19, 2017
by
Jakub Sztandera
Committed by
GitHub
Nov 19, 2017
Browse files
Merge pull request #245 from libp2p/kevina/fix-go-vet
Fix "go vet" errors.
parents
9e3cf083
62f92f7e
Changes
6
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
ebbd3bc7
...
...
@@ -115,6 +115,7 @@ type HostOpts struct {
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func
NewHost
(
ctx
context
.
Context
,
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
...
...
@@ -123,6 +124,14 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
maResolver
:
madns
.
DefaultResolver
,
}
h
.
proc
=
goprocess
.
WithTeardown
(
func
()
error
{
if
h
.
natmgr
!=
nil
{
h
.
natmgr
.
Close
()
}
cancel
()
return
h
.
Network
()
.
Close
()
})
if
opts
.
MultistreamMuxer
!=
nil
{
h
.
mux
=
opts
.
MultistreamMuxer
}
...
...
@@ -162,25 +171,11 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
net
.
Notify
(
h
.
cmgr
.
Notifee
())
}
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
)
if
opts
.
EnableRelay
{
relayCtx
,
relayCancel
=
context
.
WithCancel
(
ctx
)
err
:=
circuit
.
AddRelayTransport
(
relayCtx
,
h
,
opts
.
RelayOpts
...
)
err
:=
circuit
.
AddRelayTransport
(
ctx
,
h
,
opts
.
RelayOpts
...
)
if
err
!=
nil
{
h
.
Close
()
return
nil
,
err
...
...
p2p/host/basic/basic_host_test.go
View file @
ebbd3bc7
...
...
@@ -54,7 +54,7 @@ func TestHostSimple(t *testing.T) {
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
buf1
,
buf2
)
{
t
.
Fatal
(
"buf1 != buf2 -- %x != %x"
,
buf1
,
buf2
)
t
.
Fatal
f
(
"buf1 != buf2 -- %x != %x"
,
buf1
,
buf2
)
}
// get it from the pipe (tee)
...
...
@@ -63,7 +63,7 @@ func TestHostSimple(t *testing.T) {
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
buf1
,
buf3
)
{
t
.
Fatal
(
"buf1 != buf3 -- %x != %x"
,
buf1
,
buf3
)
t
.
Fatal
f
(
"buf1 != buf3 -- %x != %x"
,
buf1
,
buf3
)
}
}
...
...
p2p/net/mock/mock_peernet.go
View file @
ebbd3bc7
...
...
@@ -205,7 +205,7 @@ func (pn *peernet) removeConn(c *conn) {
cs
,
found
=
pn
.
connsByPeer
[
c
.
remote
]
if
!
found
{
panic
(
fmt
.
Sprintf
(
"attempting to remove a conn that doesnt exist %
p
"
,
c
.
remote
))
panic
(
fmt
.
Sprintf
(
"attempting to remove a conn that doesnt exist %
v
"
,
c
.
remote
))
}
delete
(
cs
,
c
)
}
...
...
p2p/net/mock/mock_test.go
View file @
ebbd3bc7
...
...
@@ -166,7 +166,7 @@ func TestNetworkSetup(t *testing.T) {
links12
=
mn
.
LinksBetweenPeers
(
p1
,
p2
)
if
len
(
links12
)
!=
0
{
t
.
Error
f
(
"should be 0 now..."
,
len
(
links12
))
t
.
Error
(
"should be 0 now..."
,
len
(
links12
))
}
links11
=
mn
.
LinksBetweenPeers
(
p1
,
p1
)
...
...
@@ -190,7 +190,7 @@ func TestNetworkSetup(t *testing.T) {
// first, no conns
if
len
(
n2
.
Conns
())
>
0
||
len
(
n3
.
Conns
())
>
0
{
t
.
Error
(
"should have 0 conn. Got: (%d, %d)"
,
len
(
n2
.
Conns
()),
len
(
n3
.
Conns
()))
t
.
Error
f
(
"should have 0 conn. Got: (%d, %d)"
,
len
(
n2
.
Conns
()),
len
(
n3
.
Conns
()))
}
// connect p2->p3
...
...
p2p/test/backpressure/backpressure_test.go
View file @
ebbd3bc7
...
...
@@ -146,7 +146,7 @@ a problem.
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
log
.
Debugf
(
"dialing %s"
,
h2pi
.
Addrs
)
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
t
.
Fatal
f
(
"Failed to connect:"
,
err
)
t
.
Fatal
(
"Failed to connect:"
,
err
)
}
// launch sender!
...
...
@@ -266,7 +266,7 @@ func TestStBackpressureStreamWrite(t *testing.T) {
t
.
Error
(
"read failed:"
,
err
)
}
if
expect
!=
n
{
t
.
Error
(
"read len differs: %d != %d"
,
expect
,
n
)
t
.
Error
f
(
"read len differs: %d != %d"
,
expect
,
n
)
}
}
...
...
@@ -283,7 +283,7 @@ func TestStBackpressureStreamWrite(t *testing.T) {
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
log
.
Debugf
(
"dialing %s"
,
h2pi
.
Addrs
)
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
t
.
Fatal
f
(
"Failed to connect:"
,
err
)
t
.
Fatal
(
"Failed to connect:"
,
err
)
}
// open a stream, from 2->1, this is our reader
...
...
p2p/test/reconnects/reconnect_test.go
View file @
ebbd3bc7
...
...
@@ -174,7 +174,7 @@ func SubtestConnSendDisc(t *testing.T, hosts []host.Host) {
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
log
.
Debugf
(
"dialing %s"
,
h2pi
.
Addrs
)
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
t
.
Fatal
f
(
"Failed to connect:"
,
err
)
t
.
Fatal
(
"Failed to connect:"
,
err
)
}
}
}
...
...
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