Add daemon-owned Iroh endpoint

This commit is contained in:
Eric Wendland 2026-05-16 01:54:00 +02:00
commit ebc40ed208
14 changed files with 3930 additions and 431 deletions

View file

@ -8,6 +8,7 @@ use geth_control::{
StatusResponse,
};
use geth_crypto::AgentKey;
use geth_iroh::{EndpointStatus, GethIrohConfig, GethIrohEndpoint};
use geth_resource::ResourceDescriptor;
use geth_ssh_identity::{
SshCertApproval, SshCertKind, SshCertRequest, SshCertRequestStatus, SshCertificateRecord,
@ -61,6 +62,7 @@ pub struct LocalNode {
pub paths: GethPaths,
pub agent_id: String,
pub node_id: String,
pub iroh_status: EndpointStatus,
}
pub fn init_node(paths: &GethPaths) -> Result<LocalNode, NodeError> {
@ -87,6 +89,7 @@ pub fn init_node(paths: &GethPaths) -> Result<LocalNode, NodeError> {
paths: paths.clone(),
agent_id,
node_id,
iroh_status: EndpointStatus::scaffolded(),
})
}
@ -95,7 +98,8 @@ pub fn open_node(paths: &GethPaths) -> Result<LocalNode, NodeError> {
}
pub async fn run_daemon(paths: GethPaths) -> Result<(), NodeError> {
let node = init_node(&paths)?;
let mut node = init_node(&paths)?;
let _iroh_endpoint = start_daemon_iroh_endpoint(&mut node).await?;
if Path::new(&paths.socket_path()).exists() {
std::fs::remove_file(paths.socket_path())?;
}
@ -157,12 +161,14 @@ pub fn handle_request(
socket: node.paths.socket_path(),
agent_id: node.agent_id.clone(),
node_id: node.node_id.clone(),
iroh: "scaffolded; no remote endpoint is started in bootstrap".to_owned(),
iroh_enabled: node.iroh_status.enabled,
endpoint_id: node.iroh_status.endpoint_id.clone(),
iroh: node.iroh_status.note.clone(),
})),
ControlRequest::NodeId => Ok(ControlResponse::NodeId(NodeIdResponse {
agent_id: node.agent_id.clone(),
node_id: node.node_id.clone(),
endpoint_id: None,
endpoint_id: node.iroh_status.endpoint_id.clone(),
})),
ControlRequest::ResourceList => Ok(ControlResponse::ResourceList {
resources: store
@ -438,6 +444,31 @@ fn stable_node_id(agent_id: &str) -> String {
format!("node:{agent_id}")
}
async fn start_daemon_iroh_endpoint(
node: &mut LocalNode,
) -> Result<Option<GethIrohEndpoint>, NodeError> {
let config = GethIrohConfig::local(node.paths.iroh_key());
match geth_iroh::start_endpoint(&config).await {
Ok(endpoint) => {
let status = endpoint.status();
if let Some(endpoint_id) = &status.endpoint_id {
let store = Store::open(&node.paths.metadata_db())?;
store.upsert_node_endpoint(endpoint_id, &node.node_id, &node.agent_id, "iroh")?;
}
node.iroh_status = status;
Ok(Some(endpoint))
}
Err(error) => {
node.iroh_status = EndpointStatus {
enabled: false,
endpoint_id: None,
note: format!("Iroh endpoint failed to start: {error}"),
};
Ok(None)
}
}
}
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") {