From 0f734a6069254500daab31f57332d172eb60f94c Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Fri, 11 Jul 2014 20:39:55 -0400 Subject: [PATCH] when public, create non-existing torrents --- http/announce.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/http/announce.go b/http/announce.go index 9becda7..84346b9 100644 --- a/http/announce.go +++ b/http/announce.go @@ -51,11 +51,26 @@ func (t *Tracker) ServeAnnounce(w http.ResponseWriter, r *http.Request, p httpro } } - torrent, err := conn.FindTorrent(ann.Infohash) - if err == tracker.ErrTorrentDNE { + var torrent *models.Torrent + torrent, err = conn.FindTorrent(ann.Infohash) + switch { + case t.cfg.Private && err == tracker.ErrTorrentDNE: + torrent = &models.Torrent{ + Infohash: ann.Infohash, + Seeders: make(map[string]models.Peer), + Leechers: make(map[string]models.Peer), + } + + err = conn.PutTorrent(torrent) + if err != nil { + return http.StatusInternalServerError, err + } + + case !t.cfg.Private && err == tracker.ErrTorrentDNE: fail(w, r, err) return http.StatusOK, nil - } else if err != nil { + + case err != nil: return http.StatusInternalServerError, err }