Skip to content
Snippets Groups Projects
Commit 27c038c6 authored by Éloïs's avatar Éloïs
Browse files

[tui] add url in connections view

parent 71eb99c0
Branches
Tags
1 merge request!58Resolve "Add crates blockchain, conf, core, dal, message, module, network, tui and ws2p"
...@@ -99,6 +99,12 @@ impl NodeFullId { ...@@ -99,6 +99,12 @@ impl NodeFullId {
sha256.input_str(&format!("{}", self)); sha256.input_str(&format!("{}", self));
Hash::from_hex(&sha256.result_str()).unwrap() Hash::from_hex(&sha256.result_str()).unwrap()
} }
/// To human string
pub fn to_human_string(&self) -> String {
let mut pubkey_string = self.1.to_string();
pubkey_string.truncate(8);
format!("{:8x}-{:8}", (self.0).0, pubkey_string)
}
} }
/// Trait to be implemented by the configuration object of the module managing the inter-node network. /// Trait to be implemented by the configuration object of the module managing the inter-node network.
...@@ -267,7 +273,7 @@ pub enum NetworkEvent { ...@@ -267,7 +273,7 @@ pub enum NetworkEvent {
/// Receiving a response to a network request /// Receiving a response to a network request
ReqResponse(Box<NetworkResponse>), ReqResponse(Box<NetworkResponse>),
/// A connection has changed state(`u32` is the new state, `Option<String>` est l'uid du noeud) /// A connection has changed state(`u32` is the new state, `Option<String>` est l'uid du noeud)
ConnectionStateChange(NodeFullId, u32, Option<String>), ConnectionStateChange(NodeFullId, u32, Option<String>, String),
/// Receiving Pending Documents /// Receiving Pending Documents
ReceiveDocuments(Vec<NetworkDocument>), ReceiveDocuments(Vec<NetworkDocument>),
/// Receipt of peer cards /// Receipt of peer cards
......
...@@ -150,7 +150,7 @@ impl NetworkEndpoint { ...@@ -150,7 +150,7 @@ impl NetworkEndpoint {
} }
} }
/// Generate endpoint url /// Generate endpoint url
pub fn get_url(&self) -> String { pub fn get_url(&self, get_protocol: bool) -> String {
match *self { match *self {
NetworkEndpoint::V1(ref ep) => { NetworkEndpoint::V1(ref ep) => {
let protocol = match &ep.api.0[..] { let protocol = match &ep.api.0[..] {
...@@ -165,7 +165,11 @@ impl NetworkEndpoint { ...@@ -165,7 +165,11 @@ impl NetworkEndpoint {
Some(ref path_string) => path_string.clone(), Some(ref path_string) => path_string.clone(),
None => String::new(), None => String::new(),
}; };
if get_protocol {
format!("{}{}://{}:{}/{}", protocol, tls, ep.host, ep.port, path) format!("{}{}://{}:{}/{}", protocol, tls, ep.host, ep.port, path)
} else {
format!("{}:{}/{}", ep.host, ep.port, path)
}
} }
_ => panic!("Endpoint version is not supported !"), _ => panic!("Endpoint version is not supported !"),
} }
......
...@@ -72,8 +72,10 @@ pub struct TuiModule {} ...@@ -72,8 +72,10 @@ pub struct TuiModule {}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Network connexion (data to display) /// Network connexion (data to display)
pub struct Connection { pub struct Connection {
/// connexion status /// Connexion status
status: u32, status: u32,
/// Endpoint url
url: String,
/// Node uid at the other end of the connection (member nodes only) /// Node uid at the other end of the connection (member nodes only)
uid: Option<String>, uid: Option<String>,
} }
...@@ -91,8 +93,6 @@ pub struct TuiModuleDatas { ...@@ -91,8 +93,6 @@ pub struct TuiModuleDatas {
pub connections_status: HashMap<NodeFullId, Connection>, pub connections_status: HashMap<NodeFullId, Connection>,
/// Number of connections in `Established` status /// Number of connections in `Established` status
pub established_conns_count: usize, pub established_conns_count: usize,
/// Position of the 1st connection displayed on the screen
pub conns_index: usize,
} }
impl TuiModuleDatas { impl TuiModuleDatas {
...@@ -109,7 +109,6 @@ impl TuiModuleDatas { ...@@ -109,7 +109,6 @@ impl TuiModuleDatas {
heads_index: usize, heads_index: usize,
out_connections_status: &HashMap<NodeFullId, Connection>, out_connections_status: &HashMap<NodeFullId, Connection>,
_in_connections_status: &HashMap<NodeFullId, Connection>, _in_connections_status: &HashMap<NodeFullId, Connection>,
conns_index: usize,
) { ) {
// Get Terminal size // Get Terminal size
let (w, h) = termion::terminal_size().expect("Fail to get terminal size !"); let (w, h) = termion::terminal_size().expect("Fail to get terminal size !");
...@@ -128,7 +127,11 @@ impl TuiModuleDatas { ...@@ -128,7 +127,11 @@ impl TuiModuleDatas {
1 | 3 | 5 | 7 | 8 | 9 => out_trying_conns_count += 1, 1 | 3 | 5 | 7 | 8 | 9 => out_trying_conns_count += 1,
10 => out_denial_conns_count += 1, 10 => out_denial_conns_count += 1,
11 => out_disconnected_conns_count += 1, 11 => out_disconnected_conns_count += 1,
12 => out_established_conns.push((node_full_id, connection.uid.clone())), 12 => out_established_conns.push((
node_full_id,
connection.uid.clone(),
connection.url.clone(),
)),
_ => {} _ => {}
} }
} }
...@@ -168,13 +171,6 @@ impl TuiModuleDatas { ...@@ -168,13 +171,6 @@ impl TuiModuleDatas {
color::Fg(color::White), color::Fg(color::White),
style::Italic, style::Italic,
).unwrap(); ).unwrap();
line += 1;
write!(
stdout,
"{}{}/\\",
cursor::Goto(29, line),
color::Fg(color::Black),
).unwrap();
// Draw inter-nodes established connections // Draw inter-nodes established connections
if out_established_conns.is_empty() { if out_established_conns.is_empty() {
...@@ -187,38 +183,19 @@ impl TuiModuleDatas { ...@@ -187,38 +183,19 @@ impl TuiModuleDatas {
style::Bold, style::Bold,
).unwrap(); ).unwrap();
} else { } else {
let mut count_conns = 0; for (ref node_full_id, ref uid, ref url) in out_established_conns {
let max_index = if out_established_conns.len() < 5 {
0
} else {
out_established_conns.len() - 5
};
let conns_index_use = if conns_index > max_index {
max_index
} else {
conns_index
};
for &(node_full_id, ref uid) in &out_established_conns[conns_index_use..] {
line += 1; line += 1;
count_conns += 1; let mut uid_string = uid.clone().unwrap_or(String::from("----------------"));
uid_string.truncate(16);
write!( write!(
stdout, stdout,
"{}{} {} {}", "{}{} {} {:16} {}",
cursor::Goto(2, line), cursor::Goto(2, line),
color::Fg(color::Green), color::Fg(color::Green),
node_full_id, node_full_id.to_human_string(),
uid.clone().unwrap_or_else(String::new), uid_string,
).unwrap(); url,
if count_conns == 5 {
line += 1;
write!(
stdout,
"{}{}\\/",
cursor::Goto(29, line),
color::Fg(color::Black)
).unwrap(); ).unwrap();
break;
}
} }
} }
...@@ -405,7 +382,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -405,7 +382,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
heads_index: 0, heads_index: 0,
connections_status: HashMap::new(), connections_status: HashMap::new(),
established_conns_count: 0, established_conns_count: 0,
conns_index: 0,
}; };
// Create tui main thread channel // Create tui main thread channel
...@@ -463,7 +439,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -463,7 +439,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
tui.heads_index, tui.heads_index,
&tui.connections_status, &tui.connections_status,
&HashMap::with_capacity(0), &HashMap::with_capacity(0),
tui.conns_index,
); );
// Launch stdin thread // Launch stdin thread
...@@ -529,8 +504,9 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -529,8 +504,9 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
ref node_full_id, ref node_full_id,
ref status, ref status,
ref uid, ref uid,
ref url,
) => { ) => {
if let Some(conn) = tui.connections_status.get(node_full_id) { if let Some(conn) = tui.connections_status.get(&node_full_id) {
if *status == 12 && (*conn).status != 12 { if *status == 12 && (*conn).status != 12 {
tui.established_conns_count += 1; tui.established_conns_count += 1;
} else if *status != 12 } else if *status != 12
...@@ -544,6 +520,7 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -544,6 +520,7 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
*node_full_id, *node_full_id,
Connection { Connection {
status: *status, status: *status,
url: url.clone(),
uid: uid.clone(), uid: uid.clone(),
}, },
); );
...@@ -581,25 +558,11 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -581,25 +558,11 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
break; break;
} }
&Event::Mouse(ref me) => match me { &Event::Mouse(ref me) => match me {
&MouseEvent::Press(ref button, ref _a, ref b) => match button { &MouseEvent::Press(ref button, ref _a, ref _b) => match button {
&MouseButton::WheelDown => { &MouseButton::WheelDown => {
// Get Terminal size // Get Terminal size
let (_w, h) = termion::terminal_size() let (_w, h) = termion::terminal_size()
.expect("Fail to get terminal size !"); .expect("Fail to get terminal size !");
if *b < 11 {
// conns_index
let conns_index_max = if tui.established_conns_count > 5 {
tui.established_conns_count - 5
} else {
0
};
if tui.heads_index < conns_index_max {
tui.conns_index += 1;
user_event = true;
} else {
tui.conns_index = conns_index_max;
}
} else {
// heads_index // heads_index
if h > 16 { if h > 16 {
let heads_index_max = let heads_index_max =
...@@ -616,22 +579,13 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -616,22 +579,13 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
} }
} }
} }
}
&MouseButton::WheelUp => { &MouseButton::WheelUp => {
if *b < 11 {
// conns_index
if tui.conns_index > 0 {
tui.conns_index -= 1;
user_event = true;
}
} else {
// heads_index // heads_index
if tui.heads_index > 0 { if tui.heads_index > 0 {
tui.heads_index -= 1; tui.heads_index -= 1;
user_event = true; user_event = true;
} }
} }
}
_ => {} _ => {}
}, },
&MouseEvent::Release(ref _a, ref _b) &MouseEvent::Release(ref _a, ref _b)
...@@ -662,7 +616,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule { ...@@ -662,7 +616,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
tui.heads_index, tui.heads_index,
&tui.connections_status, &tui.connections_status,
&HashMap::with_capacity(0), &HashMap::with_capacity(0),
tui.conns_index,
); );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment