mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Enable setting a fixed dandelion peer
This commit is contained in:
parent
738d49d560
commit
b2cc5ba7e1
3 changed files with 34 additions and 13 deletions
|
@ -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 prefered dandelion_peer, mainly used for testing dandelion
|
||||
# dandelion_peer = \"10.0.0.1:13144\"
|
||||
|
||||
"
|
||||
.to_string(),
|
||||
);
|
||||
|
|
|
@ -83,24 +83,38 @@ impl Peers {
|
|||
// Update the dandelion relay
|
||||
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
|
||||
);
|
||||
match &self.config.dandelion_peer {
|
||||
Some(ip) => {
|
||||
for peer in &peers {
|
||||
if peer.info.addr == *ip {
|
||||
debug!("Found predefined dandelion peer, setting as relay");
|
||||
self.set_dandelion_relay(peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
debug!("Could not find predefined dandelion peer among connected peers, choosing random")
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
match thread_rng().choose(&peers) {
|
||||
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
|
||||
pub fn get_dandelion_relay(&self) -> HashMap<i64, Arc<Peer>> {
|
||||
self.dandelion_relay.read().clone()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue