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

feat(iroh-net): Upnp port mapping #1117

Merged
merged 72 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
65d3500
add igd
divagant-martian Jun 12, 2023
6781552
add log, use types for readability
divagant-martian Jun 12, 2023
7cd2bb5
request mapping
divagant-martian Jun 13, 2023
2a29bd9
fix code placement + comments
divagant-martian Jun 13, 2023
428f6a8
filling in the gaps
divagant-martian Jun 15, 2023
99234ff
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 20, 2023
4a8865c
some cleanup and refactor
divagant-martian Jun 20, 2023
49d972d
debugging
divagant-martian Jun 21, 2023
a2288be
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 21, 2023
73ec440
debug cleanning
divagant-martian Jun 21, 2023
ea88b84
merge cleanup
divagant-martian Jun 21, 2023
a7394cf
easy doctor appointment
divagant-martian Jun 22, 2023
fb7f67f
debug cleanning
divagant-martian Jun 22, 2023
4d2b14b
use non zero to ensure port to map is positive
divagant-martian Jun 22, 2023
80fd159
spelling
divagant-martian Jun 22, 2023
32d5a0c
follow iroh code style
divagant-martian Jun 22, 2023
dd75325
log when probe fails
divagant-martian Jun 22, 2023
fea7ad3
update comment
divagant-martian Jun 22, 2023
6c97baf
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 22, 2023
850750a
more logs, use localhost
divagant-martian Jun 22, 2023
c5763be
add portmap metrics to iroh-metrics
divagant-martian Jun 22, 2023
271e801
use portmap metrics
divagant-martian Jun 22, 2023
ebb2d44
Merge branch 'main' into ducktor-portmap
divagant-martian Jun 26, 2023
246aa95
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 27, 2023
bb80d3e
Merge branch 'ducktor-portmap' into upnp-port-mapping
divagant-martian Jun 27, 2023
e0aca33
add client
divagant-martian Jun 27, 2023
80cb5e7
wip: closing for the day
divagant-martian Jun 27, 2023
0553f1a
wip
divagant-martian Jun 28, 2023
cc6a25a
more wip
divagant-martian Jun 28, 2023
319b181
connecting stuff
divagant-martian Jun 28, 2023
f5773a2
coding with the heart lol
divagant-martian Jun 29, 2023
2b5c7d8
fixes
divagant-martian Jun 29, 2023
d03dc38
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 29, 2023
420f1d3
customize timeout of portmapping doctor command
divagant-martian Jun 29, 2023
f15d75d
on_change for portmap
divagant-martian Jun 29, 2023
6d810ae
Merge branch 'main' into upnp-port-mapping
divagant-martian Jun 30, 2023
0e00c36
improve docs and logs
divagant-martian Jun 30, 2023
e66c17e
add mapping struct that handles maintenance
divagant-martian Jun 30, 2023
8319461
add waker
divagant-martian Jun 30, 2023
569dce4
improve debug logs
divagant-martian Jun 30, 2023
ed791f3
connect with mapping thing
divagant-martian Jun 30, 2023
11afc1e
partially connect current mapping stream
divagant-martian Jul 1, 2023
c5adebe
simplify mapping handling and add a sanity test
divagant-martian Jul 1, 2023
8aefb16
remove hardcoded mapping half life
divagant-martian Jul 1, 2023
264696b
remove unused field
divagant-martian Jul 1, 2023
2c76313
ensure external port is non zero
divagant-martian Jul 1, 2023
8915efd
simplify test types, reduce test timeout
divagant-martian Jul 1, 2023
ebd2f13
add external addr fn to mapping
divagant-martian Jul 2, 2023
aa51001
rework getting a new upnp mapping to reuse a known gateway and or kno…
divagant-martian Jul 2, 2023
e3b4aa9
connect expiry and renew events
divagant-martian Jul 2, 2023
15cf441
Merge branch 'main' into upnp-port-mapping
divagant-martian Jul 2, 2023
94aadcc
split client functions
divagant-martian Jul 2, 2023
33fc428
update doctor command
divagant-martian Jul 2, 2023
d5bc663
add service channel capacity
divagant-martian Jul 2, 2023
15af49a
remove unnecesary change
divagant-martian Jul 2, 2023
eaf5ede
leverage derive_more and the utils mod
divagant-martian Jul 2, 2023
f558246
remove yet one more unnecesary clone
divagant-martian Jul 2, 2023
dbe5322
Revert "remove yet one more unnecesary clone" might be controversial …
divagant-martian Jul 2, 2023
c80e0ab
misc spelling
divagant-martian Jul 2, 2023
d7b399c
misc docs
divagant-martian Jul 2, 2023
101712c
cleanup
divagant-martian Jul 2, 2023
3f41e00
more cleanup
divagant-martian Jul 2, 2023
86da496
simplify logic updating a probe
divagant-martian Jul 2, 2023
1840ebd
appease clippy
divagant-martian Jul 2, 2023
d93488f
expand comment
divagant-martian Jul 2, 2023
1905717
expand metrics
divagant-martian Jul 2, 2023
63a93a7
self review
divagant-martian Jul 3, 2023
552e1c7
improve doctor docs
divagant-martian Jul 3, 2023
0846437
unflatten portmap probe
divagant-martian Jul 3, 2023
da57bcf
Merge branch 'main' into upnp-port-mapping
divagant-martian Jul 3, 2023
5e9d6f7
get interfaces
divagant-martian Jul 3, 2023
f1ae1fc
get interfaces using dep already here
divagant-martian Jul 3, 2023
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
98 changes: 98 additions & 0 deletions Cargo.lock

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

12 changes: 11 additions & 1 deletion iroh-metrics/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use once_cell::sync::Lazy;
use prometheus_client::{encoding::text::encode, registry::Registry};

use crate::{iroh, magicsock, netcheck};
use crate::{iroh, magicsock, netcheck, portmap};

pub static CORE: Lazy<Core> = Lazy::new(Core::default);

Expand All @@ -14,6 +14,7 @@ pub struct Core {
iroh_metrics: iroh::Metrics,
magicsock_metrics: magicsock::Metrics,
netcheck_metrics: netcheck::Metrics,
portmap_metrics: portmap::Metrics,
}

impl Default for Core {
Expand All @@ -24,6 +25,7 @@ impl Default for Core {
iroh_metrics: iroh::Metrics::new(&mut reg),
magicsock_metrics: magicsock::Metrics::new(&mut reg),
netcheck_metrics: netcheck::Metrics::new(&mut reg),
portmap_metrics: portmap::Metrics::new(&mut reg),
registry: reg,
}
}
Expand All @@ -46,6 +48,10 @@ impl Core {
&self.netcheck_metrics
}

pub fn portmap_metrics(&self) -> &portmap::Metrics {
&self.portmap_metrics
}

pub(crate) fn encode(&self) -> Result<String, std::fmt::Error> {
let mut buf = String::new();
encode(&mut buf, self.registry())?;
Expand Down Expand Up @@ -122,6 +128,7 @@ where
Collector::Iroh => CORE.iroh_metrics().record(m, v),
Collector::Magicsock => CORE.magicsock_metrics().record(m, v),
Collector::Netcheck => CORE.netcheck_metrics().record(m, v),
Collector::Portmap => CORE.portmap_metrics().record(m, v),
};
}
}
Expand All @@ -140,6 +147,7 @@ where
Collector::Iroh => CORE.iroh_metrics().observe(m, v),
Collector::Magicsock => CORE.magicsock_metrics().observe(m, v),
Collector::Netcheck => CORE.netcheck_metrics().observe(m, v),
Collector::Portmap => CORE.portmap_metrics().observe(m, v),
};
}
}
Expand All @@ -154,4 +162,6 @@ pub enum Collector {
Magicsock,
/// Netcheck related metrics.
Netcheck,
/// Portmap related metrics.
Portmap,
}
1 change: 1 addition & 0 deletions iroh-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ mod service;
pub mod iroh;
pub mod magicsock;
pub mod netcheck;
pub mod portmap;
21 changes: 21 additions & 0 deletions iroh-metrics/src/portmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
super::make_metric_recorders! {
Portmap,

/*
* General port mapping metrics
*/
ProbesStarted: Counter: "Number of probing tasks started.",
LocalPortUpdates: Counter: "Number of updates to the local port.",
MappingAttempts: Counter: "Number of mapping tasks started.",
MappingFailures: Counter: "Number of failed mapping tasks",
ExternalAddressUpdated: Counter: "Number of times the external address obtained via port mapping was updated.",

/*
* UPnP metrics
*/
UpnpProbes: Counter: "Number of UPnP probes executed.",
UpnpProbesFailed: Counter: "Number of failed Upnp probes",
UpnpAvailable: Counter: "Number of UPnP probes that found it available.",
UpnpGatewayUpdated: Counter: "Number of UPnP probes that resulted in a gateway different to the previous one.",

}
5 changes: 4 additions & 1 deletion iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ curve25519-dalek = "=4.0.0-rc.3"
default-net = "0.15"
data-encoding = "2.3.3"
der = { version = "0.7", features = ["alloc", "derive"] }
derive_more = { version = "0.99.17", git = "https://github.com/JelteF/derive_more", features = ["debug", "display", "from", "try_into"] }
derive_more = { version = "0.99.17", git = "https://github.com/JelteF/derive_more", features = ["debug", "display", "from", "try_into", "deref"] }
ed25519-dalek = { version = "=2.0.0-rc.3", features = ["serde", "rand_core"] }
flume = "0.10.14"
futures = "0.3.25"
Expand All @@ -29,6 +29,7 @@ hostname = "0.3.1"
http = "0.2.9"
hyper = { version = "0.14.25", features = ["server", "client", "http1", "tcp"] }
governor = "0.5.1"
igd = { version = "0.12.1", features = ["aio"] }
libc = "0.2.139"
once_cell = "1.17.0"
os_info = "3.6.0"
Expand All @@ -52,6 +53,7 @@ tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs"] }
tokio-util = { version = "0.7", features = ["io-util", "io"] }
tokio-rustls = { version = "0.24" }
tokio-rustls-acme = { version = "0.1" }
tokio-stream = { version = "0.1", features = ["sync"]}
url = { version = "2.4", features = ["serde"] }
webpki = { version = "0.22", features = ["std"] }
webpki-roots = "0.23.0"
Expand Down Expand Up @@ -83,6 +85,7 @@ wmi = "0.13"
clap = { version = "4", features = ["derive"] }
tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs", "macros", "time", "test-util"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
ntest = "*"

[build-dependencies]
duct = "0.13.6"
Expand Down
16 changes: 4 additions & 12 deletions iroh-net/src/hp/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
};

use super::key;
use super::{key, portmapper};

/// Fake WireGuard endpoint IP address that means to
/// use DERP. When used (in the Node.DERP field), the port number of
Expand Down Expand Up @@ -68,14 +68,8 @@ pub struct NetInfo {
/// Whether we have an existing portmap open (UPnP, PMP, or PCP).
pub have_port_map: bool,

/// Whether UPnP appears present on the LAN. Empty means not checked.
pub upnp: Option<bool>,

/// Whether NAT-PMP appears present on the LAN. Empty means not checked.
pub pmp: Option<bool>,

/// Whether PCP appears present on the LAN. Empty means not checked.
pub pcp: Option<bool>,
/// Probe indicating the presence of port mapping protocols on the LAN.
pub portmap_probe: Option<portmapper::ProbeOutput>,

/// This node's preferred DERP server for incoming traffic. The node might be be temporarily
/// connected to multiple DERP servers (to send to other nodes)
Expand Down Expand Up @@ -104,9 +98,7 @@ impl NetInfo {
&& self.working_udp == other.working_udp
&& self.working_icm_pv4 == other.working_icm_pv4
&& self.have_port_map == other.have_port_map
&& self.upnp == other.upnp
&& self.pmp == other.pmp
&& self.pcp == other.pcp
&& self.portmap_probe == other.portmap_probe
&& self.preferred_derp == other.preferred_derp
&& self.link_type == other.link_type
}
Expand Down
Loading