mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-07-22 17:18:35 +00:00
implement sync rotation
This commit is contained in:
parent
bcfea98457
commit
7e9014d5c9
3 changed files with 37 additions and 5 deletions
|
@ -11,11 +11,12 @@ use rustls::{ServerCertVerifier, WebPKIVerifier};
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
fs,
|
||||
future::Future,
|
||||
path::PathBuf,
|
||||
sync::{Arc, RwLock},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
use tokio::sync::{broadcast, Semaphore};
|
||||
use trust_dns_resolver::TokioAsyncResolver;
|
||||
|
||||
use super::abstraction::Tree;
|
||||
|
@ -47,6 +48,7 @@ pub struct Globals {
|
|||
), // since, rx
|
||||
>,
|
||||
>,
|
||||
pub rotate: RotationHandler,
|
||||
}
|
||||
|
||||
struct MatrixServerVerifier {
|
||||
|
@ -82,6 +84,28 @@ impl ServerCertVerifier for MatrixServerVerifier {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>);
|
||||
|
||||
impl RotationHandler {
|
||||
pub fn new() -> Self {
|
||||
let (s, r) = broadcast::channel::<()>(1);
|
||||
|
||||
Self(s, r)
|
||||
}
|
||||
|
||||
pub fn watch(&self) -> impl Future<Output = ()> {
|
||||
let mut r = self.0.subscribe();
|
||||
|
||||
async move {
|
||||
let _ = r.recv().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fire(&self) {
|
||||
let _ = self.0.send(());
|
||||
}
|
||||
}
|
||||
|
||||
impl Globals {
|
||||
pub fn load(
|
||||
globals: Arc<dyn Tree>,
|
||||
|
@ -168,6 +192,7 @@ impl Globals {
|
|||
bad_signature_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
|
||||
servername_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
|
||||
sync_receivers: RwLock::new(BTreeMap::new()),
|
||||
rotate: RotationHandler::new(),
|
||||
};
|
||||
|
||||
fs::create_dir_all(s.get_media_folder())?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue