Almost nothing
This commit is contained in:
parent
3a9a858438
commit
1f899b63a6
2 changed files with 13 additions and 9 deletions
|
|
@ -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<impl Stream<Item = SocketAddr> + 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 {
|
||||
|
|
|
|||
|
|
@ -67,9 +67,11 @@ impl Lengths {
|
|||
chunk_length: Option<u32>,
|
||||
) -> anyhow::Result<Self> {
|
||||
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,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue