]> Sergey Matveev's repositories - btrtrc.git/blob - cmd/torrent/announce.go
cmd/torrent: Restore the announce and bencode subcommands
[btrtrc.git] / cmd / torrent / announce.go
1 package main
2
3 import (
4         "fmt"
5
6         "github.com/davecgh/go-spew/spew"
7
8         "github.com/anacrolix/torrent"
9         "github.com/anacrolix/torrent/tracker"
10 )
11
12 type AnnounceCmd struct {
13         Tracker  string           `arg:"positional"`
14         InfoHash torrent.InfoHash `arg:"positional"`
15 }
16
17 func announceErr(flags AnnounceCmd) error {
18         response, err := tracker.Announce{
19                 TrackerUrl: flags.Tracker,
20                 Request: tracker.AnnounceRequest{
21                         InfoHash: flags.InfoHash,
22                         Port:     uint16(torrent.NewDefaultClientConfig().ListenPort),
23                         NumWant:  -1,
24                 },
25         }.Do()
26         if err != nil {
27                 return fmt.Errorf("doing announce: %w", err)
28         }
29         spew.Dump(response)
30         return nil
31 }