feat: add on_piece_completed method on TorrentStorage

This commit is contained in:
LIAUD Corentin 2024-08-27 22:00:14 +02:00
parent 67f984ac6f
commit 35d57ae8a2
No known key found for this signature in database
GPG key ID: 48D3490FB1A44E6A
10 changed files with 100 additions and 18 deletions

View file

@ -97,6 +97,9 @@ pub trait TorrentStorage: Send + Sync {
/// Replace the current storage with a dummy, and return a new one that should be used instead.
/// This is used to make the underlying object useless when e.g. pausing the torrent.
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
/// Callback called every time a piece has completed and has been validated.
fn on_piece_completed(&self, file_id: usize, offset: u64) -> anyhow::Result<()>;
}
impl<U: TorrentStorage + ?Sized> TorrentStorage for Box<U> {
@ -127,4 +130,8 @@ impl<U: TorrentStorage + ?Sized> TorrentStorage for Box<U> {
fn init(&mut self, meta: &ManagedTorrentShared) -> anyhow::Result<()> {
(**self).init(meta)
}
fn on_piece_completed(&self, file_id: usize, offset: u64) -> anyhow::Result<()> {
(**self).on_piece_completed(file_id, offset)
}
}