[Pkg-privacy-commits] [onionbalance] 05/117: Upload under next descriptor ID when changing soon
Donncha O'Cearbahill
donncha-guest at moszumanska.debian.org
Wed Dec 16 23:18:41 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 295fa031d4669eed050972f6c1eed2db7c86c070
Author: Donncha O'Cearbhaill <donncha at donncha.is>
Date: Sun Apr 5 20:53:09 2015 +0100
Upload under next descriptor ID when changing soon
---
onion-balance/config.py | 3 +++
onion-balance/hiddenservice.py | 42 ++++++++++++++++++++++++++++++++----------
onion-balance/util.py | 10 +++++++++-
3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/onion-balance/config.py b/onion-balance/config.py
index 91140bc..6460129 100644
--- a/onion-balance/config.py
+++ b/onion-balance/config.py
@@ -8,6 +8,9 @@ class Config(object):
self.config = {
'replicas': 2,
'max_intro_points': 10,
+ 'descriptor_validity_period': 24 * 60 * 60,
+ 'descriptor_overlap_period': 60 * 60,
+ 'descriptor_upload_period': 60 * 60, # Re-upload every hour
'refresh': 10 * 60
}
# In memory list of hidden services and balancing instances
diff --git a/onion-balance/hiddenservice.py b/onion-balance/hiddenservice.py
index 75a4feb..9c243ef 100644
--- a/onion-balance/hiddenservice.py
+++ b/onion-balance/hiddenservice.py
@@ -2,6 +2,7 @@
import datetime
import random
import time
+import base64
import Crypto.PublicKey.RSA
import stem.descriptor.hidden_service_descriptor
@@ -78,15 +79,29 @@ class HiddenService(object):
def _descriptor_expiring(self):
"""
- Check if the last uploaded super descriptor is expiring (> 1
- hour old).
+ Check if the last uploaded super descriptor is old and should be
+ uploaded again.
"""
if not self.last_uploaded:
# No descriptor uploaded yet, we should publish.
return True
descriptor_age = (datetime.datetime.utcnow() - self.last_uploaded)
- if (descriptor_age.total_seconds() > 60 * 60):
+ if (descriptor_age.total_seconds() >
+ config.cfg.config.get("descriptor_upload_period")):
+ return True
+
+ return False
+
+ def _descriptor_id_changing_soon(self):
+ """
+ If the descriptor ID will change soon, upload under both descriptor IDs
+ """
+ seconds_valid = util.get_seconds_valid(
+ time.time(), base64.b32decode(self.onion_address, 1))
+
+ # Check if descriptor ID will be changing within the overlap period.
+ if seconds_valid < config.cfg.config.get('descriptor_overlap_period'):
return True
return False
@@ -141,7 +156,7 @@ class HiddenService(object):
return choosen_intro_points
- def _get_signed_descriptor(self, replica=0):
+ def _get_signed_descriptor(self, replica=0, timestamp=None):
"""
Generate a signed HS descriptor for this hidden service
"""
@@ -153,19 +168,18 @@ class HiddenService(object):
signed_descriptor = descriptor.generate_hs_descriptor(
self.service_key,
introduction_point_list=introduction_points,
- replica=replica
+ replica=replica,
+ timestamp=timestamp
)
return signed_descriptor
- def _upload_descriptor(self):
+ def _upload_descriptor(self, timestamp=None):
"""
Create, sign and upload a super-descriptors for this HS
-
- TODO: If the descriptor ID is changing soon, upload to current
- and upcoming set's of HSDirs.
"""
for replica in range(0, config.cfg.config.get("replicas")):
- signed_descriptor = self._get_signed_descriptor(replica=replica)
+ signed_descriptor = self._get_signed_descriptor(
+ replica=replica, timestamp=timestamp)
# Upload if a signed descriptor was generated successfully
if signed_descriptor:
@@ -187,6 +201,14 @@ class HiddenService(object):
self._upload_descriptor()
+ # If the descriptor ID will change soon, need to upload under
+ # the new ID too.
+ if self._descriptor_id_changing_soon():
+ logger.info("Publishing new descriptor for '%s' under "
+ "next descriptor ID" % self.onion_address)
+ next_time = datetime.datetime.utcnow() + datetime.timedelta(1)
+ self._upload_descriptor(timestamp=next_time)
+
class Instance(object):
"""
diff --git a/onion-balance/util.py b/onion-balance/util.py
index e755c6d..567eaee 100644
--- a/onion-balance/util.py
+++ b/onion-balance/util.py
@@ -52,7 +52,15 @@ def get_time_period(time, permanent_id):
time-period = (current-time + permanent-id-byte * 86400 / 256) / 86400
"""
permanent_id_byte = int(struct.unpack('B', permanent_id[0:1])[0])
- return int((time + permanent_id_byte * 86400 / 256) / 86400)
+ return int((int(time) + permanent_id_byte * 86400 / 256) / 86400)
+
+
+def get_seconds_valid(time, permanent_id):
+ """
+ Calculate seconds until the descriptor ID changes
+ """
+ permanent_id_byte = int(struct.unpack('B', permanent_id[0:1])[0])
+ return 86400 - int((int(time) + permanent_id_byte * 86400 / 256) % 86400)
def calc_secret_id_part(time_period, descriptor_cookie, replica):
--
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