Skip to content

Commit

Permalink
fix/binary messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 6, 2023
1 parent 6be256c commit f909c57
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hivemind_core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ 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)}")
else:
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:
Expand Down

0 comments on commit f909c57

Please sign in to comment.