mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
dnetview: make info hashmap singular and update README
instead of making several info hashmaps like so: node_info = HashMap<NodeId, NodeInfo> session_info = HashMap<SessionId, SessionInfo> we make a single info hashmap: infos = HashMap<Id, SelectableObject> this is so we can keep track of what kind of selectable object the ID is associated with.
This commit is contained in:
@@ -79,12 +79,10 @@ enum SelectableObject {
|
||||
```
|
||||
Id is a randomly generated number to correspond to the received info.
|
||||
|
||||
Each SelectableObject corresponds to an info HashMap.
|
||||
We copy all of these values into a info hashmap.
|
||||
|
||||
```
|
||||
NodeInfo = Hashmap<NodeId, NodeInfo>
|
||||
SessionInfo = Hashmap<SessionId, SessionInfo>
|
||||
ConnectInfo = Hashmap<ConnectId, ConnectInfo>
|
||||
infos = Mutex<Hashmap<u32, SelectableObject>>
|
||||
```
|
||||
|
||||
We use mutexes to protect the data because we are updating it
|
||||
|
||||
@@ -107,12 +107,10 @@ async fn main() -> Result<()> {
|
||||
|
||||
terminal.clear()?;
|
||||
|
||||
let id_set = Mutex::new(FxHashSet::default());
|
||||
let node_info = Mutex::new(FxHashMap::default());
|
||||
let session_info = Mutex::new(FxHashMap::default());
|
||||
let connect_info = Mutex::new(FxHashMap::default());
|
||||
let ids = Mutex::new(FxHashSet::default());
|
||||
let infos = Mutex::new(FxHashMap::default());
|
||||
|
||||
let model = Arc::new(Model::new(id_set, node_info, session_info, connect_info));
|
||||
let model = Arc::new(Model::new(ids, infos));
|
||||
|
||||
let nthreads = num_cpus::get();
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
|
||||
@@ -11,21 +11,21 @@ pub enum SelectableObject {
|
||||
Connect(ConnectInfo),
|
||||
}
|
||||
|
||||
// how do you know which type of thing the hashmap belongs to
|
||||
// we don't need to ??
|
||||
// given an id, return the type of Selectable
|
||||
//
|
||||
pub struct Model {
|
||||
pub id_set: Mutex<FxHashSet<u32>>,
|
||||
pub node_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
pub session_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
pub connect_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
pub ids: Mutex<FxHashSet<u32>>,
|
||||
pub infos: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn new(
|
||||
id_set: Mutex<FxHashSet<u32>>,
|
||||
node_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
session_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
connect_info: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
ids: Mutex<FxHashSet<u32>>,
|
||||
infos: Mutex<FxHashMap<u32, SelectableObject>>,
|
||||
) -> Model {
|
||||
Model { id_set, node_info, session_info, connect_info }
|
||||
Model { ids, infos }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,26 +41,26 @@ impl Model {
|
||||
// }
|
||||
//}
|
||||
|
||||
pub struct InfoList {
|
||||
pub index: Mutex<usize>,
|
||||
pub infos: Mutex<FxHashMap<String, NodeInfo>>,
|
||||
}
|
||||
|
||||
impl InfoList {
|
||||
pub fn new() -> InfoList {
|
||||
let index = 0;
|
||||
let index = Mutex::new(index);
|
||||
let infos = Mutex::new(FxHashMap::default());
|
||||
|
||||
InfoList { index, infos }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InfoList {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
//pub struct InfoList {
|
||||
// pub index: Mutex<usize>,
|
||||
// pub infos: Mutex<FxHashMap<String, NodeInfo>>,
|
||||
//}
|
||||
//
|
||||
//impl InfoList {
|
||||
// pub fn new() -> InfoList {
|
||||
// let index = 0;
|
||||
// let index = Mutex::new(index);
|
||||
// let infos = Mutex::new(FxHashMap::default());
|
||||
//
|
||||
// InfoList { index, infos }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//impl Default for InfoList {
|
||||
// fn default() -> Self {
|
||||
// Self::new()
|
||||
// }
|
||||
//}
|
||||
|
||||
type NodeId = u32;
|
||||
type SessionId = u32;
|
||||
|
||||
@@ -19,6 +19,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
|
||||
let style = Style::default();
|
||||
|
||||
// lines.push(sublist)
|
||||
// either have one hashmap w value as enum or have type info in hashset
|
||||
for id in &view.id_list.node_id {
|
||||
let id_span = Span::raw(id.to_string());
|
||||
let mut lines = vec![Spans::from(id_span)];
|
||||
|
||||
Reference in New Issue
Block a user