mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21: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
|
# 15 = Bit flags for FULL_NODE
|
||||||
#This structure needs to be changed internally, to make it more configurable
|
#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(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -83,9 +83,26 @@ impl Peers {
|
||||||
// Update the dandelion relay
|
// Update the dandelion relay
|
||||||
pub fn update_dandelion_relay(&self) {
|
pub fn update_dandelion_relay(&self) {
|
||||||
let peers = self.outgoing_connected_peers();
|
let peers = self.outgoing_connected_peers();
|
||||||
|
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) {
|
match thread_rng().choose(&peers) {
|
||||||
Some(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
|
// Clear the map and add new relay
|
||||||
let dandelion_relay = &self.dandelion_relay;
|
let dandelion_relay = &self.dandelion_relay;
|
||||||
dandelion_relay.write().clear();
|
dandelion_relay.write().clear();
|
||||||
|
@ -97,9 +114,6 @@ impl Peers {
|
||||||
peer.info.addr
|
peer.info.addr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
None => debug!("Could not update dandelion relay"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the dandelion relay
|
// Get the dandelion relay
|
||||||
pub fn get_dandelion_relay(&self) -> HashMap<i64, Arc<Peer>> {
|
pub fn get_dandelion_relay(&self) -> HashMap<i64, Arc<Peer>> {
|
||||||
|
|
|
@ -124,6 +124,8 @@ pub struct P2PConfig {
|
||||||
pub peer_max_count: Option<u32>,
|
pub peer_max_count: Option<u32>,
|
||||||
|
|
||||||
pub peer_min_preferred_count: Option<u32>,
|
pub peer_min_preferred_count: Option<u32>,
|
||||||
|
|
||||||
|
pub dandelion_peer: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default address for peer-to-peer connections.
|
/// Default address for peer-to-peer connections.
|
||||||
|
@ -142,6 +144,7 @@ impl Default for P2PConfig {
|
||||||
ban_window: None,
|
ban_window: None,
|
||||||
peer_max_count: None,
|
peer_max_count: None,
|
||||||
peer_min_preferred_count: None,
|
peer_min_preferred_count: None,
|
||||||
|
dandelion_peer: None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue