19 changed files with 1249 additions and 72 deletions

No files matched your search

+4
View File
@@ -38,4 +38,8 @@ android {
minSdkVersion 26
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
}
dependencies {
testImplementation 'junit:junit:4.13.2'
}
@@ -0,0 +1,525 @@
# Debug Log View Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add a live debug log view with a post-connect debug toggle and periodic native tunnel statistics, so a connected-but-stalled tunnel can be diagnosed without reconnecting.
**Architecture:** Extend the existing status fragment with a log buffer and controls, expose a native debug flag through JNI, and emit one compact stats line every 5 seconds from the native tunnel loop through the existing `fprintf` → broadcast path.
**Tech Stack:** Java 8, Android SDK 35 / minSdk 26, platform widgets, JNI, NDK 27, Gradle 8.7, JUnit 4 for the pure-Java log buffer.
**Spec:** `docs/superpowers/specs/2026-11-20-debug-log-view-design.md`
## Global Constraints
- minSdk 26, compileSdk 35, NDK `27.0.12077973`.
- Java source/target compatibility is 8; use `java.time` and anonymous inner classes consistent with the existing code.
- Debug stats are emitted every 5 seconds, plus once immediately when enabled.
- Log buffer is capped at 500 complete lines.
- No persistence, log files, export/share, logcat capture, per-packet traces, or per-profile verbose setting.
- The tunnel password must never appear in logs.
- `./gradlew build` must pass at the end of every task.
- Native log output must continue to use `fprintf(stderr, ...)` so `common.h` routes it through `android_printf` → `IodineClient.log_callback`.
## Review Focus
These are the failure modes most likely to bite a user, beyond what the automated tests cover:
1. **Toggling Debug mid-tunnel** must not restart, disconnect, or perturb the tunnel; only a volatile logging flag changes.
2. **Rotation and reconnect** must keep the checkbox in sync with the native flag, while a new connection clears the buffer and leaves Debug off.
3. **Copy and Clear at any time**, including with an empty buffer or an open partial line, must not crash or lose the open line unexpectedly.
4. **A stalled tunnel** must keep printing stats while traffic is absent; `last-rx` grows, `tx` keeps increasing, and output continues until the client's 60-second shutdown.
5. **Secrets** must not leak: the copied log may contain the domain/server but never the password.
Each is verified in the manual checklist in Task 3. This project has no Android
UI or native test harness, so those behaviors are checked on-device; the
pure-logic buffer behaviors are unit-tested in Task 1.
---
## Before Task 1
- [ ] Commit the approved spec and this plan:
```bash
git add docs/superpowers/specs/2026-11-20-debug-log-view-design.md docs/superpowers/plans/2026-11-20-debug-log-view.md
git commit -m "docs: add debug log view design and plan"
```
---
### Task 1: Timestamped, Capped Log Buffer
**Files:**
- Modify: `build.gradle`
- Create: `src/main/java/org/xapek/andiodine/LogBuffer.java`
- Create: `src/test/java/org/xapek/andiodine/LogBufferTest.java`
**Interfaces:**
- Consumes: nothing.
- Produces:
- `public LogBuffer(int maxLines, java.util.function.Supplier<String> timestamp)`
- `public static LogBuffer withLocalTime(int maxLines)`
- `public void append(String chunk)`
- `public String getText()`
- `public void clear()`
- `public int getLineCount()`
- [ ] **Step 1: Add the JUnit test dependency**
In `build.gradle`, add a top-level dependencies block after the `android { ... }` block:
```groovy
dependencies {
testImplementation 'junit:junit:4.13.2'
}
```
- [ ] **Step 2: Write the failing LogBuffer test**
Create `src/test/java/org/xapek/andiodine/LogBufferTest.java`:
```java
package org.xapek.andiodine;
import org.junit.Test;
import java.util.function.Supplier;
import static org.junit.Assert.assertEquals;
public class LogBufferTest {
private static final Supplier<String> TS = () -> "12:00:00.000";
@Test
public void timestampsCompleteLines() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("hello\n");
assertEquals("12:00:00.000 hello\n", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
@Test
public void assemblesPartialChunksIntoOneLine() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("Autodetect");
buffer.append("ing");
buffer.append(".\n");
assertEquals("12:00:00.000 Autodetecting.\n", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
@Test
public void splitsMultipleLinesInOneChunk() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("one\ntwo\n");
assertEquals("12:00:00.000 one\n12:00:00.000 two\n", buffer.getText());
assertEquals(2, buffer.getLineCount());
}
@Test
public void dropsOldestLinesAtCapacity() {
LogBuffer buffer = new LogBuffer(2, TS);
buffer.append("one\n");
buffer.append("two\n");
buffer.append("three\n");
assertEquals("12:00:00.000 two\n12:00:00.000 three\n", buffer.getText());
assertEquals(2, buffer.getLineCount());
}
@Test
public void clearRemovesOpenPartialLine() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("partial");
buffer.clear();
assertEquals("", buffer.getText());
assertEquals(0, buffer.getLineCount());
}
@Test
public void openLineAppearsWithoutTrailingNewline() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("partial");
assertEquals("12:00:00.000 partial", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
}
```
- [ ] **Step 3: Run the test and verify it fails**
Run:
```bash
export ANDROID_HOME=/home/arti/Android/Sdk
./gradlew testDebugUnitTest --tests "org.xapek.andiodine.LogBufferTest"
```
Expected: compilation failure, `cannot find symbol: class LogBuffer`.
- [ ] **Step 4: Implement `LogBuffer`**
Create `src/main/java/org/xapek/andiodine/LogBuffer.java` with the constructor and factory above, plus:
- A private `List<String> lines` and a `StringBuilder openLine`.
- `append`: ignore null/empty chunks; on the first character of a line append `timestamp.get() + " "`; add ordinary characters to `openLine`; on `\n`, finalize only if `openLine` has content, then trim oldest lines while `lines.size() > maxLines`.
- `getText`: join every completed line with `"\n"`, each followed by `\n`; append `openLine` without a trailing newline if it has content.
- `clear`: clear both `lines` and `openLine`.
- `getLineCount`: `lines.size()` plus 1 when `openLine` has content.
- `withLocalTime`: use `java.time.LocalTime.now()` and `java.time.format.DateTimeFormatter.ofPattern("HH:mm:ss.SSS")`.
- Reject `maxLines < 1` with `IllegalArgumentException`.
Do not add Android imports; this class must run in a plain JVM test.
- [ ] **Step 5: Run the test and verify it passes**
Run:
```bash
./gradlew testDebugUnitTest --tests "org.xapek.andiodine.LogBufferTest"
```
Expected: `BUILD SUCCESSFUL`, 6 tests passed.
- [ ] **Step 6: Commit**
```bash
git add build.gradle src/main/java/org/xapek/andiodine/LogBuffer.java src/test/java/org/xapek/andiodine/LogBufferTest.java
git commit -m "feat: add timestamped capped log buffer"
```
---
### Task 2: Native Debug Flag, Counters, Stats, and JNI
**Files:**
- Modify: `jni/iodine/src/client.h`
- Modify: `jni/iodine/src/client.c`
- Modify: `jni/iodine-client.c`
- Modify: `src/main/java/org/xapek/andiodine/IodineClient.java`
**Interfaces:**
- Consumes: the existing `android_printf` path and native client session.
- Produces:
- `void client_set_debug(int enabled)`
- `int client_get_debug(void)`
- `public static native void IodineClient.setDebug(boolean enabled)`
- `public static native boolean IodineClient.isDebug()`
- Stats lines in the form:
`[stats] elapsed=125s tx=612 rx=608 oos=2 servfail=0 last-rx=1s interval=2 lazy=1 resend=0`
- [ ] **Step 1: Declare the native debug API**
In `jni/iodine/src/client.h`, add:
```c
void client_set_debug(int enabled);
int client_get_debug(void);
```
- [ ] **Step 2: Move tunnel counters to file scope and add the debug flag**
In `jni/iodine/src/client.c`:
- Add near the other file-scope statics:
```c
static volatile int debug_stats;
static long debug_tx_queries;
static long packrecv;
static long packrecv_oos;
static long packrecv_servfail;
```
- Remove the function-local `static long packrecv`, `packrecv_oos`, and `packrecv_servfail` declarations from `tunnel_dns()`. The existing increments and reads keep working against the file-scope variables.
- In `client_init()`, reset `debug_stats`, `debug_tx_queries`, `packrecv`, `packrecv_oos`, and `packrecv_servfail` to 0.
- In `send_query()`, increment `debug_tx_queries` once per query sent.
- [ ] **Step 3: Add the getter/setter and stats emitter**
In `client.c`, add:
```c
void
client_set_debug(int enabled)
{
enabled = enabled ? 1 : 0;
if (debug_stats == enabled)
return;
debug_stats = enabled;
fprintf(stderr, "[stats] %s\n", enabled ? "enabled" : "disabled");
}
int
client_get_debug(void)
{
return debug_stats;
}
```
In `client_tunnel_cb()`, before the `while` loop, add:
```c
time_t tunnel_start = time(NULL);
time_t last_stats = 0;
debug_tx_queries = 0;
```
Resetting `debug_tx_queries` here makes the stats measure tunnel-phase queries,
not the handshake probes that ran before this loop.
At the top of the `while` loop, before `select()` is prepared, add:
```c
if (debug_stats) {
time_t now = time(NULL);
if (last_stats == 0 || now - last_stats >= 5) {
last_stats = now;
fprintf(stderr,
"[stats] elapsed=%lds tx=%ld rx=%ld oos=%ld servfail=%ld "
"last-rx=%lds interval=%d lazy=%d resend=%d\n",
(long)(now - tunnel_start), debug_tx_queries, packrecv,
packrecv_oos, packrecv_servfail,
(long)(now - lastdownstreamtime), selecttimeout, lazymode,
outchunkresent);
}
}
```
Use `time(NULL)`; `lastdownstreamtime` is already maintained by the tunnel loop.
- [ ] **Step 4: Add the JNI methods**
In `jni/iodine-client.c`, add:
```c
JNIEXPORT void JNICALL Java_org_xapek_andiodine_IodineClient_setDebug(
JNIEnv *env, jclass klass, jboolean enabled) {
client_set_debug(enabled ? 1 : 0);
}
JNIEXPORT jboolean JNICALL Java_org_xapek_andiodine_IodineClient_isDebug(
JNIEnv *env, jclass klass) {
return client_get_debug() ? JNI_TRUE : JNI_FALSE;
}
```
`client.h` is already included by `jni/iodine-client.c`.
- [ ] **Step 5: Declare the Java native methods**
In `src/main/java/org/xapek/andiodine/IodineClient.java`, add next to the other native declarations:
```java
public static native void setDebug(boolean enabled);
public static native boolean isDebug();
```
- [ ] **Step 6: Build and verify the JNI symbols**
Run:
```bash
export ANDROID_HOME=/home/arti/Android/Sdk
./gradlew assembleDebug
LIB=$(find build -name 'libiodine-client.so' | head -1)
nm -D "$LIB" | grep -E 'Java_org_xapek_andiodine_IodineClient_(setDebug|isDebug)'
```
Expected: build succeeds and both symbols appear, each on
`Java_org_xapek_andiodine_IodineClient_setDebug` and
`Java_org_xapek_andiodine_IodineClient_isDebug`.
- [ ] **Step 7: Commit**
```bash
git add jni/iodine/src/client.h jni/iodine/src/client.c jni/iodine-client.c src/main/java/org/xapek/andiodine/IodineClient.java
git commit -m "feat: add native debug stats flag and JNI hooks"
```
---
### Task 3: Status Screen Controls and Log Integration
**Files:**
- Modify: `src/main/res/layout/fragment_status.xml`
- Modify: `src/main/java/org/xapek/andiodine/FragmentStatus.java`
- Modify: `src/main/res/values/strings.xml`
- Modify: `src/main/res/values-de/strings.xml`
- Modify: `src/main/res/values-nl/strings.xml`
**Interfaces:**
- Consumes:
- `LogBuffer.withLocalTime(500)`, `append`, `getText`, `clear`
- `IodineClient.setDebug(boolean)`, `IodineClient.isDebug()`
- Produces: the user-visible debug view; no later tasks depend on it.
- [ ] **Step 1: Add the strings**
In `src/main/res/values/strings.xml`:
```xml
<string name="status_debug">Debug</string>
<string name="status_autoscroll">Auto-scroll</string>
<string name="status_copy">Copy</string>
<string name="status_clear">Clear</string>
<string name="status_copied">Log copied</string>
```
Add German equivalents to `values-de/strings.xml`:
`Debug`, `Autom. scrollen`, `Kopieren`, `Leeren`, `Log kopiert`.
Add Dutch equivalents to `values-nl/strings.xml`:
`Debug`, `Automatisch scrollen`, `Kopiëren`, `Wissen`, `Log gekopieerd`.
- [ ] **Step 2: Add the controls to the layout**
In `fragment_status.xml`, keep the existing `status_message` `TextView`, then insert
two horizontal rows before the inner `LinearLayout` that contains the
`ScrollView` and Close button:
```xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/status_debug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/status_debug"/>
<CheckBox
android:id="@+id/status_autoscroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/status_autoscroll"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/status_copy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/status_copy"/>
<Button
android:id="@+id/status_clear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/status_clear"/>
</LinearLayout>
```
The `Debug` checkbox starts disabled; Task 3's status receiver enables it on
`ACTION_STATUS_CONNECTED`.
- [ ] **Step 3: Wire the buffer and controls in `FragmentStatus`**
Add imports:
```java
import android.content.ClipData;
import android.content.ClipboardManager;
import android.widget.CheckBox;
import android.widget.Toast;
```
Add fields:
```java
private CheckBox mDebug;
private CheckBox mAutoScroll;
private Button mCopy;
private Button mClear;
private LogBuffer mLogBuffer;
```
In `onActivityCreated`, after the existing `findViewById` calls:
- Initialize `mLogBuffer = LogBuffer.withLocalTime(500)`.
- Find the new controls.
- `mDebug.setChecked(IodineClient.isDebug()); mDebug.setEnabled(false);`
- `mAutoScroll.setChecked(true);`
- `mDebug.setOnCheckedChangeListener` → `IodineClient.setDebug(isChecked)`.
- `mCopy.setOnClickListener` → copy `mLogBuffer.getText()` with
`ClipboardManager`/`ClipData.newPlainText("AndIodine log", text)`, then show
`Toast.makeText(getActivity(), R.string.status_copied, Toast.LENGTH_SHORT)`.
- `mClear.setOnClickListener` → `mLogBuffer.clear(); mLogmessages.setText("");`
Replace the log receiver's append logic with:
```java
if (mLogmessages == null) {
return;
}
mLogBuffer.append(newLogEntry);
mLogmessages.setText(mLogBuffer.getText());
if (mAutoScroll.isChecked()) {
mScrollview.fullScroll(View.FOCUS_DOWN);
}
```
In the status receiver:
- Guard view access with null checks (`if (mStatus != null)`, `if (mDebug != null)`)
so a status broadcast arriving before `onActivityCreated` cannot crash. Leave
the existing error-dialog branch outside those guards.
- On `ACTION_STATUS_CONNECT`: clear the buffer, clear the `TextView`, set
`mDebug.setChecked(false)`, `mDebug.setEnabled(false)`, and
`mAutoScroll.setChecked(true)`.
- On `ACTION_STATUS_CONNECTED`: keep the existing status text update and add
`mDebug.setEnabled(true)`.
- [ ] **Step 4: Build**
Run:
```bash
export ANDROID_HOME=/home/arti/Android/Sdk
./gradlew build
```
Expected: `BUILD SUCCESSFUL`, including lint.
- [ ] **Step 5: Manual device verification**
Install and exercise:
```bash
/home/arti/Android/Sdk/platform-tools/adb install -r build/outputs/apk/debug/andiodine-debug.apk
```
Verify:
1. Connect a tunnel; `Debug` is enabled only after the connected status.
2. Turn `Debug` on; a `[stats] enabled` line appears, then a stats line about
every 5 seconds. Turn it off; `[stats] disabled` appears once.
3. Uncheck `Auto-scroll` and scroll up; new messages do not force the view down.
Recheck it; new messages follow again.
4. `Copy` the log and paste it elsewhere; `Clear` empties the pane. Both work
with an empty pane and while a partial line is open.
5. Rotate the device; the `Debug` checkbox reflects the native state.
6. Disconnect and reconnect; the pane is empty and `Debug` is off and disabled
until connected.
7. After connecting, disable the upstream network (for example airplane mode)
and confirm stats continue with `last-rx` increasing and `tx` still
increasing until the client's 60-second no-downstream shutdown.
8. Inspect the copied log: it may contain the domain/server but not the tunnel
password.
- [ ] **Step 6: Commit**
```bash
git add src/main/res/layout/fragment_status.xml src/main/java/org/xapek/andiodine/FragmentStatus.java src/main/res/values/strings.xml src/main/res/values-de/strings.xml src/main/res/values-nl/strings.xml
git commit -m "feat: add live debug log controls to status screen"
```
@@ -0,0 +1,197 @@
# Debug log view for connected tunnels
Date: 2026-11-20
Status: proposed
## Intent
Make it possible to diagnose a tunnel that connected successfully but stopped
passing traffic, while it is still connected. The user should be able to turn on
debug output from the status screen, watch live tunnel statistics and existing
event messages, and copy the result without leaving the app or reconnecting.
This is live-only: no history, persistence, or export for now.
## Goals
- A `Debug` toggle on the status screen, enabled once the tunnel is connected.
- Enabling it mid-session starts low-volume native tunnel statistics without
restarting the tunnel.
- Existing setup, warning, and error messages keep appearing.
- Log lines carry local timestamps; the view supports pause (auto-scroll off),
copy, and clear.
- The log buffer is capped so a long session cannot grow without bound.
- Toggling debug has no meaningful effect on tunnel timing or traffic.
## Non-goals
- Persisting logs across disconnect, process death, or app restart.
- A log file, share sheet, or export feature.
- Capturing Java/logcat logs or building a general logcat viewer.
- Per-packet `Send`/`Recv` tracing.
- A per-profile "verbose" setting or always-on verbose mode.
- Background collection, notifications, or remote upload.
- Any change to connection, handshake, or error-handling behavior.
## Anti-goals
- A log level so noisy that it distorts the timing being investigated.
- Writing secrets (the password) into the log.
- Blocking the UI thread or the native tunnel loop while formatting/rendering.
## Constraints
- minSdk 26; platform widgets and the existing broadcast-based log path.
- The native client is C, compiled through the NDK; the stats check must work
while `select()` is timing out on a stalled tunnel.
- The toggle is flipped from the UI thread while the tunnel thread is running, so
the flag must be a safe volatile read/write.
- The status screen is small; controls must stay compact and not crowd the log.
## Approaches considered
**A. Extend the existing status screen (chosen).** Add the toggle and log
controls to the status fragment, and teach the native tunnel loop to emit a
periodic stats line when enabled. Smallest change, available at the exact moment
of a hang, no navigation, no reconnect.
**B. Dedicated debug log screen.** More room and room for filters/export later,
but requires a central buffer, a new activity, and navigation away from the
status screen. Overkill for a live-only first version; remains a natural
follow-up if logs ever need to survive disconnects.
**C. Per-profile verbose setting.** Requires leaving the connected screen,
editing the profile, and reconnecting, so it cannot debug a tunnel that is
already hung. Rejected.
## Design
### Logging level
Debug means **periodic stats plus the existing event/warning messages**, not
per-packet traces. For a stalled tunnel the useful questions are whether queries
still leave, whether replies still return, and how long since the last downstream
packet; a summary answers those without flooding the pane.
### UI
In `fragment_status.xml`, add a compact control row above the existing
`ScrollView`:
- `Debug` checkbox (off by default)
- `Auto-scroll` checkbox (on by default)
- `Copy` button
- `Clear` button
The existing log `TextView` stays. Controls may wrap to two rows if needed.
The `Debug` checkbox is unchecked and disabled during connection setup and
becomes enabled on `ACTION_STATUS_CONNECTED`; this avoids a race with native
session initialization, which resets the debug flag.
### Log buffering and display
`FragmentStatus` assembles native fragments into complete lines, prefixes each
line with a local `HH:mm:ss.SSS` timestamp, and keeps the last 500 lines.
Existing special handling for the progress dot (`.`) stays: dots append to the
current line rather than starting a new one.
- Auto-scroll calls `fullScroll(FOCUS_DOWN)` only when checked.
- `Copy` puts the current buffer on the clipboard and shows a toast.
- `Clear` empties the buffer and the `TextView`.
- On `ACTION_STATUS_CONNECT`, clear the buffer, uncheck and disable `Debug`, and
re-enable auto-scroll so a new session starts clean.
- On `ACTION_STATUS_CONNECTED`, enable the `Debug` checkbox.
- The buffer and auto-scroll state are process-scoped so a configuration change
(for example rotating the device) does not erase the log. They are cleared on
each connect and lost on process death.
Native log output is sanitized before it reaches Java: newlines are preserved so
the buffer can assemble real lines, while other non-printable bytes become
spaces.
### Debug toggle
Add native methods to `IodineClient`:
- `static native void setDebug(boolean enabled)`
- `static native boolean isDebug()`
The checkbox calls `setDebug()` on change and initializes from `isDebug()`, so
fragment recreation does not desynchronize the UI from the native flag.
### Native statistics
In `client.c`:
- `static volatile int debug_stats;`, reset to 0 in `client_init()`.
- `void client_set_debug(int enabled)` and `int client_get_debug(void)` in
`client.h` / `client.c`.
- Move `packrecv`, `packrecv_oos`, and `packrecv_servfail` from function-local
statics to file scope so the tunnel loop can report them.
- Add a cumulative `debug_tx_queries` counter incremented in `send_query()`.
- In `client_tunnel_cb()`, when `debug_stats` is set and at least 5 seconds have
passed since the last stats line, emit one line, for example:
```text
[stats] elapsed=125s tx=612 rx=608 oos=2 servfail=0 last-rx=1s interval=2 lazy=1 resend=0
```
Fields: elapsed seconds since tunnel start, cumulative DNS queries sent,
cumulative replies received, out-of-sequence count, SERVFAIL count, seconds
since last downstream packet, current select interval, lazy mode, and whether
an upstream fragment is being resent.
- Emit `[stats] enabled` / `[stats] disabled` once when the flag changes, so the
user gets immediate feedback.
- Use `fprintf(stderr, ...)` so the message follows the existing
`android_printf` → Java `log_callback` → broadcast path. No new logging
plumbing.
### JNI
Add `Java_org_xapek_andiodine_IodineClient_setDebug` and `_isDebug` in
`jni/iodine-client.c`, delegating to `client_set_debug()` / `client_get_debug()`.
### Privacy
Stats contain the tunnel domain/server indirectly through existing setup output,
but never the password. Copy is explicit; nothing is uploaded or persisted.
## Files
- `src/main/java/org/xapek/andiodine/FragmentStatus.java`
- `src/main/java/org/xapek/andiodine/IodineClient.java`
- `src/main/res/layout/fragment_status.xml`
- `src/main/res/values/strings.xml`
- `src/main/res/values-de/strings.xml`
- `src/main/res/values-nl/strings.xml`
- `jni/iodine-client.c`
- `jni/iodine/src/client.c`
- `jni/iodine/src/client.h`
## Testing
- `./gradlew build` must pass.
- Automated:
- `LogBuffer` unit tests: `./gradlew testDebugUnitTest --tests "org.xapek.andiodine.LogBufferTest"`.
- Native log sanitizer test (host C): `bash jni/tests/run.sh`.
- On a device, with the tunnel connected:
- Toggle `Debug` on; stats appear about every 5 seconds.
- Toggle it off; stats stop and a disabled message appears once.
- `Auto-scroll` off lets the user scroll back; on resumes following.
- `Copy` places the visible buffer on the clipboard.
- `Clear` empties the pane.
- Reconnecting starts with an empty pane and debug off.
- Buffer stays capped at 500 lines.
- Stalled-tunnel check: after the tunnel stops passing traffic, stats still
appear and show `last-rx` growing while `tx` keeps increasing, until the
client's 60-second no-downstream shutdown.
- There is no on-device UI test harness, so the checklist above remains manual.
The sanitizer test is a host C test and does not require a device.
## Left to the builder
- Exact wording and arrangement of the four controls.
- Final stats line format and field selection.
- Buffer size (proposed 500 lines).
- Where `Copy`/`Clear` live if the row is too wide.
- German/Dutch translations for the new labels.
+12 -7
View File
@@ -14,6 +14,7 @@
#include "iodine/src/tun.h"
#include "iodine/src/client.h"
#include "iodine/src/util.h"
#include "log_sanitize.h"
#define IODINE_CLIENT_CLASS "org/xapek/andiodine/IodineClient"
#define IODINE_CLIENT_CLASS_LOG_CALLBACK "log_callback"
@@ -31,7 +32,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
}
void android_log_callback(const char *msg_) {
int i;
JNIEnv *env;
char *msg = strdup(msg_);
@@ -63,12 +63,7 @@ void android_log_callback(const char *msg_) {
return;
}
for (i = 0; i< strlen(msg); i++) {
// not printable
if ( ! (msg[i] >= 0x20 && msg[i] <= 0x7e)) {
msg[i] = ' ';
}
}
andiodine_sanitize_log_message(msg);
jstring message = (*env)->NewStringUTF(env, msg);
if (!message) {
__android_log_print(ANDROID_LOG_ERROR, "iodine", "Native Debug: message == null");
@@ -85,6 +80,16 @@ JNIEXPORT jint JNICALL Java_org_xapek_andiodine_IodineClient_getDnsFd(
return dns_fd;
}
JNIEXPORT void JNICALL Java_org_xapek_andiodine_IodineClient_setDebug(
JNIEnv *env, jclass klass, jboolean enabled) {
client_set_debug(enabled ? 1 : 0);
}
JNIEXPORT jboolean JNICALL Java_org_xapek_andiodine_IodineClient_isDebug(
JNIEnv *env, jclass klass) {
return client_get_debug() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jint JNICALL Java_org_xapek_andiodine_IodineClient_connect(
JNIEnv *env, jclass klass, jstring j_nameserv_addr, jstring j_topdomain, jboolean j_raw_mode, jboolean j_lazy_mode,
jstring j_password, jint j_request_hostname_size, jint j_response_fragment_size,
+48 -3
View File
@@ -102,6 +102,12 @@ static long send_query_sendcnt = -1;
static long send_query_recvcnt = 0;
static int hostname_maxlen = 0xFF;
static volatile int debug_stats;
static long debug_tx_queries;
static long packrecv;
static long packrecv_oos;
static long packrecv_servfail;
void
client_init(void)
{
@@ -121,6 +127,12 @@ client_init(void)
inpkt.len = 0;
inpkt.seqno = 0;
inpkt.fragment = 0;
debug_stats = 0;
debug_tx_queries = 0;
packrecv = 0;
packrecv_oos = 0;
packrecv_servfail = 0;
}
void
@@ -226,6 +238,22 @@ client_set_hostname_maxlen(int i)
hostname_maxlen = i;
}
void
client_set_debug(int enabled)
{
enabled = enabled ? 1 : 0;
if (debug_stats == enabled)
return;
debug_stats = enabled;
fprintf(stderr, "[stats] %s\n", enabled ? "enabled" : "disabled");
}
int
client_get_debug(void)
{
return debug_stats;
}
const char *
client_get_raw_addr(void)
{
@@ -259,6 +287,7 @@ send_query(int fd, char *hostname)
fprintf(stderr, " Sendquery: id %5d name[0] '%c'\n", q.id, hostname[0]);
#endif
debug_tx_queries++;
sendto(fd, packet, len, 0, (struct sockaddr*)&nameserv, nameserv_len);
/* There are DNS relays that time out quickly but don't send anything
@@ -776,9 +805,6 @@ tunnel_tun(int tun_fd, int dns_fd)
static int
tunnel_dns(int tun_fd, int dns_fd)
{
static long packrecv = 0;
static long packrecv_oos = 0;
static long packrecv_servfail = 0;
int up_ack_seqno;
int up_ack_fragment;
int new_down_seqno;
@@ -1098,12 +1124,31 @@ client_tunnel_cb(int tun_fd, int dns_fd, int
fd_set fds;
int rv;
int i;
time_t tunnel_start;
time_t last_stats;
rv = 0;
lastdownstreamtime = time(NULL);
send_query_sendcnt = 0; /* start counting now */
tunnel_start = time(NULL);
last_stats = 0;
debug_tx_queries = 0;
while (running && cb_ask_continue()) {
if (debug_stats) {
time_t now = time(NULL);
if (last_stats == 0 || now - last_stats >= 5) {
last_stats = now;
fprintf(stderr,
"[stats] elapsed=%lds tx=%ld rx=%ld oos=%ld servfail=%ld "
"last-rx=%lds interval=%d lazy=%d resend=%d\n",
(long)(now - tunnel_start), debug_tx_queries, packrecv,
packrecv_oos, packrecv_servfail,
(long)(now - lastdownstreamtime), selecttimeout, lazymode,
outchunkresent);
}
}
tv.tv_sec = selecttimeout;
tv.tv_usec = 0;
+2
View File
@@ -33,6 +33,8 @@ void client_set_downenc(char *encoding);
void client_set_selecttimeout(int select_timeout);
void client_set_lazymode(int lazy_mode);
void client_set_hostname_maxlen(int i);
void client_set_debug(int enabled);
int client_get_debug(void);
int client_handshake(int dns_fd, int raw_mode, int autodetect_frag_size,
int fragsize);
+2 -2
View File
@@ -525,13 +525,13 @@ errx(int eval, const char *fmt, ...)
#if defined(__ANDROID__)
void android_log_callback(const char *);
static char printf_buf[1024];;
void android_printf(const char *fmt, ...)
{
char printf_buf[1024];
va_list list;
va_start(list, fmt);
vsnprintf(printf_buf,1024,fmt,list);
vsnprintf(printf_buf, sizeof(printf_buf), fmt, list);
android_log_callback(printf_buf);
__android_log_vprint(ANDROID_LOG_INFO, "Iodine",
+21
View File
@@ -0,0 +1,21 @@
#ifndef ANDIODINE_LOG_SANITIZE_H
#define ANDIODINE_LOG_SANITIZE_H
#include <stddef.h>
/*
* Make a native log message safe to pass through NewStringUTF while keeping
* newlines, which the status screen uses to assemble one timestamped line per
* native log event. Everything else outside printable ASCII becomes a space.
*/
static inline void andiodine_sanitize_log_message(char *msg)
{
size_t i;
for (i = 0; msg[i] != '\0'; i++) {
if (msg[i] != '\n' && (msg[i] < 0x20 || msg[i] > 0x7e)) {
msg[i] = ' ';
}
}
}
#endif
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
out=$(mktemp)
trap 'rm -f "$out"' EXIT
"${CC:-cc}" -std=c99 -Wall -Wextra -I "$here/.." \
"$here/test_log_sanitize.c" -o "$out"
"$out"
echo "log sanitizer tests passed"
+21
View File
@@ -0,0 +1,21 @@
#include <assert.h>
#include <string.h>
#include "log_sanitize.h"
int main(void)
{
char lines[] = "line one\nline two\n";
andiodine_sanitize_log_message(lines);
assert(strcmp(lines, "line one\nline two\n") == 0);
char controls[] = "a\tb\001c\177";
andiodine_sanitize_log_message(controls);
assert(strcmp(controls, "a b c ") == 0);
char utf8[] = "caf\xc3\xa9";
andiodine_sanitize_log_message(utf8);
assert(strcmp(utf8, "caf ") == 0);
return 0;
}
@@ -3,6 +3,8 @@ package org.xapek.andiodine;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -15,8 +17,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Locale;
@@ -27,6 +32,19 @@ public class FragmentStatus extends Fragment {
private TextView mLogmessages;
private ScrollView mScrollview;
private Button mClose;
private CheckBox mDebug;
private CheckBox mAutoScroll;
private Button mCopy;
private Button mClear;
/*
* Process-scoped so a configuration change (for example rotating the
* device while reading a stalled tunnel's log) does not erase the
* evidence. Cleared on ACTION_STATUS_CONNECT; lost on process death.
*/
private static final LogBuffer LOG_BUFFER = LogBuffer.withLocalTime(500);
private static boolean sAutoScroll = true;
private final LogBuffer mLogBuffer = LOG_BUFFER;
private final BroadcastReceiver broadcastReceiverStatusUpdates = new BroadcastReceiver() {
@Override
@@ -46,14 +64,35 @@ public class FragmentStatus extends Fragment {
.create() //
.show();
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
mStatus.setText(R.string.connect);
if (mDebug != null) {
mDebug.setChecked(false);
mDebug.setEnabled(false);
}
mLogBuffer.clear();
if (mLogmessages != null) {
mLogmessages.setText("");
}
sAutoScroll = true;
if (mAutoScroll != null) {
mAutoScroll.setChecked(true);
}
if (mStatus != null) {
mStatus.setText(R.string.connect);
}
} else if (IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
mStatus.setText(String.format(Locale.getDefault(), getString(R.string.vpnservice_connected_with_info),
IodineClient.getIp(),
IodineClient.getNetbits(),
IodineClient.getMtu()));
if (mStatus != null) {
mStatus.setText(String.format(Locale.getDefault(), getString(R.string.vpnservice_connected_with_info),
IodineClient.getIp(),
IodineClient.getNetbits(),
IodineClient.getMtu()));
}
if (mDebug != null) {
mDebug.setEnabled(true);
}
} else if (IodineVpnService.ACTION_STATUS_DISCONNECT.equals(intent.getAction())) {
mStatus.setText(R.string.disconnect);
if (mStatus != null) {
mStatus.setText(R.string.disconnect);
}
}
}
};
@@ -63,10 +102,16 @@ public class FragmentStatus extends Fragment {
public void onReceive(Context context, Intent intent) {
if (IodineClient.ACTION_LOG_MESSAGE.equals(intent.getAction())) {
final String newLogEntry = intent.getStringExtra(IodineClient.EXTRA_MESSAGE);
if (!".".equals(newLogEntry)) // Suppress newline for progress indicator'.'
mLogmessages.append("\n");
mLogmessages.append(newLogEntry);
mScrollview.fullScroll(View.FOCUS_DOWN);
if (newLogEntry == null) {
return;
}
mLogBuffer.append(newLogEntry);
if (mLogmessages != null) {
mLogmessages.setText(mLogBuffer.getText());
if (mAutoScroll != null && mAutoScroll.isChecked() && mScrollview != null) {
mScrollview.fullScroll(View.FOCUS_DOWN);
}
}
}
}
};
@@ -78,6 +123,46 @@ public class FragmentStatus extends Fragment {
mLogmessages = (TextView) getActivity().findViewById(R.id.status_logmessages);
mScrollview = (ScrollView) getActivity().findViewById(R.id.status_scrollview);
mClose = (Button) getActivity().findViewById(R.id.status_cancel);
mDebug = (CheckBox) getActivity().findViewById(R.id.status_debug);
mAutoScroll = (CheckBox) getActivity().findViewById(R.id.status_autoscroll);
mCopy = (Button) getActivity().findViewById(R.id.status_copy);
mClear = (Button) getActivity().findViewById(R.id.status_clear);
mLogmessages.setText(mLogBuffer.getText());
mDebug.setChecked(IodineClient.isDebug());
mDebug.setEnabled(false);
mAutoScroll.setChecked(sAutoScroll);
mAutoScroll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
sAutoScroll = isChecked;
}
});
mDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
IodineClient.setDebug(isChecked);
}
});
mCopy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
clipboard.setPrimaryClip(ClipData.newPlainText("AndIodine log", mLogBuffer.getText()));
}
Toast.makeText(getActivity(), R.string.status_copied, Toast.LENGTH_SHORT).show();
}
});
mClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mLogBuffer.clear();
mLogmessages.setText("");
}
});
mClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -26,6 +26,10 @@ public class IodineClient {
public static native String getPropertyNetDns1();
public static native void setDebug(boolean enabled);
public static native boolean isDebug();
/**
* Intent to distribute logmessages from native code
* LOG_MESSAGE(EXTRA_MESSAGE)
@@ -1,6 +1,5 @@
package org.xapek.andiodine;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -8,10 +7,10 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkCapabilities;
import android.net.VpnService;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.Log;
import org.xapek.andiodine.config.ConfigDatabase;
@@ -21,6 +20,7 @@ import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
public class IodineVpnService extends VpnService implements Runnable {
@@ -212,19 +212,34 @@ public class IodineVpnService extends VpnService implements Runnable {
}
}
private Network getActiveNetwork() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo defaultNetworkInfo = cm.getActiveNetworkInfo();
for (Network n : cm.getAllNetworks()) {
NetworkInfo info = cm.getNetworkInfo(n);
if (info.getType() == defaultNetworkInfo.getType() &&
info.getSubtype() == defaultNetworkInfo.getSubtype() &&
info.isConnected()) {
return n;
/**
* Networks whose DNS servers may be usable to reach the iodine server,
* with the active network first.
* <p>
* The old implementation matched the active network by type/subtype using
* the deprecated {@link android.net.NetworkInfo} API. That misses networks
* when a VPN is active, and only looked at a single network. Older devices
* and IPv6-only carriers may expose no IPv4 DNS server on the default
* network at all, so we also inspect the other connected networks.
*/
private List<Network> getNetworksForDnsDetection(ConnectivityManager cm) {
List<Network> networks = new ArrayList<>();
Network active = cm.getActiveNetwork();
if (active != null) {
networks.add(active);
}
Network[] all = cm.getAllNetworks();
for (Network n : all) {
if (n.equals(active)) {
continue;
}
NetworkCapabilities capabilities = cm.getNetworkCapabilities(n);
if (capabilities != null
&& capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
networks.add(n);
}
}
return null;
return networks;
}
@Override
@@ -233,42 +248,63 @@ public class IodineVpnService extends VpnService implements Runnable {
Log.d(TAG, "VPN Thread enter");
setStatus(ACTION_STATUS_CONNECT, mConfiguration.getId(), null);
String tunnelNameserver = "";
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network activeNetwork = getActiveNetwork();
if (activeNetwork == null) {
String errorMessage = getString(R.string.vpnservice_error_no_active_network);
setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage);
Log.e(TAG, "No active network. Aborting...");
return;
// An explicitly configured tunnel nameserver always wins. It is the
// documented escape hatch when the network does not announce a
// usable IPv4 resolver (IPv6-only mobile networks, private DNS,
// another VPN being active, ...). Checking it after auto-detection
// made that option useless exactly when it was needed.
String tunnelNameserver = mConfiguration.getTunnelNameserver();
if (tunnelNameserver == null) {
tunnelNameserver = "";
}
LinkProperties prop = cm.getLinkProperties(activeNetwork);
assert prop != null;
List<InetAddress> servers = prop.getDnsServers();
for (InetAddress candidate : servers) {
Log.d(TAG, "detected dns server: " + candidate);
if (candidate instanceof Inet4Address) {
tunnelNameserver = candidate.getHostAddress();
break;
tunnelNameserver = tunnelNameserver.trim();
if (tunnelNameserver.isEmpty()) {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
List<Network> networks = getNetworksForDnsDetection(cm);
if (networks.isEmpty()) {
String errorMessage = getString(R.string.vpnservice_error_no_active_network);
setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage);
Log.e(TAG, "No active network. Aborting...");
return;
}
List<String> detectedServers = new ArrayList<>();
for (Network network : networks) {
LinkProperties prop = cm.getLinkProperties(network);
if (prop == null) {
continue;
}
for (InetAddress candidate : prop.getDnsServers()) {
String address = candidate.getHostAddress();
Log.d(TAG, "detected dns server: " + address + " on " + network);
if (!detectedServers.contains(address)) {
detectedServers.add(address);
}
// The native iodine client only supports IPv4
// nameservers, so skip IPv6 ones here.
if (tunnelNameserver.isEmpty() && candidate instanceof Inet4Address) {
tunnelNameserver = address;
}
}
}
if (tunnelNameserver.isEmpty()) {
String detected = detectedServers.isEmpty()
? getString(R.string.vpnservice_error_dns_none)
: TextUtils.join(", ", detectedServers);
String errorMessage = getString(R.string.vpnservice_error_dns_detect_failed, detected);
setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage);
Log.e(TAG, "No valid IPv4 name servers detected (found: " + detected
+ "). Aborting...");
return;
}
}
assert tunnelNameserver != null;
if (tunnelNameserver.isEmpty()) {
String errorMessage = getString(R.string.vpnservice_error_dns_detect_failed);
setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage);
Log.e(TAG, "No valid IPv4 name servers detected. Aborting...");
return;
}
Log.d(TAG, "using name server: " + tunnelNameserver);
if (!"".equals(mConfiguration.getTunnelNameserver())) {
tunnelNameserver = mConfiguration.getTunnelNameserver();
}
String password = "";
if (!"".equals(mConfiguration.getPassword())) {
password = mConfiguration.getPassword();
String password = mConfiguration.getPassword();
if (password == null) {
password = "";
}
int ret = IodineClient.connect(tunnelNameserver, mConfiguration.getTopDomain(), mConfiguration.getRawMode(),
@@ -0,0 +1,77 @@
package org.xapek.andiodine;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
/**
* Assembles native log fragments into timestamped lines and keeps only the
* most recent lines. Fragments without a newline stay on the current line, so
* progress output such as "Autodetecting...." is not split into many entries.
*/
public class LogBuffer {
private static final DateTimeFormatter LOCAL_TIME =
DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
private final int maxLines;
private final Supplier<String> timestamp;
private final List<String> lines = new ArrayList<>();
private final StringBuilder openLine = new StringBuilder();
public LogBuffer(int maxLines, Supplier<String> timestamp) {
if (maxLines < 1) {
throw new IllegalArgumentException("maxLines must be at least 1");
}
this.maxLines = maxLines;
this.timestamp = timestamp;
}
public static LogBuffer withLocalTime(int maxLines) {
return new LogBuffer(maxLines, () -> LocalTime.now().format(LOCAL_TIME));
}
public void append(String chunk) {
if (chunk == null || chunk.isEmpty()) {
return;
}
for (int i = 0; i < chunk.length(); i++) {
char c = chunk.charAt(i);
if (c == '\n') {
if (openLine.length() > 0) {
lines.add(openLine.toString());
openLine.setLength(0);
while (lines.size() > maxLines) {
lines.remove(0);
}
}
} else {
if (openLine.length() == 0) {
openLine.append(timestamp.get()).append(' ');
}
openLine.append(c);
}
}
}
public String getText() {
StringBuilder text = new StringBuilder();
for (String line : lines) {
text.append(line).append('\n');
}
if (openLine.length() > 0) {
text.append(openLine);
}
return text.toString();
}
public void clear() {
lines.clear();
openLine.setLength(0);
}
public int getLineCount() {
return lines.size() + (openLine.length() > 0 ? 1 : 0);
}
}
+40
View File
@@ -15,6 +15,46 @@
style="@android:style/TextAppearance.DeviceDefault.Large"
tools:ignore="HardcodedText"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/status_debug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/status_debug"/>
<CheckBox
android:id="@+id/status_autoscroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/status_autoscroll"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/status_copy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/status_copy"/>
<Button
android:id="@+id/status_clear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/status_clear"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
+7 -1
View File
@@ -49,7 +49,8 @@
<string name="vpnservice_error_handshake_failed">Handshake fehlgeschlagen</string>
<string name="vpnservice_error_unknown_error_code">Unbekannter Fehler. Kode %d</string>
<string name="vpnservice_error_unknown_error_string">Unbekannter Fehler. Grund: %s</string>
<string name="vpnservice_error_dns_detect_failed">Es wurden keine gültigen IPv4-Nameserver erkannt</string>
<string name="vpnservice_error_dns_detect_failed">Kein IPv4-Nameserver verfügbar (gefunden: %1$s). Trage unter \"Tunnel Nameserver\" einen IPv4-Resolver wie 1.1.1.1 ein.</string>
<string name="vpnservice_error_dns_none">keine</string>
<string name="vpnservice_error_create_interface_string">Das Tunnel-Netzwerkgerät konnte nicht erstellt werden</string>
<string name="vpnservice_error_no_active_network">Kein aktives Netzwerk</string>
<string name="idle">Leerlauf</string>
@@ -73,5 +74,10 @@
<string name="pref_text_lazy_mode_label">Lazy mode</string>
<string name="pref_text_default_route_label">Standardroute</string>
<string name="vpnservice_connected_with_info">Verbindung: %1$s/%2$d MTU: %3$d</string>
<string name="status_debug">Debug</string>
<string name="status_autoscroll">Autom. scrollen</string>
<string name="status_copy">Kopieren</string>
<string name="status_clear">Leeren</string>
<string name="status_copied">Log kopiert</string>
</resources>
+7 -1
View File
@@ -35,7 +35,8 @@
<string name="idle">Inactief</string>
<string name="pref_help_password">Het is niet verplicht om dit in the vullen. Alleen de eerste 32 letters zullen worden gebruikt.</string>
<string name="pref_help_raw">Indien aangevinkt zal Iodine proberen het publieke IP-adres van de Iodined server direct proberen te bereiken. Indien dat het geval is zal het dataverkeer direct naar de server worden verzonden i.p.v. de DNS relay.</string>
<string name="vpnservice_error_dns_detect_failed">Er zijn geen geldige IPv4 servers gedetecteerd.</string>
<string name="vpnservice_error_dns_detect_failed">Geen IPv4-nameserver beschikbaar (gevonden: %1$s). Stel \"Tunnel Nameserver\" in op een IPv4-resolver zoals 1.1.1.1.</string>
<string name="vpnservice_error_dns_none">geen</string>
<string name="close">Sluit</string>
<string name="pref_help_request_type">Aangepast DNS request type. Normaal probeert Iodine automatisch het DNS request type met de hoogste bandbreedte te vinden en te gebruiken. Echter blijkt de DNS relay in sommige gevallen limieten op te leggen, waardoor andere DNS types onverwacht meer bandbreedte kunnen dragen. Als dat het geval is kunt u deze optie gebruiken om een ander type te selecteren. Van de meeste bandbreedte naar de minste zijn dit de ondersteunde DNS types: NULL, TXT, SRV, MX, CNAME en A.</string>
<string name="pref_help_topdomain">Het DNS verkeer zal als aanvragen van de subdomeinen onder _topdomain_ worden verzonden. Normaal gesproken is dit uw eigen domein. Gebruik een korte domeinnaam voor een hogere bandbreedte. Indien de gekozen nameserver die van Iodine is, kan elk tomdomein gekozen worden zolang hetzelfde domein op de server en de cliënt gekozen wordt.</string>
@@ -72,5 +73,10 @@
<string name="pref_text_tunnel_nameserver_label_or_empty">Tunnel Naamserver (optioneel)</string>
<string name="pref_text_default_route_label">Standaard Route</string>
<string name="vpnservice_connected_with_info">Verbonden: %1$s/%2$d MTE: %3$d</string>
<string name="status_debug">Debug</string>
<string name="status_autoscroll">Automatisch scrollen</string>
<string name="status_copy">Kopiëren</string>
<string name="status_clear">Wissen</string>
<string name="status_copied">Log gekopieerd</string>
</resources>
+7 -2
View File
@@ -83,7 +83,8 @@
<string name="vpnservice_error_handshake_failed">Handshake failed</string>
<string name="vpnservice_error_unknown_error_code">Unknown Error. Code %d</string>
<string name="vpnservice_error_unknown_error_string">Unknown Error. Reason: %s</string>
<string name="vpnservice_error_dns_detect_failed">No valid IPv4 name servers detected</string>
<string name="vpnservice_error_dns_detect_failed">No IPv4 name server available (found: %1$s). Set \"Tunnel Nameserver\" to an IPv4 resolver such as 1.1.1.1.</string>
<string name="vpnservice_error_dns_none">none</string>
<string name="vpnservice_error_create_interface_string">Failed to create tunnel network device</string>
<string name="vpnservice_error_no_active_network">No active network</string>
<string name="idle">Idle</string>
@@ -100,6 +101,10 @@
<string name="connect">Connecting...</string>
<string name="disconnect">Disconnecting...</string>
<string name="vpnservice_connected_with_info">Connected: %1$s/%2$d MTU: %3$d</string>
<string name="status_debug">Debug</string>
<string name="status_autoscroll">Auto-scroll</string>
<string name="status_copy">Copy</string>
<string name="status_clear">Clear</string>
<string name="status_copied">Log copied</string>
</resources>
@@ -0,0 +1,87 @@
package org.xapek.andiodine;
import org.junit.Test;
import java.util.function.Supplier;
import static org.junit.Assert.assertEquals;
public class LogBufferTest {
private static final Supplier<String> TS = () -> "12:00:00.000";
@Test
public void timestampsCompleteLines() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("hello\n");
assertEquals("12:00:00.000 hello\n", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
@Test
public void assemblesPartialChunksIntoOneLine() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("Autodetect");
buffer.append("ing");
buffer.append(".\n");
assertEquals("12:00:00.000 Autodetecting.\n", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
@Test
public void splitsMultipleLinesInOneChunk() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("one\ntwo\n");
assertEquals("12:00:00.000 one\n12:00:00.000 two\n", buffer.getText());
assertEquals(2, buffer.getLineCount());
}
@Test
public void dropsOldestLinesAtCapacity() {
LogBuffer buffer = new LogBuffer(2, TS);
buffer.append("one\n");
buffer.append("two\n");
buffer.append("three\n");
assertEquals("12:00:00.000 two\n12:00:00.000 three\n", buffer.getText());
assertEquals(2, buffer.getLineCount());
}
@Test
public void clearRemovesOpenPartialLine() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("partial");
buffer.clear();
assertEquals("", buffer.getText());
assertEquals(0, buffer.getLineCount());
}
@Test
public void openLineAppearsWithoutTrailingNewline() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("partial");
assertEquals("12:00:00.000 partial", buffer.getText());
assertEquals(1, buffer.getLineCount());
}
@Test
public void rendersSeparateNativeMessagesAsSeparateLines() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append("[stats] enabled\n");
buffer.append("Version ok, both using protocol v 0x00000502. You are user #0\n");
buffer.append("[stats] elapsed=5s tx=1 rx=0 oos=0 servfail=0 last-rx=5s interval=2 lazy=1 resend=0\n");
assertEquals(3, buffer.getLineCount());
}
@Test(expected = IllegalArgumentException.class)
public void rejectsNonPositiveCapacity() {
new LogBuffer(0, TS);
}
@Test
public void ignoresNullAndEmptyChunks() {
LogBuffer buffer = new LogBuffer(10, TS);
buffer.append(null);
buffer.append("");
assertEquals("", buffer.getText());
assertEquals(0, buffer.getLineCount());
}
}