adds Torrent BlockType

This commit is contained in:
Marcin Czenko 2025-02-28 16:16:36 +01:00
parent 6938ba203d
commit e4a04f37da
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
5 changed files with 15 additions and 2 deletions

View File

@ -134,6 +134,12 @@ func mimetype*(self: Manifest): ?string =
# Operations on block list
############################################################
func isTorrentInfoHash*(cid: Cid): ?!bool =
success (InfoHashV1Codec == ?cid.contentType().mapFailure(CodexError))
func isTorrentInfoHash*(mc: MultiCodec): ?!bool =
success (mc == InfoHashV1Codec)
func isManifest*(cid: Cid): ?!bool =
success (ManifestCodec == ?cid.contentType().mapFailure(CodexError))

View File

@ -25,6 +25,7 @@ type
BlockNotFoundError* = object of CodexError
BlockType* {.pure.} = enum
Torrent
Manifest
Block
Both

View File

@ -166,8 +166,10 @@ method listBlocks*(
return true
of BlockType.Manifest:
return isManifest
of BlockType.Torrent:
return isTorrent
of BlockType.Block:
return not isManifest
return not (isManifest or isTorrent)
)
)
success(iter)

View File

@ -24,6 +24,7 @@ const
CodexBlocksKey* = Key.init(CodexBlocksNamespace).tryGet
CodexTotalBlocksKey* = Key.init(CodexBlockTotalNamespace).tryGet
CodexManifestKey* = Key.init(CodexManifestNamespace).tryGet
TorrentInfoHashKey* = Key.init(TorrentInfoHashNamespace).tryGet
BlocksTtlKey* = Key.init(CodexBlocksTtlNamespace).tryGet
BlockProofKey* = Key.init(CodexBlockProofNamespace).tryGet
QuotaKey* = Key.init(CodexQuotaNamespace).tryGet
@ -33,7 +34,9 @@ const
func makePrefixKey*(postFixLen: int, cid: Cid): ?!Key =
let cidKey = ?Key.init(($cid)[^postFixLen ..^ 1] & "/" & $cid)
if ?cid.isManifest:
if ?cid.isTorrentInfoHash:
success TorrentInfoHashKey / cidKey
elif ?cid.isManifest:
success CodexManifestKey / cidKey
else:
success CodexBlocksKey / cidKey

View File

@ -304,6 +304,7 @@ method listBlocks*(
let key =
case blockType
of BlockType.Torrent: TorrentInfoHashKey
of BlockType.Manifest: CodexManifestKey
of BlockType.Block: CodexBlocksKey
of BlockType.Both: CodexRepoKey