relay_server/endpoints/
public_keys.rs

1use std::collections::HashMap;
2
3use axum::response::IntoResponse;
4use futures::future;
5
6use crate::endpoints::common::ServiceUnavailable;
7use crate::extractors::SignedJson;
8use crate::service::ServiceState;
9use crate::services::relays::{GetRelay, GetRelays, GetRelaysResponse};
10
11/// Handles the Relay public keys endpoint.
12///
13/// Note that this has nothing to do with Sentry public keys, which refer to the public key portion
14/// of a DSN used for authenticating event submission. This endpoint is for Relay's public keys,
15/// which authenticate entire Relays.
16pub async fn handle(
17    state: ServiceState,
18    body: SignedJson<GetRelays>,
19) -> Result<impl IntoResponse, ServiceUnavailable> {
20    let relay_cache = &state.relay_cache();
21
22    let relay_ids = body.inner.relay_ids.into_iter();
23    let futures = relay_ids.map(|relay_id| {
24        let inner = relay_cache.send(GetRelay { relay_id });
25        async move { (relay_id, inner.await) }
26    });
27
28    let mut relays = HashMap::new();
29    for (relay_id, result) in future::join_all(futures).await {
30        let relay_info = result?;
31        relays.insert(relay_id, relay_info);
32    }
33
34    Ok(axum::Json(GetRelaysResponse { relays }))
35}