Initial torrent inactivity purging

This commit is contained in:
Justin Li
2014-07-16 13:24:44 -04:00
parent 7636608725
commit ea72e9e10c
4 changed files with 72 additions and 0 deletions
+21
View File
@@ -206,3 +206,24 @@ func (c *Conn) DeleteClient(peerID string) error {
return nil
}
func (c *Conn) PurgeInactiveTorrents(before time.Time) error {
unix := before.Unix()
var queue []string
c.torrentsM.RLock()
for key, torrent := range c.torrents {
if torrent.LastAction < unix {
queue = append(queue, key)
}
}
c.torrentsM.RUnlock()
c.torrentsM.Lock()
for _, key := range queue {
delete(c.torrents, key)
}
c.torrentsM.Unlock()
return nil
}