preserve Incomplete/Complete

This commit is contained in:
Victor Shyba 2022-04-13 21:01:25 -03:00
parent 737053bd0e
commit c8f0c1eed8
2 changed files with 7 additions and 3 deletions

View file

@ -53,11 +53,15 @@ func NewHook(cfg Config) (middleware.Hook, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
ip := net.ParseIP(parts[0]).To4()
if ip == nil {
panic("Invalid ip4 on fixed_peers")
}
peers = append(peers, peers = append(peers,
bittorrent.Peer{ bittorrent.Peer{
ID: bittorrent.PeerID{0}, ID: bittorrent.PeerID{0},
Port: uint16(port), Port: uint16(port),
IP: bittorrent.IP{net.ParseIP(parts[0]), bittorrent.IPv4}, IP: bittorrent.IP{IP: ip},
}) })
} }
h := &hook{ h := &hook{

View file

@ -98,8 +98,8 @@ func (h *responseHook) HandleAnnounce(ctx context.Context, req *bittorrent.Annou
// Add the Scrape data to the response. // Add the Scrape data to the response.
s := h.store.ScrapeSwarm(req.InfoHash, req.IP.AddressFamily) s := h.store.ScrapeSwarm(req.InfoHash, req.IP.AddressFamily)
resp.Incomplete = s.Incomplete resp.Incomplete += s.Incomplete
resp.Complete = s.Complete resp.Complete += s.Complete
err = h.appendPeers(req, resp) err = h.appendPeers(req, resp)
return ctx, err return ctx, err