feature: Enable setting a node address for a dandelion peer (#2263)
* Configuration to set a fixed dandelion peer * typo + styling * more idiomatic way of picking the peer
This commit is contained in:
@@ -230,6 +230,10 @@ fn comments() -> HashMap<String, String> {
|
||||
|
||||
# 15 = Bit flags for FULL_NODE
|
||||
#This structure needs to be changed internally, to make it more configurable
|
||||
|
||||
# A preferred dandelion_peer, mainly used for testing dandelion
|
||||
# dandelion_peer = \"10.0.0.1:13144\"
|
||||
|
||||
"
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
+22
-14
@@ -84,21 +84,29 @@ impl Peers {
|
||||
pub fn update_dandelion_relay(&self) {
|
||||
let peers = self.outgoing_connected_peers();
|
||||
|
||||
match thread_rng().choose(&peers) {
|
||||
Some(peer) => {
|
||||
// Clear the map and add new relay
|
||||
let dandelion_relay = &self.dandelion_relay;
|
||||
dandelion_relay.write().clear();
|
||||
dandelion_relay
|
||||
.write()
|
||||
.insert(Utc::now().timestamp(), peer.clone());
|
||||
debug!(
|
||||
"Successfully updated Dandelion relay to: {}",
|
||||
peer.info.addr
|
||||
);
|
||||
}
|
||||
let peer = &self
|
||||
.config
|
||||
.dandelion_peer
|
||||
.and_then(|ip| peers.iter().find(|x| x.info.addr == ip))
|
||||
.or(thread_rng().choose(&peers));
|
||||
|
||||
match peer {
|
||||
Some(peer) => self.set_dandelion_relay(peer),
|
||||
None => debug!("Could not update dandelion relay"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn set_dandelion_relay(&self, peer: &Arc<Peer>) {
|
||||
// Clear the map and add new relay
|
||||
let dandelion_relay = &self.dandelion_relay;
|
||||
dandelion_relay.write().clear();
|
||||
dandelion_relay
|
||||
.write()
|
||||
.insert(Utc::now().timestamp(), peer.clone());
|
||||
debug!(
|
||||
"Successfully updated Dandelion relay to: {}",
|
||||
peer.info.addr
|
||||
);
|
||||
}
|
||||
|
||||
// Get the dandelion relay
|
||||
|
||||
@@ -124,6 +124,8 @@ pub struct P2PConfig {
|
||||
pub peer_max_count: Option<u32>,
|
||||
|
||||
pub peer_min_preferred_count: Option<u32>,
|
||||
|
||||
pub dandelion_peer: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
/// Default address for peer-to-peer connections.
|
||||
@@ -142,6 +144,7 @@ impl Default for P2PConfig {
|
||||
ban_window: None,
|
||||
peer_max_count: None,
|
||||
peer_min_preferred_count: None,
|
||||
dandelion_peer: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user