pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/storage"
"github.com/davecgh/go-spew/spew"
- "github.com/dustin/go-humanize"
+ humanize "github.com/dustin/go-humanize"
"github.com/google/btree"
"golang.org/x/time/rate"
)
}
}
-const debugLogValue = "debug"
+const debugLogValue = log.Debug
func (cl *Client) debugLogFilter(m *log.Msg) bool {
if !cl.config.Debug {
storageImpl = storage.NewFile(cfg.DataDir)
cl.onClose = append(cl.onClose, func() {
if err := storageImpl.Close(); err != nil {
- log.Printf("error closing default storage: %s", err)
+ cl.logger.Printf("error closing default storage: %s", err)
}
})
}
go func() {
ts, err := s.Bootstrap()
if err != nil {
- log.Printf("error bootstrapping dht: %s", err)
+ cl.logger.Printf("error bootstrapping dht: %s", err)
}
- log.Printf("%s: dht bootstrap: %#v", s, ts)
+ log.Str("completed bootstrap").AddValues(s, ts).Log(cl.logger)
}()
}
return
return
}
if err != nil {
- log.Printf("error accepting connection: %s", err)
+ cl.logger.Printf("error accepting connection: %s", err)
continue
}
go func() {
cl.noLongerHalfOpen(t, addr.String())
if err != nil {
if cl.config.Debug {
- log.Printf("error establishing outgoing connection: %s", err)
+ cl.logger.Printf("error establishing outgoing connection: %s", err)
}
return
}
cl.sendInitialMessages(c, t)
err := c.mainReadLoop()
if err != nil && cl.config.Debug {
- log.Printf("error during connection main read loop: %s", err)
+ cl.logger.Printf("error during connection main read loop: %s", err)
}
}
hmp := missinggo.SplitHostMaybePort(n)
ip := net.ParseIP(hmp.Host)
if ip == nil {
- log.Printf("won't add DHT node with bad IP: %q", hmp.Host)
+ cl.logger.Printf("won't add DHT node with bad IP: %q", hmp.Host)
continue
}
ni := krpc.NodeInfo{
return
}
if index >= len(t.metadataCompletedChunks) {
- log.Printf("%s: ignoring metadata piece %d", t, index)
+ t.logger.Printf("%s: ignoring metadata piece %d", t, index)
return
}
copy(t.metadataBytes[(1<<14)*index:], data)
func (t *Torrent) onSetInfo() {
for conn := range t.conns {
if err := conn.setNumPieces(t.numPieces()); err != nil {
- log.Printf("closing connection: %s", err)
+ t.logger.Printf("closing connection: %s", err)
conn.Close()
}
}
t.updatePieceCompletion(pieceIndex(i))
p := &t.pieces[i]
if !p.storageCompletionOk {
- // log.Printf("piece %s completion unknown, queueing check", p)
+ // t.logger.Printf("piece %s completion unknown, queueing check", p)
t.queuePieceCheck(pieceIndex(i))
}
}
return
}
if err != io.ErrUnexpectedEOF && !os.IsNotExist(err) {
- log.Printf("unexpected error hashing piece with %T: %s", t.storage.TorrentImpl, err)
+ t.logger.Printf("unexpected error hashing piece with %T: %s", t.storage.TorrentImpl, err)
}
return
}
if t.pendingPieces.Contains(bitmap.BitIndex(index)) {
return true
}
- // log.Printf("piece %d not pending", index)
+ // t.logger.Printf("piece %d not pending", index)
return !t.forReaderOffsetPieces(func(begin, end pieceIndex) bool {
return index < begin || index >= end
})
}
func (t *Torrent) piecePriorityChanged(piece pieceIndex) {
- // log.Printf("piece %d priority changed", piece)
+ // t.logger.Printf("piece %d priority changed", piece)
for c := range t.conns {
if c.updatePiecePriority(piece) {
// log.Print("conn piece priority changed")
func (t *Torrent) updatePiecePriority(piece pieceIndex) {
p := &t.pieces[piece]
newPrio := p.uncachedPriority()
- // log.Printf("torrent %p: piece %d: uncached priority: %v", t, piece, newPrio)
+ // t.logger.Printf("torrent %p: piece %d: uncached priority: %v", t, piece, newPrio)
if newPrio == PiecePriorityNone {
if !t.pendingPieces.Remove(bitmap.BitIndex(piece)) {
return
p.storageCompletionOk = pcu.Ok
t.completedPieces.Set(bitmap.BitIndex(piece), pcu.Complete)
t.tickleReaders()
- // log.Printf("piece %d uncached completion: %v", piece, pcu.Complete)
- // log.Printf("piece %d changed: %v", piece, changed)
+ // t.logger.Printf("piece %d uncached completion: %v", piece, pcu.Complete)
+ // t.logger.Printf("piece %d changed: %v", piece, changed)
if changed {
t.pieceCompletionChanged(piece)
}
return fmt.Errorf("error setting info bytes: %s", err)
}
if t.cl.config.Debug {
- log.Printf("%s: got metadata from peers", t)
+ t.logger.Printf("%s: got metadata from peers", t)
}
return nil
}
}
u, err := url.Parse(_url)
if err != nil {
- log.Str("error parsing tracker url").AddValues("url", _url).Log(t.logger)
- // TODO: Handle urls with leading '*', some kind of silly uTorrent
- // convention?
+ // URLs with a leading '*' appear to be a uTorrent convention to
+ // disable trackers.
+ if _url[0] != '*' {
+ log.Str("error parsing tracker url").AddValues("url", _url).Log(t.logger)
+ }
return
}
if u.Scheme == "udp" {
if err == nil {
t.numDHTAnnounces++
} else {
- log.Printf("error announcing %q to DHT: %s", t, err)
+ t.logger.Printf("error announcing %q to DHT: %s", t, err)
}
}()
select {
if correct {
pieceHashedCorrect.Add(1)
} else {
- log.Printf("%s: piece %d (%s) failed hash: %d connections contributed", t, piece, p.hash, len(touchers))
+ log.Fmsg("piece failed hash: %d connections contributed", len(touchers)).AddValue(t, p).Log(t.logger)
pieceHashedNotCorrect.Add(1)
}
}
}
err := p.Storage().MarkComplete()
if err != nil {
- log.Printf("%T: error marking piece complete %d: %s", t.storage, piece, err)
+ t.logger.Printf("%T: error marking piece complete %d: %s", t.storage, piece, err)
}
} else {
if len(touchers) != 0 {
}
slices.Sort(touchers, connLessTrusted)
if t.cl.config.Debug {
- log.Printf("dropping first corresponding conn from trust: %v", func() (ret []int64) {
+ t.logger.Printf("dropping first corresponding conn from trust: %v", func() (ret []int64) {
for _, c := range touchers {
ret = append(ret, c.netGoodPiecesDirtied())
}
t.pendAllChunkSpecs(piece)
}
if !t.wantPieceIndex(piece) {
- // log.Printf("piece %d incomplete and unwanted", piece)
+ // t.logger.Printf("piece %d incomplete and unwanted", piece)
return
}
// We could drop any connections that we told we have a piece that we