Skip to content

Commit

Permalink
add site_id
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 12, 2023
1 parent 2f9e55d commit 64b4f4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion hivemind_bus_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, key, password=None, crypto_key=None, host='127.0.0.1', port=5

super().__init__(host=host, port=port, ssl=ssl, emitter=EventEmitter())

def connect(self, bus=FakeBus(), identity=None, protocol=None):
def connect(self, bus=FakeBus(), identity=None, protocol=None, site_id=None):
from hivemind_bus_client.protocol import HiveMindSlaveProtocol
from hivemind_bus_client.identity import NodeIdentity
ident = identity or NodeIdentity()
Expand All @@ -110,9 +110,13 @@ def connect(self, bus=FakeBus(), identity=None, protocol=None):
LOG.debug("Initializing HiveMindSlaveProtocol")
self.protocol = HiveMindSlaveProtocol(self,
shared_bus=self.share_bus,
site_id=site_id or "unknown",
identity=ident)
else:
self.protocol = protocol
if site_id is not None:
self.protocol.site_id = site_id

LOG.info("Connecting to Hivemind")
self.run_in_thread()
self.protocol.bind(bus)
Expand Down
7 changes: 5 additions & 2 deletions hivemind_bus_client/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class HiveMindSlaveProtocol:
mpubkey: str = "" # asc public PGP key from master
shared_bus: bool = False
binarize: bool = False
site_id: str = "unknown"

def bind(self, bus: Optional[MessageBusClient] = None):
if self.identity is None:
Expand Down Expand Up @@ -141,10 +142,12 @@ def start_handshake(self,):
if self.pswd_handshake is not None:
envelope = self.pswd_handshake.generate_handshake()
msg = HiveMessage(HiveMessageType.HANDSHAKE, {"envelope": envelope,
"binarize": self.binarize})
"binarize": self.binarize,
"site_id": self.site_id})
else:
msg = HiveMessage(HiveMessageType.HANDSHAKE, {"pubkey": self.handshake.pubkey,
"binarize": self.binarize})
"binarize": self.binarize,
"site_id": self.site_id})
self.hm.emit(msg)

def receive_handshake(self, envelope):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ovos-bus-client
ovos_utils
ovos_utils>=0.0.6a5
pycryptodomex
bitstring

0 comments on commit 64b4f4d

Please sign in to comment.