mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-16 04:13:09 +00:00
advertising torrent info hash on DHT
This commit is contained in:
parent
e4a04f37da
commit
d85b146602
@ -56,7 +56,20 @@ proc addCidToQueue(b: Advertiser, cid: Cid) {.async: (raises: [CancelledError]).
|
||||
|
||||
trace "Advertising", cid
|
||||
|
||||
proc advertiseInfoHash(b: Advertiser, cid: Cid) {.async: (raises: [CancelledError]).} =
|
||||
if (infoHashCid =? cid.isTorrentInfoHash):
|
||||
# announce torrent info hash
|
||||
await b.addCidToQueue(cid)
|
||||
return
|
||||
await b.addCidToQueue(cid)
|
||||
|
||||
proc advertiseBlock(b: Advertiser, cid: Cid) {.async: (raises: [CancelledError]).} =
|
||||
without isTorrent =? cid.isTorrentInfoHash, err:
|
||||
warn "Unable to determine if cid is torrent info hash"
|
||||
return
|
||||
if isTorrent:
|
||||
await b.addCidToQueue(cid)
|
||||
return
|
||||
without isM =? cid.isManifest, err:
|
||||
warn "Unable to determine if cid is manifest"
|
||||
return
|
||||
@ -89,6 +102,22 @@ proc advertiseLocalStoreLoop(b: Advertiser) {.async: (raises: []).} =
|
||||
if cid =? await c:
|
||||
await b.advertiseBlock(cid)
|
||||
trace "Advertiser iterating blocks finished."
|
||||
try:
|
||||
if cids =? await b.localStore.listBlocks(blockType = BlockType.Torrent):
|
||||
trace "Advertiser begins iterating torrent blocks..."
|
||||
for c in cids:
|
||||
if cid =? await c:
|
||||
await b.advertiseBlock(cid)
|
||||
trace "Advertiser iterating torrent blocks finished."
|
||||
if cids =? await b.localStore.listBlocks(blockType = BlockType.Manifest):
|
||||
trace "Advertiser begins iterating blocks..."
|
||||
for c in cids:
|
||||
if cid =? await c:
|
||||
await b.advertiseBlock(cid)
|
||||
trace "Advertiser iterating blocks finished."
|
||||
except CatchableError as e:
|
||||
error "Error in advertise local store loop", error = e.msgDetail
|
||||
raiseAssert("Unexpected exception in advertiseLocalStoreLoop")
|
||||
|
||||
await sleepAsync(b.advertiseLocalStoreLoopSleep)
|
||||
except CancelledError:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user