Less spammy log message

This commit is contained in:
Igor Katson 2024-04-26 09:42:44 +01:00
parent 5ffe2d59b7
commit ffc662e370
4 changed files with 13 additions and 9 deletions

View file

@ -194,10 +194,6 @@ impl ChunkTracker {
.filter_map(|id| self.lengths.validate_piece_index(id))
}
pub(crate) fn is_piece_queued(&self, id: ValidPieceIndex) -> bool {
self.queue_pieces[id.get() as usize]
}
pub(crate) fn is_piece_have(&self, id: ValidPieceIndex) -> bool {
self.have[id.get() as usize]
}

View file

@ -710,7 +710,9 @@ impl TorrentStateLive {
self.streams.wake_streams_on_piece_completed(id);
if self.is_finished() {
info!("torrent finished downloading");
if self.lock_read("chunks").get_chunks()?.get_selected_pieces()[id.get_usize()] {
info!("torrent finished downloading");
}
self.finished_notify.notify_waiters();
if !self.has_active_streams_unfinished_files() {

View file

@ -304,16 +304,17 @@ impl ManagedTorrent {
})
}
fn maybe_reconnect_needed_peers_for_file(&self, file_id: usize) {
fn maybe_reconnect_needed_peers_for_file(&self, file_id: usize) -> bool {
// If we have the full file, don't bother.
if let Ok(true) = self.with_opened_file(file_id, |f| f.approx_is_finished()) {
return;
return false;
}
self.with_state(|state| {
if let crate::ManagedTorrentState::Live(l) = &state {
l.reconnect_all_not_needed_peers();
}
})
});
true
}
pub fn stream(self: Arc<Self>, file_id: usize) -> anyhow::Result<FileStream> {
@ -331,7 +332,9 @@ impl ManagedTorrent {
file_torrent_abs_offset: fd_offset,
torrent: self,
};
s.torrent.maybe_reconnect_needed_peers_for_file(file_id);
if s.torrent.maybe_reconnect_needed_peers_for_file(file_id) {
s.torrent.with_opened_file(file_id, |f| f.reopen(false))??;
}
streams.streams.insert(
s.stream_id,
StreamState {

View file

@ -67,6 +67,9 @@ impl ValidPieceIndex {
pub const fn get(&self) -> u32 {
self.0
}
pub const fn get_usize(&self) -> usize {
self.0 as usize
}
}
impl Lengths {