From f909c57e315b5add111548d63a811ef757d1d7f8 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Wed, 6 Sep 2023 20:35:11 +0100 Subject: [PATCH] fix/binary messages --- hivemind_core/protocol.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hivemind_core/protocol.py b/hivemind_core/protocol.py index 6772c18..4d4d1bb 100644 --- a/hivemind_core/protocol.py +++ b/hivemind_core/protocol.py @@ -77,11 +77,13 @@ def send(self, message: HiveMessage): LOG.debug(f"sending to {self.peer}: {message}") payload = message.serialize() # json string + is_bin = False if self.crypto_key and message.msg_type not in [HiveMessageType.HANDSHAKE, HiveMessageType.HELLO]: if self.binarize: - payload = get_bitstring(message.msg_type, message.payload) + payload = get_bitstring(message.msg_type, message.payload).bytes payload = encrypt_bin(self.crypto_key, payload) + is_bin = True else: payload = encrypt_as_json(self.crypto_key, payload) # still a json string LOG.debug(f"encrypted payload: {len(payload)}") @@ -89,7 +91,7 @@ def send(self, message: HiveMessage): LOG.debug(f"sent unencrypted!") self.loop.install() - self.socket.write_message(payload) + self.socket.write_message(payload, is_bin) def decode(self, payload: str) -> HiveMessage: if self.crypto_key: