Also use a new helper in Logger to simplify things.
StartingNodes: cl.config.DhtStartingNodes(conn.LocalAddr().Network()),
ConnectionTracking: cl.config.ConnTracker,
OnQuery: cl.config.DHTOnQuery,
- Logger: cl.logger.WithText(func(m log.Msg) string {
- return fmt.Sprintf("dht server on %v: %s", conn.LocalAddr().String(), m.Text())
- }),
+ Logger: cl.logger.WithContextText(fmt.Sprintf("dht server on %v", conn.LocalAddr().String())),
}
s, err = dht.NewServer(&cfg)
if err == nil {
}
t._pendingPieces.NewSet = priorityBitmapStableNewSet
t.requestStrategy = cl.config.DefaultRequestStrategy(t.requestStrategyCallbacks(), &cl._mu)
- t.logger = cl.logger.WithValues(t).WithText(func(m log.Msg) string {
- return fmt.Sprintf("%v: %s", t, m.Text())
- })
+ t.logger = cl.logger.WithContextValue(t)
t.setChunkSize(defaultChunkSize)
return
}
writeBuffer: new(bytes.Buffer),
}
c.peerImpl = c
- c.logger = cl.logger.WithValues(c).WithDefaultLevel(log.Debug).WithText(func(m log.Msg) string {
- return fmt.Sprintf("%v: %s", c, m.Text())
- })
+ c.logger = cl.logger.WithDefaultLevel(log.Debug).WithContextValue(c)
c.writerCond.L = cl.locker()
c.setRW(connStatsReadWriter{nc, c})
c.r = &rateLimitedReader{
github.com/anacrolix/dht/v2 v2.6.1-0.20200416071723-3850fa1b802a
github.com/anacrolix/envpprof v1.1.0
github.com/anacrolix/go-libutp v1.0.2
- github.com/anacrolix/log v0.7.0
+ github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d
github.com/anacrolix/missinggo v1.2.1
github.com/anacrolix/missinggo/perf v1.0.0
github.com/anacrolix/missinggo/v2 v2.4.1-0.20200419051441-747d9d7544c6
github.com/anacrolix/log v0.6.1-0.20200416071330-f58a030e6149/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.7.0 h1:koGkC/K0LjIbrhLhwfpsfMuvu8nhvY7J4TmLVc1mAwE=
github.com/anacrolix/log v0.7.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
+github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d h1:AkY1QtaxDBPLr1hrxLD8tUL04EPI0asYc2VB8v7Bg2U=
+github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+7cn+rWMIphK1gDH2hrDuwGOcbB6V4VXeSsEfHVk=
github.com/anacrolix/missinggo v0.0.0-20180725070939-60ef2fbf63df/go.mod h1:kwGiTUTZ0+p4vAz3VbAI5a30t2YbvemcmspjKwrAz5s=
github.com/anacrolix/missinggo v0.2.1-0.20190310234110-9fbdc9f242a8 h1:E2Xb2SBsVzHJ1tNMW9QcckYEQcyBKz1ee8qVjeVRWys=
_postCancel(request)
onGotInfo(*metainfo.Info)
drop()
+ String() string
}
},
requests: make(map[request]webseed.Request, maxRequests),
}
+ ws.peer.logger = t.logger.WithContextValue(&ws)
ws.peer.peerImpl = &ws
if t.haveInfo() {
ws.onGotInfo(t.info)
package torrent
import (
+ "fmt"
"net/http"
- "github.com/anacrolix/log"
"github.com/anacrolix/torrent/common"
"github.com/anacrolix/torrent/metainfo"
pp "github.com/anacrolix/torrent/peer_protocol"
var _ peerImpl = (*webSeed)(nil)
+func (ws *webSeed) String() string {
+ return fmt.Sprintf("webseed peer for %q", ws.client.Url)
+}
+
func (ws *webSeed) onGotInfo(info *metainfo.Info) {
ws.client.FileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles()))
ws.client.Info = info
ws.peer.t.cl.lock()
defer ws.peer.t.cl.unlock()
if result.Err != nil {
- log.Printf("webseed request rejected: %v", result.Err)
+ ws.peer.logger.Printf("request %v rejected: %v", r, result.Err)
ws.peer.remoteRejectedRequest(r)
} else {
err := ws.peer.receiveChunk(&pp.Message{