Remove name parameter from (*Peers)ForEach consumer function

It's part of the Peer anyway.
This commit is contained in:
David Wragg committed 2015-03-27 18:05:00 +00:00
1 parent 5617258cca
commit a670272a37
4 files changed
+8 -8

No files matched your search

+1 -1
View File
@@ -132,7 +132,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(name PeerName, peer *Peer) {
cm.peers.ForEach(func(peer *Peer) {
for _, conn := range peer.Connections() {
otherPeer := conn.Remote().Name
if otherPeer == cm.ourself.Name || ourConnectedPeers[otherPeer] {
+1 -1
View File
@@ -36,7 +36,7 @@ func (cache *MacCache) MarshalJSON() ([]byte, error) {
func (peers *Peers) MarshalJSON() ([]byte, error) {
var ps []*Peer
peers.ForEach(func(_ PeerName, peer *Peer) { ps = append(ps, peer) })
peers.ForEach(func(peer *Peer) { ps = append(ps, peer) })
return json.Marshal(ps)
}
+4 -4
View File
@@ -55,11 +55,11 @@ func (peers *Peers) Fetch(name PeerName) (*Peer, bool) {
return peer, found // GRRR, why can't I inline this!?
}
func (peers *Peers) ForEach(fun func(PeerName, *Peer)) {
func (peers *Peers) ForEach(fun func(*Peer)) {
peers.RLock()
defer peers.RUnlock()
for name, peer := range peers.table {
fun(name, peer)
for _, peer := range peers.table {
fun(peer)
}
}
@@ -129,7 +129,7 @@ func (peers *Peers) GarbageCollect() []*Peer {
func (peers *Peers) String() string {
var buf bytes.Buffer
peers.ForEach(func(name PeerName, peer *Peer) {
peers.ForEach(func(peer *Peer) {
fmt.Fprint(&buf, peer, "\n")
for _, conn := range peer.Connections() {
established := ""
+2 -2
View File
@@ -124,7 +124,7 @@ func (routes *Routes) calculateBroadcast() map[PeerName][]PeerName {
broadcast := make(map[PeerName][]PeerName)
ourself := routes.ourself
routes.peers.ForEach(func(name PeerName, peer *Peer) {
routes.peers.ForEach(func(peer *Peer) {
hops := []PeerName{}
if found, reached := peer.Routes(ourself, true); found {
// This is rather similar to the inner loop on
@@ -143,7 +143,7 @@ func (routes *Routes) calculateBroadcast() map[PeerName][]PeerName {
}
}
}
broadcast[name] = hops
broadcast[peer.Name] = hops
})
return broadcast
}