From a5c3d4f77b79673b67f598cb5231815b1531d76f Mon Sep 17 00:00:00 2001 From: onyinyang Date: Tue, 4 Apr 2023 18:39:28 -0400 Subject: [PATCH] Update fingerprint to match UID from rdsys --- crates/lox-library/src/bridge_table.rs | 24 ++++++++++-------------- crates/lox-library/src/lib.rs | 6 +++++- crates/lox-library/src/tests.rs | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/lox-library/src/bridge_table.rs b/crates/lox-library/src/bridge_table.rs index f291973..a9070a4 100644 --- a/crates/lox-library/src/bridge_table.rs +++ b/crates/lox-library/src/bridge_table.rs @@ -45,12 +45,11 @@ pub struct BridgeLine { /// port pub port: u16, /// fingerprint - #[serde_as(as = "[_; 40]")] - pub fingerprint: [u8; 40], + pub uid_fingerprint: u64, /// other protocol information, including pluggable transport, /// public key, etc. - #[serde_as(as = "[_; BRIDGE_BYTES - 58]")] - pub info: [u8; BRIDGE_BYTES - 58], + #[serde_as(as = "[_; BRIDGE_BYTES - 26]")] + pub info: [u8; BRIDGE_BYTES - 26], } /// A bucket contains MAX_BRIDGES_PER_BUCKET bridges plus the @@ -73,8 +72,8 @@ impl Default for BridgeLine { Self { addr: [0; 16], port: 0, - fingerprint: [0; 40], - info: [0; BRIDGE_BYTES - 58], + uid_fingerprint: 0, + info: [0; BRIDGE_BYTES - 26], } } } @@ -85,8 +84,8 @@ impl BridgeLine { let mut res: [u8; BRIDGE_BYTES] = [0; BRIDGE_BYTES]; res[0..16].copy_from_slice(&self.addr); res[16..18].copy_from_slice(&self.port.to_be_bytes()); - res[18..58].copy_from_slice(&self.fingerprint); - res[58..].copy_from_slice(&self.info); + res[18..26].copy_from_slice(&self.uid_fingerprint.to_be_bytes()); + res[26..].copy_from_slice(&self.info); res } /// Decode a BridgeLine from a byte array @@ -94,8 +93,8 @@ impl BridgeLine { let mut res: Self = Default::default(); res.addr.copy_from_slice(&data[0..16]); res.port = u16::from_be_bytes(data[16..18].try_into().unwrap()); - res.fingerprint.copy_from_slice(&data[18..58]); - res.info.copy_from_slice(&data[58..]); + res.uid_fingerprint = u64::from_be_bytes(data[18..26].try_into().unwrap()); + res.info.copy_from_slice(&data[26..]); res } /// Encode a bucket to a byte array, including a Bucket Reachability @@ -194,11 +193,8 @@ impl BridgeLine { let ports: [u16; 4] = [443, 4433, 8080, 43079]; let portidx = (rng.next_u32() % 4) as usize; res.port = ports[portidx]; - let mut fingerprint: [u8; 40] = [0; 40]; - rng.fill_bytes(&mut fingerprint); + res.uid_fingerprint = rng.next_u64(); let mut cert: [u8; 52] = [0; 52]; - rng.fill_bytes(&mut fingerprint); - res.fingerprint[0..40].copy_from_slice(&fingerprint); rng.fill_bytes(&mut cert); let infostr: String = format!( "obfs4 cert={}, iat-mode=0", diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 5c78e30..f609d59 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -331,7 +331,7 @@ impl BridgeAuth { let reachable_bridges = self.bridge_table.reachable.clone(); for reachable_bridge in reachable_bridges { - if reachable_bridge.0.fingerprint == bridge.fingerprint { + if reachable_bridge.0.uid_fingerprint == bridge.uid_fingerprint { println!( "Bridge from table: {:?} has same IP and Port as bridge {:?}!", reachable_bridge.0, bridge @@ -366,6 +366,10 @@ impl BridgeAuth { return res; } } + if !res { + // Assume the bridge is new and should be added to unallocated bridges or else a new bucket + + } res } diff --git a/crates/lox-library/src/tests.rs b/crates/lox-library/src/tests.rs index 5ca62d9..885980c 100644 --- a/crates/lox-library/src/tests.rs +++ b/crates/lox-library/src/tests.rs @@ -621,22 +621,22 @@ fn test_update_bridge() { "obfs2".to_string(), "moat".to_string(), ); - let mut updated_info_bytes: [u8; BRIDGE_BYTES - 58] = [0; BRIDGE_BYTES - 58]; + let mut updated_info_bytes: [u8; BRIDGE_BYTES - 26] = [0; BRIDGE_BYTES - 26]; updated_info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes()); let updated_bridgeline = BridgeLine { addr: bridgeline_to_update.addr, port: bridgeline_to_update.port, - fingerprint: bridgeline_to_update.fingerprint, + uid_fingerprint: bridgeline_to_update.uid_fingerprint, info: updated_info_bytes, }; assert!( - updated_bridgeline.fingerprint == bridgeline_to_update.fingerprint, + updated_bridgeline.uid_fingerprint == bridgeline_to_update.uid_fingerprint, "Bridge entering the bridgepool {:?} did not have the same fingerprint as the updating bridge {:?}", bridgeline_to_update, - updated_bridgeline.fingerprint + updated_bridgeline.uid_fingerprint ); assert!(updated_bridgeline.info != bridgeline_to_update.info); println!(