[Pkg-privacy-commits] [onionbalance] 27/117: Fix HSPOST command syntax and add debugging information

Donncha O'Cearbahill donncha-guest at moszumanska.debian.org
Wed Dec 16 23:18:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

donncha-guest pushed a commit to branch debian/sid
in repository onionbalance.

commit da0e5f7951550eb091f3c4da97da8c9594c15e47
Author: Donncha O'Cearbhaill <donncha at donncha.is>
Date:   Thu Jun 18 14:08:03 2015 +0100

    Fix HSPOST command syntax and add debugging information
    
    The HSPOST command request was including an unneccesary
    trailing '\r\n.\r\n' which was also being inserted by stem.
    Thank you to asn for finding this issue.
    
    This commit also increases the logging for HSPOST related control port
    errors and fixes the debugging output when unknown descriptors are
    received.
---
 onionbalance/descriptor.py |  8 +++++---
 onionbalance/service.py    | 23 +++++++++++++++--------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/onionbalance/descriptor.py b/onionbalance/descriptor.py
index ca77e32..2086a5d 100644
--- a/onionbalance/descriptor.py
+++ b/onionbalance/descriptor.py
@@ -216,7 +216,7 @@ def descriptor_received(descriptor_content):
 
     # No matching service instance was found for the descriptor
     logger.debug("Received a descriptor for an unknown service:\n%s",
-                 descriptor_content)
+                 descriptor_content.decode('utf-8'))
     logger.warning("Received a descriptor with address %s.onion that "
                    "did not match any configured service instances.",
                    descriptor_onion_address)
@@ -240,7 +240,8 @@ def upload_descriptor(controller, signed_descriptor, hsdirs=None):
     else:
         server_args = ""
 
-    response = controller.msg("HSPOST%s\r\n%s\r\n.\r\n" %
+    # Stem will insert the leading + and trailing '\r\n.\r\n'
+    response = controller.msg("HSPOST%s\n%s" %
                               (server_args, signed_descriptor))
 
     (response_code, divider, response_content) = response.content()[0]
@@ -249,4 +250,5 @@ def upload_descriptor(controller, signed_descriptor, hsdirs=None):
             raise stem.InvalidRequest(response_code, response_content)
         else:
             raise stem.ProtocolError("HSPOST returned unexpected response "
-                                     "code: %s", response_code)
+                                     "code: %s\n%s", response_code,
+                                     response_content)
diff --git a/onionbalance/service.py b/onionbalance/service.py
index 87c6b6e..2fa51c5 100644
--- a/onionbalance/service.py
+++ b/onionbalance/service.py
@@ -5,6 +5,7 @@ import time
 import base64
 
 import Crypto.PublicKey.RSA
+import stem
 
 from onionbalance import descriptor
 from onionbalance import util
@@ -171,10 +172,16 @@ class Service(object):
                 logger.warning("Error generating master descriptor: %s", exc)
             else:
                 # Signed descriptor was generated successfully, upload it
-                descriptor.upload_descriptor(self.controller,
-                                             signed_descriptor)
-                logger.info("Published a descriptor for service %s.onion "
-                            "under replica %d.", self.onion_address, replica)
+                try:
+                    descriptor.upload_descriptor(self.controller,
+                                                 signed_descriptor)
+                except stem.ControllerError:
+                    logger.exception("Error uploading descriptor for service "
+                                     "%s.onion.", self.onion_address)
+                else:
+                    logger.debug("Published a descriptor for service "
+                                 "%s.onion under replica %d.",
+                                 self.onion_address, replica)
 
         # It would be better to set last_uploaded when an upload succeeds and
         # not when an upload is just attempted. Unfortunately the HS_DESC #
@@ -193,15 +200,15 @@ class Service(object):
                 self._descriptor_not_uploaded_recently(),
                 force_publish]):
 
-            logger.debug("Publishing a descriptor for service %s.onion.",
-                         self.onion_address)
+            logger.info("Publishing a descriptor for service %s.onion.",
+                        self.onion_address)
             self._publish_descriptor()
 
             # If the descriptor ID will change soon, need to upload under
             # the new ID too.
             if self._descriptor_id_changing_soon():
-                logger.debug("Publishing a descriptor for service %s.onion "
-                             "under next descriptor ID.", self.onion_address)
+                logger.info("Publishing a descriptor for service %s.onion "
+                            "under next descriptor ID.", self.onion_address)
                 self._publish_descriptor(deviation=1)
 
         else:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionbalance.git



More information about the Pkg-privacy-commits mailing list