]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reinstate cmd/announce announce subcommand
authorMatt Joiner <anacrolix@gmail.com>
Mon, 4 Jan 2021 02:37:44 +0000 (13:37 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 4 Jan 2021 02:37:44 +0000 (13:37 +1100)
cmd/torrent/announce.go
cmd/torrent/main.go
metainfo/hash.go

index 5bb72fd12c327ea6f4a00de0fdbf963f9bba7f13..990688a2621a5cf6ee149c85b8a7e122ab5b8076 100644 (file)
@@ -3,20 +3,18 @@ package main
 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{
index 1cc7992398657dc18f083015d882fee5e249a5f9..59b2ddf7228ffdec1b974d790d2f08913b709cc4 100644 (file)
@@ -159,25 +159,10 @@ var flags struct {
        *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"`
@@ -243,6 +228,8 @@ func mainErr() error {
        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:
index 41ee956613de131b5f6c3280f79992c7174e7ae8..b2bab751b6564927590562c3ab28a2fb3f5e37f7 100644 (file)
@@ -2,6 +2,7 @@ package metainfo
 
 import (
        "crypto/sha1"
+       "encoding"
        "encoding/hex"
        "fmt"
 )
@@ -11,7 +12,10 @@ const HashSize = 20
 // 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
@@ -50,6 +54,10 @@ func (h *Hash) FromHexString(s string) (err error) {
        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 {