Commit baf7f580 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 70dfb639
......@@ -1309,7 +1309,7 @@ func (nl *NodeLink) recvPktN() (*pktBuf, error) {
func (nl *NodeLink) recvPktM() (*pktBuf, error) {
pkt := pktAlloc(4096)
mraw := msgp.Raw(pkt.data)
err := mraw.DecodeMsg(nl.rxbufM) // XXX limit size of one packet to e.g. 0x4000000 (= UNPACK_BUFFER_SIZE in NEO/py speak)
err := mraw.DecodeMsg(nl.rxbufM) // XXX limit size of one packet to proto.PktMaxSize (= UNPACK_BUFFER_SIZE in NEO/py speak)
if err != nil {
return nil, err
}
......@@ -1418,7 +1418,7 @@ func pktDecodeHead(e proto.Encoding, pkt *pktBuf) (connID uint32, msgCode uint16
func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
const enc = proto.Encoding('N')
l := enc.NEOMsgEncodedLen(msg)
l := enc.MsgEncodedLen(msg)
buf := pktAlloc(proto.PktHeaderLenN + l)
h := buf.HeaderN()
......@@ -1426,7 +1426,7 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
h.MsgCode = packed.Hton16(proto.MsgCode(msg))
h.MsgLen = packed.Hton32(uint32(l)) // XXX casting: think again
enc.NEOMsgEncode(msg, buf.PayloadN())
enc.MsgEncode(msg, buf.PayloadN())
return buf
}
......@@ -1453,7 +1453,7 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
hroom := msgpack.ArrayHeadSize(3) +
msgpack.Uint32Size(connId) +
msgpack.Uint16Size(msgCode)
l := enc.NEOMsgEncodedLen(msg)
l := enc.MsgEncodedLen(msg)
buf := pktAlloc(hroom + l)
......@@ -1465,7 +1465,7 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
if i != hroom {
panic("bug")
}
enc.NEOMsgEncode(msg, b[hroom:])
enc.MsgEncode(msg, b[hroom:])
return buf
}
......@@ -1518,7 +1518,7 @@ func (c *Conn) Recv() (proto.Msg, error) {
// msg := reflect.NewAt(msgType, bufAlloc(msgType.Size())
_, err = c.link.enc.NEOMsgDecode(msg, payload)
_, err = c.link.enc.MsgDecode(msg, payload)
if err != nil {
return nil, c.err("decode", err) // XXX "decode:" is already in ErrDecodeOverflow
}
......@@ -1575,7 +1575,7 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) {
for i, msg := range msgv {
if proto.MsgCode(msg) == msgCode {
_, err := c.link.enc.NEOMsgDecode(msg, payload)
_, err := c.link.enc.MsgDecode(msg, payload)
if err != nil {
return -1, c.err("decode", err)
}
......
......@@ -95,7 +95,7 @@ func pktString(e proto.Encoding, pkt *pktBuf) string {
// XXX dup wrt Conn.Recv
msg := reflect.New(msgType).Interface().(proto.Msg)
n, err := e.NEOMsgDecode(msg, payload)
n, err := e.MsgDecode(msg, payload)
if err != nil {
s += fmt.Sprintf(" (%s) %v; [%d]: % x", msgType.Name(), err, len(payload), payload)
} else {
......
......@@ -28,7 +28,7 @@
//
// Messages are represented by corresponding types that all implement Msg interface.
//
// A message type can be looked up by message code with MsgType.
// A message type can be looked up by message code with MsgType. XXX unpublish ?
//
// The proto packages provides only message definitions and low-level
// primitives for their marshalling. Package lab.nexedi.com/kirr/neo/go/neo/neonet
......@@ -58,9 +58,6 @@ package proto
//go:generate gotrace gen .
// TODO regroup messages definitions to stay more close to 1 communication topic
// TODO document protocol itself better (who sends who what with which semantic)
// NOTE for some packets it is possible to decode raw packet -> go version from
// PktBuf in place. E.g. for GetObject.
//
......@@ -80,10 +77,10 @@ import (
const (
// The protocol version must be increased whenever upgrading a node may require
// to upgrade other nodes. It is encoded as a 4-bytes big-endian integer and
// the high order byte 0 is different from TLS Handshake (0x16).
// the high order byte 0 is different from TLS Handshake (0x16). XXX update for msgpack
Version = 6
// length of packet header in 'N'-encoding
// length of packet header in 'N'-encoding XXX unpublish?
PktHeaderLenN = 10 // = unsafe.Sizeof(PktHeaderN{}), but latter gives typed constant (uintptr)
// packets larger than PktMaxSize are not allowed.
......@@ -99,7 +96,7 @@ const (
INVALID_OID zodb.Oid = 1<<64 - 1
)
// PktHeaderN represents header of a raw packet in 'N'-encoding.
// PktHeaderN represents header of a raw packet in 'N'-encoding. XXX unexport?
//
// A packet contains connection ID and message.
//
......@@ -142,9 +139,8 @@ type Msg interface {
// Encoding represents messages encoding.
type Encoding byte
// XXX drop "NEO" prefix?
// NEOMsgEncodedLen returns how much space is needed to encode msg payload via encoding e.
func (e Encoding) NEOMsgEncodedLen(msg Msg) int {
// MsgEncodedLen returns how much space is needed to encode msg payload via encoding e.
func (e Encoding) MsgEncodedLen(msg Msg) int {
switch e {
default: panic("bug")
case 'N': return msg.neoMsgEncodedLenN()
......@@ -152,10 +148,10 @@ func (e Encoding) NEOMsgEncodedLen(msg Msg) int {
}
}
// NEOMsgEncode encodes msg state into buf via encoding e.
// MsgEncode encodes msg state into buf via encoding e.
//
// len(buf) must be >= e.NEOMsgEncodedLen(m).
func (e Encoding) NEOMsgEncode(msg Msg, buf []byte) {
// len(buf) must be >= e.MsgEncodedLen(m).
func (e Encoding) MsgEncode(msg Msg, buf []byte) {
switch e {
default: panic("bug")
case 'N': msg.neoMsgEncodeN(buf)
......@@ -163,8 +159,8 @@ func (e Encoding) NEOMsgEncode(msg Msg, buf []byte) {
}
}
// NEOMsgDecode decodes data via encoding e into msg in-place.
func (e Encoding) NEOMsgDecode(msg Msg, data []byte) (nread int, err error) {
// MsgDecode decodes data via encoding e into msg in-place.
func (e Encoding) MsgDecode(msg Msg, data []byte) (nread int, err error) {
switch e {
default: panic("bug")
case 'N': return msg.neoMsgDecodeN(data)
......
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