Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor crates #640

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 3 additions & 78 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,87 +1,12 @@
[package]
name = "trippy"
[workspace.package]
version = "0.9.0-dev"
authors = ["FujiApple <fujiapple852@gmail.com>"]
description = "A network diagnostic tool"
documentation = "https://github.com/fujiapple852/trippy"
homepage = "https://github.com/fujiapple852/trippy"
repository = "https://github.com/fujiapple852/trippy"
keywords = ["cli", "tui", "traceroute", "ping", "icmp"]
categories = ["command-line-utilities", "network-programming"]
readme = "README.md"
license = "Apache-2.0"
edition = "2021"
exclude = ["assets/"]

[[bin]]
bench = false
path = "src/main.rs"
name = "trip"

[dependencies]

# Library dependencies
thiserror = "1.0.44"
derive_more = "0.99.17"
arrayvec = "0.7.4"
socket2 = { version = "0.5.2", features = [ "all" ] }
tracing = "0.1.37"

# TUI dependencies
anyhow = "1.0.72"
dns-lookup = "2.0.1"
trust-dns-resolver = "0.22.0"
crossbeam = "0.8.2"
clap = { version = "4.3.21", features = [ "derive", "wrap_help", "cargo" ] }
clap_complete = "4.3.2"
humantime = "2.1.0"
parking_lot = "0.12.1"
ratatui = "0.22.0"
crossterm = "0.27.0"
chrono = { version = "0.4.26", default-features = false, features = [ "clock" ] }
itertools = "0.11.0"
serde = { version = "1.0.168", features = [ "derive" ] }
serde_json = "1.0.104"
comfy-table = "7.0.1"
strum = { version = "0.25.0", features = [ "derive" ] }
etcetera = "0.8.0"
toml = "0.7.6"
indexmap = "2.0.0"
maxminddb = "0.23.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
tracing-chrome = "0.7.1"

# Library dependencies (Linux)
[target.'cfg(target_os = "linux")'.dependencies]
caps = "0.5.5"

# Library dependencies (Unix)
[target.'cfg(unix)'.dependencies]
nix = { version = "0.26.2", default-features = false, features = [ "user", "poll", "net" ] }

# Library dependencies (Windows)
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48.0"
features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_System_IO",
"Win32_System_Threading",
]

[target.'cfg(windows)'.dependencies]
widestring = "1.0.2"
paste = "1.0.14"

[dev-dependencies]
rand = "0.8.5"
test-case = "3.1.0"

# cargo-generate-rpm dependencies
[package.metadata.generate-rpm]
assets = [
{ source = "target/release/trip", dest = "/usr/bin/trip", mode = "755" },
]
[workspace]
members = ["trippy", "trippy-core"]
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ RUN rustup target add x86_64-unknown-linux-musl
WORKDIR /app
COPY Cargo.toml /app
COPY Cargo.lock /app
RUN mkdir /app/src
RUN echo "fn main() {}" > /app/src/main.rs
RUN mkdir -p /app/trippy/src
RUN mkdir -p /app/trippy-core/src
COPY trippy/Cargo.toml /app/trippy/Cargo.toml
COPY trippy-core/Cargo.toml /app/trippy-core/Cargo.toml
RUN echo "fn main() {}" > /app/trippy/src/main.rs
RUN touch /app/trippy-core/src/lib.rs
RUN cargo build --release --target=x86_64-unknown-linux-musl
COPY src /app/src
COPY trippy/src /app/trippy/src
COPY trippy-core/src /app/trippy-core/src
COPY README.md /app
COPY LICENSE /app
RUN cargo build --release --target=x86_64-unknown-linux-musl
Expand Down
12 changes: 0 additions & 12 deletions src/lib.rs

This file was deleted.

43 changes: 43 additions & 0 deletions trippy-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "trippy-core"
description = "A network tracing library"
version.workspace = true
authors.workspace = true
documentation.workspace = true
homepage.workspace = true
repository.workspace = true
keywords = ["traceroute", "ping", "icmp"]
categories = ["network-programming"]
readme.workspace = true
license.workspace = true
edition.workspace = true

[dependencies]
thiserror = "1.0.44"
derive_more = "0.99.17"
arrayvec = "0.7.4"
socket2 = { version = "0.5.2", features = [ "all" ] }
tracing = "0.1.37"
itertools = "0.11.0"

[target.'cfg(unix)'.dependencies]
nix = { version = "0.26.2", default-features = false, features = [ "user", "poll", "net" ] }

[target.'cfg(windows)'.dependencies]
widestring = "1.0.2"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48.0"
features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_System_IO",
"Win32_System_Threading",
]

[dev-dependencies]
rand = "0.8.5"
test-case = "3.1.0"
6 changes: 3 additions & 3 deletions src/tracing/config.rs → trippy-core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::tracing::constants::{MAX_SEQUENCE, MAX_TTL};
use crate::tracing::error::{TraceResult, TracerError};
use crate::tracing::types::{
use crate::constants::{MAX_SEQUENCE, MAX_TTL};
use crate::error::{TraceResult, TracerError};
use crate::types::{
MaxInflight, MaxRounds, PacketSize, PayloadPattern, Port, Sequence, TimeToLive, TraceId,
TypeOfService,
};
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/tracing/error.rs → trippy-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::tracing::util::RequiredError;
use crate::util::RequiredError;
use std::fmt::{Display, Formatter};
use std::io;
use std::io::ErrorKind;
Expand Down
15 changes: 12 additions & 3 deletions src/tracing.rs → trippy-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#![doc = include_str!("../../README.md")]
#![warn(clippy::all, clippy::pedantic, clippy::nursery, rust_2018_idioms)]
#![allow(
clippy::module_name_repetitions,
clippy::option_if_let_else,
clippy::missing_const_for_fn,
clippy::cast_possible_truncation,
clippy::missing_errors_doc
)]
#![deny(unsafe_code)]

mod config;
mod constants;
mod error;
Expand All @@ -7,14 +18,12 @@ mod tracer;
mod types;
mod util;

/// Packet wire formats.
pub mod packet;

pub use config::{
MultipathStrategy, PortDirection, TracerAddrFamily, TracerChannelConfig, TracerConfig,
TracerProtocol,
};
pub use net::channel::TracerChannel;
pub use net::packet;
pub use net::source::SourceAddr;
pub use probe::{IcmpPacketType, Probe, ProbeStatus};
pub use tracer::{Tracer, TracerRound};
9 changes: 6 additions & 3 deletions src/tracing/net.rs → trippy-core/src/net.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::tracing::error::TraceResult;
use crate::tracing::probe::ProbeResponse;
use crate::tracing::Probe;
use crate::error::TraceResult;
use crate::probe::ProbeResponse;
use crate::Probe;

/// IPv4 implementation.
mod ipv4;
Expand All @@ -20,6 +20,9 @@ pub mod channel;
/// Determine the source address.
pub mod source;

/// Packet wire formats.
pub mod packet;

/// An abstraction over a network interface for tracing.
pub trait Network {
/// Send a `Probe`.
Expand Down
14 changes: 7 additions & 7 deletions src/tracing/net/channel.rs → trippy-core/src/net/channel.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::tracing::error::{TraceResult, TracerError};
use crate::tracing::net::platform::Socket;
use crate::tracing::net::socket::TracerSocket as _;
use crate::tracing::net::{ipv4, ipv6, platform, Network};
use crate::tracing::probe::ProbeResponse;
use crate::tracing::types::{PacketSize, PayloadPattern, Sequence, TypeOfService};
use crate::tracing::{MultipathStrategy, Probe, TracerChannelConfig, TracerProtocol};
use crate::error::{TraceResult, TracerError};
use crate::net::platform::Socket;
use crate::net::socket::TracerSocket as _;
use crate::net::{ipv4, ipv6, platform, Network};
use crate::probe::ProbeResponse;
use crate::types::{PacketSize, PayloadPattern, Sequence, TypeOfService};
use crate::{MultipathStrategy, Probe, TracerChannelConfig, TracerProtocol};
use arrayvec::ArrayVec;
use itertools::Itertools;
use std::net::IpAddr;
Expand Down
40 changes: 20 additions & 20 deletions src/tracing/net/ipv4.rs → trippy-core/src/net/ipv4.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use crate::tracing::error::TracerError::AddressNotAvailable;
use crate::tracing::error::{IoResult, TraceResult, TracerError};
use crate::tracing::net::channel::MAX_PACKET_SIZE;
use crate::tracing::net::platform;
use crate::tracing::net::platform::Socket;
use crate::tracing::net::socket::TracerSocket as _;
use crate::tracing::packet::checksum::{icmp_ipv4_checksum, udp_ipv4_checksum};
use crate::tracing::packet::icmpv4::destination_unreachable::DestinationUnreachablePacket;
use crate::tracing::packet::icmpv4::echo_reply::EchoReplyPacket;
use crate::tracing::packet::icmpv4::echo_request::EchoRequestPacket;
use crate::tracing::packet::icmpv4::time_exceeded::TimeExceededPacket;
use crate::tracing::packet::icmpv4::{IcmpCode, IcmpPacket, IcmpType};
use crate::tracing::packet::ipv4::Ipv4Packet;
use crate::tracing::packet::tcp::TcpPacket;
use crate::tracing::packet::udp::UdpPacket;
use crate::tracing::packet::IpProtocol;
use crate::tracing::probe::{
use crate::error::TracerError::AddressNotAvailable;
use crate::error::{IoResult, TraceResult, TracerError};
use crate::net::channel::MAX_PACKET_SIZE;
use crate::net::packet::checksum::{icmp_ipv4_checksum, udp_ipv4_checksum};
use crate::net::packet::icmpv4::destination_unreachable::DestinationUnreachablePacket;
use crate::net::packet::icmpv4::echo_reply::EchoReplyPacket;
use crate::net::packet::icmpv4::echo_request::EchoRequestPacket;
use crate::net::packet::icmpv4::time_exceeded::TimeExceededPacket;
use crate::net::packet::icmpv4::{IcmpCode, IcmpPacket, IcmpType};
use crate::net::packet::ipv4::Ipv4Packet;
use crate::net::packet::tcp::TcpPacket;
use crate::net::packet::udp::UdpPacket;
use crate::net::packet::IpProtocol;
use crate::net::platform;
use crate::net::platform::Socket;
use crate::net::socket::TracerSocket as _;
use crate::probe::{
ProbeResponse, ProbeResponseData, ProbeResponseSeq, ProbeResponseSeqIcmp, ProbeResponseSeqTcp,
ProbeResponseSeqUdp,
};
use crate::tracing::types::{PacketSize, PayloadPattern, Sequence, TraceId, TypeOfService};
use crate::tracing::util::Required;
use crate::tracing::{MultipathStrategy, Probe, TracerProtocol};
use crate::types::{PacketSize, PayloadPattern, Sequence, TraceId, TypeOfService};
use crate::util::Required;
use crate::{MultipathStrategy, Probe, TracerProtocol};
use std::io::ErrorKind;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::time::SystemTime;
Expand Down
38 changes: 19 additions & 19 deletions src/tracing/net/ipv6.rs → trippy-core/src/net/ipv6.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use crate::tracing::error::TracerError::AddressNotAvailable;
use crate::tracing::error::{IoResult, TraceResult, TracerError};
use crate::tracing::net::channel::MAX_PACKET_SIZE;
use crate::tracing::net::platform;
use crate::tracing::net::platform::Socket;
use crate::tracing::net::socket::TracerSocket as _;
use crate::tracing::packet::checksum::{icmp_ipv6_checksum, udp_ipv6_checksum};
use crate::tracing::packet::icmpv6::destination_unreachable::DestinationUnreachablePacket;
use crate::tracing::packet::icmpv6::echo_reply::EchoReplyPacket;
use crate::tracing::packet::icmpv6::echo_request::EchoRequestPacket;
use crate::tracing::packet::icmpv6::time_exceeded::TimeExceededPacket;
use crate::tracing::packet::icmpv6::{IcmpCode, IcmpPacket, IcmpType};
use crate::tracing::packet::ipv6::Ipv6Packet;
use crate::tracing::packet::tcp::TcpPacket;
use crate::tracing::packet::udp::UdpPacket;
use crate::tracing::probe::{
use crate::error::TracerError::AddressNotAvailable;
use crate::error::{IoResult, TraceResult, TracerError};
use crate::net::channel::MAX_PACKET_SIZE;
use crate::net::packet::checksum::{icmp_ipv6_checksum, udp_ipv6_checksum};
use crate::net::packet::icmpv6::destination_unreachable::DestinationUnreachablePacket;
use crate::net::packet::icmpv6::echo_reply::EchoReplyPacket;
use crate::net::packet::icmpv6::echo_request::EchoRequestPacket;
use crate::net::packet::icmpv6::time_exceeded::TimeExceededPacket;
use crate::net::packet::icmpv6::{IcmpCode, IcmpPacket, IcmpType};
use crate::net::packet::ipv6::Ipv6Packet;
use crate::net::packet::tcp::TcpPacket;
use crate::net::packet::udp::UdpPacket;
use crate::net::platform;
use crate::net::platform::Socket;
use crate::net::socket::TracerSocket as _;
use crate::probe::{
ProbeResponse, ProbeResponseData, ProbeResponseSeq, ProbeResponseSeqIcmp, ProbeResponseSeqTcp,
ProbeResponseSeqUdp,
};
use crate::tracing::types::{PacketSize, PayloadPattern, Sequence, TraceId};
use crate::tracing::util::Required;
use crate::tracing::{Probe, TracerProtocol};
use crate::types::{PacketSize, PayloadPattern, Sequence, TraceId};
use crate::util::Required;
use crate::{Probe, TracerProtocol};
use std::io::ErrorKind;
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
use std::time::SystemTime;
Expand Down
File renamed without changes.
File renamed without changes.
Loading