Commit dc844465 authored by Levin Zimmermann's avatar Levin Zimmermann Committed by Kirill Smelkov

go/neo/proto: Fix KnownMasterList nesting

Before this patch, the 'KnownMasterList' field of the 'NotPrimaryMaster'
was expected to be structured in the following way:

	ArrayHeader (KnownMasterList)

	    ArrayHeader (KnownMaster)

		ArrayHeader (Address)

		    Host (string)
		    Port (uint16)

However NEO/py sends the following structure:

	ArrayHeader (KnownMasterList)

	    ArrayHeader (Address)

		Host (string)
		Port (uint16)

This also makes sense, as 'KnownMaster' doesn't need to add another
nesting, because it only includes the address.

This patch amends the NEO/go protocol definition to transparently
represent the nesting as it's send by NEO/py. See also
levin.zimmermann/neoppod@18287612 for a similar issue.

----
kirr: tests currently live only on t branch.

/reviewed-by @kirr
/reviewed-on !6
parent 7f96ad77
......@@ -452,9 +452,7 @@ type AnswerPrimary struct {
//neo:nodes SM -> *
type NotPrimaryMaster struct {
Primary NodeID // XXX PSignedNull in py
KnownMasterList []struct {
Address
}
KnownMasterList []Address
}
// Notify information about one or more nodes.
......
......@@ -811,7 +811,7 @@ func (p *NotPrimaryMaster) neoMsgDecodeN(data []byte) (int, error) {
{
l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[8:]
p.KnownMasterList = make([]struct{ Address }, l)
p.KnownMasterList = make([]Address, l)
for i := 0; uint32(i) < l; i++ {
a := &p.KnownMasterList[i]
{
......@@ -834,9 +834,9 @@ func (p *NotPrimaryMaster) neoMsgEncodedLenM() int {
var size int
for i := 0; i < len(p.KnownMasterList); i++ {
a := &p.KnownMasterList[i]
size += msgpack.BinHeadSize(len((*a).Address.Host)) + len((*a).Address.Host) + msgpack.Uint16Size((*a).Address.Port)
size += msgpack.BinHeadSize(len((*a).Host)) + len((*a).Host) + msgpack.Uint16Size((*a).Port)
}
return 1 + msgpack.Int32Size(int32(p.Primary)) + msgpack.ArrayHeadSize(len(p.KnownMasterList)) + len(p.KnownMasterList)*2 + size
return 1 + msgpack.Int32Size(int32(p.Primary)) + msgpack.ArrayHeadSize(len(p.KnownMasterList)) + len(p.KnownMasterList)*1 + size
}
func (p *NotPrimaryMaster) neoMsgEncodeM(data []byte) {
......@@ -851,17 +851,16 @@ func (p *NotPrimaryMaster) neoMsgEncodeM(data []byte) {
data = data[0+n:]
for i := 0; i < l; i++ {
a := &p.KnownMasterList[i]
data[0] = byte(msgpack.FixArray_4 | 1)
data[1] = byte(msgpack.FixArray_4 | 2)
data[0] = byte(msgpack.FixArray_4 | 2)
{
l := len((*a).Address.Host)
n := msgpack.PutBinHead(data[2:], l)
data = data[2+n:]
copy(data, (*a).Address.Host)
l := len((*a).Host)
n := msgpack.PutBinHead(data[1:], l)
data = data[1+n:]
copy(data, (*a).Host)
data = data[l:]
}
{
n := msgpack.PutUint16(data[0:], (*a).Address.Port)
n := msgpack.PutUint16(data[0:], (*a).Port)
data = data[0+n:]
}
}
......@@ -893,39 +892,36 @@ func (p *NotPrimaryMaster) neoMsgDecodeM(data []byte) (int, error) {
}
nread += uint64(len(data) - len(tail))
data = tail
p.KnownMasterList = make([]struct{ Address }, l)
p.KnownMasterList = make([]Address, l)
for i := 0; uint32(i) < l; i++ {
a := &p.KnownMasterList[i]
if len(data) < 2 {
if len(data) < 1 {
goto overflow
}
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|1; op != opOk {
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|2; op != opOk {
return 0, &mstructDecodeError{"NotPrimaryMaster", op, opOk}
}
if op, opOk := msgpack.Op(data[1]), msgpack.FixArray_4|2; op != opOk {
return 0, &mstructDecodeError{"NotPrimaryMaster.Address", op, opOk}
}
data = data[2:]
data = data[1:]
{
b, tail, err := msgp.ReadBytesZC(data)
if err != nil {
return 0, mdecodeErr("NotPrimaryMaster.Address.Host", err)
return 0, mdecodeErr("NotPrimaryMaster.Host", err)
}
(*a).Address.Host = string(b)
(*a).Host = string(b)
nread += uint64(len(data) - len(tail))
data = tail
}
{
v, tail, err := msgp.ReadUint16Bytes(data)
if err != nil {
return 0, mdecodeErr("NotPrimaryMaster.Address.Port", err)
return 0, mdecodeErr("NotPrimaryMaster.Port", err)
}
(*a).Address.Port = v
(*a).Port = v
nread += uint64(len(data) - len(tail))
data = tail
}
}
nread += uint64(l) * 2
nread += uint64(l) * 1
}
return 1 + int(nread), nil
......
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