Compare commits
9 Commits
fcaa7dae70
...
0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c1aee6bba | ||
| 7a4e062c04 | |||
| ddb55dc462 | |||
|
38d663a501
|
|||
|
bc62dbed66
|
|||
|
a28c724145
|
|||
|
54d2ba0083
|
|||
|
5458281186
|
|||
|
99e94e2f5a
|
54
CHANGELOG.md
54
CHANGELOG.md
@@ -2,6 +2,60 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.3.0] - 2025-11-30
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- [`431d8bb`](https://gitea.pufereq.pl/judas/judas_client/commit/431d8bb3bb5171a4d12ea306bfc767776bf6fb2a) **__main__.py**: fix wrong import
|
||||
- [`a00668e`](https://gitea.pufereq.pl/judas/judas_client/commit/a00668ecf3e99cf0453a7c333de4f6ab57cbcac3) **client.py**: fix wrong import
|
||||
- [`b756270`](https://gitea.pufereq.pl/judas/judas_client/commit/b7562703ddc82456859cb72da59e74b4bddf2dc9) **connector.py**: handle multiple messages in one packet
|
||||
|
||||
### Documentation
|
||||
|
||||
- [`3a46ed1`](https://gitea.pufereq.pl/judas/judas_client/commit/3a46ed197a1e700cf4cd66ec3accd96431873772) **connector.py**: add docstrings
|
||||
|
||||
### Features
|
||||
|
||||
- [`bc62dbe`](https://gitea.pufereq.pl/judas/judas_client/commit/bc62dbed66b08990a9aca790a831b07d8b5afcdb) **connector.py**: handle `self.selector.unregister` exceptions in `Connector.close()`
|
||||
- [`54d2ba0`](https://gitea.pufereq.pl/judas/judas_client/commit/54d2ba0083194ba2d6ea2df07372050f03d8182f) **connector.py**: add `pending_acks` and handle inbound/outbound ACKs
|
||||
- [`5458281`](https://gitea.pufereq.pl/judas/judas_client/commit/54582811864da1df0526763ef74b79544c695d01) **connector.py**: add `Connector.send()` method
|
||||
- [`99e94e2`](https://gitea.pufereq.pl/judas/judas_client/commit/99e94e2f5a3e89396e0a1140665edc1ba48cb0f2) **connector.py**: add `Connector.running` attribute
|
||||
- [`b887525`](https://gitea.pufereq.pl/judas/judas_client/commit/b887525cf1f6295b41c92dc8415d73c70b51a667) **__init__.py**: import `Client` and `Connector`
|
||||
- [`5261ad8`](https://gitea.pufereq.pl/judas/judas_client/commit/5261ad8e9fe6a07033395e6936713b48c29ae30c) **connector.py**: call `on_message()` on receive
|
||||
- [`3c86a5f`](https://gitea.pufereq.pl/judas/judas_client/commit/3c86a5fefd04ae03cc1503aa552cb3b5e846017b) **connector.py**: add `on_message` handler function argument to init
|
||||
- [`cc1145a`](https://gitea.pufereq.pl/judas/judas_client/commit/cc1145a4acb9b96e75e327d0060706f5f7f871ac) **connector.py**: get mac address from init argument
|
||||
- [`21bc86f`](https://gitea.pufereq.pl/judas/judas_client/commit/21bc86fa8aab7e2fae1b966ee8b831187e7e24e2) **client.py**: add `Client` class
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- [`3512608`](https://gitea.pufereq.pl/judas/judas_client/commit/3512608dd19480499e7e03592db6af88c1866e65) **connector.py**: reduce loop interval to 0.1 s in `_loop()`
|
||||
- [`cf78a4b`](https://gitea.pufereq.pl/judas/judas_client/commit/cf78a4b05b356fda9d31d31002af69143f5121d4) **connector.py**: clarify debug message for connector loop
|
||||
|
||||
### Refactor
|
||||
|
||||
- [`53912ed`](https://gitea.pufereq.pl/judas/judas_client/commit/53912ed3394b0b1909f15976bd149b3a023c210c) **connector.py**: rewrite `Connector` to use selectors
|
||||
- [`b8333b6`](https://gitea.pufereq.pl/judas/judas_client/commit/b8333b64088916dbef6c965566b0c3e38741e634) **connector.py**: avoid recursion in `connect()`
|
||||
- [`7ce3285`](https://gitea.pufereq.pl/judas/judas_client/commit/7ce32855c49435f31b0c82c7690754ae668f8709) **__main__.py**: use `Client`
|
||||
- [`014c429`](https://gitea.pufereq.pl/judas/judas_client/commit/014c4296e0cd91f0920d83e2f0993ba87166a118) **connector.py**: remove unused `Connector._get_mac_address()` method
|
||||
- [`1182e08`](https://gitea.pufereq.pl/judas/judas_client/commit/1182e089bcd74c1811faac2d6514832ba037ab42) **connector.py**: make `connect_timeout` and `ack_timeout` keyword-only
|
||||
- [`35b3af3`](https://gitea.pufereq.pl/judas/judas_client/commit/35b3af31bef60fda7549d229fa818a2a5b607e7d) **connector.py**: fix typing of `Connector.ack_timeout`
|
||||
|
||||
### Revert
|
||||
|
||||
- [`9b077c8`](https://gitea.pufereq.pl/judas/judas_client/commit/9b077c8c4868e7ef020cb2b25203b04b3fb42554) "feat(__init__.py): import `Client` and `Connector`"
|
||||
|
||||
### Styling
|
||||
|
||||
- [`38d663a`](https://gitea.pufereq.pl/judas/judas_client/commit/38d663a50178523304df0c0eff0714aef5066c74) **connector.py**: add typing to variables
|
||||
- [`a28c724`](https://gitea.pufereq.pl/judas/judas_client/commit/a28c724145534982d56b2d4b47b429af9f7eb275) **connector.py**: add blank line
|
||||
|
||||
### Build
|
||||
|
||||
- [`fcaa7da`](https://gitea.pufereq.pl/judas/judas_client/commit/fcaa7dae70abe1139ac9e7f5d1d9e7947c0814e3) **uv.lock**: update judas_protocol to 0.5.0
|
||||
- [`00d1d86`](https://gitea.pufereq.pl/judas/judas_client/commit/00d1d869d59e4bf5014a0c2baa5c0d9e3cc0fef5) **uv.lock**: update judas_protocol to 0.4.3
|
||||
- [`8646388`](https://gitea.pufereq.pl/judas/judas_client/commit/8646388851c0276616610550326e81ea9974f579) **uv.lock**: update judas_protocol to 0.3.0
|
||||
- [`b9d0fd9`](https://gitea.pufereq.pl/judas/judas_client/commit/b9d0fd92a65bd88c5069fd5e5961b1b968ab7039) **uv.lock**: update judas_protocol to 0.2.0
|
||||
|
||||
## [0.2.0] - 2025-09-19
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
||||
|
||||
[project]
|
||||
name = "judas_client"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
description = "A client for judas, a remote PC fleet management system."
|
||||
readme = "README.md"
|
||||
authors = []
|
||||
|
||||
@@ -7,7 +7,7 @@ import socket
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
from judas_protocol import Message
|
||||
from judas_protocol import Category, ControlAction, Message
|
||||
|
||||
|
||||
class Connector:
|
||||
@@ -54,6 +54,10 @@ class Connector:
|
||||
self.inbound_buffer: bytes = b""
|
||||
self.outbound_buffer: bytes = b""
|
||||
|
||||
self.pending_acks: dict[str, tuple[Message, float]] = {}
|
||||
|
||||
self.running: bool = True
|
||||
|
||||
self.on_message: Callable[[Message], None] = on_message
|
||||
|
||||
def _send_outbound(self) -> None:
|
||||
@@ -64,6 +68,7 @@ class Connector:
|
||||
self.logger.debug(
|
||||
f"[>] Sent {sent} bytes: {self.outbound_buffer[:sent]!r}"
|
||||
)
|
||||
|
||||
self.outbound_buffer = self.outbound_buffer[sent:]
|
||||
except BlockingIOError:
|
||||
# OS buffer full, wait for next EVENT_WRITE
|
||||
@@ -87,17 +92,30 @@ class Connector:
|
||||
self.logger.error(f"[!] Socket error: {e}")
|
||||
self.reconnect()
|
||||
|
||||
def send(self, message: Message) -> None:
|
||||
"""Send a message to the server.
|
||||
|
||||
Args:
|
||||
message (Message): The message to send.
|
||||
"""
|
||||
self.logger.debug(f"[>] Queueing message to send: {message}")
|
||||
if message.ack_required:
|
||||
self.pending_acks[message.id] = (message, time.time())
|
||||
self.outbound_buffer += message.to_bytes()
|
||||
|
||||
def send_hello(self) -> None:
|
||||
"""Send a HELLO message to the server."""
|
||||
self.logger.debug("[*] Sending HELLO message...")
|
||||
hello_message: bytes = Message.hello(self.mac_address).to_bytes()
|
||||
self.outbound_buffer += hello_message
|
||||
self._send_outbound()
|
||||
hello_message: Message = Message.hello(self.mac_address)
|
||||
self.send(hello_message)
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close the connection and clean up resources."""
|
||||
self.logger.debug("[*] Closing connection...")
|
||||
self.selector.unregister(self.socket)
|
||||
try:
|
||||
self.selector.unregister(self.socket)
|
||||
except Exception as e:
|
||||
self.logger.error(f"[!] Error unregistering socket: {e}")
|
||||
self.socket.close()
|
||||
self.logger.debug("[.] Connection closed.")
|
||||
|
||||
@@ -141,7 +159,7 @@ class Connector:
|
||||
"""Run the main event loop."""
|
||||
self.connect()
|
||||
try:
|
||||
while True:
|
||||
while self.running:
|
||||
events = self.selector.select(timeout=1)
|
||||
for key, mask in events:
|
||||
if mask & selectors.EVENT_READ:
|
||||
@@ -155,8 +173,28 @@ class Connector:
|
||||
self.inbound_buffer.split(b"\n", 1)
|
||||
)
|
||||
try:
|
||||
message = Message.from_bytes(message_bytes)
|
||||
self.on_message(message)
|
||||
message: Message = Message.from_bytes(message_bytes)
|
||||
# handle incoming ACKs
|
||||
if (
|
||||
message.category == Category.CONTROL
|
||||
and message.action == ControlAction.ACK
|
||||
):
|
||||
if (
|
||||
message.payload.get("target_id")
|
||||
in self.pending_acks
|
||||
):
|
||||
target_id = message.payload["target_id"]
|
||||
self.logger.debug(
|
||||
f"[.] Received ACK for message ID {target_id}"
|
||||
)
|
||||
del self.pending_acks[target_id]
|
||||
else:
|
||||
self.on_message(message)
|
||||
|
||||
if message.ack_required:
|
||||
ack_message: Message = Message.ack(message.id)
|
||||
self.send(ack_message)
|
||||
self._send_outbound()
|
||||
except Exception as e:
|
||||
self.logger.error(f"[!] Failed to parse message: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user