Remove Active from the Torrent model and keep LastAction updated
This commit is contained in:
parent
2a4d4c5aef
commit
7636608725
4 changed files with 6 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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"`
|
||||
|
|
Loading…
Add table
Reference in a new issue