mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-09-16 21:02:34 +00:00
Add get_peers method to http API
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
+12
-1
@@ -94,12 +94,17 @@ impl Http {
|
||||
peer_manager,
|
||||
message_stack,
|
||||
};
|
||||
let admin_routes = Router::new()
|
||||
.route("/admin/peers", get(get_peers))
|
||||
.with_state(server_state.clone());
|
||||
let msg_routes = Router::new()
|
||||
.route("/messages", get(get_message).post(push_message))
|
||||
.route("/messages/status/:id", get(message_status))
|
||||
.route("/messages/reply/:id", post(reply_message))
|
||||
.with_state(server_state);
|
||||
let app = Router::new().nest("/api/v1", msg_routes);
|
||||
let app = Router::new()
|
||||
.nest("/api/v1", msg_routes)
|
||||
.nest("/api/v1", admin_routes);
|
||||
let (_cancel_tx, cancel_rx) = tokio::sync::oneshot::channel();
|
||||
let server = axum::Server::bind(listen_addr)
|
||||
.serve(app.into_make_service())
|
||||
@@ -307,6 +312,12 @@ async fn message_status(
|
||||
.map(Json)
|
||||
}
|
||||
|
||||
/// Get the stats of the current known peers
|
||||
async fn get_peers(State(state): State<HttpServerState>) -> Json<Vec<PeerStats>> {
|
||||
debug!("Fetching peer stats");
|
||||
Json(state.peer_manager.peers())
|
||||
}
|
||||
|
||||
/// Module to implement base64 decoding and encoding
|
||||
// Sourced from https://users.rust-lang.org/t/serialize-a-vec-u8-to-json-as-base64/57781, with some
|
||||
// addaptions to work with the new version of the base64 crate
|
||||
|
||||
Reference in New Issue
Block a user