Add Iroh relay mode config

This commit is contained in:
Eric Wendland 2026-05-16 03:17:45 +02:00
commit 0f2ad755d9
13 changed files with 210 additions and 21 deletions

View file

@ -2,13 +2,13 @@ pub mod service;
use geth_auth::AuthExplanation;
use geth_cas::{LocalCas, hash_path};
use geth_config::GethPaths;
use geth_config::{GethConfig, GethPaths, RelayMode};
use geth_control::{
CasBlob, ControlRequest, ControlResponse, KeychainStatusResponse, NodeIdResponse,
StatusResponse,
};
use geth_crypto::AgentKey;
use geth_iroh::{EndpointStatus, GethIrohConfig, GethIrohEndpoint};
use geth_iroh::{EndpointStatus, GethIrohConfig, GethIrohEndpoint, GethRelayMode};
use geth_resource::ResourceDescriptor;
use geth_ssh_identity::{
SshCertApproval, SshCertKind, SshCertRequest, SshCertRequestStatus, SshCertificateRecord,
@ -68,10 +68,7 @@ pub struct LocalNode {
pub fn init_node(paths: &GethPaths) -> Result<LocalNode, NodeError> {
paths.ensure_base_dirs()?;
if !paths.config_file().exists() {
std::fs::write(
paths.config_file(),
"# geth local node config\n# Remote node-to-node communication is Iroh-only.\n",
)?;
std::fs::write(paths.config_file(), GethConfig::default_toml())?;
}
let key = AgentKey::load_or_create(&paths.agent_key())?;
let agent_id = key.agent_id().to_string();
@ -163,6 +160,7 @@ pub fn handle_request(
node_id: node.node_id.clone(),
iroh_enabled: node.iroh_status.enabled,
endpoint_id: node.iroh_status.endpoint_id.clone(),
iroh_relay_mode: node.iroh_status.relay_mode.clone(),
iroh: node.iroh_status.note.clone(),
})),
ControlRequest::NodeId => Ok(ControlResponse::NodeId(NodeIdResponse {
@ -447,7 +445,10 @@ fn stable_node_id(agent_id: &str) -> String {
async fn start_daemon_iroh_endpoint(
node: &mut LocalNode,
) -> Result<Option<GethIrohEndpoint>, NodeError> {
let config = GethIrohConfig::local(node.paths.iroh_key());
let node_config = GethConfig::load(&node.paths.config_file())?;
let relay_mode = node_config.iroh.relay_mode;
let iroh_relay_mode = config_relay_mode_to_iroh(relay_mode);
let config = GethIrohConfig::local_with_relay(node.paths.iroh_key(), iroh_relay_mode);
match geth_iroh::start_endpoint(&config).await {
Ok(endpoint) => {
let status = endpoint.status();
@ -462,6 +463,7 @@ async fn start_daemon_iroh_endpoint(
node.iroh_status = EndpointStatus {
enabled: false,
endpoint_id: None,
relay_mode: relay_mode.as_str().to_owned(),
note: format!("Iroh endpoint failed to start: {error}"),
};
Ok(None)
@ -469,6 +471,14 @@ async fn start_daemon_iroh_endpoint(
}
}
fn config_relay_mode_to_iroh(mode: RelayMode) -> GethRelayMode {
match mode {
RelayMode::Disabled => GethRelayMode::Disabled,
RelayMode::Default => GethRelayMode::Default,
RelayMode::Staging => GethRelayMode::Staging,
}
}
fn expected_openssh_cert_path(public_key_path: &Path) -> String {
let text = public_key_path.display().to_string();
if let Some(prefix) = text.strip_suffix(".pub") {