Commit 4ba1bf59 authored by Levin Zimmermann's avatar Levin Zimmermann

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
18287612 for a similar issue.
parent 7aa750e3
......@@ -138,7 +138,7 @@ func (node *_MasteredNode) TalkMaster(ctx context.Context, f func(context.Contex
} else {
// TODO update masterRegistry from received KnownMasterList
primary := notPrimaryMaster.KnownMasterList[p]
maddr = primary.Address.String()
maddr = primary.String()
log.Info(ctx, "switching to try %s as primary master", maddr)
}
}
......
......@@ -457,9 +457,7 @@ type AnswerPrimary struct {
//neo:nodes SM -> *
type NotPrimaryMaster struct {
Primary int32 // index of PM in KnownMasterList
KnownMasterList []struct {
Address
}
KnownMasterList []Address
}
// Notify information about one or more nodes.
......
......@@ -844,7 +844,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]
{
......@@ -867,9 +867,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(p.Primary) + msgpack.ArrayHeadSize(len(p.KnownMasterList)) + len(p.KnownMasterList)*2 + size
return 1 + msgpack.Int32Size(p.Primary) + msgpack.ArrayHeadSize(len(p.KnownMasterList)) + len(p.KnownMasterList)*1 + size
}
func (p *NotPrimaryMaster) neoMsgEncodeM(data []byte) {
......@@ -884,17 +884,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:]
}
}
......@@ -930,10 +929,10 @@ 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 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}
}
{
......@@ -944,32 +943,21 @@ func (p *NotPrimaryMaster) neoMsgDecodeM(data []byte) (int, error) {
data = tail
nread += uint64(l)
}
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|2; op != opOk {
return 0, &mstructDecodeError{"NotPrimaryMaster.Address", op, opOk}
}
{
l, tail, err := msgp.ReadArrayHeaderBytes(data)
if err != nil {
return 0, mdecodeErr("NotPrimaryMaster.Address", err)
}
data = tail
nread += uint64(l)
}
{
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
}
......
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