[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Make `Controller.create_ephemeral_hidden_service` asynchronous



commit 83cfe4cf517e72d5ff28731da849462ac13d7b6a
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date:   Tue Apr 21 22:59:20 2020 +0300

    Make `Controller.create_ephemeral_hidden_service` asynchronous
---
 stem/control.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 618408c3..dce1584b 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -2832,7 +2832,7 @@ class Controller(BaseController):
 
     return [r for r in result if r]  # drop any empty responses (GETINFO is blank if unset)
 
-  def create_ephemeral_hidden_service(self, ports: Union[int, Sequence[int], Mapping[int, str]], key_type: str = 'NEW', key_content: str = 'BEST', discard_key: bool = False, detached: bool = False, await_publication: bool = False, timeout: Optional[float] = None, basic_auth: Optional[Mapping[str, str]] = None, max_streams: Optional[int] = None) -> stem.response.add_onion.AddOnionResponse:
+  async def create_ephemeral_hidden_service(self, ports: Union[int, Sequence[int], Mapping[int, str]], key_type: str = 'NEW', key_content: str = 'BEST', discard_key: bool = False, detached: bool = False, await_publication: bool = False, timeout: Optional[float] = None, basic_auth: Optional[Mapping[str, str]] = None, max_streams: Optional[int] = None) -> stem.response.add_onion.AddOnionResponse:
     """
     Creates a new hidden service. Unlike
     :func:`~stem.control.Controller.create_hidden_service` this style of
@@ -2934,15 +2934,15 @@ class Controller(BaseController):
       * :class:`stem.Timeout` if **timeout** was reached
     """
 
-    hs_desc_queue = queue.Queue()  # type: queue.Queue[stem.response.events.Event]
+    hs_desc_queue = asyncio.Queue()  # type: asyncio.Queue[stem.response.events.Event]
     hs_desc_listener = None
     start_time = time.time()
 
     if await_publication:
-      def hs_desc_listener(event: stem.response.events.Event) -> None:
-        hs_desc_queue.put(event)
+      async def hs_desc_listener(event: stem.response.events.Event) -> None:
+        await hs_desc_queue.put(event)
 
-      self.add_event_listener(hs_desc_listener, EventType.HS_DESC)
+      await self.add_event_listener(hs_desc_listener, EventType.HS_DESC)
 
     request = 'ADD_ONION %s:%s' % (key_type, key_content)
 
@@ -2960,7 +2960,7 @@ class Controller(BaseController):
     if max_streams is not None:
       flags.append('MaxStreamsCloseCircuit')
 
-    if self.get_conf('HiddenServiceSingleHopMode', None) == '1' and self.get_conf('HiddenServiceNonAnonymousMode', None) == '1':
+    if (await self.get_conf('HiddenServiceSingleHopMode', None)) == '1' and (await self.get_conf('HiddenServiceNonAnonymousMode', None)) == '1':
       flags.append('NonAnonymous')
 
     if flags:
@@ -2987,7 +2987,7 @@ class Controller(BaseController):
         else:
           request += ' ClientAuth=%s' % client_name
 
-    response = stem.response._convert_to_add_onion(stem.response._convert_to_add_onion(self.msg(request)))
+    response = stem.response._convert_to_add_onion(await self.msg(request))
 
     if await_publication:
       # We should receive five UPLOAD events, followed by up to another five
@@ -3000,7 +3000,7 @@ class Controller(BaseController):
 
       try:
         while True:
-          event = _get_with_timeout(hs_desc_queue, timeout, start_time)
+          event = await _get_with_timeout(hs_desc_queue, timeout, start_time)
 
           if event.action == stem.HSDescAction.UPLOAD and event.address == response.service_id:
             directories_uploaded_to.append(event.directory_fingerprint)
@@ -3012,7 +3012,7 @@ class Controller(BaseController):
             if len(directories_uploaded_to) == len(failures):
               raise stem.OperationFailed(message = 'Failed to upload our hidden service descriptor to %s' % ', '.join(failures))
       finally:
-        self.remove_event_listener(hs_desc_listener)
+        await self.remove_event_listener(hs_desc_listener)
 
     return response
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits