2022-10-05 15:33:57 +02:00
|
|
|
use std::collections::BTreeMap;
|
2024-03-19 04:37:35 -07:00
|
|
|
use std::error::Error;
|
2022-10-05 15:33:57 +02:00
|
|
|
|
|
|
|
use async_trait::async_trait;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{
|
2024-03-05 19:48:54 -05:00
|
|
|
api::federation::discovery::{ServerSigningKeys, VerifyKey},
|
|
|
|
signatures::Ed25519KeyPair,
|
|
|
|
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 {
|
2024-03-05 19:48:54 -05:00
|
|
|
fn next_count(&self) -> Result<u64>;
|
|
|
|
fn current_count(&self) -> Result<u64>;
|
|
|
|
fn last_check_for_updates_id(&self) -> Result<u64>;
|
|
|
|
fn update_check_for_updates_id(&self, id: u64) -> Result<()>;
|
2024-03-14 00:15:21 -04:00
|
|
|
#[allow(unused_qualifications)] // async traits
|
2024-03-05 19:48:54 -05:00
|
|
|
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;
|
|
|
|
fn cleanup(&self) -> Result<()>;
|
2024-03-06 18:14:30 -05:00
|
|
|
fn flush(&self) -> Result<()>;
|
2024-03-05 19:48:54 -05:00
|
|
|
fn memory_usage(&self) -> String;
|
|
|
|
fn clear_caches(&self, amount: u32);
|
|
|
|
fn load_keypair(&self) -> Result<Ed25519KeyPair>;
|
|
|
|
fn remove_keypair(&self) -> Result<()>;
|
|
|
|
fn add_signing_key(
|
|
|
|
&self, origin: &ServerName, new_keys: ServerSigningKeys,
|
|
|
|
) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
|
2022-10-05 15:33:57 +02:00
|
|
|
|
2024-03-05 19:48:54 -05:00
|
|
|
/// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found
|
|
|
|
/// for the server.
|
|
|
|
fn signing_keys_for(&self, origin: &ServerName) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
|
|
|
|
fn database_version(&self) -> Result<u64>;
|
|
|
|
fn bump_database_version(&self, new_version: u64) -> Result<()>;
|
2024-03-19 04:37:35 -07:00
|
|
|
fn backup(&self) -> Result<(), Box<dyn Error>> { unimplemented!() }
|
|
|
|
fn backup_list(&self) -> Result<String> { Ok(String::new()) }
|
2022-09-07 13:25:51 +02:00
|
|
|
}
|