diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-16 08:16:33 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-16 08:16:33 +0800 |
commit | 205378016fc342a9ee683b3d040b3e7d0e2ebb51 (patch) | |
tree | 4eb81058b47994d177afd14c3a157063c703f445 /eth/downloader/peer.go | |
parent | eda10c731758217f099bf4a4e232bdb3dca1e478 (diff) | |
download | go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar.gz go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar.bz2 go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar.lz go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar.xz go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.tar.zst go-tangerine-205378016fc342a9ee683b3d040b3e7d0e2ebb51.zip |
downloader: added demotion / promotion in prep. for rep. system
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r-- | eth/downloader/peer.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index f66e5afd8..4cd306a05 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -95,3 +95,23 @@ func (p *peer) fetch(chunk *chunk) error { return nil } + +// promote increases the peer's reputation +func (p *peer) promote() { + p.mu.Lock() + defer p.mu.Unlock() + + p.rep++ +} + +// demote decreases the peer's reputation or leaves it at 0 +func (p *peer) demote() { + p.mu.Lock() + defer p.mu.Unlock() + + if p.rep > 1 { + p.rep -= 2 + } else { + p.rep = 0 + } +} |