Starting to play with alternative DHT implementations
This commit is contained in:
parent
e7c310a1df
commit
7a947ddf79
7 changed files with 232 additions and 8 deletions
|
|
@ -5,3 +5,5 @@ mod serde_bencode_ser;
|
|||
pub use bencode_value::*;
|
||||
pub use serde_bencode_de::*;
|
||||
pub use serde_bencode_ser::*;
|
||||
|
||||
pub use buffers::{ByteBuf, ByteString};
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
serde = {version = "1", features=["derive"]}
|
||||
clone_to_owned = {path="../clone_to_owned"}
|
||||
clone_to_owned = {path="../clone_to_owned"}
|
||||
hex = "0.4"
|
||||
12
crates/dht/Cargo.toml
Normal file
12
crates/dht/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "dht"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
kad = "0.6"
|
||||
tokio = {version = "1", features = ["macros", "rt"]}
|
||||
hex = "0.4"
|
||||
bencode = {path = "../bencode"}
|
||||
10
crates/dht/resources/query.js
Normal file
10
crates/dht/resources/query.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
const DHT = require('bittorrent-dht')
|
||||
|
||||
let dht = new DHT();
|
||||
let infoHash = process.env["INFOHASH"];
|
||||
|
||||
dht.on('peer', function (peer, infoHash, from) {
|
||||
console.log(peer.host + ':' + peer.port)
|
||||
})
|
||||
|
||||
dht.lookup(infoHash)
|
||||
11
crates/dht/src/lib.rs
Normal file
11
crates/dht/src/lib.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bencode::ByteBuf;
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_works() {
|
||||
let data = b"64313a6164323a696432303abd7b477cfbcd10f30b705da20201e7101d8df155363a74617267657432303abd7b477cfbcd10f30b705da20201e7101d8df15565313a71393a66696e645f6e6f6465313a74323a0005313a79313a7165";
|
||||
let data = hex::decode(data).unwrap();
|
||||
dbg!(bencode::dyn_from_bytes::<ByteBuf>(data.as_slice()).unwrap());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue