]> Sergey Matveev's repositories - btrtrc.git/blobdiff - callbacks.go
Drop support for go 1.20
[btrtrc.git] / callbacks.go
index 0e73d80993e0d207a52a43769358ac1bc7971084..f9ba131b136e8859a801837c275f4c247ae60904 100644 (file)
@@ -1,13 +1,40 @@
 package torrent
 
 import (
+       "github.com/anacrolix/torrent/mse"
        pp "github.com/anacrolix/torrent/peer_protocol"
 )
 
-// These are called synchronously, and do not pass ownership. The Client and other locks may still
-// be held. nil functions are not called.
+// These are called synchronously, and do not pass ownership of arguments (do not expect to retain
+// data after returning from the callback). The Client and other locks may still be held. nil
+// functions are not called.
 type Callbacks struct {
-       CompletedHandshake    func(_ *PeerConn, infoHash InfoHash)
+       // Called after a peer connection completes the BitTorrent handshake. The Client lock is not
+       // held.
+       CompletedHandshake    func(*PeerConn, InfoHash)
        ReadMessage           func(*PeerConn, *pp.Message)
        ReadExtendedHandshake func(*PeerConn, *pp.ExtendedHandshakeMessage)
+       PeerConnClosed        func(*PeerConn)
+
+       // Provides secret keys to be tried against incoming encrypted connections.
+       ReceiveEncryptedHandshakeSkeys mse.SecretKeyIter
+
+       ReceivedUsefulData []func(ReceivedUsefulDataEvent)
+       ReceivedRequested  []func(PeerMessageEvent)
+       DeletedRequest     []func(PeerRequestEvent)
+       SentRequest        []func(PeerRequestEvent)
+       PeerClosed         []func(*Peer)
+       NewPeer            []func(*Peer)
+}
+
+type ReceivedUsefulDataEvent = PeerMessageEvent
+
+type PeerMessageEvent struct {
+       Peer    *Peer
+       Message *pp.Message
+}
+
+type PeerRequestEvent struct {
+       Peer *Peer
+       Request
 }