aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Cargo.toml5
-rw-r--r--src/util/config.rs63
-rw-r--r--src/util/error.rs11
3 files changed, 36 insertions, 43 deletions
diff --git a/src/util/Cargo.toml b/src/util/Cargo.toml
index 91e0b2b9..c7ddc9e6 100644
--- a/src/util/Cargo.toml
+++ b/src/util/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "garage_util"
-version = "0.3.0"
+version = "0.4.0"
authors = ["Alex Auvolat <alex@adnab.me>"]
edition = "2018"
license = "AGPL-3.0"
@@ -32,7 +32,6 @@ toml = "0.5"
futures = "0.3"
tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "io-util", "net", "time", "macros", "sync", "signal", "fs"] }
+netapp = { version = "0.3.0", git = "https://git.deuxfleurs.fr/lx/netapp" }
http = "0.2"
hyper = "0.14"
-rustls = "0.19"
-webpki = "0.21"
diff --git a/src/util/config.rs b/src/util/config.rs
index 46b918a9..ee153dfa 100644
--- a/src/util/config.rs
+++ b/src/util/config.rs
@@ -3,8 +3,11 @@ use std::io::Read;
use std::net::SocketAddr;
use std::path::PathBuf;
+use serde::de::Error as SerdeError;
use serde::{de, Deserialize};
+use netapp::NodeID;
+
use crate::error::Error;
/// Represent the whole configuration
@@ -26,20 +29,20 @@ pub struct Config {
// (we can add more aliases for this later)
pub replication_mode: String,
+ /// RPC secret key: 32 bytes hex encoded
+ pub rpc_secret: String,
+
/// Address to bind for RPC
pub rpc_bind_addr: SocketAddr,
/// Bootstrap peers RPC address
#[serde(deserialize_with = "deserialize_vec_addr")]
- pub bootstrap_peers: Vec<SocketAddr>,
+ pub bootstrap_peers: Vec<(NodeID, SocketAddr)>,
/// Consule host to connect to to discover more peers
pub consul_host: Option<String>,
/// Consul service name to use
pub consul_service_name: Option<String>,
- /// Configuration for RPC TLS
- pub rpc_tls: Option<TlsConfig>,
-
/// Max number of concurrent RPC request
#[serde(default = "default_max_concurrent_rpc_requests")]
pub max_concurrent_rpc_requests: usize,
@@ -59,17 +62,6 @@ pub struct Config {
pub s3_web: WebConfig,
}
-/// Configuration for RPC TLS
-#[derive(Deserialize, Debug, Clone)]
-pub struct TlsConfig {
- /// Path to certificate autority used for all nodes
- pub ca_cert: String,
- /// Path to public certificate for this node
- pub node_cert: String,
- /// Path to private key for this node
- pub node_key: String,
-}
-
/// Configuration for S3 api
#[derive(Deserialize, Debug, Clone)]
pub struct ApiConfig {
@@ -115,27 +107,32 @@ pub fn read_config(config_file: PathBuf) -> Result<Config, Error> {
Ok(toml::from_str(&config)?)
}
-fn deserialize_vec_addr<'de, D>(deserializer: D) -> Result<Vec<SocketAddr>, D::Error>
+fn deserialize_vec_addr<'de, D>(deserializer: D) -> Result<Vec<(NodeID, SocketAddr)>, D::Error>
where
D: de::Deserializer<'de>,
{
use std::net::ToSocketAddrs;
- Ok(<Vec<&str>>::deserialize(deserializer)?
- .iter()
- .filter_map(|&name| {
- name.to_socket_addrs()
- .map(|iter| (name, iter))
- .map_err(|_| warn!("Error resolving \"{}\"", name))
- .ok()
- })
- .map(|(name, iter)| {
- let v = iter.collect::<Vec<_>>();
- if v.is_empty() {
- warn!("Error resolving \"{}\"", name)
- }
- v
- })
- .flatten()
- .collect())
+ let mut ret = vec![];
+
+ for peer in <Vec<&str>>::deserialize(deserializer)? {
+ let delim = peer
+ .find('@')
+ .ok_or_else(|| D::Error::custom("Invalid bootstrap peer: public key not specified"))?;
+ let (key, host) = peer.split_at(delim);
+ let pubkey = NodeID::from_slice(&hex::decode(&key).map_err(D::Error::custom)?)
+ .ok_or_else(|| D::Error::custom("Invalid bootstrap peer public key"))?;
+ let hosts = host[1..]
+ .to_socket_addrs()
+ .map_err(D::Error::custom)?
+ .collect::<Vec<_>>();
+ if hosts.is_empty() {
+ return Err(D::Error::custom(format!("Error resolving {}", &host[1..])));
+ }
+ for host in hosts {
+ ret.push((pubkey.clone(), host));
+ }
+ }
+
+ Ok(ret)
}
diff --git a/src/util/error.rs b/src/util/error.rs
index c3d84e63..804a0d4d 100644
--- a/src/util/error.rs
+++ b/src/util/error.rs
@@ -11,8 +11,8 @@ pub enum RpcError {
#[error(display = "Node is down: {:?}.", _0)]
NodeDown(Uuid),
- #[error(display = "Timeout: {}", _0)]
- Timeout(#[error(source)] tokio::time::error::Elapsed),
+ #[error(display = "Timeout")]
+ Timeout,
#[error(display = "HTTP error: {}", _0)]
Http(#[error(source)] http::Error),
@@ -45,11 +45,8 @@ pub enum Error {
#[error(display = "Invalid HTTP header value: {}", _0)]
HttpHeader(#[error(source)] http::header::ToStrError),
- #[error(display = "TLS error: {}", _0)]
- Tls(#[error(source)] rustls::TLSError),
-
- #[error(display = "PKI error: {}", _0)]
- Pki(#[error(source)] webpki::Error),
+ #[error(display = "Netapp error: {}", _0)]
+ Netapp(#[error(source)] netapp::error::Error),
#[error(display = "Sled error: {}", _0)]
Sled(#[error(source)] sled::Error),