diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-06 19:55:39 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-06 19:55:39 +0200 |
commit | 1a5e6e39af19d572a9de7f54e66bef911bdbbf2f (patch) | |
tree | 201638e94ede125b654691953d33aeb37fa9e2f7 /src/membership.rs | |
parent | 7102db1d544bec663a8492b24c455168d0b83f08 (diff) | |
download | garage-1a5e6e39af19d572a9de7f54e66bef911bdbbf2f.tar.gz garage-1a5e6e39af19d572a9de7f54e66bef911bdbbf2f.zip |
Some more basic work
Diffstat (limited to 'src/membership.rs')
-rw-r--r-- | src/membership.rs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/membership.rs b/src/membership.rs new file mode 100644 index 00000000..c14d370b --- /dev/null +++ b/src/membership.rs @@ -0,0 +1,86 @@ +use std::sync::Arc; +use std::collections::HashMap; +use std::time::Duration; +use std::net::SocketAddr; + +use hyper::client::Client; +use tokio::sync::RwLock; + +use crate::Config; +use crate::error::Error; +use crate::data::*; +use crate::proto::*; +use crate::rpc::*; + +const PING_INTERVAL: Duration = Duration::from_secs(10); +const PING_TIMEOUT: Duration = Duration::from_secs(2); +const MAX_FAILED_PINGS: usize = 3; + +pub struct System { + pub config: Config, + pub id: UUID, + + pub rpc_client: Client<hyper::client::HttpConnector, hyper::Body>, + + pub members: RwLock<Members>, +} + +pub struct Members { + pub present: Vec<UUID>, + pub status: HashMap<UUID, NodeStatus>, + + pub config: HashMap<UUID, NodeConfig>, + pub config_version: u64, +} + +pub struct NodeStatus { + pub addr: SocketAddr, + remaining_ping_attempts: usize, +} + +pub struct NodeConfig { + pub n_tokens: u32, +} + +impl System { + pub fn new(config: Config, id: UUID) -> Self { + System{ + config, + id, + rpc_client: Client::new(), + members: RwLock::new(Members{ + present: Vec::new(), + status: HashMap::new(), + config: HashMap::new(), + config_version: 0, + }), + } + } + + pub async fn broadcast(&self) -> Vec<UUID> { + self.members.read().await.present.clone() + } +} + +pub async fn bootstrap(system: Arc<System>) { + rpc_call_many_addr(system.clone(), + &system.config.bootstrap_peers, + &Message::Ping(PingMessage{ + id: system.id, + rpc_port: system.config.rpc_port, + present_hash: [0u8; 32], + config_version: 0, + }), + None, + PING_TIMEOUT).await; + + unimplemented!() //TODO +} + +pub async fn handle_ping(sys: Arc<System>, from: &SocketAddr, ping: &PingMessage) -> Result<Message, Error> { + unimplemented!() //TODO +} + +pub async fn handle_advertise_node(sys: Arc<System>, ping: &AdvertiseNodeMessage) -> Result<Message, Error> { + unimplemented!() //TODO +} |