Remove proto.rs & move some definitions out of data.rs

This commit is contained in:
Alex Auvolat 2020-04-18 19:30:05 +02:00
parent f41583e1b7
commit bd1618e78e
9 changed files with 52 additions and 62 deletions

View File

@ -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>;

View File

@ -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 {

View File

@ -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::*;

View File

@ -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")]

View File

@ -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,

View File

@ -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 {

View File

@ -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>,
}

View File

@ -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 {

View File

@ -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::*;