mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-23 00:08:15 -07:00
Initial torrent inactivity purging
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user