dnetview/ util: move id generation to dnetview/src/util.rs

This commit is contained in:
lunar-mining
2022-04-25 14:02:15 +02:00
parent a6c3742d59
commit 30d8b177dd
3 changed files with 4 additions and 53 deletions

View File

@@ -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};

View File

@@ -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<SessionInfo
}
}
fn make_node_id(node_name: &String) -> Result<String> {
Ok(serial::serialize_hex(node_name))
}
pub fn make_session_id(node_id: String, session: &Session) -> Result<String> {
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<String> {
Ok(serial::serialize_hex(&id))
}
// we use a random id for empty connections
fn generate_id() -> Result<String> {
let mut rng = thread_rng();
let id: u32 = rng.gen();
Ok(serial::serialize_hex(&id))
}
//fn is_empty_outbound(slots: Vec<Slot>) -> bool {
// return slots.iter().all(|slot| slot.is_empty);
//}
async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> Result<()> {
let mut asi = async_stdin();

View File

@@ -18,16 +18,13 @@ pub fn ui<B: Backend>(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())));
//}