def handle_msg_meta(self, msg, meta): """ Main routine to handle incoming SCION messages. """ if isinstance(meta, SockOnlyMetadata): # From SCIOND API try: sciond_msg = parse_sciond_msg(msg) except SCIONParseError as err: logging.error(str(err)) return self.api_handle_request(sciond_msg, meta) return super().handle_msg_meta(msg, meta)
def _test_as_request_reply(self): as_req = SCIONDASInfoRequest.from_values() api_socket = self.api_socket() api_socket.send(as_req.pack_full()) data = api_socket.recv()[0] if data: response = parse_sciond_msg(data) if response.MSG_TYPE != SMT.AS_REPLY: logging.error("Unexpected SCIOND msg type received: %s" % response.NAME) return False for entry in response.iter_entries(): if entry.isd_as() == self.addr.isd_as: logging.debug("Received correct AS reply.") return True logging.error("Wrong AS Reply received.") return False
def _get_response(self, socket, expected_id, expected_type): # pragma: no cover try: data = socket.recv()[0] except timeout: raise SCIONDResponseError("Socket timed out.") except SCIONIOError: raise SCIONDResponseError("Socket IO error.") if not data: raise SCIONDResponseError("Received empty response from SCIOND.") try: response = parse_sciond_msg(data) except SCIONParseError as e: raise SCIONDResponseError(str(e)) if response.MSG_TYPE != expected_type: raise SCIONDResponseError( "Unexpected SCIOND msg type received: %s" % response.NAME) if response.id != expected_id: raise SCIONDResponseError("Wrong response ID: %d (expected %d)" % (response.id, expected_id)) return response