flushing bitfield

This commit is contained in:
Igor Katson 2024-08-20 21:09:58 +01:00
parent bc9e72df60
commit 2fee0ca8c2
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
4 changed files with 54 additions and 12 deletions

View file

@ -70,10 +70,22 @@ impl TorrentStateInitializing {
bitv_factory: Arc<dyn BitVFactory>,
) -> anyhow::Result<TorrentStatePaused> {
let id: TorrentIdOrHash = self.meta.info_hash.into();
let have_pieces = bitv_factory
let mut have_pieces = bitv_factory
.load(id)
.await
.context("error loading have_pieces")?;
if let Some(hp) = have_pieces.as_ref() {
let actual = hp.as_bytes().len();
let expected = self.meta.lengths.piece_bitfield_bytes();
if actual != expected {
warn!(
actual,
expected,
"the bitfield loaded isn't of correct length, ignoring it, will do full check"
);
have_pieces = None;
}
}
let have_pieces = match have_pieces {
Some(h) => h,
None => {