Add some String methods and contextual information in log messages

This commit is contained in:
Matt Joiner 2014-05-21 00:52:49 +10:00
parent 0dee5d9952
commit 0f3c4cb3ec
4 changed files with 11 additions and 2 deletions

View File

@ -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 {

View File

@ -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()
}

View File

@ -44,6 +44,7 @@ type Client interface {
// Returns ErrNotConnected if Connect needs to be called.
Announce(*AnnounceRequest) (AnnounceResponse, error)
Connect() error
String() string
}
var (

View File

@ -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