Commit 98869a9b authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: RequestIdentification += NewNID; Move .DevPath

This corresponds to NEO/py commit 27e3f620 (New --new-nid storage option
for fast cloning).
parent c85756a0
...@@ -368,8 +368,10 @@ type RequestIdentification struct { ...@@ -368,8 +368,10 @@ type RequestIdentification struct {
UUID NodeUUID UUID NodeUUID
Address Address // where requesting node is also accepting connections Address Address // where requesting node is also accepting connections
ClusterName string ClusterName string
DevPath []string // [] of devid
IdTime IdTime IdTime IdTime
// storage
DevPath []string // [] of devid
NewNID []uint32 // [] of PNumber
} }
//neo:proto answer //neo:proto answer
......
...@@ -250,13 +250,14 @@ func TestMsgMarshal(t *testing.T) { ...@@ -250,13 +250,14 @@ func TestMsgMarshal(t *testing.T) {
}, },
// uint32, Address, string, IdTime // uint32, Address, string, IdTime
{&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", []string{"room1", "rack234"}, 0.12345678}, {&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678, []string{"room1", "rack234"}, []uint32{3,4,5} },
u8(2) + u32(17) + u32(9) + u8(2) + u32(17) + u32(9) +
"localhost" + u16(7777) + "localhost" + u16(7777) +
u32(6) + "myname" + u32(6) + "myname" +
hex("3fbf9add1091c895") +
u32(2) + u32(5)+"room1" + u32(7)+"rack234" + u32(2) + u32(5)+"room1" + u32(7)+"rack234" +
hex("3fbf9add1091c895"), u32(3) + u32(3)+u32(4)+u32(5),
}, },
// IdTime, empty Address, int32 // IdTime, empty Address, int32
......
...@@ -70,7 +70,7 @@ func (p *RequestIdentification) NEOMsgEncodedLen() int { ...@@ -70,7 +70,7 @@ func (p *RequestIdentification) NEOMsgEncodedLen() int {
a := &p.DevPath[i] a := &p.DevPath[i]
size += len((*a)) size += len((*a))
} }
return 13 + p.Address.neoEncodedLen() + len(p.ClusterName) + len(p.DevPath)*4 + p.IdTime.neoEncodedLen() + size return 17 + p.Address.neoEncodedLen() + len(p.ClusterName) + p.IdTime.neoEncodedLen() + len(p.DevPath)*4 + len(p.NewNID)*4 + size
} }
func (p *RequestIdentification) NEOMsgEncode(data []byte) { func (p *RequestIdentification) NEOMsgEncode(data []byte) {
...@@ -87,6 +87,10 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) { ...@@ -87,6 +87,10 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
copy(data, p.ClusterName) copy(data, p.ClusterName)
data = data[l:] data = data[l:]
} }
{
n := p.IdTime.neoEncode(data[0:])
data = data[0+n:]
}
{ {
l := uint32(len(p.DevPath)) l := uint32(len(p.DevPath))
binary.BigEndian.PutUint32(data[0:], l) binary.BigEndian.PutUint32(data[0:], l)
...@@ -104,8 +108,14 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) { ...@@ -104,8 +108,14 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
} }
} }
{ {
n := p.IdTime.neoEncode(data[0:]) l := uint32(len(p.NewNID))
data = data[0+n:] binary.BigEndian.PutUint32(data[0:], l)
data = data[4:]
for i := 0; uint32(i) < l; i++ {
a := &p.NewNID[i]
binary.BigEndian.PutUint32(data[0:], (*a))
data = data[4:]
}
} }
} }
...@@ -131,13 +141,24 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) { ...@@ -131,13 +141,24 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[0 : 0+4]) l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:] data = data[4:]
if uint64(len(data)) < 4+uint64(l) { if uint64(len(data)) < uint64(l) {
goto overflow goto overflow
} }
nread += 4 + uint64(l) nread += uint64(l)
p.ClusterName = string(data[:l]) p.ClusterName = string(data[:l])
data = data[l:] data = data[l:]
} }
{
n, ok := p.IdTime.neoDecode(data)
if !ok {
goto overflow
}
data = data[n:]
nread += n
}
if len(data) < 4 {
goto overflow
}
{ {
l := binary.BigEndian.Uint32(data[0 : 0+4]) l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:] data = data[4:]
...@@ -158,17 +179,26 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) { ...@@ -158,17 +179,26 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
data = data[l:] data = data[l:]
} }
} }
if len(data) < 4 {
goto overflow
}
nread += uint64(l) * 4 nread += uint64(l) * 4
} }
{ {
n, ok := p.IdTime.neoDecode(data) l := binary.BigEndian.Uint32(data[0 : 0+4])
if !ok { data = data[4:]
if uint64(len(data)) < uint64(l)*4 {
goto overflow goto overflow
} }
data = data[n:] nread += uint64(l) * 4
nread += n p.NewNID = make([]uint32, l)
for i := 0; uint32(i) < l; i++ {
a := &p.NewNID[i]
(*a) = binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:]
}
} }
return 9 + int(nread), nil return 17 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
......
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