federation-api: More small improvements

This commit is contained in:
Jonas Platte 2020-08-20 02:13:57 +02:00
parent 64c5159f04
commit 135bea8562
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 70 additions and 8 deletions

View File

@ -11,29 +11,45 @@ ruma_api! {
description: "Query for another server's keys.", description: "Query for another server's keys.",
method: GET, method: GET,
name: "get_remote_server_keys", name: "get_remote_server_keys",
// Note: The spec has an additional, deprecated path parameter on this. We may want to
// support an additional parameter at the end, even if it is ignored.
path: "/_matrix/key/v2/query/:server_name", path: "/_matrix/key/v2/query/:server_name",
rate_limited: false, rate_limited: false,
requires_authentication: false, requires_authentication: false,
} }
#[non_exhaustive]
request: { request: {
/// The server's DNS name to query /// The server's DNS name to query
#[ruma_api(path)] #[ruma_api(path)]
pub server_name: &'a ServerName, pub server_name: &'a ServerName,
/// A millisecond POSIX timestamp in milliseconds indicating when the /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates
/// returned certificates will need to be valid until to be useful to /// will need to be valid until to be useful to the requesting server.
/// the requesting server.
/// ///
/// If not supplied, the current time as determined by the notary server /// If not supplied, the current time as determined by the receiving server is used.
/// is used.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] #[serde(default = "SystemTime::now", with = "ruma_serde::time::ms_since_unix_epoch")]
pub minimum_valid_until_ts: SystemTime, pub minimum_valid_until_ts: SystemTime,
} }
#[non_exhaustive]
response: { response: {
/// The queried server's keys, signed by the notary server. /// The queried server's keys, signed by the notary server.
pub server_keys: Vec<ServerKey>, pub server_keys: Vec<ServerKey>,
} }
} }
impl<'a> Request<'a> {
/// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp.
pub fn new(server_name: &'a ServerName, minimum_valid_until_ts: SystemTime) -> Self {
Self { server_name, minimum_valid_until_ts }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
pub fn new(server_keys: Vec<ServerKey>) -> Self {
Self { server_keys }
}
}

View File

@ -17,6 +17,7 @@ ruma_api! {
requires_authentication: false, requires_authentication: false,
} }
#[non_exhaustive]
request: { request: {
/// The query criteria. The outer string key on the object is the server /// The query criteria. The outer string key on the object is the server
/// name (eg: matrix.org). The inner string key is the Key ID to query /// name (eg: matrix.org). The inner string key is the Key ID to query
@ -41,12 +42,30 @@ ruma_api! {
pub minimum_valid_until_ts: SystemTime, pub minimum_valid_until_ts: SystemTime,
} }
#[non_exhaustive]
response: { response: {
/// The queried server's keys, signed by the notary server. /// The queried server's keys, signed by the notary server.
pub server_keys: Vec<ServerKey>, pub server_keys: Vec<ServerKey>,
} }
} }
impl Request {
/// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp.
pub fn new(
server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerKeyId, QueryCriteria>>,
minimum_valid_until_ts: SystemTime,
) -> Self {
Self { server_keys, minimum_valid_until_ts }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
pub fn new(server_keys: Vec<ServerKey>) -> Self {
Self { server_keys }
}
}
/// The query criteria. /// The query criteria.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[non_exhaustive] #[non_exhaustive]

View File

@ -15,6 +15,7 @@ ruma_api! {
requires_authentication: true, requires_authentication: true,
} }
#[non_exhaustive]
request: { request: {
/// The room ID that is about to be joined. /// The room ID that is about to be joined.
#[ruma_api(path)] #[ruma_api(path)]
@ -24,17 +25,43 @@ ruma_api! {
#[ruma_api(path)] #[ruma_api(path)]
pub user_id: &'a UserId, pub user_id: &'a UserId,
/// The room versions the sending server has support for. Defaults to 1. /// The room versions the sending server has support for.
///
/// Defaults to `&[RoomVersionId::Version1]`.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(skip_serializing_if = "<[_]>::is_empty")] #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")]
pub ver: &'a [RoomVersionId], pub ver: &'a [RoomVersionId],
} }
#[non_exhaustive]
response: { response: {
/// The version of the room where the server is trying to join. /// The version of the room where the server is trying to join.
#[serde(skip_serializing_if = "Option::is_none")]
pub room_version: Option<RoomVersionId>, pub room_version: Option<RoomVersionId>,
/// An unsigned template event. /// An unsigned template event.
pub event: Raw<Pdu>, pub event: Raw<Pdu>,
} }
} }
fn default_ver() -> Vec<RoomVersionId> {
vec![RoomVersionId::Version1]
}
fn is_default_ver(ver: &&[RoomVersionId]) -> bool {
**ver == [RoomVersionId::Version1]
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room id and user id.
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
Self { room_id, user_id, ver: &[RoomVersionId::Version1] }
}
}
impl Response {
/// Creates a new `Response` with the given template event.
pub fn new(event: Raw<Pdu>) -> Self {
Self { room_version: None, event }
}
}