mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 20:45:38 +00:00
0beeefd760
* initial implementation of repo store * allow isManifest on multicodec * rework with new blockstore * add raw codec * rework listBlocks * remove fsstore * reworking with repostore * bump datastore * fix listBlocks iterator * adding store's common tests * run common store tests * remove fsstore backend tests * bump datastore * add `listBlocks` tests * listBlocks filter based on block type * disabling tests in need of rewriting * allow passing block type * move BlockNotFoundError definition * fix tests * increase default advertise loop sleep to 10 mins * use `self` * add cache quota functionality * pass meta store and start repo * add `CacheQuotaNamespace` * pass meta store * bump datastore to latest master * don't use os `/` as key separator * Added quota limits support * tests for quota limits * add block expiration key * remove unnesesary space * use idleAsync in listBlocks * proper test name * re-add contrlC try/except * add storage quota and block ttl config options * clarify comments * change expires key format * check for block presence before storing * bump datastore * use dht with fixed datastore `has` * bump datastore to latest master * bump dht to latest master
67 lines
1.4 KiB
Nim
67 lines
1.4 KiB
Nim
## Nim-Codex
|
|
## Copyright (c) 2022 Status Research & Development GmbH
|
|
## Licensed under either of
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
## at your option.
|
|
## This file may not be copied, modified, or distributed except according to
|
|
## those terms.
|
|
|
|
import pkg/questionable/results
|
|
import pkg/libp2p/protobuf/minprotobuf
|
|
|
|
type
|
|
Tag* = object
|
|
idx*: int64
|
|
tag*: seq[byte]
|
|
|
|
TagsMessage* = object
|
|
cid*: seq[byte]
|
|
tags*: seq[Tag]
|
|
|
|
func write*(pb: var ProtoBuffer, field: int, value: Tag) =
|
|
var ipb = initProtoBuffer()
|
|
ipb.write(1, value.idx.uint64)
|
|
ipb.write(2, value.tag)
|
|
ipb.finish()
|
|
pb.write(field, ipb)
|
|
|
|
func encode*(msg: TagsMessage): seq[byte] =
|
|
var ipb = initProtoBuffer()
|
|
ipb.write(1, msg.cid)
|
|
|
|
for tag in msg.tags:
|
|
ipb.write(2, tag)
|
|
|
|
ipb.finish()
|
|
ipb.buffer
|
|
|
|
func decode*(_: type Tag, pb: ProtoBuffer): ProtoResult[Tag] =
|
|
var
|
|
value = Tag()
|
|
idx: uint64
|
|
|
|
discard ? pb.getField(1, idx)
|
|
value.idx = idx.int64
|
|
|
|
discard ? pb.getField(2, value.tag)
|
|
|
|
ok(value)
|
|
|
|
func decode*(_: type TagsMessage, msg: openArray[byte]): ProtoResult[TagsMessage] =
|
|
var
|
|
value = TagsMessage()
|
|
pb = initProtoBuffer(msg)
|
|
|
|
discard ? pb.getField(1, value.cid)
|
|
|
|
var
|
|
bytes: seq[seq[byte]]
|
|
|
|
discard ? pb.getRepeatedField(2, bytes)
|
|
|
|
for b in bytes:
|
|
value.tags.add(? Tag.decode(initProtoBuffer(b)))
|
|
|
|
ok(value)
|