mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
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":
|
case ann.Event == "completed":
|
||||||
err = c.IncrementSnatches(t.Infohash)
|
snatched = true
|
||||||
|
|
||||||
|
err = c.IncrementTorrentSnatches(t.Infohash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
snatched = true
|
|
||||||
t.Snatches++
|
t.Snatches++
|
||||||
|
|
||||||
|
if ann.Config.Private {
|
||||||
|
err = c.IncrementUserSnatches(u.Passkey)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u.Snatches++
|
||||||
|
}
|
||||||
|
|
||||||
if t.InLeecherPool(p) {
|
if t.InLeecherPool(p) {
|
||||||
err = leecherFinished(c, t.Infohash, p)
|
err = leecherFinished(c, t.Infohash, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -71,15 +71,17 @@ type Conn interface {
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
// Torrent interactions
|
// Torrent interactions
|
||||||
|
TouchTorrent(infohash string) error
|
||||||
FindTorrent(infohash string) (*models.Torrent, error)
|
FindTorrent(infohash string) (*models.Torrent, error)
|
||||||
PutTorrent(t *models.Torrent) error
|
PutTorrent(t *models.Torrent) error
|
||||||
DeleteTorrent(infohash string) error
|
DeleteTorrent(infohash string) error
|
||||||
IncrementSnatches(infohash string) error
|
IncrementTorrentSnatches(infohash string) error
|
||||||
TouchTorrent(infohash string) error
|
|
||||||
PutLeecher(infohash string, p *models.Peer) 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
|
PutSeeder(infohash string, p *models.Peer) error
|
||||||
DeleteSeeder(infohash, peerkey string) error
|
DeleteSeeder(infohash, peerID string) error
|
||||||
|
|
||||||
PurgeInactiveTorrent(infohash string) error
|
PurgeInactiveTorrent(infohash string) error
|
||||||
PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time) error
|
PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time) error
|
||||||
|
@ -88,6 +90,7 @@ type Conn interface {
|
||||||
FindUser(passkey string) (*models.User, error)
|
FindUser(passkey string) (*models.User, error)
|
||||||
PutUser(u *models.User) error
|
PutUser(u *models.User) error
|
||||||
DeleteUser(passkey string) error
|
DeleteUser(passkey string) error
|
||||||
|
IncrementUserSnatches(passkey string) error
|
||||||
|
|
||||||
// Whitelist interactions
|
// Whitelist interactions
|
||||||
FindClient(clientID string) error
|
FindClient(clientID string) error
|
||||||
|
|
|
@ -54,12 +54,12 @@ func (c *Conn) FindClient(peerID string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) IncrementSnatches(infohash string) error {
|
func (c *Conn) IncrementTorrentSnatches(infohash string) error {
|
||||||
c.torrentsM.Lock()
|
c.torrentsM.Lock()
|
||||||
defer c.torrentsM.Unlock()
|
defer c.torrentsM.Unlock()
|
||||||
|
|
||||||
t, ok := c.torrents[infohash]
|
t, exists := c.torrents[infohash]
|
||||||
if !ok {
|
if !exists {
|
||||||
return tracker.ErrTorrentDNE
|
return tracker.ErrTorrentDNE
|
||||||
}
|
}
|
||||||
t.Snatches++
|
t.Snatches++
|
||||||
|
@ -67,6 +67,19 @@ func (c *Conn) IncrementSnatches(infohash string) error {
|
||||||
return nil
|
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 {
|
func (c *Conn) TouchTorrent(infohash string) error {
|
||||||
c.torrentsM.Lock()
|
c.torrentsM.Lock()
|
||||||
defer c.torrentsM.Unlock()
|
defer c.torrentsM.Unlock()
|
||||||
|
|
Loading…
Add table
Reference in a new issue