From ac5ef27e84be8051f18e710bc1073f4e65287f87 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 13 Nov 2023 20:43:14 -0600 Subject: [PATCH] add skipped master changes --- codex/stores/cachestore.nim | 13 ++++++++++++- codex/stores/networkstore.nim | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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 ##