Skip to content

Commit

Permalink
fix/client_session_id_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Apr 22, 2024
1 parent 8e97e04 commit 893938c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
29 changes: 17 additions & 12 deletions hivemind_core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,19 @@ def handle_internal_mycroft(self, message: str):
if not isinstance(target_peers, list):
target_peers = [target_peers]

for peer, client in self.clients.items():
if peer in target_peers:
# forward internal messages to clients if they are the target
LOG.debug(f"{message.msg_type} - destination: {peer}")
message.context["source"] = "hive"
msg = HiveMessage(
HiveMessageType.BUS,
source_peer=peer,
target_peers=target_peers,
payload=message,
)
client.send(msg)
if target_peers:
for peer, client in self.clients.items():
if peer in target_peers:
# forward internal messages to clients if they are the target
LOG.debug(f"{message.msg_type} - destination: {peer}")
message.context["source"] = "hive"
msg = HiveMessage(
HiveMessageType.BUS,
source_peer=peer,
target_peers=target_peers,
payload=message,
)
client.send(msg)


@dataclass()
Expand Down Expand Up @@ -446,8 +447,12 @@ def handle_bus_message(
self, message: HiveMessage, client: HiveMindClientConnection
):
# update the session as received by the client
old = client.peer
client.sess = Session.from_message(message.payload)
LOG.debug(f"Client session updated: {client.sess.serialize()}")
if old != client.peer:
LOG.debug(f"Client session_id changed! new peer_id: {client.peer}")
self.clients[client.peer] = self.clients.pop(old)

self.handle_inject_mycroft_msg(message.payload, client)
if self.mycroft_bus_callback:
Expand Down
5 changes: 3 additions & 2 deletions hivemind_core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def open(self):
name=name,
ip=self.request.remote_ip,
socket=self,
sess=Session(),
sess=Session(session_id="default"), # will be re-assigned once client sends it's own
handshake=handshake,
loop=self.protocol.loop,
)
Expand Down Expand Up @@ -211,7 +211,8 @@ def __init__(
if bus:
self.bus = bus
else:
self.ovos_bus_address = ovos_bus_config.get("address") or "127.0.0.1"
ovos_bus_config = ovos_bus_config or Configuration().get("websocket", {})
self.ovos_bus_address = ovos_bus_config.get("host") or "127.0.0.1"
self.ovos_bus_port = ovos_bus_config.get("port") or 8181
self.bus = MessageBusClient(
host=self.ovos_bus_address,
Expand Down

0 comments on commit 893938c

Please sign in to comment.