|
|
@@ -50,6 +50,7 @@ class RelayChannel:
|
|
|
closed: bool = False
|
|
|
send_lock: asyncio.Lock = field(default_factory=asyncio.Lock)
|
|
|
authed_at: float = 0.0
|
|
|
+ frame_count: int = 0
|
|
|
|
|
|
async def run(self) -> None:
|
|
|
peer = self.writer.get_extra_info("peername")
|
|
|
@@ -60,22 +61,22 @@ class RelayChannel:
|
|
|
raise PermissionError("invalid token")
|
|
|
authed = True
|
|
|
self.authed_at = time.monotonic()
|
|
|
- print(f"[relay] auth ok peer={peer}")
|
|
|
await self.safe_send(Frame(AUTH, 0, 0, 0, STATUS_OK, b"ok"))
|
|
|
while True:
|
|
|
frame = await read_frame(self.reader)
|
|
|
+ self.frame_count += 1
|
|
|
await self.handle(frame)
|
|
|
except asyncio.IncompleteReadError:
|
|
|
if authed:
|
|
|
lived = time.monotonic() - self.authed_at if self.authed_at else 0.0
|
|
|
- if lived >= 5:
|
|
|
+ if lived >= 5 or self.frame_count > 2:
|
|
|
print(f"[relay] disconnected peer={peer} lived={lived:.1f}s")
|
|
|
except asyncio.CancelledError:
|
|
|
pass
|
|
|
except Exception as exc:
|
|
|
if authed:
|
|
|
lived = time.monotonic() - self.authed_at if self.authed_at else 0.0
|
|
|
- if lived >= 5:
|
|
|
+ if lived >= 5 or self.frame_count > 2:
|
|
|
print(f"[relay] channel error peer={peer} lived={lived:.1f}s error={exc!r}")
|
|
|
finally:
|
|
|
await self.close()
|