diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-11 21:47:58 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-11 23:21:22 +0800 |
commit | d37a2559b928a8118a5eec77e2181cb6cf566be1 (patch) | |
tree | 12fa127f605e8b814d92c74dc5a543b9821a5189 /eth/downloader/peer.go | |
parent | 70c65835f4747d991fe8d79e7138828cd97c6ac7 (diff) | |
download | go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar.gz go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar.bz2 go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar.lz go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar.xz go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.tar.zst go-tangerine-d37a2559b928a8118a5eec77e2181cb6cf566be1.zip |
eth/downloader: revert to demotion, use harsher penalty
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r-- | eth/downloader/peer.go | 15 |
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 } |