Commit c3858e87 authored by rht's avatar rht
Browse files

Refactor FullMeshLinked and ConnectAll()



License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent 0f3e3fe2
......@@ -60,6 +60,7 @@ type Mocknet interface {
DisconnectPeers(peer.ID, peer.ID) error
DisconnectNets(inet.Network, inet.Network) error
LinkAll() error
ConnectAllButSelf() error
}
// LinkOptions are used to change aspects of the links.
......
......@@ -28,14 +28,8 @@ func FullMeshLinked(ctx context.Context, n int) (Mocknet, error) {
return nil, err
}
nets := m.Nets()
for _, n1 := range nets {
for _, n2 := range nets {
// yes, even self.
if _, err := m.LinkNets(n1, n2); err != nil {
return nil, err
}
}
if err := m.LinkAll(); err != nil {
return nil, err
}
return m, nil
......
......@@ -296,7 +296,7 @@ func (mn *mocknet) removeLink(l *link) {
delete(*mn.linksMapGet(n2.peer, n1.peer), l)
}
func (mn *mocknet) ConnectAll() error {
func (mn *mocknet) ConnectAllButSelf() error {
nets := mn.Nets()
for _, n1 := range nets {
for _, n2 := range nets {
......
......@@ -28,16 +28,9 @@ func TestNotifications(t *testing.T) {
notifiees[i] = n
}
// connect all
for _, n1 := range nets {
for _, n2 := range nets {
if n1 == n2 {
continue
}
if _, err := mn.ConnectNets(n1, n2); err != nil {
t.Fatal(err)
}
}
// connect all but self
if err := mn.ConnectAllButSelf(); err != nil {
t.Fatal(err)
}
// test everyone got the correct connection opened calls
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment