Commit 106ed0be authored by Levin Zimmermann's avatar Levin Zimmermann

proto/msgpack: Fix handshake magic

This fixes the basic NEO handshake in msgpack encoding.
parent 8effc6be
......@@ -216,7 +216,7 @@ func _handshakeServer(ctx context.Context, conn net.Conn, version uint32) (enc p
// handshake hello:
//
// - 00 00 00 <ver> for 'N' encoding, and
// - 92 c4 03 NEO ... for 'M' encoding (= msgpack of (b"NEO", <ver>))
// - 92 a3 NEO ... for 'M' encoding (= msgpack of (b"NEO", <ver>))
//
// the first byte is different from TLS handshake (0x16).
......@@ -234,9 +234,9 @@ func txHello(errctx string, conn net.Conn, version uint32, enc proto.Encoding) (
b[3] = uint8(version)
case 'M':
// (b"NEO", <V>) encoded as msgpack (= 92 c4 03 NEO int(<V>))
// (b"NEO", <V>) encoded as msgpack (= 92 a3 NEO int(<V>))
b = msgp.AppendArrayHeader(b, 2) // 92
b = msgp.AppendBytes(b, []byte("NEO")) // c4 03 NEO
b = msgp.AppendString(b, "NEO") // a3 NEO
b = msgp.AppendUint32(b, version) // u?intX version
default:
......@@ -269,24 +269,20 @@ func rxHello(errctx string, rx *xbufReader) (enc proto.Encoding, version uint32,
peerEnc = 'N'
peerVer = uint32(b[3])
case bytes.Equal(b, []byte{0x92, 0xc4, 3, 'N'}): // start of "fixarray<2> bin8 'N | EO' ...
case bytes.Equal(b, []byte{0x92, 0xa3, 'N', 'E'}): // start of "fixarray<2> bin8 'NE | O' ...
b = append(b, []byte{0,0}...)
_, err = io.ReadFull(rx, b[4:])
err = xio.NoEOF(err)
if err != nil {
return 0, 0, err
}
if !bytes.Equal(b[4:], []byte{'E','O'}) {
if !bytes.Equal(b[4:5], []byte{'O'}) {
badMagic = true
break
}
peerEnc = 'M'
rxM := msgp.Reader{R: rx.Reader}
peerVer, err = rxM.ReadUint32()
if err != nil {
return 0, 0, fmt.Errorf("M: recv peer version: %s", err) // XXX + "read magic" ctx
}
peerVer = uint32(b[5])
default:
badMagic = true
......
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