eth/downloader: revert to demotion, use harsher penalty

This commit is contained in:
Péter Szilágyi
2015-05-11 16:47:58 +03:00
parent 685862d2ce
commit ebbd8b0743
2 changed files with 19 additions and 8 deletions

View File

@ -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
}