|
| 1 | +//! `GET /_tuwunel/remote_version/{server_name}` |
| 2 | +//! |
| 3 | +//! Probe a remote server's `/_matrix/federation/v1/version` endpoint and |
| 4 | +//! return the response body together with the observed round-trip time. |
| 5 | +
|
| 6 | +pub mod unstable { |
| 7 | + //! Tuwunel-private unstable variant of the endpoint. |
| 8 | +
|
| 9 | + use std::time::Duration; |
| 10 | + |
| 11 | + use ruma_common::{ |
| 12 | + OwnedServerName, |
| 13 | + api::{auth_scheme::AccessToken, request, response}, |
| 14 | + metadata, |
| 15 | + }; |
| 16 | + use serde_json::value::RawValue as RawJsonValue; |
| 17 | + |
| 18 | + metadata! { |
| 19 | + method: GET, |
| 20 | + rate_limited: false, |
| 21 | + authentication: AccessToken, |
| 22 | + history: { |
| 23 | + unstable => "/_tuwunel/remote_version/{server_name}", |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + /// Request type for the `get_remote_version` endpoint. |
| 28 | + #[request] |
| 29 | + pub struct Request { |
| 30 | + /// Remote server to probe. |
| 31 | + #[ruma_api(path)] |
| 32 | + pub server_name: OwnedServerName, |
| 33 | + } |
| 34 | + |
| 35 | + /// Response type for the `get_remote_version` endpoint. |
| 36 | + #[response] |
| 37 | + pub struct Response { |
| 38 | + /// The remote server's `/_matrix/federation/v1/version` response body. |
| 39 | + pub data: Box<RawJsonValue>, |
| 40 | + |
| 41 | + /// Round-trip time of the probe, serialized as an integer |
| 42 | + /// millisecond count. |
| 43 | + #[serde(with = "ruma_common::serde::duration::ms")] |
| 44 | + pub rtt_ms: Duration, |
| 45 | + } |
| 46 | + |
| 47 | + impl Request { |
| 48 | + /// Creates a new `Request` with the given server name. |
| 49 | + pub fn new(server_name: OwnedServerName) -> Self { |
| 50 | + Self { server_name } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + impl Response { |
| 55 | + /// Creates a new `Response` with the given data and rtt. |
| 56 | + pub fn new(data: Box<RawJsonValue>, rtt_ms: Duration) -> Self { |
| 57 | + Self { data, rtt_ms } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments