hyperspace icon indicating copy to clipboard operation
hyperspace copied to clipboard

Expose bitfield

Open Frando opened this issue 5 years ago • 3 comments

This adds two optional fields bitfield and length to the has method request. If set, the response includes a run-length encoded bitfield of the downloaded blocks from seq for length.

On the client side, a new getBitfield method is added. It resolves to the decoded bitfield, wrapped in a bitfield instance.

This, together with #5, solves #2 and should allow indexers to work reliably and efficiently on sparsely synced hypercores.

Frando avatar Aug 11 '20 01:08 Frando

Whats your usecase for getting the bitfields out? Since this is adding the semver'ed api surface, we're per default a little conservative about adding apis

mafintosh avatar Aug 13 '20 14:08 mafintosh

I have an indexer that wants to index all downloaded blocks for a list of (sparse) feeds.Therefore, it tracks which key-seq pairs it has indexed already. With hyperspace, I cannot ensure that there's no downloads happening while the indexer is not running. So, to check for that, on each start of the indexer, without this patch I'd have to do one async has request for each seq for each feed I'm tracking. With this patch, it's just one async request per feed, and then the bitfield comparison can happen in a regular sync loop.

Frando avatar Aug 13 '20 15:08 Frando

@mafintosh if a new method getBitfield sounds better to you I'm fine with that as well. I thought it fitted nicely with the has method (to keep API surface smaller) but don't really mind.

Frando avatar Sep 07 '20 12:09 Frando