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

refactor(iroh-net): portmapper and network monitor are crates #2855

Merged
merged 34 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59457b2
add net member
divagant-martian Oct 24, 2024
4704124
move net files
divagant-martian Oct 24, 2024
38ba7a3
adjust net files
divagant-martian Oct 24, 2024
1cb8a7c
check unused deps in the crate
divagant-martian Oct 24, 2024
887041e
add net as a dep
divagant-martian Oct 24, 2024
2f572e6
adjust visibilities to use
divagant-martian Oct 24, 2024
befdb35
remove unused deps from iroh-net
divagant-martian Oct 24, 2024
69a5f8f
add portmapper as a member
divagant-martian Oct 24, 2024
543fb41
move portmapper files
divagant-martian Oct 24, 2024
d2a6616
adjust files to new structure
divagant-martian Oct 25, 2024
2dda79c
remove portmapping defaults
divagant-martian Oct 25, 2024
7bda3d0
use portmapper directly
divagant-martian Oct 25, 2024
378a72a
remove Some unused deps
divagant-martian Oct 25, 2024
df52737
Merge remote-tracking branch 'n0/main' into netmon-split
divagant-martian Oct 25, 2024
6cbae77
fmt
divagant-martian Oct 25, 2024
fbe28a7
fix net imports
divagant-martian Oct 25, 2024
f2ffed7
add windows deps in net
divagant-martian Oct 25, 2024
9f83aa7
use portmapper and net directly everywhere
divagant-martian Oct 25, 2024
2feeac8
re-add re-exports
divagant-martian Oct 25, 2024
8a1574d
remove dependency on dns alias
divagant-martian Oct 25, 2024
25aaa60
fmt
divagant-martian Oct 25, 2024
15dbac9
remove redundant import
divagant-martian Oct 25, 2024
ea0bad0
add some love to toml file
divagant-martian Oct 28, 2024
dfd457e
Merge branch 'main' into netmon-split-v2
divagant-martian Oct 28, 2024
d61a282
leave it at netwatch with udp
divagant-martian Oct 29, 2024
9b22efe
include in ci
divagant-martian Oct 29, 2024
eb7d3f8
add time to tokio in netwatch
divagant-martian Oct 29, 2024
36c1a87
Merge branch 'main' into netmon-split-v2
divagant-martian Oct 29, 2024
5131a5f
merge and sort imports
divagant-martian Oct 29, 2024
5e1e3e1
add Lincense, Contribution, improve description
divagant-martian Oct 29, 2024
e9959e5
cleanup docs
divagant-martian Oct 29, 2024
682c18d
Merge branch 'main' into netmon-split-v2
divagant-martian Oct 29, 2024
a64f8bc
remove readded reexports rerere as agreed with @dignifiedquire and @flub
divagant-martian Oct 29, 2024
0d04c36
fix missed test
divagant-martian Oct 29, 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
62 changes: 61 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ members = [
"iroh-net/bench",
"iroh-cli",
"iroh-router",
"net-tools/net",
"net-tools/portmapper",
]
resolver = "2"

Expand Down
1 change: 1 addition & 0 deletions iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ iroh-metrics = { version = "0.27.0" }
parking_lot = "0.12.1"
pkarr = { version = "2.2.0", default-features = false }
portable-atomic = "1"
portmapper = { version = "0.1.0", path = "../net-tools/portmapper" }
postcard = "1.0.8"
quic-rpc = { version = "0.12", features = ["flume-transport", "quinn-transport"] }
rand = "0.8.5"
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 @@ -37,7 +37,7 @@ use iroh::{
endpoint::{self, Connection, ConnectionTypeStream, RecvStream, RemoteInfo, SendStream},
key::{PublicKey, SecretKey},
metrics::MagicsockMetrics,
netcheck, portmapper,
netcheck,
relay::{RelayMap, RelayMode, RelayUrl},
ticket::NodeTicket,
Endpoint, NodeAddr, NodeId,
Expand Down
3 changes: 2 additions & 1 deletion iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ webpki = { package = "rustls-webpki", version = "0.102" }
webpki-roots = "0.26"
x509-parser = "0.16"
z32 = "1.0.3"
portmapper = { path = "../net-tools/portmapper" }

# iroh-relay
axum = { version = "0.7.4", optional = true }
Expand All @@ -94,6 +95,7 @@ swarm-discovery = { version = "0.2.1", optional = true }

# dht_discovery
genawaiter = { version = "0.99.1", features = ["futures03"], optional = true }
net = { version = "0.1.0", path = "../net-tools/net" }

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
netlink-packet-core = "0.7.0"
Expand All @@ -114,7 +116,6 @@ ntest = "0.9"
pretty_assertions = "1.4"
proptest = "1.2.0"
rand_chacha = "0.3.1"
testdir = "0.9.1"
tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs", "macros", "time", "test-util"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
iroh-test = "0.27.0"
Expand Down
9 changes: 0 additions & 9 deletions iroh-net/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,9 @@ pub(crate) mod timeouts {
/// The amount of time we wait for a hairpinned packet to come back.
pub(crate) const HAIRPIN_CHECK_TIMEOUT: Duration = Duration::from_millis(100);

/// Maximum duration a UPnP search can take before timing out.
pub(crate) const UPNP_SEARCH_TIMEOUT: Duration = Duration::from_secs(1);

/// Timeout to receive a response from a PCP server.
pub(crate) const PCP_RECV_TIMEOUT: Duration = Duration::from_millis(500);

/// Default Pinger timeout
pub(crate) const DEFAULT_PINGER_TIMEOUT: Duration = Duration::from_secs(5);

/// Timeout to receive a response from a NAT-PMP server.
pub(crate) const NAT_PMP_RECV_TIMEOUT: Duration = Duration::from_millis(500);

/// Timeouts specifically used in the iroh-relay
pub(crate) mod relay {
use super::*;
Expand Down
6 changes: 4 additions & 2 deletions iroh-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ pub mod dns;
pub mod endpoint;
mod magicsock;
pub mod metrics;
pub mod net;
pub mod netcheck;
pub mod ping;
pub mod portmapper;
pub mod relay;
pub mod stun;
pub mod ticket;
Expand All @@ -253,6 +251,10 @@ pub(crate) mod util;

pub use endpoint::{AddrInfo, Endpoint, NodeAddr};
pub use iroh_base::{key, key::NodeId};
// TODO(@divma): re-evaluate this re-export
pub use net;
// TODO(@divma): re-evaluate this re-export
divagant-martian marked this conversation as resolved.
Show resolved Hide resolved
pub use portmapper;

#[cfg(any(test, feature = "test-utils"))]
#[cfg_attr(iroh_docsrs, doc(cfg(any(test, feature = "test-utils"))))]
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use futures_lite::{FutureExt, Stream, StreamExt};
use futures_util::stream::BoxStream;
use iroh_base::key::NodeId;
use iroh_metrics::{inc, inc_by};
use net::{interfaces, ip::LocalAddresses, netmon};
use quinn::AsyncUdpSocket;
use rand::{seq::SliceRandom, Rng, SeedableRng};
use smallvec::{smallvec, SmallVec};
Expand Down Expand Up @@ -64,8 +65,7 @@ use crate::{
dns::DnsResolver,
endpoint::NodeAddr,
key::{PublicKey, SecretKey, SharedSecret},
net::{interfaces, ip::LocalAddresses, netmon},
netcheck, portmapper,
netcheck,
relay::{RelayMap, RelayUrl},
stun, AddrInfo,
};
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/magicsock/node_map/node_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use iroh_metrics::inc;
use net::ip::is_unicast_link_local;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc;
use tracing::{debug, event, info, instrument, trace, warn, Level};
Expand All @@ -22,7 +23,6 @@ use crate::{
endpoint::AddrInfo,
key::PublicKey,
magicsock::{ActorMessage, MagicsockMetrics, QuicMappedAddr, Timer, HEARTBEAT_INTERVAL},
net::ip::is_unicast_link_local,
relay::RelayUrl,
stun,
util::relay_only_mode,
Expand Down
3 changes: 1 addition & 2 deletions iroh-net/src/magicsock/udp_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use std::{
};

use anyhow::{bail, Context as _};
use net::UdpSocket;
use quinn::AsyncUdpSocket;
use quinn_udp::{Transmit, UdpSockRef};
use tokio::io::Interest;
use tracing::{debug, trace};

use crate::net::UdpSocket;

/// A UDP socket implementing Quinn's [`AsyncUdpSocket`].
#[derive(Clone, Debug)]
pub struct UdpConn {
Expand Down
7 changes: 3 additions & 4 deletions iroh-net/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Co-locating all of the iroh-net metrics structs
pub use portmapper::Metrics as PortmapMetrics;

#[cfg(feature = "iroh-relay")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
pub use crate::relay::server::Metrics as RelayMetrics;
pub use crate::{
magicsock::Metrics as MagicsockMetrics, netcheck::Metrics as NetcheckMetrics,
portmapper::Metrics as PortmapMetrics,
};
pub use crate::{magicsock::Metrics as MagicsockMetrics, netcheck::Metrics as NetcheckMetrics};
10 changes: 4 additions & 6 deletions iroh-net/src/netcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ use std::{

use anyhow::{anyhow, Context as _, Result};
use bytes::Bytes;
use hickory_resolver::TokioAsyncResolver as DnsResolver;
use iroh_metrics::inc;
use net::{IpFamily, UdpSocket};
use tokio::{
sync::{self, mpsc, oneshot},
time::{Duration, Instant},
};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
use tracing::{debug, error, info_span, trace, warn, Instrument};

use super::{portmapper, relay::RelayMap, stun};
use crate::{
dns::DnsResolver,
net::{IpFamily, UdpSocket},
relay::RelayUrl,
};
use super::{relay::RelayMap, stun};
use crate::relay::RelayUrl;

mod metrics;
mod reportgen;
Expand Down
3 changes: 1 addition & 2 deletions iroh-net/src/netcheck/reportgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::{

use anyhow::{anyhow, bail, Context, Result};
use iroh_metrics::inc;
use net::{interfaces, UdpSocket};
use rand::seq::IteratorRandom;
use tokio::{
sync::{mpsc, oneshot},
Expand All @@ -39,10 +40,8 @@ use super::NetcheckMetrics;
use crate::{
defaults::DEFAULT_STUN_PORT,
dns::{DnsResolver, ResolverExt},
net::{interfaces, UdpSocket},
netcheck::{self, Report},
ping::{PingError, Pinger},
portmapper,
relay::{RelayMap, RelayNode, RelayUrl},
stun,
util::MaybeFuture,
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/netcheck/reportgen/hairpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use anyhow::{bail, Context, Result};
use net::UdpSocket;
use tokio::{sync::oneshot, time::Instant};
use tokio_util::task::AbortOnDropHandle;
use tracing::{debug, error, info_span, trace, warn, Instrument};

use crate::{
defaults::timeouts::HAIRPIN_CHECK_TIMEOUT,
net::UdpSocket,
netcheck::{self, reportgen, Inflight},
stun,
};
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/netcheck/reportgen/probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use std::{collections::BTreeSet, fmt, sync::Arc};

use anyhow::{ensure, Result};
use net::interfaces;
use tokio::time::Duration;

use crate::{
net::interfaces,
netcheck::Report,
relay::{RelayMap, RelayNode, RelayUrl},
};
Expand Down
43 changes: 43 additions & 0 deletions net-tools/net/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "net"
divagant-martian marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
edition = "2021"

[lints]
workspace = true

[dependencies]
anyhow = { version = "1" }
bytes = "1.7"
futures-lite = "2.3"
futures-sink = "0.3.25"
futures-util = "0.3.25"
libc = "0.2.139"
netdev = "0.30.0"
once_cell = "1.18.0"
socket2 = "0.5.3"
thiserror = "1"
time = "0.3.20"
tokio = { version = "1", features = ["io-util", "macros", "sync", "rt", "net", "fs", "io-std", "signal", "process"] }
tracing = "0.1"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
netlink-packet-core = "0.7.0"
netlink-packet-route = "0.17.0"
netlink-sys = "0.8.5"
rtnetlink = "0.13.0"

[target.'cfg(target_os = "windows")'.dependencies]
wmi = "0.13"
windows = { version = "0.51", features = ["Win32_NetworkManagement_IpHelper", "Win32_Foundation", "Win32_NetworkManagement_Ndis", "Win32_Networking_WinSock"] }
serde = { version = "1", features = ["derive"] }
derive_more = { version = "1.0.0", features = ["debug"] }

[dev-dependencies]
tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs", "macros", "time", "test-util"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
iroh-test = "0.27.0"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "iroh_docsrs"]
Loading
Loading