chore(backend_server.py): remove redundant HELLO msg handling
This commit is contained in:
@@ -253,48 +253,6 @@ class BackendServer:
|
||||
self._disconnect(client)
|
||||
return
|
||||
|
||||
if client.id is None:
|
||||
# expect HELLO message
|
||||
try:
|
||||
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 (
|
||||
msg.category == Category.CONTROL
|
||||
and msg.action == ControlAction.HELLO
|
||||
and msg.payload.get("id") is not None
|
||||
):
|
||||
client.id = msg.payload["id"]
|
||||
if (
|
||||
client.id in self.clients
|
||||
and self.clients[client.id].status == "connected"
|
||||
):
|
||||
old_client: Client = self.clients[client.id]
|
||||
self.logger.warning(
|
||||
f"Client {client.id} is already connected from {old_client.addr}, disconnecting old client..."
|
||||
)
|
||||
self.send_close(old_client)
|
||||
|
||||
self.clients[client.id] = client
|
||||
self.known_clients[client.id] = {
|
||||
"last_seen": client.last_seen
|
||||
}
|
||||
self._save_known_clients()
|
||||
client.status = ClientStatus.ONLINE
|
||||
|
||||
self.logger.info(f"[+] Registered new client {client}")
|
||||
else:
|
||||
self.logger.error(
|
||||
f"Expected HELLO message from {client}, got {msg}"
|
||||
)
|
||||
self._disconnect(client)
|
||||
return
|
||||
|
||||
while b"\n" in client.inbound:
|
||||
line, client.inbound = client.inbound.split(b"\n", 1)
|
||||
self.logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user