feat: refactor prudp code and start working on refactoring rmc
This commit is contained in:
parent
7d24a71f09
commit
3ea7c7e671
37 changed files with 2029 additions and 456 deletions
37
src/web/mod.rs
Normal file
37
src/web/mod.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use std::net::SocketAddrV4;
|
||||
use once_cell::sync::Lazy;
|
||||
use rocket::{get, routes, Rocket};
|
||||
use rocket::serde::json::Json;
|
||||
use tokio::task::JoinHandle;
|
||||
use serde::Serialize;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[get("/")]
|
||||
async fn server_data() -> Json<WebData> {
|
||||
Json(WEB_DATA.lock().await.clone())
|
||||
}
|
||||
|
||||
pub async fn start_web() -> JoinHandle<()>{
|
||||
tokio::spawn(async{
|
||||
rocket::build()
|
||||
.mount("/",routes![server_data])
|
||||
.launch().await
|
||||
.expect("unable to start webserver");
|
||||
})
|
||||
}
|
||||
#[derive(Serialize, Clone)]
|
||||
pub enum DirectionalData{
|
||||
Incoming(String),
|
||||
Outgoing(String)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Default, Clone)]
|
||||
pub struct WebData{
|
||||
pub data: Vec<(SocketAddrV4, DirectionalData)>
|
||||
}
|
||||
|
||||
pub static WEB_DATA: Lazy<Mutex<WebData>> = Lazy::new(|| Mutex::new(
|
||||
WebData{
|
||||
data: Vec::new(),
|
||||
}
|
||||
));
|
||||
Loading…
Add table
Add a link
Reference in a new issue