Enable Iroh local network discovery

This commit is contained in:
Eric Wendland 2026-05-16 14:33:45 +02:00
commit bfc5df698c
12 changed files with 136 additions and 16 deletions

View file

@ -16,6 +16,7 @@ pub const ALPN_SSH_PROXY: &[u8] = b"/geth/ssh-proxy/1";
pub struct GethIrohConfig {
pub secret_key_path: PathBuf,
pub relay_mode: GethRelayMode,
pub local_discovery: bool,
pub bind_ipv4: Option<SocketAddrV4>,
pub bind_ipv6: Option<SocketAddrV6>,
pub alpns: Vec<Vec<u8>>,
@ -35,6 +36,7 @@ impl GethIrohConfig {
Self {
secret_key_path: secret_key_path.into(),
relay_mode,
local_discovery: true,
bind_ipv4: None,
bind_ipv6: None,
alpns: default_protocol_router().alpns(),
@ -229,6 +231,10 @@ pub async fn start_endpoint(config: &GethIrohConfig) -> Result<GethIrohEndpoint,
.relay_mode(config.relay_mode.to_iroh()?)
.alpns(config.alpns.clone());
if config.local_discovery {
builder = builder.discovery_local_network();
}
if let Some(bind_ipv4) = config.bind_ipv4 {
builder = builder.bind_addr_v4(bind_ipv4);
}
@ -241,9 +247,10 @@ pub async fn start_endpoint(config: &GethIrohConfig) -> Result<GethIrohEndpoint,
enabled: true,
endpoint_id: Some(endpoint.node_id().to_string()),
relay_mode: config.relay_mode.label(),
local_discovery: config.local_discovery,
note: format!(
"Iroh endpoint started with iroh 0.90.0; relay mode: {:?}",
config.relay_mode
"Iroh endpoint started with iroh 0.90.0; relay mode: {:?}; local discovery: {}",
config.relay_mode, config.local_discovery
),
};
Ok(GethIrohEndpoint { endpoint, status })
@ -283,6 +290,7 @@ pub struct EndpointStatus {
pub enabled: bool,
pub endpoint_id: Option<String>,
pub relay_mode: String,
pub local_discovery: bool,
pub note: String,
}
@ -293,6 +301,7 @@ impl EndpointStatus {
enabled: false,
endpoint_id: None,
relay_mode: "not-started".to_owned(),
local_discovery: false,
note: "Iroh endpoint is not running outside daemon mode".to_owned(),
}
}
@ -416,16 +425,18 @@ mod tests {
#[tokio::test]
async fn endpoint_status_tracks_node_id_when_bind_is_available() {
let dir = tempfile::tempdir().expect("tempdir");
let config = GethIrohConfig::local_with_relay(
let mut config = GethIrohConfig::local_with_relay(
dir.path().join("iroh.ed25519"),
GethRelayMode::Disabled,
);
config.local_discovery = false;
match start_endpoint(&config).await {
Ok(endpoint) => {
let status = endpoint.status();
assert!(status.enabled);
assert_eq!(status.endpoint_id, Some(endpoint.node_id()));
assert_eq!(status.relay_mode, "disabled");
assert!(!status.local_discovery);
endpoint.shutdown().await;
}
Err(IrohError::Bind(error)) => {