feat: improved state store

This commit is contained in:
Timo Kösters 2020-12-19 16:00:11 +01:00
parent 6e5b35ea92
commit 6606e41dde
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
13 changed files with 405 additions and 251 deletions

View file

@ -20,6 +20,7 @@ use serde::Deserialize;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use std::{convert::TryInto, fs::remove_dir_all};
use tokio::sync::Semaphore;
#[derive(Clone, Deserialize)]
pub struct Config {
@ -30,6 +31,8 @@ pub struct Config {
cache_capacity: u64,
#[serde(default = "default_max_request_size")]
max_request_size: u32,
#[serde(default = "default_max_concurrent_requests")]
max_concurrent_requests: u16,
#[serde(default)]
registration_disabled: bool,
#[serde(default)]
@ -39,7 +42,9 @@ pub struct Config {
}
fn default_server_name() -> Box<ServerName> {
"localhost".try_into().expect("")
"localhost"
.try_into()
.expect("localhost is valid servername")
}
fn default_cache_capacity() -> u64 {
@ -50,6 +55,10 @@ fn default_max_request_size() -> u32 {
20 * 1024 * 1024 // Default to 20 MB
}
fn default_max_concurrent_requests() -> u16 {
4
}
#[derive(Clone)]
pub struct Database {
pub globals: globals::Globals,
@ -159,6 +168,7 @@ impl Database {
roomuserid_invited: db.open_tree("roomuserid_invited")?,
userroomid_left: db.open_tree("userroomid_left")?,
statekey_short: db.open_tree("statekey_short")?,
stateid_pduid: db.open_tree("stateid_pduid")?,
pduid_statehash: db.open_tree("pduid_statehash")?,
roomid_statehash: db.open_tree("roomid_statehash")?,
@ -180,6 +190,7 @@ impl Database {
sending: sending::Sending {
servernamepduids: db.open_tree("servernamepduids")?,
servercurrentpdus: db.open_tree("servercurrentpdus")?,
maximum_requests: Arc::new(Semaphore::new(10)),
},
admin: admin::Admin {
sender: admin_sender,