|
@@ -20,7 +20,11 @@ use tui::{
|
|
|
Terminal,
|
|
Terminal,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-use map::{ui, App};
|
|
|
|
|
|
|
+use map::{
|
|
|
|
|
+ list::NodeIdList,
|
|
|
|
|
+ node_info::{NodeInfo, NodeInfoView},
|
|
|
|
|
+ ui, App,
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
struct Map {
|
|
struct Map {
|
|
|
url: String,
|
|
url: String,
|
|
@@ -91,7 +95,7 @@ async fn main() -> Result<()> {
|
|
|
// Run the main future on the current thread.
|
|
// Run the main future on the current thread.
|
|
|
.finish(|| {
|
|
.finish(|| {
|
|
|
smol::future::block_on(async move {
|
|
smol::future::block_on(async move {
|
|
|
- start(ex2.clone()).await?;
|
|
|
|
|
|
|
+ start(ex2.clone(), app.clone()).await?;
|
|
|
run_app(&mut terminal, app).await?;
|
|
run_app(&mut terminal, app).await?;
|
|
|
drop(signal);
|
|
drop(signal);
|
|
|
Ok::<(), darkfi::Error>(())
|
|
Ok::<(), darkfi::Error>(())
|
|
@@ -101,24 +105,74 @@ async fn main() -> Result<()> {
|
|
|
result
|
|
result
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn start(ex: Arc<Executor<'_>>) -> Result<()> {
|
|
|
|
|
|
|
+async fn start(ex: Arc<Executor<'_>>, mut app: App) -> Result<()> {
|
|
|
let client = Map::new("tcp://127.0.0.1:8000".to_string());
|
|
let client = Map::new("tcp://127.0.0.1:8000".to_string());
|
|
|
|
|
|
|
|
ex.spawn(async {
|
|
ex.spawn(async {
|
|
|
- poll(client).await;
|
|
|
|
|
|
|
+ poll(client, app).await;
|
|
|
})
|
|
})
|
|
|
.detach();
|
|
.detach();
|
|
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn poll(client: Map) -> Result<()> {
|
|
|
|
|
|
|
+async fn poll(client: Map, mut app: App) -> Result<()> {
|
|
|
loop {
|
|
loop {
|
|
|
- client.get_info().await?;
|
|
|
|
|
|
|
+ let reply = client.get_info().await?;
|
|
|
|
|
+ update(app.clone(), reply).await?;
|
|
|
async_util::sleep(1).await;
|
|
async_util::sleep(1).await;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async fn update(mut app: App, reply: Value) -> Result<()> {
|
|
|
|
|
+ if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
|
|
|
|
|
+ //let args = params.as_array();
|
|
|
|
|
+ let nodes = reply.as_object().unwrap().get("nodes").unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ let node1 = &nodes[0];
|
|
|
|
|
+ let node2 = &nodes[1];
|
|
|
|
|
+ let node3 = &nodes[2];
|
|
|
|
|
+
|
|
|
|
|
+ let infos = vec![
|
|
|
|
|
+ NodeInfo {
|
|
|
|
|
+ id: node1["id"].to_string(),
|
|
|
|
|
+ connections: node1["connections"].as_u64().unwrap() as usize,
|
|
|
|
|
+ is_active: node2["is_active"].as_bool().unwrap(),
|
|
|
|
|
+ last_message: "message".to_string(),
|
|
|
|
|
+ },
|
|
|
|
|
+ //NodeInfo {
|
|
|
|
|
+ // id: node2["id"].to_string(),
|
|
|
|
|
+ // connections: node2["connections"].as_u64().unwrap() as usize,
|
|
|
|
|
+ // is_active: node2["is_active"].as_bool().unwrap(),
|
|
|
|
|
+ // last_message: node2["message"].to_string(),
|
|
|
|
|
+ //},
|
|
|
|
|
+ //NodeInfo {
|
|
|
|
|
+ // id: node3["id"].to_string(),
|
|
|
|
|
+ // connections: node3["connections"].as_u64().unwrap() as usize,
|
|
|
|
|
+ // is_active: node3["is_active"].as_bool().unwrap(),
|
|
|
|
|
+ // last_message: node3["message"].to_string(),
|
|
|
|
|
+ //},
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ //app.node_info(
|
|
|
|
|
+ //let node_info = NodeInfoView::new(infos.clone());
|
|
|
|
|
+
|
|
|
|
|
+ //let ids = vec![node1["id"].to_string(), node2["id"].to_string(), node3["id"].to_string()];
|
|
|
|
|
+
|
|
|
|
|
+ // mutex
|
|
|
|
|
+ app.update(infos).await;
|
|
|
|
|
+ //let node_list = NodeIdList::new(ids);
|
|
|
|
|
+ //println!("{}", test);
|
|
|
|
|
+ // do something
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ // TODO: error handling
|
|
|
|
|
+ println!("Reply is an error");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Ok(())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
|
async fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
|
|
let mut asi = async_stdin();
|
|
let mut asi = async_stdin();
|
|
|
|
|
|