handle duplicate packets

This commit is contained in:
Milo Turner 2020-03-10 12:32:23 -04:00
parent dd6c4ff088
commit 86af734542
2 changed files with 30 additions and 13 deletions

View File

@ -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,

View File

@ -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),