summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/ping.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/services/ping.rs b/src/services/ping.rs
index 6835fc0..ed848fc 100644
--- a/src/services/ping.rs
+++ b/src/services/ping.rs
@@ -1,16 +1,15 @@
1use std::borrow::Cow; 1use std::borrow::Cow;
2use std::collections::HashMap;
3use std::sync::Arc; 2use std::sync::Arc;
4 3
5use axum::extract::{ws::WebSocket}; 4use axum::extract::{ws::WebSocket};
6use axum::extract::ws::{CloseFrame, Message}; 5use axum::extract::ws::{CloseFrame, Message};
6use dashmap::DashMap;
7use tokio::sync::broadcast::{Sender}; 7use tokio::sync::broadcast::{Sender};
8use tokio::sync::Mutex;
9use tracing::{debug, trace, warn}; 8use tracing::{debug, trace, warn};
10 9
11use crate::error::WebolError; 10use crate::error::WebolError;
12 11
13pub type PingMap = Arc<Mutex<HashMap<String, (String, bool)>>>; 12pub type PingMap = Arc<DashMap<String, (String, bool)>>;
14 13
15pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping_map: PingMap) -> Result<(), WebolError> { 14pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping_map: PingMap) -> Result<(), WebolError> {
16 let payload = [0; 8]; 15 let payload = [0; 8];
@@ -41,11 +40,11 @@ pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping
41 40
42async fn handle_broadcast_send(tx: &Sender<BroadcastCommands>, ip: String, ping_map: PingMap, uuid: String) { 41async fn handle_broadcast_send(tx: &Sender<BroadcastCommands>, ip: String, ping_map: PingMap, uuid: String) {
43 debug!("sending pingsuccess message"); 42 debug!("sending pingsuccess message");
44 ping_map.lock().await.insert(uuid.clone(), (ip.clone(), true)); 43 ping_map.insert(uuid.clone(), (ip.clone(), true));
45 let _ = tx.send(BroadcastCommands::PingSuccess(ip)); 44 let _ = tx.send(BroadcastCommands::PingSuccess(ip));
46 tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; 45 tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
47 trace!("remove {} from ping_map", uuid); 46 trace!("remove {} from ping_map", uuid);
48 ping_map.lock().await.remove(&uuid); 47 ping_map.remove(&uuid);
49} 48}
50 49
51#[derive(Clone, Debug)] 50#[derive(Clone, Debug)]
@@ -63,7 +62,7 @@ pub async fn status_websocket(mut socket: WebSocket, tx: Sender<BroadcastCommand
63 trace!("Search for uuid: {:?}", uuid); 62 trace!("Search for uuid: {:?}", uuid);
64 63
65 // TODO: Handle Error 64 // TODO: Handle Error
66 let device = ping_map.lock().await.get(&uuid).unwrap().to_owned(); 65 let device = ping_map.get(&uuid).unwrap().to_owned();
67 66
68 trace!("got device: {:?}", device); 67 trace!("got device: {:?}", device);
69 68