From 76366087256beb089850f3426e90115729a591a8 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 16 Jul 2014 13:05:13 -0400 Subject: [PATCH] Remove Active from the Torrent model and keep LastAction updated --- drivers/tracker/memory/conn.go | 6 ++++-- drivers/tracker/tracker.go | 2 +- http/announce.go | 8 +------- models/models.go | 1 - 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/tracker/memory/conn.go b/drivers/tracker/memory/conn.go index 6891d9e..dbec472 100644 --- a/drivers/tracker/memory/conn.go +++ b/drivers/tracker/memory/conn.go @@ -5,6 +5,8 @@ package memory import ( + "time" + "github.com/chihaya/chihaya/drivers/tracker" "github.com/chihaya/chihaya/models" ) @@ -60,7 +62,7 @@ func (c *Conn) IncrementSnatches(infohash string) error { return nil } -func (c *Conn) MarkActive(infohash string) error { +func (c *Conn) TouchTorrent(infohash string) error { c.torrentsM.Lock() defer c.torrentsM.Unlock() @@ -68,7 +70,7 @@ func (c *Conn) MarkActive(infohash string) error { if !ok { return tracker.ErrTorrentDNE } - t.Active = true + t.LastAction = time.Now().Unix() return nil } diff --git a/drivers/tracker/tracker.go b/drivers/tracker/tracker.go index fa7eb11..c61152d 100644 --- a/drivers/tracker/tracker.go +++ b/drivers/tracker/tracker.go @@ -74,7 +74,7 @@ type Conn interface { PutTorrent(t *models.Torrent) error DeleteTorrent(infohash string) error IncrementSnatches(infohash string) error - MarkActive(infohash string) error + TouchTorrent(infohash string) error PutLeecher(infohash string, p *models.Peer) error DeleteLeecher(infohash, peerkey string) error PutSeeder(infohash string, p *models.Peer) error diff --git a/http/announce.go b/http/announce.go index 15dde9c..0e67f31 100644 --- a/http/announce.go +++ b/http/announce.go @@ -104,13 +104,7 @@ func (t *Tracker) ServeAnnounce(w http.ResponseWriter, r *http.Request, p httpro } func updateTorrent(c tracker.Conn, a *models.Announce, p *models.Peer, t *models.Torrent) (created bool, err error) { - if !t.Active && a.Left == 0 { - err = c.MarkActive(t.Infohash) - if err != nil { - return - } - t.Active = true - } + c.TouchTorrent(t.Infohash) switch { case t.InSeederPool(p): diff --git a/models/models.go b/models/models.go index 65416f0..cf37311 100644 --- a/models/models.go +++ b/models/models.go @@ -81,7 +81,6 @@ func (p Peer) Key() string { type Torrent struct { ID uint64 `json:"id"` Infohash string `json:"infohash"` - Active bool `json:"active"` Seeders map[string]Peer `json:"seeders"` Leechers map[string]Peer `json:"leechers"`