Metadata-Version: 2.3
Name: routeopt
Version: 0.1.0
Summary: Cross-platform CDN route optimizer with a mouse-driven TUI and dynamic OS firewall blocking
Keywords: cli,tui,cdn,network,route-optimizer,firewall,latency,rust
Author: Wei Lee
Author-email: Wei Lee <mai@mai0313.com>
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: System :: Networking
Requires-Python: >=3.8
Project-URL: Bug Tracker, https://github.com/Mai0313/routeopt/issues
Project-URL: Homepage, https://github.com/Mai0313/routeopt
Project-URL: Repository, https://github.com/Mai0313/routeopt
Description-Content-Type: text/markdown

<div align="center" markdown="1">

# routeopt

[![Crates.io](https://img.shields.io/crates/v/routeopt?logo=rust&style=flat-square&color=E05D44)](https://crates.io/crates/routeopt) [![Crates.io Downloads](https://img.shields.io/crates/d/routeopt?logo=rust&style=flat-square)](https://crates.io/crates/routeopt) [![npm version](https://img.shields.io/npm/v/routeopt?logo=npm&style=flat-square&color=CB3837)](https://www.npmjs.com/package/routeopt) [![npm downloads](https://img.shields.io/npm/dt/routeopt?logo=npm&style=flat-square)](https://www.npmjs.com/package/routeopt) [![PyPI version](https://img.shields.io/pypi/v/routeopt?logo=python&style=flat-square&color=3776AB)](https://pypi.org/project/routeopt/) [![PyPI downloads](https://img.shields.io/pypi/dm/routeopt?logo=python&style=flat-square)](https://pypi.org/project/routeopt/) [![rust](https://img.shields.io/badge/Rust-stable-orange?logo=rust&logoColor=white&style=flat-square)](https://www.rust-lang.org/) [![tests](https://img.shields.io/github/actions/workflow/status/Mai0313/routeopt/test.yml?label=tests&logo=github&style=flat-square)](https://github.com/Mai0313/routeopt/actions/workflows/test.yml) [![code-quality](https://img.shields.io/github/actions/workflow/status/Mai0313/routeopt/code-quality-check.yml?label=code-quality&logo=github&style=flat-square)](https://github.com/Mai0313/routeopt/actions/workflows/code-quality-check.yml) [![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray&style=flat-square)](https://github.com/Mai0313/routeopt/tree/main?tab=License-1-ov-file) [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/Mai0313/routeopt/pulls)

</div>

Route Optimizer (`routeopt`) is a cross-platform CDN route optimizer with a mouse-driven TUI and dynamic OS firewall blocking.

Other Languages: [English](README.md) | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)

## Highlights

- Monitors active TCP connections across one or more target processes and configurable ports, probing CDN node latency, jitter, and reachability.
- Dynamically blocks slow or unstable CDN nodes using native OS firewalls (Windows Filtering Platform per-app rules on Windows, `pf` anchor rules on macOS).
- Runs strictly in the foreground with session-ephemeral cooldowns and no background daemon or auto-startup; exiting or closing the terminal clears every firewall rule and leaves a clean slate for the next session.
- Keeps the headless core and platform layers (`src/core/`, `src/platform/`) completely decoupled from the TUI (`src/tui/`) and CLI (`src/cli/`) so future GUI frontends can share the same engine.
- Supports `--dry-run` mode for safe inspection without modifying OS firewall rules.

## Installation

Prebuilt binaries and registry packages (GitHub Releases, crates.io, npm, and PyPI) are published when `v*` release tags are cut. Until the first release is published, build from source with Cargo:

```bash
git clone https://github.com/Mai0313/routeopt.git
cd routeopt
cargo build --release --locked
```

Once published, the `routeopt` CLI can also be installed via Cargo, npm, or PyPI:

```bash
cargo install routeopt
# or
npm install -g routeopt
# or
uv tool install routeopt
```

## Usage

```bash
# Run with the mouse-driven Compact TUI (requires Administrator on Windows or sudo on macOS for live blocking)
routeopt --target douyin

# Inspect connections and latency probes without modifying OS firewall rules
routeopt --target douyin --dry-run

# Monitor multiple targets and ports
routeopt --target douyin --target bilibili --port 443 --port 8443

# Run headless without the TUI and stream engine events to stdout
routeopt --target douyin --headless

# Run a one-shot TCP latency/jitter probe without touching OS firewall rules
routeopt --probe 1.1.1.1
routeopt --probe 1.1.1.1:8443

# Display version and build metadata
routeopt --version
```

### CLI Options

| Flag                       | Description                                                                                                 |
| -------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `-V`, `--version`          | Print build version metadata and exit.                                                                      |
| `--dry-run`                | Monitor connections and probe nodes without modifying OS firewall rules.                                    |
| `--headless`               | Run without the interactive TUI and stream engine events to stdout.                                         |
| `-t`, `--target <NAME>`    | Target process name to monitor (repeatable; overrides `targets` in `config.json`).                          |
| `--app-path <TARGET=PATH>` | Explicit executable path override for per-app firewall filtering (repeatable).                              |
| `-p`, `--port <PORT>`      | Remote TCP port to monitor (repeatable; defaults to `443`).                                                 |
| `--config-dir <DIR>`       | Override the directory used for `config.json` (preferences only; no block carryover).                       |
| `--max-latency <MS>`       | Override the maximum latency threshold in milliseconds (default: `150`).                                    |
| `--max-jitter <MS>`        | Override the maximum jitter threshold in milliseconds (default: `100`).                                     |
| `--cooldown <MIN>`         | Override the session block cooldown duration in minutes (default: `30`).                                    |
| `--probe <IP[:PORT]>`      | Run a one-shot TCP probe against `IP` (default port `443`) or `IP:PORT` without touching OS firewall rules. |
| `--no-auto-block`          | Start with automatic blocking paused.                                                                       |
| `--no-ipv6`                | Disable IPv6 monitoring and blocking.                                                                       |

### TUI Mouse & Keybindings

The Compact TUI supports full mouse interaction across all four tabs (`Monitor`, `Subnets`, `Events`, `Settings`) as well as keyboard shortcuts:

| Control                       | Action                                                                                                         |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------- |
| Mouse Click                   | Switch tabs, select rows, sort columns, toggle filters/settings, and click Inspector or Subnet action buttons. |
| Mouse Wheel                   | Scroll the active Nodes table, Subnets list, or Events log.                                                    |
| `1`-`4` / `Tab` / `Shift+Tab` | Switch between `Monitor`, `Subnets`, `Events`, and `Settings` tabs.                                            |
| `Up` / `k`, `Down` / `j`      | Move selection or scroll in the active view.                                                                   |
| `Space`                       | Toggle automatic blocking (`ACTIVE` / `PAUSED`).                                                               |
| `u` / `b` / `r`               | Unblock / manually block / re-probe the selected node (or release/quarantine on `Subnets`).                    |
| `c`                           | Clear all active session firewall rules and cooldowns.                                                         |
| `6` / `s`                     | Toggle IPv6 monitoring / toggle subnet quarantine (`/24` IPv4, `/48` IPv6).                                    |
| `+` / `=` / `-`               | Increase or decrease the max latency threshold by `25ms`.                                                      |
| `a` / `p`                     | Add a custom target process name or custom TCP port on the `Settings` tab.                                     |
| `?` / `Esc`                   | Open or close the Help modal; `Esc` closes modals/inputs and never quits.                                      |
| `q` / `Ctrl+C`                | Quit cleanly and immediately release every firewall rule created by the session.                               |

## Version Information

The binary embeds dynamic build metadata via `build.rs`, including git tag version, commit count, short hash, dirty state, and Rust/Cargo versions.

Example output:

```text
routeopt v0.1.0-2-gf4ae332-dirty
Built with Rust 1.99.1 and Cargo 1.99.1
```

## Docker

```bash
docker build -f docker/Dockerfile --target prod -t ghcr.io/mai0313/routeopt:latest .
docker run --rm ghcr.io/mai0313/routeopt:latest --version
```

## Development

Contributor setup, commands, tests, code conventions, CI, and release details live in [CONTRIBUTING.md](./.github/CONTRIBUTING.md). Architecture and runtime invariants are documented in [AGENTS.md](AGENTS.md).

## License

MIT (see [LICENSE](LICENSE)).
