Merge pull request #153 from mrd0ll4r/middleware-smallfix
hotfix: initialized scrape map
This commit is contained in:
commit
d5c00c24b1
5 changed files with 9 additions and 6 deletions
|
@ -51,7 +51,7 @@ type ScrapeRequest struct {
|
||||||
|
|
||||||
// ScrapeResponse represents the parameters used to create a scrape response.
|
// ScrapeResponse represents the parameters used to create a scrape response.
|
||||||
type ScrapeResponse struct {
|
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.
|
// Scrape represents the state of a swarm that is returned in a scrape response.
|
||||||
|
|
|
@ -15,14 +15,15 @@ import (
|
||||||
"github.com/chihaya/chihaya/server"
|
"github.com/chihaya/chihaya/server"
|
||||||
"github.com/chihaya/chihaya/tracker"
|
"github.com/chihaya/chihaya/tracker"
|
||||||
|
|
||||||
|
_ "github.com/chihaya/chihaya/middleware/deniability"
|
||||||
_ "github.com/chihaya/chihaya/server/http"
|
_ "github.com/chihaya/chihaya/server/http"
|
||||||
_ "github.com/chihaya/chihaya/server/prometheus"
|
_ "github.com/chihaya/chihaya/server/prometheus"
|
||||||
_ "github.com/chihaya/chihaya/server/store"
|
_ "github.com/chihaya/chihaya/server/store"
|
||||||
_ "github.com/chihaya/chihaya/server/store/memory"
|
_ "github.com/chihaya/chihaya/server/store/memory"
|
||||||
_ "github.com/chihaya/chihaya/server/store/middleware/client"
|
_ "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/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
|
var configPath string
|
||||||
|
|
|
@ -71,7 +71,7 @@ func writeAnnounceResponse(w http.ResponseWriter, resp *chihaya.AnnounceResponse
|
||||||
func writeScrapeResponse(w http.ResponseWriter, resp *chihaya.ScrapeResponse) error {
|
func writeScrapeResponse(w http.ResponseWriter, resp *chihaya.ScrapeResponse) error {
|
||||||
filesDict := bencode.NewDict()
|
filesDict := bencode.NewDict()
|
||||||
for infohash, scrape := range resp.Files {
|
for infohash, scrape := range resp.Files {
|
||||||
filesDict[infohash] = bencode.Dict{
|
filesDict[string(infohash)] = bencode.Dict{
|
||||||
"complete": scrape.Complete,
|
"complete": scrape.Complete,
|
||||||
"incomplete": scrape.Incomplete,
|
"incomplete": scrape.Incomplete,
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func responseScrapeClient(next tracker.ScrapeHandler) tracker.ScrapeHandler {
|
||||||
return func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) (err error) {
|
return func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) (err error) {
|
||||||
storage := store.MustGetStore()
|
storage := store.MustGetStore()
|
||||||
for _, infoHash := range req.InfoHashes {
|
for _, infoHash := range req.InfoHashes {
|
||||||
resp.Files[string(infoHash)] = chihaya.Scrape{
|
resp.Files[infoHash] = chihaya.Scrape{
|
||||||
Complete: int32(storage.NumSeeders(infoHash)),
|
Complete: int32(storage.NumSeeders(infoHash)),
|
||||||
Incomplete: int32(storage.NumLeechers(infoHash)),
|
Incomplete: int32(storage.NumLeechers(infoHash)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,9 @@ func (t *Tracker) HandleAnnounce(req *chihaya.AnnounceRequest) (*chihaya.Announc
|
||||||
// HandleScrape runs a ScrapeRequest through the Tracker's middleware and
|
// HandleScrape runs a ScrapeRequest through the Tracker's middleware and
|
||||||
// returns the result.
|
// returns the result.
|
||||||
func (t *Tracker) HandleScrape(req *chihaya.ScrapeRequest) (*chihaya.ScrapeResponse, error) {
|
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)
|
err := t.handleScrape(t.cfg, req, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue