mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
feat(swarm): log local peer id on swarm creation
Closes https://github.com/libp2p/rust-libp2p/issues/4394. Pull-Request: #4439.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1968,6 +1968,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-trait",
|
||||
"env_logger 0.10.0",
|
||||
"futures",
|
||||
"libp2p",
|
||||
]
|
||||
@ -3834,6 +3835,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-trait",
|
||||
"env_logger 0.10.0",
|
||||
"futures",
|
||||
"libp2p",
|
||||
]
|
||||
|
@ -51,7 +51,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
println!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
|
@ -43,7 +43,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
println!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
|
@ -44,9 +44,9 @@ struct MyBehaviour {
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Create a random PeerId
|
||||
env_logger::init();
|
||||
let id_keys = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(id_keys.public());
|
||||
println!("Local peer id: {local_peer_id}");
|
||||
|
||||
// Set up an encrypted DNS-enabled TCP Transport over the yamux protocol.
|
||||
let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
|
||||
|
@ -87,7 +87,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let local_key = generate_ed25519(opts.secret_key_seed);
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
info!("Local peer id: {:?}", local_peer_id);
|
||||
|
||||
let (relay_transport, client) = relay::client::new(local_peer_id);
|
||||
|
||||
|
@ -8,5 +8,6 @@ license = "MIT"
|
||||
[dependencies]
|
||||
async-std = { version = "1.12", features = ["attributes"] }
|
||||
async-trait = "0.1"
|
||||
env_logger = "0.10"
|
||||
futures = "0.3.28"
|
||||
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "dcutr", "identify", "macros", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] }
|
||||
|
@ -31,9 +31,9 @@ use std::error::Error;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
println!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
|
@ -41,7 +41,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
let local_pub_key = local_key.public();
|
||||
info!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let mut swarm = SwarmBuilder::without_executor(
|
||||
tcp::async_io::Transport::default()
|
||||
|
@ -8,5 +8,6 @@ license = "MIT"
|
||||
[dependencies]
|
||||
async-std = { version = "1.12", features = ["attributes"] }
|
||||
async-trait = "0.1"
|
||||
env_logger = "0.10.0"
|
||||
futures = "0.3.28"
|
||||
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] }
|
||||
|
@ -31,9 +31,9 @@ use std::error::Error;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
println!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
|
@ -47,7 +47,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Create a static known PeerId based on given secret
|
||||
let local_key: identity::Keypair = generate_ed25519(opt.secret_key_seed);
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
println!("Local peer id: {local_peer_id:?}");
|
||||
|
||||
let tcp_transport = tcp::async_io::Transport::default();
|
||||
|
||||
|
@ -56,8 +56,6 @@ async fn main() {
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
swarm.dial(rendezvous_point_address.clone()).unwrap();
|
||||
|
||||
let mut discover_tick = tokio::time::interval(Duration::from_secs(30));
|
||||
|
@ -56,8 +56,6 @@ async fn main() {
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
let _ = swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap());
|
||||
|
||||
swarm.dial(rendezvous_point_address.clone()).unwrap();
|
||||
|
@ -57,8 +57,6 @@ async fn main() {
|
||||
let external_address = "/ip4/127.0.0.1/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
swarm.add_external_address(external_address);
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
swarm.dial(rendezvous_point_address.clone()).unwrap();
|
||||
|
||||
while let Some(event) = swarm.next().await {
|
||||
|
@ -54,8 +54,6 @@ async fn main() {
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
let _ = swarm.listen_on("/ip4/0.0.0.0/tcp/62649".parse().unwrap());
|
||||
|
||||
while let Some(event) = swarm.next().await {
|
||||
|
@ -57,6 +57,7 @@
|
||||
//! [dependencies]
|
||||
//! libp2p = { version = "0.50", features = ["tcp", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] }
|
||||
//! futures = "0.3.21"
|
||||
//! env_logger = "0.10.0"
|
||||
//! async-std = { version = "1.12.0", features = ["attributes"] }
|
||||
//! ```
|
||||
//!
|
||||
@ -177,7 +178,11 @@
|
||||
//! carried out by a [`Swarm`]. Put simply, a [`Swarm`] drives both a
|
||||
//! [`Transport`] and a [`NetworkBehaviour`] forward, passing commands from the
|
||||
//! [`NetworkBehaviour`] to the [`Transport`] as well as events from the
|
||||
//! [`Transport`] to the [`NetworkBehaviour`].
|
||||
//! [`Transport`] to the [`NetworkBehaviour`]. As you can see, after [`Swarm`] initialization, we
|
||||
//! removed the print of the local [`PeerId`](crate::PeerId) because every time a [`Swarm`] is
|
||||
//! created, it prints the local [`PeerId`](crate::PeerId) in the logs at the INFO level. In order
|
||||
//! to continue to see the local [`PeerId`](crate::PeerId) you must initialize the logger
|
||||
//! (In our example, `env_logger` is used)
|
||||
//!
|
||||
//! ```rust
|
||||
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder};
|
||||
@ -186,9 +191,9 @@
|
||||
//!
|
||||
//! #[async_std::main]
|
||||
//! async fn main() -> Result<(), Box<dyn Error>> {
|
||||
//! env_logger::init();
|
||||
//! let local_key = identity::Keypair::generate_ed25519();
|
||||
//! let local_peer_id = PeerId::from(local_key.public());
|
||||
//! println!("Local peer id: {local_peer_id:?}");
|
||||
//!
|
||||
//! let transport = libp2p::development_transport(local_key).await?;
|
||||
//!
|
||||
@ -243,9 +248,9 @@
|
||||
//!
|
||||
//! #[async_std::main]
|
||||
//! async fn main() -> Result<(), Box<dyn Error>> {
|
||||
//! env_logger::init();
|
||||
//! let local_key = identity::Keypair::generate_ed25519();
|
||||
//! let local_peer_id = PeerId::from(local_key.public());
|
||||
//! println!("Local peer id: {local_peer_id:?}");
|
||||
//!
|
||||
//! let transport = libp2p::development_transport(local_key).await?;
|
||||
//!
|
||||
@ -293,9 +298,9 @@
|
||||
//!
|
||||
//! #[async_std::main]
|
||||
//! async fn main() -> Result<(), Box<dyn Error>> {
|
||||
//! env_logger::init();
|
||||
//! let local_key = identity::Keypair::generate_ed25519();
|
||||
//! let local_peer_id = PeerId::from(local_key.public());
|
||||
//! println!("Local peer id: {local_peer_id:?}");
|
||||
//!
|
||||
//! let transport = libp2p::development_transport(local_key).await?;
|
||||
//!
|
||||
@ -349,9 +354,8 @@
|
||||
//! cargo run --example ping
|
||||
//! ```
|
||||
//!
|
||||
//! It will print the PeerId and the new listening addresses, e.g.
|
||||
//! It will print the new listening addresses, e.g.
|
||||
//! ```sh
|
||||
//! Local peer id: PeerId("12D3KooWT1As4mwh3KYBnNTw9bSrRbYQGJTm9SSte82JSumqgCQG")
|
||||
//! Listening on "/ip4/127.0.0.1/tcp/24915"
|
||||
//! Listening on "/ip4/192.168.178.25/tcp/24915"
|
||||
//! Listening on "/ip4/172.17.0.1/tcp/24915"
|
||||
|
@ -79,7 +79,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
(peer_id, keypair)
|
||||
};
|
||||
info!("Local peer id: {local_peer_id}");
|
||||
|
||||
let transport = {
|
||||
let tcp_transport =
|
||||
|
@ -1520,6 +1520,7 @@ where
|
||||
|
||||
/// Builds a `Swarm` with the current configuration.
|
||||
pub fn build(self) -> Swarm<TBehaviour> {
|
||||
log::info!("Local peer id: {}", self.local_peer_id);
|
||||
Swarm {
|
||||
local_peer_id: self.local_peer_id,
|
||||
transport: self.transport,
|
||||
|
Reference in New Issue
Block a user