Allow other clients to add a trailing zero at the end of a data

This commit is contained in:
Yohann D'ANELLO 2021-01-09 20:36:32 +01:00
parent b6a27af219
commit 2797b9ddc5
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 3 additions and 1 deletions

View File

@ -283,6 +283,8 @@ class DataTLV(TLV):
self.sender_id = int.from_bytes(raw_data[2:10], sys.byteorder) 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.nonce = socket.ntohl(int.from_bytes(raw_data[10:14], sys.byteorder))
self.data = raw_data[14:len(self)] self.data = raw_data[14:len(self)]
if self.data[-1] == 0:
self.data = self[:-1]
def marshal(self) -> bytes: def marshal(self) -> bytes:
return self.type.to_bytes(1, sys.byteorder) + \ return self.type.to_bytes(1, sys.byteorder) + \
@ -302,7 +304,7 @@ class DataTLV(TLV):
return return
if 0 in self.data: 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"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)}."))) f"while a zero was found at index {self.data.index(0)}.")))
self.data = self.data[:self.data.index(0)] self.data = self.data[:self.data.index(0)]