From fd74cbd5257cc897de20256862910c0e02c4bc3d Mon Sep 17 00:00:00 2001 From: Joseph Freeston Date: Tue, 9 May 2023 03:27:59 -0400 Subject: [PATCH 1/2] Fixed data handling bugs --- .../reference/referencedispatcher.py | 3 ++ .../reference_api/__init__.py | 3 ++ .../reference_api/protocol.py | 29 ++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/CubeServer-beaconserver/cubeserver_beaconserver/reference/referencedispatcher.py b/src/CubeServer-beaconserver/cubeserver_beaconserver/reference/referencedispatcher.py index 7a31ebe..85561a1 100644 --- a/src/CubeServer-beaconserver/cubeserver_beaconserver/reference/referencedispatcher.py +++ b/src/CubeServer-beaconserver/cubeserver_beaconserver/reference/referencedispatcher.py @@ -41,6 +41,9 @@ def connect_hook(client_socket): # Send the request to the appropriate reference server with routing_id_map[req.routing_id].lock: routing_id_map[req.routing_id].tx_bytes(req.dump()) + if routing_id_map[req.routing_id].rx_bytes(1) != protocol.ReferenceSignal.ACK.value: + logging.warn("Reference server did not acknowledge request") + return response = protocol.ReferenceResponse.from_socket(routing_id_map[req.routing_id].sock) # Log the response diff --git a/src/CubeServer-common/cubeserver_common/reference_api/__init__.py b/src/CubeServer-common/cubeserver_common/reference_api/__init__.py index f69eb0e..d229c2e 100644 --- a/src/CubeServer-common/cubeserver_common/reference_api/__init__.py +++ b/src/CubeServer-common/cubeserver_common/reference_api/__init__.py @@ -23,6 +23,9 @@ def request(self, req: protocol.ReferenceRequest) -> protocol.ReferenceResponse: """Sends a request to the reference server and returns the response""" self.sock.setblocking(True) self.sock.send(req.dump()) +# if self.sock.rx_bytes(1) != protocol.ReferenceSignal.ACK.value: +# logging.warn("Reference server did not acknowledge request") +# return return protocol.ReferenceResponse.from_socket(self.sock) def close(self): diff --git a/src/CubeServer-common/cubeserver_common/reference_api/protocol.py b/src/CubeServer-common/cubeserver_common/reference_api/protocol.py index 6aa527b..a3c3dc4 100644 --- a/src/CubeServer-common/cubeserver_common/reference_api/protocol.py +++ b/src/CubeServer-common/cubeserver_common/reference_api/protocol.py @@ -128,11 +128,11 @@ def dump(self) -> bytes: """Dumps the response to a byte string""" return b''.join([ REFERENCECOM_VERSION, - self.signal.value, + self.signal.value if isinstance(self.signal, ReferenceSignal) else self.signal, self.length, self.struct_type, self.response, - ReferenceSignal.EOT + ReferenceSignal.EOT.value ]) def get_value(self) -> bytes | int | bool | float: @@ -154,26 +154,47 @@ def set_value(self, format: str | bytes, value: bytes | int | bool | float) -> N def from_socket(self, socket: socket.socket) -> 'ReferenceResponse': """Reads a response from the given socket""" # + logging.debug("Reading response from socket") version = socket.recv(1) + if version == ReferenceSignal.ACK.value: + logging.debug("Received ACK") + version = socket.recv(1) + elif version == ReferenceSignal.NAK.value: + logging.debug("Received NAK") + return None + logging.debug(f"Version: {version}") if version != REFERENCECOM_VERSION: + logging.warning(f"Invalid response - wrong version") socket.sendall(ReferenceSignal.NAK.value) return signal = socket.recv(1) + logging.debug(f"Signal: {signal}") if signal != ReferenceSignal.ACK.value: + logging.warning(f"Invalid Did not get ACK") socket.sendall(ReferenceSignal.NAK.value) return - length = int.from_bytes(self.rx_bytes(1), 'big') + length = int.from_bytes(socket.recv(1), 'big') + logging.debug(f"Length: {length}") struct_type = socket.recv(1) + logging.debug(f"Struct Type: {struct_type}") response = socket.recv(length) + logging.debug(f"Response: {response}") eot = socket.recv(1) if eot != ReferenceSignal.EOT.value: + logging.warning(f"Invalid response - missing EOT") socket.sendall(ReferenceSignal.NAK.value) return + logging.debug(f"Signal: {signal}") + logging.debug(f"Length: {bytes([length])}") + logging.debug(f"Struct Type: {struct_type}") + logging.debug(f"Response: {response}") + logging.debug(f"EOT: {eot}") + # Package response return ReferenceResponse( signal=signal, - length=length, + length=bytes([length]), struct_type=struct_type, response=response ) \ No newline at end of file From b129e32b576723dbcc954891dd2167108dcfaca3 Mon Sep 17 00:00:00 2001 From: Joseph Freeston Date: Tue, 9 May 2023 08:21:44 -0400 Subject: [PATCH 2/2] bumped version --- src/CubeServer-api/cubeserver_api/_version.py | 2 +- src/CubeServer-app/cubeserver_app/_version.py | 2 +- src/CubeServer-beaconserver/cubeserver_beaconserver/_version.py | 2 +- src/CubeServer-common/cubeserver_common/_version.py | 2 +- version.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CubeServer-api/cubeserver_api/_version.py b/src/CubeServer-api/cubeserver_api/_version.py index e4adfb8..f49459c 100644 --- a/src/CubeServer-api/cubeserver_api/_version.py +++ b/src/CubeServer-api/cubeserver_api/_version.py @@ -1 +1 @@ -__version__ = "1.6.0" +__version__ = "1.6.1" diff --git a/src/CubeServer-app/cubeserver_app/_version.py b/src/CubeServer-app/cubeserver_app/_version.py index e4adfb8..f49459c 100644 --- a/src/CubeServer-app/cubeserver_app/_version.py +++ b/src/CubeServer-app/cubeserver_app/_version.py @@ -1 +1 @@ -__version__ = "1.6.0" +__version__ = "1.6.1" diff --git a/src/CubeServer-beaconserver/cubeserver_beaconserver/_version.py b/src/CubeServer-beaconserver/cubeserver_beaconserver/_version.py index e4adfb8..f49459c 100644 --- a/src/CubeServer-beaconserver/cubeserver_beaconserver/_version.py +++ b/src/CubeServer-beaconserver/cubeserver_beaconserver/_version.py @@ -1 +1 @@ -__version__ = "1.6.0" +__version__ = "1.6.1" diff --git a/src/CubeServer-common/cubeserver_common/_version.py b/src/CubeServer-common/cubeserver_common/_version.py index e4adfb8..f49459c 100644 --- a/src/CubeServer-common/cubeserver_common/_version.py +++ b/src/CubeServer-common/cubeserver_common/_version.py @@ -1 +1 @@ -__version__ = "1.6.0" +__version__ = "1.6.1" diff --git a/version.txt b/version.txt index dc1e644..9c6d629 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.0 +1.6.1