From 6bf6d38c6d5cc115bf69adab8d5ebb5a0c8ef091 Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Wed, 4 Sep 2019 16:02:34 +0200 Subject: [PATCH] casserver/client use new interface and bytes --- remote_log/hello-twirp/casclient.nim | 27 +++++++++++++++++++++------ remote_log/hello-twirp/casserver.nim | 18 ++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/remote_log/hello-twirp/casclient.nim b/remote_log/hello-twirp/casclient.nim index 7685856..d323a1b 100644 --- a/remote_log/hello-twirp/casclient.nim +++ b/remote_log/hello-twirp/casclient.nim @@ -5,12 +5,14 @@ import strutils import cas_service_pb import cas_service_twirp -var cas_req = newvac_cas_CASRequest() +import strutils +import byteutils + +var content = newvac_cas_Content() try: - cas_req.id = "foo" - cas_req.data = "bar" + content.data = hexToSeqByte("foo".toHex()) except: - echo("Unable to create CASRequest") + echo("Unable to create Content data") quit(QuitFailure) # XXX @@ -18,7 +20,20 @@ let client = newCASClient("http://localhost:8001") # XXX: resp is wrong here try: - let resp = Post(client, cas_req) - echo(&"I got a new post: {resp.id}, {resp.data}") + let resp = Add(client, content) + let str = parseHexStr(toHex(resp.id)) + echo(&"I got a new post: {str}") except Exception as e: echo(&"Exception: {e.msg}") + + +# When you post in ipfs it's just some bytes. +# Then you get ID. + +# IPFS as CAS: +# echo "hello worlds" | ipfs add # => QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx +# ipfs cat QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx + +# Swarm as CAS: +# Very similar if used as raw chunks (otherwise content type) +# Possibly different ID scheme diff --git a/remote_log/hello-twirp/casserver.nim b/remote_log/hello-twirp/casserver.nim index fd79c3d..312a804 100644 --- a/remote_log/hello-twirp/casserver.nim +++ b/remote_log/hello-twirp/casserver.nim @@ -8,20 +8,26 @@ import nimtwirp/errors import cas_service_pb import cas_service_twirp -proc PostImpl(service: CAS, CASRequest: vac_cas_CASrequest): Future[vac_cas_CASResponse] {.async.} = - result = newvac_cas_CASResponse() - result.id = "foo2" - result.data = "bar2" +import strutils +import byteutils -# NYI: GetImpl +proc AddImpl(service: CAS, Address: vac_cas_Content): Future[vac_cas_Address] {.async.} = + # TODO: Actually store this in a (non-persisted) hash table + result = newvac_cas_Address() + result.id = hexToSeqByte("id2".toHex()) +# seq[bytes] + +proc GetImpl(service: CAS, CASRequest: vac_cas_Address): Future[vac_cas_Content] {.async.} = + result = newvac_cas_Content() + result.data = hexToSeqByte("data2".toHex()) var server = newAsyncHttpServer() service {.threadvar.}: CAS service = newCAS() -service.PostImpl = PostImpl +service.AddImpl = AddImpl proc handler(req: Request) {.async.} = # Each service will have a generated handleRequest() proc which takes the