diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 9ec4e331..d2ad2c73 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -1,7 +1,6 @@ pub mod auth; use std::collections::HashMap; -use std::net::SocketAddr; use std::sync::Arc; use std::time::Duration; @@ -40,7 +39,6 @@ pub struct Context { profile: Arc, sessions: Arc>>, cache: Option, - address: SocketAddr, } impl Context { @@ -49,7 +47,6 @@ impl Context { profile, sessions: Default::default(), cache: options.cache.map(Cache::new), - address: options.listen, } } diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index 864daa40..63535a47 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -78,6 +78,10 @@ pub enum Error { #[error(transparent)] RoutingStore(#[from] radicle::node::routing::Error), + /// Node error. + #[error(transparent)] + Node(#[from] radicle::node::Error), + /// Invalid update to issue or patch. #[error("{0}")] BadRequest(String), diff --git a/radicle-httpd/src/api/v1/node.rs b/radicle-httpd/src/api/v1/node.rs index 65a08a69..f7de8aee 100644 --- a/radicle-httpd/src/api/v1/node.rs +++ b/radicle-httpd/src/api/v1/node.rs @@ -1,31 +1,37 @@ -use std::net::SocketAddr; - use axum::extract::State; use axum::response::IntoResponse; use axum::routing::get; use axum::{Json, Router}; use serde_json::json; -use radicle::node::NodeId; +use radicle::node::Handle; +use radicle::Node; +use crate::api::error::Error; use crate::api::Context; pub fn router(ctx: Context) -> Router { - let node_id = ctx.profile.public_key; - let address = ctx.address; - Router::new() .route("/node", get(node_handler)) - .with_state((node_id, address)) + .with_state(ctx) } -/// Return the node id for the node identity. +/// Return local node information. /// `GET /node` -async fn node_handler(State((node_id, address)): State<(NodeId, SocketAddr)>) -> impl IntoResponse { +async fn node_handler(State(ctx): State) -> impl IntoResponse { + let node = Node::new(ctx.profile.socket()); + let node_id = ctx.profile.public_key; + let node_state = if node.is_running() { + "running" + } else { + "stopped" + }; + let config = node.config()?; let response = json!({ "id": node_id.to_string(), - "address": address.to_string(), + "config": config, + "state": node_state, }); - Json(response) + Ok::<_, Error>(Json(response)) }