Skip to content

Commit 2087d98

Browse files
dasha-uwujevolk
authored andcommitted
Add remote ping endpoint
1 parent 1ddd2b7 commit 2087d98

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

crates/ruma-client-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub mod tag;
5353
pub mod thirdparty;
5454
pub mod threads;
5555
pub mod to_device;
56+
pub mod tuwunel;
5657
pub mod typing;
5758
pub mod uiaa;
5859
pub mod user_directory;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Tuwunel-specific endpoints.
2+
3+
pub mod get_remote_version;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)