frontend: TrackerLogic interface returns modified context

HandleAnnounce and HandleScrape must return the modified context changed
by the hooks. These contexts are passed to AfterAnnounce and AfterScrape
for further use.

Closes #304
This commit is contained in:
Cedric Charly
2017-06-05 21:53:17 -05:00
parent abccf5bd7e
commit f7becf952b
4 changed files with 24 additions and 16 deletions
+4 -4
View File
@@ -191,7 +191,7 @@ func (f *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httpr
af = new(bittorrent.AddressFamily)
*af = req.IP.AddressFamily
resp, err := f.logic.HandleAnnounce(context.Background(), req)
ctx, resp, err := f.logic.HandleAnnounce(context.Background(), req)
if err != nil {
WriteError(w, err)
return
@@ -203,7 +203,7 @@ func (f *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httpr
return
}
go f.logic.AfterAnnounce(context.Background(), req, resp)
go f.logic.AfterAnnounce(ctx, req, resp)
}
// scrapeRoute parses and responds to a Scrape.
@@ -248,7 +248,7 @@ func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
af = new(bittorrent.AddressFamily)
*af = req.AddressFamily
resp, err := f.logic.HandleScrape(context.Background(), req)
ctx, resp, err := f.logic.HandleScrape(context.Background(), req)
if err != nil {
WriteError(w, err)
return
@@ -260,5 +260,5 @@ func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
return
}
go f.logic.AfterScrape(context.Background(), req, resp)
go f.logic.AfterScrape(ctx, req, resp)
}