|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
|
|
|
import asyncio
|
|
|
import contextlib
|
|
|
+import json
|
|
|
import time
|
|
|
from dataclasses import dataclass, field
|
|
|
from typing import Dict
|
|
|
@@ -58,6 +59,9 @@ class RelayChannel:
|
|
|
return False
|
|
|
return lived >= 15 or self.frame_count > 20
|
|
|
|
|
|
+ def _should_log_auth(self) -> bool:
|
|
|
+ return self.authed_kind not in {"probe", "normal"}
|
|
|
+
|
|
|
async def run(self) -> None:
|
|
|
peer = self.writer.get_extra_info("peername")
|
|
|
authed = False
|
|
|
@@ -67,6 +71,8 @@ class RelayChannel:
|
|
|
return
|
|
|
try:
|
|
|
payload = decode_json(auth.payload) if auth.payload else {}
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ return
|
|
|
except Exception:
|
|
|
return
|
|
|
if payload.get("token") != self.token:
|
|
|
@@ -74,6 +80,8 @@ class RelayChannel:
|
|
|
authed = True
|
|
|
self.authed_at = time.monotonic()
|
|
|
self.authed_kind = payload.get("purpose", "normal")
|
|
|
+ if self._should_log_auth():
|
|
|
+ print(f"[relay] auth ok peer={peer} kind={self.authed_kind}")
|
|
|
ack_payload = {"status": "ok", "kind": self.authed_kind}
|
|
|
await self.safe_send(Frame(AUTH, 0, 0, 0, STATUS_OK, encode_json(ack_payload)))
|
|
|
while True:
|