Skip to main content

chord_dht/
core.rs

1pub mod node;
2pub mod ring;
3pub mod config;
4pub mod data_store;
5pub mod error;
6
7pub use node::*;
8pub use config::*;
9pub use error::*;
10
11use std::{
12	collections::hash_map::DefaultHasher,
13	hash::{Hash, Hasher}
14};
15
16pub fn calculate_hash(data: &[u8]) -> u64 {
17	let mut hasher = DefaultHasher::new();
18	data.hash(&mut hasher);
19	hasher.finish()
20}
21
22pub fn construct_node(addr: &str) -> Node {
23	Node {
24		addr: addr.to_string(),
25		id: calculate_hash(addr.as_bytes())
26	}
27}