diff --git a/callbacks.go b/callbacks.go index fa9fea5b..f78c5854 100644 --- a/callbacks.go +++ b/callbacks.go @@ -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 } diff --git a/peerconn.go b/peerconn.go index 4fcb4f3d..25d29b34 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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)