Exemplo n.º 1
0
async def test_node_dial_peer(nodes):
    # Test: Exception raised when dialing a wrong addr
    with pytest.raises(ConnectionRefusedError):
        await nodes[0].dial_peer(
            nodes[1].listen_ip,
            get_open_port(),
            ID("123"),
        )
    # Test: 0 <-> 1
    await nodes[0].dial_peer(
        nodes[1].listen_ip,
        nodes[1].listen_port,
        nodes[1].peer_id,
    )
    assert nodes[0].peer_id in nodes[1].host.get_network().connections
    assert nodes[1].peer_id in nodes[0].host.get_network().connections
    # Test: Second dial to a connected peer does not open a new connection
    original_conn = nodes[1].host.get_network().connections[nodes[0].peer_id]
    await nodes[0].dial_peer(
        nodes[1].listen_ip,
        nodes[1].listen_port,
        nodes[1].peer_id,
    )
    assert nodes[1].host.get_network().connections[
        nodes[0].peer_id] is original_conn
    # Test: 0 <-> 1 <-> 2
    await nodes[2].dial_peer(
        nodes[1].listen_ip,
        nodes[1].listen_port,
        nodes[1].peer_id,
    )
    assert nodes[1].peer_id in nodes[2].host.get_network().connections
    assert nodes[2].peer_id in nodes[1].host.get_network().connections
    assert len(nodes[1].host.get_network().connections) == 2
Exemplo n.º 2
0
)
from p2p.transport import Transport

from trinity.constants import TO_NETWORKING_BROADCAST_CONFIG
from trinity.db.eth1.header import AsyncHeaderDB
from trinity.protocol.common.events import ConnectToNodeCommand
from trinity.server import BaseServer


from tests.p2p.auth_constants import eip8_values
from tests.core.integration_test_helpers import (
    run_peer_pool_event_server,
)


port = get_open_port()
NETWORK_ID = 99
RECEIVER_PRIVKEY = keys.PrivateKey(eip8_values['receiver_private_key'])
RECEIVER_PUBKEY = RECEIVER_PRIVKEY.public_key

INITIATOR_PRIVKEY = keys.PrivateKey(eip8_values['initiator_private_key'])
INITIATOR_PUBKEY = INITIATOR_PRIVKEY.public_key


class ParagonServer(BaseServer):
    def _make_peer_pool(self):
        return ParagonPeerPool(
            privkey=self.privkey,
            context=ParagonContext(),
            token=self.cancel_token,
            event_bus=self.event_bus,
Exemplo n.º 3
0
    ParagonPeer,
    ParagonPeerPool,
)
from p2p.transport import Transport

from trinity.constants import TO_NETWORKING_BROADCAST_CONFIG
from trinity.protocol.common.events import ConnectToNodeCommand
from trinity.server import BaseServer

from tests.p2p.auth_constants import eip8_values
from tests.core.integration_test_helpers import (
    FakeAsyncHeaderDB,
    run_peer_pool_event_server,
)

port = get_open_port()
NETWORK_ID = 99
SERVER_ADDRESS = Address('127.0.0.1', udp_port=port, tcp_port=port)
RECEIVER_PRIVKEY = keys.PrivateKey(eip8_values['receiver_private_key'])
RECEIVER_PUBKEY = RECEIVER_PRIVKEY.public_key
RECEIVER_REMOTE = Node(RECEIVER_PUBKEY, SERVER_ADDRESS)

INITIATOR_PRIVKEY = keys.PrivateKey(eip8_values['initiator_private_key'])
INITIATOR_PUBKEY = INITIATOR_PRIVKEY.public_key
INITIATOR_ADDRESS = Address('127.0.0.1', get_open_port() + 1)
INITIATOR_REMOTE = Node(INITIATOR_PUBKEY, INITIATOR_ADDRESS)


class ParagonServer(BaseServer):
    def _make_peer_pool(self):
        return ParagonPeerPool(