Update ruma
This commit is contained in:
parent
4b3d6e736f
commit
75ea0b3163
14 changed files with 152 additions and 122 deletions
|
@ -14,7 +14,7 @@ use rocket::{delete, get, put};
|
|||
)]
|
||||
pub fn create_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_alias::Request>,
|
||||
body: Ruma<create_alias::IncomingRequest>,
|
||||
) -> ConduitResult<create_alias::Response> {
|
||||
if db.rooms.id_from_alias(&body.room_alias)?.is_some() {
|
||||
return Err(Error::Conflict("Alias already exists."));
|
||||
|
@ -32,7 +32,7 @@ pub fn create_alias_route(
|
|||
)]
|
||||
pub fn delete_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_alias::Request>,
|
||||
body: Ruma<delete_alias::IncomingRequest>,
|
||||
) -> ConduitResult<delete_alias::Response> {
|
||||
db.rooms.set_alias(&body.room_alias, None, &db.globals)?;
|
||||
|
||||
|
@ -45,7 +45,7 @@ pub fn delete_alias_route(
|
|||
)]
|
||||
pub fn get_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_alias::Request>,
|
||||
body: Ruma<get_alias::IncomingRequest>,
|
||||
) -> ConduitResult<get_alias::Response> {
|
||||
if body.room_alias.server_name() != db.globals.server_name() {
|
||||
todo!("ask remote server");
|
||||
|
|
|
@ -27,7 +27,7 @@ use rocket::{get, post, put};
|
|||
)]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms_filtered::Request>,
|
||||
body: Ruma<get_public_rooms_filtered::IncomingRequest>,
|
||||
) -> ConduitResult<get_public_rooms_filtered::Response> {
|
||||
let limit = body.limit.map_or(10, u64::from);
|
||||
let mut since = 0_u64;
|
||||
|
@ -224,11 +224,11 @@ pub async fn get_public_rooms_filtered_route(
|
|||
)]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms::Request>,
|
||||
body: Ruma<get_public_rooms::IncomingRequest>,
|
||||
) -> ConduitResult<get_public_rooms::Response> {
|
||||
let Ruma {
|
||||
body:
|
||||
get_public_rooms::Request {
|
||||
get_public_rooms::IncomingRequest {
|
||||
limit,
|
||||
server,
|
||||
since,
|
||||
|
@ -246,7 +246,7 @@ pub async fn get_public_rooms_route(
|
|||
} = get_public_rooms_filtered_route(
|
||||
db,
|
||||
Ruma {
|
||||
body: get_public_rooms_filtered::Request {
|
||||
body: get_public_rooms_filtered::IncomingRequest {
|
||||
filter: None,
|
||||
limit,
|
||||
room_network: get_public_rooms_filtered::RoomNetwork::Matrix,
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
use super::State;
|
||||
use super::SESSION_ID_LENGTH;
|
||||
use super::{State, SESSION_ID_LENGTH};
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::{
|
||||
keys::{
|
||||
self, claim_keys, get_key_changes, get_keys, upload_keys, upload_signatures,
|
||||
upload_signing_keys,
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
r0::{
|
||||
keys::{
|
||||
claim_keys, get_key_changes, get_keys, upload_keys, upload_signatures,
|
||||
upload_signing_keys,
|
||||
},
|
||||
uiaa::{AuthFlow, UiaaInfo},
|
||||
},
|
||||
uiaa::{AuthFlow, UiaaInfo},
|
||||
},
|
||||
encryption::UnsignedDeviceInfo,
|
||||
};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
|
@ -54,7 +56,7 @@ pub fn upload_keys_route(
|
|||
)]
|
||||
pub fn get_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_keys::Request>,
|
||||
body: Ruma<get_keys::IncomingRequest>,
|
||||
) -> ConduitResult<get_keys::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -76,7 +78,7 @@ pub fn get_keys_route(
|
|||
Error::bad_database("all_device_keys contained nonexistent device.")
|
||||
})?;
|
||||
|
||||
keys.unsigned = Some(keys::UnsignedDeviceInfo {
|
||||
keys.unsigned = Some(UnsignedDeviceInfo {
|
||||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
|
@ -95,7 +97,7 @@ pub fn get_keys_route(
|
|||
),
|
||||
)?;
|
||||
|
||||
keys.unsigned = Some(keys::UnsignedDeviceInfo {
|
||||
keys.unsigned = Some(UnsignedDeviceInfo {
|
||||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
|
@ -278,7 +280,7 @@ pub fn upload_signatures_route(
|
|||
)]
|
||||
pub fn get_key_changes_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_key_changes::Request>,
|
||||
body: Ruma<get_key_changes::IncomingRequest>,
|
||||
) -> ConduitResult<get_key_changes::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ use rocket::{get, post};
|
|||
)]
|
||||
pub fn join_room_by_id_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<join_room_by_id::Request>,
|
||||
body: Ruma<join_room_by_id::IncomingRequest>,
|
||||
) -> ConduitResult<join_room_by_id::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -76,7 +76,7 @@ pub fn join_room_by_id_or_alias_route(
|
|||
sender_id: body.sender_id.clone(),
|
||||
device_id: body.device_id.clone(),
|
||||
json_body: None,
|
||||
body: join_room_by_id::Request {
|
||||
body: join_room_by_id::IncomingRequest {
|
||||
room_id,
|
||||
third_party_signed: body.third_party_signed.clone(),
|
||||
},
|
||||
|
@ -94,7 +94,7 @@ pub fn join_room_by_id_or_alias_route(
|
|||
)]
|
||||
pub fn leave_room_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<leave_room::Request>,
|
||||
body: Ruma<leave_room::IncomingRequest>,
|
||||
) -> ConduitResult<leave_room::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::State;
|
|||
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::message::{create_message_event, get_message_events},
|
||||
r0::message::{get_message_events, send_message_event},
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
||||
|
@ -13,10 +13,10 @@ use rocket::{get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/send/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
pub fn create_message_event_route(
|
||||
pub fn send_message_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_message_event::Request>,
|
||||
) -> ConduitResult<create_message_event::Response> {
|
||||
body: Ruma<send_message_event::IncomingRequest>,
|
||||
) -> ConduitResult<send_message_event::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let mut unsigned = serde_json::Map::new();
|
||||
|
@ -41,7 +41,7 @@ pub fn create_message_event_route(
|
|||
&db.account_data,
|
||||
)?;
|
||||
|
||||
Ok(create_message_event::Response { event_id }.into())
|
||||
Ok(send_message_event::Response { event_id }.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -4,8 +4,8 @@ use ruma::{
|
|||
api::client::{
|
||||
error::ErrorKind,
|
||||
r0::state::{
|
||||
create_state_event_for_empty_key, create_state_event_for_key, get_state_events,
|
||||
get_state_events_for_empty_key, get_state_events_for_key,
|
||||
get_state_events, get_state_events_for_empty_key, get_state_events_for_key,
|
||||
send_state_event_for_empty_key, send_state_event_for_key,
|
||||
},
|
||||
},
|
||||
events::{room::canonical_alias, EventType},
|
||||
|
@ -19,10 +19,10 @@ use rocket::{get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
pub fn create_state_event_for_key_route(
|
||||
pub fn send_state_event_for_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_state_event_for_key::Request>,
|
||||
) -> ConduitResult<create_state_event_for_key::Response> {
|
||||
body: Ruma<send_state_event_for_key::IncomingRequest>,
|
||||
) -> ConduitResult<send_state_event_for_key::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let content = serde_json::from_str::<serde_json::Value>(
|
||||
|
@ -78,21 +78,21 @@ pub fn create_state_event_for_key_route(
|
|||
&db.account_data,
|
||||
)?;
|
||||
|
||||
Ok(create_state_event_for_key::Response { event_id }.into())
|
||||
Ok(send_state_event_for_key::Response { event_id }.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
|
||||
)]
|
||||
pub fn create_state_event_for_empty_key_route(
|
||||
pub fn send_state_event_for_empty_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_state_event_for_empty_key::Request>,
|
||||
) -> ConduitResult<create_state_event_for_empty_key::Response> {
|
||||
// This just calls create_state_event_for_key_route
|
||||
body: Ruma<send_state_event_for_empty_key::IncomingRequest>,
|
||||
) -> ConduitResult<send_state_event_for_empty_key::Response> {
|
||||
// This just calls send_state_event_for_key_route
|
||||
let Ruma {
|
||||
body:
|
||||
create_state_event_for_empty_key::Request {
|
||||
send_state_event_for_empty_key::IncomingRequest {
|
||||
room_id,
|
||||
event_type,
|
||||
data,
|
||||
|
@ -102,11 +102,11 @@ pub fn create_state_event_for_empty_key_route(
|
|||
json_body,
|
||||
} = body;
|
||||
|
||||
Ok(create_state_event_for_empty_key::Response {
|
||||
event_id: create_state_event_for_key_route(
|
||||
Ok(send_state_event_for_empty_key::Response {
|
||||
event_id: send_state_event_for_key_route(
|
||||
db,
|
||||
Ruma {
|
||||
body: create_state_event_for_key::Request {
|
||||
body: send_state_event_for_key::IncomingRequest {
|
||||
room_id,
|
||||
event_type,
|
||||
data,
|
||||
|
|
|
@ -14,7 +14,7 @@ use rocket::put;
|
|||
)]
|
||||
pub fn send_event_to_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<send_event_to_device::Request>,
|
||||
body: Ruma<send_event_to_device::IncomingRequest>,
|
||||
) -> ConduitResult<send_event_to_device::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
|
|
@ -11,13 +11,9 @@ use rocket::post;
|
|||
)]
|
||||
pub fn search_users_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<search_users::Request>,
|
||||
body: Ruma<search_users::IncomingRequest>,
|
||||
) -> ConduitResult<search_users::Response> {
|
||||
let limit = if let Some(limit) = body.limit {
|
||||
u64::from(limit)
|
||||
} else {
|
||||
10
|
||||
} as usize;
|
||||
let limit = u64::from(body.limit) as usize;
|
||||
|
||||
let mut users = db.users.iter().filter_map(|user_id| {
|
||||
// Filter out buggy users (they should not exist, but you never know...)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::{ConduitResult, Error};
|
||||
use ruma::api::client::{error::ErrorKind, r0::message::create_message_event};
|
||||
use ruma::api::client::{error::ErrorKind, r0::message::send_message_event};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::get;
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/voip/turnServer"))]
|
||||
pub fn turn_server_route() -> ConduitResult<create_message_event::Response> {
|
||||
pub fn turn_server_route() -> ConduitResult<send_message_event::Response> {
|
||||
Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"There is no turn server yet.",
|
||||
|
|
|
@ -5,11 +5,12 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
r0::{
|
||||
device::Device,
|
||||
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
|
||||
keys::{CrossSigningKey, OneTimeKey},
|
||||
},
|
||||
},
|
||||
encryption::DeviceKeys,
|
||||
events::{AnyToDeviceEvent, EventType},
|
||||
DeviceId, Raw, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, Raw, UserId,
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime};
|
||||
|
||||
|
@ -21,7 +22,7 @@ pub struct Users {
|
|||
pub(super) userdeviceid_metadata: sled::Tree, // This is also used to check if a device exists
|
||||
pub(super) token_userdeviceid: sled::Tree,
|
||||
|
||||
pub(super) onetimekeyid_onetimekeys: sled::Tree, // OneTimeKeyId = UserId + AlgorithmAndDeviceId
|
||||
pub(super) onetimekeyid_onetimekeys: sled::Tree, // OneTimeKeyId = UserId + DeviceKeyId
|
||||
pub(super) userid_lastonetimekeyupdate: sled::Tree, // LastOneTimeKeyUpdate = Count
|
||||
pub(super) keychangeid_userid: sled::Tree, // KeyChangeId = UserId/RoomId + Count
|
||||
pub(super) keyid_key: sled::Tree, // KeyId = UserId + KeyId (depends on key type)
|
||||
|
@ -269,7 +270,7 @@ impl Users {
|
|||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
one_time_key_key: &AlgorithmAndDeviceId,
|
||||
one_time_key_key: &DeviceKeyId,
|
||||
one_time_key_value: &OneTimeKey,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
|
@ -282,11 +283,11 @@ impl Users {
|
|||
assert!(self.userdeviceid_metadata.get(&key)?.is_some());
|
||||
|
||||
key.push(0xff);
|
||||
// TODO: Use AlgorithmAndDeviceId::to_string when it's available (and update everything,
|
||||
// TODO: Use DeviceKeyId::to_string when it's available (and update everything,
|
||||
// because there are no wrapping quotation marks anymore)
|
||||
key.extend_from_slice(
|
||||
&serde_json::to_string(one_time_key_key)
|
||||
.expect("AlgorithmAndDeviceId::to_string always works")
|
||||
.expect("DeviceKeyId::to_string always works")
|
||||
.as_bytes(),
|
||||
);
|
||||
|
||||
|
@ -319,9 +320,9 @@ impl Users {
|
|||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
key_algorithm: &KeyAlgorithm,
|
||||
key_algorithm: &DeviceKeyAlgorithm,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
|
||||
) -> Result<Option<(DeviceKeyId, OneTimeKey)>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(device_id.as_bytes());
|
||||
|
@ -361,7 +362,7 @@ impl Users {
|
|||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
|
||||
) -> Result<BTreeMap<DeviceKeyAlgorithm, UInt>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
@ -374,13 +375,13 @@ impl Users {
|
|||
.keys()
|
||||
.map(|bytes| {
|
||||
Ok::<_, Error>(
|
||||
serde_json::from_slice::<AlgorithmAndDeviceId>(
|
||||
serde_json::from_slice::<DeviceKeyId>(
|
||||
&*bytes?.rsplit(|&b| b == 0xff).next().ok_or_else(|| {
|
||||
Error::bad_database("OneTimeKey ID in db is invalid.")
|
||||
})?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("AlgorithmAndDeviceID in db is invalid."))?
|
||||
.0,
|
||||
.map_err(|_| Error::bad_database("DeviceKeyId in db is invalid."))?
|
||||
.algorithm(),
|
||||
)
|
||||
})
|
||||
{
|
||||
|
|
|
@ -81,9 +81,9 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
client_server::search_users_route,
|
||||
client_server::get_member_events_route,
|
||||
client_server::get_protocols_route,
|
||||
client_server::create_message_event_route,
|
||||
client_server::create_state_event_for_key_route,
|
||||
client_server::create_state_event_for_empty_key_route,
|
||||
client_server::send_message_event_route,
|
||||
client_server::send_state_event_for_key_route,
|
||||
client_server::send_state_event_for_empty_key_route,
|
||||
client_server::get_state_events_route,
|
||||
client_server::get_state_events_for_key_route,
|
||||
client_server::get_state_events_for_empty_key_route,
|
||||
|
|
|
@ -16,7 +16,7 @@ use {
|
|||
tokio::io::AsyncReadExt,
|
||||
Request, State,
|
||||
},
|
||||
ruma::api::Endpoint,
|
||||
ruma::api::IncomingRequest,
|
||||
std::io::Cursor,
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub struct Ruma<T> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
|
||||
impl<'a, T: IncomingRequest> FromTransformedData<'a> for Ruma<T> {
|
||||
type Error = (); // TODO: Better error handling
|
||||
type Owned = Data;
|
||||
type Borrowed = Self::Owned;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue