Skip to content

Commit

Permalink
fix: stop generate_random_remote_enr from generating multicast ip's (
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML authored Feb 1, 2025
1 parent ea7af45 commit ca15f46
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/ethportal-api/src/types/enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ impl ssz::Encode for SszEnr {

pub fn generate_random_remote_enr() -> (CombinedKey, Enr) {
let key = CombinedKey::generate_secp256k1();

let mut rng = rand::thread_rng();
let ip = Ipv4Addr::from(rng.gen::<u32>());

// Generate an IP between 1.0.0.0 and 223.255.255.255
// We don't want to generate a multicast address (224.0.0.0 - 239.255.255.255)
let ip = Ipv4Addr::from(rng.gen_range(0x1000000..=0xDFFFFFFF)); // 0xDFFFFFFF == 223.255.255.255

let enr = Discv5Enr::builder()
.ip(ip.into())
Expand Down

0 comments on commit ca15f46

Please sign in to comment.