Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4d9f1f0f
Commit
4d9f1f0f
authored
Dec 18, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: Connectedness bugfix
Connectedness was totally incorrect. added a test case.
parent
7952d95b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
net/net.go
net/net.go
+7
-1
net/net_test.go
net/net_test.go
+61
-0
No files found.
net/net.go
View file @
4d9f1f0f
...
...
@@ -2,6 +2,8 @@
package
net
import
(
"fmt"
ic
"github.com/jbenet/go-ipfs/crypto"
swarm
"github.com/jbenet/go-ipfs/net/swarm"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -234,7 +236,7 @@ func (n *network) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
// For now only returns Connected || NotConnected. Expand into more later.
func
(
n
*
network
)
Connectedness
(
p
peer
.
ID
)
Connectedness
{
c
:=
n
.
swarm
.
ConnectionsToPeer
(
p
)
if
c
!=
nil
&&
len
(
c
)
<
1
{
if
c
!=
nil
&&
len
(
c
)
>
0
{
return
Connected
}
return
NotConnected
...
...
@@ -266,6 +268,10 @@ func (n *network) SetHandler(p ProtocolID, h StreamHandler) {
n
.
mux
.
SetHandler
(
p
,
h
)
}
func
(
n
*
network
)
String
()
string
{
return
fmt
.
Sprintf
(
"<Network %s>"
,
n
.
LocalPeer
())
}
func
(
n
*
network
)
IdentifyProtocol
()
*
IDService
{
return
n
.
ids
}
...
...
net/net_test.go
0 → 100644
View file @
4d9f1f0f
package
net_test
import
(
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
inet
"github.com/jbenet/go-ipfs/net"
)
// TestConnectednessCorrect starts a few networks, connects a few
// and tests Connectedness value is correct.
func
TestConnectednessCorrect
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
nets
:=
make
([]
inet
.
Network
,
4
)
for
i
:=
0
;
i
<
4
;
i
++
{
nets
[
i
]
=
GenNetwork
(
t
,
ctx
)
}
// connect 0-1, 0-2, 0-3, 1-2, 2-3
dial
:=
func
(
a
,
b
inet
.
Network
)
{
DivulgeAddresses
(
b
,
a
)
if
err
:=
a
.
DialPeer
(
ctx
,
b
.
LocalPeer
());
err
!=
nil
{
t
.
Fatalf
(
"Failed to dial: %s"
,
err
)
}
}
dial
(
nets
[
0
],
nets
[
1
])
dial
(
nets
[
0
],
nets
[
3
])
dial
(
nets
[
1
],
nets
[
2
])
dial
(
nets
[
3
],
nets
[
2
])
// test those connected show up correctly
testConnectedness
:=
func
(
a
,
b
inet
.
Network
,
c
inet
.
Connectedness
)
{
if
a
.
Connectedness
(
b
.
LocalPeer
())
!=
c
{
t
.
Error
(
"%s is connected to %s, but Connectedness incorrect"
,
a
,
b
)
}
// test symmetric case
if
b
.
Connectedness
(
a
.
LocalPeer
())
!=
c
{
t
.
Error
(
"%s is connected to %s, but Connectedness incorrect"
,
a
,
b
)
}
}
// test connected
testConnectedness
(
nets
[
0
],
nets
[
1
],
inet
.
Connected
)
testConnectedness
(
nets
[
0
],
nets
[
3
],
inet
.
Connected
)
testConnectedness
(
nets
[
1
],
nets
[
2
],
inet
.
Connected
)
testConnectedness
(
nets
[
3
],
nets
[
2
],
inet
.
Connected
)
// test not connected
testConnectedness
(
nets
[
0
],
nets
[
2
],
inet
.
NotConnected
)
testConnectedness
(
nets
[
1
],
nets
[
3
],
inet
.
NotConnected
)
for
_
,
n
:=
range
nets
{
n
.
Close
()
}
}
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