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 {
// Identify identifies peer on the link
// it expects peer to send RequestIdentification packet and TODO
func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo*/, err error) {
nodeInfo := RequestIdentification{}
// the first conn must come with RequestIdentification packet
conn, err := link.Accept()
if err != nil {
......@@ -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)
}
// TODO (.NodeType, .UUID, .Address, .Name, .IdTimestamp) -> check + register to NM
err = EncodeAndSend(conn, &AcceptIdentification{
NodeType: pkt.NodeType,
MyUUID: 0, // XXX
......
......@@ -63,29 +63,32 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
nodeInfo, err := Identify(link)
if err != nil {
fmt.Printf("stor: peer identification failed: %v\n", err)
fmt.Printf("peer identification failed: %v\n", err)
return
}
/*
pktri, err := expect(RequestIdentification)
if err != nil {
send(err)
return
}
var serveConn func(context.Context, *Conn)
switch nodeInfo.NodeType {
case CLIENT:
serveConn = stor.ServeClient
if pktri.ProtocolVersion != PROTOCOL_VERSION {
sendErr("...")
default:
fmt.Printf("unexpected peer type: %v\n", nodeInfo.NodeType)
return
}
(.NodeType, .UUID, .Address, .Name, .IdTimestamp) -> check + register to NM
send(AcceptIdentification{...})
// TODO mark link as identified
// identification passed, now serve other requests
for {
conn, err := link.Accept()
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