downloader: added demotion / promotion in prep. for rep. system

This commit is contained in:
obscuren
2015-04-16 02:16:33 +02:00
parent eda10c7317
commit 205378016f
2 changed files with 25 additions and 0 deletions

View File

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