From bd1618e78e4c4305a73bdd40004de2abe46c3ceb Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 18 Apr 2020 19:30:05 +0200 Subject: [PATCH] Remove proto.rs & move some definitions out of data.rs --- src/api_server.rs | 4 ++++ src/block.rs | 12 +++++++++++- src/data.rs | 23 ----------------------- src/main.rs | 7 ++----- src/membership.rs | 28 +++++++++++++++++++++++++++- src/object_table.rs | 1 + src/proto.rs | 31 ------------------------------- src/server.rs | 7 ++++++- src/version_table.rs | 1 + 9 files changed, 52 insertions(+), 62 deletions(-) delete mode 100644 src/proto.rs diff --git a/src/api_server.rs b/src/api_server.rs index f213b4d..14c58fc 100644 --- a/src/api_server.rs +++ b/src/api_server.rs @@ -9,11 +9,15 @@ use hyper::server::conn::AddrStream; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Method, Request, Response, Server, StatusCode}; +use crate::block::INLINE_THRESHOLD; +use crate::block_ref_table::*; use crate::data::*; use crate::error::Error; use crate::http_util::*; +use crate::object_table::*; use crate::server::Garage; use crate::table::EmptySortKey; +use crate::version_table::*; type BodyType = Box + Send + Unpin>; diff --git a/src/block.rs b/src/block.rs index 879cff2..60121ac 100644 --- a/src/block.rs +++ b/src/block.rs @@ -14,11 +14,13 @@ use crate::data; use crate::data::*; use crate::error::Error; use crate::membership::System; -use crate::proto::*; use crate::rpc_client::*; use crate::rpc_server::*; use crate::server::Garage; +pub const INLINE_THRESHOLD: usize = 3072; + +const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(42); const NEED_BLOCK_QUERY_TIMEOUT: Duration = Duration::from_secs(5); const RESYNC_RETRY_TIMEOUT: Duration = Duration::from_secs(10); @@ -31,6 +33,14 @@ pub enum Message { NeedBlockReply(bool), } +#[derive(Debug, Serialize, Deserialize)] +pub struct PutBlockMessage { + pub hash: Hash, + + #[serde(with = "serde_bytes")] + pub data: Vec, +} + impl RpcMessage for Message {} pub struct BlockManager { diff --git a/src/data.rs b/src/data.rs index a3b7b23..7db715c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -2,7 +2,6 @@ use rand::Rng; use serde::de::{self, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use sha2::{Digest, Sha256}; -use std::collections::HashMap; use std::fmt; use std::time::{SystemTime, UNIX_EPOCH}; @@ -123,25 +122,3 @@ pub fn debug_serialize(x: T) -> String { Err(e) => format!("", e), } } - -// Network management - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct NetworkConfig { - pub members: HashMap, - pub version: u64, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct NetworkConfigEntry { - pub datacenter: String, - pub n_tokens: u32, -} - -// Data management - -pub const INLINE_THRESHOLD: usize = 3072; - -pub use crate::block_ref_table::*; -pub use crate::object_table::*; -pub use crate::version_table::*; diff --git a/src/main.rs b/src/main.rs index 84b8c2b..3e91b21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ mod data; mod error; -mod proto; mod background; mod membership; @@ -25,12 +24,10 @@ use std::path::PathBuf; use std::sync::Arc; use structopt::StructOpt; -use data::*; use error::Error; -use membership::Message; -use proto::*; +use membership::*; use rpc_client::*; -use server::TlsConfig; +use server::{TlsConfig, DEFAULT_TIMEOUT}; #[derive(StructOpt, Debug)] #[structopt(name = "garage")] diff --git a/src/membership.rs b/src/membership.rs index 499637f..e2f4bb9 100644 --- a/src/membership.rs +++ b/src/membership.rs @@ -19,7 +19,6 @@ use tokio::sync::Mutex; use crate::background::BackgroundRunner; use crate::data::*; use crate::error::Error; -use crate::proto::*; use crate::rpc_client::*; use crate::rpc_server::*; use crate::server::Config; @@ -40,6 +39,33 @@ pub enum Message { impl RpcMessage for Message {} +#[derive(Debug, Serialize, Deserialize)] +pub struct PingMessage { + pub id: UUID, + pub rpc_port: u16, + + pub status_hash: Hash, + pub config_version: u64, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct AdvertisedNode { + pub id: UUID, + pub addr: SocketAddr, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NetworkConfig { + pub members: HashMap, + pub version: u64, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NetworkConfigEntry { + pub datacenter: String, + pub n_tokens: u32, +} + pub struct System { pub config: Config, pub id: UUID, diff --git a/src/object_table.rs b/src/object_table.rs index 880543e..a55af7d 100644 --- a/src/object_table.rs +++ b/src/object_table.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use crate::background::BackgroundRunner; use crate::data::*; use crate::table::*; +use crate::version_table::*; #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct Object { diff --git a/src/proto.rs b/src/proto.rs deleted file mode 100644 index d51aa36..0000000 --- a/src/proto.rs +++ /dev/null @@ -1,31 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::net::SocketAddr; -use std::time::Duration; - -use crate::data::*; - -pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); -pub const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(42); - -#[derive(Debug, Serialize, Deserialize)] -pub struct PingMessage { - pub id: UUID, - pub rpc_port: u16, - - pub status_hash: Hash, - pub config_version: u64, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct AdvertisedNode { - pub id: UUID, - pub addr: SocketAddr, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct PutBlockMessage { - pub hash: Hash, - - #[serde(with = "serde_bytes")] - pub data: Vec, -} diff --git a/src/server.rs b/src/server.rs index 57faea2..099e087 100644 --- a/src/server.rs +++ b/src/server.rs @@ -2,6 +2,7 @@ use std::io::{Read, Write}; use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; +use std::time::Duration; pub use futures_util::future::FutureExt; use serde::Deserialize; @@ -10,12 +11,16 @@ use tokio::sync::watch; use crate::api_server; use crate::background::*; use crate::block::*; +use crate::block_ref_table::*; use crate::data::*; use crate::error::Error; use crate::membership::System; -use crate::proto::*; +use crate::object_table::*; use crate::rpc_server::RpcServer; use crate::table::*; +use crate::version_table::*; + +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); #[derive(Deserialize, Debug, Clone)] pub struct Config { diff --git a/src/version_table.rs b/src/version_table.rs index 22290fd..62d6a70 100644 --- a/src/version_table.rs +++ b/src/version_table.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use std::sync::Arc; use crate::background::BackgroundRunner; +use crate::block_ref_table::*; use crate::data::*; use crate::table::*;