Commit 46b8b4f7 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 607e8e46
...@@ -26,7 +26,6 @@ import ( ...@@ -26,7 +26,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
) )
// XXX name -> zodbErrEncode, zodbErrDecode ? // XXX name -> zodbErrEncode, zodbErrDecode ?
// XXX should be not in proto/ ? // XXX should be not in proto/ ?
...@@ -71,7 +70,7 @@ func ErrDecode(e *Error) error { ...@@ -71,7 +70,7 @@ func ErrDecode(e *Error) error {
return &zodb.NoDataError{Oid: oid, DeletedAt: del} return &zodb.NoDataError{Oid: oid, DeletedAt: del}
case OID_DOES_NOT_EXIST: case OID_DOES_NOT_EXIST:
oid, err := zodb.ParseOid(e.Message) // XXX abusing message for oid oid, err := zodb.ParseOid(e.Message) // XXX abusing message for oid
if err == nil { if err == nil {
return &zodb.NoObjectError{oid} return &zodb.NoObjectError{oid}
} }
......
...@@ -79,8 +79,7 @@ func (nodeUUID NodeUUID) String() string { ...@@ -79,8 +79,7 @@ func (nodeUUID NodeUUID) String() string {
//temp := typ&(1 << 7) != 0 //temp := typ&(1 << 7) != 0
//typ &= 1<<7 - 1 //typ &= 1<<7 - 1
//nodeType := typ >> 4 //nodeType := typ >> 4
typ := uint8(-int8(nodeUUID >> 24)) >> 4 typ := uint8(-int8(nodeUUID>>24)) >> 4
if typ < 4 { if typ < 4 {
return fmt.Sprintf("%c%d", nodeTypeChar[typ], num) return fmt.Sprintf("%c%d", nodeTypeChar[typ], num)
...@@ -88,7 +87,6 @@ func (nodeUUID NodeUUID) String() string { ...@@ -88,7 +87,6 @@ func (nodeUUID NodeUUID) String() string {
return fmt.Sprintf("?(%d)%d", typ, num) return fmt.Sprintf("?(%d)%d", typ, num)
/* /*
// 's1', 'm2', for temporary nids // 's1', 'm2', for temporary nids
if temp { if temp {
...@@ -101,11 +99,11 @@ func (nodeUUID NodeUUID) String() string { ...@@ -101,11 +99,11 @@ func (nodeUUID NodeUUID) String() string {
// XXX goes out of sync wrt NodeType constants // XXX goes out of sync wrt NodeType constants
var nodeTypeNum = [...]int8 { var nodeTypeNum = [...]int8{
STORAGE: 0x00, STORAGE: 0x00,
MASTER: -0x10, MASTER: -0x10,
CLIENT: -0x20, CLIENT: -0x20,
ADMIN: -0x30, ADMIN: -0x30,
} }
// UUID creates node uuid from node type and number. // UUID creates node uuid from node type and number.
func UUID(typ NodeType, num int32) NodeUUID { func UUID(typ NodeType, num int32) NodeUUID {
...@@ -124,12 +122,12 @@ func UUID(typ NodeType, num int32) NodeUUID { ...@@ -124,12 +122,12 @@ func UUID(typ NodeType, num int32) NodeUUID {
typn := nodeTypeNum[typ] typn := nodeTypeNum[typ]
if (num < 0) || num >> 24 != 0 { if (num < 0) || num>>24 != 0 {
panic("node number out of range") panic("node number out of range")
} }
//uuid := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num) //uuid := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
uuid := uint32(uint8(typn)) << (3*8) | uint32(num) uuid := uint32(uint8(typn))<<(3*8) | uint32(num)
return NodeUUID(uuid) return NodeUUID(uuid)
} }
......
...@@ -21,8 +21,8 @@ package proto ...@@ -21,8 +21,8 @@ package proto
// NEO. protocol encoding tests // NEO. protocol encoding tests
import ( import (
hexpkg "encoding/hex"
"encoding/binary" "encoding/binary"
hexpkg "encoding/hex"
"fmt" "fmt"
"reflect" "reflect"
"runtime" "runtime"
...@@ -75,12 +75,12 @@ func TestPktHeader(t *testing.T) { ...@@ -75,12 +75,12 @@ func TestPktHeader(t *testing.T) {
// test marshalling for one message type // test marshalling for one message type
func testMsgMarshal(t *testing.T, msg Msg, encoded string) { func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
typ := reflect.TypeOf(msg).Elem() // type of *msg typ := reflect.TypeOf(msg).Elem() // type of *msg
msg2 := reflect.New(typ).Interface().(Msg) msg2 := reflect.New(typ).Interface().(Msg)
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
t.Errorf("%v: panic ↓↓↓:", typ) t.Errorf("%v: panic ↓↓↓:", typ)
panic(e) // to show traceback panic(e) // to show traceback
} }
}() }()
...@@ -104,7 +104,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) { ...@@ -104,7 +104,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
} }
// encode must panic if passed a smaller buffer // encode must panic if passed a smaller buffer
for l := len(buf)-1; l >= 0; l-- { for l := len(buf) - 1; l >= 0; l-- {
func() { func() {
defer func() { defer func() {
subj := fmt.Sprintf("%v: encode(buf[:encodedLen-%v])", typ, len(encoded)-l) subj := fmt.Sprintf("%v: encode(buf[:encodedLen-%v])", typ, len(encoded)-l)
...@@ -120,9 +120,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) { ...@@ -120,9 +120,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
} }
estr := err.Error() estr := err.Error()
if ! (strings.Contains(estr, "slice bounds out of range") || if !(strings.Contains(estr, "slice bounds out of range") ||
strings.Contains(estr, "index out of range")) { strings.Contains(estr, "index out of range")) {
t.Errorf("%s unexpected runtime panic: %v", subj, estr) t.Errorf("%s unexpected runtime panic: %v", subj, estr)
} }
}() }()
...@@ -145,9 +145,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) { ...@@ -145,9 +145,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
} }
// decode must detect buffer overflow // decode must detect buffer overflow
for l := len(encoded)-1; l >= 0; l-- { for l := len(encoded) - 1; l >= 0; l-- {
n, err = msg2.NEOMsgDecode(data[:l]) n, err = msg2.NEOMsgDecode(data[:l])
if !(n==0 && err==ErrDecodeOverflow) { if !(n == 0 && err == ErrDecodeOverflow) {
t.Errorf("%v: decode overflow not detected on [:%v]", typ, l) t.Errorf("%v: decode overflow not detected on [:%v]", typ, l)
} }
...@@ -158,8 +158,8 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) { ...@@ -158,8 +158,8 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
func TestMsgMarshal(t *testing.T) { func TestMsgMarshal(t *testing.T) {
var testv = []struct { var testv = []struct {
msg Msg msg Msg
encoded string // []byte encoded string // []byte
} { }{
// empty // empty
{&Ping{}, ""}, {&Ping{}, ""},
...@@ -168,55 +168,55 @@ func TestMsgMarshal(t *testing.T) { ...@@ -168,55 +168,55 @@ func TestMsgMarshal(t *testing.T) {
// Oid, Tid, bool, Checksum, []byte // Oid, Tid, bool, Checksum, []byte
{&StoreObject{ {&StoreObject{
Oid: 0x0102030405060708, Oid: 0x0102030405060708,
Serial: 0x0a0b0c0d0e0f0102, Serial: 0x0a0b0c0d0e0f0102,
Compression: false, Compression: false,
Checksum: Checksum{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, // XXX simpler? Checksum: Checksum{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, // XXX simpler?
Data: []byte("hello world"), Data: []byte("hello world"),
DataSerial: 0x0a0b0c0d0e0f0103, DataSerial: 0x0a0b0c0d0e0f0103,
Tid: 0x0a0b0c0d0e0f0104, Tid: 0x0a0b0c0d0e0f0104,
}, },
hex("01020304050607080a0b0c0d0e0f010200") + hex("01020304050607080a0b0c0d0e0f010200") +
hex("0102030405060708090a0b0c0d0e0f1011121314") + hex("0102030405060708090a0b0c0d0e0f1011121314") +
hex("0000000b") + "hello world" + hex("0000000b") + "hello world" +
hex("0a0b0c0d0e0f01030a0b0c0d0e0f0104")}, hex("0a0b0c0d0e0f01030a0b0c0d0e0f0104")},
// PTid, [] (of [] of {UUID, CellState}) // PTid, [] (of [] of {UUID, CellState})
{&AnswerPartitionTable{ {&AnswerPartitionTable{
PTid: 0x0102030405060708, PTid: 0x0102030405060708,
RowList: []RowInfo{ RowList: []RowInfo{
{1, []CellInfo{{11, UP_TO_DATE}, {17, OUT_OF_DATE}}}, {1, []CellInfo{{11, UP_TO_DATE}, {17, OUT_OF_DATE}}},
{2, []CellInfo{{11, FEEDING}}}, {2, []CellInfo{{11, FEEDING}}},
{7, []CellInfo{{11, CORRUPTED}, {15, DISCARDED}, {23, UP_TO_DATE}}}, {7, []CellInfo{{11, CORRUPTED}, {15, DISCARDED}, {23, UP_TO_DATE}}},
}, },
}, },
hex("0102030405060708") + hex("0102030405060708") +
hex("00000003") + hex("00000003") +
hex("00000001000000020000000b000000000000001100000001") + hex("00000001000000020000000b000000000000001100000001") +
hex("00000002000000010000000b00000002") + hex("00000002000000010000000b00000002") +
hex("00000007000000030000000b000000040000000f000000030000001700000000"), hex("00000007000000030000000b000000040000000f000000030000001700000000"),
}, },
// map[Oid]struct {Tid,Tid,bool} // map[Oid]struct {Tid,Tid,bool}
{&AnswerObjectUndoSerial{ {&AnswerObjectUndoSerial{
ObjectTIDDict: map[zodb.Oid]struct{ ObjectTIDDict: map[zodb.Oid]struct {
CurrentSerial zodb.Tid CurrentSerial zodb.Tid
UndoSerial zodb.Tid UndoSerial zodb.Tid
IsCurrent bool IsCurrent bool
} { }{
1: {1, 0, false}, 1: {1, 0, false},
2: {7, 1, true}, 2: {7, 1, true},
8: {7, 1, false}, 8: {7, 1, false},
5: {4, 3, true}, 5: {4, 3, true},
}}, }},
u32(4) + u32(4) +
u64(1) + u64(1) + u64(0) + hex("00") + u64(1) + u64(1) + u64(0) + hex("00") +
u64(2) + u64(7) + u64(1) + hex("01") + u64(2) + u64(7) + u64(1) + hex("01") +
u64(5) + u64(4) + u64(3) + hex("01") + u64(5) + u64(4) + u64(3) + hex("01") +
u64(8) + u64(7) + u64(1) + hex("00"), u64(8) + u64(7) + u64(1) + hex("00"),
}, },
// map[uint32]UUID + trailing ... // map[uint32]UUID + trailing ...
...@@ -231,35 +231,35 @@ func TestMsgMarshal(t *testing.T) { ...@@ -231,35 +231,35 @@ func TestMsgMarshal(t *testing.T) {
MaxTID: 128, MaxTID: 128,
}, },
u32(4) + u32(4) +
u32(1) + u32(7) + u32(1) + u32(7) +
u32(2) + u32(9) + u32(2) + u32(9) +
u32(4) + u32(17) + u32(4) + u32(17) +
u32(7) + u32(3) + u32(7) + u32(3) +
u64(23) + u64(128), u64(23) + u64(128),
}, },
// uint32, []uint32 // uint32, []uint32
{&PartitionCorrupted{7, []NodeUUID{1,3,9,4}}, {&PartitionCorrupted{7, []NodeUUID{1, 3, 9, 4}},
u32(7) + u32(4) + u32(1) + u32(3) + u32(9) + u32(4), u32(7) + u32(4) + u32(1) + u32(3) + u32(9) + u32(4),
}, },
// uint32, Address, string, IdTime // uint32, Address, string, IdTime
{&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678}, {&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678},
u32(2) + u32(17) + u32(9) + u32(2) + u32(17) + u32(9) +
"localhost" + u16(7777) + "localhost" + u16(7777) +
u32(6) + "myname" + u32(6) + "myname" +
hex("3fbf9add1091c895"), hex("3fbf9add1091c895"),
}, },
// IdTime, empty Address, int32 // IdTime, empty Address, int32
{&NotifyNodeInformation{1504466245.926185, []NodeInfo{ {&NotifyNodeInformation{1504466245.926185, []NodeInfo{
{CLIENT, Address{}, UUID(CLIENT, 1), RUNNING, 1504466245.925599}}}, {CLIENT, Address{}, UUID(CLIENT, 1), RUNNING, 1504466245.925599}}},
hex("41d66b15517b469d") + u32(1) + hex("41d66b15517b469d") + u32(1) +
u32(2) + u32(0) /* <- ø Address */ + hex("e0000001") + u32(2) + u32(2) + u32(0) /* <- ø Address */ + hex("e0000001") + u32(2) +
hex("41d66b15517b3d04"), hex("41d66b15517b3d04"),
}, },
// empty IdTime // empty IdTime
...@@ -297,9 +297,9 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) { ...@@ -297,9 +297,9 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
// Verify overflow handling on decode len checks // Verify overflow handling on decode len checks
func TestMsgDecodeLenOverflow(t *testing.T) { func TestMsgDecodeLenOverflow(t *testing.T) {
var testv = []struct { var testv = []struct {
msg Msg // of type to decode into msg Msg // of type to decode into
data string // []byte - tricky data to exercise decoder u32 len checks overflow data string // []byte - tricky data to exercise decoder u32 len checks overflow
} { }{
// [] with sizeof(item) = 8 -> len*sizeof(item) = 0 if u32 // [] with sizeof(item) = 8 -> len*sizeof(item) = 0 if u32
{&AnswerTIDs{}, u32(0x20000000)}, {&AnswerTIDs{}, u32(0x20000000)},
......
...@@ -89,7 +89,7 @@ var typeInfo = &types.Info{ ...@@ -89,7 +89,7 @@ var typeInfo = &types.Info{
} }
// complete position of something with .Pos() // complete position of something with .Pos()
func pos(x interface { Pos() token.Pos }) token.Position { func pos(x interface{ Pos() token.Pos }) token.Position {
return fset.Position(x.Pos()) return fset.Position(x.Pos())
} }
...@@ -234,8 +234,8 @@ func (v BySerial) Less(i, j int) bool { ...@@ -234,8 +234,8 @@ func (v BySerial) Less(i, j int) bool {
return (v[i].msgSerial < v[j].msgSerial) || return (v[i].msgSerial < v[j].msgSerial) ||
(v[i].msgSerial == v[j].msgSerial && !v[i].answer && v[j].answer) (v[i].msgSerial == v[j].msgSerial && !v[i].answer && v[j].answer)
} }
func (v BySerial) Swap(i, j int) { v[i], v[j] = v[j], v[i] } func (v BySerial) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func (v BySerial) Len() int { return len(v) } func (v BySerial) Len() int { return len(v) }
// ---------------------------------------- // ----------------------------------------
...@@ -326,7 +326,7 @@ import ( ...@@ -326,7 +326,7 @@ import (
} }
// `//neo:proto ...` annotation for this particular type // `//neo:proto ...` annotation for this particular type
specAnnotation := declAnnotation // inheriting from decl specAnnotation := declAnnotation // inheriting from decl
specAnnotation.parse(typespec.Doc) specAnnotation.parse(typespec.Doc)
// type only -> don't generate message interface for it // type only -> don't generate message interface for it
...@@ -954,11 +954,11 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) { ...@@ -954,11 +954,11 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
// emit code to size/encode/decode mem.Buf // emit code to size/encode/decode mem.Buf
// same as slice1 but buffer is allocated via mem.BufAlloc // same as slice1 but buffer is allocated via mem.BufAlloc
func (s *sizer) genBuf(path string) { func (s *sizer) genBuf(path string) {
s.genSlice1(path + ".XData()", nil /* typ unused */) s.genSlice1(path+".XData()", nil /* typ unused */)
} }
func (e *encoder) genBuf(path string) { func (e *encoder) genBuf(path string) {
e.genSlice1(path + ".XData()", nil /* typ unused */) e.genSlice1(path+".XData()", nil /* typ unused */)
} }
func (d *decoder) genBuf(path string) { func (d *decoder) genBuf(path string) {
...@@ -1092,7 +1092,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -1092,7 +1092,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
// output keys in sorted order on the wire // output keys in sorted order on the wire
// (easier for debugging & deterministic for testing) // (easier for debugging & deterministic for testing)
e.emit("keyv := make([]%s, 0, l)", typeName(typ.Key())) // FIXME do not throw old slice away -> do xslice.Realloc() e.emit("keyv := make([]%s, 0, l)", typeName(typ.Key())) // FIXME do not throw old slice away -> do xslice.Realloc()
e.emit("for key := range %s {", path) e.emit("for key := range %s {", path)
e.emit(" keyv = append(keyv, key)") e.emit(" keyv = append(keyv, key)")
e.emit("}") e.emit("}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment