2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Adjust recently added logging

This commit is contained in:
Matt Joiner 2020-04-16 12:17:18 +10:00
parent 730cebf5aa
commit 070e11a0dd
3 changed files with 14 additions and 2 deletions

View File

@ -20,6 +20,15 @@ type Peer struct {
Trusted bool
}
func (me Peer) Equal(other Peer) bool {
return me.Id == other.Id &&
me.Addr.String() == other.Addr.String() &&
me.Source == other.Source &&
me.SupportsEncryption == other.SupportsEncryption &&
me.PexPeerFlags == other.PexPeerFlags &&
me.Trusted == other.Trusted
}
// FromPex generate Peer from peer exchange
func (me *Peer) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
me.Addr = ipPortAddr{append([]byte(nil), na.IP...), na.Port}

View File

@ -269,8 +269,10 @@ func (t *Torrent) addPeer(p Peer) {
}
if replaced, ok := t.peers.AddReturningReplacedPeer(p); ok {
torrent.Add("peers replaced", 1)
if !replaced.Equal(p) {
t.logger.Printf("added %v replacing %v", p, replaced)
}
}
t.openNewConns()
for t.peers.Len() > cl.config.TorrentPeersHighWater {
_, ok := t.peers.DeleteMin()

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/anacrolix/dht/v2/krpc"
"github.com/anacrolix/log"
"github.com/anacrolix/torrent/tracker"
)
@ -116,7 +117,7 @@ func (me *trackerScraper) announce(event tracker.AnnounceEvent) (ret trackerAnno
me.t.cl.rLock()
req := me.t.announceRequest(event)
me.t.cl.rUnlock()
me.t.logger.Printf("announcing to %q: %#v", me.u.String(), req)
me.t.logger.WithValues(log.Debug).Printf("announcing to %q: %#v", me.u.String(), req)
res, err := tracker.Announce{
HTTPProxy: me.t.cl.config.HTTPProxy,
UserAgent: me.t.cl.config.HTTPUserAgent,