Ejemplo n.º 1
0
    def test_onionr_thread_initial_sleep(self):
        l = []

        def _test_func(obj_list):
            obj_list.append(1)

        add_onionr_thread(_test_func, (l, ), 0.05, 0.1)
        sleep(0.06)
        self.assertEqual(len(l), 0)
Ejemplo n.º 2
0
    def test_onionr_thread(self):
        l = []

        def _test_func(obj_list):
            obj_list.append(1)

        add_onionr_thread(_test_func, (l, ), 0.05, 0)
        sleep(0.05)
        self.assertGreaterEqual(len(l), 1)
Ejemplo n.º 3
0
    def __init__(self, shared_state, developmentMode=None):
        if developmentMode is None:
            developmentMode = config.get('general.dev_mode', False)

        # configure logger and stuff
        self.config = config
        self.shared_state = shared_state  # TooManyObjects module
        shared_state.add(self)

        # populate kv values
        self.kv = self.shared_state.get_by_string('DeadSimpleKV')

        if config.get('general.offline_mode', False):
            self.kv.put('isOnline', False)

        # initialize core with Tor socks port being 3rd argument
        self.proxyPort = shared_state.get(NetController).socksPort

        self.upload_session_manager = self.shared_state.get(
            uploadblocks.sessionmanager.BlockUploadSessionManager)
        self.shared_state.share_object()

        # loop time.sleep delay in seconds
        self.delay = 5

        # amount of threads running by name, used to prevent too many
        self.threadCounts = {}

        # Loads in and starts the enabled plugins
        plugins.reload()

        # extends our upload list and saves our list when Onionr exits
        uploadqueue.UploadQueue(self)

        add_onionr_thread(lookupblocks.lookup_blocks_from_communicator,
                          [self.shared_state], 25, 3)

        add_onionr_thread(downloadblocks.download_blocks_from_communicator,
                          [self.shared_state],
                          config.get('timers.getBlocks', 10), 1)

        add_onionr_thread(onlinepeers.clear_offline_peer, [self.kv], 58)

        add_onionr_thread(housekeeping.clean_old_blocks, [self.shared_state],
                          10, 1)

        # Discover new peers
        add_onionr_thread(
            lookupadders.lookup_new_peer_transports_with_communicator,
            [shared_state], 60, 3)

        # Timer for adjusting which peers
        # we actively communicate to at any given time,
        # to avoid over-using peers
        add_onionr_thread(cooldownpeer.cooldown_peer, [self.shared_state], 30,
                          60)

        # Timer to read the upload queue and upload the entries to peers
        add_onionr_thread(uploadblocks.upload_blocks_from_communicator,
                          [self.shared_state], 5, 1)

        # This timer creates deniable blocks,
        # in an attempt to further obfuscate block insertion metadata
        if config.get('general.insert_deniable_blocks', True):
            add_onionr_thread(deniableinserts.insert_deniable_block, [], 180,
                              10)

        if config.get('transports.tor', True):
            # Timer to check for connectivity,
            # through Tor to various high-profile onion services
            add_onionr_thread(netcheck.net_check, [shared_state], 500, 60)

        # Announce the public API server transport address
        # to other nodes if security level allows
        if config.get('general.security_level', 1) == 0 \
                and config.get('general.announce_node', True):
            # Default to high security level incase config breaks
            add_onionr_thread(announcenode.announce_node, [self.shared_state],
                              600, 60)
        else:
            logger.debug('Will not announce node.')

        add_onionr_thread(onionrpeers.peer_cleanup, [], 300, 300)

        add_onionr_thread(housekeeping.clean_keys, [], 15, 1)

        if config.get('general.use_bootstrap_list', True):
            bootstrappeers.add_bootstrap_list_to_peer_list(self.kv, [],
                                                           db_only=True)

        daemoneventhooks.daemon_event_handlers(shared_state)

        if not config.get('onboarding.done', True):
            logger.info('First run detected. Run openhome to get setup.',
                        terminal=True)
            get_url()

            while not config.get('onboarding.done', True) and \
                    not self.shared_state.get_by_string(
                        'DeadSimpleKV').get('shutdown'):
                try:
                    time.sleep(2)
                except KeyboardInterrupt:
                    self.shared_state.get_by_string('DeadSimpleKV').put(
                        'shutdown', True)

        # Main daemon loop, mainly for calling timers,
        # don't do any complex operations here to avoid locking
        try:
            while not self.shared_state.get_by_string('DeadSimpleKV').get(
                    'shutdown'):
                time.sleep(self.delay)
        except KeyboardInterrupt:
            self.shared_state.get_by_string('DeadSimpleKV').put(
                'shutdown', True)

        logger.info('Goodbye. (Onionr is cleaning up, and will exit)',
                    terminal=True)
Ejemplo n.º 4
0
def spawn_client_threads(shared_state: 'TooMany'):
    kv: 'DeadSimpleKV' = shared_state.get_by_string('DeadSimpleKV')
    add_onionr_thread(get_online_peers, (shared_state, ), 3, 1)