def startup_callback(tor_conn): self.print_startup_error = True self.tor_conn = tor_conn self.tor_conn.protocol.on_disconnect = restart_deferred log.debug('Successfully connected to Tor control port') hs_loc = ('80 localhost:8083') if not hostname and not key: log.info('Creating new onion service') ephs = EphemeralHiddenService(hs_loc) else: log.info('Setting up existing onion service %s', hostname) ephs = EphemeralHiddenService(hs_loc, key) @inlineCallbacks def initialization_callback(ret): log.info('Initialization of hidden-service %s completed.', ephs.hostname) if not hostname and not key: yield set_onion_service_info(ephs.hostname, ephs.private_key) yield refresh_memory_variables() d = ephs.add_to_tor(self.tor_conn.protocol) d.addCallback(initialization_callback) # pylint: disable=no-member
def add_onion_service(self, tid, hostname, key): if self.tor_conn is None: return hs_loc = ('80 localhost:8083') if not hostname and not key: log.err('Creating new onion service', tid=tid) if self.onion_service_version == 3: ephs = EphemeralHiddenService(hs_loc, 'NEW:ED25519-V3') else: ephs = EphemeralHiddenService(hs_loc, 'NEW:RSA1024') else: log.info('Setting up existing onion service %s', hostname, tid=tid) ephs = EphemeralHiddenService(hs_loc, key) self.hs_map[hostname] = ephs @inlineCallbacks def init_callback(ret): log.err('Initialization of onion-service %s completed.', ephs.hostname, tid=tid) if not hostname and not key: if tid in State.tenant_cache: self.hs_map[ephs.hostname] = ephs yield set_onion_service_info(tid, ephs.hostname, ephs.private_key) else: yield ephs.remove_from_tor(self.tor_conn.protocol) tid_list = list(set([1, tid])) for x in tid_list: Cache().invalidate(x) yield refresh_memory_variables(tid_list) return ephs.add_to_tor(self.tor_conn.protocol).addCallbacks(init_callback) # pylint: disable=no-member
def add_onion_service(self, tid, hostname, key): if self.tor_conn is None: return hs_loc = ('80 localhost:8083') log.info('Setting up the onion service %s', hostname, tid=tid) ephs = EphemeralHiddenService(hs_loc, key) self.hs_map[hostname] = ephs def init_callback(ret): log.err('Initialization of onion-service %s completed.', ephs.hostname, tid=tid) return ephs.add_to_tor(self.tor_conn.protocol).addCallbacks( init_callback) # pylint: disable=no-member
def configure_tor_hs(bind_port): hostname, key = yield get_onion_service_info() log.info('Starting up Tor connection') try: tor_conn = yield build_local_tor_connection(reactor) tor_conn.protocol.on_disconnect = Deferred() except ConnectionRefusedError as e: log.err('Tor daemon is down or misconfigured . . . starting up anyway') return log.debug('Successfully connected to Tor control port') hs_loc = ('80 localhost:%d' % bind_port) if hostname == '': log.info('Creating new onion service') ephs = EphemeralHiddenService(hs_loc) else: log.info('Setting up existing onion service %s', hostname) ephs = EphemeralHiddenService(hs_loc, key) @inlineCallbacks def shutdown_callback(): log.info('Shutting down Tor onion service %s' % ephs.hostname) if not getattr(tor_conn.protocol.on_disconnect, 'called', True): log.debug('Removing onion service') yield ephs.remove_from_tor(tor_conn.protocol) log.debug('Successfully handled Tor cleanup') @inlineCallbacks def initialization_callback(ret): log.info('Initialization of hidden-service %s completed.' % (ephs.hostname)) if hasattr(ephs, 'private_key'): yield set_onion_service_info(ephs.hostname, ephs.private_key) reactor.addSystemEventTrigger('before', 'shutdown', shutdown_callback) d = ephs.add_to_tor(tor_conn.protocol) d.addCallback(initialization_callback) # pylint: disable=no-member