torrent/src/core/tracker/ITracker.ts

34 lines
921 B
TypeScript

import type { AnnounceEvent, TrackerResponse } from "./TrackerResponse.js";
export interface AnnounceParams {
infoHash: Buffer;
peerId: Buffer;
port: number;
uploaded: number;
downloaded: number;
left: number;
event: AnnounceEvent;
/** HTTP User-Agent header — should match the spoofed client profile */
userAgent: string;
/** compact=1 for HTTP trackers */
compact?: boolean;
numWant?: number;
key?: string;
trackerId?: string;
}
export interface ScrapeResult {
seeders: number;
leechers: number;
completed: number;
}
export interface ITracker {
readonly url: string;
announce(params: AnnounceParams): Promise<TrackerResponse>;
/** Send stopped event and clean up resources */
stop(params: Omit<AnnounceParams, "event">): Promise<void>;
/** Fetch current seeder/leecher counts without announcing (optional) */
scrape?(infoHash: Buffer): Promise<ScrapeResult | null>;
}