Calculate up/down delta before altering peer

This commit is contained in:
Jimmy Zelinskie
2014-08-01 15:11:37 -04:00
parent f48e1e452f
commit f747a79c8c
2 changed files with 36 additions and 36 deletions
-34
View File
@@ -239,40 +239,6 @@ type AnnounceResponse struct {
Compact bool
}
// NewAnnounceDelta calculates a Peer's download and upload deltas between
// Announces and generates an AnnounceDelta.
func NewAnnounceDelta(a *Announce, created, snatched bool) *AnnounceDelta {
var (
rawDeltaUp = a.Peer.Uploaded - a.Uploaded
rawDeltaDown uint64
)
if !a.Config.FreeleechEnabled {
rawDeltaDown = a.Peer.Downloaded - a.Downloaded
}
// Restarting a torrent may cause a delta to be negative.
if rawDeltaUp < 0 {
rawDeltaUp = 0
}
if rawDeltaDown < 0 {
rawDeltaDown = 0
}
return &AnnounceDelta{
Peer: a.Peer,
Torrent: a.Torrent,
User: a.User,
Created: created,
Snatched: snatched,
Uploaded: uint64(float64(rawDeltaUp) * a.User.UpMultiplier * a.Torrent.UpMultiplier),
Downloaded: uint64(float64(rawDeltaDown) * a.User.DownMultiplier * a.Torrent.DownMultiplier),
}
}
// Scrape is a Scrape by a Peer.
type Scrape struct {
Config *config.Config `json:"config"`