feat: add on_piece_completed method on TorrentStorage#219
Merged
ikatson merged 2 commits intoikatson:mainfrom Aug 28, 2024
Merged
feat: add on_piece_completed method on TorrentStorage#219ikatson merged 2 commits intoikatson:mainfrom
ikatson merged 2 commits intoikatson:mainfrom
Conversation
ikatson
requested changes
Aug 27, 2024
| Ok(()) | ||
| } | ||
|
|
||
| fn on_piece_completed(&self, _file_id: usize, _offset: u64) -> anyhow::Result<()> { |
Owner
There was a problem hiding this comment.
It would probably make sense to implement default in the trait itself not to add this to every single storage example that exists.
There's also "storage_middleware" feature that will break if turned on (although I do understand it will break already anyway because ManagedTorrentInfo was renamed, but that's a separate thing)
Author
There was a problem hiding this comment.
Added default (empty) implementation in the trait itself, can still be override in trait implementations.
I checked and a cargo check --all-features build (apart from an error of multiple definition of Sha1
error[E0428]: the name `Sha1` is defined multiple times
--> crates/sha1w/src/lib.rs:79:1
|
76 | pub type Sha1 = crypto_hash_impl::Sha1CryptoHash;
| ------------------------------------------------- previous definition of the type `Sha1` here
...
79 | pub type Sha1 = ring_impl::Sha1Ring;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Sha1` redefined here
|
= note: `Sha1` must be defined only once in the type namespace of this module
- Reset previous implementation of InMemoryExampleStorage - Implement default (empty) behaviour of on_piece_completed in trait itself - Now passing a ValidPieceIndex in on_piece_completed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed in #211, a custom
TorrentStoragethat would remove blocks when read bypread_exact()is currently not working as this method is also called when checking torrent piece hashes.This PR adds a new method on
TorrentStoragetrait,on_piece_completed()that is automatically called by rqbit when a piece has been downloaded and checked. This allows implementations to deal with this new information as they think is best.InMemoryExampleStoragestructure has been updated to remove blocks when they have been read by a stream.For all other implementations this new method only returns Ok(()) as I don't think that this has to be handled explicitly.
Note: I think there is however still an issue but apart from this new method added as blocks are loop-downloaded as they are no more available in the
TorrentStorage