From 2797b9ddc514495a7478473e99318e1f59b689ea Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 9 Jan 2021 20:36:32 +0100 Subject: [PATCH] Allow other clients to add a trailing zero at the end of a data --- squinnondation/messages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/squinnondation/messages.py b/squinnondation/messages.py index 7fd9541..7eb7eb5 100644 --- a/squinnondation/messages.py +++ b/squinnondation/messages.py @@ -283,6 +283,8 @@ class DataTLV(TLV): self.sender_id = int.from_bytes(raw_data[2:10], sys.byteorder) self.nonce = socket.ntohl(int.from_bytes(raw_data[10:14], sys.byteorder)) self.data = raw_data[14:len(self)] + if self.data[-1] == 0: + self.data = self[:-1] def marshal(self) -> bytes: return self.type.to_bytes(1, sys.byteorder) + \ @@ -302,7 +304,7 @@ class DataTLV(TLV): return if 0 in self.data: - user.send_packet(sender, Packet.construct(WarningTLV.construct( + user.send_packet(user.find_peer_by_id(self.sender_id) or sender, Packet.construct(WarningTLV.construct( f"The length of your DataTLV mismatches. You told me that the length is {len(self.data)} " f"while a zero was found at index {self.data.index(0)}."))) self.data = self.data[:self.data.index(0)]