Initial MTP Migration [Broken]
This commit is contained in:
parent
a4ec766351
commit
b2a22456ff
30 changed files with 1886 additions and 1574 deletions
|
|
@ -1,26 +1,26 @@
|
|||
use crate::omikron_connection::OmikronConnection;
|
||||
use dashmap::DashMap;
|
||||
use iota_state::APP_STATE;
|
||||
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Instant;
|
||||
use tokio::time::Duration;
|
||||
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
||||
|
||||
static PING_TIMES: LazyLock<DashMap<u32, Instant>> = LazyLock::new(|| DashMap::new());
|
||||
|
||||
impl OmikronConnection {
|
||||
pub async fn send_ping(&self) {
|
||||
let id = rand_u32();
|
||||
let id = rand::random();
|
||||
|
||||
PING_TIMES.insert(id, Instant::now());
|
||||
|
||||
PING_TIMES.retain(|_, v| v.elapsed() < Duration::from_secs(30));
|
||||
|
||||
let ping_message = CommunicationValue::new(CommunicationType::ping)
|
||||
let ping_message = CommunicationValue::new(CommunicationType::Ping)
|
||||
.with_id(id)
|
||||
.add_data(
|
||||
DataTypes::last_ping,
|
||||
DataValue::Array(vec![DataValue::Number(*self.last_ping.lock().await)]),
|
||||
.add_typed_default(
|
||||
DataType::LastPing,
|
||||
DataValue::Array(vec![DataValue::SignedNumber(*self.last_ping.lock().await as i128)]),
|
||||
);
|
||||
|
||||
self.send_message(&ping_message).await;
|
||||
|
|
|
|||
Loading…
Reference in a new issue