use std::{sync::Arc, time::Duration};
use borsh::BorshSerialize;
use qos_crypto::sha_256;
mod error;
pub mod msg;
pub mod services;
mod state;
pub use error::ProtocolError;
pub use state::ProtocolPhase;
pub(crate) use state::ProtocolState;
pub(crate) mod processor;
use tokio::sync::RwLock;
const MEGABYTE: usize = 1024 * 1024;
const MAX_ENCODED_MSG_LEN: usize = 128 * MEGABYTE;
pub const INITIAL_CLIENT_TIMEOUT: Duration = Duration::from_secs(5);
pub type Hash256 = [u8; 32];
pub trait QosHash: BorshSerialize {
fn qos_hash(&self) -> Hash256 {
sha_256(&borsh::to_vec(self).expect("Implements borsh serialize"))
}
}
impl<T: BorshSerialize> QosHash for T {}
type SharedProtocolState = Arc<RwLock<ProtocolState>>;
impl ProtocolState {
pub fn shared(self) -> SharedProtocolState {
Arc::new(RwLock::new(self))
}
}