Add some String methods and contextual information in log messages
This commit is contained in:
parent
0dee5d9952
commit
0f3c4cb3ec
|
@ -632,7 +632,7 @@ newAnnounce:
|
|||
log.Print(err)
|
||||
return
|
||||
}
|
||||
log.Printf("%d new peers from %s", len(peers), "TODO")
|
||||
log.Printf("%s: %d new peers from %s", t, len(peers), tr)
|
||||
tier[0], tier[trIndex] = tier[trIndex], tier[0]
|
||||
time.Sleep(time.Second * time.Duration(resp.Interval))
|
||||
continue newAnnounce
|
||||
|
@ -755,7 +755,7 @@ func (me *Client) pieceHashed(t *torrent, piece peer_protocol.Integer, correct b
|
|||
p.EverHashed = true
|
||||
if correct {
|
||||
p.PendingChunkSpecs = nil
|
||||
log.Printf("got piece %d, (%d/%d)", piece, t.NumPiecesCompleted(), t.NumPieces())
|
||||
log.Printf("%s: got piece %d, (%d/%d)", t, piece, t.NumPiecesCompleted(), t.NumPieces())
|
||||
var next *list.Element
|
||||
if t.Priorities != nil {
|
||||
for e := t.Priorities.Front(); e != nil; e = next {
|
||||
|
|
|
@ -37,6 +37,10 @@ type torrent struct {
|
|||
Trackers [][]tracker.Client
|
||||
}
|
||||
|
||||
func (t *torrent) String() string {
|
||||
return t.MetaInfo.Name
|
||||
}
|
||||
|
||||
func (t *torrent) NumPieces() int {
|
||||
return len(t.MetaInfo.Pieces) / pieceHash.Size()
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ type Client interface {
|
|||
// Returns ErrNotConnected if Connect needs to be called.
|
||||
Announce(*AnnounceRequest) (AnnounceResponse, error)
|
||||
Connect() error
|
||||
String() string
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -87,6 +87,10 @@ type client struct {
|
|||
url *url.URL
|
||||
}
|
||||
|
||||
func (c *client) String() string {
|
||||
return c.url.String()
|
||||
}
|
||||
|
||||
func (c *client) Announce(req *tracker.AnnounceRequest) (res tracker.AnnounceResponse, err error) {
|
||||
if !c.connected() {
|
||||
err = tracker.ErrNotConnected
|
||||
|
|
Loading…
Reference in New Issue