This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial shred deserialize cleanup and shred type differentiation (#14094
) (#14138) * Partial shred deserialize cleanup and shred type differentiation in retransmit * consolidate packet hashing logic (cherry picked from commit d4a174f) Co-authored-by: sakridge <sakridge@gmail.com>
- Loading branch information
1 parent
fdb1c5a
commit 599b22b
Showing
5 changed files
with
312 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Get a unique hash value for a packet | ||
// Used in retransmit and shred fetch to prevent dos with same packet data. | ||
|
||
use ahash::AHasher; | ||
use rand::{thread_rng, Rng}; | ||
use solana_perf::packet::Packet; | ||
use std::hash::Hasher; | ||
|
||
#[derive(Clone)] | ||
pub struct PacketHasher { | ||
seed1: u128, | ||
seed2: u128, | ||
} | ||
|
||
impl Default for PacketHasher { | ||
fn default() -> Self { | ||
Self { | ||
seed1: thread_rng().gen::<u128>(), | ||
seed2: thread_rng().gen::<u128>(), | ||
} | ||
} | ||
} | ||
|
||
impl PacketHasher { | ||
pub fn hash_packet(&self, packet: &Packet) -> u64 { | ||
let mut hasher = AHasher::new_with_keys(self.seed1, self.seed2); | ||
hasher.write(&packet.data[0..packet.meta.size]); | ||
hasher.finish() | ||
} | ||
|
||
pub fn reset(&mut self) { | ||
*self = Self::default(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.