diff options
author | 2022-01-25 17:26:02 +0800 | |
---|---|---|
committer | 2022-01-25 21:15:26 +0800 | |
commit | 720778b07cc9270710ae01bcde2ad426e91adb6b (patch) | |
tree | 5b6fb49f0f631fb7ec22dbc3de076b0e1fcb21c4 /src | |
parent | 95efd457d50b3401ccfe9134d0acdd4ce4e2549c (diff) | |
download | rathole-720778b07cc9270710ae01bcde2ad426e91adb6b.tar.gz rathole-720778b07cc9270710ae01bcde2ad426e91adb6b.tar.zst rathole-720778b07cc9270710ae01bcde2ad426e91adb6b.zip |
chore: clean up
Diffstat (limited to '')
-rw-r--r-- | src/helper.rs | 75 |
1 files changed, 1 insertions, 74 deletions
diff --git a/src/helper.rs b/src/helper.rs index 7903312..6953919 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -1,9 +1,4 @@ -use std::{ - collections::hash_map::DefaultHasher, - hash::{Hash, Hasher}, - net::SocketAddr, - time::Duration, -}; +use std::{net::SocketAddr, time::Duration}; use anyhow::{anyhow, Result}; use socket2::{SockRef, TcpKeepalive}; @@ -56,71 +51,3 @@ pub async fn udp_connect<A: ToSocketAddrs>(addr: A) -> Result<UdpSocket> { s.connect(addr).await?; Ok(s) } - -// FIXME: These functions are for the load balance for UDP. But not used for now. -#[allow(dead_code)] -pub fn hash_socket_addr(a: &SocketAddr) -> u64 { - let mut hasher = DefaultHasher::new(); - a.hash(&mut hasher); - hasher.finish() -} - -// Wait for the stabilization of https://doc.rust-lang.org/std/primitive.i64.html#method.log2 -#[allow(dead_code)] -fn log2_floor(x: usize) -> u8 { - (x as f64).log2().floor() as u8 -} - -#[allow(dead_code)] -pub fn floor_to_pow_of_2(x: usize) -> usize { - if x == 1 { - return 1; - } - let w = log2_floor(x); - 1 << w -} - -#[cfg(test)] -mod test { - use crate::helper::{floor_to_pow_of_2, log2_floor}; - - #[test] - fn test_log2_floor() { - let t = [ - (2, 1), - (3, 1), - (4, 2), - (8, 3), - (9, 3), - (15, 3), - (16, 4), - (1023, 9), - (1024, 10), - (2000, 10), - (2048, 11), - ]; - for t in t { - assert_eq!(log2_floor(t.0), t.1); - } - } - - #[test] - fn test_floor_to_pow_of_2() { - let t = [ - (1 as usize, 1 as usize), - (2, 2), - (3, 2), - (4, 4), - (5, 4), - (15, 8), - (31, 16), - (33, 32), - (1000, 512), - (1500, 1024), - (2300, 2048), - ]; - for t in t { - assert_eq!(floor_to_pow_of_2(t.0), t.1); - } - } -} |