aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2022-12-29 03:44:11 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2022-12-29 03:44:11 +0100
commitb011620dbb4243d4a0d9febb89e438a2dd517a61 (patch)
treec7f267b3d454bd607f58c49c9332696e1865d549 /src
parent944c16adfb83976149701086e20146797d4330df (diff)
downloadmt_rudp-b011620dbb4243d4a0d9febb89e438a2dd517a61.tar.xz
finish receiver
Diffstat (limited to 'src')
-rw-r--r--src/main.rs10
-rw-r--r--src/recv_worker.rs5
2 files changed, 8 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index d5fa952..b6a6af6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,11 +10,12 @@ use byteorder::{BigEndian, WriteBytesExt};
pub use client::{connect, Sender as Client};
use num_enum::TryFromPrimitive;
use std::{
+ collections::HashMap,
io::{self, Write},
ops,
sync::Arc,
};
-use tokio::sync::{mpsc, RwLock};
+use tokio::sync::{mpsc, Mutex, RwLock};
pub const PROTO_ID: u32 = 0x4f457403;
pub const UDP_PKT_SIZE: usize = 512;
@@ -70,13 +71,10 @@ pub type Error = error::Error;
pub type InPkt = Result<Pkt<Vec<u8>>, Error>;
#[derive(Debug)]
-pub struct AckChan;
-
-#[derive(Debug)]
pub struct RudpShare<S: UdpSender> {
pub id: u16,
pub remote_id: RwLock<u16>,
- pub chans: Vec<AckChan>,
+ pub ack_chans: Mutex<HashMap<u16, mpsc::Sender<()>>>,
udp_tx: S,
}
@@ -156,7 +154,7 @@ pub fn new<S: UdpSender, R: UdpReceiver>(
id,
remote_id: RwLock::new(remote_id),
udp_tx,
- chans: (0..NUM_CHANS).map(|_| AckChan).collect(),
+ ack_chans: Mutex::new(HashMap::new()),
});
let recv_share = Arc::clone(&share);
diff --git a/src/recv_worker.rs b/src/recv_worker.rs
index f83e8ef..316bb48 100644
--- a/src/recv_worker.rs
+++ b/src/recv_worker.rs
@@ -133,7 +133,10 @@ impl<R: UdpReceiver, S: UdpSender> RecvWorker<R, S> {
match cursor.read_u8()?.try_into()? {
PktType::Ctl => match cursor.read_u8()?.try_into()? {
- CtlType::Ack => { /* TODO */ }
+ CtlType::Ack => {
+ let seqnum = cursor.read_u16::<BigEndian>()?;
+ self.share.ack_chans.lock().await.remove(&seqnum);
+ }
CtlType::SetPeerID => {
let mut id = self.share.remote_id.write().await;