Remove name parameter from (*Peers)ForEach consumer function
It's part of the Peer anyway.
This commit is contained in:
1 parent
5617258cca
commit
a670272a37
4 files changed
+8
-8
No files matched your search
@@ -132,7 +132,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
|
|||||||
|
|
||||||
// Add targets for peers that someone else is connected to, but we
|
// Add targets for peers that someone else is connected to, but we
|
||||||
// aren't
|
// aren't
|
||||||
cm.peers.ForEach(func(name PeerName, peer *Peer) {
|
cm.peers.ForEach(func(peer *Peer) {
|
||||||
for _, conn := range peer.Connections() {
|
for _, conn := range peer.Connections() {
|
||||||
otherPeer := conn.Remote().Name
|
otherPeer := conn.Remote().Name
|
||||||
if otherPeer == cm.ourself.Name || ourConnectedPeers[otherPeer] {
|
if otherPeer == cm.ourself.Name || ourConnectedPeers[otherPeer] {
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ func (cache *MacCache) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (peers *Peers) MarshalJSON() ([]byte, error) {
|
func (peers *Peers) MarshalJSON() ([]byte, error) {
|
||||||
var ps []*Peer
|
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)
|
return json.Marshal(ps)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -55,11 +55,11 @@ func (peers *Peers) Fetch(name PeerName) (*Peer, bool) {
|
|||||||
return peer, found // GRRR, why can't I inline this!?
|
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()
|
peers.RLock()
|
||||||
defer peers.RUnlock()
|
defer peers.RUnlock()
|
||||||
for name, peer := range peers.table {
|
for _, peer := range peers.table {
|
||||||
fun(name, peer)
|
fun(peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ func (peers *Peers) GarbageCollect() []*Peer {
|
|||||||
|
|
||||||
func (peers *Peers) String() string {
|
func (peers *Peers) String() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
peers.ForEach(func(name PeerName, peer *Peer) {
|
peers.ForEach(func(peer *Peer) {
|
||||||
fmt.Fprint(&buf, peer, "\n")
|
fmt.Fprint(&buf, peer, "\n")
|
||||||
for _, conn := range peer.Connections() {
|
for _, conn := range peer.Connections() {
|
||||||
established := ""
|
established := ""
|
||||||
|
|||||||
+2
-2
@@ -124,7 +124,7 @@ func (routes *Routes) calculateBroadcast() map[PeerName][]PeerName {
|
|||||||
broadcast := make(map[PeerName][]PeerName)
|
broadcast := make(map[PeerName][]PeerName)
|
||||||
ourself := routes.ourself
|
ourself := routes.ourself
|
||||||
|
|
||||||
routes.peers.ForEach(func(name PeerName, peer *Peer) {
|
routes.peers.ForEach(func(peer *Peer) {
|
||||||
hops := []PeerName{}
|
hops := []PeerName{}
|
||||||
if found, reached := peer.Routes(ourself, true); found {
|
if found, reached := peer.Routes(ourself, true); found {
|
||||||
// This is rather similar to the inner loop on
|
// 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
|
return broadcast
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user