Skip to content

Commit

Permalink
use seahash instead of manually modulo-ing to figure out endpoint index
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn committed Oct 18, 2023
1 parent 35d0e19 commit 3abf6fc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/corro-agent/src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::HashMap,
hash::{Hash, Hasher},
net::SocketAddr,
sync::Arc,
time::{Duration, Instant},
Expand Down Expand Up @@ -154,10 +155,9 @@ impl Transport {
) -> Result<Connection, TransportError> {
let start = Instant::now();

let endpoint_idx = match addr {
SocketAddr::V4(v4) => (u32::from(*v4.ip()) % self.0.endpoints.len() as u32) as usize,
SocketAddr::V6(v6) => (u128::from(*v6.ip()) % self.0.endpoints.len() as u128) as usize,
};
let mut hasher = seahash::SeaHasher::new();
addr.hash(&mut hasher);
let endpoint_idx = (hasher.finish() % self.0.endpoints.len() as u64) as usize;

async {
match tokio::time::timeout(Duration::from_secs(5), self
Expand Down

0 comments on commit 3abf6fc

Please sign in to comment.