Sketch use cas hash for ns wip

This commit is contained in:
Oskar Thoren 2019-08-07 14:51:07 +08:00
parent 2255b78a80
commit 6955e4c162
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
2 changed files with 16 additions and 1 deletions

View File

@ -71,7 +71,10 @@ proc handleMessage(message: Message): Response =
if arg == "POST": if arg == "POST":
echo("posting: ", data) echo("posting: ", data)
let key = store(data) let key = store(data)
return Response(code: OK, data: key) # XXX: Ad hoc protocol
let ret = data & " " & key
echo "Returning from post: ", ret
return Response(code: OK, data: ret)
elif arg == "GET": elif arg == "GET":
echo("getting: ", data) echo("getting: ", data)

View File

@ -45,6 +45,8 @@ proc connect(socket: AsyncSocket, serverAddr: string, portInt: int) {.async.} =
# TODO: Differentiate between NS and CAS # TODO: Differentiate between NS and CAS
echo(portInt, ": Incoming: ", line) echo(portInt, ": Incoming: ", line)
#if portInt == 6002
echo("Node started") echo("Node started")
# TODO: paramCount and paramStr parsing args # TODO: paramCount and paramStr parsing args
let serverAddr = "localhost" let serverAddr = "localhost"
@ -71,6 +73,16 @@ while true:
elif isCASMessage(^messageFlowVar): elif isCASMessage(^messageFlowVar):
echo("Send CAS: ", prepared) echo("Send CAS: ", prepared)
asyncCheck socket2.send(message) asyncCheck socket2.send(message)
# When we send here, we also want to keep the message and use for NS
# This will be in separate thread though, so how map here?
# Nothing should block us from doing multiple and then receiving
# So either need to:
# 1) Block and wait for incoming
# 2) Use request id
# 3) Respond with initial hash as well
# 4) Some kind of callback based on connection?
# 3 is not API compliant but it seems OK from KISS POV
# Oh we actually send data blob, not hash...er, fine~.
else: else:
echo("Unknown message type ", ^messageFlowVar) echo("Unknown message type ", ^messageFlowVar)