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
11 changed files with 584 additions and 389 deletions
Showing only changes of commit a5e1ba88ae - Show all commits

View File

@@ -92,7 +92,7 @@ class BackendServer:
conn, addr = sock.accept()
self.logger.info(f"[+] Accepted connection from {addr}")
client = Client(mac_id=None, addr=addr, socket=conn)
client = Client(id=None, addr=addr, socket=conn)
events = selectors.EVENT_READ | selectors.EVENT_WRITE
self.selector.register(conn, events, data=client)
@@ -168,7 +168,7 @@ class BackendServer:
self._disconnect(client)
return
if client.mac_id is None:
if client.id is None:
# expect HELLO message
try:
msg = Message.from_bytes(client.inbound)
@@ -182,22 +182,21 @@ class BackendServer:
if (
msg.category == Category.CONTROL
and msg.action == ControlAction.HELLO
and msg.payload.get("mac") is not None
and msg.payload.get("id") is not None
):
client.mac_id = msg.payload["mac"]
client.id = msg.payload["id"]
if (
client.mac_id in self.clients
and self.clients[client.mac_id].status
== "connected"
client.id in self.clients
and self.clients[client.id].status == "connected"
):
old_client: Client = self.clients[client.mac_id]
old_client: Client = self.clients[client.id]
self.logger.warning(
f"Client {client.mac_id} is already connected from {old_client.addr}, disconnecting old client..."
f"Client {client.id} is already connected from {old_client.addr}, disconnecting old client..."
)
self.send_close(old_client)
# self._disconnect(old_client)
# TODO: tell client not to reconnect
self.clients[client.mac_id] = client
self.clients[client.id] = client
self.logger.info(f"[+] Registered new client {client}")
else:
self.logger.error(

View File

@@ -17,12 +17,12 @@ class Client:
"""Represents a client."""
def __init__(
self, mac_id: str | None, addr: tuple[str, int], socket: socket.socket
self, id: str | None, addr: tuple[str, int], socket: socket.socket
) -> None:
"""Initialize the client.
Args:
mac_id (str | None): The unique identifier for the client.
id (str | None): The unique identifier for the client.
Can be None if not yet assigned.
addr (tuple[str, int]): The (IP, port) address of the client.
socket (socket.socket): The socket object for communication.
@@ -32,7 +32,7 @@ class Client:
)
self.logger.debug(f"Initializing Client {addr}...")
self.id: str | None = mac_id
self.id: str | None = id
self.last_seen: float = 0.0 # unix timestanp of last inbound message
self.status: ClientStatus = ClientStatus.CONNECTED

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Details for client {{ client.id }}</title>
<title>Details for client {{ client.mac_id }}</title>
</head>
<body></body>
</html>