Skip to content

Commit

Permalink
Fix: reuse peerId by info hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlika committed Feb 5, 2025
1 parent 22d48fb commit a3cb325
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/p2p-media-loader-core/src/p2p/tracker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function isSafariOrWkWebview() {
}

export class P2PTrackerClient {
private static readonly PEER_ID_BY_INFO_HASH = new Map<string, string>();

private readonly streamShortId: string;
private readonly client: TrackerClient;
private readonly _peers = new Map<string, PeerItem>();
Expand All @@ -52,7 +54,11 @@ export class P2PTrackerClient {
const streamHash = PeerUtil.getStreamHash(streamSwarmId);
this.streamShortId = LoggerUtils.getStreamString(stream);

const peerId = PeerUtil.generatePeerId(config.trackerClientVersionPrefix);
let peerId = P2PTrackerClient.PEER_ID_BY_INFO_HASH.get(streamHash);
if (!peerId) {
peerId = PeerUtil.generatePeerId(config.trackerClientVersionPrefix);
P2PTrackerClient.PEER_ID_BY_INFO_HASH.set(streamHash, peerId);
}

this.client = new TrackerClient({
infoHash: utf8ToUintArray(streamHash),
Expand Down

0 comments on commit a3cb325

Please sign in to comment.