Преглед изворни кода

dnetview: cleaned up Model and deleted dead code

lunar-mining пре 4 година
родитељ
комит
1365bd9078
4 измењених фајлова са 17 додато и 49 уклоњено
  1. 0 23
      bin/dnetview/src/error.rs
  2. 1 1
      bin/dnetview/src/main.rs
  3. 5 9
      bin/dnetview/src/model.rs
  4. 11 16
      bin/dnetview/src/parser.rs

+ 0 - 23
bin/dnetview/src/error.rs

@@ -54,26 +54,3 @@ impl From<url::ParseError> for DnetViewError {
         Self::UrlParse(err.to_string())
     }
 }
-//pub fn to_json_result(res: DnetViewResult<Value>, id: Value) -> JsonResult {
-//    match res {
-//        Ok(v) => JsonResult::Resp(jsonresp(v, id)),
-//        Err(err) => match err {
-//            DnetViewError::InvalidId => JsonResult::Err(jsonerr(
-//                ErrorCode::InvalidParams,
-//                Some("invalid task's id".into()),
-//                id,
-//            )),
-//            DnetViewError::InvalidData(e) | DnetViewError::SerdeJsonError(e) => {
-//                JsonResult::Err(jsonerr(ErrorCode::InvalidParams, Some(e), id))
-//            }
-//            DnetViewError::InvalidDueTime => JsonResult::Err(jsonerr(
-//                ErrorCode::InvalidParams,
-//                Some("invalid due time".into()),
-//                id,
-//            )),
-//            DnetViewError::Darkfi(e) => {
-//                JsonResult::Err(jsonerr(ErrorCode::InternalError, Some(e.to_string()), id))
-//            }
-//        },
-//    }
-//}

+ 1 - 1
bin/dnetview/src/main.rs

@@ -52,7 +52,7 @@ impl DnetView {
 
         loop {
             self.view.update(
-                self.model.new_id.lock().await.clone(),
+                self.model.id_vec.lock().await.clone(),
                 self.model.msg_map.lock().await.clone(),
                 self.model.selectables.lock().await.clone(),
             );

+ 5 - 9
bin/dnetview/src/model.rs

@@ -25,9 +25,8 @@ pub enum SelectableObject {
 
 #[derive(Debug)]
 pub struct Model {
-    pub ids: Mutex<FxHashSet<String>>,
-    pub new_id: Mutex<Vec<String>>,
-    pub nodes: Mutex<FxHashMap<String, NodeInfo>>,
+    pub unique_ids: Mutex<FxHashSet<String>>,
+    pub id_vec: Mutex<Vec<String>>,
     pub msg_map: MsgMap,
     pub msg_log: Mutex<MsgLog>,
     pub selectables: Mutex<FxHashMap<String, SelectableObject>>,
@@ -35,13 +34,12 @@ pub struct Model {
 
 impl Model {
     pub fn new() -> Arc<Self> {
-        let ids = Mutex::new(FxHashSet::default());
-        let nodes = Mutex::new(FxHashMap::default());
+        let unique_ids = Mutex::new(FxHashSet::default());
+        let id_vec = Mutex::new(Vec::new());
         let selectables = Mutex::new(FxHashMap::default());
         let msg_map = Mutex::new(FxHashMap::default());
         let msg_log = Mutex::new(Vec::new());
-        let new_id = Mutex::new(Vec::new());
-        Arc::new(Model { ids, new_id, nodes, msg_map, msg_log, selectables })
+        Arc::new(Model { unique_ids, id_vec, msg_map, msg_log, selectables })
     }
 }
 
@@ -70,7 +68,6 @@ impl NodeInfo {
 
 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
 pub struct SessionInfo {
-    // TODO: make all values optional to handle empty sessions
     pub id: String,
     pub name: String,
     pub parent: String,
@@ -94,7 +91,6 @@ impl SessionInfo {
 
 #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
 pub struct ConnectInfo {
-    // TODO: make all values optional to handle empty connections
     pub id: String,
     pub addr: String,
     pub state: String,

+ 11 - 16
bin/dnetview/src/parser.rs

@@ -125,9 +125,8 @@ impl DataParser {
             true,
         );
 
-        self.update_node(node.clone(), node_id.clone()).await;
         self.update_selectable_and_ids(sessions, node.clone()).await?;
-        self.update_new_id().await;
+        self.update_id_vec().await;
         Ok(())
     }
 
@@ -165,10 +164,9 @@ impl DataParser {
             false,
         );
 
-        self.update_node(node.clone(), node_id.clone()).await;
         self.update_selectable_and_ids(sessions.clone(), node.clone()).await?;
         self.update_msgs(sessions.clone()).await?;
-        self.update_new_id().await;
+        self.update_id_vec().await;
 
         //debug!("IDS: {:?}", self.model.ids.lock().await);
         //debug!("INFOS: {:?}", self.model.nodes.lock().await);
@@ -204,20 +202,17 @@ impl DataParser {
         Ok(())
     }
 
-    async fn update_ids(&self, id: String) {
-        self.model.ids.lock().await.insert(id);
+    async fn update_unique_ids(&self, id: String) {
+        self.model.unique_ids.lock().await.insert(id);
     }
 
-    async fn update_new_id(&self) {
-        let ids = self.model.ids.lock().await.clone();
+    async fn update_id_vec(&self) {
+        let ids = self.model.unique_ids.lock().await.clone();
 
         for id in ids.iter() {
-            self.model.new_id.lock().await.push(id.to_string());
+            self.model.id_vec.lock().await.push(id.to_string());
         }
     }
-    async fn update_node(&self, node: NodeInfo, id: String) {
-        self.model.nodes.lock().await.insert(id, node);
-    }
 
     async fn update_selectable_and_ids(
         &self,
@@ -227,20 +222,20 @@ impl DataParser {
         if node.is_offline == true {
             let node_obj = SelectableObject::Node(node.clone());
             self.model.selectables.lock().await.insert(node.id.clone(), node_obj);
-            self.update_ids(node.id.clone()).await;
+            self.update_unique_ids(node.id.clone()).await;
         } else {
             let node_obj = SelectableObject::Node(node.clone());
             self.model.selectables.lock().await.insert(node.id.clone(), node_obj);
-            self.update_ids(node.id.clone()).await;
+            self.update_unique_ids(node.id.clone()).await;
             for session in sessions {
                 if !session.is_empty {
                     let session_obj = SelectableObject::Session(session.clone());
                     self.model.selectables.lock().await.insert(session.clone().id, session_obj);
-                    self.update_ids(session.clone().id).await;
+                    self.update_unique_ids(session.clone().id).await;
                     for connect in session.children {
                         let connect_obj = SelectableObject::Connect(connect.clone());
                         self.model.selectables.lock().await.insert(connect.clone().id, connect_obj);
-                        self.update_ids(connect.clone().id).await;
+                        self.update_unique_ids(connect.clone().id).await;
                     }
                 }
             }