import (
"fmt"
- "github.com/anacrolix/tagflag"
"github.com/davecgh/go-spew/spew"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/tracker"
)
-func announceErr(args []string, parent *tagflag.Parser) error {
- var flags struct {
- tagflag.StartPos
- Tracker string
- InfoHash torrent.InfoHash
- }
- tagflag.ParseArgs(&flags, args, tagflag.Parent(parent))
+type AnnounceCmd struct {
+ Tracker string `arg:"positional"`
+ InfoHash torrent.InfoHash
+}
+
+func announceErr() error {
response, err := tracker.Announce{
TrackerUrl: flags.Tracker,
Request: tracker.AnnounceRequest{
*DownloadCmd `arg:"subcommand:download"`
*ListFilesCmd `arg:"subcommand:list-files"`
*SpewBencodingCmd `arg:"subcommand:spew-bencoding"`
+ *AnnounceCmd `arg:"subcommand:announce"`
}
-type SpewBencodingCmd struct {
-}
-
-//DownloadCmd: &DownloadCmd{
-// UploadRate: -1,
-// DownloadRate: -1,
-// Progress: true,
-// Dht: true,
-//
-// TcpPeers: true,
-// UtpPeers: true,
-// Webtorrent: true,
-//
-// Ipv4: true,
-// Ipv6: true,
-// Pex: true,
-//},
+type SpewBencodingCmd struct{}
type DownloadCmd struct {
Mmap bool `help:"memory-map torrent data"`
stdLog.SetFlags(stdLog.Flags() | stdLog.Lshortfile)
p := arg.MustParse(&flags)
switch {
+ case flags.AnnounceCmd != nil:
+ return announceErr()
//case :
// return announceErr(flags.Args, parser)
case flags.DownloadCmd != nil:
import (
"crypto/sha1"
+ "encoding"
"encoding/hex"
"fmt"
)
// 20-byte SHA1 hash used for info and pieces.
type Hash [HashSize]byte
-var _ fmt.Formatter = (*Hash)(nil)
+var (
+ _ fmt.Formatter = (*Hash)(nil)
+ _ encoding.TextUnmarshaler = (*Hash)(nil)
+)
func (h Hash) Format(f fmt.State, c rune) {
// TODO: I can't figure out a nice way to just override the 'x' rune, since it's meaningless
return
}
+func (h *Hash) UnmarshalText(b []byte) error {
+ return h.FromHexString(string(b))
+}
+
func NewHashFromHex(s string) (h Hash) {
err := h.FromHexString(s)
if err != nil {