tor-dam

tor distributed announce mechanism (not a dht)
git clone https://git.parazyd.org/tor-dam
Log | Files | Refs | README | LICENSE

damhs.py (2556B)


      1 #!/usr/bin/env python3
      2 # Copyright (c) 2017-2018 Dyne.org Foundation
      3 # tor-dam is written and maintained by Ivan Jelincic <parazyd@dyne.org>
      4 #
      5 # This file is part of tor-dam
      6 #
      7 # This program is free software: you can redistribute it and/or modify
      8 # it under the terms of the GNU Affero General Public License as published by
      9 # the Free Software Foundation, either version 3 of the License, or
     10 # (at your option) any later version.
     11 #
     12 # This program is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 # GNU Affero General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU Affero General Public License
     18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 
     20 """
     21 Controller daemon running the ephemeral hidden service.
     22 
     23 Usage: damhs.py <path_to_private.key> <portmap>
     24 
     25 <portmap> is a comma-separated string of at least one of the
     26 following element: 80:49371 (80 is the remote, 49371 is local)
     27 """
     28 
     29 from argparse import ArgumentParser
     30 from sys import stdout
     31 from time import sleep
     32 
     33 from stem.control import Controller
     34 
     35 
     36 def start_hs(ctl=None, ktype=None, kcont=None, portmap=None):
     37     """
     38     Function starting our ephemeral hidden service
     39     """
     40     return ctl.create_ephemeral_hidden_service(portmap, key_type=ktype,
     41                                                key_content=kcont,
     42                                                await_publication=True)
     43 
     44 
     45 def main():
     46     """
     47     Main loop
     48     """
     49     parser = ArgumentParser()
     50     parser.add_argument('-k', '--private-key',
     51                         help='Path to the ed25519 private key',
     52                         default='/home/decode/.dam/private.key')
     53     parser.add_argument('-p', '--port-map',
     54                         help='Comma-separated string of local:remote ports',
     55                         default='80:49731,5000:5000')
     56     args = parser.parse_args()
     57 
     58     ctl = Controller.from_port()
     59     ctl.authenticate(password='topkek')
     60 
     61     portmap = {}
     62     ports = args.port_map.split(',')
     63     for i in ports:
     64         tup = i.split(':')
     65         portmap[int(tup[0])] = int(tup[1])
     66 
     67     keyfile = args.private_key
     68     ktype = 'ED25519-V3'
     69     kcont = open(keyfile).read()
     70 
     71     service = start_hs(ctl=ctl, ktype=ktype, kcont=kcont, portmap=portmap)
     72 
     73     stdout.write('Started HS at %s.onion\n' % service.service_id)
     74     stdout.write('OK\n')
     75     stdout.flush()
     76     while True:
     77         sleep(60)
     78 
     79 
     80 if __name__ == '__main__':
     81     main()