rqbit/crates/dht/src/main.rs

24 lines
686 B
Rust
Raw Normal View History

use std::{collections::HashSet, str::FromStr};
2021-07-10 23:56:42 +01:00
2021-07-12 19:42:48 +01:00
use anyhow::Context;
use dht::{Dht, Id20};
2021-07-12 19:42:48 +01:00
use tokio_stream::StreamExt;
2021-07-10 23:56:42 +01:00
2021-07-12 11:56:26 +01:00
#[tokio::main]
async fn main() -> anyhow::Result<()> {
2021-07-12 16:24:26 +01:00
pretty_env_logger::init();
2021-07-12 19:42:48 +01:00
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")?;
2021-07-12 11:56:26 +01:00
let mut stream = dht.get_peers(info_hash).await;
2021-07-12 19:42:48 +01:00
let mut seen = HashSet::new();
2021-07-12 11:56:26 +01:00
while let Some(peer) = stream.next().await {
2021-07-12 19:42:48 +01:00
if seen.insert(peer) {
log::info!("peer found: {}", peer)
}
2021-07-10 23:56:42 +01:00
}
2021-07-12 11:56:26 +01:00
Ok(())
2021-07-10 23:56:42 +01:00
}