diff options
author | FxQnLr <[email protected]> | 2023-11-02 20:58:29 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-11-02 20:58:29 +0100 |
commit | 9e3afcfee276af982a1e1d11f24c9711defc124e (patch) | |
tree | 38c4b47ae97742560963e6b2b4cba3eb84bbaf8a /src/services/ping.rs | |
parent | 94104b621e2eec44dd90eb22fae2db2ce4938b87 (diff) | |
download | webol-9e3afcfee276af982a1e1d11f24c9711defc124e.tar webol-9e3afcfee276af982a1e1d11f24c9711defc124e.tar.gz webol-9e3afcfee276af982a1e1d11f24c9711defc124e.zip |
Revert "update dependencies"
This reverts commit 94104b621e2eec44dd90eb22fae2db2ce4938b87.
Diffstat (limited to 'src/services/ping.rs')
-rw-r--r-- | src/services/ping.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/services/ping.rs b/src/services/ping.rs index d900acb..a26dacc 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs | |||
@@ -41,7 +41,7 @@ pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping | |||
41 | } | 41 | } |
42 | } else { | 42 | } else { |
43 | let (_, duration) = ping.map_err(|err| error!("{}", err.to_string())).expect("fatal error"); | 43 | let (_, duration) = ping.map_err(|err| error!("{}", err.to_string())).expect("fatal error"); |
44 | debug!("ping took {:?}", duration); | 44 | debug!("Ping took {:?}", duration); |
45 | cont = false; | 45 | cont = false; |
46 | handle_broadcast_send(&tx, ip.clone(), ping_map, uuid.clone()).await; | 46 | handle_broadcast_send(&tx, ip.clone(), ping_map, uuid.clone()).await; |
47 | }; | 47 | }; |
@@ -50,12 +50,10 @@ pub async fn spawn(tx: Sender<BroadcastCommands>, ip: String, uuid: String, ping | |||
50 | 50 | ||
51 | async fn handle_broadcast_send(tx: &Sender<BroadcastCommands>, ip: String, ping_map: &PingMap, uuid: String) { | 51 | async fn handle_broadcast_send(tx: &Sender<BroadcastCommands>, ip: String, ping_map: &PingMap, uuid: String) { |
52 | debug!("send pingsuccess message"); | 52 | debug!("send pingsuccess message"); |
53 | let _ = tx.send(BroadcastCommands::PingSuccess(uuid.clone())); | ||
54 | trace!("sent message"); | ||
55 | ping_map.insert(uuid.clone(), PingValue { ip: ip.clone(), online: true }); | 53 | ping_map.insert(uuid.clone(), PingValue { ip: ip.clone(), online: true }); |
56 | trace!("updated ping_map"); | 54 | let _ = tx.send(BroadcastCommands::PingSuccess(uuid.clone())); |
57 | tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; | 55 | tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; |
58 | debug!("remove {} from ping_map after success", uuid); | 56 | trace!("remove {} from ping_map after success", uuid); |
59 | ping_map.remove(&uuid); | 57 | ping_map.remove(&uuid); |
60 | } | 58 | } |
61 | 59 | ||
@@ -72,12 +70,12 @@ pub async fn status_websocket(mut socket: WebSocket, state: Arc<AppState>) { | |||
72 | 70 | ||
73 | trace!("Search for uuid: {:?}", uuid); | 71 | trace!("Search for uuid: {:?}", uuid); |
74 | 72 | ||
75 | let device_exists = state.ping_map.contains_key(&uuid); | 73 | match state.ping_map.get(&uuid) { |
76 | match device_exists { | 74 | Some(device) => { |
77 | true => { | 75 | debug!("got device: {} (online: {})", device.ip, device.online); |
78 | let _ = socket.send(process_device(state.clone(), uuid).await).await; | 76 | let _ = socket.send(process_device(state.clone(), uuid, device.to_owned()).await).await; |
79 | }, | 77 | }, |
80 | false => { | 78 | None => { |
81 | debug!("didn't find any device"); | 79 | debug!("didn't find any device"); |
82 | let _ = socket.send(Message::Text(format!("notfound_{}", uuid))).await; | 80 | let _ = socket.send(Message::Text(format!("notfound_{}", uuid))).await; |
83 | }, | 81 | }, |
@@ -86,10 +84,7 @@ pub async fn status_websocket(mut socket: WebSocket, state: Arc<AppState>) { | |||
86 | let _ = socket.close().await; | 84 | let _ = socket.close().await; |
87 | } | 85 | } |
88 | 86 | ||
89 | async fn process_device(state: Arc<AppState>, uuid: String) -> Message { | 87 | async fn process_device(state: Arc<AppState>, uuid: String, device: PingValue) -> Message { |
90 | let pm = state.ping_map.clone().into_read_only(); | ||
91 | let device = pm.get(&uuid).expect("fatal error"); | ||
92 | debug!("got device: {} (online: {})", device.ip, device.online); | ||
93 | match device.online { | 88 | match device.online { |
94 | true => { | 89 | true => { |
95 | debug!("already started"); | 90 | debug!("already started"); |