Merge branch 'main' of github.com:Tensamin/Iota
This commit is contained in:
commit
d289346c63
2 changed files with 11 additions and 5 deletions
|
|
@ -77,7 +77,6 @@ async fn main() {
|
||||||
JsonValue::Number(Number::from(
|
JsonValue::Number(Number::from(
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
|
||||||
.unwrap_or(Duration::from_millis(0))
|
.unwrap_or(Duration::from_millis(0))
|
||||||
.as_millis() as i64,
|
.as_millis() as i64,
|
||||||
)),
|
)),
|
||||||
|
|
@ -127,8 +126,6 @@ async fn main() {
|
||||||
let iface: NetworkInterface = iface;
|
let iface: NetworkInterface = iface;
|
||||||
if iface.ips.len() > 0 {
|
if iface.ips.len() > 0 {
|
||||||
let ipsv = format!("{}", iface.ips[0]);
|
let ipsv = format!("{}", iface.ips[0]);
|
||||||
let ips: &str = ipsv.split('/').next().unwrap();
|
|
||||||
|
|
||||||
let ips: &str = ipsv.split('/').next().unwrap_or("");
|
let ips: &str = ipsv.split('/').next().unwrap_or("");
|
||||||
if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") {
|
if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") {
|
||||||
ip = ips.to_string();
|
ip = ips.to_string();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ use hyper::upgrade::Upgraded;
|
||||||
use hyper_util::rt::TokioIo;
|
use hyper_util::rt::TokioIo;
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
use json::number::Number;
|
use json::number::Number;
|
||||||
use ratatui::crossterm::event::poll;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, LazyLock};
|
use std::sync::{Arc, LazyLock};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
@ -38,6 +37,8 @@ pub enum ConnectionVariant {
|
||||||
pub struct OmikronConnection {
|
pub struct OmikronConnection {
|
||||||
pub variant: Arc<RwLock<ConnectionVariant>>,
|
pub variant: Arc<RwLock<ConnectionVariant>>,
|
||||||
pub user_id: Arc<RwLock<i64>>,
|
pub user_id: Arc<RwLock<i64>>,
|
||||||
|
pub(crate) writer:
|
||||||
|
Arc<Mutex<Option<Box<dyn Sink<Message, Error = tungstenite::Error> + Send + Unpin>>>>,
|
||||||
waiting: Arc<Mutex<HashMap<Uuid, Box<dyn Fn(CommunicationValue) + Send + Sync>>>>,
|
waiting: Arc<Mutex<HashMap<Uuid, Box<dyn Fn(CommunicationValue) + Send + Sync>>>>,
|
||||||
pingpong: Arc<Mutex<Option<tokio::task::JoinHandle<()>>>>,
|
pingpong: Arc<Mutex<Option<tokio::task::JoinHandle<()>>>>,
|
||||||
pub last_ping: Arc<Mutex<i64>>,
|
pub last_ping: Arc<Mutex<i64>>,
|
||||||
|
|
@ -69,6 +70,8 @@ impl OmikronConnection {
|
||||||
as Box<dyn Sink<Message, Error = tungstenite::Error> + Send + Unpin>))),
|
as Box<dyn Sink<Message, Error = tungstenite::Error> + Send + Unpin>))),
|
||||||
waiting: Arc::new(Mutex::new(HashMap::new())),
|
waiting: Arc::new(Mutex::new(HashMap::new())),
|
||||||
pingpong: Arc::new(Mutex::new(None)),
|
pingpong: Arc::new(Mutex::new(None)),
|
||||||
|
last_ping: Arc::new(Mutex::new(-1)),
|
||||||
|
message_send_times: Arc::new(Mutex::new(HashMap::new())),
|
||||||
is_connected: Arc::new(Mutex::new(true)),
|
is_connected: Arc::new(Mutex::new(true)),
|
||||||
});
|
});
|
||||||
let boxed_reader: Box<
|
let boxed_reader: Box<
|
||||||
|
|
@ -155,6 +158,8 @@ impl OmikronConnection {
|
||||||
|
|
||||||
{
|
{
|
||||||
ACTIVE_TASKS.lock().unwrap().push("Listener".to_string());
|
ACTIVE_TASKS.lock().unwrap().push("Listener".to_string());
|
||||||
|
}
|
||||||
|
tokio::spawn(async move {
|
||||||
while let Some(msg) = read_half.next().await {
|
while let Some(msg) = read_half.next().await {
|
||||||
if *SHUTDOWN.read().await {
|
if *SHUTDOWN.read().await {
|
||||||
break;
|
break;
|
||||||
|
|
@ -335,6 +340,8 @@ impl OmikronConnection {
|
||||||
let other_id = cv
|
let other_id = cv
|
||||||
.get_data(DataTypes::receiver_id)
|
.get_data(DataTypes::receiver_id)
|
||||||
.unwrap_or(&JsonValue::Null)
|
.unwrap_or(&JsonValue::Null)
|
||||||
|
.as_i64()
|
||||||
|
.unwrap_or(0);
|
||||||
let now_ms = SystemTime::now()
|
let now_ms = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -381,7 +388,9 @@ impl OmikronConnection {
|
||||||
cv.get_data(DataTypes::content).unwrap().to_string(),
|
cv.get_data(DataTypes::content).unwrap().to_string(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Self::send_message_static(
|
||||||
|
&writer.clone(),
|
||||||
|
is_connected,
|
||||||
forward.to_json().to_string(),
|
forward.to_json().to_string(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue