mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-09 18:59:36 +00:00
feat(torrents): add global open-file limit
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
isValidTorrentExcludeTrackerList,
|
||||
isValidTorrentTrackerList,
|
||||
normalizeTorrentEncryptionPolicy,
|
||||
normalizeTorrentMaxOpenFiles,
|
||||
normalizeTorrentPrioritizePiece,
|
||||
normalizeTorrentTrackerInterval,
|
||||
normalizeTorrentTrackerTimeout,
|
||||
@@ -126,6 +127,19 @@ describe('Torrent tracker timing validation', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Torrent open-file limit validation', () => {
|
||||
it('accepts bounded integer limits', () => {
|
||||
expect(normalizeTorrentMaxOpenFiles(1)).toBe(1);
|
||||
expect(normalizeTorrentMaxOpenFiles(4096)).toBe(4096);
|
||||
});
|
||||
|
||||
it('rejects zero, fractional, and oversized limits', () => {
|
||||
expect(normalizeTorrentMaxOpenFiles(0)).toBeUndefined();
|
||||
expect(normalizeTorrentMaxOpenFiles('1.5')).toBeUndefined();
|
||||
expect(normalizeTorrentMaxOpenFiles(4097)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('download connection resolution', () => {
|
||||
it('uses a clamped fallback for legacy rows without a saved value', () => {
|
||||
expect(resolveDownloadConnections(undefined, 8)).toBe(8);
|
||||
|
||||
@@ -67,6 +67,9 @@ export const normalizeTorrentEncryptionPolicy = (
|
||||
|
||||
export const MAX_TORRENT_TRACKER_TIMEOUT = 604800;
|
||||
export const MAX_TORRENT_TRACKER_INTERVAL = 604800;
|
||||
export const DEFAULT_TORRENT_MAX_OPEN_FILES = 100;
|
||||
export const MIN_TORRENT_MAX_OPEN_FILES = 1;
|
||||
export const MAX_TORRENT_MAX_OPEN_FILES = 4096;
|
||||
|
||||
const parseIntegerOption = (value: unknown): number | undefined => {
|
||||
if (typeof value === 'number') {
|
||||
@@ -93,6 +96,15 @@ export const normalizeTorrentTrackerInterval = (value: unknown): number | undefi
|
||||
: undefined;
|
||||
};
|
||||
|
||||
export const normalizeTorrentMaxOpenFiles = (value: unknown): number | undefined => {
|
||||
const parsed = parseIntegerOption(value);
|
||||
return parsed !== undefined
|
||||
&& parsed >= MIN_TORRENT_MAX_OPEN_FILES
|
||||
&& parsed <= MAX_TORRENT_MAX_OPEN_FILES
|
||||
? parsed
|
||||
: undefined;
|
||||
};
|
||||
|
||||
// Keep every filename component within the common cross-platform filesystem
|
||||
// limit. Count UTF-8 bytes because POSIX filesystems enforce bytes, while this
|
||||
// bound is also conservative for Windows filename components.
|
||||
|
||||
Reference in New Issue
Block a user