fixed some handshake socket issues

This commit is contained in:
Nickiel12 2024-04-16 17:26:03 -07:00
parent 1bebdd1fd8
commit ef96409082
3 changed files with 25 additions and 25 deletions

View file

@ -81,25 +81,23 @@ impl<'a> CoordState<'a> {
self.sck_outbound.is_some()
}
pub async fn socket_start(&mut self, conn: String) {
if !(self.sck_alive_recvr.load(Ordering::SeqCst)) {
info!("Starting socket");
async fn socket_start(&mut self, conn: String) {
info!("Starting socket");
match connect_async(conn).await {
Ok((val, _)) => {
info!("Socket connection to camera made successfully");
match connect_async(conn).await {
Ok((val, _)) => {
info!("Socket connection to camera made successfully");
let (outbound, inbound) = val.split();
self.rt.spawn(socket_listen(
self.to_mec.clone(),
self.sck_alive_recvr.clone(),
inbound,
));
self.sck_outbound = Some(outbound);
}
Err(_) => {
error!("Couldn't connect to URL!");
}
let (outbound, inbound) = val.split();
self.rt.spawn(socket_listen(
self.to_mec.clone(),
self.sck_alive_recvr.clone(),
inbound,
));
self.sck_outbound = Some(outbound);
}
Err(_) => {
error!("Couldn't connect to URL!");
}
}
}
@ -122,7 +120,7 @@ impl<'a> CoordState<'a> {
));
}
if !self.sck_alive_server.load(Ordering::SeqCst) || self.sck_outbound.is_none() {
if !self.sck_alive_server.load(Ordering::SeqCst) {
info!("Restarting socket server");
self.sck_alive_server.store(true, Ordering::SeqCst);
self.rt.spawn(remote_sources::start_socketserver(

View file

@ -101,15 +101,12 @@ fn process_incoming_string(
ts.tracking_id = boxes[0].id;
}
info!("boxes len: {}", boxes.len());
if let Some(target_box) = boxes.into_iter().find(|e| e.id == ts.tracking_id) {
let x_adjust = calc_x_adjust(target_box.x1, target_box.x2);
let y_adjust = calc_y_adjust(target_box.y1);
ts.last_detect = Instant::now();
Ok((x_adjust, y_adjust))
} else {
info!("Tracking ID: {}", ts.tracking_id);
Err("Couldn't find target in results".to_string())
}
} else {

View file

@ -10,7 +10,7 @@ use std::{
use async_channel::Sender;
use futures_core::FusedStream;
use futures_util::{SinkExt, StreamExt};
use log::{error, info};
use log::{debug, error, info, warn};
use tokio::{
net::{TcpListener, TcpStream},
runtime::Handle,
@ -50,7 +50,7 @@ pub async fn start_socketserver(
let peer = stream
.peer_addr()
.expect("connected streams should have a peer address");
info!("Peer address: {}", peer);
debug!("Peer address: {}", peer);
rt.spawn(accept_connection(
peer,
@ -109,14 +109,19 @@ async fn handle_connection(
};
if msg.is_text() && msg.to_string().starts_with("Type: ") {
match msg.to_string().split(' ').collect::<Vec<&str>>()[0] {
match msg.to_string().split(' ').collect::<Vec<&str>>()[1] {
"Automated" => {
debug!("Connection type is: Automated");
connection_type = Some(ConnectionType::Automated);
}
"Remote" => {
debug!("Connection type is: Remote");
connection_type = Some(ConnectionType::Remote);
}
_ => {}
_ => {
warn!("Unknown connection type, dropping connection");
ws_stream.close(None).await?;
}
}
}