]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve cmd/tracker-announce output
authorMatt Joiner <anacrolix@gmail.com>
Wed, 20 May 2020 02:04:53 +0000 (12:04 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 20 May 2020 02:04:53 +0000 (12:04 +1000)
cmd/tracker-announce/main.go
tracker/peer.go

index 6f63b295b583527bbdcf72fef8ab92e878f8f537..8d9681dd4f94c75bdc9defd8059bc8a4814d4d01 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "fmt"
        "log"
        "net/url"
        "os"
@@ -8,8 +9,6 @@ import (
        "sync"
        "sync/atomic"
 
-       "github.com/davecgh/go-spew/spew"
-
        "github.com/anacrolix/tagflag"
 
        "github.com/anacrolix/torrent"
@@ -76,7 +75,7 @@ func doTracker(tURI string, ar tracker.AnnounceRequest) (hadError bool) {
                        log.Printf("error announcing to %q: %s", tURI, err)
                        continue
                }
-               spew.Dump(resp)
+               fmt.Printf("response from %q: %+v\n", tURI, resp)
        }
        return
 }
index 91af5f94741bede1ec0b9bcad21266d0dd132913..3cda3dc3a520525116ff3d7bc6538e8391f67cea 100644 (file)
@@ -1,6 +1,7 @@
 package tracker
 
 import (
+       "fmt"
        "net"
 
        "github.com/anacrolix/dht/v2/krpc"
@@ -12,6 +13,15 @@ type Peer struct {
        ID   []byte
 }
 
+func (p Peer) String() string {
+       loc := net.JoinHostPort(p.IP.String(), fmt.Sprintf("%d", p.Port))
+       if len(p.ID) != 0 {
+               return fmt.Sprintf("%x at %s", p.ID, loc)
+       } else {
+               return loc
+       }
+}
+
 // Set from the non-compact form in BEP 3.
 func (p *Peer) FromDictInterface(d map[string]interface{}) {
        p.IP = net.ParseIP(d["ip"].(string))