]> Sergey Matveev's repositories - btrtrc.git/blob - peer_protocol/protocol.go
Support AllowedFast and enable fast extension
[btrtrc.git] / peer_protocol / protocol.go
1 package peer_protocol
2
3 import "strconv"
4
5 const (
6         Protocol = "\x13BitTorrent protocol"
7 )
8
9 type (
10         MessageType byte
11 )
12
13 // Hopefully uncaught panics format using this so we don't just see a pair of
14 // unhelpful uintptrs.
15 func (me MessageType) String() string {
16         return strconv.FormatInt(int64(me), 10)
17 }
18
19 func (mt MessageType) FastExtension() bool {
20         return mt >= Suggest && mt <= AllowedFast
21 }
22
23 const (
24         Choke         MessageType = iota
25         Unchoke                   // 1
26         Interested                // 2
27         NotInterested             // 3
28         Have                      // 4
29         Bitfield                  // 5
30         Request                   // 6
31         Piece                     // 7
32         Cancel                    // 8
33         Port                      // 9
34
35         // BEP 6
36         Suggest     = 0xd  // 13
37         HaveAll     = 0xe  // 14
38         HaveNone    = 0xf  // 15
39         Reject      = 0x10 // 16
40         AllowedFast = 0x11 // 17
41
42         Extended = 20
43
44         HandshakeExtendedID = 0
45
46         RequestMetadataExtensionMsgType = 0
47         DataMetadataExtensionMsgType    = 1
48         RejectMetadataExtensionMsgType  = 2
49 )