diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-18 19:30:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-18 19:30:05 +0200 |
commit | bd1618e78e4c4305a73bdd40004de2abe46c3ceb (patch) | |
tree | 8d84b73808a3a968941a59672aae398a61f8d5ff | |
parent | f41583e1b731574b4bb13a20d4b3fd9fe3a899f5 (diff) | |
download | garage-bd1618e78e4c4305a73bdd40004de2abe46c3ceb.tar.gz garage-bd1618e78e4c4305a73bdd40004de2abe46c3ceb.zip |
Remove proto.rs & move some definitions out of data.rs
-rw-r--r-- | src/api_server.rs | 4 | ||||
-rw-r--r-- | src/block.rs | 12 | ||||
-rw-r--r-- | src/data.rs | 23 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | src/membership.rs | 28 | ||||
-rw-r--r-- | src/object_table.rs | 1 | ||||
-rw-r--r-- | src/proto.rs | 31 | ||||
-rw-r--r-- | src/server.rs | 7 | ||||
-rw-r--r-- | src/version_table.rs | 1 |
9 files changed, 52 insertions, 62 deletions
diff --git a/src/api_server.rs b/src/api_server.rs index f213b4dd..14c58fc4 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<dyn HttpBody<Data = Bytes, Error = Error> + Send + Unpin>; diff --git a/src/block.rs b/src/block.rs index 879cff2c..60121ac5 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<u8>, +} + impl RpcMessage for Message {} pub struct BlockManager { diff --git a/src/data.rs b/src/data.rs index a3b7b23b..7db715cb 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<T: Serialize>(x: T) -> String { Err(e) => format!("<JSON serialization error: {}>", e), } } - -// Network management - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct NetworkConfig { - pub members: HashMap<UUID, NetworkConfigEntry>, - 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 84b8c2bc..3e91b21d 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 499637fb..e2f4bb90 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<UUID, NetworkConfigEntry>, + 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 880543e1..a55af7db 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 d51aa36b..00000000 --- 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<u8>, -} diff --git a/src/server.rs b/src/server.rs index 57faea21..099e087e 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 22290fd7..62d6a702 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::*; |