Exemplo n.º 1
0
    def handle(self, connection_id, message_content):
        request = PingRequest()
        request.ParseFromString(message_content)

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

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)
Exemplo n.º 2
0
    def handle(self, identity, message_content):
        request = PingRequest()
        request.ParseFromString(message_content)

        LOGGER.debug("got ping 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.º 3
0
    def handle(self, message, peer):
        LOGGER.debug("PingHandler message: %s", message)
        request = PingRequest()
        request.ParseFromString(message.content)

        LOGGER.debug("Got ping message %s "
                     "from %s. sending ack", message.content, 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.º 4
0
    def handle(self, connection_id, message_content):

        request = PingRequest()
        request.ParseFromString(message_content)

        ack = PingResponse()
        if self._network.get_connection_status(connection_id) == \
                ConnectionStatus.CONNECTED:

            if connection_id in self._last_message:
                del self._last_message[connection_id]

            return HandlerResult(
                HandlerStatus.RETURN,
                message_out=ack,
                message_type=validator_pb2.Message.PING_RESPONSE)

        if connection_id in self._last_message:
            ping_frequency = time.time() - self._last_message[connection_id]

            if ping_frequency < self._allowed_frequency:
                LOGGER.warning("Too many Pings (%s) in %s seconds before "
                               "authorization is complete: %s",
                               ping_frequency,
                               self._allowed_frequency,
                               connection_id)
                violation = AuthorizationViolation(
                    violation=RoleType.Value("NETWORK"))

                return HandlerResult(
                    HandlerStatus.RETURN_AND_CLOSE,
                    message_out=violation,
                    message_type=validator_pb2.Message.AUTHORIZATION_VIOLATION)

        self._last_message[connection_id] = time.time()

        return HandlerResult(
            HandlerStatus.RETURN,
            message_out=ack,
            message_type=validator_pb2.Message.PING_RESPONSE)
Exemplo n.º 5
0
    def handle(self, connection_id, message_content):

        request = PingRequest()
        request.ParseFromString(message_content)
        #LOGGER.debug("PingHandler PingRequest %s(%s)",connection_id[:8],self._network.connection_id_to_endpoint(connection_id))
        ack = PingResponse()
        if self._network.get_connection_status(
                connection_id) == ConnectionStatus.CONNECTED:

            if connection_id in self._last_message:
                del self._last_message[connection_id]
            """
            Here we can ask SYNC with this peer -in case we have no sync yet
            """
            #LOGGER.debug("PingRequest from CONNECTED %s(%s)",connection_id[:8],self._network.connection_id_to_endpoint(connection_id))
            return HandlerResult(
                HandlerStatus.RETURN,
                message_out=ack,
                message_type=validator_pb2.Message.PING_RESPONSE)

        if connection_id in self._last_message:
            if time.time(
            ) - self._last_message[connection_id] < self._allowed_frequency:
                LOGGER.debug(
                    "Too many Pings in %s seconds before authorization is complete: %s",
                    self._allowed_frequency, connection_id)
                violation = AuthorizationViolation(
                    violation=RoleType.Value("NETWORK"))

                return HandlerResult(
                    HandlerStatus.RETURN_AND_CLOSE,
                    message_out=violation,
                    message_type=validator_pb2.Message.AUTHORIZATION_VIOLATION)

        self._last_message[connection_id] = time.time()

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.PING_RESPONSE)
Exemplo n.º 6
0
    def handle(self, connection_id, message_content):

        request = PingRequest()
        request.ParseFromString(message_content)

        ack = NetworkAcknowledgement()
        ack.status = ack.OK
        if self._network.get_connection_status(connection_id) == \
                ConnectionStatus.CONNECTED:

            if connection_id in self._last_message:
                del self._last_message[connection_id]

            return HandlerResult(
                HandlerStatus.RETURN,
                message_out=ack,
                message_type=validator_pb2.Message.NETWORK_ACK)

        if connection_id in self._last_message:
            if time.time() - self._last_message[connection_id] < \
                    self._allowed_frequency:
                LOGGER.debug(
                    "Too many Pings in %s seconds before"
                    "authorization is complete: %s", self._allowed_frequency,
                    connection_id)
                violation = AuthorizationViolation(
                    violation=RoleType.Value("NETWORK"))

                return HandlerResult(
                    HandlerStatus.RETURN_AND_CLOSE,
                    message_out=violation,
                    message_type=validator_pb2.Message.AUTHORIZATION_VIOLATION)

        self._last_message[connection_id] = time.time()

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)