2022-10-05 15:33:57 +02:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{
|
|
|
|
api::federation::discovery::{ServerSigningKeys, VerifyKey},
|
|
|
|
signatures::Ed25519KeyPair,
|
2022-10-09 17:26:53 +02:00
|
|
|
DeviceId, OwnedServerSigningKeyId, ServerName, UserId,
|
2022-10-05 20:34:31 +02:00
|
|
|
};
|
2022-09-07 13:25:51 +02:00
|
|
|
|
|
|
|
use crate::Result;
|
|
|
|
|
2022-10-05 15:33:57 +02:00
|
|
|
#[async_trait]
|
|
|
|
pub trait Data: Send + Sync {
|
|
|
|
fn next_count(&self) -> Result<u64>;
|
|
|
|
fn current_count(&self) -> Result<u64>;
|
|
|
|
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;
|
|
|
|
fn cleanup(&self) -> Result<()>;
|
2023-07-03 19:37:54 +02:00
|
|
|
fn memory_usage(&self) -> String;
|
|
|
|
fn clear_caches(&self, amount: u32);
|
2022-09-07 13:25:51 +02:00
|
|
|
fn load_keypair(&self) -> Result<Ed25519KeyPair>;
|
|
|
|
fn remove_keypair(&self) -> Result<()>;
|
2022-10-05 15:33:57 +02:00
|
|
|
fn add_signing_key(
|
|
|
|
&self,
|
|
|
|
origin: &ServerName,
|
|
|
|
new_keys: ServerSigningKeys,
|
2022-10-09 17:25:06 +02:00
|
|
|
) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
|
2022-10-05 15:33:57 +02:00
|
|
|
|
|
|
|
/// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server.
|
|
|
|
fn signing_keys_for(
|
|
|
|
&self,
|
|
|
|
origin: &ServerName,
|
2022-10-09 17:25:06 +02:00
|
|
|
) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
|
2022-10-05 15:33:57 +02:00
|
|
|
fn database_version(&self) -> Result<u64>;
|
|
|
|
fn bump_database_version(&self, new_version: u64) -> Result<()>;
|
2022-09-07 13:25:51 +02:00
|
|
|
}
|