Skip to content

Commit

Permalink
Merge pull request #13 from Nuhvi/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
Nuhvi authored Apr 29, 2024
2 parents 8ea3b8e + 1be2212 commit 732b931
Show file tree
Hide file tree
Showing 35 changed files with 2,504 additions and 2,561 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ jobs:
run: cargo fmt -- --check

- name: Lint with Clippy
run: cargo clippy -- -D warnings
run: cargo clippy --workspace --all-features --bins --tests

- name: Build
run: cargo build --verbose
run: cargo build --release --workspace --all-features --verbose


- name: Run tests
run: cargo test --verbose
run: cargo test --all-features --workspace --verbose

- name: Run docs
run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose
17 changes: 5 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mainline"
version = "1.5.0"
version = "2.0.0-rc1"
authors = ["nuh.dev"]
edition = "2018"
description = "Simple, robust, BitTorrent's Mainline DHT implementation"
Expand All @@ -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 All @@ -31,14 +31,7 @@ tracing-subscriber = "0.3"

[features]
async = ["flume/async"]
default = ["async"]
default = []

[[example]]
name = "async_put_mutable"
path = "examples/async/put_mutable.rs"
required-features = ["async"]

[[example]]
name = "async_get_immutable"
path = "examples/async/get_immutable.rs"
required-features = ["async"]
[package.metadata.docs.rs]
all-features = true
13 changes: 0 additions & 13 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,3 @@ cargo run --example put_mutable <64 bytes hex secret_key> <string>

```sh
cargo run --example get_mutable <40 bytes hex target from put_mutable>
````

## Async Put Mutable

```sh
cargo run --example async_put_mutable <64 bytes hex secret_key> <string>
```

## Async Get Mutable

```sh
cargo run --example async_get_mutable <40 bytes hex target from put_mutable>
`````
70 changes: 19 additions & 51 deletions examples/announce_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,31 @@ struct Cli {
}

fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
tracing_subscriber::fmt().with_max_level(Level::INFO).init();

let cli = Cli::parse();

match Id::from_str(cli.infohash.as_str()) {
Ok(infohash) => {
let dht = Dht::default();
let info_hash = Id::from_str(cli.infohash.as_str()).expect("invalid infohash");

let start = Instant::now();
let dht = Dht::client().unwrap();

println!("\nAnnouncing peer on an infohash: {} ...\n", cli.infohash);
println!("\nAnnouncing peer on an infohash: {} ...\n", cli.infohash);

let metadata = dht
.announce_peer(infohash, Some(6991))
.expect("announce_peer fialed");
println!(
"Announced peer in {:?} seconds",
start.elapsed().as_secs_f32()
);
let stored_at = metadata.stored_at();
println!("Stored at: {:?} nodes", stored_at.len());
for node in stored_at {
println!(" {:?}", node);
}
println!("\n=== COLD QUERY ===");
announce(&dht, info_hash);

// You can now reannounce to the same closest nodes
// skipping the the lookup step.
//
// This time we choose to not sepcify the port, effectively
// making the port implicit to be detected by the storing node
// from the source address of the announce_peer request
//
// Uncomment the following lines to try it out:
println!("\n=== SUBSEQUENT QUERY ===");
announce(&dht, info_hash);
}

fn announce(dht: &Dht, info_hash: Id) {
let start = Instant::now();

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

// println!(
// "Announcing again to {:?} closest_nodes ...",
// metadata.closest_nodes().len()
// );
//
// let again = Instant::now();
// match dht.announce_peer_to(infohash, metadata.closest_nodes(), None) {
// Ok(metadata) => {
// println!(
// "Announced again to {:?} nodes in {:?} seconds",
// metadata.stored_at().len(),
// again.elapsed().as_secs()
// );
// }
// Err(err) => {
// println!("Error: {:?}", err);
// }
// }
}
Err(err) => {
println!("Error: {:?}", err)
}
};
println!(
"Announced peer in {:?} seconds",
start.elapsed().as_secs_f32()
);
}
74 changes: 0 additions & 74 deletions examples/async/get_immutable.rs

This file was deleted.

116 changes: 0 additions & 116 deletions examples/async/put_mutable.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
.with_max_level(Level::DEBUG)
.init();

Dht::default();
Dht::client().unwrap();

thread::sleep(Duration::from_secs(5));
}
Loading

0 comments on commit 732b931

Please sign in to comment.