Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/async dht #12

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ serde_bytes = "0.11.5"
thiserror = "1.0.49"
crc = "3.0.1"
sha1_smol = "1.0.0"
flume = { version = "0.11.0", features = ["select", "eventual-fairness"], default-features = false }
flume = { version = "0.11.0", features = [], default-features = false}
ed25519-dalek = "2.1.0"
bytes = "1.5.0"
tracing = "0.1"
Expand Down
2 changes: 0 additions & 2 deletions examples/announce_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fn announce(dht: &Dht, info_hash: Id) {
let start = Instant::now();

dht.announce_peer(info_hash, Some(6991))
.recv()
.unwrap()
.expect("announce_peer failed");

println!(
Expand Down
41 changes: 18 additions & 23 deletions examples/get_immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,24 @@ fn main() {
fn get_immutable(dht: &Dht, info_hash: Id) {
let start = Instant::now();

let receiever = &mut dht.get_immutable(info_hash);

// No need to stream responses, just print the first result, since
// all immutable data items are guaranteed to be the same.
match receiever.recv() {
Ok(value) => {
let string = String::from_utf8(value.to_vec())
.expect("expected immutable data to be valid utf-8 for this demo");

println!(
"Got result in {:?} milliseconds\n",
start.elapsed().as_millis()
);

println!("Got immutable data: {:?}", string);

println!(
"\nQuery exhausted in {:?} milliseconds",
start.elapsed().as_millis(),
);
}
Err(_) => {
println!("\nFailed to find the immutable value for the provided info_hash",);
}
}
let value = dht
.get_immutable(info_hash)
.expect("Failed to find the immutable value for the provided info_hash");

let string = String::from_utf8(value.to_vec())
.expect("expected immutable data to be valid utf-8 for this demo");

println!(
"Got result in {:?} milliseconds\n",
start.elapsed().as_millis()
);

println!("Got immutable data: {:?}", string);

println!(
"\nQuery exhausted in {:?} milliseconds",
start.elapsed().as_millis(),
);
}
4 changes: 1 addition & 3 deletions examples/get_mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ fn lookup(dht: &Dht, public_key: VerifyingKey) {
let mut first = false;
let mut count = 0;

let receiver = dht.get_mutable(public_key.as_bytes(), None);

println!("Streaming mutable items:");
while let Ok(item) = receiver.recv() {
for item in dht.get_mutable(public_key.as_bytes(), None).unwrap() {
count += 1;

if !first {
Expand Down
4 changes: 1 addition & 3 deletions examples/get_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ fn get_peers(dht: &Dht, info_hash: &Id) {

let mut count = 0;

let receiver = dht.get_peers(*info_hash);

while let Ok(peer) = receiver.recv() {
for peer in dht.get_peers(*info_hash).unwrap() {
if !first {
first = true;
println!(
Expand Down
2 changes: 0 additions & 2 deletions examples/put_immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fn put_immutable(dht: &Dht, value: &Bytes) {

let info_hash = dht
.put_immutable(value.to_owned())
.recv()
.unwrap()
.expect("put immutable failed");

println!(
Expand Down
5 changes: 1 addition & 4 deletions examples/put_mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ fn main() {
fn put(dht: &Dht, item: &MutableItem) {
let start = Instant::now();

dht.put_mutable(item.clone())
.recv()
.unwrap()
.expect("Put mutable failed");
dht.put_mutable(item.clone()).expect("Put mutable failed");

println!(
"Stored mutable data as {:?} in {:?} milliseconds",
Expand Down
Loading