Skip to content

Commit

Permalink
Set features in ENR
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Sep 9, 2022
1 parent b699290 commit 86b7491
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 8 additions & 12 deletions src/discv5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct Discv5 {

impl Discv5 {
pub fn new(
local_enr: Enr,
mut local_enr: Enr,
enr_key: CombinedKey,
mut config: Discv5Config,
) -> Result<Self, &'static str> {
Expand All @@ -145,6 +145,12 @@ impl Discv5 {
(None, None)
};

// This node supports topic requests REGTOPIC and TOPICQUERY, and their responses.
if let Err(e) = local_enr.insert(ENR_KEY_FEATURES, &[Features::Topics as u8], &enr_key) {
error!("Failed writing to enr. Error {:?}", e);
return Err("Failed to insert field 'features' into local enr");
}

let local_enr = Arc::new(RwLock::new(local_enr));
let enr_key = Arc::new(RwLock::new(enr_key));
let kbuckets = Arc::new(RwLock::new(KBucketsTable::new(
Expand All @@ -155,16 +161,6 @@ impl Discv5 {
bucket_filter,
)));

// This node supports topic requests REGTOPIC and TOPICQUERY, and their responses.
if let Err(e) = local_enr.write().insert(
ENR_KEY_FEATURES,
&[Features::Topics as u8],
&enr_key.write(),
) {
error!("Failed writing to enr. Error {:?}", e);
return Err("Failed to insert field 'version' into local enr");
}

println!("{:?}", local_enr.read().get(ENR_KEY_FEATURES).unwrap());

// Update the PermitBan list based on initial configuration
Expand Down Expand Up @@ -879,7 +875,7 @@ pub fn supports_feature(peer: &Enr, feature: Features) -> bool {
}
} else {
warn!(
"Enr of peer {} doesn't contain field 'version'",
"Enr of peer {} doesn't contain field 'features'",
peer.node_id()
);
false
Expand Down
8 changes: 6 additions & 2 deletions src/discv5/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ async fn test_bucket_limits() {
}

#[test]
fn test_version_check() {
fn test_features_check() {
// Create the test values needed
let port = 6666;
let ip: std::net::IpAddr = "127.0.0.1".parse().unwrap();
Expand All @@ -639,9 +639,13 @@ fn test_version_check() {
.udp4(port)
.build(&key)
.unwrap();
let supported_versions = Features::Topics as u8 | 2;

let supported_versions = Features::Topics as u8;

enr.insert(ENR_KEY_FEATURES, &[supported_versions], &key)
.unwrap();

assert!(supports_feature(&enr, Features::Topics));
}


0 comments on commit 86b7491

Please sign in to comment.