Add a scrape command so I can work out if trackers are seeing my test clients

I don't even know if scrape is the right word.
This commit is contained in:
Matt Joiner 2014-03-20 04:30:32 +11:00
parent 9ee83455cf
commit 771a08d4f4
1 changed files with 39 additions and 0 deletions

39
cmd/scrape/main.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"bitbucket.org/anacrolix/go.torrent"
"bitbucket.org/anacrolix/go.torrent/tracker"
_ "bitbucket.org/anacrolix/go.torrent/tracker/udp"
"flag"
metainfo "github.com/nsf/libtorgo/torrent"
"log"
"os"
)
func main() {
flag.Parse()
mi, err := metainfo.Load(os.Stdin)
if err != nil {
log.Fatal(err)
}
for _, tier := range mi.AnnounceList {
for _, url := range tier {
tr, err := tracker.New(url)
if err != nil {
log.Fatal(err)
}
err = tr.Connect()
if err != nil {
log.Fatal(err)
}
resp, err := tr.Announce(&tracker.AnnounceRequest{
NumWant: -1,
InfoHash: torrent.BytesInfoHash(mi.InfoHash),
})
if err != nil {
log.Fatal(err)
}
log.Print(resp)
}
}
}