chore(release): 0.5.0 #13

Merged
pufereq merged 33 commits from release/0.5.0 into main 2026-02-28 22:48:50 +00:00
2 changed files with 409 additions and 303 deletions
Showing only changes of commit 5510e9dd08 - Show all commits

View File

@@ -164,11 +164,21 @@ class BackendServer:
try: try:
if mask & selectors.EVENT_READ: if mask & selectors.EVENT_READ:
self._receive_inbound(sock, client) self._receive_inbound(sock, client)
if client.inbound: if not client.inbound:
self._disconnect(client)
return
if client.mac_id is None: if client.mac_id is None:
# expect HELLO message # expect HELLO message
try: try:
msg = Message.from_bytes(client.inbound) msg = Message.from_bytes(client.inbound)
except Exception as e:
self.logger.error(
f"Failed to parse HELLO message from {client}: {e}"
)
self._disconnect(client)
return
if ( if (
msg.category == Category.CONTROL msg.category == Category.CONTROL
and msg.action == ControlAction.HELLO and msg.action == ControlAction.HELLO
@@ -180,30 +190,21 @@ class BackendServer:
and self.clients[client.mac_id].status and self.clients[client.mac_id].status
== "connected" == "connected"
): ):
old_client: Client = self.clients[ old_client: Client = self.clients[client.mac_id]
client.mac_id
]
self.logger.warning( self.logger.warning(
f"Client {client.mac_id} is already connected from {old_client.addr}, disconnecting old client..." f"Client {client.mac_id} is already connected from {old_client.addr}, disconnecting old client..."
) )
self._disconnect(old_client) self.send_close(old_client)
# self._disconnect(old_client)
# TODO: tell client not to reconnect # TODO: tell client not to reconnect
self.clients[client.mac_id] = client self.clients[client.mac_id] = client
self.logger.info( self.logger.info(f"[+] Registered new client {client}")
f"[+] Registered new client {client}"
)
else: else:
self.logger.error( self.logger.error(
f"Expected HELLO message from {client}, got {msg}" f"Expected HELLO message from {client}, got {msg}"
) )
self._disconnect(client) self._disconnect(client)
return return
except Exception as e:
self.logger.error(
f"Failed to parse HELLO message from {client}: {e}"
)
self._disconnect(client)
return
while b"\n" in client.inbound: while b"\n" in client.inbound:
line, client.inbound = client.inbound.split(b"\n", 1) line, client.inbound = client.inbound.split(b"\n", 1)
@@ -214,8 +215,7 @@ class BackendServer:
msg = Message.from_bytes(line) msg = Message.from_bytes(line)
self.logger.info(f"[.] Parsed message {msg.id}") self.logger.info(f"[.] Parsed message {msg.id}")
if msg.ack_required: if msg.ack_required:
self._send_ack(client, target_id=msg.id) self.send_ack(client, target_id=msg.id)
except Exception as e: except Exception as e:
self.logger.error( self.logger.error(
f"Failed to parse message from {client}: {e}" f"Failed to parse message from {client}: {e}"
@@ -223,11 +223,7 @@ class BackendServer:
self._disconnect(client) self._disconnect(client)
return return
else: if mask & selectors.EVENT_WRITE and client.outbound:
self._disconnect(client)
if mask & selectors.EVENT_WRITE:
if client.outbound:
self._send_outbound(sock, client) self._send_outbound(sock, client)
except ConnectionResetError as e: except ConnectionResetError as e: