openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 1.1 kB
JavaScript
import { t as pruneMapToMaxSize } from "./map-size-BBr20tbc.mjs";
//#region src/gateway/server/ws-connection/handshake-auth-log-limiter.ts
/** Per-key log limiter that reports suppressed auth attempts on the next emitted log. */
var HandshakeAuthLogLimiter = class {
constructor() {
this.entries = /* @__PURE__ */ new Map();
}
missingCredentialLogSuffix(e, t) {
if (e.authProvided !== "none" || e.reason !== "token_missing" && e.reason !== "password_missing") return "";
const n = [
e.reason,
e.remoteAddr ?? "?",
e.client ?? "?",
e.mode ?? "?",
e.authProvided
].join("|");
const r = t ?? Date.now();
const i = this.entries.get(n);
if (!i) {
pruneMapToMaxSize(this.entries, 255);
this.entries.set(n, {
lastLoggedAtMs: r,
suppressedSinceLastLog: 0
});
return "";
}
if (r - i.lastLoggedAtMs < 3e4) {
i.suppressedSinceLastLog += 1;
return;
}
const a = i.suppressedSinceLastLog;
i.lastLoggedAtMs = r;
i.suppressedSinceLastLog = 0;
return a > 0 ? ` suppressed=${a}` : "";
}
};
//#endregion
export { HandshakeAuthLogLimiter as t };