-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disable async_dht when not using the default features
see: cargo run --no-default-features --example get_immutable 4238af8aff56cf6e0007d9d2003bf23d33eea7c3
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{str::FromStr, time::Instant}; | ||
|
||
use mainline::{Dht, Id}; | ||
|
||
use clap::Parser; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
/// Immutable data sha1 hash to lookup. | ||
target: String, | ||
} | ||
|
||
async fn async_main() { | ||
let cli = Cli::parse(); | ||
|
||
let target_parse_result: Result<Id, _> = Id::from_str(cli.target.as_str()); | ||
|
||
match target_parse_result { | ||
Ok(infohash) => { | ||
let dht = Dht::default().as_async(); | ||
|
||
let start = Instant::now(); | ||
|
||
println!("\nLooking up immutable data: {} ...\n", cli.target); | ||
|
||
let response = &mut dht.get_immutable(infohash).await; | ||
|
||
if let Some(res) = response.next_async().await { | ||
println!( | ||
"Got result in {:?} seconds\n", | ||
start.elapsed().as_secs_f32() | ||
); | ||
|
||
// No need to stream responses, just print the first result, since | ||
// all immutable data items are guaranteed to be the same. | ||
|
||
match String::from_utf8(res.value.to_vec()) { | ||
Ok(string) => { | ||
println!("Got immutable data: {:?} | from: {:?}", string, res.from); | ||
} | ||
Err(_) => { | ||
println!("Got immutable data: {:?} | from: {:?}", res.value, res.from); | ||
} | ||
}; | ||
} | ||
|
||
println!( | ||
"\nVisited {:?} nodes, found {:?} closest nodes", | ||
response.visited, | ||
&response.closest_nodes.len() | ||
); | ||
|
||
println!( | ||
"\nQuery exhausted in {:?} seconds", | ||
start.elapsed().as_secs_f32(), | ||
); | ||
} | ||
Err(err) => { | ||
println!("Error: {}", err) | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
futures::executor::block_on(async_main()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters