From 1f899b63a63dff78ae650a7b14dd9c34ef2e405e Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 14 Jul 2021 15:50:40 +0100 Subject: [PATCH] Almost nothing --- crates/dht/src/dht.rs | 12 +++++++----- crates/librqbit_core/src/lengths.rs | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/dht/src/dht.rs b/crates/dht/src/dht.rs index 2680236..2eea931 100644 --- a/crates/dht/src/dht.rs +++ b/crates/dht/src/dht.rs @@ -370,6 +370,10 @@ impl DhtState { let seen = self.seen_peers.entry(target).or_default(); for peer in peers.iter() { + if peer.addr.port() < 1024 { + debug!("bad peer port, ignoring: {}", peer.addr); + continue; + } let addr = SocketAddr::V4(peer.addr); if seen.insert(addr) { bsender @@ -591,7 +595,7 @@ impl Stream for PeerStream { } Err(e) => match e { tokio_stream::wrappers::errors::BroadcastStreamRecvError::Lagged(lagged_by) => { - warn!("peer stream is lagged by {}", lagged_by); + debug!("peer stream is lagged by {}", lagged_by); let s = self.absolute_stream_pos; let e = s + lagged_by as usize; self.initial_peers_pos = Some((s, e)); @@ -639,16 +643,14 @@ impl Dht { &self, info_hash: Id20, ) -> anyhow::Result + Unpin> { - // TODO: we don't need the vec here. let (pos, rx) = self.state.lock().get_peers(info_hash)?; - let stream = PeerStream { + Ok(PeerStream { info_hash, state: self.state.clone(), absolute_stream_pos: 0, initial_peers_pos: pos, broadcast_rx: BroadcastStream::new(rx), - }; - Ok(stream) + }) } pub fn stats(&self) -> DhtStats { diff --git a/crates/librqbit_core/src/lengths.rs b/crates/librqbit_core/src/lengths.rs index d65b53b..3d5ade4 100644 --- a/crates/librqbit_core/src/lengths.rs +++ b/crates/librqbit_core/src/lengths.rs @@ -67,9 +67,11 @@ impl Lengths { chunk_length: Option, ) -> anyhow::Result { let chunk_length = chunk_length.unwrap_or(CHUNK_SIZE); - if !(is_power_of_two(piece_length as u64)) { - anyhow::bail!("piece length {} is not a power of 2", piece_length); - } + // I guess this is not needed? Don't recall why I put this check here. + // + // if !(is_power_of_two(piece_length as u64)) { + // anyhow::bail!("piece length {} is not a power of 2", piece_length); + // } if !(is_power_of_two(chunk_length as u64)) { anyhow::bail!("chunk length {} is not a power of 2", chunk_length); } @@ -84,7 +86,7 @@ impl Lengths { chunk_length, piece_length, total_length, - chunks_per_piece: piece_length / chunk_length, + chunks_per_piece: ceil_div_u64(piece_length as u64, chunk_length as u64) as u32, last_piece_id: ((total_length + 1) / piece_length as u64) as u32, last_piece_length: last_element_size_u64(total_length, piece_length as u64) as u32, })