Эх сурвалжийг харах

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

parazyd 2 жил өмнө
parent
commit
e09f0b192d

+ 6 - 2
src/net/transport/mod.rs

@@ -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(),
+        }
     }
 }
 

+ 6 - 1
src/net/transport/tor.rs

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