Skip to content

Commit

Permalink
Update rendezvous examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Aug 13, 2023
1 parent 7a7e3c4 commit f4a4ca3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 71 deletions.
30 changes: 12 additions & 18 deletions examples/rendezvous/src/bin/rzv-discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

use futures::StreamExt;
use libp2p::{
core::transport::upgrade::Version,
identity,
multiaddr::Protocol,
noise, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
tcp, yamux, Multiaddr, PeerId, Transport,
ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
Multiaddr,
};
use std::time::Duration;

Expand All @@ -35,26 +33,22 @@ const NAMESPACE: &str = "rendezvous";
async fn main() {
env_logger::init();

let key_pair = identity::Keypair::generate_ed25519();
let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::<Multiaddr>().unwrap();
let rendezvous_point = "12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN"
.parse()
.unwrap();

let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::Config::default())
.boxed(),
MyBehaviour {
rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()),
let mut swarm = libp2p::builder::SwarmBuilder::new()
.with_new_identity()
.with_tokio()
.with_tcp()
.with_noise()
.with_behaviour(|key| MyBehaviour {
rendezvous: rendezvous::client::Behaviour::new(key.clone()),
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
keep_alive: keep_alive::Behaviour,
},
PeerId::from(key_pair.public()),
)
.build();
})
.build();

log::info!("Local peer id: {}", swarm.local_peer_id());

Expand Down
31 changes: 13 additions & 18 deletions examples/rendezvous/src/bin/rzv-identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,36 @@

use futures::StreamExt;
use libp2p::{
core::transport::upgrade::Version,
identify, identity, noise, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
tcp, yamux, Multiaddr, PeerId, Transport,
identify, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
Multiaddr,
};
use std::time::Duration;

#[tokio::main]
async fn main() {
env_logger::init();

let key_pair = identity::Keypair::generate_ed25519();
let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::<Multiaddr>().unwrap();
let rendezvous_point = "12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN"
.parse()
.unwrap();

let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::Config::default())
.boxed(),
MyBehaviour {
let mut swarm = libp2p::builder::SwarmBuilder::new()
.with_new_identity()
.with_tokio()
.with_tcp()
.with_noise()
.with_behaviour(|key| MyBehaviour {
identify: identify::Behaviour::new(identify::Config::new(
"rendezvous-example/1.0.0".to_string(),
key_pair.public(),
key.public(),
)),
rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()),
rendezvous: rendezvous::client::Behaviour::new(key.clone()),
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
keep_alive: keep_alive::Behaviour,
},
PeerId::from(key_pair.public()),
)
.build();
})
.build();

log::info!("Local peer id: {}", swarm.local_peer_id());

Expand Down
29 changes: 12 additions & 17 deletions examples/rendezvous/src/bin/rzv-register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,32 @@

use futures::StreamExt;
use libp2p::{
core::transport::upgrade::Version,
identity, noise, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
tcp, yamux, Multiaddr, PeerId, Transport,
ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
Multiaddr,
};
use std::time::Duration;

#[tokio::main]
async fn main() {
env_logger::init();

let key_pair = identity::Keypair::generate_ed25519();
let rendezvous_point_address = "/ip4/127.0.0.1/tcp/62649".parse::<Multiaddr>().unwrap();
let rendezvous_point = "12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN"
.parse()
.unwrap();

let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::Config::default())
.boxed(),
MyBehaviour {
rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()),
let mut swarm = libp2p::builder::SwarmBuilder::new()
.with_new_identity()
.with_tokio()
.with_tcp()
.with_noise()
.with_behaviour(|key| MyBehaviour {
rendezvous: rendezvous::client::Behaviour::new(key.clone()),
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
keep_alive: keep_alive::Behaviour,
},
PeerId::from(key_pair.public()),
)
.build();
})
.build();

// In production the external address should be the publicly facing IP address of the rendezvous point.
// This address is recorded in the registration entry by the rendezvous point.
Expand Down
29 changes: 11 additions & 18 deletions examples/rendezvous/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,30 @@

use futures::StreamExt;
use libp2p::{
core::transport::upgrade::Version,
identify, identity, noise, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
tcp, yamux, PeerId, Transport,
identify, ping, rendezvous,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
};
use std::time::Duration;

#[tokio::main]
async fn main() {
env_logger::init();

let key_pair = identity::Keypair::generate_ed25519();

let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::Config::default())
.boxed(),
MyBehaviour {
let mut swarm = libp2p::builder::SwarmBuilder::new()
.with_new_identity()
.with_tokio()
.with_tcp()
.with_noise()
.with_behaviour(|key| MyBehaviour {
identify: identify::Behaviour::new(identify::Config::new(
"rendezvous-example/1.0.0".to_string(),
key_pair.public(),
key.public(),
)),
rendezvous: rendezvous::server::Behaviour::new(rendezvous::server::Config::default()),
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
keep_alive: keep_alive::Behaviour,
},
PeerId::from(key_pair.public()),
)
.build();
})
.build();

log::info!("Local peer id: {}", swarm.local_peer_id());

Expand Down

0 comments on commit f4a4ca3

Please sign in to comment.