Exemplo n.º 1
0
def run_fullnode_process(chain_config: ChainConfig, listen_on: str) -> None:

    manager = create_dbmanager(chain_config.database_ipc_path)
    db = manager.get_db()  # type: ignore
    headerdb = manager.get_headerdb()  # type: ignore
    chaindb = manager.get_chaindb()  # type: ignore
    chain = manager.get_chain()  # type: ignore

    address = Address(listen_on, 30303)
    peer_pool_class = HardCodedNodesPeerPool
    server = Server(
        chain_config.nodekey, address, chain, chaindb, headerdb, db, chain_config.network_id,
        peer_pool_class=peer_pool_class)

    loop = asyncio.get_event_loop()
    # Use a ProcessPoolExecutor as the default so that we can offload cpu-intensive tasks from the
    # main thread.
    loop.set_default_executor(ProcessPoolExecutor())
    sigint_received = asyncio.Event()
    for sig in [signal.SIGINT, signal.SIGTERM]:
        loop.add_signal_handler(sig, sigint_received.set)

    async def exit_on_sigint():
        await sigint_received.wait()
        await server.cancel()
        loop.stop()

    asyncio.ensure_future(exit_on_sigint())
    asyncio.ensure_future(server.run())
    loop.run_forever()
    loop.close()
Exemplo n.º 2
0
def run_fullnode_process(chain_config: ChainConfig, port: int) -> None:
    logger = logging.getLogger('trinity')
    logger.info(TRINITY_HEADER)
    logger.info(construct_trinity_client_identifier())

    manager = create_dbmanager(chain_config.database_ipc_path)
    db = manager.get_db()  # type: ignore
    headerdb = manager.get_headerdb()  # type: ignore
    chaindb = manager.get_chaindb()  # type: ignore
    chain = manager.get_chain()  # type: ignore

    peer_pool_class = HardCodedNodesPeerPool
    server = Server(
        chain_config.nodekey, port, chain, chaindb, headerdb, db, chain_config.network_id,
        peer_pool_class=peer_pool_class)

    loop = asyncio.get_event_loop()
    # Use a ProcessPoolExecutor as the default so that we can offload cpu-intensive tasks from the
    # main thread.
    loop.set_default_executor(ProcessPoolExecutor())
    sigint_received = asyncio.Event()
    for sig in [signal.SIGINT, signal.SIGTERM]:
        loop.add_signal_handler(sig, sigint_received.set)

    async def exit_on_sigint():
        await sigint_received.wait()
        await server.cancel()
        loop.stop()

    asyncio.ensure_future(exit_on_sigint())
    asyncio.ensure_future(server.run())
    loop.run_forever()
    loop.close()
Exemplo n.º 3
0
def get_server(privkey, address, peer_class):
    bootstrap_nodes = []
    chaindb = ChainDB(MemoryDB())
    server = Server(
        privkey,
        address,
        chaindb,
        bootstrap_nodes,
        network_id=1,
        min_peers=1,
        peer_class=peer_class,
    )
    return server
Exemplo n.º 4
0
def get_server(privkey, address, bootstrap_nodes=None, peer_class=DumbPeer):
    if bootstrap_nodes is None:
        bootstrap_nodes = []
    chaindb = ChainDB(MemoryDB())
    server = Server(
        privkey,
        address,
        chaindb,
        bootstrap_nodes,
        1,
        min_peers=1,
        peer_class=peer_class,
    )
    return server
Exemplo n.º 5
0
 def get_p2p_server(self) -> BaseService:
     if self._p2p_server is None:
         manager = self.db_manager
         self._p2p_server = Server(
             self._node_key,
             self._node_port,
             manager.get_chain(),  # type: ignore
             manager.get_chaindb(),  # type: ignore
             self.headerdb,
             manager.get_db(),  # type: ignore
             self._network_id,
             peer_pool_class=PreferredNodePeerPool,
             bootstrap_nodes=self._bootstrap_nodes,
             token=self.cancel_token,
         )
     return self._p2p_server
Exemplo n.º 6
0
def get_server(privkey, address, peer_class):
    base_db = MemoryDB()
    headerdb = HeaderDB(base_db)
    chaindb = ChainDB(base_db)
    chaindb.persist_header(ROPSTEN_GENESIS_HEADER)
    chain = RopstenChain(base_db)
    server = Server(
        privkey,
        address.tcp_port,
        chain,
        chaindb,
        headerdb,
        base_db,
        network_id=NETWORK_ID,
        peer_class=peer_class,
    )
    return server
Exemplo n.º 7
0
 def get_p2p_server(self) -> Server:
     if self._p2p_server is None:
         manager = self.db_manager
         self._p2p_server = Server(
             self._node_key,
             self._node_port,
             manager.get_chain(),  # type: ignore
             manager.get_chaindb(),  # type: ignore
             self.headerdb,
             manager.get_db(),  # type: ignore
             self._network_id,
             max_peers=self._max_peers,
             bootstrap_nodes=self._bootstrap_nodes,
             preferred_nodes=self._preferred_nodes,
             token=self.cancel_token,
         )
     return self._p2p_server
Exemplo n.º 8
0
def get_server(privkey, address, peer_class):
    db = MemoryDB()
    headerdb = HeaderDB(db)
    chaindb = ChainDB(db)
    chaindb.persist_header(ROPSTEN_GENESIS_HEADER)
    chain = RopstenChain(chaindb)
    server = Server(
        privkey,
        address,
        chain,
        chaindb,
        headerdb,
        db,
        network_id=1,
        min_peers=1,
        peer_class=peer_class,
    )
    return server
Exemplo n.º 9
0
def p2p_server(jsonrpc_ipc_pipe_path):
    return Server(None, None, None, None, None, None, None)
Exemplo n.º 10
0
def p2p_server(monkeypatch, jsonrpc_ipc_pipe_path):
    monkeypatch.setattr(Server, '_make_peer_pool',
                        lambda s: PeerPool(None, None, None, None, None, None))
    return Server(None, None, None, None, None, None, None)
Exemplo n.º 11
0
def server():
    privkey = keys.PrivateKey(eip8_values['receiver_private_key'])
    chaindb = ChainDB(MemoryDB())
    server = Server(privkey, SERVER_ADDRESS, chaindb, [], 1)
    return server