ghassmo 4 лет назад
Родитель
Сommit
75072bbb5b
3 измененных файлов с 28 добавлено и 50 удалено
  1. 2 5
      bin/dnetview/src/main.rs
  2. 8 3
      bin/dnetview/src/model.rs
  3. 18 42
      bin/dnetview/src/util.rs

+ 2 - 5
bin/dnetview/src/main.rs

@@ -3,11 +3,10 @@ use std::{collections::hash_map::Entry, fs::File, io, io::Read, path::PathBuf};
 
 use easy_parallel::Parallel;
 use fxhash::{FxHashMap, FxHashSet};
-use log::info;
+use log::{error, info};
 use serde_json::{json, Value};
 use simplelog::*;
 use smol::Executor;
-
 use termion::{async_stdin, event::Key, input::TermRead, raw::IntoRawMode};
 use tui::{
     backend::{Backend, TermionBackend},
@@ -34,8 +33,6 @@ use dnetview::{
     view::{IdListView, NodeInfoView, View},
 };
 
-use log::error;
-
 struct DnetView {
     name: String,
     rpc_client: RpcClient,
@@ -392,7 +389,7 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult<Sess
 }
 
 // TODO: placeholder for now
-async fn parse_manual(_manual: &Value, node_id: &String) -> DnetViewResult<SessionInfo> {
+async fn _parse_manual(_manual: &Value, node_id: &String) -> DnetViewResult<SessionInfo> {
     let name = "Manual".to_string();
     let session_type = Session::Manual;
     let mut connects: Vec<ConnectInfo> = Vec::new();

+ 8 - 3
bin/dnetview/src/model.rs

@@ -1,8 +1,13 @@
 use async_std::sync::Mutex;
-use darkfi::util::NanoTimestamp;
+
 use fxhash::{FxHashMap, FxHashSet};
 use serde::{Deserialize, Serialize};
 
+use darkfi::util::NanoTimestamp;
+
+type MsgLogMutex = Mutex<FxHashMap<String, Vec<(NanoTimestamp, String, String)>>>;
+
+
 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
 pub enum Session {
     Inbound,
@@ -21,7 +26,7 @@ pub enum SelectableObject {
 pub struct Model {
     pub ids: Mutex<FxHashSet<String>>,
     pub nodes: Mutex<FxHashMap<String, NodeInfo>>,
-    pub msg_log: Mutex<FxHashMap<String, Vec<(NanoTimestamp, String, String)>>>,
+    pub msg_log: MsgLogMutex,
     pub selectables: Mutex<FxHashMap<String, SelectableObject>>,
 }
 
@@ -29,7 +34,7 @@ impl Model {
     pub fn new(
         ids: Mutex<FxHashSet<String>>,
         nodes: Mutex<FxHashMap<String, NodeInfo>>,
-        msg_log: Mutex<FxHashMap<String, Vec<(NanoTimestamp, String, String)>>>,
+        msg_log: MsgLogMutex,
         selectables: Mutex<FxHashMap<String, SelectableObject>>,
     ) -> Model {
         Model { ids, nodes, msg_log, selectables }

+ 18 - 42
bin/dnetview/src/util.rs

@@ -13,27 +13,15 @@ pub fn make_node_id(node_name: &String) -> Result<String> {
 pub fn make_session_id(node_id: &str, 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;
-            }
-        }
-        Session::Offline => {
-            for i in ['o', 'f', 'f'] {
-                num += i as u64
-            }
-        }
+    let session_chars = match session {
+        Session::Inbound => vec!['i', 'n'],
+        Session::Outbound => vec!['o', 'u', 't'],
+        Session::Manual => vec!['m', 'a', 'n'],
+        Session::Offline => vec!['o', 'f', 'f'],
+    };
+
+    for i in session_chars {
+        num += i as u64
     }
 
     for i in node_id.chars() {
@@ -62,27 +50,15 @@ pub fn make_empty_id(node_id: &str, session: &Session, count: u64) -> Result<Str
 
     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;
-            }
-        }
-        Session::Offline => {
-            for i in ['o', 'f', 'f'] {
-                num += i as u64
-            }
-        }
+    let session_chars = match session {
+        Session::Inbound => vec!['i', 'n'],
+        Session::Outbound => vec!['o', 'u', 't'],
+        Session::Manual => vec!['m', 'a', 'n'],
+        Session::Offline => vec!['o', 'f', 'f'],
+    };
+
+    for i in session_chars {
+        num += i as u64
     }
 
     for i in node_id.chars() {