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
c3858e87
Commit
c3858e87
authored
Aug 28, 2015
by
rht
Browse files
Refactor FullMeshLinked and ConnectAll()
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
parent
0f3e3fe2
Changes
4
Hide whitespace changes
Inline
Side-by-side
net/mock/interface.go
View file @
c3858e87
...
@@ -60,6 +60,7 @@ type Mocknet interface {
...
@@ -60,6 +60,7 @@ type Mocknet interface {
DisconnectPeers
(
peer
.
ID
,
peer
.
ID
)
error
DisconnectPeers
(
peer
.
ID
,
peer
.
ID
)
error
DisconnectNets
(
inet
.
Network
,
inet
.
Network
)
error
DisconnectNets
(
inet
.
Network
,
inet
.
Network
)
error
LinkAll
()
error
LinkAll
()
error
ConnectAllButSelf
()
error
}
}
// LinkOptions are used to change aspects of the links.
// LinkOptions are used to change aspects of the links.
...
...
net/mock/mock.go
View file @
c3858e87
...
@@ -28,14 +28,8 @@ func FullMeshLinked(ctx context.Context, n int) (Mocknet, error) {
...
@@ -28,14 +28,8 @@ func FullMeshLinked(ctx context.Context, n int) (Mocknet, error) {
return
nil
,
err
return
nil
,
err
}
}
nets
:=
m
.
Nets
()
if
err
:=
m
.
LinkAll
();
err
!=
nil
{
for
_
,
n1
:=
range
nets
{
return
nil
,
err
for
_
,
n2
:=
range
nets
{
// yes, even self.
if
_
,
err
:=
m
.
LinkNets
(
n1
,
n2
);
err
!=
nil
{
return
nil
,
err
}
}
}
}
return
m
,
nil
return
m
,
nil
...
...
net/mock/mock_net.go
View file @
c3858e87
...
@@ -296,7 +296,7 @@ func (mn *mocknet) removeLink(l *link) {
...
@@ -296,7 +296,7 @@ func (mn *mocknet) removeLink(l *link) {
delete
(
*
mn
.
linksMapGet
(
n2
.
peer
,
n1
.
peer
),
l
)
delete
(
*
mn
.
linksMapGet
(
n2
.
peer
,
n1
.
peer
),
l
)
}
}
func
(
mn
*
mocknet
)
ConnectAll
()
error
{
func
(
mn
*
mocknet
)
ConnectAll
ButSelf
()
error
{
nets
:=
mn
.
Nets
()
nets
:=
mn
.
Nets
()
for
_
,
n1
:=
range
nets
{
for
_
,
n1
:=
range
nets
{
for
_
,
n2
:=
range
nets
{
for
_
,
n2
:=
range
nets
{
...
...
net/mock/mock_notif_test.go
View file @
c3858e87
...
@@ -28,16 +28,9 @@ func TestNotifications(t *testing.T) {
...
@@ -28,16 +28,9 @@ func TestNotifications(t *testing.T) {
notifiees
[
i
]
=
n
notifiees
[
i
]
=
n
}
}
// connect all
// connect all but self
for
_
,
n1
:=
range
nets
{
if
err
:=
mn
.
ConnectAllButSelf
();
err
!=
nil
{
for
_
,
n2
:=
range
nets
{
t
.
Fatal
(
err
)
if
n1
==
n2
{
continue
}
if
_
,
err
:=
mn
.
ConnectNets
(
n1
,
n2
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
}
// test everyone got the correct connection opened calls
// test everyone got the correct connection opened calls
...
...
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