casserver/client use new interface and bytes

This commit is contained in:
Oskar Thoren 2019-09-04 16:02:34 +02:00
parent 19b06cb1a8
commit 6bf6d38c6d
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
2 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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