Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions en/host/telnet-and-serial-feasibility-research.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,96 @@
> Purpose: Provide **factual basis and an implementation checklist** for subsequently implementing Telnet and serial session types.
> All code conclusions are supported by `file:line` evidence. Parts verified online include the version and license. Anything not verified is marked "unverified".

> **2026-08-17 implementation note (Telnet is implemented, as a plugin rather than built in)**
>
> The whole "protocol generalization" rework in Section 3 **was not done and is not needed**: Telnet uses the plugin
> protocol capability added after S3, and the session type stays the existing `ConnectionType.Plugin`, so the four enum
> clamps in 3.1 and the new `SessionProfile` fields in 3.5 (five hand-written copies) are all avoided. What actually shipped:
>
> - The SDK gained a **terminal protocol** capability: `IProtocolTerminal` / `IProtocolTerminalSession`
> (byte duplex + Resize), alongside the existing `IProtocolFileSystem`, plus
> `ProtocolFeatures.NoCredentials` (hides the user name / password fields).
> - The host gained an adapter, `PluginTerminalShellStream`: plugin session → `IShellStreamWrapper`,
> so the "directly reusable" table in Section 2 **holds in full** (bridge, VT engine, ZModem, session logging, reconnection state machine).
> - The dispatch points got a single check (is the registry entry a terminal or a file system); each of the two in 3.2 is one line.
> - Most of the guards in 3.4 were already covered by existing conditions (tunnels already exclude `Plugin`; the task manager and
> file panel grey out on `SessionId == Guid.Empty`); the only real change was `RebindFileBrowser` —
> it used to keep showing the previous SSH session's file panel on a Telnet tab (exactly the bug recorded in 3.4).
> - The "local echo" of 3.6 was not built into the terminal layer: the Telnet plugin injects the echo into its own read pipeline,
> with zero changes to the host terminal layer.
> - Implementation: `plugins/VelaShell.Plugin.Telnet` (RFC 854 negotiation / NAWS / TERMINAL-TYPE /
> 8-bit transparency, no third-party dependencies, consistent with the choice in §4.2).
>
> **2026-08-26 implementation note (serial is implemented, also as a plugin)**
>
> Serial reuses the same terminal protocol capability and ships as `velashell.serial` (`plugins/VelaShell.Plugin.Serial`
> in the velashell-plugins repository). The conclusions of Sections 4 and 5 about `System.IO.Ports`, three-platform port
> enumeration, the `Close()` deadlock and packaging **all hold**, only the code lives in the plugin rather than in the host.
> The last disabled placeholder tab on the connection page was therefore removed — the host no longer knows any specific protocol.
>
> Where it departs from this document's plan, recorded here so nobody goes looking in the old text:
>
> - **§3.5 "do not use `Host` to carry `COM3`" is reversed in the plugin form.** That conclusion was written for the built-in
> `SessionProfile` + SSH-only `ConnectionInfo`; in plugin protocols `Host` had long been generalized to "where to connect"
> (S3 puts the service endpoint there, SQLite the database file). Serial puts the device name in that field, the same move as PuTTY
> replacing *Host Name* with *Serial line*, which also lets the recent-connections list and session names show the device.
> The cost is that the SDK must be able to turn that field **into a drop-down** — see the next item.
> - **The SDK added three things (1.5.0)**: `ProtocolFeatures.NoEndpoint` (hides the port field, same meaning as the existing
> `WorkspaceFeatures.NoEndpoint`; that bit was finally implemented on the host side too — it had been declared since 1.3.1 and
> never read), `ProtocolSettingKind.DynamicChoice` + `IProtocolChoiceSource` (choices fetched when the form opens: USB serial
> adapters are **hot-pluggable**, and a list enumerated once at registration is long stale by the time the user plugs one in),
> and `AllowsCustomValue` / `HostKind` / `HostChoices` (editable drop-downs: non-standard baud rates such as 250000 (Marlin)
> and 76800, and devices the enumeration misses, must still be enterable).
> - **The "local echo" of §3.6 is still not in the terminal layer**, handled the same way as Telnet: the plugin injects the echo
> into its own read pipeline, with zero changes to the host terminal layer.
> - **Windows friendly names do not use the WMI of §4.1** but SetupAPI (what Device Manager uses): no new dependency,
> no COM start-up cost, a few milliseconds. Failing only means no description — the port list itself comes from
> `SerialPort.GetPortNames()` and is unaffected.
> - **The packaging risk of §5.2 is ruled out**: the plugin is a RID-agnostic dynamically loaded project, and the
> `runtimes/<rid>/native/` layer of `System.IO.Ports` lands in the plugin output as is (628KB measured), resolved by the host's
> `PluginAssemblyLoadContext.LoadUnmanagedDll` through the plugin's own `deps.json`.
> - **The workaround for the `Close()` deadlock of §5.1 goes further than planned**: reads poll with a 250ms timeout, so
> **the close path wakes nothing up** — the reader thread sees the stop flag and closes the port itself. Neither #20362 nor #44952 can be reached.
> - **"Cannot be verified automatically" (§5.4) still holds**: serial has no loopback. The byte paths (read loop, EOF
> normalization, newline state machine, write serialization, control-line actions) are pinned by the `FakeSerialPort` double;
> end to end still needs real hardware or `socat` / `com0com`.
>
> **2026-12-01 revision note (echo, back-pressure and close paths in both plugins)**
>
> A review of both plugins against their implementation fixed a set of problems (velashell-plugins
> [#195](https://github.com/VelaShell/velashell-plugins/pull/195)). The behaviour changes:
>
> - **The local echo of §3.6 no longer sends key bytes back verbatim.** Each plugin carries its own `LocalEchoRenderer` (plugins
> ship separately and cannot share assemblies), doing the part of the display that a terminal driver does under ECHO + ICANON:
> CR / LF / CR LF are all shown as a new line; backspace erases the previous character on the line, never past the start of
> the line, two cells for a wide character; cursor keys and other control sequences, and the remaining C0 control characters,
> are not shown. Before, Enter on Telnet only returned to the start of the line (so the server's reply overwrote it) and
> backspace (DEL) did nothing on screen; serial echoed a staircase when Enter sent LF. The bytes on the wire are unchanged.
> - **Telnet negotiation records our own requests as RFC 1143 describes.** The WILL / DO sent in the handshake are marked
> "pending": the DO / WILL that come back are acknowledgements and DONT / WONT are refusals, and neither is answered again.
> The minimum negotiation set of §4.2 is unchanged; each option just loses a redundant round trip.
> - **Telnet subnegotiation is bounded.** Only the first 1KB of a payload is kept (the plugin only handles TERMINAL-TYPE SEND);
> past 64KB without `IAC SE` it is treated as broken and parsing returns to data — otherwise a device that sends `IAC SB` but
> never `IAC SE` would have all later output swallowed as subnegotiation.
> - **Telnet output has back-pressure.** The channel between the read pump and the terminal engine is capped at about 1MB; when
> it is full the pump stops reading the socket, so the pressure reaches the server through the TCP window instead of
> everything it sends at network speed piling up in memory.
> - **§5 Telnet item 3 (the scope of CRLF rewriting) gains an edge case**: a pasted CRLF split across two writes no longer sends
> an extra LF (whether the previous write ended with a bare CR is remembered across writes). Serial's outbound newline rewrite
> does the same.
> - **Serial transmit pacing** waits with millisecond precision on a dedicated thread: `Task.Delay` has a granularity of about
> 15.6ms on Windows, so "1ms per byte" used to become 15ms. Paced writes no longer block the caller's thread; CR LF counts as
> one line and waits for the line delay once; closing the session stops it.
> - **Serial now opens the port in the background, and the open can be cancelled.** `SerialPort.Open` blocks (a Bluetooth COM
> port whose device is absent can hang for over ten seconds) and cannot be interrupted: cancelling takes effect at once, and
> the plugin closes the port when the late open returns.
> - **The macOS conclusion of §4.1 port enumeration goes one step further**: the drop-down already lists only `/dev/cu.*`, but a
> `/dev/tty.xxx` typed in or stored in an old profile is now opened as the existing `/dev/cu.xxx` (the same hardware) instead
> of waiting for carrier forever.
> - The Telnet and serial (and S3) plugins unsubscribe from `LocaleChanged` on deactivation. They used to subscribe with an
> anonymous lambda and never unsubscribe, so the host's event list kept the plugin instance alive and the collectible ALC
> could not unload.

---

## 1. Conclusion First
Expand Down
5 changes: 3 additions & 2 deletions en/host/vnc-plugin-design-and-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ The size in extended-clipboard Caps limits unsolicited Provide messages, not res

- **Play remote audio** (`audio`, off by default, as in the RDP plugin). When on, the client lists the QEMU Audio pseudo-encoding (-259) in SetEncodings; once the server confirms it with a rectangle of encoding -259 (QEMU fills in the desktop size, which means nothing here), the client sends set-format (signed 16-bit, stereo, 44.1 kHz) and then enable. Only QEMU / libvirt consoles implement this extension so far; other servers ignore the pseudo-encoding.
- Samples are read in QEMU's default byte order (little-endian). The PCM output is the same implementation as the RDP plugin's (WaveOut on Windows, AudioQueue on macOS, ALSA on Linux, calling the system libraries through `LibraryImport`), its source copied into the library's `Audio/` folder — plugins ship separately and cannot share assemblies.
- The receive thread only hands data over and never blocks: the player gathers it into 40 ms buffers and queues at most 8 of them at the output (about 320 ms), so latency stays bounded. When the network delivers faster than the device plays (clock drift, a burst after a stall), the newest data is dropped — QEMU itself drops audio under back-pressure.
- The receive thread only hands data over and never blocks: the player gathers it into 40 ms buffers and queues at most 8 of them at the output (about 320 ms). Latency is bounded in **time**, not just in bytes: data that waited more than 600 ms after it was received (a burst after a stall, a device that fell behind) is skipped, so playback catches up with the server instead of carrying the backlog for the rest of the session — QEMU keeps capturing in real time, so late audio is not worth playing. Each skip logs how many milliseconds were skipped. Only when the hand-over queue itself is full (about 1 MiB, which only a stalled device reaches) is the newest data dropped.
- The output uses the same playout timing as the RDP plugin: it waits instead of failing when its queue is full, the stall timeout starts when a buffer is actually admitted, new data wakes the playback worker at once, and clock-drift correction stops speeding up once the reserve runs thin.
- A failing output device stops audio only: the status bar says so once (hover the status bar to see it again) and a disable message stops the server capturing; the desktop is unaffected. An audio buffer that is not whole frames stops audio the same way (the data is skipped and the stream stays in step); one over 1 MiB is a protocol error.
- While audio is on, the status bar shows *Audio*.

Expand Down Expand Up @@ -104,7 +105,7 @@ Install the signed `.vpx` from the same release as the other plugins and create

## Verification

`tests/VelaShell.Plugin.Vnc.Tests` runs the real `VncSession` against a scripted in-process RFB server (`FakeVncServer`) that checks the client's bytes from the server side: every version mapping; None / VNC / ARD (the fake server decrypts the credentials) / VeNCrypt X.509 with a self-signed certificate (trust prompt, then a pinned reconnect; Plain credentials inside TLS; a changed certificate); Auto's fallback from anonymous-only VeNCrypt; DES against the FIPS 46-3 known answer (and, on Windows, the platform cipher); every encoding through the real reader and framebuffer, including malformed-data rejection; incremental requests, keysym vs. QEMU scan-code messages, both clipboards in both directions, the SetDesktopSize round trip, paused display, clean close vs. reset vs. protocol error; continuous updates and fences (asking for them or not, turning them on for the whole desktop after the confirmation and requesting no more, requesting each update without it, the fence answer's flags and payload, re-enabling after a resize, off when hidden and on again when shown, falling back to requests when the server ends them); QEMU audio's confirmation, the set-format and enable bytes, PCM reaching the output in order, a device failure stopping audio only and sending disable, rejection of a buffer that is not whole frames, and dropping instead of blocking when the output falls behind; UltraVNC file transfer against both LibVNC and UltraVNC server behaviour (access, drive and folder listings, Unicode names and block size, downloading compressed and raw packets, uploading compressed blocks, refusals, cancel aborting, commands, timeouts, a server without it closing the connection); and on the plugin side manifest vs. registration, all five languages complete with matching placeholders, settings parsing, exception translation, auto-reconnect rules, the headless UI (including the file panel's browsing, upload replace confirmation, delete confirmation, download, rename validation and error display, and the audio status and failure notice), JPEG decoding through Skia, and unloading in a collectible load context.
`tests/VelaShell.Plugin.Vnc.Tests` runs the real `VncSession` against a scripted in-process RFB server (`FakeVncServer`) that checks the client's bytes from the server side: every version mapping; None / VNC / ARD (the fake server decrypts the credentials) / VeNCrypt X.509 with a self-signed certificate (trust prompt, then a pinned reconnect; Plain credentials inside TLS; a changed certificate); Auto's fallback from anonymous-only VeNCrypt; DES against the FIPS 46-3 known answer (and, on Windows, the platform cipher); every encoding through the real reader and framebuffer, including malformed-data rejection; incremental requests, keysym vs. QEMU scan-code messages, both clipboards in both directions, the SetDesktopSize round trip, paused display, clean close vs. reset vs. protocol error; continuous updates and fences (asking for them or not, turning them on for the whole desktop after the confirmation and requesting no more, requesting each update without it, the fence answer's flags and payload, re-enabling after a resize, off when hidden and on again when shown, falling back to requests when the server ends them); QEMU audio's confirmation, the set-format and enable bytes, PCM reaching the output in order, a device failure stopping audio only and sending disable, rejection of a buffer that is not whole frames, dropping instead of blocking when the output falls behind, and skipping late audio to catch up after a stall; UltraVNC file transfer against both LibVNC and UltraVNC server behaviour (access, drive and folder listings, Unicode names and block size, downloading compressed and raw packets, uploading compressed blocks, refusals, cancel aborting, commands, timeouts, a server without it closing the connection); and on the plugin side manifest vs. registration, all five languages complete with matching placeholders, settings parsing, exception translation, auto-reconnect rules, the headless UI (including the file panel's browsing, upload replace confirmation, delete confirmation, download, rename validation and error display, and the audio status and failure notice), JPEG decoding through Skia, and unloading in a collectible load context.

**Observed with the original plugin:** on Ubuntu 24 with TigerVNC 1.13.1, sending message type 7 caused an `unknown message type 7` error and disconnected the desktop. This is evidence of the original compatibility problem, not validation of the fix. **The fix has not been built, tested or verified with a real client/server**: local command execution was unavailable during this update. The list above describes test scope, not a passing result.

Expand Down
30 changes: 30 additions & 0 deletions zh/host/Telnet与串口可行性调研.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@
> - **§五.4「无法自动化验证」依然成立**:串口没有环回可用。字节路径(读循环、EOF 归一化、
> 换行状态机、写序列化、控制线动作)靠 `FakeSerialPort` 替身钉住;端到端仍需真硬件或
> `socat` / `com0com`。
>
> **2026-12-01 修订说明(两个插件的回显、背压与关闭路径)**
>
> 对照实现复查两个插件后修了一批问题(velashell-plugins
> [#195](https://github.com/VelaShell/velashell-plugins/pull/195)),行为变化如下:
>
> - **§3.6 的本地回显不再原样回送按键。** 两个插件各带一份 `LocalEchoRenderer`(插件各自分发,
> 不能共享程序集),做的是终端驱动在 ECHO + ICANON 下做的那部分显示:CR / LF / CR LF 一律
> 显示成换行;退格擦掉本行上一个字符,不擦过行首,宽字符擦两格;方向键等控制序列与其余
> C0 控制字符不显示。此前 Telnet 回车只回行首(对端的应答随即盖掉这一行)、退格(DEL)
> 在屏幕上什么都不发生;串口在"回车发 LF"时回显成阶梯。线上字节不受影响。
> - **Telnet 协商按 RFC 1143 记录主动请求。** 握手里发出的 WILL / DO 记成"待确认":对端回来的
> DO / WILL 是确认,DONT / WONT 是拒绝,都不再应答。§4.2 的最小协商集不变,只是每个选项少了
> 一轮多余的往返。
> - **Telnet 子协商有上限。** 载荷只保存前 1KB(插件只处理 TERMINAL-TYPE SEND);超过 64KB 仍没等到
> `IAC SE` 就当它坏了、回到数据态 —— 否则一台发了 `IAC SB` 却不发 `IAC SE` 的设备会让之后的
> 全部输出被当成子协商吞掉。
> - **Telnet 输出有背压。** 读泵到终端引擎之间的通道约 1MB 封顶,满了就停读套接字,压力经 TCP 窗口
> 顶回对端,而不是把对端按网速吐出的数据全部收进内存。
> - **§五 Telnet 第 3 条(CRLF 改写的作用域)补一处边界**:粘贴的 CRLF 被切在两次写入之间时,
> 不再多发一个 LF(跨写入记着上一次是否以裸 CR 收尾)。串口的出方向换行改写同样处理。
> - **串口发送节流**在专用线程上按毫秒精度等待:`Task.Delay` 在 Windows 上的粒度约 15.6ms,
> "每字节 1ms"实际会变成 15ms。节流写不再在调用方线程上阻塞;CR LF 只算一行、只等一次行间隔;
> 关会话即停。
> - **串口打开端口改为后台执行、可取消。** `SerialPort.Open` 是阻塞调用(设备不在场的蓝牙 COM 口能卡
> 十几秒),而且中途打断不了:取消立即生效,那次迟到的打开返回后由插件把端口关掉。
> - **§4.1 端口枚举的 macOS 结论再补一层**:下拉本来只列 `/dev/cu.*`,但手输或旧配置里的
> `/dev/tty.xxx` 现在打开时会自动换成存在的 `/dev/cu.xxx`(同一个硬件),不再一直等载波。
> - Telnet、串口(以及 S3)插件停用时退订 `LocaleChanged`。此前用匿名 lambda 订阅、从不退订,
> 宿主的事件表一直握着插件实例,可收集 ALC 卸不掉。

---

Expand Down
Loading