diff options
author | Alex Auvolat <alex@adnab.me> | 2021-02-21 15:24:30 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-02-21 15:24:30 +0100 |
commit | b1b640ae8bd8d2ed7c128cb3f90e3e56226a5560 (patch) | |
tree | 55a703af2b8816b5c2e1aeb635db3538daa96a75 /src/rpc | |
parent | e59322041a0f894db0dfbd32805303b64048c810 (diff) | |
download | garage-b1b640ae8bd8d2ed7c128cb3f90e3e56226a5560.tar.gz garage-b1b640ae8bd8d2ed7c128cb3f90e3e56226a5560.zip |
rename hash() to sha256sum(), we might want to change it at some places
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/membership.rs | 10 | ||||
-rw-r--r-- | src/rpc/ring.rs | 2 |
2 files changed, 5 insertions, 7 deletions
diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index 4872899b..2d3b37a2 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::io::{Read, Write}; +use std::fmt::Write as FmtWrite; use std::net::{IpAddr, SocketAddr}; use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -10,7 +11,6 @@ use futures::future::join_all; use futures::select; use futures_util::future::*; use serde::{Deserialize, Serialize}; -use sha2::{Digest, Sha256}; use tokio::prelude::*; use tokio::sync::watch; use tokio::sync::Mutex; @@ -134,16 +134,14 @@ impl Status { let mut nodes = self.nodes.iter().collect::<Vec<_>>(); nodes.sort_unstable_by_key(|(id, _status)| *id); - let mut hasher = Sha256::new(); + let mut nodes_txt = String::new(); debug!("Current set of pingable nodes: --"); for (id, status) in nodes { debug!("{} {}", hex::encode(&id), status.addr); - hasher.input(format!("{} {}\n", hex::encode(&id), status.addr)); + writeln!(&mut nodes_txt, "{} {}", hex::encode(&id), status.addr).unwrap(); } debug!("END --"); - self.hash - .as_slice_mut() - .copy_from_slice(&hasher.result()[..]); + self.hash = sha256sum(nodes_txt.as_bytes()); } } diff --git a/src/rpc/ring.rs b/src/rpc/ring.rs index 1646afbf..1df0bb41 100644 --- a/src/rpc/ring.rs +++ b/src/rpc/ring.rs @@ -56,7 +56,7 @@ impl Ring { let datacenter_idx = datacenters.iter().enumerate().find(|(_, dc)| *dc == datacenter).unwrap().0; for i in 0..config.n_tokens { - let location = hash(format!("{} {}", hex::encode(&id), i).as_bytes()); + let location = sha256sum(format!("{} {}", hex::encode(&id), i).as_bytes()); new_ring.push(RingEntry { location: location.into(), |