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 29 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
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
package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper
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"
CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper"
IROH_FORCE_STAGING_RELAYS: "1"

jobs:
Expand Down
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/netwatch",
"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
9 changes: 5 additions & 4 deletions iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ workspace = true

[dependencies]
anyhow = { version = "1" }
base64 = "0.22.1"
backoff = "0.4.0"
base64 = "0.22.1"
bytes = "1.7"
netdev = "0.30.0"
der = { version = "0.7", features = ["alloc", "derive"] }
derive_more = { version = "1.0.0", features = ["debug", "display", "from", "try_into", "deref"] }
futures-buffered = "0.2.8"
Expand All @@ -40,11 +39,14 @@ hyper-util = "0.1.1"
igd-next = { version = "0.15.1", features = ["aio_tokio"] }
iroh-base = { version = "0.27.0", features = ["key"] }
libc = "0.2.139"
netdev = "0.30.0"
netwatch = { version = "0.1.0", path = "../net-tools/netwatch" }
num_enum = "0.7"
once_cell = "1.18.0"
parking_lot = "0.12.1"
pin-project = "1"
pkarr = { version = "2", default-features = false, features = ["async", "relay"] }
portmapper = { path = "../net-tools/portmapper" }
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
quinn = { package = "iroh-quinn", version = "0.11" }
quinn-proto = { package = "iroh-quinn-proto", version = "0.11" }
Expand All @@ -63,10 +65,10 @@ thiserror = "1"
time = "0.3.20"
tokio = { version = "1", features = ["io-util", "macros", "sync", "rt", "net", "fs", "io-std", "signal", "process"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "ring"] }
tokio-stream = { version = "0.1.15" }
tokio-tungstenite = "0.21"
tokio-tungstenite-wasm = "0.3"
tokio-util = { version = "0.7.12", features = ["io-util", "io", "codec", "rt"] }
tokio-stream = { version = "0.1.15" }
tracing = "0.1"
tungstenite = "0.21"
url = { version = "2.4", features = ["serde"] }
Expand Down Expand Up @@ -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 netwatch as 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 netwatch::{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 netwatch::ip::is_unicast_link_local;
divagant-martian marked this conversation as resolved.
Show resolved Hide resolved
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 netwatch::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 netwatch::{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 netwatch::{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 netwatch::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 netwatch::interfaces;
use tokio::time::Duration;

use crate::{
net::interfaces,
netcheck::Report,
relay::{RelayMap, RelayNode, RelayUrl},
};
Expand Down
Loading
Loading