Merge branch 'tests' into 'next'
Bug fixes See merge request famedly/conduit!278
This commit is contained in:
commit
b4755ba15b
5 changed files with 51 additions and 43 deletions
|
@ -60,15 +60,16 @@ pub async fn get_register_available_route(
|
||||||
body: Ruma<get_username_availability::Request<'_>>,
|
body: Ruma<get_username_availability::Request<'_>>,
|
||||||
) -> ConduitResult<get_username_availability::Response> {
|
) -> ConduitResult<get_username_availability::Response> {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = UserId::parse_with_server_name(body.username.clone(), db.globals.server_name())
|
let user_id =
|
||||||
.ok()
|
UserId::parse_with_server_name(body.username.to_lowercase(), db.globals.server_name())
|
||||||
.filter(|user_id| {
|
.ok()
|
||||||
!user_id.is_historical() && user_id.server_name() == db.globals.server_name()
|
.filter(|user_id| {
|
||||||
})
|
!user_id.is_historical() && user_id.server_name() == db.globals.server_name()
|
||||||
.ok_or(Error::BadRequest(
|
})
|
||||||
ErrorKind::InvalidUsername,
|
.ok_or(Error::BadRequest(
|
||||||
"Username is invalid.",
|
ErrorKind::InvalidUsername,
|
||||||
))?;
|
"Username is invalid.",
|
||||||
|
))?;
|
||||||
|
|
||||||
// Check if username is creative enough
|
// Check if username is creative enough
|
||||||
if db.users.exists(&user_id)? {
|
if db.users.exists(&user_id)? {
|
||||||
|
|
|
@ -655,7 +655,7 @@ async fn join_room_by_id_helper(
|
||||||
|
|
||||||
db.rooms.get_or_create_shortroomid(room_id, &db.globals)?;
|
db.rooms.get_or_create_shortroomid(room_id, &db.globals)?;
|
||||||
|
|
||||||
let pdu = PduEvent::from_id_val(event_id, join_event.clone())
|
let parsed_pdu = PduEvent::from_id_val(event_id, join_event.clone())
|
||||||
.map_err(|_| Error::BadServerResponse("Invalid join event PDU."))?;
|
.map_err(|_| Error::BadServerResponse("Invalid join event PDU."))?;
|
||||||
|
|
||||||
let mut state = HashMap::new();
|
let mut state = HashMap::new();
|
||||||
|
@ -695,14 +695,15 @@ async fn join_room_by_id_helper(
|
||||||
}
|
}
|
||||||
|
|
||||||
let incoming_shortstatekey = db.rooms.get_or_create_shortstatekey(
|
let incoming_shortstatekey = db.rooms.get_or_create_shortstatekey(
|
||||||
&pdu.kind,
|
&parsed_pdu.kind,
|
||||||
pdu.state_key
|
parsed_pdu
|
||||||
|
.state_key
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Pdu is a membership state event"),
|
.expect("Pdu is a membership state event"),
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
state.insert(incoming_shortstatekey, pdu.event_id.clone());
|
state.insert(incoming_shortstatekey, parsed_pdu.event_id.clone());
|
||||||
|
|
||||||
let create_shortstatekey = db
|
let create_shortstatekey = db
|
||||||
.rooms
|
.rooms
|
||||||
|
@ -738,12 +739,12 @@ async fn join_room_by_id_helper(
|
||||||
|
|
||||||
// We append to state before appending the pdu, so we don't have a moment in time with the
|
// We append to state before appending the pdu, so we don't have a moment in time with the
|
||||||
// pdu without it's state. This is okay because append_pdu can't fail.
|
// pdu without it's state. This is okay because append_pdu can't fail.
|
||||||
let statehashid = db.rooms.append_to_state(&pdu, &db.globals)?;
|
let statehashid = db.rooms.append_to_state(&parsed_pdu, &db.globals)?;
|
||||||
|
|
||||||
db.rooms.append_pdu(
|
db.rooms.append_pdu(
|
||||||
&pdu,
|
&parsed_pdu,
|
||||||
utils::to_canonical_object(&pdu).expect("Pdu is valid canonical object"),
|
join_event,
|
||||||
iter::once(&*pdu.event_id),
|
iter::once(&*parsed_pdu.event_id),
|
||||||
db,
|
db,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -344,10 +344,13 @@ pub async fn create_room_route(
|
||||||
|
|
||||||
// 6. Events listed in initial_state
|
// 6. Events listed in initial_state
|
||||||
for event in &body.initial_state {
|
for event in &body.initial_state {
|
||||||
let pdu_builder = PduBuilder::from(event.deserialize().map_err(|e| {
|
let mut pdu_builder = event.deserialize_as::<PduBuilder>().map_err(|e| {
|
||||||
warn!("Invalid initial state event: {:?}", e);
|
warn!("Invalid initial state event: {:?}", e);
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.")
|
Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.")
|
||||||
})?);
|
})?;
|
||||||
|
|
||||||
|
// Implicit state key defaults to ""
|
||||||
|
pdu_builder.state_key.get_or_insert_with(|| "".to_owned());
|
||||||
|
|
||||||
// Silently skip encryption events if they are not allowed
|
// Silently skip encryption events if they are not allowed
|
||||||
if pdu_builder.event_type == EventType::RoomEncryption && !db.globals.allow_encryption() {
|
if pdu_builder.event_type == EventType::RoomEncryption && !db.globals.allow_encryption() {
|
||||||
|
|
|
@ -49,6 +49,8 @@ pub struct Config {
|
||||||
database_path: String,
|
database_path: String,
|
||||||
#[serde(default = "default_db_cache_capacity_mb")]
|
#[serde(default = "default_db_cache_capacity_mb")]
|
||||||
db_cache_capacity_mb: f64,
|
db_cache_capacity_mb: f64,
|
||||||
|
#[serde(default = "default_conduit_cache_capacity_modifier")]
|
||||||
|
conduit_cache_capacity_modifier: f64,
|
||||||
#[serde(default = "default_rocksdb_max_open_files")]
|
#[serde(default = "default_rocksdb_max_open_files")]
|
||||||
rocksdb_max_open_files: i32,
|
rocksdb_max_open_files: i32,
|
||||||
#[serde(default = "default_pdu_cache_capacity")]
|
#[serde(default = "default_pdu_cache_capacity")]
|
||||||
|
@ -129,8 +131,12 @@ fn default_db_cache_capacity_mb() -> f64 {
|
||||||
10.0
|
10.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_conduit_cache_capacity_modifier() -> f64 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
|
|
||||||
fn default_rocksdb_max_open_files() -> i32 {
|
fn default_rocksdb_max_open_files() -> i32 {
|
||||||
512
|
20
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_pdu_cache_capacity() -> u32 {
|
fn default_pdu_cache_capacity() -> u32 {
|
||||||
|
@ -361,15 +367,27 @@ impl Database {
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("pdu cache capacity fits into usize"),
|
.expect("pdu cache capacity fits into usize"),
|
||||||
)),
|
)),
|
||||||
auth_chain_cache: Mutex::new(LruCache::new(1_000_000)),
|
auth_chain_cache: Mutex::new(LruCache::new(
|
||||||
shorteventid_cache: Mutex::new(LruCache::new(1_000_000)),
|
(100_000.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
eventidshort_cache: Mutex::new(LruCache::new(1_000_000)),
|
)),
|
||||||
shortstatekey_cache: Mutex::new(LruCache::new(1_000_000)),
|
shorteventid_cache: Mutex::new(LruCache::new(
|
||||||
statekeyshort_cache: Mutex::new(LruCache::new(1_000_000)),
|
(100_000.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
|
)),
|
||||||
|
eventidshort_cache: Mutex::new(LruCache::new(
|
||||||
|
(100_000.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
|
)),
|
||||||
|
shortstatekey_cache: Mutex::new(LruCache::new(
|
||||||
|
(100_000.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
|
)),
|
||||||
|
statekeyshort_cache: Mutex::new(LruCache::new(
|
||||||
|
(100_000.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
|
)),
|
||||||
our_real_users_cache: RwLock::new(HashMap::new()),
|
our_real_users_cache: RwLock::new(HashMap::new()),
|
||||||
appservice_in_room_cache: RwLock::new(HashMap::new()),
|
appservice_in_room_cache: RwLock::new(HashMap::new()),
|
||||||
lazy_load_waiting: Mutex::new(HashMap::new()),
|
lazy_load_waiting: Mutex::new(HashMap::new()),
|
||||||
stateinfo_cache: Mutex::new(LruCache::new(1000)),
|
stateinfo_cache: Mutex::new(LruCache::new(
|
||||||
|
(100.0 * config.conduit_cache_capacity_modifier) as usize,
|
||||||
|
)),
|
||||||
},
|
},
|
||||||
account_data: account_data::AccountData {
|
account_data: account_data::AccountData {
|
||||||
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
||||||
|
|
19
src/pdu.rs
19
src/pdu.rs
|
@ -1,9 +1,8 @@
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{
|
events::{
|
||||||
room::member::RoomMemberEventContent, AnyEphemeralRoomEvent, AnyInitialStateEvent,
|
room::member::RoomMemberEventContent, AnyEphemeralRoomEvent, AnyRoomEvent, AnyStateEvent,
|
||||||
AnyRoomEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent,
|
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
||||||
EventType, StateEvent,
|
|
||||||
},
|
},
|
||||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||||
state_res, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, UInt, UserId,
|
state_res, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, UInt, UserId,
|
||||||
|
@ -361,17 +360,3 @@ pub struct PduBuilder {
|
||||||
pub state_key: Option<String>,
|
pub state_key: Option<String>,
|
||||||
pub redacts: Option<Arc<EventId>>,
|
pub redacts: Option<Arc<EventId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Direct conversion prevents loss of the empty `state_key` that ruma requires.
|
|
||||||
impl From<AnyInitialStateEvent> for PduBuilder {
|
|
||||||
fn from(event: AnyInitialStateEvent) -> Self {
|
|
||||||
Self {
|
|
||||||
event_type: EventType::from(event.event_type()),
|
|
||||||
content: to_raw_value(&event.content())
|
|
||||||
.expect("AnyStateEventContent came from JSON and can thus turn back into JSON."),
|
|
||||||
unsigned: None,
|
|
||||||
state_key: Some(event.state_key().to_owned()),
|
|
||||||
redacts: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue