mirror of
https://github.com/vacp2p/research.git
synced 2025-02-24 04:08:15 +00:00
WIP misc parsing/creation
still some issues with .id field now
This commit is contained in:
parent
8a7042741e
commit
fe09be631e
@ -48,6 +48,7 @@ proc contentHash(data: string): string =
|
|||||||
let sha1 = secureHash(str)
|
let sha1 = secureHash(str)
|
||||||
return $sha1
|
return $sha1
|
||||||
|
|
||||||
|
# TODO: Remove me
|
||||||
proc parseMessage(message: string): Message =
|
proc parseMessage(message: string): Message =
|
||||||
var msg = Message()
|
var msg = Message()
|
||||||
stdout.writeLine("Server: received from client: ", message)
|
stdout.writeLine("Server: received from client: ", message)
|
||||||
@ -59,6 +60,12 @@ proc parseMessage(message: string): Message =
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
proc stringifyProtobuf[T](protobuf: T): string =
|
||||||
|
var stream = newStringStream()
|
||||||
|
stream.write(protobuf)
|
||||||
|
var stringified = $stream.data
|
||||||
|
return stringified
|
||||||
|
|
||||||
proc store(data: string): string =
|
proc store(data: string): string =
|
||||||
let hash = contentHash(data)
|
let hash = contentHash(data)
|
||||||
contentStorage[hash] = data
|
contentStorage[hash] = data
|
||||||
@ -108,6 +115,7 @@ proc handleMessage2(msg: string): CASResponse =
|
|||||||
var resp = new CASResponse
|
var resp = new CASResponse
|
||||||
resp.id = key
|
resp.id = key
|
||||||
resp.data = data
|
resp.data = data
|
||||||
|
echo("resp: ", resp)
|
||||||
return resp
|
return resp
|
||||||
elif readMsg.has(operation) and readMsg.operation == CASRequest_Op.GET:
|
elif readMsg.has(operation) and readMsg.operation == CASRequest_Op.GET:
|
||||||
# TODO: Handle GET op
|
# TODO: Handle GET op
|
||||||
@ -135,20 +143,15 @@ while true:
|
|||||||
if message == "":
|
if message == "":
|
||||||
clientsToRemove.add(index)
|
clientsToRemove.add(index)
|
||||||
|
|
||||||
let resp = handleMessage2(message)
|
# XXX: Getting field id not init, er
|
||||||
#let resp = handleMessage(parseMessage(message))
|
let casResp = handleMessage2(message)
|
||||||
# TODO: Respond to client
|
let resp = stringifyProtobuf(casResp)
|
||||||
# XXX: Client is currently non-interactive so sending to other client
|
|
||||||
# That is, node is split into node_receiving and node_sending
|
|
||||||
# Sending to all clients:
|
# Sending to all clients:
|
||||||
echo("RESPONSE: ", resp)
|
echo("RESPONSE: ", resp)
|
||||||
# TODO XXX: This seems off? Just send to replier here
|
# TODO: Should send to actually sending client, not all
|
||||||
# XXX: Wrong, need to serialize here right
|
|
||||||
|
|
||||||
# TODO: Fixme
|
|
||||||
for c in clients:
|
for c in clients:
|
||||||
c.send($resp & "\r\L")
|
let payload = $resp & "\r\L"
|
||||||
|
c.send(payload)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ proc handler() {.noconv.} =
|
|||||||
|
|
||||||
setControlCHook(handler)
|
setControlCHook(handler)
|
||||||
|
|
||||||
|
# TODO: Move to protocol yeah
|
||||||
proc parseCASResponse(msg: string): CASResponse =
|
proc parseCASResponse(msg: string): CASResponse =
|
||||||
var stream = newStringStream()
|
var stream = newStringStream()
|
||||||
stream.write(msg)
|
stream.write(msg)
|
||||||
@ -43,9 +43,13 @@ proc connect(socket: AsyncSocket, serverAddr: string, portInt: int) {.async.} =
|
|||||||
try:
|
try:
|
||||||
var readMsg = parseCASResponse(line)
|
var readMsg = parseCASResponse(line)
|
||||||
echo("readMsg2: ", readMsg)
|
echo("readMsg2: ", readMsg)
|
||||||
|
# XXX: This should be hit, wy not?
|
||||||
if readMsg.has(id):
|
if readMsg.has(id):
|
||||||
# XXX: for data, need to map it back
|
# XXX: for data, need to map it back
|
||||||
echo("readMsg id: ", readMsg.id)
|
echo("readMsg id: ", readMsg.id)
|
||||||
|
echo("readMsg id regardless:", readMsg.id)
|
||||||
|
if readMsg.has(data):
|
||||||
|
echo("readMsg data: ", readMsg.data)
|
||||||
except:
|
except:
|
||||||
echo("Ignoring incoming message: " & getCurrentExceptionMsg())
|
echo("Ignoring incoming message: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user