|
|
|
@ -6,17 +6,26 @@ use libp2p::{identity, noise, yamux, Swarm, Transport, Multiaddr};
|
|
|
|
|
use libp2p_tor::duplex;
|
|
|
|
|
use libp2p_tor::torut_ext::AuthenticatedConnectionExt;
|
|
|
|
|
use noise::NoiseConfig;
|
|
|
|
|
use rand::Rng;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
use torut::control::AuthenticatedConn;
|
|
|
|
|
use torut::onion::TorSecretKeyV3;
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
use libp2p::mplex::MplexConfig;
|
|
|
|
|
use libp2p::identity::Keypair;
|
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
|
|
|
|
|
let key = random_onion_identity();
|
|
|
|
|
let _guard = tracing_subscriber::fmt()
|
|
|
|
|
.with_env_filter("debug,libp2p_tor=debug") // add `reqwest::connect::verbose=trace` if you want to logs of the RPC clients
|
|
|
|
|
.with_test_writer()
|
|
|
|
|
.set_default();
|
|
|
|
|
|
|
|
|
|
tracing::debug!("test");
|
|
|
|
|
|
|
|
|
|
let key = fixed_onion_identity();
|
|
|
|
|
|
|
|
|
|
let onion_address = key.public().get_onion_address().get_address_without_dot_onion();
|
|
|
|
|
let onion_port = 7654;
|
|
|
|
|
|
|
|
|
@ -66,7 +75,7 @@ async fn main() {
|
|
|
|
|
/// In particular, this swarm can create ephemeral hidden services on the
|
|
|
|
|
/// configured Tor node.
|
|
|
|
|
async fn new_swarm(key: TorSecretKeyV3) -> Swarm<Ping> {
|
|
|
|
|
let identity = identity::Keypair::generate_ed25519();
|
|
|
|
|
let identity = fixed_libp2p_identity();
|
|
|
|
|
|
|
|
|
|
SwarmBuilder::new(
|
|
|
|
|
duplex::TorConfig::new(
|
|
|
|
@ -100,9 +109,16 @@ async fn new_swarm(key: TorSecretKeyV3) -> Swarm<Ping> {
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn random_onion_identity() -> TorSecretKeyV3 {
|
|
|
|
|
let mut onion_key_bytes = [0u8; 64];
|
|
|
|
|
rand::thread_rng().fill(&mut onion_key_bytes);
|
|
|
|
|
fn fixed_onion_identity() -> TorSecretKeyV3 {
|
|
|
|
|
// randomly generated bytes, corresponding onion address: jpclybnowuibjexya3qggzvzkoeruuav4nyjlxpnkrosldsvykfbn6qd
|
|
|
|
|
let fixed_onion_bytes = [7, 164, 217, 80, 139, 239, 11, 110, 37, 77, 191, 158, 206, 252, 178, 188, 147, 98, 54, 13, 35, 183, 114, 231, 202, 38, 30, 29, 245, 8, 118, 153, 55, 141, 228, 109, 78, 189, 120, 28, 172, 131, 198, 55, 113, 47, 131, 135, 139, 117, 182, 195, 46, 34, 234, 169, 85, 96, 203, 215, 7, 155, 209, 211];
|
|
|
|
|
fixed_onion_bytes.into()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn fixed_libp2p_identity() -> Keypair {
|
|
|
|
|
// randomly venerated bytes, corresponding peer-id: 12D3KooWHKqGyK4hVtf5BQY8GpbY6fSGKDZ8eBXMQ3H2RsdnKVzC
|
|
|
|
|
let fixed_identity = [75,146,26,107,50,252,71,2,238,224,92,112,216,238,131,57,84,9,218,120,195,9,129,102,42,206,165,102,32,238,158,248];
|
|
|
|
|
|
|
|
|
|
onion_key_bytes.into()
|
|
|
|
|
let key = identity::ed25519::SecretKey::from_bytes(fixed_identity).expect("we always pass 32 bytes");
|
|
|
|
|
identity::Keypair::Ed25519(key.into())
|
|
|
|
|
}
|
|
|
|
|