Fix fast extension message type constants
iota isn't worth the trouble
This commit is contained in:
parent
d5682e9cd0
commit
54f43419e2
|
@ -6,19 +6,24 @@ import "strconv"
|
|||
|
||||
const (
|
||||
_MessageType_name_0 = "ChokeUnchokeInterestedNotInterestedHaveBitfieldRequestPieceCancelPort"
|
||||
_MessageType_name_1 = "Suggest"
|
||||
_MessageType_name_1 = "SuggestHaveAllHaveNoneRejectAllowedFast"
|
||||
_MessageType_name_2 = "Extended"
|
||||
)
|
||||
|
||||
var (
|
||||
_MessageType_index_0 = [...]uint8{0, 5, 12, 22, 35, 39, 47, 54, 59, 65, 69}
|
||||
_MessageType_index_1 = [...]uint8{0, 7, 14, 22, 28, 39}
|
||||
)
|
||||
|
||||
func (i MessageType) String() string {
|
||||
switch {
|
||||
case 0 <= i && i <= 9:
|
||||
return _MessageType_name_0[_MessageType_index_0[i]:_MessageType_index_0[i+1]]
|
||||
case i == 23:
|
||||
return _MessageType_name_1
|
||||
case 13 <= i && i <= 17:
|
||||
i -= 13
|
||||
return _MessageType_name_1[_MessageType_index_1[i]:_MessageType_index_1[i+1]]
|
||||
case i == 20:
|
||||
return _MessageType_name_2
|
||||
default:
|
||||
return "MessageType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
|
|
|
@ -13,26 +13,30 @@ func (mt MessageType) FastExtension() bool {
|
|||
}
|
||||
|
||||
const (
|
||||
Choke MessageType = iota
|
||||
Unchoke // 1
|
||||
Interested // 2
|
||||
NotInterested // 3
|
||||
Have // 4
|
||||
Bitfield // 5
|
||||
Request // 6
|
||||
Piece // 7
|
||||
Cancel // 8
|
||||
Port // 9
|
||||
// BEP 3
|
||||
Choke MessageType = 0
|
||||
Unchoke MessageType = 1
|
||||
Interested MessageType = 2
|
||||
NotInterested MessageType = 3
|
||||
Have MessageType = 4
|
||||
Bitfield MessageType = 5
|
||||
Request MessageType = 6
|
||||
Piece MessageType = 7
|
||||
Cancel MessageType = 8
|
||||
Port MessageType = 9
|
||||
|
||||
// BEP 6
|
||||
Suggest MessageType = iota + 0xd // 13
|
||||
HaveAll = 0xe // 14
|
||||
HaveNone = 0xf // 15
|
||||
Reject = 0x10 // 16
|
||||
AllowedFast = 0x11 // 17
|
||||
Suggest MessageType = 0x0d // 13
|
||||
HaveAll MessageType = 0x0e // 14
|
||||
HaveNone MessageType = 0x0f // 15
|
||||
Reject MessageType = 0x10 // 16
|
||||
AllowedFast MessageType = 0x11 // 17
|
||||
|
||||
Extended = 20
|
||||
// BEP 10
|
||||
Extended MessageType = 20
|
||||
)
|
||||
|
||||
const (
|
||||
HandshakeExtendedID = 0
|
||||
|
||||
RequestMetadataExtensionMsgType = 0
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBinaryReadSliceOfPointers(t *testing.T) {
|
||||
|
@ -25,10 +27,8 @@ func TestBinaryReadSliceOfPointers(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConstants(t *testing.T) {
|
||||
// check that iota works as expected in the const block
|
||||
if NotInterested != 3 {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.EqualValues(t, 3, NotInterested)
|
||||
assert.EqualValues(t, 14, HaveAll)
|
||||
}
|
||||
|
||||
func TestBitfieldEncode(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue