'Main method to startup a tunnel helper and add a signal handler.'

def start_tunnel(self, options):

    socks5_port = options['socks5']
    introduce_port = options['introduce']
    dispersy_port = options['dispersy']
    crawl_keypair_filename = options['crawl']
    settings = TunnelSettings()
    settings.min_circuits = 0
    settings.max_circuits = 0
    if (socks5_port is not None):
        settings.socks_listen_ports = range(socks5_port, (socks5_port + 5))
    else:
        settings.socks_listen_ports = [random.randint(1000, 65535) for _ in range(5)]
    settings.become_exitnode = bool(options['exit'])
    if settings.become_exitnode:
        logger.info('Exit-node    enabled')
    else:
        logger.info('Exit-node    disabled')
    settings.enable_trustchain = bool(options['trustchain'])
    if settings.enable_trustchain:
        logger.info('Trustchain    enabled')
    else:
        logger.info('Trustchain    disabled')
    tunnel = Tunnel(settings, crawl_keypair_filename, dispersy_port)
    StandardIO(LineHandler(tunnel))
    def stop_tunnel_api():
        if self.tunnel_site:
            return maybeDeferred(self.tunnel_site.stopListening)
        return succeed(None)
    def signal_handler(sig, _):
        msg(('Received    shut    down    signal    %s' % sig))
        if (not self._stopping):
            self._stopping = True
            msg('Setting    the    tunnel    should_run    variable    to    False')
            tunnel.should_run = False
            tunnel.stop().addCallback((lambda _: stop_tunnel_api().addCallback((lambda _: reactor.stop()))))
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
    tunnel.start(introduce_port)
    if (options['tunnelapi'] > 0):
        self.tunnel_site = self.site = reactor.listenTCP(options['tunnelapi'], server.Site(resource=TunnelRootEndpoint(tunnel)))
