mirror of
https://github.com/zerotier/sequential-exchange.git
synced 2026-05-22 16:28:28 -07:00
changed names
This commit is contained in:
@@ -44,8 +44,8 @@ fn receive<'a>(
|
||||
while let Ok(packet) = recv.try_recv() {
|
||||
if !drop_packet() {
|
||||
match packet {
|
||||
PacketType::EmptyReply { reply_no } => {
|
||||
let _ = seq.receive_empty_reply(reply_no);
|
||||
PacketType::Ack { reply_no } => {
|
||||
let _ = seq.receive_ack(reply_no);
|
||||
}
|
||||
PacketType::Payload { seq_no, reply_no, payload } => {
|
||||
for RecvSuccess { guard, packet, send_data } in seq.receive_iter(transport, seq_no, reply_no, payload) {
|
||||
|
||||
@@ -39,8 +39,8 @@ fn process(guard: ReplyGuard<'_, &MpscTransport<Packet>>, recv_packet: Packet, s
|
||||
|
||||
fn receive<'a>(recv: &Receiver<PacketType<Packet>>, seq: &SeqExSync<&'a MpscTransport<Packet>>, transport: &'a MpscTransport<Packet>) {
|
||||
match recv.recv().unwrap() {
|
||||
PacketType::EmptyReply { reply_no } => {
|
||||
let result = seq.receive_empty_reply(reply_no);
|
||||
PacketType::Ack { reply_no } => {
|
||||
let result = seq.receive_ack(reply_no);
|
||||
if let Ok(Exclamation) = result {
|
||||
// Our Hello World exchange ends right here.
|
||||
print!("\n");
|
||||
|
||||
+10
-10
@@ -64,7 +64,7 @@ pub struct SeqEx<TL: TransportLayer, const CAP: usize = DEFAULT_WINDOW_CAP> {
|
||||
concurrent_replies: [SeqNo; CAP],
|
||||
/// The total number of concurrent replies being processed. When a packet is received, a reply
|
||||
/// number is issued for that packet. That reply number reserves resources for itself, so that
|
||||
/// when `reply_raw` or `reply_empty_raw` are called with it, they are guaranteed not to fail.
|
||||
/// when `reply_raw` or `ack_raw` are called with it, they are guaranteed not to fail.
|
||||
/// To accomplish this we must track all issued reply numbers.
|
||||
concurrent_replies_total: usize,
|
||||
}
|
||||
@@ -158,7 +158,7 @@ impl<TL: TransportLayer, const CAP: usize> SeqEx<TL, CAP> {
|
||||
///
|
||||
/// If the return value is `Err` the queue is full and the packet will not be sent.
|
||||
/// The caller must either cancel sending, abort the connection, or wait until a call to
|
||||
/// `receive` or `receive_empty_reply` returns `Ok` and try again.
|
||||
/// `receive` or `receive_ack` returns `Ok` and try again.
|
||||
///
|
||||
/// If `Ok` is returned then the packet was successfully sent.
|
||||
///
|
||||
@@ -209,13 +209,13 @@ impl<TL: TransportLayer, const CAP: usize> SeqEx<TL, CAP> {
|
||||
let is_next = normalized_seq_no == 0;
|
||||
if is_below_range {
|
||||
// If it is below the range, that means the packet has been received twice.
|
||||
// For every received packet we either send a normal reply or send an empty reply.
|
||||
// For every received packet we either send a normal reply or send an ack.
|
||||
// If the application sent a normal reply in response to this packet previously, and
|
||||
// that reply has not been acknowledged, then arg `seq_no` will be in the send window,
|
||||
// and if the application is still deciding what to reply with, it will be in the
|
||||
// concurrent replies array.
|
||||
// If either are the case then we know we will eventually send a reply to the packet.
|
||||
// If neither are the case then we must send an empty reply so the remote peer can stop
|
||||
// If neither are the case then we must send an ack so the remote peer can stop
|
||||
// resending the packet.
|
||||
for entry in self.send_window.iter().flatten() {
|
||||
if entry.reply_no == Some(seq_no) {
|
||||
@@ -227,7 +227,7 @@ impl<TL: TransportLayer, const CAP: usize> SeqEx<TL, CAP> {
|
||||
return Err(Error::OutOfSequence);
|
||||
}
|
||||
}
|
||||
app.send_empty_reply(seq_no);
|
||||
app.send_ack(seq_no);
|
||||
return Err(Error::OutOfSequence);
|
||||
} else if is_above_range {
|
||||
return Err(Error::OutOfSequence);
|
||||
@@ -270,7 +270,7 @@ impl<TL: TransportLayer, const CAP: usize> SeqEx<TL, CAP> {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn receive_empty_reply(&mut self, reply_no: SeqNo) -> Result<TL::SendData, Error> {
|
||||
pub fn receive_ack(&mut self, reply_no: SeqNo) -> Result<TL::SendData, Error> {
|
||||
let slot = self.send_window_slot_mut(reply_no);
|
||||
if slot.as_ref().map_or(false, |e| e.seq_no == reply_no) {
|
||||
let entry = slot.take().unwrap();
|
||||
@@ -352,11 +352,11 @@ impl<TL: TransportLayer, const CAP: usize> SeqEx<TL, CAP> {
|
||||
app.send(entry.seq_no, entry.reply_no, &entry.data);
|
||||
}
|
||||
}
|
||||
pub fn reply_empty_raw(&mut self, mut app: TL, reply_no: SeqNo) {
|
||||
pub fn ack_raw(&mut self, mut app: TL, reply_no: SeqNo) {
|
||||
if self.remove_reservation(reply_no) {
|
||||
// Empty replies are only sent once. There is code in `receive_raw` to handle resending
|
||||
// an empty reply in the event that the first one here was dropped by the network.
|
||||
app.send_empty_reply(reply_no);
|
||||
// Acks are only sent once. There is code in `receive_raw` to handle resending
|
||||
// an ack in the event that the first one here was dropped by the network.
|
||||
app.send_ack(reply_no);
|
||||
}
|
||||
}
|
||||
fn remove_reservation(&mut self, reply_no: SeqNo) -> bool {
|
||||
|
||||
@@ -14,7 +14,7 @@ impl<'a, TL: TransportLayer> ReplyGuard<'a, TL> {
|
||||
}
|
||||
impl<'a, TL: TransportLayer> Drop for ReplyGuard<'a, TL> {
|
||||
fn drop(&mut self) {
|
||||
self.0.reply_empty_raw(self.1.clone(), self.2)
|
||||
self.0.ack_raw(self.1.clone(), self.2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -36,7 +36,7 @@ impl<'a, TL: TransportLayer, const CAP: usize> ReplyGuard<'a, TL, CAP> {
|
||||
impl<'a, TL: TransportLayer, const CAP: usize> Drop for ReplyGuard<'a, TL, CAP> {
|
||||
fn drop(&mut self) {
|
||||
let mut seq = self.0.seq_ex.lock().unwrap();
|
||||
seq.reply_empty_raw(self.1.clone(), self.2);
|
||||
seq.ack_raw(self.1.clone(), self.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ impl<TL: TransportLayer, const CAP: usize> SeqExSync<TL, CAP> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_empty_reply(&self, reply_no: SeqNo) -> Result<TL::SendData, Error> {
|
||||
let ret = self.lock().receive_empty_reply(reply_no);
|
||||
pub fn receive_ack(&self, reply_no: SeqNo) -> Result<TL::SendData, Error> {
|
||||
let ret = self.lock().receive_ack(reply_no);
|
||||
self.unblock(ret.is_ok());
|
||||
ret
|
||||
}
|
||||
@@ -153,7 +153,7 @@ pub enum PacketType<Payload: Clone> {
|
||||
reply_no: Option<SeqNo>,
|
||||
payload: Payload,
|
||||
},
|
||||
EmptyReply {
|
||||
Ack {
|
||||
reply_no: SeqNo,
|
||||
},
|
||||
}
|
||||
@@ -183,7 +183,7 @@ impl<Payload: Clone> TransportLayer for &MpscTransport<Payload> {
|
||||
fn send(&mut self, seq_no: SeqNo, reply_no: Option<SeqNo>, payload: &Payload) {
|
||||
let _ = self.channel.send(PacketType::Payload { seq_no, reply_no, payload: payload.clone() });
|
||||
}
|
||||
fn send_empty_reply(&mut self, reply_no: SeqNo) {
|
||||
let _ = self.channel.send(PacketType::EmptyReply { reply_no });
|
||||
fn send_ack(&mut self, reply_no: SeqNo) {
|
||||
let _ = self.channel.send(PacketType::Ack { reply_no });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ pub trait TransportLayer: Clone {
|
||||
fn update_service_time(&mut self, timestamp: i64, current_time: i64) {}
|
||||
|
||||
fn send(&mut self, seq_no: SeqNo, reply_no: Option<SeqNo>, payload: &Self::SendData);
|
||||
fn send_empty_reply(&mut self, reply_no: SeqNo);
|
||||
fn send_ack(&mut self, reply_no: SeqNo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user