net/tor: Add a way to retrieve the running onion address

This commit is contained in:
parazyd
2024-07-02 13:05:43 +02:00
parent ccc5d9cf30
commit e09f0b192d
2 changed files with 12 additions and 3 deletions

View File

@@ -375,8 +375,12 @@ impl Listener {
}
}
pub fn endpoint(&self) -> &Url {
&self.endpoint
pub async fn endpoint(&self) -> Url {
match &self.variant {
#[cfg(feature = "p2p-tor")]
ListenerVariant::Tor(listener) => listener.endpoint.lock().await.clone().unwrap(),
_ => self.endpoint.clone(),
}
}
}

View File

@@ -154,12 +154,13 @@ impl TorDialer {
#[derive(Clone, Debug)]
pub struct TorListener {
datastore: Option<String>,
pub endpoint: Arc<Mutex<Option<Url>>>,
}
impl TorListener {
/// Instantiate a new [`TorListener`]
pub async fn new(datastore: Option<String>) -> io::Result<Self> {
Ok(Self { datastore })
Ok(Self { datastore, endpoint: Arc::new(Mutex::new(None)) })
}
/// Internal listen function
@@ -223,6 +224,10 @@ impl TorListener {
onion_service.onion_name().unwrap(), port,
);
*self.endpoint.lock().await = Some(
Url::parse(&format!("tor://{}:{}", onion_service.onion_name().unwrap(), port)).unwrap(),
);
Ok(TorListenerIntern {
port,
_onion_service: onion_service,