pubhubs/api/server.rs
1//! Endpoints served by every PubHubs server (PHC, Transcryptor, Authentication Server)
2//! aside from the discovery related endpoints ([`DiscoveryInfo`] and [`DiscoveryRun`]).
3//!
4//! Currently only [`HubPingEP`], a worked example of an endpoint that requires the caller
5//! to authenticate as a hub via a [`phc::hub::TicketSigned`] request.
6
7use crate::api::*;
8use crate::handle;
9use crate::misc::serde_ext::bytes_wrapper::B64UU;
10
11use actix_web::http;
12use serde::{Deserialize, Serialize};
13
14/// Demo health-check endpoint that requires the caller to authenticate as a hub via
15/// [`phc::hub::TicketSigned`].
16pub struct HubPingEP {}
17impl EndpointDetails for HubPingEP {
18 type RequestType = phc::hub::TicketSigned<PingReq>;
19 type ResponseType = Result<PingResp>;
20
21 const METHOD: http::Method = http::Method::POST;
22 const PATH: &'static str = ".ph/hub/ping";
23}
24
25/// Request type of [`HubPingEP`].
26#[derive(Serialize, Deserialize, Debug, Clone)]
27#[serde(deny_unknown_fields)]
28pub struct PingReq {
29 /// Echoed back as [`PingResp::Success::nonce`].
30 pub nonce: B64UU,
31}
32
33having_message_code!(PingReq, HubPing);
34
35/// Returned by [`HubPingEP`].
36#[derive(Serialize, Deserialize, Debug, Clone)]
37#[serde(deny_unknown_fields)]
38#[must_use]
39pub enum PingResp {
40 Success {
41 /// Hub handle taken from the [`phc::hub::Ticket`].
42 hub_handle: handle::Handle,
43
44 /// Echo of [`PingReq::nonce`].
45 nonce: B64UU,
46
47 /// Identifies which server answered.
48 served_by: crate::servers::Name,
49 },
50
51 /// Ticket signature was invalid or expired. Obtain a new ticket and retry.
52 RetryWithNewTicket,
53}