/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2023 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
use std::collections::HashMap;
use async_std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};
use darkfi::util::time::NanoTimestamp;
type MsgLog = Vec<(NanoTimestamp, String, String)>;
type MsgMap = Mutex>;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub enum Session {
Inbound,
Outbound,
//Manual,
Offline,
Null,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub enum SelectableObject {
Node(NodeInfo),
Lilith(LilithInfo),
Network(NetworkInfo),
Session(SessionInfo),
Slot(SlotInfo),
}
#[derive(Debug)]
pub struct Model {
pub msg_map: MsgMap,
pub log: Mutex,
pub selectables: Mutex>,
}
impl Model {
pub fn new() -> Arc {
let selectables = Mutex::new(HashMap::new());
let msg_map = Mutex::new(HashMap::new());
let log = Mutex::new(Vec::new());
Arc::new(Model { msg_map, log, selectables })
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct NodeInfo {
pub dnet_id: String,
pub name: String,
pub hosts: Vec,
pub inbound: Vec,
pub outbound: Vec,
pub is_offline: bool,
pub dnet_enabled: bool,
}
impl NodeInfo {
pub fn new(
dnet_id: String,
name: String,
hosts: Vec,
inbound: Vec,
outbound: Vec,
is_offline: bool,
dnet_enabled: bool,
) -> Self {
Self { dnet_id, name, hosts, inbound, outbound, is_offline, dnet_enabled }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct SessionInfo {
pub dnet_id: String,
pub node_id: String,
pub addr: String,
pub state: Option,
pub info: SlotInfo,
pub sort: Session,
pub is_empty: bool,
}
impl SessionInfo {
pub fn new(
dnet_id: String,
node_id: String,
addr: String,
state: Option,
info: SlotInfo,
sort: Session,
is_empty: bool,
) -> Self {
Self { dnet_id, node_id, addr, state, info, sort, is_empty }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct SlotInfo {
pub dnet_id: String,
pub node_id: String,
pub addr: String,
pub random_id: u64,
pub remote_id: String,
pub log: Vec<(NanoTimestamp, String, String)>,
pub is_empty: bool,
}
impl SlotInfo {
#[allow(clippy::too_many_arguments)]
pub fn new(
dnet_id: String,
node_id: String,
addr: String,
random_id: u64,
remote_id: String,
log: Vec<(NanoTimestamp, String, String)>,
is_empty: bool,
) -> Self {
Self { dnet_id, addr, random_id, remote_id, log, node_id, is_empty }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct LilithInfo {
pub id: String,
pub name: String,
pub networks: Vec,
}
impl LilithInfo {
pub fn new(id: String, name: String, networks: Vec) -> Self {
Self { id, name, networks }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct NetworkInfo {
pub id: String,
pub name: String,
pub urls: Vec,
pub nodes: Vec,
}
impl NetworkInfo {
pub fn new(id: String, name: String, urls: Vec, nodes: Vec) -> Self {
Self { id, name, urls, nodes }
}
}