aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/dashboard')
-rw-r--r--src/api/dashboard/mod.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/api/dashboard/mod.rs b/src/api/dashboard/mod.rs
index 831df6f..aae514a 100644
--- a/src/api/dashboard/mod.rs
+++ b/src/api/dashboard/mod.rs
@@ -574,30 +574,40 @@ struct TreeQuery {
}
/// `GET /admin/dashboard/tree?writer=…`: the writer's tree (`swarm::tree`), as this node
-/// computes it from the member list and the links members report (whom each reaches;
-/// one that reports none counts as reaching its neighbours by the member list): every
-/// member's parent, `null` for one without. `404` if the writer isn't a member.
+/// computes it from the member list and the links members report (whom each reaches,
+/// and how far: its round trip, as a bucket, `rtt::bucket`; one that reports none counts
+/// as reaching its neighbours by the member list): every member's parent, `null` for
+/// one without. `404` if the writer isn't a member.
async fn writer_tree(
Extension(hub): Extension<Arc<Hub>>,
Query(query): Query<TreeQuery>,
) -> Response {
let state = &hub.state;
- let mut reaches: BTreeMap<String, BTreeSet<String>> = state
+ let mut reports: BTreeMap<String, Vec<Link>> = state
.links
.replies()
.into_iter()
- .map(|(member, _, links)| (member, reached_by(&links)))
+ .map(|(member, _, links)| (member, links))
+ .collect();
+ reports.insert(state.local_id().to_owned(), links::own_links(state).await);
+ let reaches: BTreeMap<&str, BTreeSet<String>> = reports
+ .iter()
+ .map(|(member, links)| (member.as_str(), reached_by(links)))
.collect();
- reaches.insert(
- state.local_id().to_owned(),
- reached_by(&links::own_links(state).await),
- );
let reached = |by: &str, member: &str| {
reaches
.get(by)
.is_none_or(|reached| reached.contains(member))
};
- match crate::swarm::tree::whole(state, &query.writer, &reached) {
+ let round_trip = |by: &str, member: &str| {
+ let rtt = reports
+ .get(by)
+ .and_then(|links| links.iter().find(|link| link.peer == member))
+ .and_then(|link| link.rtt_us)
+ .map(|us| std::time::Duration::from_micros(u64::from(us)));
+ crate::swarm::rtt::bucket(rtt, None)
+ };
+ match crate::swarm::tree::whole(state, &query.writer, &reached, &round_trip) {
Some(parents) => {
axum::Json(json!({ "writer": query.writer, "parents": parents })).into_response()
}