Skip to content

Commit

Permalink
Ignore common prefixes of tracker domains
Browse files Browse the repository at this point in the history
Issue #51
  • Loading branch information
qu1ck committed Jul 25, 2023
1 parent ed0c1d4 commit d9384e3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/rpc/torrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ function getTrackerStatus(torrent: TorrentBase): string {
return getTrackerAnnounceState(trackers[0]);
}

const portRe = /:\d+$/;
const prefixRe = /^(tracker\d*|bt\d*)\.[^.]+\.[^.]+$/;

function getTorrentMainTracker(t: TorrentBase): string {
if (t.trackerStats.length === 0) return "<No trackers>";
const host = t.trackerStats[0].host as string;
const portMatch = /:\d+$/.exec(host);
if (portMatch != null) return host.substring(0, portMatch.index);
let host = t.trackerStats[0].host as string;
const portMatch = portRe.exec(host);
if (portMatch != null) host = host.substring(0, portMatch.index);
const prefixMatch = prefixRe.exec(host);
if (prefixMatch != null) host = host.substring(prefixMatch[1].length + 1);
return host;
}

Expand Down

0 comments on commit d9384e3

Please sign in to comment.