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)
|
||||
return $sha1
|
||||
|
||||
# TODO: Remove me
|
||||
proc parseMessage(message: string): Message =
|
||||
var msg = Message()
|
||||
stdout.writeLine("Server: received from client: ", message)
|
||||
@ -59,6 +60,12 @@ proc parseMessage(message: string): Message =
|
||||
|
||||
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 =
|
||||
let hash = contentHash(data)
|
||||
contentStorage[hash] = data
|
||||
@ -108,6 +115,7 @@ proc handleMessage2(msg: string): CASResponse =
|
||||
var resp = new CASResponse
|
||||
resp.id = key
|
||||
resp.data = data
|
||||
echo("resp: ", resp)
|
||||
return resp
|
||||
elif readMsg.has(operation) and readMsg.operation == CASRequest_Op.GET:
|
||||
# TODO: Handle GET op
|
||||
@ -135,20 +143,15 @@ while true:
|
||||
if message == "":
|
||||
clientsToRemove.add(index)
|
||||
|
||||
let resp = handleMessage2(message)
|
||||
#let resp = handleMessage(parseMessage(message))
|
||||
# TODO: Respond to client
|
||||
# XXX: Client is currently non-interactive so sending to other client
|
||||
# That is, node is split into node_receiving and node_sending
|
||||
# XXX: Getting field id not init, er
|
||||
let casResp = handleMessage2(message)
|
||||
let resp = stringifyProtobuf(casResp)
|
||||
# Sending to all clients:
|
||||
echo("RESPONSE: ", resp)
|
||||
# TODO XXX: This seems off? Just send to replier here
|
||||
# XXX: Wrong, need to serialize here right
|
||||
|
||||
# TODO: Fixme
|
||||
# TODO: Should send to actually sending client, not all
|
||||
for c in clients:
|
||||
c.send($resp & "\r\L")
|
||||
|
||||
let payload = $resp & "\r\L"
|
||||
c.send(payload)
|
||||
except TimeoutError:
|
||||
discard
|
||||
|
||||
|
@ -12,7 +12,7 @@ proc handler() {.noconv.} =
|
||||
|
||||
setControlCHook(handler)
|
||||
|
||||
|
||||
# TODO: Move to protocol yeah
|
||||
proc parseCASResponse(msg: string): CASResponse =
|
||||
var stream = newStringStream()
|
||||
stream.write(msg)
|
||||
@ -43,9 +43,13 @@ proc connect(socket: AsyncSocket, serverAddr: string, portInt: int) {.async.} =
|
||||
try:
|
||||
var readMsg = parseCASResponse(line)
|
||||
echo("readMsg2: ", readMsg)
|
||||
# XXX: This should be hit, wy not?
|
||||
if readMsg.has(id):
|
||||
# XXX: for data, need to map it back
|
||||
echo("readMsg id: ", readMsg.id)
|
||||
echo("readMsg id regardless:", readMsg.id)
|
||||
if readMsg.has(data):
|
||||
echo("readMsg data: ", readMsg.data)
|
||||
except:
|
||||
echo("Ignoring incoming message: " & getCurrentExceptionMsg())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user