From 91d94f2f6fe0009e08df536fec1ec3680c7b5b73 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 10 Sep 2021 21:35:30 +0200 Subject: [PATCH] Fixed incorrect transfer size indications on single-packet request responses with msgpacked dictionaries as payloads. --- RNS/Link.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index a3e2957..4e56d82 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -525,13 +525,15 @@ class Link: identity_string = RNS.prettyhexrep(self.get_remote_identity()) if self.get_remote_identity() != None else "" RNS.log("Request "+RNS.prettyhexrep(request_id)+" from "+identity_string+" not allowed for: "+str(path), RNS.LOG_DEBUG) - def handle_response(self, request_id, response_data): + def handle_response(self, request_id, response_data, response_size, response_transfer_size): if self.status == Link.ACTIVE: remove = None for pending_request in self.pending_requests: if pending_request.request_id == request_id: remove = pending_request try: + pending_request.response_size = response_size + pending_request.response_transfer_size = response_transfer_size pending_request.response_received(response_data) except Exception as e: RNS.log("Error occurred while handling response. The contained exception was: "+str(e), RNS.LOG_ERROR) @@ -559,7 +561,7 @@ class Link: request_id = unpacked_response[0] response_data = unpacked_response[1] - self.handle_response(request_id, response_data) + self.handle_response(request_id, response_data, resource.total_size, resource.size) else: RNS.log("Incoming response resource failed with status: "+RNS.hexrep([resource.status]), RNS.LOG_DEBUG) for pending_request in self.pending_requests: @@ -623,7 +625,8 @@ class Link: unpacked_response = umsgpack.unpackb(packed_response) request_id = unpacked_response[0] response_data = unpacked_response[1] - self.handle_response(request_id, response_data) + transfer_size = len(umsgpack.packb(response_data))-2 + self.handle_response(request_id, response_data, transfer_size, transfer_size) except Exception as e: RNS.log("Error occurred while handling response. The contained exception was: "+str(e), RNS.LOG_ERROR) @@ -971,10 +974,6 @@ class RequestReceipt(): self.status = RequestReceipt.READY self.response_concluded_at = time.time() - if len(response) <= Link.MDU: - self.response_size = len(response) - self.response_transfer_size = len(response) - if self.packet_receipt != None: self.packet_receipt.status = RNS.PacketReceipt.DELIVERED self.packet_receipt.proved = True