@torrent-tv/proxy 2.107.70 → 2.107.72
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/package.json +3 -2
- package/scripts/install-native.sh +128 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torrent-tv/proxy",
|
|
3
|
-
"version": "2.107.
|
|
3
|
+
"version": "2.107.72",
|
|
4
4
|
"description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"services/",
|
|
25
25
|
"store/",
|
|
26
26
|
"utils/",
|
|
27
|
-
"server.js"
|
|
27
|
+
"server.js",
|
|
28
|
+
"scripts/install-native.sh"
|
|
28
29
|
],
|
|
29
30
|
"scripts": {
|
|
30
31
|
"start": "node ./bin/cli.js",
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Builds and checks the proxy's two native modules in an installed proxy:
|
|
3
|
+
# node-datachannel (WebRTC) and utp-native (our fork, uTP to peers). Every
|
|
4
|
+
# image that installs the proxy runs this one script after its install with
|
|
5
|
+
# `--ignore-scripts` (torrent-tv/meta#302).
|
|
6
|
+
#
|
|
7
|
+
# sh scripts/install-native.sh <package dir>
|
|
8
|
+
#
|
|
9
|
+
# <package dir> holds the installed proxy: its package.json and node_modules/.
|
|
10
|
+
# INSTALL_NATIVE_RETRY_DELAY is the wait in seconds between node-datachannel
|
|
11
|
+
# attempts (default 10). npm and node are taken from PATH, and every npm call
|
|
12
|
+
# runs in the package directory, never with --global.
|
|
13
|
+
|
|
14
|
+
set -eu
|
|
15
|
+
|
|
16
|
+
usage() {
|
|
17
|
+
echo "usage: install-native.sh <package dir>" >&2
|
|
18
|
+
echo " <package dir> holds the installed proxy (package.json and node_modules/)" >&2
|
|
19
|
+
exit 2
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fatal() {
|
|
23
|
+
echo "FATAL: install-native: $*" >&2
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Prints a field of a JSON file, or `undefined` when it is absent.
|
|
28
|
+
# json_field <file> <key> [<key>...]
|
|
29
|
+
json_field() {
|
|
30
|
+
node -e '
|
|
31
|
+
const [file, ...keys] = process.argv.slice(1);
|
|
32
|
+
let value = JSON.parse(require("node:fs").readFileSync(file, "utf8"));
|
|
33
|
+
for (const key of keys) value = value === null || typeof value !== "object" ? undefined : value[key];
|
|
34
|
+
process.stdout.write(String(value));
|
|
35
|
+
' "$@"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[ "$#" -eq 1 ] || usage
|
|
39
|
+
[ -f "$1/package.json" ] || usage
|
|
40
|
+
cd "$1"
|
|
41
|
+
package_dir=$(pwd)
|
|
42
|
+
|
|
43
|
+
# 1. Node floor, as the package states it in engines.node.
|
|
44
|
+
engines=$(json_field package.json engines node)
|
|
45
|
+
case $engines in
|
|
46
|
+
">="*) floor=${engines#>=} ;;
|
|
47
|
+
*) floor= ;;
|
|
48
|
+
esac
|
|
49
|
+
case $floor in
|
|
50
|
+
"" | *[!0-9]*) fatal "engines.node must be \">=N\", found $engines" ;;
|
|
51
|
+
esac
|
|
52
|
+
version=$(node -p process.versions.node)
|
|
53
|
+
major=${version%%.*}
|
|
54
|
+
case $major in
|
|
55
|
+
"" | *[!0-9]*) fatal "cannot read the running Node version: $version" ;;
|
|
56
|
+
esac
|
|
57
|
+
if [ "$major" -lt "$floor" ]; then
|
|
58
|
+
fatal "this proxy requires Node $floor or newer; found v$version"
|
|
59
|
+
fi
|
|
60
|
+
echo "install-native: node v$version (floor $floor)"
|
|
61
|
+
|
|
62
|
+
# 2. node-datachannel fetches a prebuilt binary; one failed request ends the
|
|
63
|
+
# rebuild, so it is tried up to five times. Without the binary the proxy has no
|
|
64
|
+
# WebRTC.
|
|
65
|
+
delay=${INSTALL_NATIVE_RETRY_DELAY:-10}
|
|
66
|
+
attempt=1
|
|
67
|
+
while ! npm rebuild node-datachannel; do
|
|
68
|
+
if [ "$attempt" -ge 5 ]; then
|
|
69
|
+
break
|
|
70
|
+
fi
|
|
71
|
+
echo "install-native: node-datachannel attempt $attempt of 5 failed; retrying in ${delay}s" >&2
|
|
72
|
+
sleep "$delay"
|
|
73
|
+
attempt=$((attempt + 1))
|
|
74
|
+
done
|
|
75
|
+
binary_found=
|
|
76
|
+
for binary in node_modules/node-datachannel/build/Release/*.node; do
|
|
77
|
+
if [ -f "$binary" ]; then
|
|
78
|
+
binary_found=1
|
|
79
|
+
fi
|
|
80
|
+
done
|
|
81
|
+
[ -n "$binary_found" ] || fatal "node-datachannel has no native binary; the proxy would have no WebRTC"
|
|
82
|
+
|
|
83
|
+
# 3. The proxy pins our utp-native fork through overrides.
|
|
84
|
+
spec=$(json_field package.json overrides utp-native)
|
|
85
|
+
case $spec in
|
|
86
|
+
"npm:@torrent-tv/utp-native@"*) ;;
|
|
87
|
+
*) fatal "the proxy pins no utp-native build of ours: $spec" ;;
|
|
88
|
+
esac
|
|
89
|
+
echo "utp-native: the proxy pins $spec"
|
|
90
|
+
|
|
91
|
+
# 4. Ours at the top. A global install ignores overrides, so the top copy may
|
|
92
|
+
# be missing or foreign; after `npm ci` it is already ours.
|
|
93
|
+
top=
|
|
94
|
+
if [ -f node_modules/utp-native/package.json ]; then
|
|
95
|
+
top=$(json_field node_modules/utp-native/package.json name)
|
|
96
|
+
fi
|
|
97
|
+
if [ "$top" != "@torrent-tv/utp-native" ]; then
|
|
98
|
+
npm install --omit=dev --ignore-scripts --no-save --no-audit --no-fund "utp-native@$spec"
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
# 5. Nested copies are removed, so every require of utp-native reaches ours.
|
|
102
|
+
find node_modules -mindepth 3 -type d -name utp-native -prune -exec rm -rf {} +
|
|
103
|
+
|
|
104
|
+
# 6. Source build, best effort: without it peers are reached over TCP only.
|
|
105
|
+
if ! npm_config_build_from_source=true npm rebuild utp-native; then
|
|
106
|
+
echo "WARNING: utp-native build failed; peer connections stay TCP-only" >&2
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# 7. Provenance: every utp_native.node belongs to our package.
|
|
110
|
+
find node_modules -type d -name obj.target -prune -o \
|
|
111
|
+
-type f -path "*/build/Release/utp_native.node" -print |
|
|
112
|
+
while IFS= read -r binary; do
|
|
113
|
+
owner=$(dirname "$(dirname "$(dirname "$binary")")")
|
|
114
|
+
name=undefined
|
|
115
|
+
if [ -f "$owner/package.json" ]; then
|
|
116
|
+
name=$(json_field "$owner/package.json" name)
|
|
117
|
+
fi
|
|
118
|
+
if [ "$name" != "@torrent-tv/utp-native" ]; then
|
|
119
|
+
fatal "$package_dir/$binary is not our build"
|
|
120
|
+
fi
|
|
121
|
+
echo "utp-native: our build at $package_dir/$binary"
|
|
122
|
+
done
|
|
123
|
+
|
|
124
|
+
# 8. Clean-up: the intermediate build files are not shipped.
|
|
125
|
+
find node_modules -type d \( -path "*/build/Release/obj.target" -o -path "*/build/Release/.deps" \) \
|
|
126
|
+
-prune -exec rm -rf {} +
|
|
127
|
+
|
|
128
|
+
exit 0
|