2020-07-15 12:00:47 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2020-11-05 10:28:45 +08:00
|
|
|
"github.com/anacrolix/torrent/mse"
|
2020-07-15 12:00:47 +08:00
|
|
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
|
|
|
)
|
|
|
|
|
2020-11-05 10:28:45 +08:00
|
|
|
// 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.
|
2020-07-15 12:00:47 +08:00
|
|
|
type Callbacks struct {
|
2020-11-05 10:28:45 +08:00
|
|
|
// Called after a peer connection completes the BitTorrent handshake. The Client lock is not
|
|
|
|
// held.
|
|
|
|
CompletedHandshake func(*PeerConn, InfoHash)
|
2020-07-15 14:16:09 +08:00
|
|
|
ReadMessage func(*PeerConn, *pp.Message)
|
|
|
|
ReadExtendedHandshake func(*PeerConn, *pp.ExtendedHandshakeMessage)
|
2020-10-13 10:02:39 +08:00
|
|
|
PeerConnClosed func(*PeerConn)
|
2020-11-05 10:28:45 +08:00
|
|
|
|
|
|
|
// Provides secret keys to be tried against incoming encrypted connections.
|
|
|
|
ReceiveEncryptedHandshakeSkeys mse.SecretKeyIter
|
2021-01-20 11:22:44 +08:00
|
|
|
|
|
|
|
ReceivedUsefulData []func(ReceivedUsefulDataEvent)
|
2021-01-28 11:23:22 +08:00
|
|
|
ReceivedRequested []func(PeerMessageEvent)
|
|
|
|
DeletedRequest []func(PeerRequestEvent)
|
|
|
|
SentRequest []func(PeerRequestEvent)
|
|
|
|
PeerClosed []func(*Peer)
|
|
|
|
NewPeer []func(*Peer)
|
2021-01-20 11:22:44 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 11:23:22 +08:00
|
|
|
type ReceivedUsefulDataEvent = PeerMessageEvent
|
|
|
|
|
|
|
|
type PeerMessageEvent struct {
|
2021-01-20 11:22:44 +08:00
|
|
|
Peer *Peer
|
|
|
|
Message *pp.Message
|
2020-07-15 12:00:47 +08:00
|
|
|
}
|
2021-01-28 11:23:22 +08:00
|
|
|
|
|
|
|
type PeerRequestEvent struct {
|
|
|
|
Peer *Peer
|
|
|
|
Request
|
|
|
|
}
|