Skip to content

Commit

Permalink
refactor: move tracing library into separate trippy-core crate
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Aug 13, 2023
1 parent 648a8d6 commit 32b22f2
Show file tree
Hide file tree
Showing 66 changed files with 274 additions and 227 deletions.
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
11 changes: 11 additions & 0 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 Down
6 changes: 3 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 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::platform;
use crate::net::platform::Socket;
use crate::net::socket::TracerSocket as _;
use crate::packet::checksum::{icmp_ipv4_checksum, udp_ipv4_checksum};
use crate::packet::icmpv4::destination_unreachable::DestinationUnreachablePacket;
use crate::packet::icmpv4::echo_reply::EchoReplyPacket;
use crate::packet::icmpv4::echo_request::EchoRequestPacket;
use crate::packet::icmpv4::time_exceeded::TimeExceededPacket;
use crate::packet::icmpv4::{IcmpCode, IcmpPacket, IcmpType};
use crate::packet::ipv4::Ipv4Packet;
use crate::packet::tcp::TcpPacket;
use crate::packet::udp::UdpPacket;
use crate::packet::IpProtocol;
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::platform;
use crate::net::platform::Socket;
use crate::net::socket::TracerSocket as _;
use crate::packet::checksum::{icmp_ipv6_checksum, udp_ipv6_checksum};
use crate::packet::icmpv6::destination_unreachable::DestinationUnreachablePacket;
use crate::packet::icmpv6::echo_reply::EchoReplyPacket;
use crate::packet::icmpv6::echo_request::EchoRequestPacket;
use crate::packet::icmpv6::time_exceeded::TimeExceededPacket;
use crate::packet::icmpv6::{IcmpCode, IcmpPacket, IcmpType};
use crate::packet::ipv6::Ipv6Packet;
use crate::packet::tcp::TcpPacket;
use crate::packet::udp::UdpPacket;
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::tracing::error::TraceResult;
use crate::tracing::net::platform::for_address;
use crate::error::TraceResult;
use crate::net::platform::for_address;
use std::net::IpAddr;

/// The byte order to encode the `total_length`, `flags` and `fragment_offset` fields of the IPv4 header.
Expand Down
File renamed without changes.
Loading

0 comments on commit 32b22f2

Please sign in to comment.