diff options
| -rw-r--r-- | src/api/peers.rs | 10 | ||||
| -rw-r--r-- | src/api/stats.rs | 3 |
2 files changed, 10 insertions, 3 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. diff --git a/src/api/stats.rs b/src/api/stats.rs index 889b675..114f644 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -249,7 +249,8 @@ pub(crate) async fn get_stats(State(state): State<AppState>, headers: HeaderMap) } } -async fn collect(state: &AppState) -> StatsResponse { +/// What `GET /admin/stats` answers as JSON, for others to show too (the dashboard). +pub(crate) async fn collect(state: &AppState) -> StatsResponse { let node = state.stats.snapshot(); let (heads, tier, remakes) = { |
