[FIX] Migrated to Tensamin Transport Protocol

This commit is contained in:
Alex Emmet 2026-02-27 23:44:47 +01:00
commit c9d21fd3c6
24 changed files with 1451 additions and 2252 deletions

View file

@ -1,30 +1,29 @@
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
use crate::omega::omega_connection::OmegaConnection;
use json::number::Number;
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
use std::time::Duration;
use tokio::time::Instant;
use uuid::Uuid;
use crate::omega::omega_connection::OmegaConnection;
const PING_TIMEOUT: Duration = Duration::from_secs(30);
impl OmegaConnection {
pub async fn send_ping(&self) {
let uuid = Uuid::new_v4();
let id = rand_u32();
let send_time = Instant::now();
let mut message_send_times = self.message_send_times.lock().await;
message_send_times.retain(|_uuid, time| time.elapsed() < PING_TIMEOUT);
message_send_times.insert(uuid, send_time);
message_send_times.insert(id as i64, send_time);
self.send_ping_message(uuid).await;
self.send_ping_message(id).await;
}
pub async fn send_ping_message(&self, uuid: Uuid) {
pub async fn send_ping_message(&self, id: u32) {
let ping_message = CommunicationValue::new(CommunicationType::ping)
.with_id(uuid)
.add_data_num(
.with_id(id)
.add_data(
DataTypes::last_ping,
Number::from(*self.last_ping.lock().await),
DataValue::Number(self.last_ping.lock().await.unwrap()),
);
self.send_message(&ping_message).await;
@ -34,7 +33,7 @@ impl OmegaConnection {
pub async fn handle_pong(&self, cv: &CommunicationValue, _log: bool) {
let id = cv.get_id();
let mut message_send_times = self.message_send_times.lock().await;
if let Some(send_time) = message_send_times.remove(&id) {
if let Some(send_time) = message_send_times.remove(&(id as i64)) {
let ping = Instant::now().duration_since(send_time).as_millis() as i64;
*self.last_ping.lock().await = ping;
}