This commit is contained in:
Daniel Karzel 2021-06-11 16:00:17 +10:00 committed by Thomas Eizinger
parent 10a5bf05ca
commit dede7b38f9
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
3 changed files with 17 additions and 6 deletions

View file

@ -1,10 +1,11 @@
use libp2p::core::muxing::StreamMuxerBox;
use libp2p::core::upgrade::Version;
use libp2p::core::upgrade::{Version, SelectUpgrade};
use libp2p::ping::{Ping, PingEvent, PingSuccess};
use libp2p::swarm::{SwarmBuilder, SwarmEvent};
use libp2p::{identity, noise, yamux, Multiaddr, Swarm, Transport};
use libp2p_tor::dial_only;
use std::time::Duration;
use libp2p::mplex::MplexConfig;
#[tokio::main]
async fn main() {
@ -55,6 +56,9 @@ async fn main() {
/// Builds a new swarm that is capable of dialling onion address.
fn new_swarm() -> Swarm<Ping> {
let identity = identity::Keypair::generate_ed25519();
let peer_id = identity.public().into_peer_id();
println!("peer id upon swarm setup: {}", peer_id);
SwarmBuilder::new(
dial_only::TorConfig::new(9050)
@ -67,12 +71,15 @@ fn new_swarm() -> Swarm<Ping> {
)
.into_authenticated(),
)
.multiplex(yamux::YamuxConfig::default())
.multiplex(SelectUpgrade::new(
yamux::YamuxConfig::default(),
MplexConfig::new(),
))
.timeout(Duration::from_secs(20))
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
.boxed(),
Ping::default(),
identity.public().into_peer_id(),
peer_id,
)
.executor(Box::new(|f| {
tokio::spawn(f);