Repository navigation
feat: listen changes that take effect cleanly, keys shown in full, no global cap - #91
Merged
Merged
Conversation
fylorn
force-pushed
the
feat/listen-and-keys
branch
from
September 22, 2026 03:22
cb888ee to
7946640
Compare
… global cap Listening - The status now reports where the gateway is actually listening. It used to be the address recorded once at startup, so after a port change the UI kept showing the old one while traffic was already on the new one. `Event::ListenChanged` says when the listener moved or failed to. - A rebind binds the new address first and only then lets the old one drain. It used to wait for every in-flight request on the old listener to finish before binding the new one, leaving no listener at all for as long as a stream ran. - A rebind that cannot bind (port taken, interface without an address) keeps the current listener and reports why in `Status::listen_error`. It used to return an error that took the whole process down. - Binding a specific interface also listens on loopback. Adopted clients are pointed at 127.0.0.1, so "local network" used to cut every client on this machine off. Loopback peers are always let through the source allow-list for the same reason. - `PUT /listen` saves bind, port and allow-list together and tries to bind the new address before writing, so a config that cannot take effect is never written. Keys - `GET /keys` returns the key values in full; the keys page shows them with a copy button. `/overview` keeps them masked. Limits - `limits.max_concurrent` is gone. On a desktop gateway it only throttled the user's own parallel sessions; the per-upstream and per-key limits are what guard against a slow upstream or a runaway script. CONTROL_API_VERSION goes to 5. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ss, with their own codes A bind that names an interface can fail two ways that call for different actions: the name is wrong (fix the setting), or the interface has no address right now (plug the cable in). Both used to come through as one code carrying the English sentence, so the Chinese UI could only show it untranslated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The overview filled an empty allow-list with the private ranges when the gateway listened beyond this machine. A settings form that loads that list and saves it back would rewrite a config that said nothing into six lines of defaults, and could no longer tell the user that nothing was set. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fylorn
force-pushed
the
feat/listen-and-keys
branch
from
September 22, 2026 03:31
7946640 to
4850d0c
Compare
Merged
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.
Why
The desktop app is moving the listen settings into Settings behind an explicit Save button, giving keys their own page with the full value and a copy button, and dropping the global concurrency limit. Doing that honestly needed four things from core:
Status::gateway_addrwas recorded once at startup. After changing the port, the gateway was already serving on the new one while the sidebar still said the old one.serve_following_configawaited the old listener's graceful shutdown — i.e. every in-flight request, possibly a multi-minute stream — before binding the new address. In between, neither address accepted connections.en0bound only its address, and adopted clients are pointed at127.0.0.1.What changes
Listening (
tw-gateway/src/listen.rs)AppState::listening()is the live state: the bound addresses plus, when the last change could not be applied, the reason./statusreads it (gateway_addr, newlisten_error); the diagnostics bundle too.Event::ListenChanged { addr, error }is emitted when it changes.gw.listen.port_taken/addr_unavailable/denied/bind_failed/unresolved.relistenusesnotify_one, so a change that arrives while a rebind is in progress is not lost.GatewayListen::addrs()replacessocket_addr(): a concrete interface is listened on alongside127.0.0.1. The allow-list always admits loopback peers (they still need a key).PUT /listen(tw-control/src/listen.rs)Takes
{ bind, port, allow_from, base_version }, parsesbindwith the config file's own rules, resolves the interface, and tries to bind the new addresses before writing. A port in use is a 409 withgw.listen.port_takenand the file is untouched. Defaults are removed from the file rather than written out.An interface that cannot be resolved comes back as
gw.listen.no_such_nic(with the interfaces that do exist) orgw.listen.nic_no_addr, so the UI can say it in the user's language.ListenView.allow_fromis the list as written. It used to be the effective list, which fills an empty one with the private ranges — a form that loads it and saves it back would turn "nothing set" into six lines of defaults.Keys
GET /keysreturns key values in full./overviewkeeps its copy masked; upstream credentials are unaffected.Limits
limits.max_concurrentand the global semaphore are removed; per-upstream and per-key limits remain, as do the queue depth and timeout. A config that still containsmax_concurrentis rejected as an unknown field, in line with the project's no-compat policy.CONTROL_API_VERSION→ 5.Tests
tw-control/tests/listen.rs: writes and defaults, a taken port refused with nothing written, unknown interface / bad bind / port 0, stale version, the status following the listener after a save, and the overview reporting the allow-list as written.hotreload.rs: the port move now also checks the state and the event; the in-flight test now asserts the new port accepts while the old request is still running; new test for a taken port keeping the old listener and clearing the error once it is free.addrs(), loopback always allowed, and the gate without a global dimension.bind: en0listens on127.0.0.1:pand10.0.3.7:p, both answer;PUT /listento another port moves/statusimmediately; a taken port is refused.cargo fmt --check,clippy -D warnings,cargo test --workspaceandscripts/smoke.sh(51 passed) pass locally.🤖 Generated with Claude Code