commit 6108e68c184befb078906704c746260906732f47
Author: teor <teor2345(a)gmail.com>
Date: Wed Dec 24 07:41:28 2014 +1100
Automatically create hidden service directory for hidden services
Add a new env hs (boolean) that is set to 1 for hidden services.
Add a new env hs_directory (string) that is set to the name of the hidden
service directory ('hidden_service' by default).
When hs is 1, create hs_directory with mode 0700 (448 decimal).
---
lib/chutney/TorNet.py | 19 +++++++++++++++++++
networks/hs | 2 +-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index 2d2054b..ef85e1f 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -199,6 +199,7 @@ class LocalNodeBuilder(NodeBuilder):
# bridgeauthority -- bool -- are we a bridge authority?
# relay -- bool -- are we a relay?
# bridge -- bool -- are we a bridge?
+ # hs -- bool -- are we a hidden service?
# nodenum -- int -- set by chutney -- which unique node index is this?
# dir -- path -- set by chutney -- data directory for this tor
# tor_gencert -- path to tor_gencert binary
@@ -319,6 +320,8 @@ class LocalNodeBuilder(NodeBuilder):
self._genAuthorityKey()
if self._env['relay']:
self._genRouterKey()
+ if self._env['hs']:
+ self._makeHiddenServiceDir()
def config(self, net):
"""Called to configure a node: creates a torrc file for it."""
@@ -336,6 +339,20 @@ class LocalNodeBuilder(NodeBuilder):
datadir = self._env['dir']
mkdir_p(os.path.join(datadir, 'keys'))
+ def _makeHiddenServiceDir(self):
+ """Create the hidden service subdirectory for this node.
+
+ The directory name is stored under the 'hs_directory' environment
+ key. It is combined with the 'dir' data directory key to yield the
+ path to the hidden service directory.
+
+ 448 is the decimal representation of the octal number 0700. Since
+ python2 only supports 0700 and python3 only supports 0o700, we can
+ use neither.
+ """
+ datadir = self._env['dir']
+ mkdir_p(os.path.join(datadir, self._env['hs_directory']), 448)
+
def _genAuthorityKey(self):
"""Generate an authority identity and signing key for this authority,
if they do not already exist."""
@@ -647,6 +664,8 @@ DEFAULTS = {
'hasbridgeauth': False,
'relay': False,
'bridge': False,
+ 'hs': False,
+ 'hs_directory': 'hidden_service',
'connlimit': 60,
'net_base_dir': 'net',
'tor': os.environ.get('CHUTNEY_TOR', 'tor'),
diff --git a/networks/hs b/networks/hs
index a76ba2b..e91f82e 100644
--- a/networks/hs
+++ b/networks/hs
@@ -2,7 +2,7 @@ Authority = Node(tag="a", authority=1, relay=1, torrc="authority.tmpl")
Middle = Node(tag="m", relay=1, torrc="relay-non-exit.tmpl")
Relay = Node(tag="r", relay=1, torrc="relay.tmpl")
Client = Node(tag="c", torrc="client.tmpl")
-HS = Node(tag="h", torrc="hs.tmpl")
+HS = Node(tag="h", hs=1, torrc="hs.tmpl")
NODES = Authority.getN(4) + Middle.getN(10) + Relay.getN(6) + Client.getN(5) + HS.getN(1)