Skip to content

Commit

Permalink
feat: implement dublin and paris approach for UDP (#158 - WIP #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Aug 19, 2022
1 parent a787152 commit 9b363cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::BTreeMap;
use std::io;
use std::net::IpAddr;
use std::time::{Duration, SystemTime};
use trippy::tracing::{PortDirection, TracerAddrFamily};
use trippy::tracing::{PortDirection, TracerProtocol};
use tui::layout::{Alignment, Direction, Rect};
use tui::symbols::Marker;
use tui::text::{Span, Spans};
Expand Down Expand Up @@ -465,9 +465,14 @@ fn render_header<B: Backend>(f: &mut Frame<'_, B>, app: &mut TuiApp, rect: Rect)
.style(Style::default())
.block(header_block.clone())
.alignment(Alignment::Right);
let protocol = match &app.tracer_config().addr_family {
TracerAddrFamily::Ipv4 => format!("{}(v4)", app.tracer_config().protocol),
TracerAddrFamily::Ipv6 => format!("{}(v6)", app.tracer_config().protocol),
let protocol = match app.tracer_config().protocol {
TracerProtocol::Icmp => format!("icmp({})", app.tracer_config().addr_family),
TracerProtocol::Udp => format!(
"udp({}, {})",
app.tracer_config().addr_family,
app.tracer_config().multipath_strategy,
),
TracerProtocol::Tcp => format!("tcp({})", app.tracer_config().addr_family),
};
let dns = format_dns_method(app.resolver.config().resolve_method);
let as_info = match app.resolver.config().resolve_method {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use std::sync::Arc;
use std::thread;
use std::time::Duration;
use trippy::tracing::{
PortDirection, TracerAddrFamily, TracerChannel, TracerChannelConfig, TracerConfig,
TracerProtocol,
MultipathStrategy, PortDirection, TracerAddrFamily, TracerChannel, TracerChannelConfig,
TracerConfig, TracerProtocol,
};

mod backend;
Expand Down Expand Up @@ -191,6 +191,7 @@ fn make_trace_info(
source_addr,
target,
target_addr,
args.multipath_strategy,
args.port_direction,
args.protocol,
args.addr_family,
Expand Down Expand Up @@ -220,6 +221,7 @@ pub struct TraceInfo {
pub source_addr: IpAddr,
pub target_hostname: String,
pub target_addr: IpAddr,
pub multipath_strategy: MultipathStrategy,
pub port_direction: PortDirection,
pub protocol: TracerProtocol,
pub addr_family: TracerAddrFamily,
Expand All @@ -237,6 +239,7 @@ impl TraceInfo {
source_addr: IpAddr,
target_hostname: String,
target_addr: IpAddr,
multipath_strategy: MultipathStrategy,
port_direction: PortDirection,
protocol: TracerProtocol,
addr_family: TracerAddrFamily,
Expand All @@ -250,6 +253,7 @@ impl TraceInfo {
source_addr,
target_hostname,
target_addr,
multipath_strategy,
port_direction,
protocol,
addr_family,
Expand Down
19 changes: 19 additions & 0 deletions src/tracing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub enum TracerAddrFamily {
Ipv6,
}

impl Display for TracerAddrFamily {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Ipv4 => write!(f, "v4"),
Self::Ipv6 => write!(f, "v6"),
}
}
}

/// The tracing protocol.
#[derive(Debug, Copy, Clone)]
pub enum TracerProtocol {
Expand Down Expand Up @@ -76,6 +85,16 @@ pub enum MultipathStrategy {
Dublin,
}

impl Display for MultipathStrategy {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Classic => write!(f, "classic"),
Self::Paris => write!(f, "paris"),
Self::Dublin => write!(f, "dublin"),
}
}
}

/// Whether to fix the src, dest or both ports for a trace.
#[derive(Debug, Copy, Clone)]
pub enum PortDirection {
Expand Down

0 comments on commit 9b363cd

Please sign in to comment.