Browse Source

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).
teor 9 years ago
parent
commit
6108e68c18
2 changed files with 20 additions and 1 deletions
  1. 19 0
      lib/chutney/TorNet.py
  2. 1 1
      networks/hs

+ 19 - 0
lib/chutney/TorNet.py

@@ -199,6 +199,7 @@ class LocalNodeBuilder(NodeBuilder):
     # bridgeauthority -- bool -- are we a bridge authority?
     # bridgeauthority -- bool -- are we a bridge authority?
     # relay -- bool -- are we a relay?
     # relay -- bool -- are we a relay?
     # bridge -- bool -- are we a bridge?
     # bridge -- bool -- are we a bridge?
+    # hs -- bool -- are we a hidden service?
     # nodenum -- int -- set by chutney -- which unique node index is this?
     # nodenum -- int -- set by chutney -- which unique node index is this?
     # dir -- path -- set by chutney -- data directory for this tor
     # dir -- path -- set by chutney -- data directory for this tor
     # tor_gencert -- path to tor_gencert binary
     # tor_gencert -- path to tor_gencert binary
@@ -319,6 +320,8 @@ class LocalNodeBuilder(NodeBuilder):
             self._genAuthorityKey()
             self._genAuthorityKey()
         if self._env['relay']:
         if self._env['relay']:
             self._genRouterKey()
             self._genRouterKey()
+        if self._env['hs']:
+            self._makeHiddenServiceDir()
 
 
     def config(self, net):
     def config(self, net):
         """Called to configure a node: creates a torrc file for it."""
         """Called to configure a node: creates a torrc file for it."""
@@ -336,6 +339,20 @@ class LocalNodeBuilder(NodeBuilder):
         datadir = self._env['dir']
         datadir = self._env['dir']
         mkdir_p(os.path.join(datadir, 'keys'))
         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):
     def _genAuthorityKey(self):
         """Generate an authority identity and signing key for this authority,
         """Generate an authority identity and signing key for this authority,
            if they do not already exist."""
            if they do not already exist."""
@@ -647,6 +664,8 @@ DEFAULTS = {
     'hasbridgeauth': False,
     'hasbridgeauth': False,
     'relay': False,
     'relay': False,
     'bridge': False,
     'bridge': False,
+    'hs': False,
+    'hs_directory': 'hidden_service',
     'connlimit': 60,
     'connlimit': 60,
     'net_base_dir': 'net',
     'net_base_dir': 'net',
     'tor': os.environ.get('CHUTNEY_TOR', 'tor'),
     'tor': os.environ.get('CHUTNEY_TOR', 'tor'),

+ 1 - 1
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")
 Middle = Node(tag="m", relay=1, torrc="relay-non-exit.tmpl")
 Relay = Node(tag="r", relay=1, torrc="relay.tmpl")
 Relay = Node(tag="r", relay=1, torrc="relay.tmpl")
 Client = Node(tag="c", torrc="client.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)
 NODES = Authority.getN(4) + Middle.getN(10) + Relay.getN(6) + Client.getN(5) + HS.getN(1)