]> Sergey Matveev's repositories - btrtrc.git/blob - callbacks.go
cmd/btrtrc client
[btrtrc.git] / callbacks.go
1 package torrent
2
3 import (
4         "github.com/anacrolix/torrent/mse"
5         pp "github.com/anacrolix/torrent/peer_protocol"
6 )
7
8 // These are called synchronously, and do not pass ownership of arguments (do not expect to retain
9 // data after returning from the callback). The Client and other locks may still be held. nil
10 // functions are not called.
11 type Callbacks struct {
12         // Called after a peer connection completes the BitTorrent handshake. The Client lock is not
13         // held.
14         CompletedHandshake func(*PeerConn, InfoHash)
15         ReadMessage        func(*PeerConn, *pp.Message)
16         // This can be folded into the general case below.
17         ReadExtendedHandshake func(*PeerConn, *pp.ExtendedHandshakeMessage)
18         PeerConnClosed        func(*PeerConn)
19         // BEP 10 message. Not sure if I should call this Ltep universally. Each handler here is called
20         // in order.
21         PeerConnReadExtensionMessage []func(PeerConnReadExtensionMessageEvent)
22
23         // Provides secret keys to be tried against incoming encrypted connections.
24         ReceiveEncryptedHandshakeSkeys mse.SecretKeyIter
25
26         ReceivedUsefulData []func(ReceivedUsefulDataEvent)
27         ReceivedRequested  []func(PeerMessageEvent)
28         DeletedRequest     []func(PeerRequestEvent)
29         SentRequest        []func(PeerRequestEvent)
30         PeerClosed         []func(*Peer)
31         NewPeer            []func(*Peer)
32         // Called when a PeerConn has been added to a Torrent. It's finished all BitTorrent protocol
33         // handshakes, and is about to start sending and receiving BitTorrent messages. The extended
34         // handshake has not yet occurred. This is a good time to alter the supported extension
35         // protocols.
36         PeerConnAdded []func(*PeerConn)
37 }
38
39 type ReceivedUsefulDataEvent = PeerMessageEvent
40
41 type PeerMessageEvent struct {
42         Peer    *Peer
43         Message *pp.Message
44 }
45
46 type PeerRequestEvent struct {
47         Peer *Peer
48         Request
49 }
50
51 type PeerConnReadExtensionMessageEvent struct {
52         PeerConn *PeerConn
53         // You can look up what protocol this corresponds to using the PeerConn.LocalLtepProtocolMap.
54         ExtensionNumber pp.ExtensionNumber
55         Payload         []byte
56 }