mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
net/tor: Add a way to retrieve the running onion address
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user