Commit fad3e24
authored
refactor(iroh-net): portmapper and network monitor are crates (#2855)
## Description
The non-controversial part of the big network-utils refactor as
described in the title.
## Breaking Changes
<details><summary>Full <code>cargo public-api</code> diff
report</summary>
```
Removed items from the public API
=================================
-pub struct iroh_net::metrics::PortmapMetrics
-pub iroh_net::metrics::PortmapMetrics::external_address_updated: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::local_port_updates: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::mapping_attempts: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::mapping_failures: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::pcp_available: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::pcp_probes: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::probes_started: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::upnp_available: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::upnp_gateway_updated: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::upnp_probes: iroh_metrics::core::Counter
-pub iroh_net::metrics::PortmapMetrics::upnp_probes_failed: iroh_metrics::core::Counter
-impl core::default::Default for iroh_net::metrics::PortmapMetrics
-impl core::default::Default for iroh_net::metrics::PortmapMetrics
-pub fn iroh_net::metrics::PortmapMetrics::default() -> Self
-pub fn iroh_net::metrics::PortmapMetrics::default() -> Self
-impl iroh_metrics::core::Metric for iroh_net::metrics::PortmapMetrics
-impl iroh_metrics::core::Metric for iroh_net::metrics::PortmapMetrics
-pub fn iroh_net::metrics::PortmapMetrics::name() -> &'static str
-pub fn iroh_net::metrics::PortmapMetrics::name() -> &'static str
-impl struct_iterable_internal::Iterable for iroh_net::metrics::PortmapMetrics
-impl struct_iterable_internal::Iterable for iroh_net::metrics::PortmapMetrics
-pub fn iroh_net::metrics::PortmapMetrics::iter<'a>(&'a self) -> alloc::vec::into_iter::IntoIter<(&'static str, &'a dyn core::any::Any)>
-pub fn iroh_net::metrics::PortmapMetrics::iter<'a>(&'a self) -> alloc::vec::into_iter::IntoIter<(&'static str, &'a dyn core::any::Any)>
-pub mod iroh_net::net
-pub mod iroh_net::net::ip
-pub struct iroh_net::net::ip::LocalAddresses
-pub iroh_net::net::ip::LocalAddresses::loopback: alloc::vec::Vec<core::net::ip_addr::IpAddr>
-pub iroh_net::net::ip::LocalAddresses::regular: alloc::vec::Vec<core::net::ip_addr::IpAddr>
-impl iroh_net::net::ip::LocalAddresses
-pub fn iroh_net::net::ip::LocalAddresses::new() -> Self
-impl core::default::Default for iroh_net::net::ip::LocalAddresses
-pub fn iroh_net::net::ip::LocalAddresses::default() -> Self
-pub const fn iroh_net::net::ip::is_unicast_link_local(addr: core::net::ip_addr::Ipv6Addr) -> bool
-pub mod iroh_net::net::netmon
-pub struct iroh_net::net::netmon::CallbackToken(_)
-pub struct iroh_net::net::netmon::Monitor
-impl iroh_net::net::netmon::Monitor
-pub async fn iroh_net::net::netmon::Monitor::network_change(&self) -> anyhow::Result<()>
-pub async fn iroh_net::net::netmon::Monitor::new() -> anyhow::Result<Self>
-pub async fn iroh_net::net::netmon::Monitor::subscribe<F>(&self, callback: F) -> anyhow::Result<iroh_net::net::netmon::CallbackToken> where F: core::ops::function::Fn(bool) -> futures_lite::future::Boxed<()> + 'static + core::marker::Sync + core::marker::Send
-pub async fn iroh_net::net::netmon::Monitor::unsubscribe(&self, token: iroh_net::net::netmon::CallbackToken) -> anyhow::Result<()>
-impl core::ops::drop::Drop for iroh_net::net::netmon::Monitor
-pub fn iroh_net::net::netmon::Monitor::drop(&mut self)
-pub enum iroh_net::net::IpFamily
-pub iroh_net::net::IpFamily::V4
-pub iroh_net::net::IpFamily::V6
-impl iroh_net::net::IpFamily
-pub fn iroh_net::net::IpFamily::local_addr(&self) -> core::net::ip_addr::IpAddr
-pub fn iroh_net::net::IpFamily::unspecified_addr(&self) -> core::net::ip_addr::IpAddr
-impl core::convert::From<core::net::ip_addr::IpAddr> for iroh_net::net::IpFamily
-pub fn iroh_net::net::IpFamily::from(value: core::net::ip_addr::IpAddr) -> Self
-impl core::convert::From<iroh_net::net::IpFamily> for socket2::Domain
-pub fn socket2::Domain::from(value: iroh_net::net::IpFamily) -> Self
-pub struct iroh_net::net::UdpSocket(_)
-impl iroh_net::net::UdpSocket
-pub fn iroh_net::net::UdpSocket::bind(network: iroh_net::net::IpFamily, port: u16) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_full(addr: impl core::convert::Into<core::net::socket_addr::SocketAddr>) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_local(network: iroh_net::net::IpFamily, port: u16) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_local_v4(port: u16) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_local_v6(port: u16) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_v4(port: u16) -> anyhow::Result<Self>
-pub fn iroh_net::net::UdpSocket::bind_v6(port: u16) -> anyhow::Result<Self>
-impl core::convert::From<tokio::net::udp::UdpSocket> for iroh_net::net::UdpSocket
-pub fn iroh_net::net::UdpSocket::from(socket: tokio::net::udp::UdpSocket) -> Self
-impl core::ops::deref::Deref for iroh_net::net::UdpSocket
-pub type iroh_net::net::UdpSocket::Target = tokio::net::udp::UdpSocket
-pub fn iroh_net::net::UdpSocket::deref(&self) -> &Self::Target
-impl core::ops::drop::Drop for iroh_net::net::UdpSocket
-pub fn iroh_net::net::UdpSocket::drop(&mut self)
-impl std::os::fd::owned::AsFd for iroh_net::net::UdpSocket
-pub fn iroh_net::net::UdpSocket::as_fd(&self) -> std::os::fd::owned::BorrowedFd<'_>
-pub mod iroh_net::portmapper
-pub struct iroh_net::portmapper::Client
-impl iroh_net::portmapper::Client
-pub fn iroh_net::portmapper::Client::deactivate(&self)
-pub fn iroh_net::portmapper::Client::new(config: iroh_net::portmapper::Config) -> Self
-pub fn iroh_net::portmapper::Client::probe(&self) -> tokio::sync::oneshot::Receiver<anyhow::Result<iroh_net::portmapper::ProbeOutput, alloc::string::String>>
-pub fn iroh_net::portmapper::Client::procure_mapping(&self)
-pub fn iroh_net::portmapper::Client::update_local_port(&self, local_port: core::num::nonzero::NonZeroU16)
-pub fn iroh_net::portmapper::Client::watch_external_address(&self) -> tokio::sync::watch::Receiver<core::option::Option<core::net::socket_addr::SocketAddrV4>>
-impl core::default::Default for iroh_net::portmapper::Client
-pub fn iroh_net::portmapper::Client::default() -> Self
-pub struct iroh_net::portmapper::Config
-pub iroh_net::portmapper::Config::enable_nat_pmp: bool
-pub iroh_net::portmapper::Config::enable_pcp: bool
-pub iroh_net::portmapper::Config::enable_upnp: bool
-impl core::default::Default for iroh_net::portmapper::Config
-pub fn iroh_net::portmapper::Config::default() -> Self
-pub struct iroh_net::portmapper::Metrics
-pub iroh_net::portmapper::Metrics::external_address_updated: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::local_port_updates: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::mapping_attempts: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::mapping_failures: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::pcp_available: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::pcp_probes: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::probes_started: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::upnp_available: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::upnp_gateway_updated: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::upnp_probes: iroh_metrics::core::Counter
-pub iroh_net::portmapper::Metrics::upnp_probes_failed: iroh_metrics::core::Counter
-pub struct iroh_net::portmapper::ProbeOutput
-pub iroh_net::portmapper::ProbeOutput::nat_pmp: bool
-pub iroh_net::portmapper::ProbeOutput::pcp: bool
-pub iroh_net::portmapper::ProbeOutput::upnp: bool
-impl iroh_net::portmapper::ProbeOutput
-pub fn iroh_net::portmapper::ProbeOutput::all_available(&self) -> bool
-pub struct iroh_net::portmapper::Service
Changed items in the public API
===============================
-pub async fn iroh_net::netcheck::Client::get_report(&mut self, dm: iroh_net::relay::RelayMap, stun_conn4: core::option::Option<alloc::sync::Arc<iroh_net::net::UdpSocket>>, stun_conn6: core::option::Option<alloc::sync::Arc<iroh_net::net::UdpSocket>>) -> anyhow::Result<alloc::sync::Arc<iroh_net::netcheck::Report>>
+pub async fn iroh_net::netcheck::Client::get_report(&mut self, dm: iroh_net::relay::RelayMap, stun_conn4: core::option::Option<alloc::sync::Arc<netwatch::udp::UdpSocket>>, stun_conn6: core::option::Option<alloc::sync::Arc<netwatch::udp::UdpSocket>>) -> anyhow::Result<alloc::sync::Arc<iroh_net::netcheck::Report>>
-pub async fn iroh_net::netcheck::Client::get_report_channel(&mut self, dm: iroh_net::relay::RelayMap, stun_conn4: core::option::Option<alloc::sync::Arc<iroh_net::net::UdpSocket>>, stun_conn6: core::option::Option<alloc::sync::Arc<iroh_net::net::UdpSocket>>) -> anyhow::Result<tokio::sync::oneshot::Receiver<anyhow::Result<alloc::sync::Arc<iroh_net::netcheck::Report>>>>
+pub async fn iroh_net::netcheck::Client::get_report_channel(&mut self, dm: iroh_net::relay::RelayMap, stun_conn4: core::option::Option<alloc::sync::Arc<netwatch::udp::UdpSocket>>, stun_conn6: core::option::Option<alloc::sync::Arc<netwatch::udp::UdpSocket>>) -> anyhow::Result<tokio::sync::oneshot::Receiver<anyhow::Result<alloc::sync::Arc<iroh_net::netcheck::Report>>>>
-pub fn iroh_net::netcheck::Client::new(port_mapper: core::option::Option<iroh_net::portmapper::Client>, dns_resolver: iroh_net::dns::DnsResolver) -> anyhow::Result<Self>
+pub fn iroh_net::netcheck::Client::new(port_mapper: core::option::Option<portmapper::Client>, dns_resolver: hickory_resolver::async_resolver::TokioAsyncResolver) -> anyhow::Result<Self>
-pub iroh_net::netcheck::Report::portmap_probe: core::option::Option<iroh_net::portmapper::ProbeOutput>
+pub iroh_net::netcheck::Report::portmap_probe: core::option::Option<portmapper::ProbeOutput>
Added items to the public API
=============================
+pub use iroh_net::metrics::PortmapMetrics
```
</details>
- `iroh_net::net` is removed. The unchanged functionality can be found
in the published crate `netwatch` which the `n0 team` will keep
maintaining. This has been moved to allow serving a more general public.
- `iroh_net::portmapper` is removed. The unchanged functionality can be
found in the published crate `portmapper` which the `n0 team` will keep
maintaining. This has been moved to allow serving a more general public.
- The origin of `iroh_net::metrics::PortmapMetrics` is changed. The type
is no longer internal to `iroh-net` but re-exported from `portmapper`
- Some `netcheck` functions now require `netwatcher` and `portmapper`
parameters that are _not_ currently re-exported. `netcheck` will be
moved to it's own crate as well so this intermediate state is acceptable
for the time being
## Notes & open questions
- **what used to be called net**
has a very small API that might not be as useful to the general public.
It only gives a `subscribe` to changes that only reports if the change
"is major" without any description of what being major is or the origin
of the change. Providing a more detailed API and better docs is
something we can do later, but it's worth noticing.
- **portmapper**
might be good to start doing the move to `thiserror` here since it's
very clearly isolated. Maybe turn on/off as features specific protocols.
All this, again, to make it more attractive/useful to a wider audience.
- there is `netwatcher`, which I found by looking for what I thought was
a natural name to this (`netwatch`) and it has the API I'd imagine this
crate should provide. https://crates.io/crates/netwatcher
## Change checklist
- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.1 parent fe684c2 commit fad3e24
File tree
54 files changed
+301
-76
lines changed- .github/workflows
- iroh-cli
- src/commands
- iroh-net
- src
- magicsock
- node_map
- netcheck
- reportgen
- net-tools
- netwatch
- src
- interfaces
- bsd
- netmon
- portmapper
- src
- nat_pmp
- protocol
- pcp
- protocol
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
54 files changed
+301
-76
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | | - | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | 165 | | |
172 | 166 | | |
173 | 167 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 168 | | |
178 | 169 | | |
179 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | 244 | | |
246 | 245 | | |
247 | | - | |
248 | 246 | | |
249 | 247 | | |
250 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
0 commit comments