fix: ruma

next
Timo Kösters 2021-07-15 19:54:04 +02:00
parent d07762f596
commit 0fcefa4125
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
8 changed files with 115 additions and 66 deletions

23
Cargo.lock generated
View File

@ -2015,7 +2015,6 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"assign",
"js_int",
@ -2036,7 +2035,6 @@ dependencies = [
[[package]]
name = "ruma-api"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"bytes",
"http",
@ -2052,7 +2050,6 @@ dependencies = [
[[package]]
name = "ruma-api-macros"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@ -2063,7 +2060,6 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"ruma-api",
"ruma-common",
@ -2077,7 +2073,6 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.11.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"assign",
"bytes",
@ -2097,7 +2092,6 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.5.4"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"indexmap",
"js_int",
@ -2111,8 +2105,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.23.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
version = "0.23.2"
dependencies = [
"indoc",
"js_int",
@ -2122,12 +2115,12 @@ dependencies = [
"ruma-serde",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "ruma-events-macros"
version = "0.23.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
version = "0.23.2"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@ -2138,7 +2131,6 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"js_int",
"ruma-api",
@ -2153,7 +2145,6 @@ dependencies = [
[[package]]
name = "ruma-identifiers"
version = "0.19.4"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"paste",
"rand 0.8.4",
@ -2167,7 +2158,6 @@ dependencies = [
[[package]]
name = "ruma-identifiers-macros"
version = "0.19.4"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"quote",
"ruma-identifiers-validation",
@ -2177,12 +2167,10 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
[[package]]
name = "ruma-identity-service-api"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"js_int",
"ruma-api",
@ -2195,7 +2183,6 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"js_int",
"ruma-api",
@ -2210,7 +2197,6 @@ dependencies = [
[[package]]
name = "ruma-serde"
version = "0.4.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"bytes",
"form_urlencoded",
@ -2224,7 +2210,6 @@ dependencies = [
[[package]]
name = "ruma-serde-macros"
version = "0.4.1"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@ -2235,7 +2220,6 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.8.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"base64 0.13.0",
"ed25519-dalek",
@ -2252,7 +2236,6 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
dependencies = [
"itertools 0.10.1",
"js_int",

View File

@ -18,8 +18,8 @@ edition = "2018"
rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests
# Used for matrix spec type definitions and helpers
ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
# Used for long polling and federation sender, should be the same as rocket::tokio
tokio = "1.2.0"
@ -119,5 +119,5 @@ maintainer-scripts = "debian/"
systemd-units = { unit-name = "matrix-conduit" }
# For flamegraphs:
#[profile.release]
#debug = true
[profile.release]
debug = true

View File

@ -1,4 +1,8 @@
use std::{collections::BTreeMap, convert::TryInto, sync::Arc};
use std::{
collections::BTreeMap,
convert::{TryFrom, TryInto},
sync::Arc,
};
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
@ -16,7 +20,8 @@ use ruma::{
},
events::{
room::{
canonical_alias, guest_access, history_visibility, join_rules, member, message, name,
canonical_alias, guest_access, history_visibility, join_rules, member, message,
name::{self, RoomName},
topic,
},
EventType,
@ -375,11 +380,9 @@ pub async fn register_route(
db.rooms.build_and_append_pdu(
PduBuilder {
event_type: EventType::RoomName,
content: serde_json::to_value(
name::NameEventContent::new("Admin Room".to_owned()).map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.")
})?,
)
content: serde_json::to_value(name::NameEventContent::new(Some(
RoomName::try_from("Admin Room".to_owned()).expect("Room name is valid"),
)))
.expect("event is valid, we just created it"),
unsigned: None,
state_key: Some("".to_owned()),

View File

@ -87,17 +87,17 @@ pub async fn set_room_visibility_route(
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
match &body.visibility {
room::Visibility::_Custom(_s) => {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room visibility type is not supported.",
));
}
room::Visibility::Public => {
db.rooms.set_public(&body.room_id, true)?;
info!("{} made {} public", sender_user, body.room_id);
}
room::Visibility::Private => db.rooms.set_public(&body.room_id, false)?,
_ => {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room visibility type is not supported.",
));
}
}
db.flush().await?;
@ -231,8 +231,8 @@ pub async fn get_public_rooms_filtered_helper(
.map_err(|_| {
Error::bad_database("Invalid room name event in database.")
})?
.name()
.map(|n| n.to_owned()))
.name
.map(|n| n.to_owned().into()))
})?,
num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(),
topic: db

View File

@ -81,7 +81,7 @@ pub async fn get_pushrule_route(
.content
.get(body.rule_id.as_str())
.map(|rule| rule.clone().into()),
RuleKind::_Custom(_) => None,
_ => None,
};
if let Some(rule) = rule {
@ -181,7 +181,7 @@ pub async fn set_pushrule_route(
.into(),
);
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(
@ -245,7 +245,7 @@ pub async fn get_pushrule_actions_route(
.content
.get(body.rule_id.as_str())
.map(|rule| rule.actions.clone()),
RuleKind::_Custom(_) => None,
_ => None,
};
db.flush().await?;
@ -314,7 +314,7 @@ pub async fn set_pushrule_actions_route(
global.content.replace(rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
};
db.account_data.update(
@ -383,7 +383,7 @@ pub async fn get_pushrule_enabled_route(
.iter()
.find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.enabled),
RuleKind::_Custom(_) => false,
_ => false,
};
db.flush().await?;
@ -454,7 +454,7 @@ pub async fn set_pushrule_enabled_route(
global.content.insert(rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(
@ -523,7 +523,7 @@ pub async fn delete_pushrule_route(
global.content.remove(&rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(

View File

@ -9,7 +9,11 @@ use ruma::{
r0::room::{self, create_room, get_room_event, upgrade_room},
},
events::{
room::{guest_access, history_visibility, join_rules, member, name, topic},
room::{
guest_access, history_visibility, join_rules, member,
name::{self, RoomName},
topic,
},
EventType,
},
serde::Raw,
@ -113,7 +117,7 @@ pub async fn create_room_route(
.unwrap_or_else(|| match &body.visibility {
room::Visibility::Private => create_room::RoomPreset::PrivateChat,
room::Visibility::Public => create_room::RoomPreset::PublicChat,
room::Visibility::_Custom(_) => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
_ => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
});
let mut users = BTreeMap::new();
@ -251,11 +255,11 @@ pub async fn create_room_route(
db.rooms.build_and_append_pdu(
PduBuilder {
event_type: EventType::RoomName,
content: serde_json::to_value(
name::NameEventContent::new(name.clone()).map_err(|_| {
content: serde_json::to_value(name::NameEventContent::new(Some(
RoomName::try_from(name.clone()).map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.")
})?,
)
)))
.expect("event is valid, we just created it"),
unsigned: None,
state_key: Some("".to_owned()),

View File

@ -490,6 +490,27 @@ impl Rooms {
.transpose()
}
/// Returns the json of a pdu.
pub fn get_non_outlier_pdu_json(
&self,
event_id: &EventId,
) -> Result<Option<CanonicalJsonObject>> {
self.eventid_pduid
.get(event_id.as_bytes())?
.map_or_else::<Result<_>, _, _>(
|| Ok(None),
|pduid| {
Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| {
Error::bad_database("Invalid pduid in eventid_pduid.")
})?))
},
)?
.map(|pdu| {
serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db."))
})
.transpose()
}
/// Returns the pdu's id.
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> {
self.eventid_pduid
@ -903,11 +924,59 @@ impl Rooms {
"list_appservices" => {
db.admin.send(AdminCommand::ListAppservices);
}
"get_pdu" => {
if args.len() == 1 {
if let Ok(event_id) = EventId::try_from(args[0]) {
let mut outlier = false;
let mut pdu_json =
db.rooms.get_non_outlier_pdu_json(&event_id)?;
if pdu_json.is_none() {
outlier = true;
pdu_json = db.rooms.get_pdu_json(&event_id)?;
}
match pdu_json {
Some(json) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_html(
format!("{}\n```json\n{:#?}\n```",
if outlier {
"PDU is outlier"
} else { "PDU was accepted"}, json),
format!("<p>{}</p>\n<pre><code class=\"language-json\">{}\n</code></pre>\n",
if outlier {
"PDU is outlier"
} else { "PDU was accepted"}, serde_json::to_string_pretty(&json).expect("canonical json is valid json"))
),
));
}
None => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
"PDU not found.",
),
));
}
}
} else {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
"Event ID could not be parsed.",
),
));
}
} else {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
"Usage: get_pdu <eventid>",
),
));
}
}
_ => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(format!(
"Command: {}, Args: {:?}",
command, args
"Unrecognized command: {}",
command
)),
));
}

View File

@ -1254,15 +1254,6 @@ pub fn handle_incoming_pdu<'a>(
// We do need to force an update to this room's state
update_state = true;
let mut auth_events = vec![];
for map in &fork_states {
let state_auth = map
.values()
.flat_map(|pdu| pdu.auth_events.clone())
.collect();
auth_events.push(state_auth);
}
match state_res::StateResolution::resolve(
&room_id,
room_version_id,
@ -1274,8 +1265,7 @@ pub fn handle_incoming_pdu<'a>(
.collect::<StateMap<_>>()
})
.collect::<Vec<_>>(),
auth_events,
&|id| {
|id| {
let res = db.rooms.get_pdu(id);
if let Err(e) = &res {
error!("LOOK AT ME Failed to fetch event: {}", e);
@ -2432,10 +2422,10 @@ pub fn get_profile_information_route(
let mut avatar_url = None;
match &body.field {
// TODO: what to do with custom
Some(ProfileField::_Custom(_s)) => {}
Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?,
Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?,
// TODO: what to do with custom
Some(_) => {}
None => {
displayname = db.users.displayname(&body.user_id)?;
avatar_url = db.users.avatar_url(&body.user_id)?;