diff options
Diffstat (limited to 'src/services/ping.rs')
-rw-r--r-- | src/services/ping.rs | 11 |
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 @@ | |||
1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
2 | use std::collections::HashMap; | ||
3 | use std::sync::Arc; | 2 | use std::sync::Arc; |
4 | 3 | ||
5 | use axum::extract::{ws::WebSocket}; | 4 | use axum::extract::{ws::WebSocket}; |
6 | use axum::extract::ws::{CloseFrame, Message}; | 5 | use axum::extract::ws::{CloseFrame, Message}; |
6 | use dashmap::DashMap; | ||
7 | use tokio::sync::broadcast::{Sender}; | 7 | use tokio::sync::broadcast::{Sender}; |
8 | use tokio::sync::Mutex; | ||
9 | use tracing::{debug, trace, warn}; | 8 | use tracing::{debug, trace, warn}; |
10 | 9 | ||
11 | use crate::error::WebolError; | 10 | use crate::error::WebolError; |
12 | 11 | ||
13 | pub type PingMap = Arc<Mutex<HashMap<String, (String, bool)>>>; | 12 | pub type PingMap = Arc<DashMap<String, (String, bool)>>; |
14 | 13 | ||
15 | pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping_map: PingMap) -> Result<(), WebolError> { | 14 | pub 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 | ||
42 | async fn handle_broadcast_send(tx: &Sender<BroadcastCommands>, ip: String, ping_map: PingMap, uuid: String) { | 41 | async 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 | ||