createChatWsUnauthenticatedPeerLimit (v2/unauthenticated-peers.ts)

airi · server/apps/api/src/routes/chat-ws/v2/unauthenticated-peers.ts · typescript · MIT
auth, tag:embed-classified

Creates a limiter for unauthenticated WebSocket peers, managing concurrent connection slots.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
export interface ChatWsUnauthenticatedPeerLimit {
  /** Reserves an unauthenticated connection slot when capacity remains. */
  tryAcquire: () => boolean
  /** Releases a previously reserved unauthenticated connection slot. */
  release: () => void
}

/**
 * Limits concurrent peers that have upgraded but have not authenticated yet.
 *
 * One instance owns only its local sockets, so the count protects the memory,
 * timer, and Eventa-context capacity of that process. Releasing more than once
 * is safe because close and error events can both arrive for one peer.
 */
export function createChatWsUnauthenticatedPeerLimit(maximumConnecti

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key