feat(asb): add peer-id command to asb-controller (#754)

* add peer-id command to controller

* add peer-id command to changelog

* nitpick: add some more context to peer id command

---------

Co-authored-by: Binarybaron <binarybaron@protonmail.com>
This commit is contained in:
jstark2a 2025-11-19 13:42:10 -06:00 committed by GitHub
parent ea94437315
commit 8fe2c2ad7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 2 deletions

View file

@ -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)

View file

@ -28,6 +28,11 @@ pub struct MultiaddressesResponse {
pub multiaddresses: Vec<String>,
}
#[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<MoneroSeedResponse, ErrorObjectOwned>;
#[method(name = "multiaddresses")]
async fn multiaddresses(&self) -> Result<MultiaddressesResponse, ErrorObjectOwned>;
#[method(name = "peer_id")]
async fn peer_id(&self) -> Result<PeerIdResponse, ErrorObjectOwned>;
#[method(name = "active_connections")]
async fn active_connections(&self) -> Result<ActiveConnectionsResponse, ErrorObjectOwned>;
#[method(name = "get_swaps")]

View file

@ -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

View file

@ -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);

View file

@ -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<PeerIdResponse, ErrorObjectOwned> {
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<ActiveConnectionsResponse, ErrorObjectOwned> {
let connections = self
.event_loop_service