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 { ...@@ -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.
......
...@@ -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
......
...@@ -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) ConnectAllButSelf() error {
nets := mn.Nets() nets := mn.Nets()
for _, n1 := range nets { for _, n1 := range nets {
for _, n2 := range nets { for _, n2 := range nets {
......
...@@ -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
......
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