Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FullMeshLinked and ConnectAll() #1617

Merged
merged 1 commit into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions p2p/net/mock/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions p2p/net/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/mock/mock_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 3 additions & 10 deletions p2p/net/mock/mock_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down