Commit ef5e0a40 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3ec038b7
...@@ -60,11 +60,17 @@ type Conn struct { ...@@ -60,11 +60,17 @@ type Conn struct {
rxq chan Pkt // XXX chan &Pkt ? rxq chan Pkt // XXX chan &Pkt ?
} }
// Buffer with packet data
type PktBuf struct {
PktHead
Body []byte
}
// Send packet via connection // Send packet via connection
// XXX vs cancel // XXX vs cancel
func (Conn *c) Send(pkt Pkt) error { func (Conn *c) Send(pkt Pkt) error {
pkt.MsgId = ... // TODO next msgid, or using same msgid as received pkt.MsgId = 0 // TODO next msgid, or using same msgid as received
_, err := c.nodeLink.peerLink.Write(pkt.WholeBuffer()) // TODO -> sendPkt(pkt) _, err := c.nodeLink.peerLink.Write(pkt.WholeBuffer()) // TODO -> sendPkt(pkt)
if err != nil { if err != nil {
// TODO data could be written partially and thus the message stream is now broken // TODO data could be written partially and thus the message stream is now broken
...@@ -76,7 +82,7 @@ func (Conn *c) Send(pkt Pkt) error { ...@@ -76,7 +82,7 @@ func (Conn *c) Send(pkt Pkt) error {
// Receive packet from connection // Receive packet from connection
// XXX vs cancel // XXX vs cancel
func (Conn *c) Recv() (PktBuf, error) { func (Conn *c) Recv() (PktBuf, error) {
pkt, ok <- rxq pkt, ok := <-rxq
if !ok { if !ok {
return PktBuf{}, io.EOF // XXX check erroring & other errors? return PktBuf{}, io.EOF // XXX check erroring & other errors?
} }
...@@ -108,7 +114,7 @@ func NewNodeLink(c net.Conn) *NodeLink { ...@@ -108,7 +114,7 @@ func NewNodeLink(c net.Conn) *NodeLink {
func (nl *NodeLink) NewConn() *Conn { func (nl *NodeLink) NewConn() *Conn {
c := &Conn{nodeLink: nl, rxq: make(chan Pkt)} c := &Conn{nodeLink: nl, rxq: make(chan Pkt)}
// XXX locking // XXX locking
nl.connTab[...] = c // XXX also check not a duplicate nl.connTab[0] = c // FIXME 0 -> msgid; XXX also check not a duplicate
return c return c
} }
...@@ -135,7 +141,7 @@ func (nl *NodeLink) serveRecv() error { ...@@ -135,7 +141,7 @@ func (nl *NodeLink) serveRecv() error {
continue continue
} }
conn = nl.NewConn(...) // XXX should also update connTab conn = nl.NewConn()
// TODO avoid spawning goroutine for each new Ask request - // TODO avoid spawning goroutine for each new Ask request -
// - by keeping pool of read inactive goroutine / conn pool // - by keeping pool of read inactive goroutine / conn pool
go nl.handleNewConn(conn) go nl.handleNewConn(conn)
...@@ -153,13 +159,6 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) { ...@@ -153,13 +159,6 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) {
} }
// information about (received ?) packet
// XXX place?
type PktBuf struct {
PktHead
Body []byte
}
// receive 1 packet from peer // receive 1 packet from peer
func (c *NodeLink) recvPkt() (pkt Pkt, err error) { func (c *NodeLink) recvPkt() (pkt Pkt, err error) {
// TODO organize rx buffers management (freelist etc) // TODO organize rx buffers management (freelist etc)
......
...@@ -4,10 +4,8 @@ package neo ...@@ -4,10 +4,8 @@ package neo
import ( import (
"context" "context"
"encoding/binary"
"net" "net"
"fmt" "fmt"
"io"
//"../neo/proto" //"../neo/proto"
) )
......
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