Просмотр исходного кода

remove Addr structs and cleanup

lunar-mining 4 лет назад
Родитель
Сommit
d6b48f71a8
5 измененных файлов с 9 добавлено и 98 удалено
  1. 2 2
      bin/dnetview/src/lib.rs
  2. 3 22
      bin/dnetview/src/main.rs
  3. 2 30
      bin/dnetview/src/model.rs
  4. 1 15
      bin/dnetview/src/ui.rs
  5. 1 29
      bin/dnetview/src/view.rs

+ 2 - 2
bin/dnetview/src/lib.rs

@@ -5,7 +5,7 @@ pub mod ui;
 pub mod view;
 
 pub use config::{DnvConfig, CONFIG_FILE_CONTENTS};
-pub use model::{AddrInfo, AddrList, IdList, InfoList, Model, NodeInfo};
+pub use model::{IdList, InfoList, Model, NodeInfo};
 pub use options::ProgramOptions;
 pub use ui::ui;
-pub use view::{AddrListView, IdListView, InfoListView, View};
+pub use view::{IdListView, InfoListView, View};

+ 3 - 22
bin/dnetview/src/main.rs

@@ -27,13 +27,10 @@ use darkfi::{
 
 use dnetview::{
     config::{DnvConfig, CONFIG_FILE_CONTENTS},
-    model::{
-        AddrInfo, AddrList, Channel, IdList, InboundInfo, InfoList, ManualInfo, NodeInfo,
-        OutboundInfo, Slot,
-    },
+    model::{Channel, IdList, InboundInfo, InfoList, ManualInfo, NodeInfo, OutboundInfo, Slot},
     options::ProgramOptions,
     ui,
-    view::{AddrListView, IdListView, InfoListView},
+    view::{IdListView, InfoListView},
     Model, View,
 };
 
@@ -113,9 +110,8 @@ async fn main() -> Result<()> {
     let info_list = InfoList::new();
     let ids = FxHashSet::default();
     let id_list = IdList::new(ids);
-    let addr_list = AddrList::new();
 
-    let model = Arc::new(Model::new(id_list, info_list, addr_list));
+    let model = Arc::new(Model::new(id_list, info_list));
 
     let nthreads = num_cpus::get();
     let (signal, shutdown) = async_channel::unbounded::<()>();
@@ -249,18 +245,6 @@ async fn poll(client: DNetView, model: Arc<Model>) -> Result<()> {
                 model.id_list.node_id.lock().await.insert(key.to_string().clone());
                 model.info_list.infos.lock().await.insert(key.to_string(), value);
             }
-
-            // TODO: this is just a placeholder. Later this will contain a message log.
-            // There's an obvious bug here (all addrs are matched with the same ainfo)
-            let mut addr_info = FxHashMap::default();
-            let ainfos = AddrInfo::new(msgs);
-            for addr in addrs {
-                addr_info.insert(addr, ainfos.clone());
-            }
-
-            for (key, value) in addr_info.clone() {
-                model.addr_list.infos.lock().await.insert(key.to_string(), value);
-            }
         } else {
             // TODO: error handling
             //debug!("Reply is empty");
@@ -298,15 +282,12 @@ async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> io
                 }
                 Key::Char('j') => {
                     view.id_list.next();
-                    view.info_list.next().await;
                 }
                 Key::Char('k') => {
                     view.id_list.previous();
-                    view.info_list.previous().await;
                 }
                 _ => (),
             }
         }
-        //async_util::sleep(3).await;
     }
 }

+ 2 - 30
bin/dnetview/src/model.rs

@@ -7,12 +7,11 @@ use tui::widgets::ListState;
 pub struct Model {
     pub id_list: IdList,
     pub info_list: InfoList,
-    pub addr_list: AddrList,
 }
 
 impl Model {
-    pub fn new(id_list: IdList, info_list: InfoList, addr_list: AddrList) -> Model {
-        Model { id_list, info_list, addr_list }
+    pub fn new(id_list: IdList, info_list: InfoList) -> Model {
+        Model { id_list, info_list }
     }
 }
 
@@ -49,21 +48,6 @@ impl Default for InfoList {
     }
 }
 
-pub struct AddrList {
-    pub index: Mutex<usize>,
-    pub infos: Mutex<FxHashMap<String, AddrInfo>>,
-}
-
-impl AddrList {
-    pub fn new() -> AddrList {
-        let index = 0;
-        let index = Mutex::new(index);
-        let infos = Mutex::new(FxHashMap::default());
-
-        AddrList { index, infos }
-    }
-}
-
 #[derive(Clone, Debug, PartialEq, Eq, Hash)]
 pub struct NodeInfo {
     pub outbound: Vec<OutboundInfo>,
@@ -144,15 +128,3 @@ impl InboundInfo {
         InboundInfo { is_empty, connected, channel }
     }
 }
-
-#[derive(Clone, Deserialize, Debug, PartialEq, Eq, Hash)]
-pub struct AddrInfo {
-    // TODO: this will be a message log
-    pub msgs: Vec<String>,
-}
-
-impl AddrInfo {
-    pub fn new(msgs: Vec<String>) -> AddrInfo {
-        AddrInfo { msgs }
-    }
-}

+ 1 - 15
bin/dnetview/src/ui.rs

@@ -16,15 +16,12 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
     let list_cnstrnts = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
 
     let mut nodes = Vec::new();
-    // we write all the span data to a Vec<String> for debugging purposes
-    let mut data = Vec::new();
     let style = Style::default();
 
+    // lines.push(sublist)
     for id in &view.id_list.node_id {
         let id_span = Span::raw(id.to_string());
         let mut lines = vec![Spans::from(id_span)];
-        data.push(id.to_string());
-        debug!("1 LINES: {:?}", lines);
 
         // create a new vector of addresses
         // render as a sub node
@@ -32,12 +29,10 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
             Some(node) => {
                 if !node.outbound.iter().all(|node| node.is_empty == true) {
                     lines.push(Spans::from(Span::styled("   Outgoing", Style::default())));
-                    data.push("Outgoing".to_string());
                 }
                 for outbound in &node.outbound.clone() {
                     for slot in outbound.slots.clone() {
                         let addr = Span::styled(format!("       {}", slot.addr), style);
-                        data.push(format!("{}", slot.addr));
                         let msg: Span = match slot.channel.last_status.as_str() {
                             "recv" => Span::styled(
                                 format!("               [R: {}]", slot.channel.last_msg),
@@ -49,17 +44,14 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
                             ),
                             a => Span::styled(a.to_string(), style),
                         };
-                        data.push(format!("{}", slot.channel.last_msg));
                         lines.push(Spans::from(vec![addr, msg]));
                     }
                 }
                 if !node.inbound.iter().all(|node| node.is_empty == true) {
                     lines.push(Spans::from(Span::styled("   Incoming", Style::default())));
-                    data.push("Incoming".to_string());
                 }
                 for inbound in &node.inbound {
                     let addr = Span::styled(format!("       {}", inbound.connected), style);
-                    data.push(format!("{}", inbound.connected));
                     let msg: Span = match inbound.channel.last_status.as_str() {
                         "recv" => Span::styled(
                             format!("               [R: {}]", inbound.channel.last_msg),
@@ -71,14 +63,11 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
                         ),
                         a => Span::styled(a.to_string(), style),
                     };
-                    data.push(format!("{}", inbound.channel.last_msg));
                     lines.push(Spans::from(vec![addr, msg]));
                 }
                 lines.push(Spans::from(Span::styled("   Manual", Style::default())));
-                data.push("Manual".to_string());
                 for connect in &node.manual {
                     lines.push(Spans::from(Span::styled(format!("       {}", connect.key), style)));
-                    data.push(format!("{}", connect.key));
                 }
             }
             None => {
@@ -87,11 +76,8 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
             }
         }
 
-        debug!("2 LINES: {:?}", lines);
         let ids = ListItem::new(lines);
-        debug!("1 IDS: {:?}", ids);
         nodes.push(ids);
-        debug!("1 NODES: {:?}", nodes);
     }
 
     let nodes =

+ 1 - 29
bin/dnetview/src/view.rs

@@ -1,5 +1,5 @@
 use fxhash::{FxHashMap, FxHashSet};
-use log::debug;
+//use log::debug;
 use tui::widgets::ListState;
 
 use crate::model::NodeInfo;
@@ -45,7 +45,6 @@ impl IdListView {
             None => 0,
         };
         self.state.select(Some(i));
-        debug!("NEXT STATE {:?}", i);
     }
 
     pub fn previous(&mut self) {
@@ -60,7 +59,6 @@ impl IdListView {
             None => 0,
         };
         self.state.select(Some(i));
-        debug!("PREV STATE {:?}", i);
     }
 
     pub fn unselect(&mut self) {
@@ -93,29 +91,3 @@ impl InfoListView {
         }
     }
 }
-
-#[derive(Clone)]
-pub struct AddrListView {
-    pub index: usize,
-    pub infos: FxHashMap<String, NodeInfo>,
-}
-
-impl AddrListView {
-    pub fn new(infos: FxHashMap<String, NodeInfo>) -> AddrListView {
-        let index = 0;
-
-        AddrListView { index, infos }
-    }
-
-    pub async fn next(&mut self) {
-        self.index = (self.index + 1) % self.infos.len();
-    }
-
-    pub async fn previous(&mut self) {
-        if self.index > 0 {
-            self.index -= 1;
-        } else {
-            self.index = self.infos.len() - 1;
-        }
-    }
-}