Commit ec21319
committed
feat(agent): use multistream and yamux muxer instead of HTTP server
This change replaces the legacy per-connection HTTP/revdial
reverse-tunnel flow with a multiplexed, per-stream protocol (v2) based
on HashiCorp's yamux and multistream-select.
Yamux sessions allow a single agent websocket to host many logical
streams without repeating the HTTP reverse-listen handshake for each
session. Multistream-select provides explicit per-stream protocol
negotiation, making each logical stream's intent (SSH open/close, HTTP
proxy) explicit and versionable. The new approach reduces handshake
overhead and makes future protocol extensions easier and safer.
Over time the legacy reverse-tunnel implementation (per-request
HTTP/revdial) has become a maintenance burden and a performance limiter:
each logical session required a full HTTP handshake and a separate
reverse listener, which increased latency and duplicated logic across
server components. This change replaces that model with a single
multiplexed transport per agent using HashiCorp's yamux, and introduces
explicit per-stream protocol negotiation via multistream-select.
Practically, when an agent connects we now bind its websocket to a yamux
session (Manager.Bind) and keep that session alive with a light ping
loop. Individual logical operations—opening an SSH session, closing it,
or proxying HTTP—are created as yamux streams. Each stream negotiates
its intent using multistream identifiers (`/ssh/open/1.0.0`,
`/ssh/close/1.0.0`, `/http/proxy/1.0.0`) and then exchanges a small JSON
envelope for any parameters. The dialer package centralizes version
handling and prepares connections for callers via DialTo(ctx, tenant,
uid, target), while Target implementations encapsulate the
version-specific bootstrap (legacy HTTP v1 vs yamux+multistream v2).
We kept backward compatibility in mind: the Manager still recognizes
existing revdial-based connections and will return a v1 connection when
appropriate. That lets the system run both v1 and v2 agents concurrently
and supports staged rollouts. I also removed the duplicated tunnel
wiring and replaced it with a focused HTTP sidecar (http) that exposes
both the legacy endpoints and the new v2 bind endpoint; server and
session code now call into dialer.Dialer and Target helpers rather than
performing raw HTTP handshakes.1 parent 62ae183 commit ec21319
File tree
28 files changed
+1449
-817
lines changed- agent
- gateway/nginx/conf.d
- pkg
- agent
- pkg/tunnel
- api/client
- mocks
- connman
- httptunnel
- wsconnadapter
- ssh
- http
- pkg
- dialer
- tunnel
- server
- session
28 files changed
+1449
-817
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
371 | 394 | | |
372 | 395 | | |
373 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
0 commit comments