Пример #1
0
async def tidy_http_peers_job(config=None):
    """Check that HTTP peers are reacheable, else remove them from the list"""
    from aleph.web import app
    from aleph.services.p2p import singleton
    from aleph.services.utils import get_IP

    my_ip = await get_IP()
    if config is None:
        config = app['config']
    await asyncio.sleep(2)
    while True:
        try:
            peers = list()
            jobs = list()
            async for peer in get_peers(peer_type='HTTP'):
                if my_ip in peer:
                    continue

                jobs.append(check_peer(peers, peer))
            await asyncio.gather(*jobs)
            singleton.api_servers = peers

        except Exception:
            LOGGER.exception("Error reconnecting to peers")

        await asyncio.sleep(config.p2p.reconnect_delay.value)
Пример #2
0
async def reconnect_ipfs_job(config):
    from aleph.services.utils import get_IP
    my_ip = await get_IP()
    await asyncio.sleep(2)
    while True:
        try:
            LOGGER.info("Reconnecting to peers")
            for peer in config.ipfs.peers.value:
                try:
                    ret = await connect_ipfs_peer(peer)
                    if 'Strings' in ret:
                        LOGGER.info('\n'.join(ret['Strings']))
                except aioipfs.APIError:
                    LOGGER.warning("Can't reconnect to %s" % peer)

            async for peer in get_peers(peer_type='IPFS'):
                if peer in config.ipfs.peers.value:
                    continue

                if my_ip in peer:
                    continue

                try:
                    ret = await connect_ipfs_peer(peer)
                    if 'Strings' in ret:
                        LOGGER.info('\n'.join(ret['Strings']))
                except aioipfs.APIError:
                    LOGGER.warning("Can't reconnect to %s" % peer)

        except Exception:
            LOGGER.exception("Error reconnecting to peers")

        await asyncio.sleep(config.ipfs.reconnect_delay.value)
Пример #3
0
async def reconnect_p2p_job(config=None):
    from aleph.web import app
    if config is None:
        config = app['config']
    await asyncio.sleep(2)
    while True:
        try:
            peers = set(config.p2p.peers.value +
                        [a async for a in get_peers(peer_type='P2P')])
            for peer in peers:
                try:
                    await connect_peer(config, peer)
                except:
                    LOGGER.debug("Can't reconnect to %s" % peer)

        except Exception:
            LOGGER.exception("Error reconnecting to peers")

        await asyncio.sleep(config.p2p.reconnect_delay.value)