[Pkg-privacy-commits] [onionshare] 35/53: Refactored non-ephemeral hidden services to use get_hidden_service_conf and set_hidden_service_conf rather than get_conf_map and set_options. So much cleaner this way. (fixes #216)
Ulrike Uhlig
u-guest at moszumanska.debian.org
Wed Dec 30 00:20:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch debian
in repository onionshare.
commit df8e4f6cd4a34af0c5e6a881d377373190445300
Author: Micah Lee <micah at micahflee.com>
Date: Fri Nov 20 17:47:42 2015 -0800
Refactored non-ephemeral hidden services to use get_hidden_service_conf and set_hidden_service_conf rather than get_conf_map and set_options. So much cleaner this way. (fixes #216)
---
onionshare/hs.py | 72 +++++++++++---------------------------------------------
1 file changed, 14 insertions(+), 58 deletions(-)
diff --git a/onionshare/hs.py b/onionshare/hs.py
index 27712b4..e7029c5 100644
--- a/onionshare/hs.py
+++ b/onionshare/hs.py
@@ -107,26 +107,18 @@ class HS(object):
if not os.access(path, os.W_OK):
raise HSDirError(strings._("error_hs_dir_not_writable").format(path))
- hidserv_dir = tempfile.mkdtemp(dir=path)
- self.cleanup_filenames.append(hidserv_dir)
+ self.hidserv_dir = tempfile.mkdtemp(dir=path)
+ self.cleanup_filenames.append(self.hidserv_dir)
# set up hidden service
- hsdic = self.c.get_conf_map('HiddenServiceOptions') or {
- 'HiddenServiceDir': [], 'HiddenServicePort': []
- }
- if hidserv_dir in hsdic.get('HiddenServiceDir', []):
- # Maybe a stale service with the wrong local port
- dropme = hsdic['HiddenServiceDir'].index(hidserv_dir)
- del hsdic['HiddenServiceDir'][dropme]
- del hsdic['HiddenServicePort'][dropme]
- hsdic['HiddenServiceDir'] = hsdic.get('HiddenServiceDir', [])+[hidserv_dir]
- hsdic['HiddenServicePort'] = hsdic.get('HiddenServicePort', [])+[
- '80 127.0.0.1:{0:d}'.format(port)]
-
- self.c.set_options(self._hsdic2list(hsdic))
+ hs_conf = self.c.get_hidden_service_conf()
+ if self.hidserv_dir in hs_conf:
+ del hs_conf[self.hidserv_dir]
+ hs_conf[self.hidserv_dir] = {'HiddenServicePort': [(80, '127.0.0.1', port)]}
+ self.c.set_hidden_service_conf(hs_conf)
# figure out the .onion hostname
- hostname_file = '{0:s}/hostname'.format(hidserv_dir)
+ hostname_file = '{0:s}/hostname'.format(self.hidserv_dir)
onion_host = open(hostname_file, 'r').read().strip()
return onion_host
@@ -193,19 +185,14 @@ class HS(object):
else:
# cleanup hidden service
try:
- if self.controller:
+ if self.c:
# Get fresh hidden services (maybe changed since last time)
# and remove ourselves
- hsdic = self.controller.get_conf_map('HiddenServiceOptions') or {
- 'HiddenServiceDir': [], 'HiddenServicePort': []
- }
- if self.hidserv_dir and self.hidserv_dir in hsdic.get('HiddenServiceDir', []):
- dropme = hsdic['HiddenServiceDir'].index(self.hidserv_dir)
- del hsdic['HiddenServiceDir'][dropme]
- del hsdic['HiddenServicePort'][dropme]
- self.controller.set_options(self._hsdic2list(hsdic))
- # Politely close the controller
- self.controller.close()
+ hs_conf = self.c.get_hidden_service_conf()
+ if self.hidserv_dir in hs_conf:
+ del hs_conf[self.hidserv_dir]
+ self.c.set_hidden_service_conf(hs_conf)
+ self.c.close()
except:
pass
@@ -216,34 +203,3 @@ class HS(object):
elif os.path.isdir(filename):
shutil.rmtree(filename)
self.cleanup_filenames = []
-
- def _hsdic2list(self, dic):
- """
- Convert what we get from get_conf_map to what we need for set_options.
-
- For example, if input looks like this:
- {
- 'HiddenServicePort': [
- '80 127.0.0.1:47906',
- '80 127.0.0.1:33302'
- ],
- 'HiddenServiceDir': [
- '/tmp/onionshare/tmplTfZZu',
- '/tmp/onionshare/tmpchDai3'
- ]
- }
-
-
- Output will look like this:
- [
- ('HiddenServiceDir', '/tmp/onionshare/tmplTfZZu'),
- ('HiddenServicePort', '80 127.0.0.1:47906'),
- ('HiddenServiceDir', '/tmp/onionshare/tmpchDai3'),
- ('HiddenServicePort', '80 127.0.0.1:33302')
- ]
- """
- l = []
- for i in range(len(dic['HiddenServiceDir'])):
- l.append(('HiddenServiceDir', dic['HiddenServiceDir'][i]))
- l.append(('HiddenServicePort', dic['HiddenServicePort'][i]))
- return l
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git
More information about the Pkg-privacy-commits
mailing list