Skip to content

Commit f7f93d9

Browse files
authored
Merge pull request #224 from gosuda/copilot/replace-policy-engine-with-mols
feat: replace relay selection policy engine with MOLS over GF(64)
2 parents 6e87be6 + a4835cf commit f7f93d9

12 files changed

Lines changed: 1098 additions & 401 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Architecture, product behavior, and design rationale belong in `docs/architectur
99
- Prefer a single stable contract with one real owner.
1010
- Prefer local simplicity over premature or speculative abstraction.
1111
- Add indirection only when it removes real coupling or protects a real boundary.
12-
- Tests should protect stable contracts and invariants, not drive the spec.
12+
- Tests should protect real stable contracts and invariants, not drive the spec or exist only for regression prevention.
1313

1414
## Project Principles
1515

@@ -30,4 +30,4 @@ Architecture, product behavior, and design rationale belong in `docs/architectur
3030
- CI commands: `make vet`, `make lint`, `make test`, `make vuln`.
3131
- `make tidy` is local maintenance, not a CI requirement.
3232
- Run tests only when explicitly requested.
33-
- If verification seems necessary, ask before running it.
33+
- If verification seems necessary, ask before running it.

cmd/portal-tunnel/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ portal expose --name myapp \
7272
- Routed HTTP mode automatically forwards `X-Forwarded-*`, rewrites upstream `Location` redirects back to the public route path, and strips loopback cookie domains while remapping cookie paths to the mounted route prefix.
7373
- `--name` is optional. When omitted, the CLI generates a name for that run.
7474
- `--relays` adds explicit relay API URLs for that run. Explicit relays are always kept connected and are not counted against `--max-active-relays`.
75+
- `--multi-hop` sets one ordered multi-hop relay path for that run.
76+
- `--multi-hop-depth` automatically selects one multi-hop relay path with that hop count.
7577
- `--discovery=false` disables the public registry seed list and the runtime relay discovery expansion loop for that run. With `--discovery=false`, only the explicit `--relays` values are used.
7678
- `--ban-mitm` enables strict rejection when the TLS self-probe detects termination in the path.
7779
- `--tcp` requests a dedicated TCP port on the relay for raw TCP services that do not use TLS (e.g., Minecraft, game servers).
@@ -81,6 +83,8 @@ Flags:
8183

8284
```text
8385
--relays Portal relay API URLs (comma-separated, https only)
86+
--multi-hop Ordered multi-hop relay API URLs, comma-separated
87+
--multi-hop-depth Automatically select one multi-hop route with this hop count; 0 or 1 disables multi-hop
8488
--discovery Include public registry relays and discover additional relay bootstraps
8589
--max-active-relays Maximum number of auto-selected relays; explicit --relays are always included
8690
--ban-mitm Ban relay when the MITM self-probe detects TLS termination

cmd/portal-tunnel/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type exposeFlags struct {
6060
udpAddr string
6161
tcp bool
6262
maxActiveRelays int
63+
multiHopDepth int
6364
}
6465

6566
func runExposeCommand(args []string) error {
@@ -85,6 +86,7 @@ func runExposeCommand(args []string) error {
8586
utils.StringFlagEnv(fs, &flags.udpAddr, "udp-addr", "", "Local UDP target address for relayed datagrams (host:port or port only); defaults to the target when --udp is enabled", "UDP_ADDR")
8687
utils.BoolFlagEnv(fs, &flags.tcp, "tcp", false, "Request a dedicated TCP port on the relay for raw TCP services (no TLS; e.g., Minecraft, game servers)", "TCP_ENABLED")
8788
utils.IntFlagEnv(fs, &flags.maxActiveRelays, "max-active-relays", 3, nil, "Maximum number of auto-selected relays to keep connected; explicit --relays are always included", "MAX_ACTIVE_RELAYS")
89+
utils.IntFlagEnv(fs, &flags.multiHopDepth, "multi-hop-depth", 0, nil, "Automatically select one multi-hop route with this hop count; 0 or 1 disables multi-hop", "MULTI_HOP_DEPTH")
8890

8991
if err := utils.ParseFlagSet(fs, args, printExposeUsage); err != nil {
9092
if errors.Is(err, flag.ErrHelp) {
@@ -124,6 +126,7 @@ func runExposeCommand(args []string) error {
124126
UDPEnabled: flags.udp,
125127
TCPEnabled: flags.tcp,
126128
MultiHop: utils.SplitCSV(flags.multiHopCSV),
129+
MultiHopDepth: flags.multiHopDepth,
127130
BanMITM: flags.banMITM,
128131
MaxActiveRelays: flags.maxActiveRelays,
129132
Metadata: types.LeaseMetadata{
@@ -308,6 +311,7 @@ func printExposeUsage(w io.Writer) {
308311
"portal expose 3000 --ban-mitm",
309312
"portal expose 3000 --relays https://portal.example.com --discovery=false",
310313
"portal expose 3000 --multi-hop https://entry.example.com,https://transit.example.com,https://exit.example.com",
314+
"portal expose 3000 --multi-hop-depth 3",
311315
},
312316
)
313317
}

docs/src/routes/cli-reference/+page.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Instead of a positional target, you can use `--http-route` for multi-service rou
5858
|------|------|---------|-------------|
5959
| `--relays` | string | _(registry)_ | Portal relay API URLs (comma-separated, https only) |
6060
| `--discovery` | bool | `true` | Include public registry relays and discover additional bootstraps |
61+
| `--multi-hop` | string | | Ordered multi-hop relay API URLs, comma-separated |
62+
| `--multi-hop-depth` | int | `0` | Automatically select one multi-hop route with this hop count; 0 or 1 disables multi-hop |
6163
| `--max-active-relays` | int | `3` | Maximum auto-selected relays to keep connected; explicit relays are always included |
6264
| `--ban-mitm` | bool | `true` | Ban relay when the MITM self-probe detects TLS termination |
6365
| `--identity-path` | string | `./identity.json` | Identity JSON file path; created automatically when missing |
@@ -113,6 +115,18 @@ Disable relay discovery:
113115
portal expose 3000 --relays https://portal.example.com --discovery=false
114116
```
115117

118+
Explicit multi-hop route:
119+
120+
```bash
121+
portal expose 3000 --multi-hop https://entry.example.com,https://transit.example.com,https://exit.example.com
122+
```
123+
124+
Automatic multi-hop route:
125+
126+
```bash
127+
portal expose 3000 --multi-hop-depth 3
128+
```
129+
116130
Warning-only MITM mode:
117131

118132
```bash

docs/src/routes/configuration/+page.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ The `portal expose` subcommand accepts the following flags. Flags that read from
9595
|------|---------|------|---------|-------------|
9696
| `--relays` | | string | _(registry)_ | Additional Portal relay server API URLs (comma-separated; scheme omitted defaults to https) |
9797
| `--discovery` | | bool | `true` | Include public registry relays and discover additional relay bootstraps |
98+
| `--multi-hop` | `MULTI_HOP` | string | | Ordered multi-hop relay API URLs, comma-separated |
99+
| `--multi-hop-depth` | `MULTI_HOP_DEPTH` | int | `0` | Automatically select one multi-hop route with this hop count; 0 or 1 disables multi-hop |
98100
| `--max-active-relays` | `MAX_ACTIVE_RELAYS` | int | `3` | Maximum auto-selected relays to keep connected; explicit relays are always included |
99101
| `--ban-mitm` | `BAN_MITM` | bool | `true` | Ban relay when the MITM self-probe detects TLS termination |
100102

0 commit comments

Comments
 (0)