Commit 433c5400 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 7ded0d06
......@@ -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.
......
......@@ -817,7 +817,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]
{
......@@ -840,7 +840,7 @@ func (p *NotPrimaryMaster) neoMsgEncodedLenM() int {
var size int
for i := 0; i < len(p.KnownMasterList); i++ {
a := &p.KnownMasterList[i]
size += msgpack.ArrayHeadSize(reflect.TypeOf((*a)).NumField()) + msgpack.ArrayHeadSize(reflect.TypeOf((*a).Address).NumField()) + msgpack.BinHeadSize(len((*a).Address.Host)) + len((*a).Address.Host) + msgpack.Uint16Size((*a).Address.Port)
size += msgpack.ArrayHeadSize(reflect.TypeOf((*a)).NumField()) + msgpack.BinHeadSize(len((*a).Host)) + len((*a).Host) + msgpack.Uint16Size((*a).Port)
}
return msgpack.ArrayHeadSize(reflect.TypeOf((*p)).NumField()) + msgpack.Int32Size(p.Primary) + msgpack.ArrayHeadSize(len(p.KnownMasterList)) + size
}
......@@ -857,17 +857,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:]
}
}
......@@ -900,7 +899,7 @@ 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]
{
......@@ -911,29 +910,21 @@ func (p *NotPrimaryMaster) neoMsgDecodeM(data []byte) (int, error) {
nread += uint64(len(data) - len(tail))
data = tail
}
{
_, tail, err := msgp.ReadArrayHeaderBytes(data)
if err != nil {
return 0, mdecodeErr("NotPrimaryMaster.Address", err)
}
nread += uint64(len(data) - len(tail))
data = tail
}
{
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