Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
RUST_BACKTRACE: 1
RUSTFLAGS: -Dwarnings
RUSTDOCFLAGS: -Dwarnings
MSRV: "1.85"
MSRV: "1.89"
SCCACHE_CACHE_SIZE: "10G"
IROH_FORCE_STAGING_RELAYS: "1"

Expand Down
50 changes: 25 additions & 25 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions netwatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["networking", "interfaces"]
edition = "2024"

# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.85"
rust-version = "1.89"

[lints]
workspace = true
Expand All @@ -34,7 +34,7 @@ tracing = "0.1"

# non-browser dependencies
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
quinn-udp = { package = "iroh-quinn-udp", version = "0.7" }
quinn-udp = { package = "iroh-quinn-udp", version = "0.8" }
libc = "0.2.139"
netdev = "0.40.0"
socket2 = { version = "0.6", features = ["all"] }
Expand Down
8 changes: 4 additions & 4 deletions netwatch/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ impl fmt::Display for State {
ifaces.sort_by_key(|iface| iface.iface.index);
for iface in ifaces {
write!(f, "{iface}")?;
if let Some(ref default_if) = self.default_route_interface {
if iface.name() == default_if {
write!(f, " (default)")?;
}
if let Some(ref default_if) = self.default_route_interface
&& iface.name() == default_if
{
write!(f, " (default)")?;
}
if f.alternate() {
writeln!(f)?;
Expand Down
22 changes: 10 additions & 12 deletions netwatch/src/netmon/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,21 @@ pub(super) fn is_interesting_message(msg: &WireMessage) -> bool {
WireMessage::InterfaceMulticastAddr(_) => true,
WireMessage::Interface(_) => false,
WireMessage::InterfaceAddr(msg) => {
if let Some(addr) = msg.addrs.get(RTAX_IFP as usize) {
if let Some(name) = addr.name() {
if !is_interesting_interface(name) {
return false;
}
}
if let Some(addr) = msg.addrs.get(RTAX_IFP as usize)
&& let Some(name) = addr.name()
&& !is_interesting_interface(name)
{
return false;
}
true
}
WireMessage::Route(msg) => {
// Ignore local unicast
if let Some(addr) = msg.addrs.get(RTAX_DST as usize) {
if let Some(ip) = addr.ip() {
if is_link_local(ip) {
return false;
}
}
if let Some(addr) = msg.addrs.get(RTAX_DST as usize)
&& let Some(ip) = addr.ip()
&& is_link_local(ip)
{
return false;
}

true
Expand Down
20 changes: 10 additions & 10 deletions netwatch/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,16 @@ impl SocketState {

impl Drop for UdpSocket {
fn drop(&mut self) {
if let Some((socket, _)) = self.socket.write().unwrap().close() {
if let Ok(handle) = tokio::runtime::Handle::try_current() {
// No wakeup after dropping write lock here, since we're getting dropped.
// this will be empty if `close` was called before
let std_sock = socket.into_std();
handle.spawn_blocking(move || {
// Calls libc::close, which can block
drop(std_sock);
});
}
if let Some((socket, _)) = self.socket.write().unwrap().close()
&& let Ok(handle) = tokio::runtime::Handle::try_current()
{
// No wakeup after dropping write lock here, since we're getting dropped.
// this will be empty if `close` was called before
let std_sock = socket.into_std();
handle.spawn_blocking(move || {
// Calls libc::close, which can block
drop(std_sock);
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion portmapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/n0-computer/net-tools"
keywords = ["portmapping", "pmp", "pcp", "upnp"]

# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.85"
rust-version = "1.89"

[lints]
workspace = true
Expand Down
41 changes: 20 additions & 21 deletions portmapper/src/current_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,27 @@ impl<M: Mapping> CurrentMapping<M> {
deadline,
expire_after,
}) = &mut self.mapping
&& deadline.as_mut().poll(cx).is_ready()
{
if deadline.as_mut().poll(cx).is_ready() {
let (external_ip, external_port) = mapping.external();
// check if the deadline means the mapping is expired or due for renewal
return if *expire_after {
trace!("mapping expired {mapping:?}");
self.update(None);
Poll::Ready(Event::Expired {
external_ip,
external_port,
})
} else {
// mapping is due for renewal
*deadline = Box::pin(time::sleep(mapping.half_lifetime()));
*expire_after = true;
trace!("due for renewal {mapping:?}");
Poll::Ready(Event::Renew {
external_ip,
external_port,
})
};
}
let (external_ip, external_port) = mapping.external();
// check if the deadline means the mapping is expired or due for renewal
return if *expire_after {
trace!("mapping expired {mapping:?}");
self.update(None);
Poll::Ready(Event::Expired {
external_ip,
external_port,
})
} else {
// mapping is due for renewal
*deadline = Box::pin(time::sleep(mapping.half_lifetime()));
*expire_after = true;
trace!("due for renewal {mapping:?}");
Poll::Ready(Event::Renew {
external_ip,
external_port,
})
};
}
Poll::Pending
}
Expand Down
8 changes: 4 additions & 4 deletions portmapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ impl Service {

/// Clears the current mapping and releases it.
async fn invalidate_mapping(&mut self) {
if let Some(old_mapping) = self.current_mapping.update(None) {
if let Err(e) = old_mapping.release().await {
debug!("failed to release mapping {e}");
}
if let Some(old_mapping) = self.current_mapping.update(None)
&& let Err(e) = old_mapping.release().await
{
debug!("failed to release mapping {e}");
}
}

Expand Down
19 changes: 9 additions & 10 deletions portmapper/src/upnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl Mapping {

// if we are trying to get a specific external port, try this first. If this fails, default
// to try to get any port
if let Some(external_port) = preferred_port {
if gateway
if let Some(external_port) = preferred_port
&& gateway
.add_port(
protocol,
external_port.into(),
Expand All @@ -108,14 +108,13 @@ impl Mapping {
)
.await
.is_ok()
{
return Ok(Mapping {
protocol,
gateway,
external_ip,
external_port,
});
}
{
return Ok(Mapping {
protocol,
gateway,
external_ip,
external_port,
});
}

let external_port = gateway
Expand Down
Loading