feat(tunnel): free finished tunnels at once and wait out 429s on --remote

A tunnel closed with code 1000 is freed without the 60s grace, a shared: true API key counts tunnels per X-Client-Id, and --remote waits out Retry-After and a full tunnel cap with a countdown; responses carry X-RateLimit-* headers.
This commit is contained in:
imSp4rky
2026-11-09 15:43:33 -07:00
parent 4b6d15cc2a
commit b10fd2d3a4
13 changed files with 358 additions and 25 deletions
+12
View File
@@ -183,6 +183,18 @@ class ServerStats:
entry.window_used += 1
return None
def rate_limit_headers(self, key: str) -> Dict[str, str]:
"""The ``X-RateLimit-*`` headers for ``key``'s current window; none for an API key with no limit."""
limit = key_rate_limit(key)
if limit is None:
return {}
entry = self.key_stats(key)
return {
"X-RateLimit-Limit": str(limit),
"X-RateLimit-Remaining": str(max(0, limit - entry.window_used)),
"X-RateLimit-Reset": str(max(0, int(entry.window_start + RATE_LIMIT_WINDOW - time.time()))),
}
def to_dict(self) -> Dict[str, Any]:
return {
"version": __version__,