mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-12 15:53:32 -07:00
implement incrementing user's snatches
This commit is contained in:
+11
-2
@@ -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 {
|
||||
|
||||
+7
-4
@@ -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
|
||||
|
||||
+16
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user