Skip to content

Commit 3d14417

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/dns
2 parents c3252b6 + 35a1cdd commit 3d14417

File tree

10 files changed

+63
-34
lines changed

10 files changed

+63
-34
lines changed

Cargo.lock

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh-cli/src/commands.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ pub(crate) struct Cli {
4040
#[cfg(unix)]
4141
#[clap(long)]
4242
pub(crate) log_fd: Option<i32>,
43+
44+
/// Port to serve metrics on. -1 to disable.
45+
#[clap(long)]
46+
pub(crate) metrics_port: Option<i16>,
4347
}
4448

4549
#[derive(Parser, Debug, Clone)]
@@ -127,7 +131,14 @@ impl Cli {
127131
path.display()
128132
);
129133
}
130-
let config = NodeConfig::from_env(self.config.as_deref())?;
134+
let mut config = NodeConfig::from_env(self.config.as_deref())?;
135+
if let Some(metrics_port) = self.metrics_port {
136+
if metrics_port < 0 {
137+
config.metrics_addr = None;
138+
} else {
139+
config.metrics_addr = Some(([127, 0, 0, 1], metrics_port as u16).into())
140+
}
141+
}
131142

132143
let add_command = add.map(|source| blob::BlobCommands::Add {
133144
source,

iroh-cli/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Default for NodeConfig {
9999
// TODO(ramfox): this should probably just be a relay map
100100
relay_nodes: [default_na_relay_node(), default_eu_relay_node()].into(),
101101
gc_policy: GcPolicy::Disabled,
102-
metrics_addr: None,
102+
metrics_addr: Some(([127, 0, 0, 1], 9090).into()),
103103
}
104104
}
105105
}

iroh-net/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ http = "1"
3636
http-body-util = "0.1.0"
3737
hyper = { version = "1", features = ["server", "client", "http1"] }
3838
hyper-util = "0.1.1"
39-
igd = { version = "0.12.1", features = ["aio"] }
39+
igd-next = { version = "0.14.3", features = ["aio_tokio"] }
4040
iroh-base = { version = "0.13.0", path = "../iroh-base", features = ["key"] }
4141
libc = "0.2.139"
4242
num_enum = "0.7"

iroh-net/src/portmapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Client {
210210
struct Probe {
211211
/// When was the probe last updated.
212212
last_probe: Instant,
213-
/// The last [`igd::aio::Gateway`] and when was it last seen.
213+
/// The last [`upnp::Gateway`] and when was it last seen.
214214
last_upnp_gateway_addr: Option<(upnp::Gateway, Instant)>,
215215
/// Last time PCP was seen.
216216
last_pcp: Option<Instant>,

iroh-net/src/portmapper/mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Mapping {
5757
pub(crate) async fn new_upnp(
5858
local_ip: Ipv4Addr,
5959
local_port: NonZeroU16,
60-
gateway: Option<igd::aio::Gateway>,
60+
gateway: Option<upnp::Gateway>,
6161
external_port: Option<NonZeroU16>,
6262
) -> Result<Self> {
6363
upnp::Mapping::new(local_ip, local_port, gateway, external_port)

iroh-net/src/portmapper/upnp.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use std::{
44
time::Duration,
55
};
66

7-
use anyhow::Result;
8-
use igd::aio as aigd;
7+
use anyhow::{anyhow, Result};
8+
use igd_next::aio as aigd;
99

1010
use iroh_metrics::inc;
1111
use tracing::debug;
1212

1313
use super::Metrics;
1414

15-
pub use aigd::Gateway;
15+
pub type Gateway = aigd::Gateway<aigd::tokio::Tokio>;
1616

1717
/// Seconds we ask the router to maintain the port mapping. 0 means infinite.
1818
const PORT_MAPPING_LEASE_DURATION_SECONDS: u32 = 0;
@@ -31,7 +31,7 @@ const PORT_MAPPING_DESCRIPTION: &str = "iroh-portmap";
3131
pub struct Mapping {
3232
/// The internet Gateway device (router) used to create this mapping.
3333
#[debug("{}", gateway)]
34-
gateway: aigd::Gateway,
34+
gateway: Gateway,
3535
/// The external address obtained by this mapping.
3636
external_ip: Ipv4Addr,
3737
/// External port obtained by this mapping.
@@ -42,7 +42,7 @@ impl Mapping {
4242
pub(crate) async fn new(
4343
local_addr: Ipv4Addr,
4444
port: NonZeroU16,
45-
gateway: Option<aigd::Gateway>,
45+
gateway: Option<Gateway>,
4646
preferred_port: Option<NonZeroU16>,
4747
) -> Result<Self> {
4848
let local_addr = SocketAddrV4::new(local_addr, port.into());
@@ -51,23 +51,25 @@ impl Mapping {
5151
let gateway = if let Some(known_gateway) = gateway {
5252
known_gateway
5353
} else {
54-
aigd::search_gateway(igd::SearchOptions {
54+
aigd::tokio::search_gateway(igd_next::SearchOptions {
5555
timeout: Some(SEARCH_TIMEOUT),
5656
..Default::default()
5757
})
5858
.await?
5959
};
6060

61-
let external_ip = gateway.get_external_ip().await?;
61+
let std::net::IpAddr::V4(external_ip) = gateway.get_external_ip().await? else {
62+
return Err(anyhow!("igd device's external ip is ipv6"));
63+
};
6264

6365
// if we are trying to get a specific external port, try this first. If this fails, default
6466
// to try to get any port
6567
if let Some(external_port) = preferred_port {
6668
if gateway
6769
.add_port(
68-
igd::PortMappingProtocol::UDP,
70+
igd_next::PortMappingProtocol::UDP,
6971
external_port.into(),
70-
local_addr,
72+
local_addr.into(),
7173
PORT_MAPPING_LEASE_DURATION_SECONDS,
7274
PORT_MAPPING_DESCRIPTION,
7375
)
@@ -84,8 +86,8 @@ impl Mapping {
8486

8587
let external_port = gateway
8688
.add_any_port(
87-
igd::PortMappingProtocol::UDP,
88-
local_addr,
89+
igd_next::PortMappingProtocol::UDP,
90+
local_addr.into(),
8991
PORT_MAPPING_LEASE_DURATION_SECONDS,
9092
PORT_MAPPING_DESCRIPTION,
9193
)
@@ -112,7 +114,7 @@ impl Mapping {
112114
..
113115
} = self;
114116
gateway
115-
.remove_port(igd::PortMappingProtocol::UDP, external_port.into())
117+
.remove_port(igd_next::PortMappingProtocol::UDP, external_port.into())
116118
.await?;
117119
Ok(())
118120
}
@@ -126,7 +128,7 @@ impl Mapping {
126128
/// Searches for UPnP gateways.
127129
pub async fn probe_available() -> Option<Gateway> {
128130
inc!(Metrics, upnp_probes);
129-
match aigd::search_gateway(igd::SearchOptions {
131+
match aigd::tokio::search_gateway(igd_next::SearchOptions {
130132
timeout: Some(SEARCH_TIMEOUT),
131133
..Default::default()
132134
})

iroh/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ clap = { version = "4", features = ["derive"], optional = true }
5757
indicatif = { version = "0.17", features = ["tokio"], optional = true }
5858

5959
[features]
60-
default = ["metrics"]
60+
default = ["metrics", "fs-store"]
6161
metrics = ["iroh-metrics", "iroh-bytes/metrics"]
6262
fs-store = ["iroh-bytes/fs-store"]
6363
test = []

iroh/src/node.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<D> NodeInner<D> {
277277
}
278278
}
279279

280-
#[cfg(all(test, feature = "fs-store"))]
280+
#[cfg(test)]
281281
mod tests {
282282
use std::path::Path;
283283
use std::time::Duration;
@@ -387,4 +387,24 @@ mod tests {
387387

388388
Ok(())
389389
}
390+
391+
#[cfg(feature = "fs-store")]
392+
#[tokio::test]
393+
async fn test_shutdown() -> Result<()> {
394+
let _guard = iroh_test::logging::setup();
395+
396+
let iroh_root = tempfile::TempDir::new()?;
397+
{
398+
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
399+
let doc = iroh.docs.create().await?;
400+
drop(doc);
401+
iroh.shutdown();
402+
iroh.await?;
403+
}
404+
405+
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
406+
let _doc = iroh.docs.create().await?;
407+
408+
Ok(())
409+
}
390410
}

iroh/src/node/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,15 @@ where
492492
debug!(me = ?server.node_id(), "gossip initial update: {local_endpoints:?}");
493493
gossip.update_endpoints(&local_endpoints).ok();
494494
}
495-
496495
loop {
497496
tokio::select! {
498497
biased;
499498
_ = cancel_token.cancelled() => {
500499
// clean shutdown of the blobs db to close the write transaction
501500
handler.inner.db.shutdown().await;
501+
if let Err(err) = handler.inner.sync.shutdown().await {
502+
warn!("sync shutdown error: {:?}", err);
503+
}
502504
break
503505
},
504506
// handle rpc requests. This will do nothing if rpc is not configured, since

0 commit comments

Comments
 (0)