From 30d8b177dd23edf708846221ae440380dfa769a3 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Mon, 25 Apr 2022 14:02:15 +0200 Subject: [PATCH] dnetview/ util: move id generation to dnetview/src/util.rs --- bin/dnetview/src/lib.rs | 1 + bin/dnetview/src/main.rs | 51 ++-------------------------------------- bin/dnetview/src/ui.rs | 5 +--- 3 files changed, 4 insertions(+), 53 deletions(-) diff --git a/bin/dnetview/src/lib.rs b/bin/dnetview/src/lib.rs index aa419e79f..89bb61502 100644 --- a/bin/dnetview/src/lib.rs +++ b/bin/dnetview/src/lib.rs @@ -2,6 +2,7 @@ pub mod config; pub mod model; pub mod options; pub mod ui; +pub mod util; pub mod view; pub use config::{DnvConfig, CONFIG_FILE_CONTENTS}; diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index cb0bd9120..ec877c31a 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -4,7 +4,6 @@ use std::{fs::File, io, io::Read, path::PathBuf}; use easy_parallel::Parallel; use fxhash::{FxHashMap, FxHashSet}; use log::{debug, info}; -use rand::{thread_rng, Rng}; use serde_json::{json, Value}; use simplelog::*; use smol::Executor; @@ -22,7 +21,7 @@ use darkfi::{ util::{ async_util, cli::{log_config, spawn_config, Config}, - join_config_path, serial, + join_config_path, }, }; @@ -31,6 +30,7 @@ use dnetview::{ model::{ConnectInfo, Model, NodeInfo, SelectableObject, Session, SessionInfo}, options::ProgramOptions, ui, + util::{generate_id, make_connect_id, make_node_id, make_session_id}, view::{IdListView, InfoListView, View}, }; @@ -354,53 +354,6 @@ async fn parse_outbound(outbound: &Value, node_id: String) -> Result Result { - Ok(serial::serialize_hex(node_name)) -} - -pub fn make_session_id(node_id: String, session: &Session) -> Result { - let mut num = 0_u64; - - match session { - Session::Inbound => { - for i in ['i', 'n'] { - num += i as u64; - } - } - Session::Outbound => { - for i in ['o', 'u', 't'] { - num += i as u64; - } - } - Session::Manual => { - for i in ['m', 'a', 'n'] { - num += i as u64; - } - } - } - - for i in node_id.chars() { - num += i as u64 - } - - Ok(serial::serialize_hex(&num)) -} - -pub fn make_connect_id(id: u64) -> Result { - Ok(serial::serialize_hex(&id)) -} - -// we use a random id for empty connections -fn generate_id() -> Result { - let mut rng = thread_rng(); - let id: u32 = rng.gen(); - Ok(serial::serialize_hex(&id)) -} - -//fn is_empty_outbound(slots: Vec) -> bool { -// return slots.iter().all(|slot| slot.is_empty); -//} - async fn render(terminal: &mut Terminal, model: Arc) -> Result<()> { let mut asi = async_stdin(); diff --git a/bin/dnetview/src/ui.rs b/bin/dnetview/src/ui.rs index 74f5f8d3f..547674266 100644 --- a/bin/dnetview/src/ui.rs +++ b/bin/dnetview/src/ui.rs @@ -18,16 +18,13 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { let mut nodes = Vec::new(); let style = Style::default(); - // lines.push(sublist) - // either have one hashmap w value as enum or have type info in hashset for id in &view.id_list.ids { let id_span = Span::raw(id.to_string()); let mut lines = vec![Spans::from(id_span)]; - // create a new vector of addresses - // render as a sub node match &view.info_list.infos.get(id) { Some(node) => { + //debug!("NODE: {:?}", node); //if !node.outbound.iter().all(|node| node.is_empty) { // lines.push(Spans::from(Span::styled(" Outgoing", Style::default()))); //}