| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- use async_std::sync::Mutex;
- use fxhash::{FxHashMap, FxHashSet};
- use serde::Deserialize;
- 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 struct IdList {
- pub state: Mutex<ListState>,
- pub node_id: Mutex<FxHashSet<String>>,
- }
- impl IdList {
- pub fn new(node_id: FxHashSet<String>) -> IdList {
- let node_id = Mutex::new(node_id);
- IdList { state: Mutex::new(ListState::default()), node_id }
- }
- }
- 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 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>,
- pub manual: Vec<ManualInfo>,
- pub inbound: Vec<InboundInfo>,
- }
- impl NodeInfo {
- pub fn new() -> NodeInfo {
- NodeInfo { outbound: Vec::new(), manual: Vec::new(), inbound: Vec::new() }
- }
- }
- impl Default for NodeInfo {
- fn default() -> Self {
- Self::new()
- }
- }
- #[derive(Clone, Debug, PartialEq, Deserialize, Eq, Hash)]
- pub struct ManualInfo {
- pub key: u64,
- }
- impl ManualInfo {
- pub fn new(key: u64) -> ManualInfo {
- ManualInfo { key }
- }
- }
- #[derive(Clone, Debug, PartialEq, Deserialize, Eq, Hash)]
- pub struct OutboundInfo {
- pub is_empty: bool,
- pub slots: Vec<Slot>,
- }
- impl OutboundInfo {
- pub fn new(is_empty: bool, slots: Vec<Slot>) -> OutboundInfo {
- OutboundInfo { is_empty, slots }
- }
- }
- #[derive(Clone, Debug, PartialEq, Deserialize, Eq, Hash)]
- pub struct Slot {
- pub is_empty: bool,
- pub addr: String,
- pub channel: Channel,
- pub state: String,
- }
- impl Slot {
- pub fn new(is_empty: bool, addr: String, channel: Channel, state: String) -> Slot {
- Slot { is_empty, addr, channel, state }
- }
- }
- #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
- pub struct Channel {
- pub last_msg: String,
- pub last_status: String,
- }
- impl Channel {
- pub fn new(last_msg: String, last_status: String) -> Channel {
- Channel { last_msg, last_status }
- }
- }
- #[derive(Clone, Deserialize, Debug, PartialEq, Eq, Hash)]
- pub struct InboundInfo {
- pub is_empty: bool,
- pub connected: String,
- pub channel: Channel,
- }
- impl InboundInfo {
- pub fn new(is_empty: bool, connected: String, channel: Channel) -> 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 }
- }
- }
|