diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index 14c48f4c4..59b7debb5 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -4,6 +4,7 @@ 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; @@ -201,8 +202,7 @@ async fn parse_inbound(inbound: &Value, node_id: String) -> Result true => { // channel is empty. initialize with empty values // TODO: fix this - let id: u64 = 0; - let connect_id = make_connect_id(id)?; + let connect_id = generate_id()?; let addr = "Null".to_string(); let msg = "Null".to_string(); let status = "Null".to_string(); @@ -282,8 +282,7 @@ async fn parse_outbound(outbound: &Value, node_id: String) -> Result { // channel is empty. initialize with empty values // TODO: fix this - let id: u64 = 0; - let connect_id = make_connect_id(id)?; + let connect_id = generate_id()?; let is_empty = true; let addr = "Null".to_string(); let state = &slot["state"]; @@ -374,6 +373,14 @@ pub fn make_session_id(node_id: String, session: &Session) -> Result { 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); //}