Beispiel #1
0
    def getOnlinePeers(self):
        '''
            Manages the self.onlinePeers attribute list, connects to more peers if we have none connected
        '''

        logger.debug('Refreshing peer pool...')
        maxPeers = int(config.get('peers.max_connect', 10))
        needed = maxPeers - len(self.onlinePeers)

        for i in range(needed):
            if len(self.onlinePeers) == 0:
                self.connectNewPeer(useBootstrap=True)
            else:
                self.connectNewPeer()

            if self.shutdown:
                break
        else:
            if len(self.onlinePeers) == 0:
                logger.debug('Couldn\'t connect to any peers.' + (
                    ' Last node seen %s ago.' %
                    humanreadabletime.human_readable_time(time.time() -
                                                          self.lastNodeSeen)
                    if not self.lastNodeSeen is None else ''))
            else:
                self.lastNodeSeen = time.time()
        self.decrementThreadCount('getOnlinePeers')
Beispiel #2
0
def get_online_peers(shared_state):
    """Manage the kv.get('onlinePeers') attribute list.

    Connect to more peers if we have none connected
    """
    kv: "DeadSimpleKV" = shared_state.get_by_string("DeadSimpleKV")
    if config.get('general.offline_mode', False):
        return
    logger.info('Refreshing peer pool...')
    max_peers = int(config.get('peers.max_connect', 10))
    needed = max_peers - len(kv.get('onlinePeers'))

    last_seen = 'never'
    if not isinstance(kv.get('lastNodeSeen'), type(None)):
        last_seen = human_readable_time(kv.get('lastNodeSeen'))

    for _ in range(needed):
        if len(kv.get('onlinePeers')) == 0:
            connect_new_peer_to_communicator(shared_state, useBootstrap=True)
        else:
            connect_new_peer_to_communicator(shared_state)

        if kv.get('shutdown'):
            break
    else:
        if len(kv.get('onlinePeers')) == 0:
            logger.debug('Couldn\'t connect to any peers.' +
                         f' Last node seen {last_seen}  ago.')
            try:
                get_online_peers(shared_state)
            except RecursionError:
                pass
        else:
            kv.put('lastNodeSeen', time.time())
Beispiel #3
0
def get_online_peers(comm_inst: 'OnionrCommunicatorDaemon'):
    """Manage the comm_inst.onlinePeers attribute list.

    Connect to more peers if we have none connected
    """
    config = comm_inst.config
    if config.get('general.offline_mode', False):
        comm_inst.decrementThreadCount('get_online_peers')
        return
    logger.debug('Refreshing peer pool...')
    max_peers = int(config.get('peers.max_connect', 10))
    needed = max_peers - len(comm_inst.onlinePeers)

    last_seen = 'never'
    if not isinstance(comm_inst.lastNodeSeen, type(None)):
        last_seen = humanreadabletime.human_readable_time(
            comm_inst.lastNodeSeen)

    for _ in range(needed):
        if len(comm_inst.onlinePeers) == 0:
            comm_inst.connectNewPeer(useBootstrap=True)
        else:
            comm_inst.connectNewPeer()

        if comm_inst.shutdown:
            break
    else:
        if len(comm_inst.onlinePeers) == 0:
            logger.debug('Couldn\'t connect to any peers.' +
                         f' Last node seen {last_seen}  ago.')
            try:
                get_online_peers(comm_inst)
            except RecursionError:
                pass
        else:
            comm_inst.lastNodeSeen = time.time()
    comm_inst.decrementThreadCount('get_online_peers')
Beispiel #4
0
 def heartbeat(self):
     '''Show a heartbeat debug message'''
     logger.debug('Heartbeat. Node running for %s.' % humanreadabletime.human_readable_time(self.getUptime()))
     self.decrementThreadCount('heartbeat')