mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-19 23:52:16 +00:00
feat(torrents): add global open-file limit
This commit is contained in:
@@ -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