Esempio n. 1
0
    def handle(self, connection_id, message_content):
        message = DisconnectMessage()
        message.ParseFromString(message_content)
        LOGGER.debug("got disconnect message from %s. sending ack",
                     connection_id)

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

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)
Esempio n. 2
0
 def _remove_temporary_connection(self, connection_id):
     status = self._connection_statuses.get(connection_id)
     if status == "temp":
         LOGGER.debug("Closing connection to %s", connection_id)
         msg = DisconnectMessage()
         self._network.send(validator_pb2.Message.NETWORK_DISCONNECT,
                            msg.SerializeToString(), connection_id)
         del self._connection_statuses[connection_id]
         self._network.remove_connection(connection_id)
     elif status == "peer":
         LOGGER.debug("Connection is a peer, do not close.")
     elif status is None:
         LOGGER.debug("Connection is not found")
Esempio n. 3
0
    def stop(self):
        self._stopped = True
        for connection_id in self._connection_statuses:
            try:
                if self._connection_statuses[connection_id] == "closed":
                    continue

                msg = DisconnectMessage()
                self._network.send(validator_pb2.Message.NETWORK_DISCONNECT,
                                   msg.SerializeToString(), connection_id)
                self._connection_statuses[connection_id] = "closed"
            except ValueError:
                # Connection has already been disconnected.
                pass
Esempio n. 4
0
 def _remove_temporary_connection(self, connection_id):
     status = self._connection_statuses.get(connection_id)
     if status == PeerStatus.TEMP:
         LOGGER.debug("Closing connection to %s", connection_id)
         msg = DisconnectMessage()
         self._network.send(validator_pb2.Message.NETWORK_DISCONNECT,
                            msg.SerializeToString(), connection_id)
         del self._connection_statuses[connection_id]
         self._network.remove_connection(connection_id)
     elif status == PeerStatus.PEER:
         LOGGER.debug("Connection close request for peer ignored: %s",
                      connection_id)
     elif status is None:
         LOGGER.debug(
             "Connection close request for unknown connection "
             "ignored: %s", connection_id)