mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-22 08:01:02 +00:00
Remove proto.rs & move some definitions out of data.rs
This commit is contained in:
parent
f41583e1b7
commit
bd1618e78e
9 changed files with 52 additions and 62 deletions
|
@ -9,11 +9,15 @@ use hyper::server::conn::AddrStream;
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use hyper::{Body, Method, Request, Response, Server, StatusCode};
|
use hyper::{Body, Method, Request, Response, Server, StatusCode};
|
||||||
|
|
||||||
|
use crate::block::INLINE_THRESHOLD;
|
||||||
|
use crate::block_ref_table::*;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::http_util::*;
|
use crate::http_util::*;
|
||||||
|
use crate::object_table::*;
|
||||||
use crate::server::Garage;
|
use crate::server::Garage;
|
||||||
use crate::table::EmptySortKey;
|
use crate::table::EmptySortKey;
|
||||||
|
use crate::version_table::*;
|
||||||
|
|
||||||
type BodyType = Box<dyn HttpBody<Data = Bytes, Error = Error> + Send + Unpin>;
|
type BodyType = Box<dyn HttpBody<Data = Bytes, Error = Error> + Send + Unpin>;
|
||||||
|
|
||||||
|
|
12
src/block.rs
12
src/block.rs
|
@ -14,11 +14,13 @@ use crate::data;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::membership::System;
|
use crate::membership::System;
|
||||||
use crate::proto::*;
|
|
||||||
use crate::rpc_client::*;
|
use crate::rpc_client::*;
|
||||||
use crate::rpc_server::*;
|
use crate::rpc_server::*;
|
||||||
use crate::server::Garage;
|
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 NEED_BLOCK_QUERY_TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
const RESYNC_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
|
const RESYNC_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
|
@ -31,6 +33,14 @@ pub enum Message {
|
||||||
NeedBlockReply(bool),
|
NeedBlockReply(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct PutBlockMessage {
|
||||||
|
pub hash: Hash,
|
||||||
|
|
||||||
|
#[serde(with = "serde_bytes")]
|
||||||
|
pub data: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
impl RpcMessage for Message {}
|
impl RpcMessage for Message {}
|
||||||
|
|
||||||
pub struct BlockManager {
|
pub struct BlockManager {
|
||||||
|
|
23
src/data.rs
23
src/data.rs
|
@ -2,7 +2,6 @@ use rand::Rng;
|
||||||
use serde::de::{self, Visitor};
|
use serde::de::{self, Visitor};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
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),
|
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::*;
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod data;
|
mod data;
|
||||||
mod error;
|
mod error;
|
||||||
mod proto;
|
|
||||||
|
|
||||||
mod background;
|
mod background;
|
||||||
mod membership;
|
mod membership;
|
||||||
|
@ -25,12 +24,10 @@ use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use data::*;
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use membership::Message;
|
use membership::*;
|
||||||
use proto::*;
|
|
||||||
use rpc_client::*;
|
use rpc_client::*;
|
||||||
use server::TlsConfig;
|
use server::{TlsConfig, DEFAULT_TIMEOUT};
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(name = "garage")]
|
#[structopt(name = "garage")]
|
||||||
|
|
|
@ -19,7 +19,6 @@ use tokio::sync::Mutex;
|
||||||
use crate::background::BackgroundRunner;
|
use crate::background::BackgroundRunner;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::proto::*;
|
|
||||||
use crate::rpc_client::*;
|
use crate::rpc_client::*;
|
||||||
use crate::rpc_server::*;
|
use crate::rpc_server::*;
|
||||||
use crate::server::Config;
|
use crate::server::Config;
|
||||||
|
@ -40,6 +39,33 @@ pub enum Message {
|
||||||
|
|
||||||
impl RpcMessage for 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 struct System {
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub id: UUID,
|
pub id: UUID,
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||||
use crate::background::BackgroundRunner;
|
use crate::background::BackgroundRunner;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::table::*;
|
use crate::table::*;
|
||||||
|
use crate::version_table::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
|
|
31
src/proto.rs
31
src/proto.rs
|
@ -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>,
|
|
||||||
}
|
|
|
@ -2,6 +2,7 @@ use std::io::{Read, Write};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub use futures_util::future::FutureExt;
|
pub use futures_util::future::FutureExt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -10,12 +11,16 @@ use tokio::sync::watch;
|
||||||
use crate::api_server;
|
use crate::api_server;
|
||||||
use crate::background::*;
|
use crate::background::*;
|
||||||
use crate::block::*;
|
use crate::block::*;
|
||||||
|
use crate::block_ref_table::*;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::membership::System;
|
use crate::membership::System;
|
||||||
use crate::proto::*;
|
use crate::object_table::*;
|
||||||
use crate::rpc_server::RpcServer;
|
use crate::rpc_server::RpcServer;
|
||||||
use crate::table::*;
|
use crate::table::*;
|
||||||
|
use crate::version_table::*;
|
||||||
|
|
||||||
|
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::background::BackgroundRunner;
|
use crate::background::BackgroundRunner;
|
||||||
|
use crate::block_ref_table::*;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::table::*;
|
use crate::table::*;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue