A small refactor
This commit is contained in:
parent
2eabebb5c3
commit
6eef3b9b66
25 changed files with 111 additions and 189 deletions
|
|
@ -8,6 +8,7 @@ use crate::{
|
|||
self, CompactNodeInfo, FindNodeRequest, GetPeersRequest, Message, MessageKind, Node,
|
||||
},
|
||||
routing_table::{InsertResult, RoutingTable},
|
||||
DHT_BOOTSTRAP,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use bencode::ByteString;
|
||||
|
|
@ -495,12 +496,15 @@ impl DhtWorker {
|
|||
}
|
||||
|
||||
impl Dht {
|
||||
pub async fn new(bootstrap_addrs: &[&str]) -> anyhow::Result<Self> {
|
||||
pub async fn new() -> anyhow::Result<Self> {
|
||||
Self::with_bootstrap_addrs(DHT_BOOTSTRAP).await
|
||||
}
|
||||
pub async fn with_bootstrap_addrs(bootstrap_addrs: &[&str]) -> anyhow::Result<Self> {
|
||||
let (request_tx, request_rx) = channel(1);
|
||||
let socket = UdpSocket::bind("0.0.0.0:0")
|
||||
.await
|
||||
.context("error binding socket")?;
|
||||
let peer_id = Id20(generate_peer_id());
|
||||
let peer_id = generate_peer_id();
|
||||
info!("starting up DHT with peer id {:?}", peer_id);
|
||||
let bootstrap_addrs = bootstrap_addrs
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -4,3 +4,5 @@ mod routing_table;
|
|||
|
||||
pub use dht::Dht;
|
||||
pub use librqbit_core::id20::Id20;
|
||||
|
||||
pub static DHT_BOOTSTRAP: &[&str] = &["dht.transmissionbt.com:6881", "dht.libtorrent.org:25401"];
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
pretty_env_logger::init();
|
||||
|
||||
let info_hash = Id20::from_str("64a980abe6e448226bb930ba061592e44c3781a1").unwrap();
|
||||
let dht = Dht::new(&["dht.transmissionbt.com:6881", "dht.libtorrent.org:25401"])
|
||||
.await
|
||||
.context("error initializing dht")?;
|
||||
let dht = Dht::new().await.context("error initializing DHT")?;
|
||||
let mut stream = dht.get_peers(info_hash).await;
|
||||
let mut seen = HashSet::new();
|
||||
while let Some(peer) = stream.next().await {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue