mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
dnetview: make_empty_id to avoid endlessly creating ids
This commit is contained in:
@@ -30,7 +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},
|
||||
util::{generate_id, make_connect_id, make_empty_id, make_node_id, make_session_id},
|
||||
view::{ConnectInfoView, IdListView, InfoListView, NodeInfoView, SessionInfoView, View},
|
||||
};
|
||||
|
||||
@@ -220,14 +220,16 @@ async fn parse_inbound(inbound: &Value, node_id: String) -> Result<SessionInfo>
|
||||
let session_id = make_session_id(node_id.clone(), &session_type)?;
|
||||
let mut connects: Vec<ConnectInfo> = Vec::new();
|
||||
let connections = &inbound["connected"];
|
||||
let mut connect_count = 0;
|
||||
|
||||
match connections.as_object() {
|
||||
Some(connect) => {
|
||||
match connect.is_empty() {
|
||||
true => {
|
||||
connect_count += 1;
|
||||
// channel is empty. initialize with empty values
|
||||
// TODO: fix this
|
||||
let connect_id = generate_id()?;
|
||||
let connect_id = make_empty_id(node_id.clone(), &session_type, connect_count)?;
|
||||
let addr = "Null".to_string();
|
||||
let msg = "Null".to_string();
|
||||
let status = "Null".to_string();
|
||||
@@ -305,15 +307,17 @@ async fn parse_outbound(outbound: &Value, node_id: String) -> Result<SessionInfo
|
||||
let mut connects: Vec<ConnectInfo> = Vec::new();
|
||||
let slots = &outbound["slots"];
|
||||
let session_id = make_session_id(node_id.clone(), &session_type)?;
|
||||
let mut slot_count = 0;
|
||||
|
||||
match slots.as_array() {
|
||||
Some(slots) => {
|
||||
for slot in slots {
|
||||
slot_count += 1;
|
||||
match slot["channel"].is_null() {
|
||||
true => {
|
||||
// channel is empty. initialize with empty values
|
||||
// TODO: fix this
|
||||
let connect_id = generate_id()?;
|
||||
let connect_id = make_empty_id(node_id.clone(), &session_type, slot_count)?;
|
||||
let is_empty = true;
|
||||
let addr = "Null".to_string();
|
||||
let state = &slot["state"];
|
||||
|
||||
@@ -45,6 +45,35 @@ pub fn generate_id() -> Result<String> {
|
||||
Ok(serial::serialize_hex(&id))
|
||||
}
|
||||
|
||||
pub fn make_empty_id(node_id: String, session: &Session, count: u64) -> 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
|
||||
}
|
||||
|
||||
num += count;
|
||||
|
||||
Ok(serial::serialize_hex(&num))
|
||||
}
|
||||
//pub fn is_empty_outbound(slots: Vec<Slot>) -> bool {
|
||||
// return slots.iter().all(|slot| slot.is_empty);
|
||||
//}
|
||||
|
||||
@@ -92,8 +92,20 @@ impl View {
|
||||
nodes.push(names);
|
||||
//nodes.push(node);
|
||||
}
|
||||
SelectableObject::Session(info) => self.session_info.clone().render(info),
|
||||
SelectableObject::Connect(info) => self.connect_info.clone().render(info),
|
||||
SelectableObject::Session(info) => {
|
||||
let name_span = Span::raw(&info.session_name);
|
||||
let lines = vec![Spans::from(name_span)];
|
||||
let names = ListItem::new(lines);
|
||||
nodes.push(names);
|
||||
//self.session_info.clone().render(info),
|
||||
}
|
||||
SelectableObject::Connect(info) => {
|
||||
let name_span = Span::raw(&info.connect_id);
|
||||
let lines = vec![Spans::from(name_span)];
|
||||
let names = ListItem::new(lines);
|
||||
nodes.push(names);
|
||||
//self.connect_info.clone().render(info),
|
||||
}
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user