diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b69f02..368f18e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- ASB + CONTROLLER: Add the `peer-id` command to the controller shell which can be used to obtain the Peer ID of your ASB instance. + ## [3.3.7] - 2025-11-19 - ORCHESTRATOR + ASB: Support for tunneling both the Bitcoin and Monero node over Tor has been added (thanks to @nabijaczleweli) diff --git a/swap-controller-api/src/lib.rs b/swap-controller-api/src/lib.rs index 4d9b8152..883059a7 100644 --- a/swap-controller-api/src/lib.rs +++ b/swap-controller-api/src/lib.rs @@ -28,6 +28,11 @@ pub struct MultiaddressesResponse { pub multiaddresses: Vec, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct PeerIdResponse { + pub peer_id: String, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ActiveConnectionsResponse { pub connections: usize, @@ -87,6 +92,8 @@ pub trait AsbApi { async fn monero_seed(&self) -> Result; #[method(name = "multiaddresses")] async fn multiaddresses(&self) -> Result; + #[method(name = "peer_id")] + async fn peer_id(&self) -> Result; #[method(name = "active_connections")] async fn active_connections(&self) -> Result; #[method(name = "get_swaps")] diff --git a/swap-controller/src/cli.rs b/swap-controller/src/cli.rs index 9f8a8e91..f0f89f20 100644 --- a/swap-controller/src/cli.rs +++ b/swap-controller/src/cli.rs @@ -29,6 +29,8 @@ pub enum Cmd { MoneroSeed, /// Get external multiaddresses Multiaddresses, + /// Get peer ID + PeerId, /// Get active connection count ActiveConnections, /// Get list of swaps diff --git a/swap-controller/src/main.rs b/swap-controller/src/main.rs index 89d87c26..a831c443 100644 --- a/swap-controller/src/main.rs +++ b/swap-controller/src/main.rs @@ -66,6 +66,13 @@ async fn dispatch(cmd: Cmd, client: impl AsbApiClient) -> anyhow::Result<()> { } } } + Cmd::PeerId => { + let response = client.peer_id().await?; + println!("Peer IDs are used to identify peers within the P2P network."); + println!("They are effectively the hash of your public key and are used for end-to-end encryption of network traffic."); + println!(); + println!("Your Peer ID is: {}", response.peer_id); + } Cmd::ActiveConnections => { let response = client.active_connections().await?; println!("Connected to {} peers", response.connections); diff --git a/swap/src/asb/rpc/server.rs b/swap/src/asb/rpc/server.rs index eea1157d..bc38dfe9 100644 --- a/swap/src/asb/rpc/server.rs +++ b/swap/src/asb/rpc/server.rs @@ -10,8 +10,8 @@ use std::sync::Arc; use swap_controller_api::{ ActiveConnectionsResponse, AsbApiServer, BitcoinBalanceResponse, BitcoinSeedResponse, MoneroAddressResponse, MoneroBalanceResponse, MoneroSeedResponse, MultiaddressesResponse, - RegistrationStatusItem, RegistrationStatusResponse, RendezvousConnectionStatus, - RendezvousRegistrationStatus, Swap, + PeerIdResponse, RegistrationStatusItem, RegistrationStatusResponse, + RendezvousConnectionStatus, RendezvousRegistrationStatus, Swap, }; use tokio_util::task::AbortOnDropHandle; @@ -131,6 +131,18 @@ impl AsbApiServer for RpcImpl { Ok(MultiaddressesResponse { multiaddresses }) } + async fn peer_id(&self) -> Result { + let (peer_id, _) = self + .event_loop_service + .get_multiaddresses() + .await + .into_json_rpc_result()?; + + Ok(PeerIdResponse { + peer_id: peer_id.to_string(), + }) + } + async fn active_connections(&self) -> Result { let connections = self .event_loop_service