refactor: make Peer.Connections() return a set instead of a slice

This is more flexible since it allows callers to perform efficient
lookups on the result.
This commit is contained in:
Matthias Radestock committed 2015-04-06 13:57:13 +01:00
1 parent fe4d8b7767
commit 9b9d8a03aa
6 files changed
+16 -9

No files matched your search

+2 -2
View File
@@ -116,7 +116,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
// copy the set of things we are connected to, so we can access them without locking
ourConnectedPeers := make(PeerNameSet)
ourConnectedTargets := make(map[string]struct{})
for _, conn := range cm.ourself.Connections() {
for conn := range cm.ourself.Connections() {
ourConnectedPeers[conn.Remote().Name] = void
ourConnectedTargets[conn.RemoteTCPAddr()] = void
}
@@ -136,7 +136,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
// Add targets for peers that someone else is connected to, but we
// aren't
cm.peers.ForEach(func(peer *Peer) {
for _, conn := range peer.Connections() {
for conn := range peer.Connections() {
otherPeer := conn.Remote().Name
if otherPeer == cm.ourself.Name {
continue