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();
|
let seen = self.seen_peers.entry(target).or_default();
|
||||||
|
|
||||||
for peer in peers.iter() {
|
for peer in peers.iter() {
|
||||||
|
if peer.addr.port() < 1024 {
|
||||||
|
debug!("bad peer port, ignoring: {}", peer.addr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let addr = SocketAddr::V4(peer.addr);
|
let addr = SocketAddr::V4(peer.addr);
|
||||||
if seen.insert(addr) {
|
if seen.insert(addr) {
|
||||||
bsender
|
bsender
|
||||||
|
|
@ -591,7 +595,7 @@ impl Stream for PeerStream {
|
||||||
}
|
}
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
tokio_stream::wrappers::errors::BroadcastStreamRecvError::Lagged(lagged_by) => {
|
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 s = self.absolute_stream_pos;
|
||||||
let e = s + lagged_by as usize;
|
let e = s + lagged_by as usize;
|
||||||
self.initial_peers_pos = Some((s, e));
|
self.initial_peers_pos = Some((s, e));
|
||||||
|
|
@ -639,16 +643,14 @@ impl Dht {
|
||||||
&self,
|
&self,
|
||||||
info_hash: Id20,
|
info_hash: Id20,
|
||||||
) -> anyhow::Result<impl Stream<Item = SocketAddr> + Unpin> {
|
) -> 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 (pos, rx) = self.state.lock().get_peers(info_hash)?;
|
||||||
let stream = PeerStream {
|
Ok(PeerStream {
|
||||||
info_hash,
|
info_hash,
|
||||||
state: self.state.clone(),
|
state: self.state.clone(),
|
||||||
absolute_stream_pos: 0,
|
absolute_stream_pos: 0,
|
||||||
initial_peers_pos: pos,
|
initial_peers_pos: pos,
|
||||||
broadcast_rx: BroadcastStream::new(rx),
|
broadcast_rx: BroadcastStream::new(rx),
|
||||||
};
|
})
|
||||||
Ok(stream)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stats(&self) -> DhtStats {
|
pub fn stats(&self) -> DhtStats {
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,11 @@ impl Lengths {
|
||||||
chunk_length: Option<u32>,
|
chunk_length: Option<u32>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
let chunk_length = chunk_length.unwrap_or(CHUNK_SIZE);
|
let chunk_length = chunk_length.unwrap_or(CHUNK_SIZE);
|
||||||
if !(is_power_of_two(piece_length as u64)) {
|
// I guess this is not needed? Don't recall why I put this check here.
|
||||||
anyhow::bail!("piece length {} is not a power of 2", piece_length);
|
//
|
||||||
}
|
// 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)) {
|
if !(is_power_of_two(chunk_length as u64)) {
|
||||||
anyhow::bail!("chunk length {} is not a power of 2", chunk_length);
|
anyhow::bail!("chunk length {} is not a power of 2", chunk_length);
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +86,7 @@ impl Lengths {
|
||||||
chunk_length,
|
chunk_length,
|
||||||
piece_length,
|
piece_length,
|
||||||
total_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_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,
|
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