Show HN: Tt – 基于 WebRTC 的 P2P 终端共享

2作者: artpar6 个月前
我制作了这个工具,可以在移动设备上使用笔记本电脑的终端会话,而无需通过服务器传输数据。 使用方法:`tt start -p mypassword` → 获取一个 URL(二维码) → 在浏览器中打开 → 输入密码 → 连接成功。 它通过直接的 WebRTC 数据通道在你的机器和浏览器之间建立连接。 信令服务器是一个 Cloudflare Worker,它交换大约 2KB 的 sdp/ice 元数据后就会退出。密码永远不会被传输 - argon2id 在两端本地派生 256 位密钥。所有终端输入/输出在进入数据通道之前都会经过 nacl secretbox 加密。底层使用 DTLS 进行双重加密,但我希望即使在信令期间,中继也无法看到任何有用的信息。 使用 Go + pion/webrtc,大约 14k 行代码。浏览器端使用 xterm.js + webcrypto 进行 argon2id 加密。STUN 默认,TURN 用于对称 NAT。 我的用例:当我不坐在办公桌前时,通过手机检查 Claude 代码的运行情况。酒店 Wi-Fi,移动数据不稳定。花时间处理了 TURN 备用方案、带有重新连接的保活机制、断开连接期间的缓冲写入。PWA 可以在主屏幕上运行,并且在切换应用程序时也能正常工作。在 3G 网络下也能正常运行。 权衡:ICE 收集需要 2-5 秒才能连接。浏览器无法发起连接,需要在主机上使用 CLI。代码 24 小时后过期。 单个二进制文件,无依赖。支持守护进程模式,用于多个会话。使用竞争检测器进行测试,使用混沌测试模拟断开连接,模拟网络状况。加密和 WebRTC 的代码覆盖率约为 72%。 [https://github.com/artpar/terminal-tunnel](https://github.com/artpar/terminal-tunnel) PS:默认中继运行在我的 Cloudflare 免费套餐上,因此不提供任何保证。你可以自托管 Worker 或在本地运行 tt 中继。
查看原文
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&#x2F;ice metadata then gets out of the way. Password never transmitted - argon2id derives 256-bit key locally on both ends. All terminal i&#x2F;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&#x2F;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:&#x2F;&#x2F;github.com&#x2F;artpar&#x2F;terminal-tunnel" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;artpar&#x2F;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.