Ejemplo n.º 1
0
    def _peer_callback(self, request, result, connection_id, endpoint=None):
        with self._lock:
            ack = NetworkAcknowledgement()
            ack.ParseFromString(result.content)

            if ack.status == ack.ERROR:
                LOGGER.debug("Peering request to %s was NOT successful",
                             connection_id)
                self._remove_temporary_connection(connection_id)
            elif ack.status == ack.OK:
                LOGGER.debug("Peering request to %s was successful",
                             connection_id)
                if endpoint:
                    try:
                        self._gossip.register_peer(connection_id, endpoint)
                        self._connection_statuses[connection_id] = \
                            PeerStatus.PEER
                        self._gossip.send_block_request("HEAD", connection_id)
                    except PeeringException:
                        # Remove unsuccessful peer
                        self._remove_temporary_connection(connection_id)
                else:
                    LOGGER.debug(
                        "Cannot register peer with no endpoint for "
                        "connection_id: %s", connection_id)
                    self._remove_temporary_connection(connection_id)
Ejemplo n.º 2
0
    def _peer_callback(self, request, result, connection_id):
        ack = NetworkAcknowledgement()
        ack.ParseFromString(result.content)

        if ack.status == ack.ERROR:
            LOGGER.debug("Peering request to %s was NOT successful",
                         connection_id)
        elif ack.status == ack.OK:
            LOGGER.debug("Peering request to %s was successful", connection_id)
            self._peers.append(connection_id)
            self.broadcast_block_request("HEAD")
Ejemplo n.º 3
0
    def _peer_callback(self, request, result, connection_id, endpoint=None):
        with self._condition:
            ack = NetworkAcknowledgement()
            ack.ParseFromString(result.content)

            if ack.status == ack.ERROR:
                LOGGER.debug("Peering request to %s was NOT successful",
                             connection_id)
            elif ack.status == ack.OK:
                LOGGER.debug("Peering request to %s was successful",
                             connection_id)
                if endpoint:
                    self._gossip.register_peer(connection_id, endpoint)
                else:
                    LOGGER.debug(
                        "Cannot register peer with no endpoint for "
                        "connection_id: %s", connection_id)

                self._gossip.send_block_request("HEAD", connection_id)
Ejemplo n.º 4
0
    def _connect_callback(self, request, result,
                          connection=None,
                          success_callback=None,
                          failure_callback=None):
        ack = NetworkAcknowledgement()
        ack.ParseFromString(result.content)

        if ack.status == ack.ERROR:
            LOGGER.debug("Received an error response to the NETWORK_CONNECT "
                         "we sent. Removing connection: %s",
                         connection.connection_id)
            self.remove_connection(connection.connection_id)
            if failure_callback:
                failure_callback(connection_id=connection.connection_id)
        elif ack.status == ack.OK:
            LOGGER.debug("Connection to %s was acknowledged",
                         connection.connection_id)
            if success_callback:
                success_callback(connection_id=connection.connection_id)