From 0f11ab051eb06206d48181dbe2c486f3d077ed22 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Mon, 26 Apr 2021 11:51:03 +1000 Subject: [PATCH] Print peer ID on debog when starting CLI In order to add more context to the debug logs we print Bob's peer ID. This allows identifying peer related logs on the ASB. --- swap/src/bin/swap.rs | 2 ++ swap/src/network/swarm.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index c155ba57..7662506d 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -174,6 +174,8 @@ async fn main() -> Result<()> { let alice_peer_id = db.get_peer_id(swap_id)?; let mut swarm = swarm::bob(&seed, alice_peer_id)?; + let bob_peer_id = swarm.local_peer_id(); + tracing::debug!("Our peer-id: {}", bob_peer_id); swarm .behaviour_mut() .add_address(alice_peer_id, alice_multiaddr); diff --git a/swap/src/network/swarm.rs b/swap/src/network/swarm.rs index 9d0bea28..67a24581 100644 --- a/swap/src/network/swarm.rs +++ b/swap/src/network/swarm.rs @@ -19,8 +19,10 @@ where { let identity = seed.derive_libp2p_identity(); let transport = transport::build(&identity)?; + let peer_id = identity.public().into_peer_id(); + tracing::debug!("Our peer-id: {}", peer_id); - let swarm = SwarmBuilder::new(transport, behaviour, identity.public().into_peer_id()) + let swarm = SwarmBuilder::new(transport, behaviour, peer_id) .executor(Box::new(|f| { tokio::spawn(f); }))