Skip to content

feat: web page port in Network, the next free one when taken; camex 4.1.2 (2.25.0) - #285

Merged
compot-dev merged 1 commit into
v2from
feat/web-port-284
Nov 18, 2026
Merged

compot-dev merged 1 commit into
v2from
feat/web-port-284

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #284.

Decided for all our Android apps (2026-11-18): the web page is on 8085 by default, the port is settable, and when it is taken the app takes the next free one and shows the real address. One app with a page and a camex tunnel runs on a device at a time; this keeps two from clashing when they do.

  • Network → Web page port (WebPort): 1024 to 65535, empty = 8085; checked on Save.
  • DebugServer: binds the set port or the next free one of ten (8085 … 8094), logs which and why; port() is the real one; a port change in Network rebinds at once. /stats.json addresses, the debug text and the dialog show the real port.
  • camex tunnel: web_port is the port the page really got. A start waits until the page has tried its port (so a taken 8085 does not mean a tunnel restart right after the app starts — such a restart in one process is what Android 5 handles worst); a running tunnel restarts when the port changes later.
  • bundles/camex → 53c3dd8 (4.1.2, Android library: the tunnel reaches other apps' servers (another app's page under this client's name) camex#187): from the tunnel the library lets in only the app's own web port, held by the app itself; anything else is refused, so the server shows an error rather than another app's page (seen on a TECNO KM4 with MicroSNANDer on 8085).
  • 2.25.0 (versionCode 61), CHANGELOG, README (three languages), docs/debug.md, docs/security.md, docs/testing.md.
  • tests/e2e.sh: adbd holds 8085 (adb reverse tcp:8085), Decoder restarts: the page is on 8086 through the tunnel (401 / 200 with the password, addresses say :8086), 8085 through the tunnel is refused. The camera check now also waits for the reader (with the 60 ms round trip the RTSP setup can end a few seconds after the session is created on Android 5).

Tests (local, Docker):

  • testDebugUnitTest lintDebug assembleDebug in compot/android:2026.10: pass (new WebPortTest; lint 13 warnings, as before).
  • TRANSPORT=TCP tests/e2e.sh 21 three times: 18 passed each; TRANSPORT=TCP tests/e2e.sh 34: 18 passed; tests/e2e.sh 34 (UDP): 17 passed. Before the start was made to wait, API 21 failed the taken-port check in 2 of 4 runs.

….1.2 (2.25.0)

The debug page listens on the port set in Network -> Web page port (default
8085, as before). When it is taken, for example by another of our apps on the
device, the server takes the next free one (up to nine on), logs which and
why, and /stats.json, the debug text and the dialog show the real port.

The camex tunnel is told the port the page really got: a start waits until
the page has tried its port (no restart right after the app's start), and a
running tunnel restarts when the port changes (Network, or taken later).

camex 4.1.2 (OpenIPC/camex#187): from the tunnel the library lets in only the
app's own web port held by the app itself; the server shows an error rather
than another app's page.

tests/e2e.sh: the port taken by adbd (adb reverse tcp:8085): the page is on
8086 through the tunnel, 8085 through the tunnel is refused; the camera check
waits for the reader, which takes longer with the round trip.

Closes #284
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Make the debug page port configurable with safe tunnel fallback

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Add a configurable debug-page port and use the next free port when it is taken.
• Show and announce the actual port, while preventing tunnel access to another app’s page.
• Add port-collision coverage and document the behavior for the 2.25.0 release.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 3 capabilities

  • 3 affected capabilities within one bounded functional scope: debug-and-camex-network-integration.
  • The tunnel is the same bounded Network integration that carries camera traffic and exposes the app page through camex; this is an end-to-end remote camera-access outcome, not a separate implementation hop.
  • This is a distinct user-visible operation from camera playback, but it belongs to the same bounded camex/debug-page integration because the tunnel is explicitly configured with the app's web port.
  • The HTTP listener, stats/UI URLs, and camex web-port announcement form one end-to-end debug-page capability across components; the propagation path shows the shared port contract rather than independent technical capabilities.
Behavioral complexity 🔴 High 🧩 Interacting branches, Concurrent ordering

  • Before: tunnel startup was a direct operation using the fixed debug port.
  • After: startup is coordinated with an asynchronously settling server and a process-wide pending callback.
  • New correctness condition: Network's current enabled state, activity lifecycle, server settlement, and tunnel start must agree at the moment the callback executes.
  • The changed Handler posting and pendingStart state introduce an ordering condition; this is not merely routine use of an existing helper.
Potential damage 🟡 Medium 🩹 Recoverable

  • The concrete failure is unintended tunnel activation, potentially causing remote camera/debug-page connectivity when the user selected Off.
  • Reverting the app code removes the race, but a currently running tunnel must be stopped; no persistent application-state corruption or irreversible external effect is established.
  • Remote debug data exposure is possible only while the unexpectedly active tunnel is reachable, and the exact camex gate behavior is unresolved.
  • Code rollback prevents future stale starts.
  • Immediate recovery requires stopping the running tunnel or restarting the app; no automatic repair invocation was established.
  • The debug page itself remains local-network available because it is intentionally ungated.
Assessed commit d4e4dda
Diagram

graph TD
  N["Network dialog"] --> W["WebPort settings"] --> D{"Port free?"}
  D -->|yes| S["DebugServer listener"] -->|settled port| T["camex tunnel"] --> R["Server nginx"]
  D -->|try next| D
  S --> A["Displayed addresses"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use an OS-assigned fallback port
  • ➕ Avoids exhausting a fixed range when nearby ports are occupied.
  • ➖ Produces less predictable local addresses and requires the tunnel and users to rely entirely on runtime port discovery.

Recommendation: Keep the configurable port with bounded, sequential fallback: it preserves a predictable default while handling collisions. Announcing the bound port and restricting tunnel access to the app-owned listener are important parts of that approach.

Files changed (16) +344 / -41

Enhancement (3) +228 / -22
DebugServer.javaBind the requested or next available web port +94/-16

Bind the requested or next available web port

• Replaces the fixed listener port with up to ten bind attempts, records the actual port, and supports rebinding after a setting change. Notifies NetworkPanel when a bind attempt settles.

android/app/src/main/java/com/openipc/decoder/DebugServer.java

NetworkPanel.javaConfigure the port and synchronize tunnel startup +65/-6

Configure the port and synchronize tunnel startup

• Adds a validated web-page port field and rebinds the server when it changes. Tunnel startup waits for the initial bind attempt, and a running tunnel restarts when the announced port changes.

android/app/src/main/java/com/openipc/decoder/NetworkPanel.java

WebPort.javaAdd persistent web-port settings and validation +69/-0

Add persistent web-port settings and validation

• Defines the default and fallback range, parses ports from 1024 through 65535, and persists the requested port. Empty input restores the 8085 default.

android/app/src/main/java/com/openipc/decoder/WebPort.java

Bug fix (1) +5 / -3
Decoder.javaReport the listener’s actual address +5/-3

Report the listener’s actual address

• Uses the server’s current port in debug-text URLs and the addresses reported through debug statistics.

android/app/src/main/java/com/openipc/decoder/Decoder.java

Tests (2) +82 / -1
WebPortTest.javaTest web-port parsing boundaries +41/-0

Test web-port parsing boundaries

• Covers empty defaults, accepted boundary values, and rejection of malformed or out-of-range ports.

android/app/src/test/java/com/openipc/decoder/WebPortTest.java

e2e.shExercise port fallback through the tunnel +41/-1

Exercise port fallback through the tunnel

• Occupies 8085 with adbd, restarts Decoder, verifies authenticated access and reported addresses on 8086, and checks that 8085 is refused through the tunnel. Also waits for an active camera reader before proceeding.

tests/e2e.sh

Documentation (8) +26 / -12
CHANGELOG.mdRecord the 2.25.0 port and tunnel changes +14/-0

Record the 2.25.0 port and tunnel changes

• Documents configurable port fallback, actual-port reporting, camex access restrictions, and collision coverage.

CHANGELOG.md

README.mdExplain configurable debug-page access +2/-2

Explain configurable debug-page access

• Updates the English overview and Network guidance for camex 4.1.2, port fallback, actual-port announcement, and tunnel restrictions.

README.md

README.ru.mdUpdate Russian Network guidance +2/-2

Update Russian Network guidance

• Describes the configurable port, collision fallback, actual tunnel port, and camex 4.1.2 behavior in Russian.

README.ru.md

README.zh-CN.mdUpdate Chinese Network guidance +2/-2

Update Chinese Network guidance

• Describes the configurable port, collision fallback, actual tunnel port, and camex 4.1.2 behavior in Simplified Chinese.

README.zh-CN.md

WebPassword.javaRemove the fixed-port reference +1/-1

Remove the fixed-port reference

• Adjusts the file header to describe the password without assuming port 8085.

android/app/src/main/java/com/openipc/decoder/WebPassword.java

debug.mdDocument debug-server port selection +3/-3

Document debug-server port selection

• Explains configuration, bounded collision fallback, actual-port reporting, retry behavior, and tunnel port updates.

docs/debug.md

security.mdClarify that the debug port can change +1/-1

Clarify that the debug port can change

• Updates the security description to include a port selected in Network.

docs/security.md

testing.mdDocument the expanded end-to-end checks +1/-1

Document the expanded end-to-end checks

• Updates test counts and describes the occupied-port and tunnel-access scenarios.

docs/testing.md

Other (2) +3 / -3
build.gradleBump the app to 2.25.0 +2/-2

Bump the app to 2.25.0

• Increments versionCode to 61 and versionName to 2.25.0.

android/app/build.gradle

camexAdvance the camex submodule to 4.1.2 +1/-1

Advance the camex submodule to 4.1.2

• Updates the pinned commit to the library version that restricts tunnel access to the app’s own web port.

bundles/camex

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Network can turn back on after being disabled 🐞 Bug ≡ Correctness
Description
webPortSettled() runs a deferred start() without checking whether Network is still on. If the
user saves Network as off before the debug server's first bind attempt finishes, that deferred start
can run after CamexTunnel.stop() and start the tunnel anyway.
Code

android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[R203-205]

+            Runnable r = pendingStart;
+            pendingStart = null;
+            if (r != null) r.run();
Evidence
start() stores a runnable while the server is unsettled; settlement executes it unconditionally,
whereas saving off stops the tunnel without clearing the runnable.

android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[219-240]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[397-402]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[200-206]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A deferred tunnel start can run after the user saves Network as off.
## Fix Focus Areas
- android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[200-206]
- android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[397-402]
## Recommended Fix
Cancel any pending start on the off path and check the current on setting before executing a deferred start.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. A saved port can leave the old page active 🐞 Bug ☼ Reliability
Description
rebind() returns when server is null, although acceptLoop() can already be opening a socket
for the previous setting before assigning that field. If a save falls between open(wanted) and
server = s, the loop accepts on the old port indefinitely because the requested close was lost.
Code

android/app/src/main/java/com/openipc/decoder/DebugServer.java[R154-157]

+    void rebind() {
+        ServerSocket s = server;
+        if (s == null) return;
+        port = 0;   // until the new one is open, port() is the one now set
Evidence
Saving changes the preference and invokes rebind(), but the socket is bound before it becomes
visible through server; no subsequent setting check occurs before the accept loop.

android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[396-399]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[153-176]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[191-223]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A port save during socket opening can leave the server bound to the previous port.
## Fix Focus Areas
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[153-163]
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[191-217]
## Recommended Fix
Track a rebind generation or synchronize socket publication with rebind requests; after publishing a socket, close and reopen it if the saved port changed during the bind.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. A new port waits after all ports fail 🐞 Bug ≡ Correctness
Description
rebind() does nothing when server is null, which is also its state after every candidate port
has failed to bind. If the user then saves an available port during the retry sleep, the server does
not try it until the ten-second delay expires.
Code

android/app/src/main/java/com/openipc/decoder/DebugServer.java[R154-156]

+    void rebind() {
+        ServerSocket s = server;
+        if (s == null) return;
Evidence
The failed-open branch leaves server null and reaches the fixed retry sleep; the Save handler
calls rebind(), whose null check supplies no wake-up.

android/app/src/main/java/com/openipc/decoder/DebugServer.java[153-156]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[191-202]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[232-238]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[396-399]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Saving an available port cannot interrupt the retry delay after all earlier candidates failed.
## Fix Focus Areas
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[153-163]
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[191-238]
## Recommended Fix
Signal the accept loop on every saved port change, including when no socket is open, and make its retry wait wake on that signal.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Debug text can show an obsolete address 🐞 Bug ≡ Correctness
Description
updateDebugUrls() reads the live port only when one of its existing UI callers runs; the new
port-settlement path does not refresh that text. In single-view mode, a fallback bind or Network
port change can therefore leave the displayed URL on the former port until stats are toggled or the
activity resumes.
Code

android/app/src/main/java/com/openipc/decoder/Decoder.java[R491-494]

+        int port = DebugServer.get().port();
       for (String ip : NetInfo.addresses()) {
           if (sb.length() > 0) sb.append('\n');
-            sb.append("http://").append(ip).append(':').append(DebugServer.PORT).append('/');
+            sb.append("http://").append(ip).append(':').append(port).append('/');
Evidence
The server changes its live port and notifies NetworkPanel, but the URL view has no settlement
callback; its periodic refresh runs only while quad or UDP view is active.

android/app/src/main/java/com/openipc/decoder/Decoder.java[484-497]
android/app/src/main/java/com/openipc/decoder/Decoder.java[1216-1243]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[203-215]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The debug text is not refreshed when the server binds a different port.
## Fix Focus Areas
- android/app/src/main/java/com/openipc/decoder/Decoder.java[484-497]
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[203-215]
## Recommended Fix
Notify the active activity on the main thread when the server's bound port changes, and call its URL refresh method.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View review recommended (1)
5. Saving a taken port restarts the tunnel twice 🐞 Bug ☼ Reliability
Description
DebugServer.rebind() clears the live port without clearing settled, so a Save-triggered
NetworkPanel.start() can pass the requested port to Camex before the replacement socket binds. If
that port is taken, settlement on the next free port can trigger a second tunnel start, or the
correction can be skipped if settlement occurs before CamexTunnel.running() becomes true; which
path occurs depends on the timing of the accept thread and tunnel startup.
Code

android/app/src/main/java/com/openipc/decoder/DebugServer.java[R154-157]

+    void rebind() {
+        ServerSocket s = server;
+        if (s == null) return;
+        port = 0;   // until the new one is open, port() is the one now set
Evidence
After Save changes the configured port, rebind() sets the live port to zero and closes the socket,
but settled remains true. The immediate connect(a) therefore reaches load(), where
DebugServer.port() returns the configured port and records it as announcedPort. The accept loop
can subsequently open the next free port and call webPortSettled(): a differing port triggers
another start if Camex is running, while a callback before Camex reaches its running state returns
without arranging that correction.

android/app/src/main/java/com/openipc/decoder/DebugServer.java[142-163]
android/app/src/main/java/com/openipc/decoder/DebugServer.java[224-231]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[200-241]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[396-403]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[396-402]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[91-94]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[207-215]
android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[227-240]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A Save-triggered start can supply Camex with the requested web port before `DebugServer` has bound a replacement socket. If the requested port is taken, the later port settlement can cause a second start or be missed while the tunnel is still starting.
## Fix Focus Areas
- android/app/src/main/java/com/openipc/decoder/DebugServer.java[154-163]
- android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[200-216]
- android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[219-240]
- android/app/src/main/java/com/openipc/decoder/NetworkPanel.java[396-402]
## Recommended Fix
Set `settled = false` in `rebind()` before closing the socket, including when `server == null`, so a start during the retry sleep also waits. Coordinate the Save-triggered start with the accept loop’s settlement callback so Camex receives the port actually bound, then reconcile the port supplied after startup rather than discarding a change solely because `CamexTunnel.running()` is not yet true.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev

Copy link
Copy Markdown
Collaborator Author

Qodo review on d4e4dda — all five are real; fixed in the next PR (the brass PR for #286, which rewrites the same code), not here, so this green head merges:

  1. Network can turn back on — a deferred start runs only if Network is still on, and saving Network off clears it.
  2. A saved port can leave the old page active — rebind() bumps a generation; a socket opened for an older setting is closed again right after it is published.
  3. A new port waits after all ports fail — rebind() always wakes the loop (a wait on a monitor instead of Thread.sleep), with or without an open socket.
  4. Debug text can show an obsolete address — the activity's refresh runs when the server settles its port.
  5. Saving a taken port restarts the tunnel twice — rebind() clears settled, so the start after Save waits until the new port is known; no restart follows.

@compot-dev
compot-dev merged commit 46f6d0f into v2 Nov 18, 2026
7 checks passed
@compot-dev
compot-dev deleted the feat/web-port-284 branch November 18, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web page port: settable in Network, the next free port when taken; camex 4.1.2

1 participant