mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-09-03 02:35:18 +00:00
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
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/drivers/tracker"
|
"github.com/chihaya/chihaya/drivers/tracker"
|
||||||
"github.com/chihaya/chihaya/models"
|
"github.com/chihaya/chihaya/models"
|
||||||
)
|
)
|
||||||
|
@ -60,7 +62,7 @@ func (c *Conn) IncrementSnatches(infohash string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) MarkActive(infohash string) error {
|
func (c *Conn) TouchTorrent(infohash string) error {
|
||||||
c.torrentsM.Lock()
|
c.torrentsM.Lock()
|
||||||
defer c.torrentsM.Unlock()
|
defer c.torrentsM.Unlock()
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ func (c *Conn) MarkActive(infohash string) error {
|
||||||
if !ok {
|
if !ok {
|
||||||
return tracker.ErrTorrentDNE
|
return tracker.ErrTorrentDNE
|
||||||
}
|
}
|
||||||
t.Active = true
|
t.LastAction = time.Now().Unix()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ type Conn interface {
|
||||||
PutTorrent(t *models.Torrent) error
|
PutTorrent(t *models.Torrent) error
|
||||||
DeleteTorrent(infohash string) error
|
DeleteTorrent(infohash string) error
|
||||||
IncrementSnatches(infohash string) error
|
IncrementSnatches(infohash string) error
|
||||||
MarkActive(infohash string) error
|
TouchTorrent(infohash string) error
|
||||||
PutLeecher(infohash string, p *models.Peer) error
|
PutLeecher(infohash string, p *models.Peer) error
|
||||||
DeleteLeecher(infohash, peerkey string) error
|
DeleteLeecher(infohash, peerkey string) error
|
||||||
PutSeeder(infohash string, p *models.Peer) 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) {
|
func updateTorrent(c tracker.Conn, a *models.Announce, p *models.Peer, t *models.Torrent) (created bool, err error) {
|
||||||
if !t.Active && a.Left == 0 {
|
c.TouchTorrent(t.Infohash)
|
||||||
err = c.MarkActive(t.Infohash)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t.Active = true
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case t.InSeederPool(p):
|
case t.InSeederPool(p):
|
||||||
|
|
|
@ -81,7 +81,6 @@ func (p Peer) Key() string {
|
||||||
type Torrent struct {
|
type Torrent struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Infohash string `json:"infohash"`
|
Infohash string `json:"infohash"`
|
||||||
Active bool `json:"active"`
|
|
||||||
|
|
||||||
Seeders map[string]Peer `json:"seeders"`
|
Seeders map[string]Peer `json:"seeders"`
|
||||||
Leechers map[string]Peer `json:"leechers"`
|
Leechers map[string]Peer `json:"leechers"`
|
||||||
|
|
Loading…
Add table
Reference in a new issue