def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.Database): root = rs.get() msg = service.CreateDatabase(request) return dbCreateResponse( reply = msg )
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.SafeSetOptions): root = rs.get() index = schema_pb2.Index(index=root.index) content = schema_pb2.Content(timestamp=int(time()), payload=request.kv.value) skv = schema_pb2.StructuredKeyValue(key=request.kv.key, value=content) rawRequest = schema_pb2.SafeSetSVOptions(skv=skv, rootIndex=index) msg = service.SafeSetSV(rawRequest) digest = item.digest(msg.index, rawRequest.skv.key, rawRequest.skv.value.SerializeToString()) if bytes(msg.leaf) != digest: raise VerificationException("Proof does not match the given item.") verified = proofs.verify(msg, bytes(msg.leaf), root) if verified: toCache = schema_pb2.Root(index=msg.index, root=msg.root) try: rs.set(toCache) except Exception as e: raise e return SafeSetResponse(index=msg.index, leaf=msg.leaf, root=msg.root, at=msg.at, inclusionPath=msg.inclusionPath, consistencyPath=msg.consistencyPath, verified=verified)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.KVList): currtime = int(time()) rawRequest = schema_pb2.SKVList( SKVs=[_packValueTime(kv, currtime) for kv in request.KVs], ) idx = service.SetBatchSV(rawRequest) return batchSetResponse(index=idx)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.KeyValue): content = schema_pb2.Content(timestamp=int(time()), payload=request.value) skv = schema_pb2.StructuredKeyValue(key=request.key, value=content) msg = service.SetSV(skv) return SetResponse(index=msg.index)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.KeyList): rawRequest = schema_pb2.KeyList(keys=request.keys) msg = service.GetBatchSV(rawRequest) return batchGetResponse(itemlist=msg #keylist = msg.KeyList, #itemlist = msg.ItemList )
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.SafeGetOptions): root = rs.get() index = schema_pb2.Index(index=root.index) rawRequest = schema_pb2.SafeGetOptions(key=request.key, rootIndex=index) msg = service.SafeGetSV(rawRequest) verified = proofs.verify( msg.proof, item.digest(msg.item.index, msg.item.key, msg.item.value.SerializeToString()), root) if verified: toCache = schema_pb2.Root(index=msg.proof.at, root=msg.proof.root) try: rs.set(toCache) except: raise VerificationException("Failed to verify") i = msg.item return SafeGetResponse(index=i.index, key=i.key, timestamp=i.value.timestamp, value=i.value.payload.decode("utf-8"), verified=verified)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.Key): msg = service.GetSV(request) return GetResponse(value=msg.value.payload, timestamp=msg.value.timestamp)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: schema_pb2.Database): msg = service.UseDatabase(request) return dbUseResponse(reply=msg)
def call(service: schema_pb2_grpc.ImmuServiceStub, rs: RootService, request: None): NoRequest = Empty() msg = service.DatabaseList(NoRequest) return dbListResponse(dblist=msg)