mslxdff 0.1.31 → 0.1.32
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/bin/mslxdff.js +53 -0
- package/package.json +1 -1
package/bin/mslxdff.js
CHANGED
|
@@ -664,6 +664,49 @@ const groupSyncTimer = setInterval(() => {
|
|
|
664
664
|
}, groupSyncIntervalMs());
|
|
665
665
|
groupSyncTimer.unref();
|
|
666
666
|
|
|
667
|
+
// Auto-update: periodically check npm for a newer mslxdff and restart.
|
|
668
|
+
// Enable with MSLXDFF_AUTO_UPDATE=1 (hourly) or MSLXDFF_AUTO_UPDATE_MS=<ms>.
|
|
669
|
+
// Uses the same npm view/install path as `mslxdff -update`, but runs inside
|
|
670
|
+
// the daemon so no manual intervention is needed.
|
|
671
|
+
const autoUpdateMs = autoUpdateIntervalMs();
|
|
672
|
+
if (autoUpdateMs) {
|
|
673
|
+
console.log(`auto-update enabled: checking every ${Math.round(autoUpdateMs / 60000)}m`);
|
|
674
|
+
const autoUpdateTimer = setInterval(() => {
|
|
675
|
+
checkAndAutoUpdate().catch((err) => console.log(`auto-update check failed: ${errMsg(err)}`));
|
|
676
|
+
}, autoUpdateMs);
|
|
677
|
+
autoUpdateTimer.unref();
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
async function checkAndAutoUpdate() {
|
|
681
|
+
const info = await run(npmCmd(), ["view", "mslxdff", "version", "dist-tags.latest"]);
|
|
682
|
+
if (info.err) throw new Error(info.err.message);
|
|
683
|
+
const parts = (info.stdout || "").trim().split(/\s+/).filter(Boolean);
|
|
684
|
+
const latest = parts[parts.length - 1];
|
|
685
|
+
if (!latest || latest === VERSION) return;
|
|
686
|
+
// simple semver compare: skip if latest is not newer
|
|
687
|
+
if (compareSemver(latest, VERSION) <= 0) return;
|
|
688
|
+
console.log(`auto-update: v${VERSION} -> v${latest}, installing...`);
|
|
689
|
+
const up = await run(npmCmd(), ["install", "-g", `mslxdff@${latest}`]);
|
|
690
|
+
if (up.err) throw new Error(up.err.message);
|
|
691
|
+
console.log(`auto-update: installed v${latest}, restarting daemon...`);
|
|
692
|
+
try { stopDaemon(); } catch {}
|
|
693
|
+
// startDaemon re-reads VERSION from the newly installed package on next boot;
|
|
694
|
+
// for the current process we just respawn with the new code.
|
|
695
|
+
const newPid = startDaemon([]);
|
|
696
|
+
await waitForHealth(resolvePort(), 8000);
|
|
697
|
+
console.log(`auto-update: restarted as v${latest} (pid ${newPid})`);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function compareSemver(a, b) {
|
|
701
|
+
const pa = a.split(".").map((x) => parseInt(x, 10) || 0);
|
|
702
|
+
const pb = b.split(".").map((x) => parseInt(x, 10) || 0);
|
|
703
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
704
|
+
const av = pa[i] || 0, bv = pb[i] || 0;
|
|
705
|
+
if (av !== bv) return av - bv;
|
|
706
|
+
}
|
|
707
|
+
return 0;
|
|
708
|
+
}
|
|
709
|
+
|
|
667
710
|
function argValue(...names) {
|
|
668
711
|
for (let i = 0; i < args.length; i++) {
|
|
669
712
|
if (names.includes(args[i])) return args[i + 1];
|
|
@@ -712,6 +755,14 @@ function groupSyncIntervalMs() {
|
|
|
712
755
|
return Number.isInteger(n) && n > 0 ? n : 60_000;
|
|
713
756
|
}
|
|
714
757
|
|
|
758
|
+
function autoUpdateIntervalMs() {
|
|
759
|
+
const raw = process.env.MSLXDFF_AUTO_UPDATE_MS ?? process.env.MSLXDFF_AUTO_UPDATE;
|
|
760
|
+
if (raw === undefined || raw === null || raw === "") return 0;
|
|
761
|
+
if (raw === "1" || String(raw).toLowerCase() === "true") return 60 * 60 * 1000;
|
|
762
|
+
const n = Number(raw);
|
|
763
|
+
return Number.isInteger(n) && n > 0 ? n : 0;
|
|
764
|
+
}
|
|
765
|
+
|
|
715
766
|
function banWindowMs() {
|
|
716
767
|
const n = Number(process.env.MSLXDFF_BAN_WINDOW_MS);
|
|
717
768
|
return Number.isInteger(n) && n > 0 ? n : 48 * 60 * 60 * 1000;
|
|
@@ -778,6 +829,8 @@ Environment:
|
|
|
778
829
|
MSLXDFF_MAX_HOPS max peer-forwarding depth (default 3)
|
|
779
830
|
MSLXDFF_BAN_THRESHOLD failed joins before an ip is banned (default 5)
|
|
780
831
|
MSLXDFF_BAN_WINDOW_MS ban duration after too many failures (default 48h)
|
|
832
|
+
MSLXDFF_AUTO_UPDATE auto-update: 1/true=hourly, or ms interval (0=off)
|
|
833
|
+
MSLXDFF_AUTO_UPDATE_MS same as above, explicit ms (overrides AUTO_UPDATE)
|
|
781
834
|
`);
|
|
782
835
|
}
|
|
783
836
|
|