Commit a024d393 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b50f771e
...@@ -82,8 +82,6 @@ func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error { ...@@ -82,8 +82,6 @@ func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
// Identify identifies peer on the link // Identify identifies peer on the link
// it expects peer to send RequestIdentification packet and TODO // it expects peer to send RequestIdentification packet and TODO
func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo*/, err error) { func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo*/, err error) {
nodeInfo := RequestIdentification{}
// the first conn must come with RequestIdentification packet // the first conn must come with RequestIdentification packet
conn, err := link.Accept() conn, err := link.Accept()
if err != nil { if err != nil {
...@@ -112,6 +110,8 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo ...@@ -112,6 +110,8 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo
return nodeInfo, fmt.Errorf("protocol version mismatch: peer = %d ; our side = %d", pkt.ProtocolVersion, PROTOCOL_VERSION) return nodeInfo, fmt.Errorf("protocol version mismatch: peer = %d ; our side = %d", pkt.ProtocolVersion, PROTOCOL_VERSION)
} }
// TODO (.NodeType, .UUID, .Address, .Name, .IdTimestamp) -> check + register to NM
err = EncodeAndSend(conn, &AcceptIdentification{ err = EncodeAndSend(conn, &AcceptIdentification{
NodeType: pkt.NodeType, NodeType: pkt.NodeType,
MyUUID: 0, // XXX MyUUID: 0, // XXX
......
...@@ -63,29 +63,32 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) { ...@@ -63,29 +63,32 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
nodeInfo, err := Identify(link) nodeInfo, err := Identify(link)
if err != nil { if err != nil {
fmt.Printf("stor: peer identification failed: %v\n", err) fmt.Printf("peer identification failed: %v\n", err)
return return
} }
/* var serveConn func(context.Context, *Conn)
pktri, err := expect(RequestIdentification) switch nodeInfo.NodeType {
if err != nil { case CLIENT:
send(err) serveConn = stor.ServeClient
return
}
if pktri.ProtocolVersion != PROTOCOL_VERSION { default:
sendErr("...") fmt.Printf("unexpected peer type: %v\n", nodeInfo.NodeType)
return return
} }
(.NodeType, .UUID, .Address, .Name, .IdTimestamp) -> check + register to NM // identification passed, now serve other requests
for {
send(AcceptIdentification{...}) conn, err := link.Accept()
// TODO mark link as identified if err != nil {
fmt.Printf("accept: %v\n", err) // XXX err ctx
continue
}
*/ // XXX adjust ctx ?
// XXX wrap conn close to happen here, not in ServeClient ?
go serveConn(ctx, conn)
}
} }
......
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