From: Lizzy Fleckenstein Date: Thu, 29 Dec 2022 02:44:11 +0000 (+0100) Subject: finish receiver X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b011620dbb4243d4a0d9febb89e438a2dd517a61;hp=944c16adfb83976149701086e20146797d4330df;p=mt_rudp.git finish receiver --- 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; @@ -69,14 +70,11 @@ pub struct Pkt { pub type Error = error::Error; pub type InPkt = Result>, Error>; -#[derive(Debug)] -pub struct AckChan; - #[derive(Debug)] pub struct RudpShare { pub id: u16, pub remote_id: RwLock, - pub chans: Vec, + pub ack_chans: Mutex>>, udp_tx: S, } @@ -156,7 +154,7 @@ pub fn new( 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 RecvWorker { match cursor.read_u8()?.try_into()? { PktType::Ctl => match cursor.read_u8()?.try_into()? { - CtlType::Ack => { /* TODO */ } + CtlType::Ack => { + let seqnum = cursor.read_u16::()?; + self.share.ack_chans.lock().await.remove(&seqnum); + } CtlType::SetPeerID => { let mut id = self.share.remote_id.write().await;