展示HN:Tt – 基于WebRTC的点对点终端共享
我制作了这个工具,以便在手机上使用我的笔记本终端会话,而不需要数据经过服务器。<p>使用命令 tt start -p mypassword → 获取一个 URL(二维码)→ 在浏览器中打开 → 输入密码 → 连接成功。<p>在你的设备和浏览器之间建立直接的 WebRTC 数据通道。<p>信令服务器是一个 Cloudflare Worker,交换约 2KB 的 SDP/ICE 元数据后就不再干预。密码从未传输 - argon2id 在两端本地生成 256 位密钥。所有终端输入输出在到达数据通道之前都经过 NaCl SecretBox 加密。底层使用 DTLS 进行双重加密,但我希望中继在信令期间也看不到任何有用的信息。<p>使用 Go 和 Pion/WebRTC,代码量约 14k 行。浏览器使用 xterm.js 和 WebCrypto 进行 argon2id。默认使用 STUN,TURN 适用于对称 NAT。<p>我的使用案例:在不在办公桌前时,通过手机检查 Claude 代码的运行情况。酒店 WiFi 和不稳定的移动数据。花了一些时间在 TURN 回退、保持连接和断开时的缓冲写入上。作为 PWA,这个工具可以从主屏幕启动,并在应用切换时保持有效。在 3G 网络下表现尚可。<p>权衡:ICE 收集在连接时需要 2-5 秒。浏览器无法发起连接,需在主机上使用 CLI。代码在 24 小时后过期。<p>单一二进制文件,无依赖。支持多会话的守护进程模式。进行了竞争检测测试、断开连接的混沌测试和网络条件模拟。加密和 WebRTC 的代码覆盖率约为 72%。<p><a href="https://github.com/artpar/terminal-tunnel" rel="nofollow">https://github.com/artpar/terminal-tunnel</a><p>附言:默认中继运行在我的 Cloudflare 免费套餐上,因此没有保证。你可以自托管 Worker 或在本地运行 tt relay。
查看原文
Made this to use my laptop terminal session on mobile without data going through a server.<p>tt start -p mypassword → get a URL (qrcode) → open in browser → enter password → connected.<p>Direct webrtc datachannel between your machine and browser.<p>Signaling server is a cloudflare worker, exchanges ~2KB of sdp/ice metadata then gets out of the way. Password never transmitted - argon2id derives 256-bit key locally on both ends. All terminal i/o gets nacl secretbox encryption before hitting the datachannel. double encrypted with dtls underneath but I wanted the relay to see nothing useful even during signaling.<p>go + pion/webrtc, about 14k loc. browser is xterm.js + webcrypto for argon2id. stun default, turn for symmetric nat.<p>my use case: checking on claude code runs from my phone when im not at my desk. hotel wifi, spotty mobile data. spent time on turn fallback, keepalive with reconnection, buffered writes during disconnects. pwa so it works from home screen and survives app switching. holds up ok on 3g.<p>Trade-offs: ice gathering takes 2-5s on connect. browser cant initiate, need cli on host. codes expire 24h.<p>Single binary, no deps. daemon mode for multiple sessions. tests with race detector, chaos tests for disconnects, network condition simulation. crypto and webrtc at ~72% coverage.<p><a href="https://github.com/artpar/terminal-tunnel" rel="nofollow">https://github.com/artpar/terminal-tunnel</a><p>ps: default relay runs on my cloudflare free tier so no guarantees. you can self-host the worker or run tt relay locally.