Commit 85666824 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 028efc96
......@@ -20,6 +20,8 @@ import (
"io"
"net"
"sync"
"fmt"
)
// NodeLink is a node-node link in NEO
......@@ -150,6 +152,10 @@ func (nl *NodeLink) Close() error {
// send raw packet to peer
func (nl *NodeLink) sendPkt(pkt *PktBuf) error {
if true {
// XXX -> log
fmt.Printf("%v > %v: %v\n", nl.peerLink.LocalAddr(), nl.peerLink.RemoteAddr(), pkt)
}
_, err := nl.peerLink.Write(pkt.Data) // FIXME write Data in full
if err != nil {
// XXX do we need to retry if err is temporary?
......
......@@ -15,6 +15,7 @@
package neo
import (
"fmt"
"unsafe"
)
......@@ -42,3 +43,27 @@ func (pkt *PktBuf) Header() *PktHead {
func (pkt *PktBuf) Payload() []byte {
return pkt.Data[PktHeadLen:]
}
// packet dumping
func (pkt *PktBuf) String() string {
if len(pkt.Data) < PktHeadLen {
return fmt.Sprintf("(! < PktHeadLen) % x", pkt.Data)
}
h := pkt.Header()
s := fmt.Sprintf(".%d", ntoh32(h.ConnId))
msgCode := ntoh16(h.MsgCode)
msgType := pktTypeRegistry[msgCode]
if msgType == nil {
s += fmt.Sprintf(" ? (%d)", msgCode)
} else {
s += fmt.Sprintf(" %s", msgType)
}
s += fmt.Sprintf(" #%d | ", ntoh32(h.Len))
s += fmt.Sprintf("% x\n", pkt.Payload()) // XXX better decode
return s
}
......@@ -3345,7 +3345,7 @@ func (p *NotifyReady) NEODecode(data []byte) (int, error) {
}
// registry of packet types
var pktTypeRegistry = map[int]reflect.Type{
var pktTypeRegistry = map[uint16]reflect.Type{
0: reflect.TypeOf(Address{}),
1: reflect.TypeOf(NodeInfo{}),
2: reflect.TypeOf(CellInfo{}),
......
......@@ -204,7 +204,7 @@ import (
// now generate packet types registry
buf.emit("\n// registry of packet types")
buf.emit("var pktTypeRegistry = map[int]reflect.Type {") // XXX key -> PktCode ?
buf.emit("var pktTypeRegistry = map[uint16]reflect.Type {") // XXX key -> PktCode ?
// ordered by pktCode
pktCodeV := []int{}
......
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