Esempio n. 1
0
async def pool(tester, initiator, events, channels):
    pool = Pool(
        local_private_key=initiator.private_key,
        local_node_id=initiator.enr.node_id,
        enr_db=initiator.enr_db,
        outbound_envelope_send_channel=channels.outbound_envelope_send_channel,
        inbound_message_send_channel=channels.inbound_message_send_channel,
        events=initiator.events,
    )
    tester.register_pool(pool, channels)
    return pool
Esempio n. 2
0
 def _get_or_create_pool_for_node(self, node: NodeAPI) -> PoolAndChannels:
     if node.node_id not in self._pools:
         channels = SessionChannels.init()
         pool = Pool(
             local_private_key=node.private_key,
             local_node_id=node.enr.node_id,
             enr_db=node.enr_db,
             outbound_envelope_send_channel=channels.
             outbound_envelope_send_channel,
             inbound_message_send_channel=channels.
             inbound_message_send_channel,
             events=node.events,
         )
         self._pools[node.node_id] = PoolAndChannels(pool, channels)
     return self._pools[node.node_id]
Esempio n. 3
0
    def __init__(
        self,
        local_private_key: keys.PrivateKey,
        listen_on: Endpoint,
        enr_db: ENRDatabaseAPI,
        events: EventsAPI = None,
        message_type_registry: MessageTypeRegistry = v51_registry,
    ) -> None:
        self._local_private_key = local_private_key

        self.listen_on = listen_on
        self._listening = trio.Event()

        self.enr_manager = ENRManager(
            private_key=local_private_key,
            enr_db=enr_db,
        )
        self.enr_db = enr_db
        self._registry = message_type_registry

        # Datagrams
        (
            self._outbound_datagram_send_channel,
            self._outbound_datagram_receive_channel,
        ) = trio.open_memory_channel[OutboundDatagram](256)
        (
            self._inbound_datagram_send_channel,
            self._inbound_datagram_receive_channel,
        ) = trio.open_memory_channel[InboundDatagram](256)

        # EnvelopePair
        (
            self._outbound_envelope_send_channel,
            self._outbound_envelope_receive_channel,
        ) = trio.open_memory_channel[OutboundEnvelope](256)
        (
            self._inbound_envelope_send_channel,
            self._inbound_envelope_receive_channel,
        ) = trio.open_memory_channel[InboundEnvelope](256)

        # Messages
        (
            self._outbound_message_send_channel,
            self._outbound_message_receive_channel,
        ) = trio.open_memory_channel[AnyOutboundMessage](256)
        (
            self._inbound_message_send_channel,
            self._inbound_message_receive_channel,
        ) = trio.open_memory_channel[AnyInboundMessage](256)

        if events is None:
            events = Events()
        self.events = events

        self.pool = Pool(
            local_private_key=self._local_private_key,
            local_node_id=self.enr_manager.enr.node_id,
            enr_db=self.enr_db,
            outbound_envelope_send_channel=self.
            _outbound_envelope_send_channel,
            inbound_message_send_channel=self._inbound_message_send_channel,
            message_type_registry=self._registry,
            events=self.events,
        )

        self.dispatcher = Dispatcher(
            self._inbound_envelope_receive_channel,
            self._inbound_message_receive_channel,
            self.pool,
            self.enr_db,
            self._registry,
            self.events,
        )
        self.envelope_decoder = EnvelopeEncoder(
            self._outbound_envelope_receive_channel,
            self._outbound_datagram_send_channel,
        )
        self.envelope_encoder = EnvelopeDecoder(
            self._inbound_datagram_receive_channel,
            self._inbound_envelope_send_channel,
            self.enr_manager.enr.node_id,
        )

        self._ready = trio.Event()