Commit f609d6df 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 4efd2626
......@@ -113,8 +113,9 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
UUID: app.MyInfo.UUID,
Address: app.MyInfo.Addr,
ClusterName: app.ClusterName,
DevPath: nil, // XXX stub
IdTime: app.MyInfo.IdTime, // XXX ok?
DevPath: nil, // XXX stub
NewNID: nil, // XXX stub
}
accept := &proto.AcceptIdentification{}
// FIXME error if peer sends us something with another connID
......
......@@ -107,8 +107,9 @@ func TestMasterStorage(t0 *testing.T) {
UUID: 0,
Address: xnaddr("s:1"),
ClusterName: "abc1",
DevPath: nil,
IdTime: proto.IdTimeNone,
DevPath: nil,
NewNID: nil,
}))
......@@ -209,8 +210,9 @@ func TestMasterStorage(t0 *testing.T) {
UUID: 0,
Address: xnaddr(""),
ClusterName: "abc1",
DevPath: nil,
IdTime: proto.IdTimeNone,
DevPath: nil,
NewNID: nil,
}))
tM.Expect(δnode("m", "", proto.CLIENT, 1, proto.RUNNING, 0.02))
......@@ -295,8 +297,9 @@ func TestMasterStorage(t0 *testing.T) {
UUID: proto.UUID(proto.CLIENT, 1),
Address: xnaddr(""),
ClusterName: "abc1",
DevPath: nil,
IdTime: 0.02,
DevPath: nil,
NewNID: nil,
}))
tCS.Expect(conntx("s:3", "c:2", 1, &proto.AcceptIdentification{
......
......@@ -372,8 +372,10 @@ type RequestIdentification struct {
UUID NodeUUID
Address Address // where requesting node is also accepting connections
ClusterName string
DevPath []string // [] of devid
IdTime IdTime
// storage
DevPath []string // [] of devid
NewNID []uint32 // [] of PNumber
}
//neo:proto answer
......
......@@ -250,13 +250,14 @@ func TestMsgMarshal(t *testing.T) {
},
// 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) +
"localhost" + u16(7777) +
u32(6) + "myname" +
hex("3fbf9add1091c895") +
u32(2) + u32(5)+"room1" + u32(7)+"rack234" +
hex("3fbf9add1091c895"),
u32(3) + u32(3)+u32(4)+u32(5),
},
// IdTime, empty Address, int32
......
......@@ -70,7 +70,7 @@ func (p *RequestIdentification) NEOMsgEncodedLen() int {
a := &p.DevPath[i]
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) {
......@@ -87,6 +87,10 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
copy(data, p.ClusterName)
data = data[l:]
}
{
n := p.IdTime.neoEncode(data[0:])
data = data[0+n:]
}
{
l := uint32(len(p.DevPath))
binary.BigEndian.PutUint32(data[0:], l)
......@@ -104,8 +108,14 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
}
}
{
n := p.IdTime.neoEncode(data[0:])
data = data[0+n:]
l := uint32(len(p.NewNID))
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) {
{
l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:]
if uint64(len(data)) < 4+uint64(l) {
if uint64(len(data)) < uint64(l) {
goto overflow
}
nread += 4 + uint64(l)
nread += uint64(l)
p.ClusterName = string(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])
data = data[4:]
......@@ -158,17 +179,26 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
data = data[l:]
}
}
if len(data) < 4 {
goto overflow
}
nread += uint64(l) * 4
}
{
n, ok := p.IdTime.neoDecode(data)
if !ok {
l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:]
if uint64(len(data)) < uint64(l)*4 {
goto overflow
}
data = data[n:]
nread += n
nread += uint64(l) * 4
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:
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