Skip to content

Commit 1391562

Browse files
sirtimidclaude
andcommitted
refactor(transport): move rate limiter constants to constants.ts
Move DEFAULT_MESSAGE_RATE_LIMIT, DEFAULT_MESSAGE_RATE_WINDOW_MS, DEFAULT_CONNECTION_RATE_LIMIT, and DEFAULT_CONNECTION_RATE_WINDOW_MS to constants.ts for consistency with other default constants. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 16a6277 commit 1391562

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

packages/ocap-kernel/src/remotes/platform/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ export const DEFAULT_WRITE_TIMEOUT_MS = 10_000;
1515

1616
/** SCTP user initiated abort code (RFC 4960) */
1717
export const SCTP_USER_INITIATED_ABORT = 12;
18+
19+
/** Default message rate limit: 100 messages per second per peer */
20+
export const DEFAULT_MESSAGE_RATE_LIMIT = 100;
21+
22+
/** Default message rate window in milliseconds (1 second) */
23+
export const DEFAULT_MESSAGE_RATE_WINDOW_MS = 1000;
24+
25+
/** Default connection attempt rate limit: 10 attempts per minute per peer */
26+
export const DEFAULT_CONNECTION_RATE_LIMIT = 10;
27+
28+
/** Default connection rate window in milliseconds (1 minute) */
29+
export const DEFAULT_CONNECTION_RATE_WINDOW_MS = 60_000;

packages/ocap-kernel/src/remotes/platform/rate-limiter.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { ResourceLimitError } from '@metamask/kernel-errors';
22
import { describe, it, expect, beforeEach } from 'vitest';
33

4+
import {
5+
DEFAULT_CONNECTION_RATE_LIMIT,
6+
DEFAULT_CONNECTION_RATE_WINDOW_MS,
7+
DEFAULT_MESSAGE_RATE_LIMIT,
8+
DEFAULT_MESSAGE_RATE_WINDOW_MS,
9+
} from './constants.ts';
410
import {
511
SlidingWindowRateLimiter,
612
makeMessageRateLimiter,
713
makeConnectionRateLimiter,
8-
DEFAULT_MESSAGE_RATE_LIMIT,
9-
DEFAULT_MESSAGE_RATE_WINDOW_MS,
10-
DEFAULT_CONNECTION_RATE_LIMIT,
11-
DEFAULT_CONNECTION_RATE_WINDOW_MS,
1214
} from './rate-limiter.ts';
1315

1416
describe('SlidingWindowRateLimiter', () => {

packages/ocap-kernel/src/remotes/platform/rate-limiter.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { ResourceLimitError } from '@metamask/kernel-errors';
22

3-
/** Default message rate limit: 100 messages per second per peer */
4-
export const DEFAULT_MESSAGE_RATE_LIMIT = 100;
5-
6-
/** Default message rate window in milliseconds (1 second) */
7-
export const DEFAULT_MESSAGE_RATE_WINDOW_MS = 1000;
8-
9-
/** Default connection attempt rate limit: 10 attempts per minute per peer */
10-
export const DEFAULT_CONNECTION_RATE_LIMIT = 10;
11-
12-
/** Default connection rate window in milliseconds (1 minute) */
13-
export const DEFAULT_CONNECTION_RATE_WINDOW_MS = 60_000;
3+
import {
4+
DEFAULT_CONNECTION_RATE_LIMIT,
5+
DEFAULT_CONNECTION_RATE_WINDOW_MS,
6+
DEFAULT_MESSAGE_RATE_LIMIT,
7+
DEFAULT_MESSAGE_RATE_WINDOW_MS,
8+
} from './constants.ts';
149

1510
/**
1611
* A sliding window rate limiter that tracks event counts per key within a time window.

packages/ocap-kernel/src/remotes/platform/transport.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { makeErrorLogger, writeWithTimeout } from './channel-utils.ts';
77
import { ConnectionFactory } from './connection-factory.ts';
88
import {
99
DEFAULT_CLEANUP_INTERVAL_MS,
10+
DEFAULT_CONNECTION_RATE_LIMIT,
1011
DEFAULT_MAX_CONCURRENT_CONNECTIONS,
1112
DEFAULT_MAX_MESSAGE_SIZE_BYTES,
13+
DEFAULT_MESSAGE_RATE_LIMIT,
14+
DEFAULT_MESSAGE_RATE_WINDOW_MS,
1215
DEFAULT_STALE_PEER_TIMEOUT_MS,
1316
DEFAULT_WRITE_TIMEOUT_MS,
1417
SCTP_USER_INITIATED_ABORT,
1518
} from './constants.ts';
1619
import { PeerStateManager } from './peer-state-manager.ts';
1720
import {
18-
DEFAULT_CONNECTION_RATE_LIMIT,
19-
DEFAULT_MESSAGE_RATE_LIMIT,
20-
DEFAULT_MESSAGE_RATE_WINDOW_MS,
2121
makeConnectionRateLimiter,
2222
makeMessageRateLimiter,
2323
} from './rate-limiter.ts';

0 commit comments

Comments
 (0)