From 9c1168746aed5abb53c2c105c1ab52fdd94ed62b Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Sat, 2 Apr 2016 20:22:15 -0400 Subject: [PATCH] hotfix: initialized scrape map --- chihaya.go | 2 +- cmd/chihaya/main.go | 5 +++-- server/http/writer.go | 2 +- server/store/middleware/response/response.go | 2 +- tracker/tracker.go | 4 +++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chihaya.go b/chihaya.go index 6ed4027..1c51899 100644 --- a/chihaya.go +++ b/chihaya.go @@ -51,7 +51,7 @@ type ScrapeRequest struct { // ScrapeResponse represents the parameters used to create a scrape response. type ScrapeResponse struct { - Files map[string]Scrape + Files map[InfoHash]Scrape } // Scrape represents the state of a swarm that is returned in a scrape response. diff --git a/cmd/chihaya/main.go b/cmd/chihaya/main.go index 27c6751..08f4569 100644 --- a/cmd/chihaya/main.go +++ b/cmd/chihaya/main.go @@ -15,14 +15,15 @@ import ( "github.com/chihaya/chihaya/server" "github.com/chihaya/chihaya/tracker" + _ "github.com/chihaya/chihaya/middleware/deniability" _ "github.com/chihaya/chihaya/server/http" _ "github.com/chihaya/chihaya/server/prometheus" _ "github.com/chihaya/chihaya/server/store" _ "github.com/chihaya/chihaya/server/store/memory" _ "github.com/chihaya/chihaya/server/store/middleware/client" - _ "github.com/chihaya/chihaya/server/store/middleware/ip" _ "github.com/chihaya/chihaya/server/store/middleware/infohash" - _ "github.com/chihaya/chihaya/middleware/deniability" + _ "github.com/chihaya/chihaya/server/store/middleware/ip" + _ "github.com/chihaya/chihaya/server/store/middleware/response" ) var configPath string diff --git a/server/http/writer.go b/server/http/writer.go index 1b3353c..45b4cff 100644 --- a/server/http/writer.go +++ b/server/http/writer.go @@ -71,7 +71,7 @@ func writeAnnounceResponse(w http.ResponseWriter, resp *chihaya.AnnounceResponse func writeScrapeResponse(w http.ResponseWriter, resp *chihaya.ScrapeResponse) error { filesDict := bencode.NewDict() for infohash, scrape := range resp.Files { - filesDict[infohash] = bencode.Dict{ + filesDict[string(infohash)] = bencode.Dict{ "complete": scrape.Complete, "incomplete": scrape.Incomplete, } diff --git a/server/store/middleware/response/response.go b/server/store/middleware/response/response.go index 7ee459e..c79c3fe 100644 --- a/server/store/middleware/response/response.go +++ b/server/store/middleware/response/response.go @@ -46,7 +46,7 @@ func responseScrapeClient(next tracker.ScrapeHandler) tracker.ScrapeHandler { return func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) (err error) { storage := store.MustGetStore() for _, infoHash := range req.InfoHashes { - resp.Files[string(infoHash)] = chihaya.Scrape{ + resp.Files[infoHash] = chihaya.Scrape{ Complete: int32(storage.NumSeeders(infoHash)), Incomplete: int32(storage.NumLeechers(infoHash)), } diff --git a/tracker/tracker.go b/tracker/tracker.go index 11a81f5..c3406c9 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -75,7 +75,9 @@ func (t *Tracker) HandleAnnounce(req *chihaya.AnnounceRequest) (*chihaya.Announc // HandleScrape runs a ScrapeRequest through the Tracker's middleware and // returns the result. func (t *Tracker) HandleScrape(req *chihaya.ScrapeRequest) (*chihaya.ScrapeResponse, error) { - resp := &chihaya.ScrapeResponse{} + resp := &chihaya.ScrapeResponse{ + Files: make(map[chihaya.InfoHash]chihaya.Scrape), + } err := t.handleScrape(t.cfg, req, resp) return resp, err }