mirror of
https://github.com/imsnif/bandwhich.git
synced 2026-02-09 01:59:18 +08:00
Compact imports
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use ::std::fmt;
|
||||
use std::fmt;
|
||||
|
||||
pub struct DisplayBandwidth {
|
||||
pub bandwidth: f64,
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
terminal::Frame,
|
||||
text::Span,
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
use crate::display::{DisplayBandwidth, UIState};
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::layout::{Alignment, Rect};
|
||||
use ::ratatui::style::{Color, Modifier, Style};
|
||||
use ::ratatui::terminal::Frame;
|
||||
use ::ratatui::text::Span;
|
||||
use ::ratatui::widgets::Paragraph;
|
||||
use ::std::time::{Duration, Instant};
|
||||
|
||||
const SECONDS_IN_DAY: u64 = 86400;
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::layout::{Alignment, Rect};
|
||||
use ::ratatui::style::{Modifier, Style};
|
||||
use ::ratatui::terminal::Frame;
|
||||
use ::ratatui::text::Span;
|
||||
use ::ratatui::widgets::Paragraph;
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Rect},
|
||||
style::{Modifier, Style},
|
||||
terminal::Frame,
|
||||
text::Span,
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
pub struct HelpText {
|
||||
pub paused: bool,
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::layout::{Constraint, Direction, Rect};
|
||||
use ::ratatui::terminal::Frame;
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Constraint, Direction, Rect},
|
||||
terminal::Frame,
|
||||
};
|
||||
|
||||
use super::HeaderDetails;
|
||||
use super::HelpText;
|
||||
use super::Table;
|
||||
use crate::display::{HeaderDetails, HelpText, Table};
|
||||
|
||||
const FIRST_HEIGHT_BREAKPOINT: u16 = 30;
|
||||
const FIRST_WIDTH_BREAKPOINT: u16 = 120;
|
||||
|
||||
fn top_app_and_bottom_split(rect: Rect) -> (Rect, Rect, Rect) {
|
||||
let parts = ::ratatui::layout::Layout::default()
|
||||
let parts = ratatui::layout::Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(0)
|
||||
.constraints(
|
||||
@@ -37,7 +37,7 @@ impl<'a> Layout<'a> {
|
||||
.into_iter()
|
||||
.fold(vec![rect], |mut layout, direction| {
|
||||
let last_rect = layout.pop().unwrap();
|
||||
let halves = ::ratatui::layout::Layout::default()
|
||||
let halves = ratatui::layout::Layout::default()
|
||||
.direction(direction)
|
||||
.margin(0)
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
@@ -74,12 +74,12 @@ impl<'a> Layout<'a> {
|
||||
self.progressive_split(rect, vec![Direction::Vertical])
|
||||
} else {
|
||||
// default layout
|
||||
let halves = ::ratatui::layout::Layout::default()
|
||||
let halves = ratatui::layout::Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(0)
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
.split(rect);
|
||||
let top_quarters = ::ratatui::layout::Layout::default()
|
||||
let top_quarters = ratatui::layout::Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.margin(0)
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
use ::std::collections::{BTreeMap, HashMap};
|
||||
use ::std::iter::FromIterator;
|
||||
use ::unicode_width::UnicodeWidthChar;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
iter::FromIterator,
|
||||
net::IpAddr,
|
||||
};
|
||||
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::layout::{Constraint, Rect};
|
||||
use ::ratatui::style::{Color, Style};
|
||||
use ::ratatui::terminal::Frame;
|
||||
use ::ratatui::widgets::{Block, Borders, Row};
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Constraint, Rect},
|
||||
style::{Color, Style},
|
||||
terminal::Frame,
|
||||
widgets::{Block, Borders, Row},
|
||||
};
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
|
||||
use crate::display::{Bandwidth, DisplayBandwidth, UIState};
|
||||
use crate::network::{display_connection_string, display_ip_or_host};
|
||||
|
||||
use ::std::net::IpAddr;
|
||||
use crate::{
|
||||
display::{Bandwidth, DisplayBandwidth, UIState},
|
||||
network::{display_connection_string, display_ip_or_host},
|
||||
};
|
||||
|
||||
fn display_upload_and_download(bandwidth: &impl Bandwidth, total: bool) -> String {
|
||||
format!(
|
||||
@@ -292,7 +297,7 @@ impl<'a> Table<'a> {
|
||||
let table_rows = rows.map(|row| Row::new(row).style(Style::default()));
|
||||
let width_constraints: Vec<Constraint> =
|
||||
widths.iter().map(|w| Constraint::Length(*w)).collect();
|
||||
let table = ::ratatui::widgets::Table::new(table_rows)
|
||||
let table = ratatui::widgets::Table::new(table_rows)
|
||||
.block(Block::default().title(self.title).borders(Borders::ALL))
|
||||
.header(Row::new(column_names).style(Style::default().fg(Color::Yellow)))
|
||||
.widths(&width_constraints)
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
// that implements the Backend TUI trait, but does nothing
|
||||
// this way, we don't need to create the TermionBackend
|
||||
// and thus skew our stdout when we don't need it
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::buffer::Cell;
|
||||
use ::ratatui::layout::Rect;
|
||||
use ::std::io;
|
||||
|
||||
use std::io;
|
||||
|
||||
use ratatui::{backend::Backend, buffer::Cell, layout::Rect};
|
||||
|
||||
pub struct RawTerminalBackend {}
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
use ::std::collections::HashMap;
|
||||
use std::{collections::HashMap, net::IpAddr, time::Duration};
|
||||
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::Terminal;
|
||||
|
||||
use crate::display::components::{HeaderDetails, HelpText, Layout, Table};
|
||||
use crate::display::UIState;
|
||||
use crate::network::{display_connection_string, display_ip_or_host, LocalSocket, Utilization};
|
||||
|
||||
use ::std::net::IpAddr;
|
||||
|
||||
use crate::RenderOpts;
|
||||
use chrono::prelude::*;
|
||||
use std::time::Duration;
|
||||
use ratatui::{backend::Backend, Terminal};
|
||||
|
||||
use crate::{
|
||||
display::{
|
||||
components::{HeaderDetails, HelpText, Layout, Table},
|
||||
UIState,
|
||||
},
|
||||
network::{display_connection_string, display_ip_or_host, LocalSocket, Utilization},
|
||||
RenderOpts,
|
||||
};
|
||||
|
||||
pub struct Ui<B>
|
||||
where
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use ::std::cmp;
|
||||
use ::std::collections::{HashMap, HashSet, VecDeque};
|
||||
use ::std::hash::Hash;
|
||||
use ::std::iter::FromIterator;
|
||||
use ::std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::{
|
||||
cmp,
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
hash::Hash,
|
||||
iter::FromIterator,
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr},
|
||||
};
|
||||
|
||||
use crate::network::{Connection, LocalSocket, Utilization};
|
||||
|
||||
|
||||
35
src/main.rs
35
src/main.rs
@@ -6,28 +6,29 @@ mod os;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::Ipv4Addr,
|
||||
process,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
Arc, Mutex, RwLock,
|
||||
},
|
||||
thread::{self, park_timeout},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crossterm::{
|
||||
event::{Event, KeyCode, KeyEvent, KeyModifiers},
|
||||
terminal,
|
||||
};
|
||||
use display::{elapsed_time, RawTerminalBackend, Ui};
|
||||
use network::{
|
||||
dns::{self, IpTable},
|
||||
LocalSocket, Sniffer, Utilization,
|
||||
};
|
||||
|
||||
use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use ::crossterm::terminal;
|
||||
use ::pnet::datalink::{DataLinkReceiver, NetworkInterface};
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use ::std::sync::{Arc, Mutex};
|
||||
use ::std::thread;
|
||||
use ::std::thread::park_timeout;
|
||||
|
||||
use std::process;
|
||||
|
||||
use ::ratatui::backend::CrosstermBackend;
|
||||
use ::std::net::Ipv4Addr;
|
||||
use ::std::time::{Duration, Instant};
|
||||
use std::sync::RwLock;
|
||||
use pnet::datalink::{DataLinkReceiver, NetworkInterface};
|
||||
use ratatui::backend::{Backend, CrosstermBackend};
|
||||
use structopt::StructOpt;
|
||||
|
||||
const DISPLAY_DELTA: Duration = Duration::from_millis(1000);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::fmt;
|
||||
use ::std::net::IpAddr;
|
||||
|
||||
use ::std::net::SocketAddr;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt,
|
||||
net::{IpAddr, SocketAddr},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Hash, Eq, Clone, PartialOrd, Ord, Debug, Copy)]
|
||||
pub enum Protocol {
|
||||
@@ -11,10 +11,7 @@ pub enum Protocol {
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
// Currently, linux implementation doesn't use this function.
|
||||
// Without this #[cfg] clippy complains about dead code, and CI refuses
|
||||
// to pass.
|
||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||
#[allow(dead_code)]
|
||||
pub fn from_str(string: &str) -> Option<Self> {
|
||||
match string {
|
||||
"TCP" => Some(Protocol::Tcp),
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
use crate::network::dns::{resolver::Lookup, IpTable};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
net::IpAddr,
|
||||
sync::{Arc, Mutex},
|
||||
thread::{Builder, JoinHandle},
|
||||
};
|
||||
|
||||
use tokio::{
|
||||
runtime::Runtime,
|
||||
sync::mpsc::{self, Sender},
|
||||
};
|
||||
|
||||
use crate::network::dns::{resolver::Lookup, IpTable};
|
||||
|
||||
type PendingAddrs = HashSet<IpAddr>;
|
||||
|
||||
const CHANNEL_SIZE: usize = 1_000;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
||||
use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts};
|
||||
use trust_dns_resolver::{error::ResolveErrorKind, TokioAsyncResolver};
|
||||
use trust_dns_resolver::{
|
||||
config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts},
|
||||
error::ResolveErrorKind,
|
||||
TokioAsyncResolver,
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Lookup {
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
use ::std::boxed::Box;
|
||||
use std::{
|
||||
io::{self, Result},
|
||||
net::{IpAddr, SocketAddr},
|
||||
thread::park_timeout,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use ::pnet::datalink::{DataLinkReceiver, NetworkInterface};
|
||||
use ::pnet::packet::ethernet::{EtherTypes, EthernetPacket};
|
||||
use ::pnet::packet::ip::{IpNextHeaderProtocol, IpNextHeaderProtocols};
|
||||
use ::pnet::packet::ipv4::Ipv4Packet;
|
||||
use ::pnet::packet::ipv6::Ipv6Packet;
|
||||
use ::pnet::packet::tcp::TcpPacket;
|
||||
use ::pnet::packet::udp::UdpPacket;
|
||||
use ::pnet::packet::Packet;
|
||||
use ipnetwork::IpNetwork;
|
||||
use pnet::{
|
||||
datalink::{DataLinkReceiver, NetworkInterface},
|
||||
packet::{
|
||||
ethernet::{EtherTypes, EthernetPacket},
|
||||
ip::{IpNextHeaderProtocol, IpNextHeaderProtocols},
|
||||
ipv4::Ipv4Packet,
|
||||
ipv6::Ipv6Packet,
|
||||
tcp::TcpPacket,
|
||||
udp::UdpPacket,
|
||||
Packet,
|
||||
},
|
||||
};
|
||||
|
||||
use ::ipnetwork::IpNetwork;
|
||||
use ::std::io::{self, Result};
|
||||
use ::std::net::{IpAddr, SocketAddr};
|
||||
use ::std::thread::park_timeout;
|
||||
use crate::{
|
||||
network::{Connection, Protocol},
|
||||
os::shared::get_datalink_channel,
|
||||
};
|
||||
|
||||
use crate::network::{Connection, Protocol};
|
||||
use crate::os::shared::get_datalink_channel;
|
||||
|
||||
const PACKET_WAIT_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(10);
|
||||
const CHANNEL_RESET_DELAY: std::time::Duration = std::time::Duration::from_millis(1000);
|
||||
const PACKET_WAIT_TIMEOUT: Duration = Duration::from_millis(10);
|
||||
const CHANNEL_RESET_DELAY: Duration = Duration::from_millis(1000);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Segment {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::network::{Connection, Direction, Segment};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ::std::collections::HashMap;
|
||||
use crate::network::{Connection, Direction, Segment};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConnectionInfo {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use ::std::collections::HashMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ::procfs::process::FDTarget;
|
||||
use procfs::process::FDTarget;
|
||||
|
||||
use crate::network::{LocalSocket, Protocol};
|
||||
use crate::OpenSockets;
|
||||
use crate::{
|
||||
network::{LocalSocket, Protocol},
|
||||
OpenSockets,
|
||||
};
|
||||
|
||||
pub(crate) fn get_open_sockets() -> OpenSockets {
|
||||
let mut open_sockets = HashMap::new();
|
||||
@@ -22,8 +24,8 @@ pub(crate) fn get_open_sockets() -> OpenSockets {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mut tcp) = ::procfs::net::tcp() {
|
||||
if let Ok(mut tcp6) = ::procfs::net::tcp6() {
|
||||
if let Ok(mut tcp) = procfs::net::tcp() {
|
||||
if let Ok(mut tcp6) = procfs::net::tcp6() {
|
||||
tcp.append(&mut tcp6);
|
||||
}
|
||||
for entry in tcp.into_iter() {
|
||||
@@ -40,8 +42,8 @@ pub(crate) fn get_open_sockets() -> OpenSockets {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mut udp) = ::procfs::net::udp() {
|
||||
if let Ok(mut udp6) = ::procfs::net::udp6() {
|
||||
if let Ok(mut udp) = procfs::net::udp() {
|
||||
if let Ok(mut udp6) = procfs::net::udp6() {
|
||||
udp.append(&mut udp6);
|
||||
}
|
||||
for entry in udp.into_iter() {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
use ::std::collections::HashMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::network::LocalSocket;
|
||||
use crate::OpenSockets;
|
||||
|
||||
use super::lsof_utils;
|
||||
use crate::{network::LocalSocket, os::lsof_utils::get_connections, OpenSockets};
|
||||
|
||||
pub(crate) fn get_open_sockets() -> OpenSockets {
|
||||
let mut open_sockets = HashMap::new();
|
||||
|
||||
let connections = lsof_utils::get_connections();
|
||||
let connections = get_connections();
|
||||
|
||||
for raw_connection in connections {
|
||||
open_sockets.insert(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::network::Protocol;
|
||||
use std::{ffi::OsStr, net::IpAddr, process::Command};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use std::ffi::OsStr;
|
||||
use std::net::IpAddr;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::network::Protocol;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
use ::crossterm::event::read;
|
||||
use ::crossterm::event::Event;
|
||||
use ::pnet::datalink::Channel::Ethernet;
|
||||
use ::pnet::datalink::DataLinkReceiver;
|
||||
use ::pnet::datalink::{self, Config, NetworkInterface};
|
||||
use ::std::io::{self, ErrorKind, Write};
|
||||
use ::tokio::runtime::Runtime;
|
||||
use std::{
|
||||
io::{self, ErrorKind, Write},
|
||||
net::Ipv4Addr,
|
||||
time,
|
||||
};
|
||||
|
||||
use ::std::net::Ipv4Addr;
|
||||
use ::std::time;
|
||||
use crossterm::event::{read, Event};
|
||||
use pnet::datalink::{self, Channel::Ethernet, Config, DataLinkReceiver, NetworkInterface};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use crate::os::errors::GetInterfaceError;
|
||||
use crate::{network::dns, os::errors::GetInterfaceError, OsInputOutput};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use crate::os::linux::get_open_sockets;
|
||||
@@ -18,8 +17,6 @@ use crate::os::lsof::get_open_sockets;
|
||||
#[cfg(target_os = "windows")]
|
||||
use crate::os::windows::get_open_sockets;
|
||||
|
||||
use crate::{network::dns, OsInputOutput};
|
||||
|
||||
pub struct TerminalEvents;
|
||||
|
||||
impl Iterator for TerminalEvents {
|
||||
|
||||
@@ -3,8 +3,10 @@ use std::collections::HashMap;
|
||||
use netstat2::*;
|
||||
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};
|
||||
|
||||
use crate::network::{LocalSocket, Protocol};
|
||||
use crate::OpenSockets;
|
||||
use crate::{
|
||||
network::{LocalSocket, Protocol},
|
||||
OpenSockets,
|
||||
};
|
||||
|
||||
pub(crate) fn get_open_sockets() -> OpenSockets {
|
||||
let mut open_sockets = HashMap::new();
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
use crate::tests::fakes::{create_fake_dns_client, NetworkFrames};
|
||||
|
||||
use ::insta::assert_snapshot;
|
||||
use ::std::sync::{Arc, Mutex};
|
||||
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::net::IpAddr;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::IpAddr,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use packet_builder::*;
|
||||
use pnet::{datalink::DataLinkReceiver, packet::Packet};
|
||||
|
||||
use crate::tests::cases::test_utils::{
|
||||
build_tcp_packet, opts_raw, os_input_output_dns, os_input_output_stdout, test_backend_factory,
|
||||
use crate::{
|
||||
start,
|
||||
tests::{
|
||||
cases::test_utils::{
|
||||
build_tcp_packet, opts_raw, os_input_output_dns, os_input_output_stdout,
|
||||
test_backend_factory,
|
||||
},
|
||||
fakes::{create_fake_dns_client, NetworkFrames},
|
||||
},
|
||||
Opt, RenderOpts,
|
||||
};
|
||||
|
||||
use crate::{start, Opt, RenderOpts};
|
||||
|
||||
fn build_ip_tcp_packet(
|
||||
source_ip: &str,
|
||||
destination_ip: &str,
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
use crate::tests::fakes::{
|
||||
create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, TerminalEvent,
|
||||
TerminalEvents, TestBackend,
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::Write,
|
||||
iter,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::iter;
|
||||
|
||||
use crate::network::dns::Client;
|
||||
use crate::{Opt, OsInputOutput, RenderOpts};
|
||||
use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use packet_builder::*;
|
||||
use pnet::datalink::DataLinkReceiver;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use pnet::packet::Packet;
|
||||
use pnet::{datalink::DataLinkReceiver, packet::Packet};
|
||||
use pnet_base::MacAddr;
|
||||
|
||||
use crate::{
|
||||
network::dns::Client,
|
||||
tests::fakes::{
|
||||
create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, TerminalEvent,
|
||||
TerminalEvents, TestBackend,
|
||||
},
|
||||
Opt, OsInputOutput, RenderOpts,
|
||||
};
|
||||
|
||||
pub fn sleep_and_quit_events(sleep_num: usize) -> Box<TerminalEvents> {
|
||||
let mut events: Vec<Option<Event>> = iter::repeat(None).take(sleep_num).collect();
|
||||
events.push(Some(Event::Key(KeyEvent::new(
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
use crate::tests::fakes::TerminalEvent::*;
|
||||
use crate::tests::fakes::{
|
||||
create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames,
|
||||
};
|
||||
use std::{collections::HashMap, iter, net::IpAddr};
|
||||
|
||||
use ::insta::assert_snapshot;
|
||||
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::net::IpAddr;
|
||||
|
||||
use crate::tests::cases::test_utils::{
|
||||
build_tcp_packet, opts_ui, os_input_output, os_input_output_factory, sample_frames,
|
||||
sleep_and_quit_events, sleep_resize_and_quit_events, test_backend_factory,
|
||||
};
|
||||
use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use insta::assert_snapshot;
|
||||
use pnet::datalink::DataLinkReceiver;
|
||||
use std::iter;
|
||||
|
||||
use crate::tests::fakes::TerminalEvents;
|
||||
|
||||
use crate::{start, Opt, OsInputOutput, RenderOpts};
|
||||
use crate::{
|
||||
start,
|
||||
tests::{
|
||||
cases::test_utils::{
|
||||
build_tcp_packet, opts_ui, os_input_output, os_input_output_factory, sample_frames,
|
||||
sleep_and_quit_events, sleep_resize_and_quit_events, test_backend_factory,
|
||||
},
|
||||
fakes::{
|
||||
create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames,
|
||||
TerminalEvent::*, TerminalEvents,
|
||||
},
|
||||
},
|
||||
Opt, OsInputOutput, RenderOpts,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn basic_startup() {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use ::async_trait::async_trait;
|
||||
use ::crossterm::event::Event;
|
||||
use ::ipnetwork::IpNetwork;
|
||||
use ::pnet::datalink::DataLinkReceiver;
|
||||
use ::pnet::datalink::NetworkInterface;
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use ::std::{thread, time};
|
||||
use ::tokio::runtime::Runtime;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
thread, time,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use crossterm::event::Event;
|
||||
use ipnetwork::IpNetwork;
|
||||
use pnet::datalink::{DataLinkReceiver, NetworkInterface};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use crate::{
|
||||
network::{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use ::ratatui::backend::Backend;
|
||||
use ::ratatui::buffer::Cell;
|
||||
use ::ratatui::layout::Rect;
|
||||
use ::std::collections::HashMap;
|
||||
use ::std::io;
|
||||
use ::std::sync::{Arc, Mutex};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use ratatui::{backend::Backend, buffer::Cell, layout::Rect};
|
||||
|
||||
#[derive(Hash, Debug, PartialEq)]
|
||||
pub enum TerminalEvent {
|
||||
|
||||
Reference in New Issue
Block a user