Merge pull request 'chore(release): 0.7.0-dev.1' (#16) from release/0.7.0-dev.1 into main
Reviewed-on: #16
This commit is contained in:
@@ -8,11 +8,15 @@ import threading
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
|
||||
from judas_protocol.types import TelemetryAction
|
||||
import yaml
|
||||
from judas_protocol import Category, ControlAction, Message
|
||||
|
||||
from judas_server.backend.client import Client, ClientStatus
|
||||
from judas_server.backend.handler.hello_handler import HelloHandler
|
||||
from judas_server.backend.handler.telemetry.initial_handler import (
|
||||
InitialTelemetryHandler,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Callable
|
||||
@@ -67,11 +71,16 @@ class BackendServer:
|
||||
"""Initialize message handlers."""
|
||||
|
||||
hello_handler = HelloHandler(self)
|
||||
initial_telemetry_handler = InitialTelemetryHandler(self)
|
||||
|
||||
self.message_handlers[(Category.CONTROL, ControlAction.HELLO)] = (
|
||||
hello_handler.handle
|
||||
)
|
||||
|
||||
self.message_handlers[
|
||||
(Category.TELEMETRY, TelemetryAction.INITIAL)
|
||||
] = initial_telemetry_handler.handle
|
||||
|
||||
def _load_known_clients(self) -> dict[str, dict[str, str | float]]:
|
||||
"""Load the list of known clients from a YAML file and validate."""
|
||||
known_clients: dict[str, dict[str, str | float]] = {}
|
||||
@@ -108,6 +117,9 @@ class BackendServer:
|
||||
client.last_seen = float(
|
||||
known_clients[client_id].get("last_seen", 0.0)
|
||||
)
|
||||
client.initial_telemetry = known_clients[client_id].get( # type: ignore
|
||||
"initial_telemetry", None
|
||||
)
|
||||
self.clients[client_id] = client
|
||||
|
||||
except FileNotFoundError:
|
||||
@@ -399,4 +411,5 @@ class BackendServer:
|
||||
"addr": client.addr,
|
||||
"last_seen": client.last_seen,
|
||||
"status": client.status,
|
||||
"initial_telemetry": client.initial_telemetry,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ from __future__ import annotations
|
||||
import logging as lg
|
||||
import socket
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from judas_server.backend.client_status import ClientStatus
|
||||
|
||||
@@ -41,6 +42,8 @@ class Client:
|
||||
self.inbound: bytes = b""
|
||||
self.outbound: bytes = b""
|
||||
|
||||
self.initial_telemetry: dict[str, Any] | None = None
|
||||
|
||||
def __str__(self) -> str:
|
||||
if self.addr:
|
||||
return f"Client({self.id} ({self.addr[0]}:{self.addr[1]}))"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Initial telemetry handler."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from judas_protocol import Message
|
||||
|
||||
from judas_server.backend.handler.base_handler import BaseHandler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from judas_server.backend import BackendServer
|
||||
from judas_server.backend.client import Client
|
||||
|
||||
|
||||
class InitialTelemetryHandler(BaseHandler):
|
||||
"""Handles the initial telemetry message from a client."""
|
||||
|
||||
def __init__(self, backend_server: BackendServer) -> None:
|
||||
"""Initialize the handler."""
|
||||
super().__init__(backend_server)
|
||||
|
||||
def handle(self, client: Client, message: Message) -> None:
|
||||
"""Handle the initial telemetry message."""
|
||||
self.logger.debug(
|
||||
f"Handling initial telemetry message from {client}..."
|
||||
)
|
||||
|
||||
client.initial_telemetry = message.payload
|
||||
self.backend_server.known_clients[client.id]["initial_telemetry"] = ( # type: ignore
|
||||
message.payload
|
||||
)
|
||||
@@ -18,6 +18,10 @@
|
||||
<strong>Last Seen:</strong>
|
||||
<span id="last-seen">{{ client.last_seen }}</span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Initial:</strong>
|
||||
<pre>{{ client.initial_telemetry | tojson(indent=2) }}</pre>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
4
uv.lock
generated
4
uv.lock
generated
@@ -358,8 +358,8 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "judas-protocol"
|
||||
version = "0.8.0"
|
||||
source = { git = "https://gitea.pufereq.pl/judas/judas_protocol.git#a805ccf38edffadc1b8c8b276e60758c86516cd3" }
|
||||
version = "0.9.1"
|
||||
source = { git = "https://gitea.pufereq.pl/judas/judas_protocol.git#085c34f232f95313d66db48a7d17bc25c92a35ae" }
|
||||
|
||||
[[package]]
|
||||
name = "judas-server"
|
||||
|
||||
Reference in New Issue
Block a user