diff --git a/crates/core/src/bc/codex.rs b/crates/core/src/bc/codex.rs index d4e8dcf..3cc7821 100644 --- a/crates/core/src/bc/codex.rs +++ b/crates/core/src/bc/codex.rs @@ -7,7 +7,6 @@ use crate::bc::model::*; use crate::bc::xml::*; use crate::{Credentials, Error, Result}; use bytes::BytesMut; -use log::*; use tokio_util::codec::{Decoder, Encoder}; pub(crate) struct BcCodex { @@ -39,9 +38,9 @@ impl Decoder for BcCodex { type Item = Bc; type Error = Error; fn decode(&mut self, src: &mut BytesMut) -> Result> { - trace!("Decoding: {:X?}", src); + // trace!("Decoding: {:X?}", src); let bc = Bc::deserialize(&self.context, src); - trace!("As: {:?}", bc); + // trace!("As: {:?}", bc); let bc = match bc { Ok(bc) => bc, Err(Error::NomIncomplete(_)) => return Ok(None), diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index 0649a72..623b0f5 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -203,9 +203,9 @@ impl BcCamera { SocketAddrOrUid::Uid(uid) => { debug!("Trying uid {}", uid); // TODO Make configurable - let allow_local = true; + let allow_local = false; let allow_remote = false; - let allow_relay = false; + let allow_relay = true; let discovery = { let mut set = tokio::task::JoinSet::new(); diff --git a/crates/core/src/bc_protocol/connection/bcconn.rs b/crates/core/src/bc_protocol/connection/bcconn.rs index d1ceeb2..42ca5b3 100644 --- a/crates/core/src/bc_protocol/connection/bcconn.rs +++ b/crates/core/src/bc_protocol/connection/bcconn.rs @@ -37,9 +37,7 @@ impl BcConnection { rx_thread.spawn(async move { loop { - trace!("packet Wait"); let packet = source.next().await; - trace!("packet: {:?}", packet); let bc = match packet { Some(Ok(bc)) => bc, Some(Err(e)) => { diff --git a/crates/core/src/bc_protocol/connection/bcsub.rs b/crates/core/src/bc_protocol/connection/bcsub.rs index 3340136..7c95cd1 100644 --- a/crates/core/src/bc_protocol/connection/bcsub.rs +++ b/crates/core/src/bc_protocol/connection/bcsub.rs @@ -49,17 +49,20 @@ impl<'a> Stream for BcPayloadStream<'a> { cx: &mut Context<'_>, ) -> Poll>>> { match Pin::new(&mut self.rx).poll_next(cx) { - Poll::Ready(Some(bc)) => match bc { - Bc { - body: - BcBody::ModernMsg(ModernMsg { - payload: Some(BcPayloads::Binary(data)), - .. - }), - .. - } => Poll::Ready(Some(Ok(data))), - _ => Poll::Pending, - }, + Poll::Ready(Some(bc)) => { + log::info!("Got Bc Packet"); + match bc { + Bc { + body: + BcBody::ModernMsg(ModernMsg { + payload: Some(BcPayloads::Binary(data)), + .. + }), + .. + } => Poll::Ready(Some(Ok(data))), + _ => Poll::Pending, + } + } Poll::Ready(None) => Poll::Ready(None), Poll::Pending => Poll::Pending, } diff --git a/crates/core/src/bc_protocol/connection/udpsource.rs b/crates/core/src/bc_protocol/connection/udpsource.rs index 9139f7a..ddcb5e9 100644 --- a/crates/core/src/bc_protocol/connection/udpsource.rs +++ b/crates/core/src/bc_protocol/connection/udpsource.rs @@ -159,7 +159,7 @@ impl BcUdpSource { recieved: Default::default(), state: State::Normal, send_buffer: Default::default(), - interval: interval(Duration::from_millis(500)), + interval: interval(Duration::from_millis(10)), // Offical Client does ack every 10ms } } } @@ -209,6 +209,9 @@ pub(crate) struct UdpPayloadSource { recieved: BTreeMap>, state: State, send_buffer: VecDeque, + /// Offical Client does ack every 10ms if we don't also do this the camera + /// seems to think we have a poor connection and will abort + /// This `intveral` controls how ofen we do this interval: Interval, } @@ -265,7 +268,7 @@ impl Stream for UdpPayloadSource { trace!("UDPSource.State: Normal"); // Data ready to go if let Some(payload) = this.recieved.remove(&this.packets_want) { - trace!("UDPSource.Data: Ready"); + trace!("UDPSource.Data: PreReady: {}", this.packets_want); this.packets_want += 1; return Poll::Ready(Some(Ok(payload))); } @@ -301,26 +304,14 @@ impl Stream for UdpPayloadSource { && addr == camera_addr && packet_id >= this.packets_want => { - trace!("UDPSource.RecievedPacker: Data"); if packet_id == this.packets_want { + trace!("UDPSource.RecievedPacker: NewData: {}", this.packets_want); this.packets_want += 1; return Poll::Ready(Some(Ok(payload))); } else { + trace!("UDPSource.RecievedPacker: OtherData"); this.recieved.insert(packet_id, payload); } - // Build and queue ack - if this.packets_want == 0 { - // When no packets have been recieved the - // ACK is different specifically unknown_b - // is set to -1 and packet_id is also set to - // -1 - // TODO Add this style of ACK - this.state = State::Normal; - } else { - let ack = BcUdp::Ack(this.build_send_ack()); - this.send_buffer.push_back(ack); - this.state = State::Flushing; - } } Poll::Ready(Some(Ok(( BcUdp::Ack(ack @ UdpAck { connection_id, .. }), @@ -328,11 +319,8 @@ impl Stream for UdpPayloadSource { )))) if connection_id == this.client_id && addr == camera_addr => { trace!("UDPSource.RecievedPacket: Ack"); this.handle_ack(ack); - - for (_, resend) in this.sent.iter() { - this.send_buffer.push_back(BcUdp::Data(resend.clone())); - } - this.state = State::Flushing; + // Rather then immediatly flush wait for the next call + // this.state = State::Flushing; } Poll::Ready(Some(Err(e))) => { trace!("UDPSource.RecievedPacker: Error"); diff --git a/crates/core/src/bcudp/model.rs b/crates/core/src/bcudp/model.rs index a1af2d6..c84aea2 100644 --- a/crates/core/src/bcudp/model.rs +++ b/crates/core/src/bcudp/model.rs @@ -80,7 +80,7 @@ pub struct UdpAck { pub const MAGIC_HEADER_UDP_DATA: u32 = 0x2a87cf10; /// Contains the data of a [`crate::bc::model::Bc`] packet -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone)] pub struct UdpData { /// The connection ID of the other party /// @@ -102,3 +102,13 @@ pub struct UdpData { /// The payload pub payload: Vec, } + +impl std::fmt::Debug for UdpData { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_map() + .entry(&"connection_id", &self.connection_id) + .entry(&"packet_id", &self.connection_id) + .entry(&"payload_len", &self.payload.len()) + .finish() + } +}