implement incrementing user's snatches

This commit is contained in:
Jimmy Zelinskie
2014-07-19 04:22:27 -04:00
parent 78d94d1e99
commit 490dfa7877
3 changed files with 34 additions and 9 deletions
+16 -3
View File
@@ -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()