Commit c3cd34d
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 e94728a commit c3cd34d
File tree
27 files changed
+1447
-849
lines changed- agent
- pkg/tunnel
- gateway/nginx/conf.d
- pkg
- api/client
- mocks
- connman
- httptunnel
- wsconnadapter
- ssh
- http
- pkg
- dialer
- tunnel
- server
- session
27 files changed
+1447
-849
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 29 | | |
36 | 30 | | |
37 | 31 | | |
| |||
49 | 43 | | |
50 | 44 | | |
51 | 45 | | |
52 | | - | |
53 | 46 | | |
54 | 47 | | |
55 | 48 | | |
56 | 49 | | |
| 50 | + | |
57 | 51 | | |
58 | 52 | | |
59 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 70 | | |
73 | 71 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 72 | | |
82 | 73 | | |
83 | 74 | | |
| |||
86 | 77 | | |
87 | 78 | | |
88 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
89 | 84 | | |
90 | 85 | | |
91 | 86 | | |
| |||
123 | 118 | | |
124 | 119 | | |
125 | 120 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 121 | | |
132 | 122 | | |
133 | 123 | | |
| |||
176 | 166 | | |
177 | 167 | | |
178 | 168 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | 169 | | |
183 | 170 | | |
184 | 171 | | |
185 | | - | |
186 | 172 | | |
187 | | - | |
188 | 173 | | |
189 | 174 | | |
190 | 175 | | |
| |||
220 | 205 | | |
221 | 206 | | |
222 | 207 | | |
223 | | - | |
224 | 208 | | |
225 | 209 | | |
226 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | | - | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | | - | |
9 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | | - | |
31 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | | - | |
40 | | - | |
| 54 | + | |
| 55 | + | |
41 | 56 | | |
42 | | - | |
43 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
44 | 61 | | |
45 | | - | |
46 | | - | |
| 62 | + | |
47 | 63 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
51 | 68 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 69 | + | |
| 70 | + | |
87 | 71 | | |
88 | | - | |
89 | | - | |
| 72 | + | |
90 | 73 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 74 | + | |
| 75 | + | |
95 | 76 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 77 | + | |
| 78 | + | |
101 | 79 | | |
102 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
103 | 86 | | |
| 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 | | |
| |||
0 commit comments