aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/peer.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r--eth/downloader/peer.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go
index e2dec5571..1ff2d5149 100644
--- a/eth/downloader/peer.go
+++ b/eth/downloader/peer.go
@@ -86,10 +86,8 @@ func (p *peer) Demote() {
for {
// Calculate the new reputation value
prev := atomic.LoadInt32(&p.rep)
- next := prev - 2
- if next < 0 {
- next = 0
- }
+ next := prev / 2
+
// Try to update the old value
if atomic.CompareAndSwapInt32(&p.rep, prev, next) {
return
@@ -177,7 +175,7 @@ func (ps *peerSet) AllPeers() []*peer {
}
// IdlePeers retrieves a flat list of all the currently idle peers within the
-// active peer set.
+// active peer set, ordered by their reputation.
func (ps *peerSet) IdlePeers() []*peer {
ps.lock.RLock()
defer ps.lock.RUnlock()
@@ -188,5 +186,12 @@ func (ps *peerSet) IdlePeers() []*peer {
list = append(list, p)
}
}
+ for i := 0; i < len(list); i++ {
+ for j := i + 1; j < len(list); j++ {
+ if atomic.LoadInt32(&list[i].rep) < atomic.LoadInt32(&list[j].rep) {
+ list[i], list[j] = list[j], list[i]
+ }
+ }
+ }
return list
}