Add ReceivedUsefulData Callback

This commit is contained in:
Matt Joiner 2021-01-20 14:22:44 +11:00
parent 27108bd2f7
commit 669905e203
2 changed files with 10 additions and 0 deletions

View File

@ -18,4 +18,11 @@ type Callbacks struct {
// Provides secret keys to be tried against incoming encrypted connections.
ReceiveEncryptedHandshakeSkeys mse.SecretKeyIter
ReceivedUsefulData []func(ReceivedUsefulDataEvent)
}
type ReceivedUsefulDataEvent struct {
Peer *Peer
Message *pp.Message
}

View File

@ -1378,6 +1378,9 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {
c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.ChunksReadUseful }))
c.allStats(add(int64(len(msg.Piece)), func(cs *ConnStats) *Count { return &cs.BytesReadUsefulData }))
for _, f := range c.t.cl.config.Callbacks.ReceivedUsefulData {
f(ReceivedUsefulDataEvent{c, msg})
}
c.lastUsefulChunkReceived = time.Now()
// if t.fastestPeer != c {
// log.Printf("setting fastest connection %p", c)