Exemplo n.º 1
0
    def _attempt_to_peer_with_endpoint(self, endpoint):
        LOGGER.debug("Attempting to connect/peer with %s", endpoint)

        # check if the connection exists, if it does - send,
        # otherwise create it
        try:
            connection_id = \
                self._network.get_connection_id_by_endpoint(
                    endpoint)

            register_request = PeerRegisterRequest(endpoint=self._endpoint)

            self._network.send(validator_pb2.Message.GOSSIP_REGISTER,
                               register_request.SerializeToString(),
                               connection_id,
                               callback=partial(self._peer_callback,
                                                endpoint=endpoint,
                                                connection_id=connection_id))
        except KeyError:
            # if the connection uri wasn't found in the network's
            # connections, it raises a KeyError and we need to add
            # a new outbound connection
            self._network.add_outbound_connection(
                endpoint,
                success_callback=partial(
                    self._connect_success_peering_callback, endpoint=endpoint),
                failure_callback=self._connect_failure_peering_callback)
Exemplo n.º 2
0
    def _attempt_to_peer_with_endpoint(self, endpoint):
        LOGGER.debug("Attempting to connect/peer with %s", endpoint)

        # check if the connection exists, if it does - send,
        # otherwise create it
        try:
            connection_id = \
                self._network.get_connection_id_by_endpoint(
                    endpoint)

            register_request = PeerRegisterRequest(endpoint=self._endpoint)

            self._network.send(validator_pb2.Message.GOSSIP_REGISTER,
                               register_request.SerializeToString(),
                               connection_id,
                               callback=partial(self._peer_callback,
                                                endpoint=endpoint,
                                                connection_id=connection_id))
        except KeyError:
            # if the connection uri wasn't found in the network's
            # connections, it raises a KeyError and we need to add
            # a new outbound connection
            with self._lock:
                self._temp_endpoints[endpoint] = EndpointInfo(
                    EndpointStatus.PEERING, time.time(),
                    INITIAL_RETRY_FREQUENCY)
            self._network.add_outbound_connection(endpoint)
Exemplo n.º 3
0
    def _connect_success_callback(self, connection_id):
        LOGGER.debug("Connection to %s succeeded", connection_id)

        register_request = PeerRegisterRequest()
        self._network.send(validator_pb2.Message.GOSSIP_REGISTER,
                           register_request.SerializeToString(),
                           connection_id,
                           callback=partial(self._peer_callback,
                                            connection_id=connection_id))
Exemplo n.º 4
0
    def handle(self, identity, message_content):
        request = PeerRegisterRequest()
        request.ParseFromString(message_content)
        LOGGER.debug("got peer register message "
                     "from %s. sending ack", identity)
        ack = NetworkAcknowledgement()
        ack.status = ack.OK

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.GOSSIP_ACK)
Exemplo n.º 5
0
    def _connect_success_peering_callback(self, connection_id, endpoint=None):
        LOGGER.debug("Connection to %s succeeded", connection_id)

        register_request = PeerRegisterRequest(endpoint=self._endpoint)
        self._connection_statuses[connection_id] = "temp"

        self._network.send(validator_pb2.Message.GOSSIP_REGISTER,
                           register_request.SerializeToString(),
                           connection_id,
                           callback=partial(self._peer_callback,
                                            connection_id=connection_id,
                                            endpoint=endpoint))
Exemplo n.º 6
0
    def handle(self, connection_id, message_content):
        request = PeerRegisterRequest()
        request.ParseFromString(message_content)
        LOGGER.debug("got peer register message "
                     "from %s. sending ack", connection_id)
        self._gossip.register_peer(connection_id)
        ack = NetworkAcknowledgement()
        ack.status = ack.OK

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)
Exemplo n.º 7
0
    def _connect_success_peering(self, connection_id, endpoint):
        LOGGER.debug("Connection to %s succeeded", connection_id)

        register_request = PeerRegisterRequest(endpoint=self._endpoint)
        self._connection_statuses[connection_id] = PeerStatus.TEMP
        try:
            self._network.send(validator_pb2.Message.GOSSIP_REGISTER,
                               register_request.SerializeToString(),
                               connection_id,
                               callback=partial(self._peer_callback,
                                                connection_id=connection_id,
                                                endpoint=endpoint))
        except ValueError:
            LOGGER.debug("Connection disconnected: %s", connection_id)
Exemplo n.º 8
0
    def start(self):
        futures = []

        fut = self._stream.send(
            message_type=validator_pb2.Message.GOSSIP_REGISTER,
            content=PeerRegisterRequest().SerializeToString())
        futures.append(fut)
Exemplo n.º 9
0
 def start(self):
     for connection in self._network.connections:
         connection.start(daemon=True)
     register_request = PeerRegisterRequest()
     self.broadcast_peer_request(
         validator_pb2.Message.GOSSIP_REGISTER,
         register_request)
Exemplo n.º 10
0
    def handle(self, connection_id, message_content):
        request = PeerRegisterRequest()
        request.ParseFromString(message_content)

        LOGGER.debug("Got peer register message from %s", connection_id)

        ack = NetworkAcknowledgement()
        try:
            self._gossip.register_peer(connection_id, request.endpoint)
            ack.status = ack.OK
        except PeeringException:
            ack.status = ack.ERROR

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)
Exemplo n.º 11
0
    def handle(self, message, peer):
        request = PeerRegisterRequest()
        request.ParseFromString(message.content)

        self._service.register_peer(message.sender, request.identity)

        LOGGER.debug("Got peer register message "
                     "from %s. Sending ack", message.sender)

        ack = NetworkAcknowledgement()
        ack.status = ack.OK

        peer.send(
            validator_pb2.Message(sender=message.sender,
                                  message_type='gossip/ack',
                                  correlation_id=message.correlation_id,
                                  content=ack.SerializeToString()))
Exemplo n.º 12
0
 def start(self):
     futures = []
     fut = self._stream.send(
         message_type='gossip/register',
         content=PeerRegisterRequest().SerializeToString())
     futures.append(fut)