Relay connection works
This commit is contained in:
1 parent
c2212b9038
commit
3949dca1af
6 files changed
+38
-40
No files matched your search
@@ -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<Option<Self::Item>> {
|
||||
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),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)) => {
|
||||
|
||||
@@ -49,17 +49,20 @@ impl<'a> Stream for BcPayloadStream<'a> {
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Option<IoResult<Vec<u8>>>> {
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -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<u32, Vec<u8>>,
|
||||
state: State,
|
||||
send_buffer: VecDeque<BcUdp>,
|
||||
/// 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");
|
||||
|
||||
@@ -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<u8>,
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user