diff options
| author | tv <tv@krebsco.de> | 2026-10-30 17:33:59 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 17:33:59 +0100 |
| commit | 236a11a4798574b9c710dde4b97231ff4cade86d (patch) | |
| tree | 1203102bc44aa9bcc002646934d59c5a3f3bcd83 /src/api/peers.rs | |
| parent | f091fb2a9188f686e5b1f9012c510a1b3c8ad840 (diff) | |
build stats and peers as values
Both /admin/stats and /peers can now be built as plain values
(stats::collect, peers::peer_list), so the upcoming dashboard
can reuse them.
Diffstat (limited to 'src/api/peers.rs')
| -rw-r--r-- | src/api/peers.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs index eeb3fb2..da714d0 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -114,6 +114,12 @@ pub(crate) struct DeletePeerQuery { pub(crate) async fn list_peers( State(state): State<AppState>, ) -> Result<Json<PeerListResponse>, StatusCode> { + Ok(Json(peer_list(&state).await)) +} + +/// What `GET /peers` answers, for others to show too (the dashboard). +pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse { + let state = state.clone(); let snapshot = state.peers_snapshot().await; let now = Instant::now(); @@ -173,13 +179,13 @@ pub(crate) async fn list_peers( } let local_heads = state.doc.read().await.heads().len(); - Ok(Json(PeerListResponse { + PeerListResponse { local_alias: state.alias.clone(), local_addresses: state.transport.local_addresses(), local_epoch: local_epoch.into(), local_heads, peers, - })) + } } /// `DELETE /peers/{pk}`: forgets a peer swarm-wide. |
