diff --git a/codex/stores/cachestore.nim b/codex/stores/cachestore.nim index 404fbbcb..c2c7001c 100644 --- a/codex/stores/cachestore.nim +++ b/codex/stores/cachestore.nim @@ -27,6 +27,7 @@ import ../errors import ../manifest import ../merkletree import ../utils +import ../clock export blockstore @@ -219,6 +220,16 @@ method putBlockCidAndProof*( self.cidAndProofCache[(treeCid, index)] = (blockCid, proof) success() +method ensureExpiry*( + self: CacheStore, + cid: Cid, + expiry: SecondsSince1970 +): Future[?!void] {.async.} = + ## Updates block's assosicated TTL in store - not applicable for CacheStore + ## + + discard # CacheStore does not have notion of TTL + method delBlock*(self: CacheStore, cid: Cid): Future[?!void] {.async.} = ## Delete a block from the blockstore ## @@ -239,7 +250,7 @@ method delBlock*(self: CacheStore, treeCid: Cid, index: Natural): Future[?!void] if removed =? maybeRemoved: return await self.delBlock(removed[0]) - + return success() method close*(self: CacheStore): Future[void] {.async.} = diff --git a/codex/stores/networkstore.nim b/codex/stores/networkstore.nim index c5e0d208..16e72b21 100644 --- a/codex/stores/networkstore.nim +++ b/codex/stores/networkstore.nim @@ -20,6 +20,7 @@ import pkg/libp2p import ../blocktype import ../utils/asyncheapqueue import ../utils/asynciter +import ../clock import ./blockstore import ../blockexchange @@ -91,6 +92,27 @@ method putBlockCidAndProof*( ): Future[?!void] = self.localStore.putBlockCidAndProof(treeCid, index, blockCid, proof) +method ensureExpiry*( + self: NetworkStore, + cid: Cid, + expiry: SecondsSince1970 +): Future[?!void] {.async.} = + ## Ensure that block's assosicated expiry is at least given timestamp + ## If the current expiry is lower then it is updated to the given one, otherwise it is left intact + ## + + if (await self.localStore.hasBlock(cid)).tryGet: + return await self.localStore.ensureExpiry(cid, expiry) + else: + trace "Updating expiry - block not in local store", cid + + return success() + +method listBlocks*( + self: NetworkStore, + blockType = BlockType.Manifest): Future[?!AsyncIter[?Cid]] = + self.localStore.listBlocks(blockType) + method delBlock*(self: NetworkStore, cid: Cid): Future[?!void] = ## Delete a block from the blockstore ##