implement incrementing user's snatches
This commit is contained in:
parent
78d94d1e99
commit
490dfa7877
3 changed files with 34 additions and 9 deletions
|
@ -148,13 +148,22 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
|
|||
}
|
||||
|
||||
case ann.Event == "completed":
|
||||
err = c.IncrementSnatches(t.Infohash)
|
||||
snatched = true
|
||||
|
||||
err = c.IncrementTorrentSnatches(t.Infohash)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
snatched = true
|
||||
t.Snatches++
|
||||
|
||||
if ann.Config.Private {
|
||||
err = c.IncrementUserSnatches(u.Passkey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
u.Snatches++
|
||||
}
|
||||
|
||||
if t.InLeecherPool(p) {
|
||||
err = leecherFinished(c, t.Infohash, p)
|
||||
if err != nil {
|
||||
|
|
|
@ -71,15 +71,17 @@ type Conn interface {
|
|||
Close() error
|
||||
|
||||
// Torrent interactions
|
||||
TouchTorrent(infohash string) error
|
||||
FindTorrent(infohash string) (*models.Torrent, error)
|
||||
PutTorrent(t *models.Torrent) error
|
||||
DeleteTorrent(infohash string) error
|
||||
IncrementSnatches(infohash string) error
|
||||
TouchTorrent(infohash string) error
|
||||
IncrementTorrentSnatches(infohash string) error
|
||||
|
||||
PutLeecher(infohash string, p *models.Peer) error
|
||||
DeleteLeecher(infohash, peerkey string) error
|
||||
DeleteLeecher(infohash, peerID string) error
|
||||
|
||||
PutSeeder(infohash string, p *models.Peer) error
|
||||
DeleteSeeder(infohash, peerkey string) error
|
||||
DeleteSeeder(infohash, peerID string) error
|
||||
|
||||
PurgeInactiveTorrent(infohash string) error
|
||||
PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time) error
|
||||
|
@ -88,6 +90,7 @@ type Conn interface {
|
|||
FindUser(passkey string) (*models.User, error)
|
||||
PutUser(u *models.User) error
|
||||
DeleteUser(passkey string) error
|
||||
IncrementUserSnatches(passkey string) error
|
||||
|
||||
// Whitelist interactions
|
||||
FindClient(clientID string) error
|
||||
|
|
|
@ -54,12 +54,12 @@ func (c *Conn) FindClient(peerID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) IncrementSnatches(infohash string) error {
|
||||
func (c *Conn) IncrementTorrentSnatches(infohash string) error {
|
||||
c.torrentsM.Lock()
|
||||
defer c.torrentsM.Unlock()
|
||||
|
||||
t, ok := c.torrents[infohash]
|
||||
if !ok {
|
||||
t, exists := c.torrents[infohash]
|
||||
if !exists {
|
||||
return tracker.ErrTorrentDNE
|
||||
}
|
||||
t.Snatches++
|
||||
|
@ -67,6 +67,19 @@ func (c *Conn) IncrementSnatches(infohash string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) IncrementUserSnatches(userID string) error {
|
||||
c.usersM.Lock()
|
||||
defer c.usersM.Unlock()
|
||||
|
||||
u, exists := c.users[userID]
|
||||
if !exists {
|
||||
return tracker.ErrUserDNE
|
||||
}
|
||||
u.Snatches++
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) TouchTorrent(infohash string) error {
|
||||
c.torrentsM.Lock()
|
||||
defer c.torrentsM.Unlock()
|
||||
|
|
Loading…
Reference in a new issue