1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::sync::Arc;
use ratatui::layout::{Offset, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::Text;
use ratatui::widgets::Paragraph;
use crate::global_state::GlobalState;
use crate::types::tui_state::TuiState;
use super::Theme;
pub fn draw(
f: &mut ratatui::Frame,
global_state: Arc<GlobalState>,
_tui_state: &mut TuiState,
area: Rect,
theme: &Theme,
) {
let size = area.as_size();
if size.height < 20 || size.width < 50 {
return;
}
let is_dark_theme = matches!(&theme,Theme::Dark(_));
use std::collections::HashSet;
// let total_connections = global_state
// .app_state
// .statistics
// .connections_per_hostname
// .iter()
// .map(|x| {
// let (_, count) = x.pair();
// count.load(std::sync::atomic::Ordering::SeqCst)
// })
// .sum::<usize>();
let mut unique_hostnames = HashSet::new();
for x in global_state
.app_state
.statistics
.connections_per_hostname
.iter()
{
let (domain_name, _) = x.pair();
unique_hostnames.insert(domain_name.clone());
}
//let num_unique_hostnames = unique_hostnames.len();
let style = if is_dark_theme { Style::new().fg(Color::White) } else { Style::new().fg(Color::Black) };
// let p2 = Paragraph::new(format!(
// "Received TCP connections: {}",
// total_connections // <--- this i no longer just tcp connections , its a mix.. we need to sort this out
// after the rewrite so that we use the correct data from the new implementation
// )).style(style);
let p2 = Paragraph::new(format!("This page is under re-construction..")).style(style);
// let p3 = Paragraph::new(format!("Number of unique hostnames seen: {}", num_unique_hostnames)).style(style);
//f.render_widget(p1, area.offset(Offset { x: 4, y: 1 }));
f.render_widget(p2, area.offset(Offset { x: 4, y: 1 }));
// f.render_widget(p3, area.offset(Offset { x: 4, y: 2 }));
// TODO - Use a scrollable table and display all host specific stats
// TODO - Add data-transfer count for each hostname:
// - for tunnelled traffic, we can use the total number of bytes sent/received as observed by the bidirectional copy call.
// - for terminated traffic we can most likely add support for getting this data from the ManagedStream implementation
f.render_widget(
Paragraph::new(Text::styled("... This page will have more data in the future :-)", Style::default().fg(Color::DarkGray))),
area.offset(Offset { x: 4, y: 5 })
);
}