mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
stop putting comments and code on the same line
This commit is contained in:
parent
0915aba44c
commit
1911ad34d9
35 changed files with 305 additions and 142 deletions
|
|
@ -80,10 +80,11 @@ where
|
||||||
.expect("http::response::Builder is usable"),
|
.expect("http::response::Builder is usable"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: handle timeout
|
||||||
let body = response.bytes().await.unwrap_or_else(|e| {
|
let body = response.bytes().await.unwrap_or_else(|e| {
|
||||||
warn!("server error: {}", e);
|
warn!("server error: {}", e);
|
||||||
Vec::new().into()
|
Vec::new().into()
|
||||||
}); // TODO: handle timeout
|
});
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,8 @@ pub(crate) async fn upload_signing_keys_route(
|
||||||
master_key,
|
master_key,
|
||||||
&body.self_signing_key,
|
&body.self_signing_key,
|
||||||
&body.user_signing_key,
|
&body.user_signing_key,
|
||||||
true, // notify so that other users see the new keys
|
// notify so that other users see the new keys
|
||||||
|
true,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +197,8 @@ pub(crate) async fn upload_signatures_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_signatures::v3::Response {
|
Ok(upload_signatures::v3::Response {
|
||||||
failures: BTreeMap::new(), // TODO: integrate
|
// TODO: integrate
|
||||||
|
failures: BTreeMap::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +254,8 @@ pub(crate) async fn get_key_changes_route(
|
||||||
}
|
}
|
||||||
Ok(get_key_changes::v3::Response {
|
Ok(get_key_changes::v3::Response {
|
||||||
changed: device_list_updates.into_iter().collect(),
|
changed: device_list_updates.into_iter().collect(),
|
||||||
left: Vec::new(), // TODO
|
// TODO
|
||||||
|
left: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +425,8 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
|
||||||
let raw = serde_json::from_value(json).expect("Raw::from_value always works");
|
let raw = serde_json::from_value(json).expect("Raw::from_value always works");
|
||||||
services().users.add_cross_signing_keys(
|
services().users.add_cross_signing_keys(
|
||||||
&user, &raw, &None, &None,
|
&user, &raw, &None, &None,
|
||||||
false, // Dont notify. A notification would trigger another key request resulting in an endless loop
|
// Dont notify. A notification would trigger another key request resulting in an endless loop
|
||||||
|
false,
|
||||||
)?;
|
)?;
|
||||||
master_keys.insert(user, raw);
|
master_keys.insert(user, raw);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ pub(crate) async fn join_room_by_id_route(
|
||||||
) -> Result<join_room_by_id::v3::Response> {
|
) -> Result<join_room_by_id::v3::Response> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut servers = Vec::new(); // There is no body.server_name for /roomId/join
|
// There is no body.server_name for /roomId/join
|
||||||
|
let mut servers = Vec::new();
|
||||||
servers.extend(
|
servers.extend(
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
@ -1012,7 +1013,8 @@ async fn join_room_by_id_helper(
|
||||||
let authenticated = state_res::event_auth::auth_check(
|
let authenticated = state_res::event_auth::auth_check(
|
||||||
&state_res::RoomVersion::new(&room_version_id).expect("room version is supported"),
|
&state_res::RoomVersion::new(&room_version_id).expect("room version is supported"),
|
||||||
&parsed_join_pdu,
|
&parsed_join_pdu,
|
||||||
None::<PduEvent>, // TODO: third party invite
|
// TODO: third party invite
|
||||||
|
None::<PduEvent>,
|
||||||
|k, s| {
|
|k, s| {
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,8 @@ pub(crate) async fn create_room_route(
|
||||||
})?,
|
})?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RoomVersionId::V11 => {} // V11 removed the "creator" key
|
// V11 removed the "creator" key
|
||||||
|
RoomVersionId::V11 => {}
|
||||||
_ => unreachable!("Validity of room version already checked"),
|
_ => unreachable!("Validity of room version already checked"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -790,7 +791,8 @@ pub(crate) async fn upgrade_room_route(
|
||||||
.room_state_get(&body.room_id, &event_type, "")?
|
.room_state_get(&body.room_id, &event_type, "")?
|
||||||
{
|
{
|
||||||
Some(v) => v.content.clone(),
|
Some(v) => v.content.clone(),
|
||||||
None => continue, // Skipping missing events.
|
// Skipping missing events.
|
||||||
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
services()
|
services()
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,8 @@ pub(crate) async fn search_events_route(
|
||||||
"Invalid next_batch token.",
|
"Invalid next_batch token.",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
None => 0, // Default to the start
|
// Default to the start
|
||||||
|
None => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
|
|
@ -133,10 +134,12 @@ pub(crate) async fn search_events_route(
|
||||||
Ok(search_events::v3::Response::new(ResultCategories {
|
Ok(search_events::v3::Response::new(ResultCategories {
|
||||||
room_events: ResultRoomEvents {
|
room_events: ResultRoomEvents {
|
||||||
count: None,
|
count: None,
|
||||||
groups: BTreeMap::new(), // TODO
|
// TODO
|
||||||
|
groups: BTreeMap::new(),
|
||||||
next_batch,
|
next_batch,
|
||||||
results,
|
results,
|
||||||
state: BTreeMap::new(), // TODO
|
// TODO
|
||||||
|
state: BTreeMap::new(),
|
||||||
highlights: search_criteria
|
highlights: search_criteria
|
||||||
.search_term
|
.search_term
|
||||||
.split_terminator(|c: char| !c.is_alphanumeric())
|
.split_terminator(|c: char| !c.is_alphanumeric())
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ pub(crate) async fn send_state_event_for_key_route(
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&body.event_type,
|
&body.event_type,
|
||||||
&body.body.body, // Yes, I hate it too
|
// Yes, I hate it too
|
||||||
|
&body.body.body,
|
||||||
body.state_key.clone(),
|
body.state_key.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -210,7 +211,8 @@ async fn send_state_event_for_key_helper(
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.resolve_local_alias(&alias)?
|
.resolve_local_alias(&alias)?
|
||||||
.filter(|room| room == room_id) // Make sure it's the right room
|
// Make sure it's the right room
|
||||||
|
.filter(|room| room == room_id)
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,8 @@ async fn sync_helper(
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
let sincecount = PduCount::Normal(since);
|
let sincecount = PduCount::Normal(since);
|
||||||
|
|
||||||
let mut left_encrypted_users = HashSet::new(); // Users that have left any encrypted rooms the sender was in
|
// Users that have left any encrypted rooms the sender was in
|
||||||
|
let mut left_encrypted_users = HashSet::new();
|
||||||
let mut device_list_updates = HashSet::new();
|
let mut device_list_updates = HashSet::new();
|
||||||
let mut device_list_left = HashSet::new();
|
let mut device_list_left = HashSet::new();
|
||||||
|
|
||||||
|
|
@ -492,7 +493,8 @@ async fn sync_helper(
|
||||||
leave: left_rooms,
|
leave: left_rooms,
|
||||||
join: joined_rooms,
|
join: joined_rooms,
|
||||||
invite: invited_rooms,
|
invite: invited_rooms,
|
||||||
knock: BTreeMap::new(), // TODO
|
// TODO
|
||||||
|
knock: BTreeMap::new(),
|
||||||
},
|
},
|
||||||
presence: Presence::default(),
|
presence: Presence::default(),
|
||||||
account_data: GlobalAccountData {
|
account_data: GlobalAccountData {
|
||||||
|
|
@ -543,7 +545,8 @@ async fn sync_helper(
|
||||||
};
|
};
|
||||||
Ok((response, false))
|
Ok((response, false))
|
||||||
} else {
|
} else {
|
||||||
Ok((response, since != next_batch)) // Only cache if we made progress
|
// Only cache if we made progress
|
||||||
|
Ok((response, since != next_batch))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1201,7 +1204,8 @@ pub(crate) async fn sync_events_v4_route(
|
||||||
.remove_to_device_events(&sender_user, &sender_device, globalsince)?;
|
.remove_to_device_events(&sender_user, &sender_device, globalsince)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut left_encrypted_users = HashSet::new(); // Users that have left any encrypted rooms the sender was in
|
// Users that have left any encrypted rooms the sender was in
|
||||||
|
let mut left_encrypted_users = HashSet::new();
|
||||||
let mut device_list_changes = HashSet::new();
|
let mut device_list_changes = HashSet::new();
|
||||||
let mut device_list_left = HashSet::new();
|
let mut device_list_left = HashSet::new();
|
||||||
|
|
||||||
|
|
@ -1381,7 +1385,8 @@ pub(crate) async fn sync_events_v4_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut lists = BTreeMap::new();
|
let mut lists = BTreeMap::new();
|
||||||
let mut todo_rooms = BTreeMap::new(); // and required state
|
// and required state
|
||||||
|
let mut todo_rooms = BTreeMap::new();
|
||||||
|
|
||||||
for (list_id, list) in body.lists {
|
for (list_id, list) in body.lists {
|
||||||
if list.filters.and_then(|f| f.is_invite).unwrap_or(false) {
|
if list.filters.and_then(|f| f.is_invite).unwrap_or(false) {
|
||||||
|
|
@ -1646,7 +1651,8 @@ pub(crate) async fn sync_events_v4_route(
|
||||||
.map(UInt::new_saturating)
|
.map(UInt::new_saturating)
|
||||||
.unwrap_or(uint!(0)),
|
.unwrap_or(uint!(0)),
|
||||||
),
|
),
|
||||||
num_live: None, // Count events in timeline greater than global sync counter
|
// Count events in timeline greater than global sync counter
|
||||||
|
num_live: None,
|
||||||
timestamp: None,
|
timestamp: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,8 @@ where
|
||||||
|
|
||||||
struct XMatrix {
|
struct XMatrix {
|
||||||
origin: OwnedServerName,
|
origin: OwnedServerName,
|
||||||
key: String, // KeyName?
|
// KeyName?
|
||||||
|
key: String,
|
||||||
sig: String,
|
sig: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,10 +260,11 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
debug!("Getting response bytes from {destination}");
|
debug!("Getting response bytes from {destination}");
|
||||||
|
// TODO: handle timeout
|
||||||
let body = response.bytes().await.unwrap_or_else(|e| {
|
let body = response.bytes().await.unwrap_or_else(|e| {
|
||||||
warn!("server error {}", e);
|
warn!("server error {}", e);
|
||||||
Vec::new().into()
|
Vec::new().into()
|
||||||
}); // TODO: handle timeout
|
});
|
||||||
debug!("Got response bytes from {destination}");
|
debug!("Got response bytes from {destination}");
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
|
|
@ -1555,7 +1556,8 @@ async fn create_join_event(
|
||||||
.filter_map(|(_, id)| services().rooms.timeline.get_pdu_json(id).ok().flatten())
|
.filter_map(|(_, id)| services().rooms.timeline.get_pdu_json(id).ok().flatten())
|
||||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||||
.collect(),
|
.collect(),
|
||||||
event: None, // TODO: handle restricted joins
|
// TODO: handle restricted joins
|
||||||
|
event: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,11 +239,13 @@ fn default_pdu_cache_capacity() -> u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_cleanup_second_interval() -> u32 {
|
fn default_cleanup_second_interval() -> u32 {
|
||||||
60 // every minute
|
// every minute
|
||||||
|
60
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_max_request_size() -> u32 {
|
fn default_max_request_size() -> u32 {
|
||||||
20 * 1024 * 1024 // Default to 20 MB
|
// Default to 20 MB
|
||||||
|
20 * 1024 * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_max_concurrent_requests() -> u16 {
|
fn default_max_concurrent_requests() -> u16 {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ impl ProxyConfig {
|
||||||
ProxyConfig::None => None,
|
ProxyConfig::None => None,
|
||||||
ProxyConfig::Global { url } => Some(Proxy::all(url)?),
|
ProxyConfig::Global { url } => Some(Proxy::all(url)?),
|
||||||
ProxyConfig::ByDomain(proxies) => Some(Proxy::custom(move |url| {
|
ProxyConfig::ByDomain(proxies) => Some(Proxy::custom(move |url| {
|
||||||
proxies.iter().find_map(|proxy| proxy.for_url(url)).cloned() // first matching proxy
|
// first matching proxy
|
||||||
|
proxies.iter().find_map(|proxy| proxy.for_url(url)).cloned()
|
||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -63,8 +64,10 @@ pub(crate) struct PartialProxyConfig {
|
||||||
impl PartialProxyConfig {
|
impl PartialProxyConfig {
|
||||||
pub(crate) fn for_url(&self, url: &Url) -> Option<&Url> {
|
pub(crate) fn for_url(&self, url: &Url) -> Option<&Url> {
|
||||||
let domain = url.domain()?;
|
let domain = url.domain()?;
|
||||||
let mut included_because = None; // most specific reason it was included
|
// most specific reason it was included
|
||||||
let mut excluded_because = None; // most specific reason it was excluded
|
let mut included_because = None;
|
||||||
|
// most specific reason it was excluded
|
||||||
|
let mut excluded_because = None;
|
||||||
if self.include.is_empty() {
|
if self.include.is_empty() {
|
||||||
// treat empty include list as `*`
|
// treat empty include list as `*`
|
||||||
included_because = Some(&WildCardedDomain::WildCard);
|
included_because = Some(&WildCardedDomain::WildCard);
|
||||||
|
|
@ -86,7 +89,8 @@ impl PartialProxyConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match (included_because, excluded_because) {
|
match (included_because, excluded_because) {
|
||||||
(Some(a), Some(b)) if a.more_specific_than(b) => Some(&self.url), // included for a more specific reason than excluded
|
// included for a more specific reason than excluded
|
||||||
|
(Some(a), Some(b)) if a.more_specific_than(b) => Some(&self.url),
|
||||||
(Some(_), None) => Some(&self.url),
|
(Some(_), None) => Some(&self.url),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
147
src/database.rs
147
src/database.rs
|
|
@ -42,77 +42,122 @@ pub(crate) struct KeyValueDatabase {
|
||||||
pub(super) userid_avatarurl: Arc<dyn KvTree>,
|
pub(super) userid_avatarurl: Arc<dyn KvTree>,
|
||||||
pub(super) userid_blurhash: Arc<dyn KvTree>,
|
pub(super) userid_blurhash: Arc<dyn KvTree>,
|
||||||
pub(super) userdeviceid_token: Arc<dyn KvTree>,
|
pub(super) userdeviceid_token: Arc<dyn KvTree>,
|
||||||
pub(super) userdeviceid_metadata: Arc<dyn KvTree>, // This is also used to check if a device exists
|
|
||||||
pub(super) userid_devicelistversion: Arc<dyn KvTree>, // DevicelistVersion = u64
|
// This is also used to check if a device exists
|
||||||
|
pub(super) userdeviceid_metadata: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// DevicelistVersion = u64
|
||||||
|
pub(super) userid_devicelistversion: Arc<dyn KvTree>,
|
||||||
pub(super) token_userdeviceid: Arc<dyn KvTree>,
|
pub(super) token_userdeviceid: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) onetimekeyid_onetimekeys: Arc<dyn KvTree>, // OneTimeKeyId = UserId + DeviceKeyId
|
// OneTimeKeyId = UserId + DeviceKeyId
|
||||||
pub(super) userid_lastonetimekeyupdate: Arc<dyn KvTree>, // LastOneTimeKeyUpdate = Count
|
pub(super) onetimekeyid_onetimekeys: Arc<dyn KvTree>,
|
||||||
pub(super) keychangeid_userid: Arc<dyn KvTree>, // KeyChangeId = UserId/RoomId + Count
|
|
||||||
pub(super) keyid_key: Arc<dyn KvTree>, // KeyId = UserId + KeyId (depends on key type)
|
// LastOneTimeKeyUpdate = Count
|
||||||
|
pub(super) userid_lastonetimekeyupdate: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// KeyChangeId = UserId/RoomId + Count
|
||||||
|
pub(super) keychangeid_userid: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// KeyId = UserId + KeyId (depends on key type)
|
||||||
|
pub(super) keyid_key: Arc<dyn KvTree>,
|
||||||
pub(super) userid_masterkeyid: Arc<dyn KvTree>,
|
pub(super) userid_masterkeyid: Arc<dyn KvTree>,
|
||||||
pub(super) userid_selfsigningkeyid: Arc<dyn KvTree>,
|
pub(super) userid_selfsigningkeyid: Arc<dyn KvTree>,
|
||||||
pub(super) userid_usersigningkeyid: Arc<dyn KvTree>,
|
pub(super) userid_usersigningkeyid: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) userfilterid_filter: Arc<dyn KvTree>, // UserFilterId = UserId + FilterId
|
// UserFilterId = UserId + FilterId
|
||||||
|
pub(super) userfilterid_filter: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) todeviceid_events: Arc<dyn KvTree>, // ToDeviceId = UserId + DeviceId + Count
|
// ToDeviceId = UserId + DeviceId + Count
|
||||||
|
pub(super) todeviceid_events: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::uiaa`
|
// Trees "owned" by `self::key_value::uiaa`
|
||||||
pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>, // User-interactive authentication
|
// User-interactive authentication
|
||||||
|
pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>,
|
||||||
pub(super) userdevicesessionid_uiaarequest:
|
pub(super) userdevicesessionid_uiaarequest:
|
||||||
RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
|
RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::rooms::edus`
|
// Trees "owned" by `self::key_value::rooms::edus`
|
||||||
pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId
|
// ReadReceiptId = RoomId + Count + UserId
|
||||||
pub(super) roomuserid_privateread: Arc<dyn KvTree>, // RoomUserId = Room + User, PrivateRead = Count
|
pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>,
|
||||||
pub(super) roomuserid_lastprivatereadupdate: Arc<dyn KvTree>, // LastPrivateReadUpdate = Count
|
|
||||||
|
// RoomUserId = Room + User, PrivateRead = Count
|
||||||
|
pub(super) roomuserid_privateread: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// LastPrivateReadUpdate = Count
|
||||||
|
pub(super) roomuserid_lastprivatereadupdate: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// PresenceId = RoomId + Count + UserId
|
||||||
// This exists in the database already but is currently unused
|
// This exists in the database already but is currently unused
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(super) presenceid_presence: Arc<dyn KvTree>, // PresenceId = RoomId + Count + UserId
|
pub(super) presenceid_presence: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// LastPresenceUpdate = Count
|
||||||
// This exists in the database already but is currently unused
|
// This exists in the database already but is currently unused
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(super) userid_lastpresenceupdate: Arc<dyn KvTree>, // LastPresenceUpdate = Count
|
pub(super) userid_lastpresenceupdate: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::rooms`
|
// Trees "owned" by `self::key_value::rooms`
|
||||||
pub(super) pduid_pdu: Arc<dyn KvTree>, // PduId = ShortRoomId + Count
|
// PduId = ShortRoomId + Count
|
||||||
|
pub(super) pduid_pdu: Arc<dyn KvTree>,
|
||||||
pub(super) eventid_pduid: Arc<dyn KvTree>,
|
pub(super) eventid_pduid: Arc<dyn KvTree>,
|
||||||
pub(super) roomid_pduleaves: Arc<dyn KvTree>,
|
pub(super) roomid_pduleaves: Arc<dyn KvTree>,
|
||||||
pub(super) alias_roomid: Arc<dyn KvTree>,
|
pub(super) alias_roomid: Arc<dyn KvTree>,
|
||||||
pub(super) aliasid_alias: Arc<dyn KvTree>, // AliasId = RoomId + Count
|
|
||||||
|
// AliasId = RoomId + Count
|
||||||
|
pub(super) aliasid_alias: Arc<dyn KvTree>,
|
||||||
pub(super) publicroomids: Arc<dyn KvTree>,
|
pub(super) publicroomids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) threadid_userids: Arc<dyn KvTree>, // ThreadId = RoomId + Count
|
// ThreadId = RoomId + Count
|
||||||
|
pub(super) threadid_userids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) tokenids: Arc<dyn KvTree>, // TokenId = ShortRoomId + Token + PduIdCount
|
// TokenId = ShortRoomId + Token + PduIdCount
|
||||||
|
pub(super) tokenids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
/// Participating servers in a room.
|
/// Participating servers in a room.
|
||||||
pub(super) roomserverids: Arc<dyn KvTree>, // RoomServerId = RoomId + ServerName
|
// RoomServerId = RoomId + ServerName
|
||||||
pub(super) serverroomids: Arc<dyn KvTree>, // ServerRoomId = ServerName + RoomId
|
pub(super) roomserverids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// ServerRoomId = ServerName + RoomId
|
||||||
|
pub(super) serverroomids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) userroomid_joined: Arc<dyn KvTree>,
|
pub(super) userroomid_joined: Arc<dyn KvTree>,
|
||||||
pub(super) roomuserid_joined: Arc<dyn KvTree>,
|
pub(super) roomuserid_joined: Arc<dyn KvTree>,
|
||||||
pub(super) roomid_joinedcount: Arc<dyn KvTree>,
|
pub(super) roomid_joinedcount: Arc<dyn KvTree>,
|
||||||
pub(super) roomid_invitedcount: Arc<dyn KvTree>,
|
pub(super) roomid_invitedcount: Arc<dyn KvTree>,
|
||||||
pub(super) roomuseroncejoinedids: Arc<dyn KvTree>,
|
pub(super) roomuseroncejoinedids: Arc<dyn KvTree>,
|
||||||
pub(super) userroomid_invitestate: Arc<dyn KvTree>, // InviteState = Vec<Raw<Pdu>>
|
|
||||||
pub(super) roomuserid_invitecount: Arc<dyn KvTree>, // InviteCount = Count
|
// InviteState = Vec<Raw<Pdu>>
|
||||||
|
pub(super) userroomid_invitestate: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// InviteCount = Count
|
||||||
|
pub(super) roomuserid_invitecount: Arc<dyn KvTree>,
|
||||||
pub(super) userroomid_leftstate: Arc<dyn KvTree>,
|
pub(super) userroomid_leftstate: Arc<dyn KvTree>,
|
||||||
pub(super) roomuserid_leftcount: Arc<dyn KvTree>,
|
pub(super) roomuserid_leftcount: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) disabledroomids: Arc<dyn KvTree>, // Rooms where incoming federation handling is disabled
|
// Rooms where incoming federation handling is disabled
|
||||||
|
pub(super) disabledroomids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) lazyloadedids: Arc<dyn KvTree>, // LazyLoadedIds = UserId + DeviceId + RoomId + LazyLoadedUserId
|
// LazyLoadedIds = UserId + DeviceId + RoomId + LazyLoadedUserId
|
||||||
|
pub(super) lazyloadedids: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) userroomid_notificationcount: Arc<dyn KvTree>, // NotifyCount = u64
|
// NotifyCount = u64
|
||||||
pub(super) userroomid_highlightcount: Arc<dyn KvTree>, // HightlightCount = u64
|
pub(super) userroomid_notificationcount: Arc<dyn KvTree>,
|
||||||
pub(super) roomuserid_lastnotificationread: Arc<dyn KvTree>, // LastNotificationRead = u64
|
|
||||||
|
// HightlightCount = u64
|
||||||
|
pub(super) userroomid_highlightcount: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// LastNotificationRead = u64
|
||||||
|
pub(super) roomuserid_lastnotificationread: Arc<dyn KvTree>,
|
||||||
|
|
||||||
/// Remember the current state hash of a room.
|
/// Remember the current state hash of a room.
|
||||||
pub(super) roomid_shortstatehash: Arc<dyn KvTree>,
|
pub(super) roomid_shortstatehash: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) roomsynctoken_shortstatehash: Arc<dyn KvTree>,
|
pub(super) roomsynctoken_shortstatehash: Arc<dyn KvTree>,
|
||||||
|
|
||||||
/// Remember the state hash at events in the past.
|
/// Remember the state hash at events in the past.
|
||||||
pub(super) shorteventid_shortstatehash: Arc<dyn KvTree>,
|
pub(super) shorteventid_shortstatehash: Arc<dyn KvTree>,
|
||||||
|
|
||||||
/// StateKey = EventType + StateKey, ShortStateKey = Count
|
/// StateKey = EventType + StateKey, ShortStateKey = Count
|
||||||
pub(super) statekey_shortstatekey: Arc<dyn KvTree>,
|
pub(super) statekey_shortstatekey: Arc<dyn KvTree>,
|
||||||
pub(super) shortstatekey_statekey: Arc<dyn KvTree>,
|
pub(super) shortstatekey_statekey: Arc<dyn KvTree>,
|
||||||
|
|
@ -123,7 +168,9 @@ pub(crate) struct KeyValueDatabase {
|
||||||
pub(super) eventid_shorteventid: Arc<dyn KvTree>,
|
pub(super) eventid_shorteventid: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) statehash_shortstatehash: Arc<dyn KvTree>,
|
pub(super) statehash_shortstatehash: Arc<dyn KvTree>,
|
||||||
pub(super) shortstatehash_statediff: Arc<dyn KvTree>, // StateDiff = parent (or 0) + (shortstatekey+shorteventid++) + 0_u64 + (shortstatekey+shorteventid--)
|
|
||||||
|
// StateDiff = parent (or 0) + (shortstatekey+shorteventid++) + 0_u64 + (shortstatekey+shorteventid--)
|
||||||
|
pub(super) shortstatehash_statediff: Arc<dyn KvTree>,
|
||||||
|
|
||||||
pub(super) shorteventid_authchain: Arc<dyn KvTree>,
|
pub(super) shorteventid_authchain: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
|
@ -134,26 +181,44 @@ pub(crate) struct KeyValueDatabase {
|
||||||
|
|
||||||
/// ShortEventId + ShortEventId -> ().
|
/// ShortEventId + ShortEventId -> ().
|
||||||
pub(super) tofrom_relation: Arc<dyn KvTree>,
|
pub(super) tofrom_relation: Arc<dyn KvTree>,
|
||||||
|
|
||||||
/// RoomId + EventId -> Parent PDU EventId.
|
/// RoomId + EventId -> Parent PDU EventId.
|
||||||
pub(super) referencedevents: Arc<dyn KvTree>,
|
pub(super) referencedevents: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::account_data`
|
// Trees "owned" by `self::key_value::account_data`
|
||||||
pub(super) roomuserdataid_accountdata: Arc<dyn KvTree>, // RoomUserDataId = Room + User + Count + Type
|
// RoomUserDataId = Room + User + Count + Type
|
||||||
pub(super) roomusertype_roomuserdataid: Arc<dyn KvTree>, // RoomUserType = Room + User + Type
|
pub(super) roomuserdataid_accountdata: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// RoomUserType = Room + User + Type
|
||||||
|
pub(super) roomusertype_roomuserdataid: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::media`
|
// Trees "owned" by `self::key_value::media`
|
||||||
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
|
// MediaId = MXC + WidthHeight + ContentDisposition + ContentType
|
||||||
|
pub(super) mediaid_file: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::key_backups`
|
// Trees "owned" by `self::key_value::key_backups`
|
||||||
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
|
// BackupId = UserId + Version(Count)
|
||||||
pub(super) backupid_etag: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
|
pub(super) backupid_algorithm: Arc<dyn KvTree>,
|
||||||
pub(super) backupkeyid_backup: Arc<dyn KvTree>, // BackupKeyId = UserId + Version + RoomId + SessionId
|
|
||||||
|
// BackupId = UserId + Version(Count)
|
||||||
|
pub(super) backupid_etag: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// BackupKeyId = UserId + Version + RoomId + SessionId
|
||||||
|
pub(super) backupkeyid_backup: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::transaction_ids`
|
// Trees "owned" by `self::key_value::transaction_ids`
|
||||||
pub(super) userdevicetxnid_response: Arc<dyn KvTree>, // Response can be empty (/sendToDevice) or the event id (/send)
|
// Response can be empty (/sendToDevice) or the event id (/send)
|
||||||
|
pub(super) userdevicetxnid_response: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::sending`
|
// Trees "owned" by `self::key_value::sending`
|
||||||
pub(super) servername_educount: Arc<dyn KvTree>, // EduCount: Count of last EDU sync
|
// EduCount: Count of last EDU sync
|
||||||
pub(super) servernameevent_data: Arc<dyn KvTree>, // ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content
|
pub(super) servername_educount: Arc<dyn KvTree>,
|
||||||
pub(super) servercurrentevent_data: Arc<dyn KvTree>, // ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content
|
|
||||||
|
// ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content
|
||||||
|
pub(super) servernameevent_data: Arc<dyn KvTree>,
|
||||||
|
|
||||||
|
// ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content
|
||||||
|
pub(super) servercurrentevent_data: Arc<dyn KvTree>,
|
||||||
|
|
||||||
// Trees "owned" by `self::key_value::appservice`
|
// Trees "owned" by `self::key_value::appservice`
|
||||||
pub(super) id_appserviceregistrations: Arc<dyn KvTree>,
|
pub(super) id_appserviceregistrations: Arc<dyn KvTree>,
|
||||||
|
|
@ -278,7 +343,8 @@ impl KeyValueDatabase {
|
||||||
userdevicesessionid_uiaainfo: builder.open_tree("userdevicesessionid_uiaainfo")?,
|
userdevicesessionid_uiaainfo: builder.open_tree("userdevicesessionid_uiaainfo")?,
|
||||||
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
|
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
|
||||||
readreceiptid_readreceipt: builder.open_tree("readreceiptid_readreceipt")?,
|
readreceiptid_readreceipt: builder.open_tree("readreceiptid_readreceipt")?,
|
||||||
roomuserid_privateread: builder.open_tree("roomuserid_privateread")?, // "Private" read receipt
|
// "Private" read receipt
|
||||||
|
roomuserid_privateread: builder.open_tree("roomuserid_privateread")?,
|
||||||
roomuserid_lastprivatereadupdate: builder
|
roomuserid_lastprivatereadupdate: builder
|
||||||
.open_tree("roomuserid_lastprivatereadupdate")?,
|
.open_tree("roomuserid_lastprivatereadupdate")?,
|
||||||
presenceid_presence: builder.open_tree("presenceid_presence")?,
|
presenceid_presence: builder.open_tree("presenceid_presence")?,
|
||||||
|
|
@ -601,7 +667,8 @@ impl KeyValueDatabase {
|
||||||
current_sstatehash,
|
current_sstatehash,
|
||||||
Arc::new(statediffnew),
|
Arc::new(statediffnew),
|
||||||
Arc::new(statediffremoved),
|
Arc::new(statediffremoved),
|
||||||
2, // every state change is 2 event changes on average
|
// every state change is 2 event changes on average
|
||||||
|
2,
|
||||||
states_parents,
|
states_parents,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,8 @@ impl KvTree for SqliteTable {
|
||||||
backwards: bool,
|
backwards: bool,
|
||||||
) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {
|
) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {
|
||||||
let guard = self.engine.read_lock_iterator();
|
let guard = self.engine.read_lock_iterator();
|
||||||
let from = from.to_vec(); // TODO change interface?
|
// TODO change interface?
|
||||||
|
let from = from.to_vec();
|
||||||
|
|
||||||
if backwards {
|
if backwards {
|
||||||
let statement = Box::leak(Box::new(
|
let statement = Box::leak(Box::new(
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase {
|
||||||
let prefix2 = prefix.clone();
|
let prefix2 = prefix.clone();
|
||||||
|
|
||||||
let mut first_possible_edu = prefix.clone();
|
let mut first_possible_edu = prefix.clone();
|
||||||
first_possible_edu.extend_from_slice(&(since + 1).to_be_bytes()); // +1 so we don't send the event at since
|
// +1 so we don't send the event at since
|
||||||
|
first_possible_edu.extend_from_slice(&(since + 1).to_be_bytes());
|
||||||
|
|
||||||
Box::new(
|
Box::new(
|
||||||
self.readreceiptid_readreceipt
|
self.readreceiptid_readreceipt
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ impl service::rooms::search::Data for KeyValueDatabase {
|
||||||
let mut key = shortroomid.to_be_bytes().to_vec();
|
let mut key = shortroomid.to_be_bytes().to_vec();
|
||||||
key.extend_from_slice(word.as_bytes());
|
key.extend_from_slice(word.as_bytes());
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
key.extend_from_slice(pdu_id); // TODO: currently we save the room id a second time here
|
// TODO: currently we save the room id a second time here
|
||||||
|
key.extend_from_slice(pdu_id);
|
||||||
(key, Vec::new())
|
(key, Vec::new())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -52,7 +53,8 @@ impl service::rooms::search::Data for KeyValueDatabase {
|
||||||
last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes());
|
last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes());
|
||||||
|
|
||||||
self.tokenids
|
self.tokenids
|
||||||
.iter_from(&last_possible_id, true) // Newest pdus first
|
// Newest pdus first
|
||||||
|
.iter_from(&last_possible_id, true)
|
||||||
.take_while(move |(k, _)| k.starts_with(&prefix2))
|
.take_while(move |(k, _)| k.starts_with(&prefix2))
|
||||||
.map(move |(key, _)| key[prefix3.len()..].to_vec())
|
.map(move |(key, _)| key[prefix3.len()..].to_vec())
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ impl service::rooms::state::Data for KeyValueDatabase {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
new_shortstatehash: u64,
|
new_shortstatehash: u64,
|
||||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
_mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.roomid_shortstatehash
|
self.roomid_shortstatehash
|
||||||
.insert(room_id.as_bytes(), &new_shortstatehash.to_be_bytes())?;
|
.insert(room_id.as_bytes(), &new_shortstatehash.to_be_bytes())?;
|
||||||
|
|
@ -53,7 +54,8 @@ impl service::rooms::state::Data for KeyValueDatabase {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_ids: Vec<OwnedEventId>,
|
event_ids: Vec<OwnedEventId>,
|
||||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
_mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut prefix = room_id.as_bytes().to_vec();
|
let mut prefix = room_id.as_bytes().to_vec();
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,11 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
|
||||||
userroom_id.push(0xff);
|
userroom_id.push(0xff);
|
||||||
userroom_id.extend_from_slice(room_id.as_bytes());
|
userroom_id.extend_from_slice(room_id.as_bytes());
|
||||||
|
|
||||||
|
// TODO
|
||||||
self.userroomid_leftstate.insert(
|
self.userroomid_leftstate.insert(
|
||||||
&userroom_id,
|
&userroom_id,
|
||||||
&serde_json::to_vec(&Vec::<Raw<AnySyncStateEvent>>::new()).unwrap(),
|
&serde_json::to_vec(&Vec::<Raw<AnySyncStateEvent>>::new()).unwrap(),
|
||||||
)?; // TODO
|
)?;
|
||||||
self.roomuserid_leftcount.insert(
|
self.roomuserid_leftcount.insert(
|
||||||
&roomuser_id,
|
&roomuser_id,
|
||||||
&services().globals.next_count()?.to_be_bytes(),
|
&services().globals.next_count()?.to_be_bytes(),
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,8 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
.find(|(_, &b)| b == 0xff)
|
.find(|(_, &b)| b == 0xff)
|
||||||
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
|
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
|
||||||
.0
|
.0
|
||||||
+ 1; // +1 because the room id starts AFTER the separator
|
// +1 because the room id starts AFTER the separator
|
||||||
|
+ 1;
|
||||||
|
|
||||||
let room_id = key[roomid_index..].to_vec();
|
let room_id = key[roomid_index..].to_vec();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,8 @@ impl service::users::Data for KeyValueDatabase {
|
||||||
&serde_json::to_vec(&Device {
|
&serde_json::to_vec(&Device {
|
||||||
device_id: device_id.into(),
|
device_id: device_id.into(),
|
||||||
display_name: initial_device_display_name,
|
display_name: initial_device_display_name,
|
||||||
last_seen_ip: None, // TODO
|
// TODO
|
||||||
|
last_seen_ip: None,
|
||||||
last_seen_ts: Some(MilliSecondsSinceUnixEpoch::now()),
|
last_seen_ts: Some(MilliSecondsSinceUnixEpoch::now()),
|
||||||
})
|
})
|
||||||
.expect("Device::to_string never fails."),
|
.expect("Device::to_string never fails."),
|
||||||
|
|
@ -365,7 +366,8 @@ impl service::users::Data for KeyValueDatabase {
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.extend_from_slice(device_id.as_bytes());
|
prefix.extend_from_slice(device_id.as_bytes());
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.push(b'"'); // Annoying quotation mark
|
// Annoying quotation mark
|
||||||
|
prefix.push(b'"');
|
||||||
prefix.extend_from_slice(key_algorithm.as_ref().as_bytes());
|
prefix.extend_from_slice(key_algorithm.as_ref().as_bytes());
|
||||||
prefix.push(b':');
|
prefix.push(b':');
|
||||||
|
|
||||||
|
|
@ -828,7 +830,8 @@ impl service::users::Data for KeyValueDatabase {
|
||||||
|
|
||||||
for (key, _) in self
|
for (key, _) in self
|
||||||
.todeviceid_events
|
.todeviceid_events
|
||||||
.iter_from(&last, true) // this includes last
|
// this includes last
|
||||||
|
.iter_from(&last, true)
|
||||||
.take_while(move |(k, _)| k.starts_with(&prefix))
|
.take_while(move |(k, _)| k.starts_with(&prefix))
|
||||||
.map(|(key, _)| {
|
.map(|(key, _)| {
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
|
|
|
||||||
|
|
@ -43,16 +43,20 @@ use base64::{engine::general_purpose, Engine as _};
|
||||||
|
|
||||||
type WellKnownMap = HashMap<OwnedServerName, (FedDest, String)>;
|
type WellKnownMap = HashMap<OwnedServerName, (FedDest, String)>;
|
||||||
type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>;
|
type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>;
|
||||||
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
|
// Time if last failed try, number of failed tries
|
||||||
|
type RateLimitState = (Instant, u32);
|
||||||
type SyncHandle = (
|
type SyncHandle = (
|
||||||
Option<String>, // since
|
// since
|
||||||
Receiver<Option<Result<sync_events::v3::Response>>>, // rx
|
Option<String>,
|
||||||
|
// rx
|
||||||
|
Receiver<Option<Result<sync_events::v3::Response>>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
pub(crate) db: &'static dyn Data,
|
pub(crate) db: &'static dyn Data,
|
||||||
|
|
||||||
pub(crate) actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
|
// actual_destination, host
|
||||||
|
pub(crate) actual_destination_cache: Arc<RwLock<WellKnownMap>>,
|
||||||
pub(crate) tls_name_override: Arc<StdRwLock<TlsNameMap>>,
|
pub(crate) tls_name_override: Arc<StdRwLock<TlsNameMap>>,
|
||||||
pub(crate) config: Config,
|
pub(crate) config: Config,
|
||||||
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
||||||
|
|
@ -69,7 +73,9 @@ pub(crate) struct Service {
|
||||||
pub(crate) sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
|
pub(crate) sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
|
||||||
pub(crate) roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
pub(crate) roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
||||||
pub(crate) roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
pub(crate) roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
||||||
pub(crate) roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer
|
|
||||||
|
// this lock will be held longer
|
||||||
|
pub(crate) roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
||||||
pub(crate) roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
|
pub(crate) roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
|
||||||
pub(crate) stateres_mutex: Arc<Mutex<()>>,
|
pub(crate) stateres_mutex: Arc<Mutex<()>>,
|
||||||
pub(crate) rotate: RotationHandler,
|
pub(crate) rotate: RotationHandler,
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,9 @@ impl Service {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result<Option<FileMeta>> {
|
) -> Result<Option<FileMeta>> {
|
||||||
|
// 0, 0 because that's the original file
|
||||||
let (width, height, crop) =
|
let (width, height, crop) =
|
||||||
Self::thumbnail_properties(width, height).unwrap_or((0, 0, false)); // 0, 0 because that's the original file
|
Self::thumbnail_properties(width, height).unwrap_or((0, 0, false));
|
||||||
|
|
||||||
if let Ok((content_disposition, content_type, key)) =
|
if let Ok((content_disposition, content_type, key)) =
|
||||||
self.db.search_file_metadata(mxc.clone(), width, height)
|
self.db.search_file_metadata(mxc.clone(), width, height)
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,11 @@ impl Service {
|
||||||
.expect("http::response::Builder is usable"),
|
.expect("http::response::Builder is usable"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: handle timeout
|
||||||
let body = response.bytes().await.unwrap_or_else(|e| {
|
let body = response.bytes().await.unwrap_or_else(|e| {
|
||||||
warn!("server error {}", e);
|
warn!("server error {}", e);
|
||||||
Vec::new().into()
|
Vec::new().into()
|
||||||
}); // TODO: handle timeout
|
});
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
info!(
|
info!(
|
||||||
|
|
@ -201,7 +202,8 @@ impl Service {
|
||||||
|
|
||||||
let ctx = PushConditionRoomCtx {
|
let ctx = PushConditionRoomCtx {
|
||||||
room_id: room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
member_count: 10_u32.into(), // TODO: get member count efficiently
|
// TODO: get member count efficiently
|
||||||
|
member_count: 10_u32.into(),
|
||||||
user_id: user.to_owned(),
|
user_id: user.to_owned(),
|
||||||
user_display_name: services()
|
user_display_name: services()
|
||||||
.users
|
.users
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,10 @@ use tracing::trace;
|
||||||
use crate::{services, utils, Result};
|
use crate::{services, utils, Result};
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
|
// u64 is unix timestamp of timeout
|
||||||
pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users
|
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>,
|
||||||
|
// timestamp of the last change to typing users
|
||||||
|
pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>,
|
||||||
pub(crate) typing_update_sender: broadcast::Sender<OwnedRoomId>,
|
pub(crate) typing_update_sender: broadcast::Sender<OwnedRoomId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,8 @@ impl Service {
|
||||||
if !state_res::event_auth::auth_check(
|
if !state_res::event_auth::auth_check(
|
||||||
&room_version,
|
&room_version,
|
||||||
&incoming_pdu,
|
&incoming_pdu,
|
||||||
None::<PduEvent>, // TODO: third party invite
|
// TODO: third party invite
|
||||||
|
None::<PduEvent>,
|
||||||
|k, s| auth_events.get(&(k.to_string().into(), s.to_owned())),
|
|k, s| auth_events.get(&(k.to_string().into(), s.to_owned())),
|
||||||
)
|
)
|
||||||
.map_err(|_e| Error::BadRequest(ErrorKind::InvalidParam, "Auth check failed"))?
|
.map_err(|_e| Error::BadRequest(ErrorKind::InvalidParam, "Auth check failed"))?
|
||||||
|
|
@ -748,7 +749,8 @@ impl Service {
|
||||||
let check_result = state_res::event_auth::auth_check(
|
let check_result = state_res::event_auth::auth_check(
|
||||||
&room_version,
|
&room_version,
|
||||||
&incoming_pdu,
|
&incoming_pdu,
|
||||||
None::<PduEvent>, // TODO: third party invite
|
// TODO: third party invite
|
||||||
|
None::<PduEvent>,
|
||||||
|k, s| {
|
|k, s| {
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ impl Service {
|
||||||
let events_after: Vec<_> = services()
|
let events_after: Vec<_> = services()
|
||||||
.rooms
|
.rooms
|
||||||
.pdu_metadata
|
.pdu_metadata
|
||||||
.relations_until(sender_user, room_id, target, from)? // TODO: should be relations_after
|
// TODO: should be relations_after
|
||||||
|
.relations_until(sender_user, room_id, target, from)?
|
||||||
.filter(|r| {
|
.filter(|r| {
|
||||||
r.as_ref().map_or(true, |(_, pdu)| {
|
r.as_ref().map_or(true, |(_, pdu)| {
|
||||||
filter_event_type.as_ref().map_or(true, |t| &&pdu.kind == t)
|
filter_event_type.as_ref().map_or(true, |t| &&pdu.kind == t)
|
||||||
|
|
@ -90,14 +91,16 @@ impl Service {
|
||||||
.user_can_see_event(sender_user, room_id, &pdu.event_id)
|
.user_can_see_event(sender_user, room_id, &pdu.event_id)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.take_while(|&(k, _)| Some(k) != to) // Stop at `to`
|
// Stop at `to`
|
||||||
|
.take_while(|&(k, _)| Some(k) != to)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
next_token = events_after.last().map(|(count, _)| count).copied();
|
next_token = events_after.last().map(|(count, _)| count).copied();
|
||||||
|
|
||||||
let events_after: Vec<_> = events_after
|
let events_after: Vec<_> = events_after
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.rev() // relations are always most recent first
|
// relations are always most recent first
|
||||||
|
.rev()
|
||||||
.map(|(_, pdu)| pdu.to_message_like_event())
|
.map(|(_, pdu)| pdu.to_message_like_event())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
@ -137,7 +140,8 @@ impl Service {
|
||||||
.user_can_see_event(sender_user, room_id, &pdu.event_id)
|
.user_can_see_event(sender_user, room_id, &pdu.event_id)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.take_while(|&(k, _)| Some(k) != to) // Stop at `to`
|
// Stop at `to`
|
||||||
|
.take_while(|&(k, _)| Some(k) != to)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
next_token = events_before.last().map(|(count, _)| count).copied();
|
next_token = events_before.last().map(|(count, _)| count).copied();
|
||||||
|
|
@ -167,7 +171,8 @@ impl Service {
|
||||||
let target = match services().rooms.timeline.get_pdu_count(target)? {
|
let target = match services().rooms.timeline.get_pdu_count(target)? {
|
||||||
Some(PduCount::Normal(c)) => c,
|
Some(PduCount::Normal(c)) => c,
|
||||||
// TODO: Support backfilled relations
|
// TODO: Support backfilled relations
|
||||||
_ => 0, // This will result in an empty iterator
|
// This will result in an empty iterator
|
||||||
|
_ => 0,
|
||||||
};
|
};
|
||||||
self.db.relations_until(user_id, room_id, target, until)
|
self.db.relations_until(user_id, room_id, target, until)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ impl Service {
|
||||||
shortstatehash: u64,
|
shortstatehash: u64,
|
||||||
statediffnew: Arc<HashSet<CompressedStateEvent>>,
|
statediffnew: Arc<HashSet<CompressedStateEvent>>,
|
||||||
_statediffremoved: Arc<HashSet<CompressedStateEvent>>,
|
_statediffremoved: Arc<HashSet<CompressedStateEvent>>,
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for event_id in statediffnew.iter().filter_map(|new| {
|
for event_id in statediffnew.iter().filter_map(|new| {
|
||||||
services()
|
services()
|
||||||
|
|
@ -169,7 +170,8 @@ impl Service {
|
||||||
shortstatehash,
|
shortstatehash,
|
||||||
statediffnew,
|
statediffnew,
|
||||||
statediffremoved,
|
statediffremoved,
|
||||||
1_000_000, // high number because no state will be based on this one
|
// high number because no state will be based on this one
|
||||||
|
1_000_000,
|
||||||
states_parents,
|
states_parents,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +317,8 @@ impl Service {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
shortstatehash: u64,
|
shortstatehash: u64,
|
||||||
mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.set_room_state(room_id, shortstatehash, mutex_lock)
|
self.db.set_room_state(room_id, shortstatehash, mutex_lock)
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +361,8 @@ impl Service {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_ids: Vec<OwnedEventId>,
|
event_ids: Vec<OwnedEventId>,
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db
|
self.db
|
||||||
.set_forward_extremities(room_id, event_ids, state_lock)
|
.set_forward_extremities(room_id, event_ids, state_lock)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ pub(crate) trait Data: Send + Sync {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
new_shortstatehash: u64,
|
new_shortstatehash: u64,
|
||||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
_mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
/// Associates a state with an event.
|
/// Associates a state with an event.
|
||||||
|
|
@ -26,6 +27,7 @@ pub(crate) trait Data: Send + Sync {
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_ids: Vec<OwnedEventId>,
|
event_ids: Vec<OwnedEventId>,
|
||||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
_mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,10 @@ impl Service {
|
||||||
let is_ignored = services()
|
let is_ignored = services()
|
||||||
.account_data
|
.account_data
|
||||||
.get(
|
.get(
|
||||||
None, // Ignored users are in global account data
|
// Ignored users are in global account data
|
||||||
user_id, // Receiver
|
None,
|
||||||
|
// Receiver
|
||||||
|
user_id,
|
||||||
GlobalAccountDataEventType::IgnoredUserList
|
GlobalAccountDataEventType::IgnoredUserList
|
||||||
.to_string()
|
.to_string()
|
||||||
.into(),
|
.into(),
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,14 @@ pub(crate) struct Service {
|
||||||
LruCache<
|
LruCache<
|
||||||
u64,
|
u64,
|
||||||
Vec<(
|
Vec<(
|
||||||
u64, // shortstatehash
|
// shortstatehash
|
||||||
Arc<HashSet<CompressedStateEvent>>, // full state
|
u64,
|
||||||
Arc<HashSet<CompressedStateEvent>>, // added
|
// full state
|
||||||
Arc<HashSet<CompressedStateEvent>>, // removed
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// added
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// removed
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
)>,
|
)>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
|
|
@ -41,10 +45,14 @@ impl Service {
|
||||||
shortstatehash: u64,
|
shortstatehash: u64,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Vec<(
|
Vec<(
|
||||||
u64, // shortstatehash
|
// shortstatehash
|
||||||
Arc<HashSet<CompressedStateEvent>>, // full state
|
u64,
|
||||||
Arc<HashSet<CompressedStateEvent>>, // added
|
// full state
|
||||||
Arc<HashSet<CompressedStateEvent>>, // removed
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// added
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// removed
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
)>,
|
)>,
|
||||||
> {
|
> {
|
||||||
if let Some(r) = self
|
if let Some(r) = self
|
||||||
|
|
@ -152,10 +160,14 @@ impl Service {
|
||||||
statediffremoved: Arc<HashSet<CompressedStateEvent>>,
|
statediffremoved: Arc<HashSet<CompressedStateEvent>>,
|
||||||
diff_to_sibling: usize,
|
diff_to_sibling: usize,
|
||||||
mut parent_states: Vec<(
|
mut parent_states: Vec<(
|
||||||
u64, // shortstatehash
|
// shortstatehash
|
||||||
Arc<HashSet<CompressedStateEvent>>, // full state
|
u64,
|
||||||
Arc<HashSet<CompressedStateEvent>>, // added
|
// full state
|
||||||
Arc<HashSet<CompressedStateEvent>>, // removed
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// added
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
|
// removed
|
||||||
|
Arc<HashSet<CompressedStateEvent>>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let diffsum = statediffnew.len() + statediffremoved.len();
|
let diffsum = statediffnew.len() + statediffremoved.len();
|
||||||
|
|
@ -318,7 +330,8 @@ impl Service {
|
||||||
new_shortstatehash,
|
new_shortstatehash,
|
||||||
statediffnew.clone(),
|
statediffnew.clone(),
|
||||||
statediffremoved.clone(),
|
statediffremoved.clone(),
|
||||||
2, // every state change is 2 event changes on average
|
// every state change is 2 event changes on average
|
||||||
|
2,
|
||||||
states_parents,
|
states_parents,
|
||||||
)?;
|
)?;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,8 @@ impl Service {
|
||||||
pdu: &PduEvent,
|
pdu: &PduEvent,
|
||||||
mut pdu_json: CanonicalJsonObject,
|
mut pdu_json: CanonicalJsonObject,
|
||||||
leaves: Vec<OwnedEventId>,
|
leaves: Vec<OwnedEventId>,
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
let shortroomid = services()
|
let shortroomid = services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
@ -527,7 +528,8 @@ impl Service {
|
||||||
.threads
|
.threads
|
||||||
.add_to_thread(&thread.event_id, pdu)?;
|
.add_to_thread(&thread.event_id, pdu)?;
|
||||||
}
|
}
|
||||||
_ => {} // TODO: Aggregate other types
|
// TODO: Aggregate other types
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -598,7 +600,8 @@ impl Service {
|
||||||
pdu_builder: PduBuilder,
|
pdu_builder: PduBuilder,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
_mutex_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<(PduEvent, CanonicalJsonObject)> {
|
) -> Result<(PduEvent, CanonicalJsonObject)> {
|
||||||
let PduBuilder {
|
let PduBuilder {
|
||||||
event_type,
|
event_type,
|
||||||
|
|
@ -702,7 +705,8 @@ impl Service {
|
||||||
let auth_check = state_res::auth_check(
|
let auth_check = state_res::auth_check(
|
||||||
&room_version,
|
&room_version,
|
||||||
&pdu,
|
&pdu,
|
||||||
None::<PduEvent>, // TODO: third_party_invite
|
// TODO: third_party_invite
|
||||||
|
None::<PduEvent>,
|
||||||
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
|
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|
@ -781,7 +785,8 @@ impl Service {
|
||||||
pdu_builder: PduBuilder,
|
pdu_builder: PduBuilder,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<Arc<EventId>> {
|
) -> Result<Arc<EventId>> {
|
||||||
let (pdu, pdu_json) =
|
let (pdu, pdu_json) =
|
||||||
self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
|
self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
|
||||||
|
|
@ -990,7 +995,8 @@ impl Service {
|
||||||
new_room_leaves: Vec<OwnedEventId>,
|
new_room_leaves: Vec<OwnedEventId>,
|
||||||
state_ids_compressed: Arc<HashSet<CompressedStateEvent>>,
|
state_ids_compressed: Arc<HashSet<CompressedStateEvent>>,
|
||||||
soft_fail: bool,
|
soft_fail: bool,
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
// Take mutex guard to make sure users get the room state mutex
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<Option<Vec<u8>>> {
|
) -> Result<Option<Vec<u8>>> {
|
||||||
// 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.
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ use tracing::{debug, error, warn};
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum OutgoingKind {
|
pub(crate) enum OutgoingKind {
|
||||||
Appservice(String),
|
Appservice(String),
|
||||||
Push(OwnedUserId, String), // user and pushkey
|
// user and pushkey
|
||||||
|
Push(OwnedUserId, String),
|
||||||
Normal(OwnedServerName),
|
Normal(OwnedServerName),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,8 +82,10 @@ impl OutgoingKind {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum SendingEventType {
|
pub(crate) enum SendingEventType {
|
||||||
Pdu(Vec<u8>), // pduid
|
// pduid
|
||||||
Edu(Vec<u8>), // pdu json
|
Pdu(Vec<u8>),
|
||||||
|
// pdu json
|
||||||
|
Edu(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
|
|
@ -96,8 +99,10 @@ pub(crate) struct Service {
|
||||||
|
|
||||||
enum TransactionStatus {
|
enum TransactionStatus {
|
||||||
Running,
|
Running,
|
||||||
Failed(u32, Instant), // number of times failed, time of last failure
|
// number of times failed, time of last failure
|
||||||
Retrying(u32), // number of times failed
|
Failed(u32, Instant),
|
||||||
|
// number of times failed
|
||||||
|
Retrying(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
|
|
@ -203,7 +208,8 @@ impl Service {
|
||||||
fn select_events(
|
fn select_events(
|
||||||
&self,
|
&self,
|
||||||
outgoing_kind: &OutgoingKind,
|
outgoing_kind: &OutgoingKind,
|
||||||
new_events: Vec<(SendingEventType, Vec<u8>)>, // Events we want to send: event and full key
|
// Events we want to send: event and full key
|
||||||
|
new_events: Vec<(SendingEventType, Vec<u8>)>,
|
||||||
current_transaction_status: &mut HashMap<OutgoingKind, TransactionStatus>,
|
current_transaction_status: &mut HashMap<OutgoingKind, TransactionStatus>,
|
||||||
) -> Result<Option<Vec<SendingEventType>>> {
|
) -> Result<Option<Vec<SendingEventType>>> {
|
||||||
let mut retry = false;
|
let mut retry = false;
|
||||||
|
|
@ -214,7 +220,8 @@ impl Service {
|
||||||
entry
|
entry
|
||||||
.and_modify(|e| match e {
|
.and_modify(|e| match e {
|
||||||
TransactionStatus::Running | TransactionStatus::Retrying(_) => {
|
TransactionStatus::Running | TransactionStatus::Retrying(_) => {
|
||||||
allow = false; // already running
|
// already running
|
||||||
|
allow = false;
|
||||||
}
|
}
|
||||||
TransactionStatus::Failed(tries, time) => {
|
TransactionStatus::Failed(tries, time) => {
|
||||||
// Fail if a request has failed recently (exponential backoff)
|
// Fail if a request has failed recently (exponential backoff)
|
||||||
|
|
@ -444,7 +451,6 @@ impl Service {
|
||||||
|
|
||||||
/// Cleanup event data
|
/// Cleanup event data
|
||||||
/// Used for instance after we remove an appservice registration
|
/// Used for instance after we remove an appservice registration
|
||||||
///
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub(crate) fn cleanup_events(&self, appservice_id: String) -> Result<()> {
|
pub(crate) fn cleanup_events(&self, appservice_id: String) -> Result<()> {
|
||||||
self.db
|
self.db
|
||||||
|
|
@ -543,9 +549,8 @@ impl Service {
|
||||||
})?,
|
})?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
SendingEventType::Edu(_) => {
|
// Push gateways don't need EDUs (?)
|
||||||
// Push gateways don't need EDUs (?)
|
SendingEventType::Edu(_) => {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ impl Service {
|
||||||
self.db.set_uiaa_request(
|
self.db.set_uiaa_request(
|
||||||
user_id,
|
user_id,
|
||||||
device_id,
|
device_id,
|
||||||
uiaainfo.session.as_ref().expect("session should be set"), // TODO: better session error handling (why is it optional in ruma?)
|
// TODO: better session error handling (why is it optional in ruma?)
|
||||||
|
uiaainfo.session.as_ref().expect("session should be set"),
|
||||||
json_body,
|
json_body,
|
||||||
)?;
|
)?;
|
||||||
self.db.update_uiaa_session(
|
self.db.update_uiaa_session(
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ use crate::{services, Error, Result};
|
||||||
pub(crate) struct SlidingSyncCache {
|
pub(crate) struct SlidingSyncCache {
|
||||||
lists: BTreeMap<String, SyncRequestList>,
|
lists: BTreeMap<String, SyncRequestList>,
|
||||||
subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>,
|
subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>,
|
||||||
known_rooms: BTreeMap<String, BTreeMap<OwnedRoomId, u64>>, // For every room, the roomsince number
|
// For every room, the roomsince number
|
||||||
|
known_rooms: BTreeMap<String, BTreeMap<OwnedRoomId, u64>>,
|
||||||
extensions: ExtensionsConfig,
|
extensions: ExtensionsConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
src/utils.rs
11
src/utils.rs
|
|
@ -27,7 +27,8 @@ pub(crate) fn increment(old: Option<&[u8]>) -> Vec<u8> {
|
||||||
let number = u64::from_be_bytes(bytes);
|
let number = u64::from_be_bytes(bytes);
|
||||||
number + 1
|
number + 1
|
||||||
}
|
}
|
||||||
_ => 1, // Start at one. since 0 should return the first event in the db
|
// Start at one. since 0 should return the first event in the db
|
||||||
|
_ => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
number.to_be_bytes().to_vec()
|
number.to_be_bytes().to_vec()
|
||||||
|
|
@ -97,10 +98,12 @@ where
|
||||||
other_iterators.iter_mut().all(|it| {
|
other_iterators.iter_mut().all(|it| {
|
||||||
while let Some(element) = it.peek() {
|
while let Some(element) = it.peek() {
|
||||||
match check_order(element, target) {
|
match check_order(element, target) {
|
||||||
Ordering::Greater => return false, // We went too far
|
// We went too far
|
||||||
Ordering::Equal => return true, // Element is in both iters
|
Ordering::Greater => return false,
|
||||||
|
// Element is in both iters
|
||||||
|
Ordering::Equal => return true,
|
||||||
|
// Keep searching
|
||||||
Ordering::Less => {
|
Ordering::Less => {
|
||||||
// Keep searching
|
|
||||||
it.next();
|
it.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,9 @@ pub(crate) enum Error {
|
||||||
Uiaa(UiaaInfo),
|
Uiaa(UiaaInfo),
|
||||||
#[error("{0}: {1}")]
|
#[error("{0}: {1}")]
|
||||||
BadRequest(ErrorKind, &'static str),
|
BadRequest(ErrorKind, &'static str),
|
||||||
|
// This is only needed for when a room alias already exists
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Conflict(&'static str), // This is only needed for when a room alias already exists
|
Conflict(&'static str),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Extension(#[from] axum::extract::rejection::ExtensionRejection),
|
Extension(#[from] axum::extract::rejection::ExtensionRejection),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue