Skip to content

feat(iroh-base, iroh-net-report)!: intro net-report as a crate #2921

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

Merged
merged 31 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
349b259
start the exodusssss
divagant-martian Nov 13, 2024
b4a4df6
move ping in
divagant-martian Nov 13, 2024
3e278dd
temporarily do gross 'use crate::self as netcheck'
divagant-martian Nov 13, 2024
2eee98c
start dealing with dns, again
divagant-martian Nov 14, 2024
829b51a
move relay map and node to base; fix dns stuff
divagant-martian Nov 16, 2024
385b3c6
use netcheck as a crate
divagant-martian Nov 16, 2024
82f8079
fix warns
divagant-martian Nov 16, 2024
9baf0f5
fmt
divagant-martian Nov 16, 2024
c6ed4d9
reduce deps, supposedly
divagant-martian Nov 16, 2024
4efedc8
fix iroh-base relay feature deps
divagant-martian Nov 19, 2024
9f6fbb9
reduce lockfile diff
divagant-martian Nov 19, 2024
9833490
start self-review
divagant-martian Nov 19, 2024
71f2231
fix doc warnings
divagant-martian Nov 19, 2024
0c28d73
fix toml even if it works
divagant-martian Nov 19, 2024
fd023a8
add README.md
divagant-martian Nov 20, 2024
bd4f566
add toml keys
divagant-martian Nov 20, 2024
b11212c
netcheck is 28vo
divagant-martian Nov 20, 2024
92c05bb
add crate to ci with new name
divagant-martian Nov 20, 2024
984f13b
mass renaming to net-report
divagant-martian Nov 20, 2024
b81463b
include net_check on renaming
divagant-martian Nov 20, 2024
61bcc38
finish renaming
divagant-martian Nov 20, 2024
0ea084b
Merge remote-tracking branch 'n0/main' into move-netcheck-out
divagant-martian Nov 20, 2024
8017587
make fmt
divagant-martian Nov 20, 2024
5d34415
address TODO missed before
divagant-martian Nov 20, 2024
0ae2f48
revert a change, double down in another
divagant-martian Nov 20, 2024
1700c40
Merge remote-tracking branch 'n0/main' into move-netcheck-out
divagant-martian Nov 20, 2024
38eecd5
add license files
divagant-martian Nov 20, 2024
a9520a8
NetReport
divagant-martian Nov 20, 2024
6f24fa7
Merge remote-tracking branch 'n0/main' into move-netcheck-out
divagant-martian Nov 20, 2024
be83843
rename const
divagant-martian Nov 21, 2024
edde29d
Merge branch 'main' into move-netcheck-out
divagant-martian Nov 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
# uses: obi1kenobi/cargo-semver-checks-action@v2
uses: n0-computer/cargo-semver-checks-action@feat-baseline
with:
package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay
package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay, iroh-net-report
baseline-rev: ${{ env.HEAD_COMMIT_SHA }}
use-cache: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
RUSTFLAGS: -Dwarnings
RUSTDOCFLAGS: -Dwarnings
SCCACHE_CACHE_SIZE: "50G"
CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay"
CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay,iroh-net-report"
IROH_FORCE_STAGING_RELAYS: "1"

jobs:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
"iroh-router",
"net-tools/netwatch",
"net-tools/portmapper",
"iroh-netcheck",
"iroh-net-report",
]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ iroh-blobs = { version = "0.28.1", features = ["cli"] }
iroh-docs = { version = "0.28.0", features = ["cli"] }
iroh-gossip = { version = "0.28.1", features = ["cli"] }
iroh-metrics = { version = "0.28.0" }
netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.28" }
net-report = { package = "iroh-net-report", path = "../iroh-net-report", version = "0.28" }
parking_lot = "0.12.1"
pkarr = { version = "2.2.0", default-features = false }
portable-atomic = "1"
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async fn report(
) -> anyhow::Result<()> {
let port_mapper = portmapper::Client::default();
let dns_resolver = default_resolver().clone();
let mut client = netcheck::Client::new(Some(port_mapper), dns_resolver)?;
let mut client = net_report::Client::new(Some(port_mapper), dns_resolver)?;

let dm = match stun_host {
Some(host_name) => {
Expand Down
2 changes: 1 addition & 1 deletion iroh-netcheck/Cargo.toml → iroh-net-report/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "iroh-netcheck"
name = "iroh-net-report"
version = "0.28.0"
edition = "2021"
readme = "README.md"
Expand Down
6 changes: 3 additions & 3 deletions iroh-netcheck/README.md → iroh-net-report/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Iroh Netcheck
# Iroh Net Report

`iroh-netcheck` is a tool for generating detailed reports on network
`iroh-net-report` is a tool for generating detailed reports on network
connectivity and configuration on the current host for nodes powered by [iroh].
`iroh-netcheck` evaluates key aspects of network performance and behavior,
`iroh-net-report` evaluates key aspects of network performance and behavior,
including NAT traversal capabilities, protocol availability, and relay server
latencies. Key features include:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Default values used in netcheck.
//! Default values used in net_report.

/// The default STUN port used by the Relay server.
///
/// The STUN port as defined by [RFC 8489](<https://www.rfc-editor.org/rfc/rfc8489#section-18.6>)
pub const DEFAULT_STUN_PORT: u16 = 3478;

/// Contains all timeouts that we use in `iroh-netcheck`.
/// Contains all timeouts that we use in `iroh-net_report`.
pub(crate) mod timeouts {
use std::time::Duration;

// Timeouts for netcheck
// Timeouts for net_report

/// The maximum amount of time netcheck will spend gathering a single report.
/// The maximum amount of time net_report will spend gathering a single report.
pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5);

/// The total time we wait for all the probes.
Expand Down
File renamed without changes.
44 changes: 22 additions & 22 deletions iroh-netcheck/src/lib.rs → iroh-net-report/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Netcheck is responsible for finding out the network conditions of the current host, like
//! whether it is connected to the internet via IPv4 and/or IPv6, what the NAT situation is
//! etc and reachability to the configured relays.
// Based on <https://github.com/tailscale/tailscale/blob/main/net/netcheck/netcheck.go>
// Based on <https://github.com/tailscale/tailscale/blob/main/net/net_report/net_report.go>

use std::{
collections::{BTreeMap, HashMap},
Expand Down Expand Up @@ -48,7 +48,7 @@ const FULL_REPORT_INTERVAL: Duration = Duration::from_secs(5 * 60);
/// default which will never be used.
const DEFAULT_MAX_LATENCY: Duration = Duration::from_millis(100);

/// A netcheck report.
/// A net_report report.
///
/// Can be obtained by calling [`Client::get_report`].
#[derive(Default, Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -159,15 +159,15 @@ impl RelayLatencies {
}
}

/// Client to run netchecks.
/// Client to run net_reports.
///
/// Creating this creates a netcheck actor which runs in the background. Most of the time
/// Creating this creates a net_report actor which runs in the background. Most of the time
/// it is idle unless [`Client::get_report`] is called, which is the main interface.
///
/// The [`Client`] struct can be cloned and results multiple handles to the running actor.
/// If all [`Client`]s are dropped the actor stops running.
///
/// While running the netcheck actor expects to be passed all received stun packets using
/// While running the net_report actor expects to be passed all received stun packets using
/// `Addr::receive_stun_packet`.
#[derive(Debug)]
pub struct Client {
Expand Down Expand Up @@ -204,15 +204,15 @@ impl Default for Reports {
}

impl Client {
/// Creates a new netcheck client.
/// Creates a new net_report client.
///
/// This starts a connected actor in the background. Once the client is dropped it will
/// stop running.
pub fn new(port_mapper: Option<portmapper::Client>, dns_resolver: DnsResolver) -> Result<Self> {
let mut actor = Actor::new(port_mapper, dns_resolver)?;
let addr = actor.addr();
let task =
tokio::spawn(async move { actor.run().await }.instrument(info_span!("netcheck.actor")));
tokio::spawn(async move { actor.run().await }.instrument(info_span!("net_report.actor")));
let drop_guard = AbortOnDropHandle::new(task);
Ok(Client {
addr,
Expand All @@ -228,7 +228,7 @@ impl Client {
self.addr.clone()
}

/// Runs a netcheck, returning the report.
/// Runs a net_report, returning the report.
///
/// It may not be called concurrently with itself, `&mut self` takes care of that.
///
Expand Down Expand Up @@ -289,9 +289,9 @@ pub(crate) struct Inflight {
/// Messages to send to the [`Actor`].
#[derive(Debug)]
pub(crate) enum Message {
/// Run a netcheck.
/// Run a net_report.
///
/// Only one netcheck can be run at a time, trying to run multiple concurrently will
/// Only one net_report can be run at a time, trying to run multiple concurrently will
/// fail.
RunCheck {
/// The relay configuration.
Expand Down Expand Up @@ -339,15 +339,15 @@ pub struct Addr {
}

impl Addr {
/// Pass a received STUN packet to the netchecker.
/// Pass a received STUN packet to the net_reporter.
///
/// Normally the UDP sockets to send STUN messages from are passed in so that STUN
/// packets are sent from the sockets that carry the real traffic. However because
/// these sockets carry real traffic they will also receive non-STUN traffic, thus the
/// netcheck actor does not read from the sockets directly. If you receive a STUN
/// net_report actor does not read from the sockets directly. If you receive a STUN
/// packet on the socket you should pass it to this method.
///
/// It is safe to call this even when the netcheck actor does not currently have any
/// It is safe to call this even when the net_report actor does not currently have any
/// in-flight STUN probes. The actor will simply ignore any stray STUN packets.
///
/// There is an implicit queue here which may drop packets if the actor does not keep up
Expand All @@ -365,12 +365,12 @@ impl Addr {

async fn send(&self, msg: Message) -> Result<(), mpsc::error::SendError<Message>> {
self.sender.send(msg).await.inspect_err(|_| {
error!("netcheck actor lost");
error!("net_report actor lost");
})
}
}

/// The netcheck actor.
/// The net_report actor.
///
/// This actor runs for the entire duration there's a [`Client`] connected.
#[derive(Debug)]
Expand Down Expand Up @@ -439,7 +439,7 @@ impl Actor {
/// It will now run and handle messages. Once the connected [`Client`] (including all
/// its clones) is dropped this will terminate.
async fn run(&mut self) {
debug!("netcheck actor starting");
debug!("net_report actor starting");
while let Some(msg) = self.receiver.recv().await {
trace!(?msg, "handling message");
match msg {
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Actor {
|| now.duration_since(self.reports.last_full) > FULL_REPORT_INTERVAL;

// If the last report had a captive portal and reported no UDP access,
// it's possible that we didn't get a useful netcheck due to the
// it's possible that we didn't get a useful net_report due to the
// captive portal blocking us. If so, make this report a full (non-incremental) one.
if !do_full {
if let Some(ref last) = self.reports.last {
Expand Down Expand Up @@ -694,12 +694,12 @@ impl Actor {
}
}

/// State the netcheck actor needs for an in-progress report generation.
/// State the net_report actor needs for an in-progress report generation.
#[derive(Debug)]
struct ReportRun {
/// The handle of the [`reportgen`] actor, cancels the actor on drop.
_reportgen: reportgen::Client,
/// Drop guard to optionally kill workers started by netcheck to support reportgen.
/// Drop guard to optionally kill workers started by net_report to support reportgen.
_drop_guard: tokio_util::sync::DropGuard,
/// Where to send the completed report.
report_tx: oneshot::Sender<Result<Arc<Report>>>,
Expand Down Expand Up @@ -1251,9 +1251,9 @@ mod tests {

// Set up an external socket to send STUN requests from, this will be discovered as
// our public socket address by STUN. We send back any packets received on this
// socket to the netcheck client using Client::receive_stun_packet. Once we sent
// socket to the net_report client using Client::receive_stun_packet. Once we sent
// the hairpin STUN request (from a different randomly bound socket) we are sending
// it to this socket, which is forwarnding it back to our netcheck client, because
// it to this socket, which is forwarnding it back to our net_report client, because
// this dumb implementation just forwards anything even if it would be garbage.
// Thus hairpinning detection will declare hairpinning to work.
let sock = UdpSocket::bind_local(IpFamily::V4, 0)?;
Expand All @@ -1270,7 +1270,7 @@ mod tests {
info!(
addr=?sock.local_addr().unwrap(),
%count,
"Forwarding payload to netcheck client",
"Forwarding payload to net_report client",
);
let payload = buf.split_to(count).freeze();
addr.receive_stun_packet(payload, src);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl Default for Metrics {
stun_packets_sent_ipv6: Counter::new("Number of IPv6 STUN packets sent"),
stun_packets_recv_ipv4: Counter::new("Number of IPv4 STUN packets received"),
stun_packets_recv_ipv6: Counter::new("Number of IPv6 STUN packets received"),
reports: Counter::new("Number of reports executed by netcheck, including full reports"),
reports_full: Counter::new("Number of full reports executed by netcheck"),
reports: Counter::new("Number of reports executed by net_report, including full reports"),
reports_full: Counter::new("Number of full reports executed by net_report"),
}
}
}

impl Metric for Metrics {
fn name() -> &'static str {
"netcheck"
"net_report"
}
}
4 changes: 2 additions & 2 deletions iroh-netcheck/src/ping.rs → iroh-net-report/src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Pinger {
let ident = PingIdentifier(rand::random());
debug!(%addr, %ident, "Creating pinger");
let mut pinger = client.pinger(addr, ident).await;
pinger.timeout(DEFAULT_TIMEOUT); // todo: timeout too large for netcheck
pinger.timeout(DEFAULT_TIMEOUT); // todo: timeout too large for net_report
match pinger.ping(PingSequence(0), data).await? {
(IcmpPacket::V4(packet), dur) => {
debug!(
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
Ok(())
}

// See netcheck::reportgen::tests::test_icmp_probe_eu_relay for permissions to ping.
// See net_report::reportgen::tests::test_icmp_probe_eu_relay for permissions to ping.
#[tokio::test]
async fn test_ping_localhost() {
let _guard = iroh_test::logging::setup();
Expand Down
Loading