aboutsummaryrefslogtreecommitdiff
path: root/src/routes/start.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-10-29 21:09:46 +0100
committerFxQnLr <[email protected]>2023-10-29 21:09:46 +0100
commitdd303dc41e4d500e48760f79351720cc2c1c9ffe (patch)
treeb730a1da1e0e58e12494bbab88076d403f4ccd97 /src/routes/start.rs
parent84c32953ae5f52be44af4b48381747f55cb04f4a (diff)
downloadwebol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.tar
webol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.tar.gz
webol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.zip
add ip to database and use for ping, remove arc from pingmap
Diffstat (limited to 'src/routes/start.rs')
-rw-r--r--src/routes/start.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/routes/start.rs b/src/routes/start.rs
index 5b73281..3bccb0f 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -22,7 +22,7 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
22 let device = sqlx::query_as!( 22 let device = sqlx::query_as!(
23 Device, 23 Device,
24 r#" 24 r#"
25 SELECT id, mac, broadcast_addr 25 SELECT id, mac, broadcast_addr, ip
26 FROM devices 26 FROM devices
27 WHERE id = $1; 27 WHERE id = $1;
28 "#, 28 "#,
@@ -44,16 +44,15 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
44 let uuid = if payload.ping.is_some_and(|ping| ping) { 44 let uuid = if payload.ping.is_some_and(|ping| ping) {
45 let uuid_gen = Uuid::new_v4().to_string(); 45 let uuid_gen = Uuid::new_v4().to_string();
46 let uuid_genc = uuid_gen.clone(); 46 let uuid_genc = uuid_gen.clone();
47 let uuid_gencc = uuid_gen.clone(); 47 tokio::spawn(async move {
48 tokio::spawn(async move{
49 debug!("Init ping service"); 48 debug!("Init ping service");
50 state.ping_map.insert(uuid_gen, ("192.168.178.94".to_string(), false)); 49 state.ping_map.insert(uuid_gen.clone(), (device.ip.clone(), false));
51 50
52 warn!("{:?}", state.ping_map); 51 warn!("{:?}", state.ping_map);
53 52
54 crate::services::ping::spawn(state.ping_send.clone(), "192.168.178.94".to_string(), uuid_genc.clone(), state.ping_map.clone()).await 53 crate::services::ping::spawn(state.ping_send.clone(), device.ip, uuid_gen.clone(), &state.ping_map).await
55 }); 54 });
56 Some(uuid_gencc) 55 Some(uuid_genc)
57 } else { None }; 56 } else { None };
58 Ok(Json(json!(StartResponse { id: device.id, boot: true, uuid }))) 57 Ok(Json(json!(StartResponse { id: device.id, boot: true, uuid })))
59 } else { 58 } else {