Commit 35d32ba6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1cf2712f
...@@ -1187,7 +1187,7 @@ const dumpio = false ...@@ -1187,7 +1187,7 @@ const dumpio = false
func (nl *NodeLink) sendPkt(pkt *pktBuf) error { func (nl *NodeLink) sendPkt(pkt *pktBuf) error {
if dumpio { if dumpio {
// XXX -> log // XXX -> log
fmt.Printf("%v > %v: %v\n", nl.peerLink.LocalAddr(), nl.peerLink.RemoteAddr(), pkt) fmt.Printf("%s > %s: %s\n", nl.peerLink.LocalAddr(), nl.peerLink.RemoteAddr(), pktString(nl.enc, pkt))
//defer fmt.Printf("\t-> sendPkt err: %v\n", err) //defer fmt.Printf("\t-> sendPkt err: %v\n", err)
} }
...@@ -1213,7 +1213,13 @@ func (nl *NodeLink) recvPkt() (pkt *pktBuf, err error) { ...@@ -1213,7 +1213,13 @@ func (nl *NodeLink) recvPkt() (pkt *pktBuf, err error) {
if dumpio { if dumpio {
// XXX -> log // XXX -> log
fmt.Printf("%v < %v: %v\n", nl.peerLink.LocalAddr(), nl.peerLink.RemoteAddr(), pkt) s := fmt.Sprintf("%s < %s: ", nl.peerLink.LocalAddr(), nl.peerLink.RemoteAddr())
if err != nil {
s += err.Error()
} else {
s += pktString(nl.enc, pkt)
}
fmt.Println(s)
} }
return pkt, err return pkt, err
...@@ -1387,10 +1393,15 @@ func pktEncode(e proto.Encoding, connId uint32, msg proto.Msg) *pktBuf { ...@@ -1387,10 +1393,15 @@ func pktEncode(e proto.Encoding, connId uint32, msg proto.Msg) *pktBuf {
// pktDecodeHead decodes header of a packet. // pktDecodeHead decodes header of a packet.
func pktDecodeHead(e proto.Encoding, pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) { func pktDecodeHead(e proto.Encoding, pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) {
switch e { switch e {
case 'N': return pktDecodeHeadN(pkt) case 'N': connID, msgCode, payload, err = pktDecodeHeadN(pkt)
case 'M': return pktDecodeHeadM(pkt) case 'M': connID, msgCode, payload, err = pktDecodeHeadM(pkt)
default: panic("bug") default: panic("bug")
} }
if err != nil {
err = fmt.Errorf("decode header: %s", err)
}
return connID, msgCode, payload, err
} }
...@@ -1408,6 +1419,9 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf { ...@@ -1408,6 +1419,9 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
} }
func pktDecodeHeadN(pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) { func pktDecodeHeadN(pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) {
if len(pkt.data) < proto.PktHeaderLen {
return 0, 0, nil, fmt.Errorf("packet too short") // XXX -> ErrTooShort?
}
pkth := pkt.HeaderN() pkth := pkt.HeaderN()
connID = packed.Ntoh32(pkth.ConnId) connID = packed.Ntoh32(pkth.ConnId)
msgCode = packed.Ntoh16(pkth.MsgCode) msgCode = packed.Ntoh16(pkth.MsgCode)
...@@ -1442,7 +1456,6 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf { ...@@ -1442,7 +1456,6 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
} }
func pktDecodeHeadM(pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) { func pktDecodeHeadM(pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte, err error) {
// XXX errctx = "decode header"
b := pkt.data b := pkt.data
sz, b, err := msgp.ReadArrayHeaderBytes(b) sz, b, err := msgp.ReadArrayHeaderBytes(b)
if err != nil { if err != nil {
......
...@@ -28,7 +28,6 @@ import ( ...@@ -28,7 +28,6 @@ import (
"lab.nexedi.com/kirr/go123/xbytes" "lab.nexedi.com/kirr/go123/xbytes"
"lab.nexedi.com/kirr/neo/go/internal/packed"
"lab.nexedi.com/kirr/neo/go/neo/proto" "lab.nexedi.com/kirr/neo/go/neo/proto"
) )
...@@ -80,35 +79,31 @@ func (pkt *pktBuf) Free() { ...@@ -80,35 +79,31 @@ func (pkt *pktBuf) Free() {
// ---- pktBuf dump ---- // ---- pktBuf dump ----
// String dumps a packet in human-readable form. // pktString dumps a packet in human-readable form.
func (pkt *pktBuf) String() string { func pktString(e proto.Encoding, pkt *pktBuf) string {
if len(pkt.data) < proto.PktHeaderLen { connID, msgCode, payload, err := pktDecodeHead(e, pkt)
return fmt.Sprintf("(! < PktHeaderLen) % x", pkt.data) if err != nil {
return fmt.Sprintf("(%s) % x", err, pkt.data)
} }
h := pkt.Header() s := fmt.Sprintf(".%d", connID)
s := fmt.Sprintf(".%d", packed.Ntoh32(h.ConnId))
// XXX encN-specific
msgCode := packed.Ntoh16(h.MsgCode)
msgLen := packed.Ntoh32(h.MsgLen)
data := pkt.Payload()
msgType := proto.MsgType(msgCode) msgType := proto.MsgType(msgCode)
if msgType == nil { if msgType == nil {
s += fmt.Sprintf(" ? (%d) #%d [%d]: % x", msgCode, msgLen, len(data), data) s += fmt.Sprintf(" ? (%d) [%d]: % x", msgCode, len(payload), payload)
return s return s
} }
// XXX dup wrt Conn.Recv // XXX dup wrt Conn.Recv
msg := reflect.New(msgType).Interface().(proto.Msg) msg := reflect.New(msgType).Interface().(proto.Msg)
n, err := encN.NEOMsgDecode(msg, data) // XXX encN hardcoded n, err := e.NEOMsgDecode(msg, payload)
if err != nil { if err != nil {
s += fmt.Sprintf(" (%s) %v; #%d [%d]: % x", msgType.Name(), err, msgLen, len(data), data) s += fmt.Sprintf(" (%s) %v; [%d]: % x", msgType.Name(), err, len(payload), payload)
} else { } else {
s += fmt.Sprintf(" %s %v", msgType.Name(), msg) // XXX or %+v better? s += fmt.Sprintf(" %s %v", msgType.Name(), msg) // XXX or %+v better?
if n < len(data) { if n < len(payload) {
tail := data[n:] tail := payload[n:]
s += fmt.Sprintf(" ; [%d]tail: % x", len(tail), tail) s += fmt.Sprintf(" ; [%d]tail: % x", len(tail), tail)
} }
} }
...@@ -116,8 +111,10 @@ func (pkt *pktBuf) String() string { ...@@ -116,8 +111,10 @@ func (pkt *pktBuf) String() string {
return s return s
} }
/*
// Dump dumps a packet in raw form. // Dump dumps a packet in raw form.
func (pkt *pktBuf) Dump() string { func (pkt *pktBuf) Dump() string {
// XXX encN-specific
if len(pkt.data) < proto.PktHeaderLen { if len(pkt.data) < proto.PktHeaderLen {
return fmt.Sprintf("(! < pktHeaderLen) % x", pkt.data) return fmt.Sprintf("(! < pktHeaderLen) % x", pkt.data)
} }
...@@ -127,3 +124,4 @@ func (pkt *pktBuf) Dump() string { ...@@ -127,3 +124,4 @@ func (pkt *pktBuf) Dump() string {
return fmt.Sprintf(".%d (%d) #%d [%d]: % x", return fmt.Sprintf(".%d (%d) #%d [%d]: % x",
packed.Ntoh32(h.ConnId), packed.Ntoh16(h.MsgCode), packed.Ntoh32(h.MsgLen), len(data), data) packed.Ntoh32(h.ConnId), packed.Ntoh16(h.MsgCode), packed.Ntoh32(h.MsgLen), len(data), 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