|
|
|
|
@ -4,7 +4,8 @@ use ruma::{
@@ -4,7 +4,8 @@ use ruma::{
|
|
|
|
|
client::r0::sync::sync_events, |
|
|
|
|
federation::discovery::{ServerSigningKeys, VerifyKey}, |
|
|
|
|
}, |
|
|
|
|
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, UserId, |
|
|
|
|
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName, |
|
|
|
|
ServerSigningKeyId, UserId, |
|
|
|
|
}; |
|
|
|
|
use std::{ |
|
|
|
|
collections::{BTreeMap, HashMap}, |
|
|
|
|
@ -39,6 +40,8 @@ pub struct Globals {
@@ -39,6 +40,8 @@ pub struct Globals {
|
|
|
|
|
keypair: Arc<ruma::signatures::Ed25519KeyPair>, |
|
|
|
|
dns_resolver: TokioAsyncResolver, |
|
|
|
|
jwt_decoding_key: Option<jsonwebtoken::DecodingKey<'static>>, |
|
|
|
|
pub stable_room_versions: Vec<RoomVersionId>, |
|
|
|
|
pub unstable_room_versions: Vec<RoomVersionId>, |
|
|
|
|
pub(super) server_signingkeys: Arc<dyn Tree>, |
|
|
|
|
pub bad_event_ratelimiter: Arc<RwLock<HashMap<EventId, RateLimitState>>>, |
|
|
|
|
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>, |
|
|
|
|
@ -132,6 +135,11 @@ impl Globals {
@@ -132,6 +135,11 @@ impl Globals {
|
|
|
|
|
.as_ref() |
|
|
|
|
.map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static()); |
|
|
|
|
|
|
|
|
|
// Supported and stable room versions
|
|
|
|
|
let stable_room_versions = vec![RoomVersionId::Version6]; |
|
|
|
|
// Experimental, partially supported room versions
|
|
|
|
|
let unstable_room_versions = vec![RoomVersionId::Version5]; |
|
|
|
|
|
|
|
|
|
let s = Self { |
|
|
|
|
globals, |
|
|
|
|
config, |
|
|
|
|
@ -143,6 +151,8 @@ impl Globals {
@@ -143,6 +151,8 @@ impl Globals {
|
|
|
|
|
tls_name_override, |
|
|
|
|
server_signingkeys, |
|
|
|
|
jwt_decoding_key, |
|
|
|
|
stable_room_versions, |
|
|
|
|
unstable_room_versions, |
|
|
|
|
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())), |
|
|
|
|
bad_signature_ratelimiter: Arc::new(RwLock::new(HashMap::new())), |
|
|
|
|
servername_ratelimiter: Arc::new(RwLock::new(HashMap::new())), |
|
|
|
|
@ -214,6 +224,22 @@ impl Globals {
@@ -214,6 +224,22 @@ impl Globals {
|
|
|
|
|
self.config.allow_room_creation |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn allow_unstable_room_versions(&self) -> bool { |
|
|
|
|
self.config.allow_unstable_room_versions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn default_room_version(&self) -> RoomVersionId { |
|
|
|
|
if self |
|
|
|
|
.supported_room_versions() |
|
|
|
|
.contains(&self.config.default_room_version.clone()) |
|
|
|
|
{ |
|
|
|
|
self.config.default_room_version.clone() |
|
|
|
|
} else { |
|
|
|
|
error!("Room version in config isn't supported, falling back to Version 6"); |
|
|
|
|
RoomVersionId::Version6 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn trusted_servers(&self) -> &[Box<ServerName>] { |
|
|
|
|
&self.config.trusted_servers |
|
|
|
|
} |
|
|
|
|
@ -246,6 +272,19 @@ impl Globals {
@@ -246,6 +272,19 @@ impl Globals {
|
|
|
|
|
&self.config.turn_secret |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> { |
|
|
|
|
let mut room_versions: Vec<RoomVersionId> = vec![]; |
|
|
|
|
self.stable_room_versions |
|
|
|
|
.iter() |
|
|
|
|
.for_each(|room_version| room_versions.push(room_version.clone())); |
|
|
|
|
if self.allow_unstable_room_versions() { |
|
|
|
|
self.unstable_room_versions |
|
|
|
|
.iter() |
|
|
|
|
.for_each(|room_version| room_versions.push(room_version.clone())); |
|
|
|
|
}; |
|
|
|
|
room_versions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// TODO: the key valid until timestamp is only honored in room version > 4
|
|
|
|
|
/// Remove the outdated keys and insert the new ones.
|
|
|
|
|
///
|
|
|
|
|
|