-
-
Notifications
You must be signed in to change notification settings - Fork 628
/
callbacks.go
56 lines (48 loc) · 1.97 KB
/
callbacks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package torrent
import (
"github.com/anacrolix/torrent/mse"
pp "github.com/anacrolix/torrent/peer_protocol"
)
// 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 {
// Called after a peer connection completes the BitTorrent handshake. The Client lock is not
// held.
CompletedHandshake func(*PeerConn, InfoHash)
ReadMessage func(*PeerConn, *pp.Message)
// This can be folded into the general case below.
ReadExtendedHandshake func(*PeerConn, *pp.ExtendedHandshakeMessage)
PeerConnClosed func(*PeerConn)
// BEP 10 message. Not sure if I should call this Ltep universally. Each handler here is called
// in order.
PeerConnReadExtensionMessage []func(PeerConnReadExtensionMessageEvent)
// 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)
// Called when a PeerConn has been added to a Torrent. It's finished all BitTorrent protocol
// handshakes, and is about to start sending and receiving BitTorrent messages. The extended
// handshake has not yet occurred. This is a good time to alter the supported extension
// protocols.
PeerConnAdded []func(*PeerConn)
}
type ReceivedUsefulDataEvent = PeerMessageEvent
type PeerMessageEvent struct {
Peer *Peer
Message *pp.Message
}
type PeerRequestEvent struct {
Peer *Peer
Request
}
type PeerConnReadExtensionMessageEvent struct {
PeerConn *PeerConn
// You can look up what protocol this corresponds to using the PeerConn.LocalLtepProtocolMap.
ExtensionNumber pp.ExtensionNumber
Payload []byte
}