Skip to content

Commit

Permalink
Merge pull request #190 from xch-dev/fix-peer-discovery
Browse files Browse the repository at this point in the history
Fix peer discovery settings
  • Loading branch information
Rigidity authored Dec 24, 2024
2 parents a0f7d14 + af765d4 commit 01399a9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
5 changes: 4 additions & 1 deletion crates/sage-wallet/src/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ impl SyncManager {
SyncCommand::SetTargetPeers(target_peers) => {
self.options.target_peers = target_peers;
}
SyncCommand::SetDiscoverPeers(discover_peers) => {
self.options.discover_peers = discover_peers;
}
}
}
}
Expand Down Expand Up @@ -311,7 +314,7 @@ impl SyncManager {
async fn update(&mut self) {
let peer_count = self.state.lock().await.peer_count();

if peer_count < self.options.target_peers {
if peer_count < self.options.target_peers && self.options.discover_peers {
if peer_count > 0 {
if !self.peer_discovery().await {
self.dns_discovery().await;
Expand Down
1 change: 1 addition & 0 deletions crates/sage-wallet/src/sync_manager/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Duration;
#[derive(Debug, Clone, Copy)]
pub struct SyncOptions {
pub target_peers: usize,
pub discover_peers: bool,
pub dns_batch_size: usize,
pub connection_batch_size: usize,
pub max_peer_age_seconds: u64,
Expand Down
1 change: 1 addition & 0 deletions crates/sage-wallet/src/sync_manager/sync_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub enum SyncCommand {
},
ConnectionClosed(IpAddr),
SetTargetPeers(usize),
SetDiscoverPeers(bool),
}
1 change: 1 addition & 0 deletions crates/sage-wallet/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl TestWallet {
let (mut sync_manager, sender, events) = SyncManager::new(
SyncOptions {
target_peers: 0,
discover_peers: false,
dns_batch_size: 0,
connection_batch_size: 0,
max_peer_age_seconds: 0,
Expand Down
6 changes: 1 addition & 5 deletions crates/sage/src/endpoints/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ impl Sage {
self.config.network.discover_peers = req.discover_peers;
self.save_config()?;
self.command_sender
.send(SyncCommand::SetTargetPeers(if req.discover_peers {
self.config.network.target_peers as usize
} else {
0
}))
.send(SyncCommand::SetDiscoverPeers(req.discover_peers))
.await?;
}

Expand Down
7 changes: 2 additions & 5 deletions crates/sage/src/sage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,8 @@ impl Sage {

let (sync_manager, command_sender, receiver) = SyncManager::new(
SyncOptions {
target_peers: if self.config.network.discover_peers {
self.config.network.target_peers as usize
} else {
0
},
target_peers: self.config.network.target_peers.try_into()?,
discover_peers: self.config.network.discover_peers,
max_peer_age_seconds: 3600 * 8,
dns_batch_size: 10,
connection_batch_size: 30,
Expand Down

0 comments on commit 01399a9

Please sign in to comment.