add Remote Access utility (UPnP / NAT-PMP hole-punch)#560
Open
IrosTheBeggar wants to merge 1 commit intomasterfrom
Open
add Remote Access utility (UPnP / NAT-PMP hole-punch)#560IrosTheBeggar wants to merge 1 commit intomasterfrom
IrosTheBeggar wants to merge 1 commit intomasterfrom
Conversation
New admin feature that asks the user's router to open a port via UPnP (and optionally NAT-PMP) so mStream can be reached from outside the home LAN without manual router port forwarding. - Config: new `remoteAccess` Joi block alongside the existing (untouched) `rpn` options reserved for the future FRP-based fallback. - Runtime: `src/state/remote-access.js` owns the nat-api client, lease renewal timer, kill-queue cleanup, and a narrow uncaughtException guard that swallows only nat-api's known NAT-PMP crash path so a library bug can't take down the server. map/unmap calls are timeout-guarded to prevent hung HTTP responses. - API: `GET /api/v1/admin/remote-access` for status and a single `POST /api/v1/admin/remote-access/toggle` endpoint that branches on the `enabled` flag. Serialized via an in-flight guard (409 on concurrent toggles). Gated by the existing admin-auth middleware in `src/api/admin.js`. - Server integration: boot-time `remoteAccess.setup()` after listen(), and `reboot()` now tears down the mapping first so router state stays in sync across port / protocol changes. - UI: new "Remote Access" section in webapp/admin/ with an enable toggle, a single "Also try NAT-PMP (experimental)" checkbox, public-port and lease-seconds inputs, live status (public URL, lease countdown, last error), and a security notice. - Docs: OpenAPI spec updated with the new tag, paths, RemoteAccessStatus schema, and 403/409 responses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nat-apidep, no bundled binaries. The pre-existingrpn/FRP scaffolding is left untouched for a future reverse-tunnel fallback PR.nat-apilibrary's known NAT-PMP crash path with a narrowuncaughtExceptionguard and timeouts on every map/unmap call.What's in here
remoteAccessJoi block (src/state/config.js) alongside the untouchedrpnoptions.src/state/remote-access.jsowns the nat-api client, lease-renewal timer, kill-queue cleanup, crash guard, and pending-promise reject hooks so a mid-op library crash never leaves an HTTP handler hung.GET /api/v1/admin/remote-accessfor status,POST /api/v1/admin/remote-access/togglethat branches onenabled. In-flight guard returns 409 on concurrent toggles. Reuses the existing admin-auth middleware.remoteAccess.setup()afterserver.listen();reboot()now callsteardown()first so router state stays in sync when port / protocol changes.webapp/admin/with an enable toggle, a single "Also try NAT-PMP (experimental)" checkbox, public-port and lease-seconds inputs, live status (public URL, lease countdown, last error), and a security notice.RemoteAccessStatusschema, and 403/409 responses.Known limitations
nat-apilibrary can throw from inside its UDP 'message' handler on malformed datagrams. We catch it via a scopeduncaughtExceptionhandler and keep the server alive, but discourage the option by default.nat-apiitself is unmaintained (last publish ~7y). Fine for v1 alpha; worth swapping for@libp2p/upnp-nator a newer lib if we want to go GA.exitevent can't await async UDP traffic, so cleanup relies on the lease TTL (default 2h) if the shutdown isn't graceful.Test plan
lastErrorpopulates and the LAN-side server still works.POST /togglerequests → one gets 200, the other gets 409.npm run lintandnpm run docs:api:validateclean (baseline of ~55 pre-existing lint issues should be unchanged).🤖 Generated with Claude Code