#![cfg_attr(not(test), warn(clippy::unwrap_used, clippy::expect_used))]
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use tsoracle_consensus::ConsensusDriver;
mod config;
pub use config::{
DriverConfig, FileConfig, MemberAddr, OpenraftConfig, PaxosConfig, PeerTlsConfig, RaftTuning,
parse_peer_map,
};
mod drivers;
#[cfg(feature = "file")]
pub use drivers::file::init_file_seeded;
mod error;
pub use error::StandaloneError;
mod admin;
pub use admin::{
AdminError, MemberEntry, MemberRole, MembershipAdmin, MembershipView, NewMember,
UnsupportedAdmin,
};
#[cfg(feature = "openraft")]
pub mod admin_proto {
tonic::include_proto!("tsoracle.admin.v1");
}
mod transport;
pub use transport::TransportHandle;
#[cfg(any(feature = "openraft", feature = "paxos"))]
pub(crate) mod peer_tls;
pub struct Standalone {
pub driver: Arc<dyn ConsensusDriver>,
transport: TransportHandle,
drain: Option<Pin<Box<dyn Future<Output = ()> + Send>>>,
pub admin: Arc<dyn MembershipAdmin>,
admin_transport: TransportHandle,
}
impl Standalone {
pub fn take_drain(&mut self) -> Option<Pin<Box<dyn Future<Output = ()> + Send>>> {
self.drain.take()
}
pub async fn shutdown(mut self) {
self.admin_transport.shutdown().await;
self.transport.shutdown().await;
}
}
pub async fn build(cfg: DriverConfig) -> Result<Standalone, StandaloneError> {
match cfg {
#[cfg(feature = "file")]
DriverConfig::File(c) => drivers::file::build_file(c),
#[cfg(feature = "openraft")]
DriverConfig::Openraft(c) => drivers::openraft::build_openraft(c).await,
#[cfg(feature = "paxos")]
DriverConfig::Paxos(c) => drivers::paxos::build_paxos(c).await,
}
}