From 399fc6f21ffdba2f537a46d164182c05b1a576a0 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Fri, 11 Aug 2023 20:30:50 +0300 Subject: [PATCH] Improve structure.Object: - use shared.stream instead of hardcoded 1; - reuse pow_initial_hash() in is_valid(). --- minode/structure.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/minode/structure.py b/minode/structure.py index d2352fa..9f43f2a 100644 --- a/minode/structure.py +++ b/minode/structure.py @@ -112,18 +112,16 @@ class Object(): 'Invalid object %s, reason: payload is too long', base64.b16encode(self.vector).decode()) return False - if self.stream_number != 1: + if self.stream_number != shared.stream: logging.warning( - 'Invalid object %s, reason: not in stream 1', - base64.b16encode(self.vector).decode()) + 'Invalid object %s, reason: not in stream %i', + base64.b16encode(self.vector).decode(), shared.stream) return False - data = self.to_bytes()[8:] - # length = len(data) + 8 + shared.payload_length_extra_bytes - # dt = max(self.expires_time - time.time(), 0) - h = hashlib.sha512(data).digest() + pow_value = int.from_bytes( hashlib.sha512(hashlib.sha512( - self.nonce + h).digest()).digest()[:8], 'big') + self.nonce + self.pow_initial_hash() + ).digest()).digest()[:8], 'big') target = self.pow_target() if target < pow_value: logging.warning(