Allow other clients to add a trailing zero at the end of a data
This commit is contained in:
parent
b6a27af219
commit
2797b9ddc5
|
@ -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)]
|
||||
|
|
Loading…
Reference in New Issue