@torrent-tv/proxy 2.87.3 → 2.87.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2161 -2153
- package/package.json +50 -50
- package/routes/api/sources/post.js +1 -1
- package/routes/api/sources/warm/post.js +217 -181
- package/server.js +721 -720
- package/services/media/playback-planner.js +856 -848
- package/services/torrent/torrent-pool.js +2675 -2635
- package/services/torrent/worker/client.js +765 -760
- package/services/torrent/worker/pool-adapter.js +365 -350
- package/services/torrent/worker/protocol.js +184 -182
- package/services/torrent/worker/worker.js +1129 -1116
- package/store/source-registry.js +7 -9
- package/test/source-registry.test.js +18 -0
package/store/source-registry.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file In-memory registry of torrent sources.
|
|
3
3
|
*
|
|
4
|
-
* Sources are stored under
|
|
4
|
+
* Sources are stored under the torrent infohash, independent of magnet URI
|
|
5
|
+
* names or tracker lists.
|
|
5
6
|
* The registry is bounded: when `maxSources` is exceeded, the oldest entries
|
|
6
7
|
* are evicted to keep memory usage predictable.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
import
|
|
10
|
+
import { deriveSourceKey } from "../services/torrent/torrent-source-key.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @typedef {Object} SourceRecord
|
|
@@ -20,7 +21,7 @@ import crypto from "node:crypto";
|
|
|
20
21
|
*
|
|
21
22
|
* @param {number} [maxSources=200] - Maximum number of entries to retain.
|
|
22
23
|
* @returns {{
|
|
23
|
-
* upsert: (sourceType: string, source: string) => string
|
|
24
|
+
* upsert: (sourceType: string, source: string) => Promise<string>,
|
|
24
25
|
* get: (sourceKey: string) => SourceRecord | null
|
|
25
26
|
* }}
|
|
26
27
|
*/
|
|
@@ -35,13 +36,10 @@ export function createSourceRegistry(maxSources = 200) {
|
|
|
35
36
|
*
|
|
36
37
|
* @param {string} sourceType
|
|
37
38
|
* @param {string} source
|
|
38
|
-
* @returns {string}
|
|
39
|
+
* @returns {Promise<string>} Canonical `torrent:<infohash>` key.
|
|
39
40
|
*/
|
|
40
|
-
upsert(sourceType, source) {
|
|
41
|
-
const sourceKey =
|
|
42
|
-
.createHash("sha1")
|
|
43
|
-
.update(`${sourceType}:${source}`)
|
|
44
|
-
.digest("hex");
|
|
41
|
+
async upsert(sourceType, source) {
|
|
42
|
+
const sourceKey = await deriveSourceKey(sourceType, source);
|
|
45
43
|
|
|
46
44
|
sources.set(sourceKey, {
|
|
47
45
|
sourceType,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createSourceRegistry } from "../store/source-registry.js";
|
|
4
|
+
|
|
5
|
+
const infoHash = "0123456789abcdef0123456789abcdef01234567";
|
|
6
|
+
|
|
7
|
+
test("magnet links for one torrent share a source key", async () => {
|
|
8
|
+
const registry = createSourceRegistry();
|
|
9
|
+
const first = `magnet:?xt=urn:btih:${infoHash}&dn=First+name&tr=udp%3A%2F%2Ftracker.one%3A80`;
|
|
10
|
+
const second = `magnet:?xt=urn:btih:${infoHash}&dn=Different+name&tr=udp%3A%2F%2Ftracker.two%3A80`;
|
|
11
|
+
|
|
12
|
+
const firstKey = await registry.upsert("magnet", first);
|
|
13
|
+
const secondKey = await registry.upsert("magnet", second);
|
|
14
|
+
|
|
15
|
+
assert.equal(firstKey, `torrent:${infoHash}`);
|
|
16
|
+
assert.equal(secondKey, firstKey);
|
|
17
|
+
assert.equal(registry.get(firstKey)?.source, second);
|
|
18
|
+
});
|