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")
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
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)