hotfix: initialized scrape map

This commit is contained in:
Leo Balduf 2016-04-02 20:22:15 -04:00
parent cd979c61c9
commit 9c1168746a
5 changed files with 9 additions and 6 deletions

View file

@ -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.

View file

@ -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

View file

@ -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,
}

View file

@ -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)),
}

View file

@ -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
}