udp: Implement scrapes

This commit is contained in:
Justin Li
2015-02-20 12:35:31 -05:00
parent be5720dadd
commit 9526df74ad
2 changed files with 59 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ import (
type Writer struct {
buf *bytes.Buffer
connectionID []byte
transactionID []byte
}
@@ -40,6 +41,13 @@ func (w *Writer) WriteAnnounce(res *models.AnnounceResponse) error {
func (w *Writer) WriteScrape(res *models.ScrapeResponse) error {
w.writeHeader(2)
for _, torrent := range res.Files {
binary.Write(w.buf, binary.BigEndian, uint32(torrent.Seeders.Len()))
binary.Write(w.buf, binary.BigEndian, uint32(torrent.Snatches))
binary.Write(w.buf, binary.BigEndian, uint32(torrent.Leechers.Len()))
}
return nil
}