Skip to content

Commit

Permalink
the great peer connection rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
denisu committed Nov 5, 2024
1 parent e374068 commit fabd25a
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 116 deletions.
80 changes: 78 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ edition = "2021"

[dependencies]
anyhow = "1.0.92"
async-channel = "2.3.1"
async-trait = "0.1.83"
chia = "0.15.0"
chia-wallet-sdk = { version = "0.17.0", features = ["rustls"] }
clap = { version = "4.5.20", features = ["derive"] }
dashmap = "6.1.0"
futures = "0.3.31"
futures-util = "0.3.31"
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

pub const PEER_TIMEOUT: u64 = 5;
pub const PEER_TIMEOUT: u64 = 7;
pub const DNS_RECORD_TTL: u32 = 300;
pub const MAX_CONCURRENT_TASKS: usize = 100;
pub const MAX_RECORDS_TO_RETURN: usize = 32;
Expand Down
8 changes: 7 additions & 1 deletion src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ impl RandomizedAuthority {
}
}

pub async fn known_peer(&self, addr: &SocketAddr) -> bool {
self.peers.read().await.contains(addr)
}

pub async fn get_peers(&self) -> Vec<SocketAddr> {
let peers = self.peers.read().await;
peers.iter().cloned().collect()
}

pub fn block_peer(&self, addr: SocketAddr, duration: Duration) {
pub async fn block_peer(&self, addr: SocketAddr, duration: Duration) {
self.remove_peer(addr).await;

let mut blocked = self.blocked_peers.lock().unwrap();
blocked.retain(|peer| peer.addr != addr);
blocked.push(BlockedPeer {
Expand Down
Loading

0 comments on commit fabd25a

Please sign in to comment.