handle duplicate packets
This commit is contained in:
parent
dd6c4ff088
commit
86af734542
|
@ -61,16 +61,27 @@ where
|
|||
loop {
|
||||
match peer.recv().await {
|
||||
Ok(UpMsg::Data { payload, seg_idx }) => {
|
||||
let len = payload.len();
|
||||
segs.entry(seg_idx).or_insert(Some(payload));
|
||||
if segs.contains_key(&seg_idx) {
|
||||
log.recv_data_ignored(seg_idx as usize, payload.len()).await;
|
||||
} else {
|
||||
log.recv_data_accepted(
|
||||
seg_idx as usize,
|
||||
payload.len(),
|
||||
hptp::logger::OutOfOrder,
|
||||
)
|
||||
.await;
|
||||
segs.insert(seg_idx, Some(payload));
|
||||
let ack = DownMsg::Ack {
|
||||
idxs: segs.keys().cloned().collect(),
|
||||
};
|
||||
log.debug_msg(format!("sent ack: {:?}",
|
||||
segs.keys().collect::<Vec<_>>())).await;
|
||||
send(peer, ack).await?;
|
||||
log.recv_data_accepted(seg_idx as usize, len, hptp::logger::OutOfOrder)
|
||||
log.debug_msg(format!("sent ack: {:?}", {
|
||||
let mut idxs = segs.keys().collect::<Vec<_>>();
|
||||
idxs.sort_unstable();
|
||||
idxs
|
||||
}))
|
||||
.await;
|
||||
send(peer, ack).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Err(peer::RecvError::InvalidMessage { .. }) => log.recv_corrupt().await,
|
||||
|
|
|
@ -44,8 +44,9 @@ impl Logger {
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn recv_data_ignored(&mut self) {
|
||||
self.log_payload(LogPayload::RecvDataIgnored).await
|
||||
pub async fn recv_data_ignored(&mut self, start: usize, len: usize) {
|
||||
self.log_payload(LogPayload::RecvDataIgnored { start, len })
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn recv_ack(&mut self, last_offset: usize) {
|
||||
|
@ -91,7 +92,10 @@ enum LogPayload<'a> {
|
|||
len: usize,
|
||||
order: AcceptedOrder,
|
||||
},
|
||||
RecvDataIgnored,
|
||||
RecvDataIgnored {
|
||||
start: usize,
|
||||
len: usize,
|
||||
},
|
||||
RecvAck {
|
||||
last_offset: usize,
|
||||
},
|
||||
|
@ -134,7 +138,9 @@ impl Display for LogPayload<'_> {
|
|||
LogPayload::RecvDataAccepted { start, len, order } => {
|
||||
write!(f, "[recv data] {} ({}) ACCEPTED ({})", start, len, order)
|
||||
}
|
||||
LogPayload::RecvDataIgnored => write!(f, "[recv data] IGNORED"),
|
||||
LogPayload::RecvDataIgnored { start, len } => {
|
||||
write!(f, "[recv data] {} ({}) IGNORED", start, len)
|
||||
}
|
||||
LogPayload::RecvCorrupt => write!(f, "[recv corrupt packet]"),
|
||||
LogPayload::RecvAck { last_offset } => write!(f, "[recv ack] {}", last_offset),
|
||||
LogPayload::SendData { start, len } => write!(f, "[send data] {} ({})", start, len),
|
||||
|
|
Loading…
Reference in New Issue