From 40763fd749f36fe612f20f79ff7cac51252cc128 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 23 Feb 2021 18:46:25 +0100 Subject: [PATCH] Cargo fmt --- src/api/api_server.rs | 11 ++++++++--- src/api/s3_copy.rs | 4 ++-- src/api/s3_delete.rs | 4 ++-- src/api/s3_list.rs | 18 ++++++++++++++---- src/api/s3_put.rs | 31 +++++++++++++++++++++++-------- src/api/signature.rs | 7 +++++-- src/rpc/lib.rs | 3 +-- src/rpc/membership.rs | 4 ++-- src/rpc/ring.rs | 11 +++++++---- src/table/table_fullcopy.rs | 2 +- src/table/table_sharded.rs | 2 +- src/util/data.rs | 2 +- 12 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/api/api_server.rs b/src/api/api_server.rs index c3e205ab..c6b1d483 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -160,10 +160,15 @@ async fn handler_inner(garage: Arc, req: Request) -> Result").unwrap(); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(xml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(xml.into_bytes()))?) } diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index 91cfbfbe..4b6a2b18 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -123,8 +123,8 @@ pub async fn handle_delete_objects( writeln!(&mut retxml, "").unwrap(); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(retxml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(retxml.into_bytes()))?) } struct DeleteRequest { diff --git a/src/api/s3_list.rs b/src/api/s3_list.rs index 2be47091..98d774db 100644 --- a/src/api/s3_list.rs +++ b/src/api/s3_list.rs @@ -229,10 +229,20 @@ pub async fn handle_list( } else { // TODO: are these supposed to be urlencoded when encoding-type is URL?? if let Some(mkr) = &query.marker { - writeln!(&mut xml, "\t{}", xml_encode_key(mkr, query.urlencode_resp)).unwrap(); + writeln!( + &mut xml, + "\t{}", + xml_encode_key(mkr, query.urlencode_resp) + ) + .unwrap(); } if let Some(next_marker) = truncated { - writeln!(&mut xml, "\t{}", xml_encode_key(&next_marker, query.urlencode_resp)).unwrap(); + writeln!( + &mut xml, + "\t{}", + xml_encode_key(&next_marker, query.urlencode_resp) + ) + .unwrap(); } } @@ -272,6 +282,6 @@ pub async fn handle_list( debug!("{}", xml); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(xml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(xml.into_bytes()))?) } diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index 969b4098..ec599a05 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -17,8 +17,8 @@ use garage_model::garage::Garage; use garage_model::object_table::*; use garage_model::version_table::*; -use crate::error::*; use crate::encoding::*; +use crate::error::*; use crate::signature::verify_signed_content; pub async fn handle_put( @@ -427,8 +427,12 @@ pub async fn handle_complete_multipart_upload( verify_signed_content(content_sha256, &body[..])?; let body_xml = roxmltree::Document::parse(&std::str::from_utf8(&body)?)?; - let body_list_of_parts = parse_complete_multpart_upload_body(&body_xml).ok_or_bad_request("Invalid CompleteMultipartUpload XML")?; - debug!("CompleteMultipartUpload list of parts: {:?}", body_list_of_parts); + let body_list_of_parts = parse_complete_multpart_upload_body(&body_xml) + .ok_or_bad_request("Invalid CompleteMultipartUpload XML")?; + debug!( + "CompleteMultipartUpload list of parts: {:?}", + body_list_of_parts + ); let version_uuid = decode_upload_id(upload_id)?; @@ -461,10 +465,16 @@ pub async fn handle_complete_multipart_upload( // Check that the list of parts they gave us corresponds to the parts we have here // TODO: check MD5 sum of all uploaded parts? but that would mean we have to store them somewhere... - let mut parts = version.blocks().iter().map(|x| x.part_number) + let mut parts = version + .blocks() + .iter() + .map(|x| x.part_number) .collect::>(); parts.dedup(); - let same_parts = body_list_of_parts.iter().map(|x| &x.part_number).eq(parts.iter()); + let same_parts = body_list_of_parts + .iter() + .map(|x| &x.part_number) + .eq(parts.iter()); if !same_parts { return Err(Error::BadRequest(format!("We don't have the same parts"))); } @@ -604,7 +614,9 @@ struct CompleteMultipartUploadPart { part_number: u64, } -fn parse_complete_multpart_upload_body(xml: &roxmltree::Document) -> Option> { +fn parse_complete_multpart_upload_body( + xml: &roxmltree::Document, +) -> Option> { let mut parts = vec![]; let root = xml.root(); @@ -616,8 +628,11 @@ fn parse_complete_multpart_upload_body(xml: &roxmltree::Document) -> Option String { } pub fn verify_signed_content(content_sha256: Option, body: &[u8]) -> Result<(), Error> { - let expected_sha256 = content_sha256.ok_or_bad_request("Request content hash not signed, aborting.")?; + let expected_sha256 = + content_sha256.ok_or_bad_request("Request content hash not signed, aborting.")?; if expected_sha256 != sha256sum(body) { - return Err(Error::BadRequest(format!("Request content hash does not match signed hash"))); + return Err(Error::BadRequest(format!( + "Request content hash does not match signed hash" + ))); } Ok(()) } diff --git a/src/rpc/lib.rs b/src/rpc/lib.rs index 71d75395..00e31f57 100644 --- a/src/rpc/lib.rs +++ b/src/rpc/lib.rs @@ -4,9 +4,8 @@ extern crate log; pub mod consul; pub(crate) mod tls_util; -pub mod ring; pub mod membership; +pub mod ring; pub mod rpc_client; pub mod rpc_server; - diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index 783f6eb8..f9047b35 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use std::io::{Read, Write}; use std::fmt::Write as FmtWrite; +use std::io::{Read, Write}; use std::net::{IpAddr, SocketAddr}; use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -20,9 +20,9 @@ use garage_util::data::*; use garage_util::error::Error; use crate::consul::get_consul_nodes; +use crate::ring::*; use crate::rpc_client::*; use crate::rpc_server::*; -use crate::ring::*; const PING_INTERVAL: Duration = Duration::from_secs(10); const CONSUL_INTERVAL: Duration = Duration::from_secs(60); diff --git a/src/rpc/ring.rs b/src/rpc/ring.rs index 1df0bb41..5ca43ac9 100644 --- a/src/rpc/ring.rs +++ b/src/rpc/ring.rs @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize}; use garage_util::data::*; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetworkConfig { pub members: HashMap, @@ -13,7 +12,7 @@ pub struct NetworkConfig { impl NetworkConfig { pub(crate) fn new() -> Self { - Self{ + Self { members: HashMap::new(), version: 0, } @@ -27,7 +26,6 @@ pub struct NetworkConfigEntry { pub tag: String, } - #[derive(Clone)] pub struct Ring { pub config: NetworkConfig, @@ -53,7 +51,12 @@ impl Ring { if !datacenters.contains(datacenter) { datacenters.push(datacenter.to_string()); } - let datacenter_idx = datacenters.iter().enumerate().find(|(_, dc)| *dc == datacenter).unwrap().0; + let datacenter_idx = datacenters + .iter() + .enumerate() + .find(|(_, dc)| *dc == datacenter) + .unwrap() + .0; for i in 0..config.n_tokens { let location = sha256sum(format!("{} {}", hex::encode(&id), i).as_bytes()); diff --git a/src/table/table_fullcopy.rs b/src/table/table_fullcopy.rs index 64ac89ee..5dd0ebb1 100644 --- a/src/table/table_fullcopy.rs +++ b/src/table/table_fullcopy.rs @@ -1,7 +1,7 @@ use arc_swap::ArcSwapOption; use std::sync::Arc; -use garage_rpc::membership::{System}; +use garage_rpc::membership::System; use garage_rpc::ring::Ring; use garage_util::data::*; diff --git a/src/table/table_sharded.rs b/src/table/table_sharded.rs index 4f98902d..cbb1bc01 100644 --- a/src/table/table_sharded.rs +++ b/src/table/table_sharded.rs @@ -1,4 +1,4 @@ -use garage_rpc::membership::{System}; +use garage_rpc::membership::System; use garage_rpc::ring::Ring; use garage_util::data::*; diff --git a/src/util/data.rs b/src/util/data.rs index a1c292e7..f46454be 100644 --- a/src/util/data.rs +++ b/src/util/data.rs @@ -99,8 +99,8 @@ pub fn blake2sum(data: &[u8]) -> Hash { pub type FastHash = u64; pub fn fasthash(data: &[u8]) -> FastHash { - use std::hash::Hasher; use fasthash::{xx::Hasher64, FastHasher}; + use std::hash::Hasher; let mut h = Hasher64::new(); h.write(data);