コード例 #1
0
 def set_nodes(role, id_with_key):
     configuration = get_default_configuration()
     configuration['keys'] = [{
         'alias':
         "my peer",
         'generation':
         u"curve25519",
         # 'file': u"ec_{1}{0}.pem".format(*id_with_key)
         'file':
         u"ec{}_{}_{!r}.pem".format(*((id_with_key) +
                                      (str(uuid.uuid4()), )))
     }]
     configuration['logger'] = {'level': 'ERROR'}
     configuration['overlays'] = [{
         'class':
         role,
         'key':
         "my peer",
         'walkers': [{
             'strategy': "RandomWalk",
             'peers': 10,
             'init': {
                 'timeout': 3.0
             }
         }],
         'initialize': {},
         'on_start': [('started', )]
     }]
     IPv8(configuration)
コード例 #2
0
ファイル: main.py プロジェクト: ureeves/NewBlocksOnTheChain
async def start_communities():
    for i in [1, 2]:
        configuration = get_default_configuration()
        configuration['keys'] = [{
            'alias': "my peer",
            'generation': u"medium",
            'file': u"ec%d.pem" % i
        }]
        # We provide the 'started' function to the 'on_start'.
        # We will call the overlay's 'started' function without any
        # arguments once IPv8 is initialized.
        configuration['overlays'] = [{
            'class':
            'MyCommunity',
            'key':
            "my peer",
            'walkers': [{
                'strategy': "RandomWalk",
                'peers': 10,
                'init': {
                    'timeout': 3.0
                }
            }],
            'initialize': {},
            'on_start': [('started', )]
        }]
        await IPv8(configuration,
                   extra_communities={
                       'MyCommunity': MyCommunity
                   }).start()
コード例 #3
0
def server():
    _COMMUNITIES['Server'] = Server

    for i in [1]:
        configuration = get_default_configuration()
        configuration['keys'] = [{
            'alias': "my peer2",
            'generation': u"curve25519",
            'file': u"ec%d.pem" % i
        }]
        configuration['logger'] = {'level': 'DEBUG'}
        configuration['overlays'] = [{
            'class':
            'Server',
            'key':
            "my peer2",
            'walkers': [{
                'strategy': "RandomWalk",
                'peers': 10,
                'init': {
                    'timeout': 3.0
                }
            }],
            'initialize': {},
            'on_start': [('started', )]
        }]
        IPv8(configuration)
コード例 #4
0
async def start_communities():
    rest_port = 8000
    ipv8_port = 8090
    hostname = GATEWAY_HOSTNAME
    ip_address = GATEWAY_IP
    configuration = get_default_configuration()
    configuration['port'] = ipv8_port
    configuration['keys'] = [{
        'alias':
        "my peer",
        'generation':
        u"curve25519",
        'file': (f"/vol/keys/trustchain/ec.pem" if DOCKER else
                 resolve_user("~/.ssh/eurotoken/trustchain/ec.pem"))
    }]
    configuration['address'] = ip_address
    configuration['logger'] = {
        'level': "INFO",
    }
    configuration['overlays'] = [{
        'class':
        'MyTrustChainCommunity',
        'key':
        "my peer",
        'walkers': [{
            'strategy': "RandomWalk",
            'peers': 10,
            'init': {
                'timeout': 3.0
            }
        }],
        'initialize': {
            'working_directory': (f'/vol/database' if DOCKER else f'.local')
        },
        'on_start': [('started', )]
    }, {
        'class':
        'EuroTokenCommunity',
        'key':
        "my peer",
        'walkers': [{
            'strategy': "RandomWalk",
            'peers': 10,
            'init': {
                'timeout': 3.0
            }
        }],
        'initialize': {},
        'on_start': [('started', )]
    }]

    ipv8 = IPv8(configuration,
                extra_communities={
                    'MyTrustChainCommunity': MyTrustChainCommunity,
                    'EuroTokenCommunity': EuroTokenCommunity
                })
    await ipv8.start()
    interactor = buildSI(ipv8, hostname, ipv8_port)
    rest_manager = get_rest_manager(interactor)
    await rest_manager.start(ip_address, rest_port)
コード例 #5
0
ファイル: main.py プロジェクト: discipl/waardepapieren
async def start_communities():
    for i, v in enumerate(["site", "service", "app"]):
        configuration = get_default_configuration()
        configuration['logger']['level'] = "ERROR"
        configuration['keys'] = [
            {'alias': "anonymous id", 'generation': u"curve25519", 'file': u"certs/ec%d_multichain.pem" % i},
            {'alias': i, 'generation': u"medium", 'file': u"certs/ec%d.pem" % i}
        ]

        # Only load the basic communities
        requested_overlays = ['DiscoveryCommunity', 'AttestationCommunity', 'IdentityCommunity']
        configuration['overlays'] = [o for o in configuration['overlays'] if o['class'] in requested_overlays]

        # Give each peer a separate working directory
        working_directory_overlays = ['AttestationCommunity', 'IdentityCommunity']
        for overlay in configuration['overlays']:
            if overlay['class'] in working_directory_overlays:
                overlay['initialize'] = {'working_directory': 'db/state_%d' % i}

        # Start the IPv8 service
        ipv8 = IPv8(configuration)
        await ipv8.start()
        rest_manager = RESTManager(ipv8)
        await rest_manager.start(14410 + i, '0.0.0.0')

        # Print the peer for reference
        print("Starting " + v, b64encode(ipv8.keys["anonymous id"].mid))
コード例 #6
0
    def set_nodes(role, id_with_key, hop, build_tunnels=False):
        on_start = [('started', )]
        if build_tunnels:
            on_start.append(('build_tunnels', hop))

        configuration = get_default_configuration()
        configuration['keys'] = [{
            'alias':
            "my peer",
            'generation':
            u"curve25519",
            # 'file': u"ec_{1}{0}.pem".format(*id_with_key)
            'file':
            u"ec{}_{}_{!r}.pem".format(*((id_with_key) + (os.urandom(2), )))
        }]
        configuration['logger'] = {'level': 'ERROR'}
        configuration['overlays'] = [{
            'class':
            role,
            'key':
            "my peer",
            'walkers': [{
                'strategy': "RandomWalk",
                'peers': 10,
                'init': {
                    'timeout': 3.0
                }
            }],
            'hops':
            hop,
            'initialize': {},
            'on_start':
            on_start
        }]
        IPv8(configuration)
コード例 #7
0
ファイル: main.py プロジェクト: discipl/core
async def start_communities():
    # Launch two IPv8 services.
    # We run REST endpoints for these services on:
    #  - http://localhost:14411/
    #  - http://localhost:14412/
    # This script also prints the peer ids for reference with:
    #  - http://localhost:1441*/attestation?type=peers
    for i, v in enumerate(["employee", "employer", "brewer"]):
        configuration = get_default_configuration()
        configuration['logger']['level'] = "ERROR"
        configuration['keys'] = [
            {'alias': "anonymous id", 'generation': u"curve25519", 'file': u"certs/ec%d_multichain.pem" % i},
            {'alias': i, 'generation': u"medium", 'file': u"certs/ec%d.pem" % i}
        ]

        # Only load the basic communities
        requested_overlays = ['DiscoveryCommunity', 'AttestationCommunity', 'IdentityCommunity']
        configuration['overlays'] = [o for o in configuration['overlays'] if o['class'] in requested_overlays]

        # Give each peer a separate working directory
        working_directory_overlays = ['AttestationCommunity', 'IdentityCommunity']
        for overlay in configuration['overlays']:
            if overlay['class'] in working_directory_overlays:
                overlay['initialize'] = {'working_directory': 'db/state_%d' % i}

        # Start the IPv8 service
        ipv8 = IPv8(configuration)
        await ipv8.start()
        rest_manager = RESTManager(ipv8)
        await rest_manager.start(14410 + i)

        # Print the peer for reference
        print("Starting " + v, b64encode(ipv8.keys["anonymous id"].mid))
コード例 #8
0
def trust_client():
    _COMMUNITIES['TrustClient'] = TrustClient

    for i in [4]:
        configuration = get_default_configuration()
        configuration['keys'] = [{
            'alias': "my peer",
            'generation': u"curve25519",
            'file': u"ec%d.pem" % i
        }]
        configuration['overlays'] = [{
            'class':
            'TrustClient',
            'key':
            "my peer",
            'walkers': [{
                'strategy': "RandomWalk",
                'peers': 10,
                'init': {
                    'timeout': 3.0
                }
            }],
            'initialize': {},
            'on_start': [('started', )]
        }]
        IPv8(configuration)
コード例 #9
0
async def start_communities():
    ipv8_port = 8090
    settings = TrustChainSettings()
    settings.broadcast_fanout = 0
    configuration = get_default_configuration()
    configuration['port'] = ipv8_port
    configuration['keys'] = [{
        'alias': "my peer",
        'generation': u"curve25519",
        'file': KEY_PATH
    }]
    configuration['address'] = "0.0.0.0"
    configuration['logger'] = {
        'level': "WARNING",
    }
    configuration['overlays'] = [{
        'class':
        'EvalTrustChainCommunity',
        'key':
        "my peer",
        'walkers': [{
            'strategy': "RandomWalk",
            'peers': 10,
            'init': {
                'timeout': 3.0
            }
        }],
        'initialize': {
            'working_directory': f'/vol/database',
            'is_gateway': IS_GATEWAY,
            'n_gateways': GATEWAYS,
            'n_clients': CLIENTS,
            'key_file': KEY_FILE,
            'settings': settings,
            'transactions_to_do': TRANSACTIONS_TO_DO,
            'min_checkpoint_freq': CHECKPOINT_EVERY,
        },
        'on_start': [('started', )]
    }]
    global ipv8
    ipv8 = IPv8(
        configuration,
        extra_communities={'EvalTrustChainCommunity': EvalTrustChainCommunity})

    def stop():
        global STOP
        STOP = True

    ipv8.get_overlay(EvalTrustChainCommunity).set_stop(stop)
    await ipv8.start()
コード例 #10
0
async def start_community():
    for peer_id in [1, 2]:
        configuration = get_default_configuration()
        configuration['keys'] = [
            {'alias': "anonymous id", 'generation': u"curve25519", 'file': f"keyfile_{peer_id}.pem"}]
        configuration['working_directory'] = f"state_{peer_id}"
        configuration['overlays'] = []

        # Start the IPv8 service
        ipv8 = IPv8(configuration)
        await ipv8.start()
        rest_manager = RESTManager(ipv8)
        await rest_manager.start(14410 + peer_id)

        # Print the peer for reference
        print("Starting peer", b64encode(ipv8.keys["anonymous id"].mid))
コード例 #11
0
ファイル: roles.py プロジェクト: Quintor/discipl-core-ipv8
def initialize_peer(path):
    configuration = get_default_configuration()
    configuration['logger'] = {'level': "ERROR"}
    configuration['walker_interval'] = 4
    overlays = ['AttestationCommunity', 'IdentityCommunity']
    configuration['overlays'] = [o for o in configuration['overlays'] if o['class'] in overlays]
    for o in configuration['overlays']:
        o['walkers'] = [{
                    'strategy': "RandomWalk",
                    'peers': 4,
                    'init': {
                        'timeout': 60.0
                    }
                }]
    create_working_dir(path)
    os.chdir(path)
    ipv8 = IPv8(configuration)
    os.chdir(os.path.dirname(__file__))
    rest_manager = TestRESTAPI(ipv8)
    rest_manager.start()
    return ipv8, "http://localhost:%d/attestation" % rest_manager.port
コード例 #12
0
async def start_community():
    for peer_id in [1, 2]:
        configuration = get_default_configuration()
        configuration['keys'] = [{
            'alias': "anonymous id",
            'generation': u"curve25519",
            'file': f"keyfile_{peer_id}.pem"
        }]
        configuration['working_directory'] = f"state_{peer_id}"
        configuration['overlays'] = [
            overlay for overlay in configuration['overlays']
            if overlay['class'] == 'HiddenTunnelCommunity'
        ]

        # Start the IPv8 service
        ipv8 = IPv8(configuration)
        await ipv8.start()
        ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
        ssl_context.load_cert_chain(cert_fileX)
        rest_manager = RESTManager(ipv8)
        await rest_manager.start(14410 + peer_id, ssl_context=ssl_context)

        # Print the peer for reference
        print("Starting peer", b64encode(ipv8.keys["anonymous id"].mid))
コード例 #13
0
                      [c.peer.address
                       for c in self.circuits.values()], "exit node",
                      [c.address for c in self.exit_candidates.values()])
                if p not in self.nodes:
                    self.nodes[p] = None

        # We register a Twisted task with this overlay.
        # This makes sure that the task ends when this overlay is unloaded.
        # We call the 'print_peers' function every 5.0 seconds, starting now.
        self.register_task("print_peers",
                           LoopingCall(print_peers)).start(5.0, True)

_COMMUNITIES['MyCommunity'] = MyCommunity

for i in [3]:
    configuration = get_default_configuration()
    configuration['keys'] = [{
        'alias': "my peer",
        'generation': u"curve25519",
        'file': u"ec%d.pem" % i
    }]
    # We provide the 'started' function to the 'on_start'.
    # We will call the overlay's 'started' function without any
    # arguments once IPv8 is initialized.
    configuration['overlays'] = [{
        'class':
        'MyCommunity',
        'key':
        "my peer",
        'walkers': [{
            'strategy': "RandomWalk",
コード例 #14
0
ファイル: run_ipv8.py プロジェクト: TimSpeelman/ow-ssi
    async def start_peer(self, name, i):

        # Give the peer its own working directory
        workdir = u"%s/%s" % (tempdir, name)
        os.mkdir(workdir)

        # Set up its IPv8 Configuration
        configuration = get_default_configuration()
        configuration['logger']['level'] = "ERROR"
        configuration['keys'] = [{
            'alias': "anonymous id",
            'generation': u"curve25519",
            'file': u"%s/multichain.pem" % (workdir)
        }, {
            'alias': "my peer",
            'generation': u"medium",
            'file': u"%s/ec.pem" % (workdir)
        }]

        # Only load the basic communities
        requested_overlays = [
            'AttestationCommunity', 'IdentityCommunity',
            'DHTDiscoveryCommunity', 'DiscoveryCommunity'
        ]
        configuration['overlays'] = [
            o for o in configuration['overlays']
            if o['class'] in requested_overlays
        ]

        # Provide the working directory to its overlays
        working_directory_overlays = [
            'AttestationCommunity', 'IdentityCommunity', 'TrustChainCommunity'
        ]
        for overlay in configuration['overlays']:
            if overlay['class'] in working_directory_overlays:
                overlay['initialize'] = {'working_directory': workdir}

        # Start its IPv8 service
        ipv8 = IPv8(configuration)
        await ipv8.start()

        # Print the peer for reference
        port = self.first_port + i
        url = "http://localhost:%d" % port
        mid_b64 = b64encode(ipv8.keys["anonymous id"].mid).decode('utf-8')

        print("Starting peer %d (%s) running at %s" % (i, name, url))
        print("- workdir: %s" % workdir)
        print("- mid_b64: %s" % mid_b64)
        print("- mid_hex: %s" % hexlify(ipv8.keys["anonymous id"].mid))

        data = {
            'port': port,
            'mid_b64': mid_b64,
        }

        with open('%s/config.json' % workdir, 'w') as outfile:
            json.dump(data, outfile)
            outfile.close()

        # Start its API
        api = RESTManager(ipv8)
        await api.start(port)

        return (i, name, ipv8, api)
コード例 #15
0
async def start_ipv8():
    # The first IPv8 will attempt to claim a port.
    await IPv8(get_default_configuration()).start()
    # The second IPv8 will attempt to claim a port.
    # It cannot claim the same port and will end up claiming a different one.
    await IPv8(get_default_configuration()).start()
コード例 #16
0
async def start_ipv8():
    # Create an IPv8 object with the default settings.
    ipv8 = IPv8(get_default_configuration())
    await ipv8.start()