Add ReceivedUsefulData Callback
This commit is contained in:
parent
27108bd2f7
commit
669905e203
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue