RemoHop

中文

Docs

RemoHop architecture

RemoHop is a P2P remote-control tool. One static Go binary, remohop, is the controlling CLI, the controlled host daemon, the rendezvous server, the browser gateway and the MCP server. The user guide is in en/ and zh/; this page is for people reading the code.

 controlling machine                                       controlled machine
┌──────────────────────────┐   UDP hole punch + QUIC     ┌──────────────────────────┐
│ remohop <ID> shell ...   │◄═══════════════════════════►│ remohop host             │
│ remohop mcp  (AI agents) │   end-to-end encrypted      │  shell / fs / forward    │
└─────────┬────────────────┘                             │  clip / desktop ...      │
          │                                              └────────────┬─────────────┘
          │  signalling (who is where)                                │
          └──────────────►  remohop signal  ◄─────────────────────────┘
                    (optional relay and websocket bridge, off by default)

Layers

LayerPackageJob
Framinginternal/wirelength-prefixed JSON messages and typed binary frames
Sessioninternal/peerConn: an authenticated session multiplexing service streams
Rendezvousinternal/signalID allocation, presence, candidate exchange, the optional relay and websocket bridge, optional accounts (remohop signal)
NAT traversalinternal/natcandidate gathering, UDP hole punching
Websocket bridgeinternal/wsdgramUDP datagrams over a WebSocket (HTTPS proxy aware), for networks without UDP
Authenticationinternal/authidentity keys, password PAKE bound to the TLS channel, pairing
Host daemoninternal/hostdremohop host: registers, accepts sessions, serves peer.HostServices
Diallinginternal/dialremohop <ID> ...: resolve, punch, connect, authenticate → *peer.Conn
Servicesinternal/svc/*one package per feature, owning host handler + client API + CLI
X11 discoveryinternal/x11dispwhich display a daemon should use, and its Xauthority cookie
CLIinternal/cli, cmd/remohopcommand registry and dispatcher
Backgroundinternal/bg-b detaching, remohop ps, remohop stop
MCPinternal/mcpremohop mcp: the services as MCP tools for AI agents
Accountsinternal/accountclient side of accounts (remohop login, remohop account), the signed membership log, host-side account-trust
Meshinternal/meshremohop net: the mesh network of an account's devices, running inside the host daemon (see net.md)
Tailscaleinternal/tailnetdetects a running Tailscale and offers its addresses as candidate paths
Web gatewayinternal/webremohop web: a browser UI that is the client of a normal session
Quick supportinternal/quick, cmd/remohop-quickremohop quick and the double-click RemoHop.exe / RemoHop.app
OS servicesinternal/service, internal/unattendedremohop service install (systemd, launchd, Windows service); Windows console access for --unattended
Inputinternal/injectpointer and keyboard injection (XTEST on X11, Quartz events on macOS, SendInput on Windows)
Permissionsinternal/permwhich feature switch each host service belongs to
Mobile coreinternal/mobile, mobile/the in-process gateway of the Android and iOS apps
Grantsinternal/grantscoped, expiring access for agents: allow-list parsing, path and command checks, the Guard services ask, asciicast recording (stored and enforced by internal/hostd, see agents.md)

Services

PackageCommandsNotes
svc/shellshell, spawn, jobs, logs, killPTY sessions that outlive the connection; exec with separate stdout/stderr; detached jobs with on-disk logs
svc/fsls, cp, send, sync, mount, umountrfs is the pipelined file protocol, xfer copies and syncs, mount is the FUSE filesystem or a loopback WebDAV server
svc/forwardforward, unforwardone stream per TCP connection, UDP forwards; reverse forwards call back into the client
svc/clipcliptext and image sync, one-shot get/set, local history
svc/screenshotscreenshotpure-Go X11 capture on Linux; platform capture on macOS and Windows
svc/inputclick, move, type, press, scrollsingle pointer and keyboard actions through internal/inject
svc/desktopdesktopH.264 or AV1 video (and optional Opus audio) from an ffmpeg subprocess on the host, WebCodecs viewer served on the client's loopback, input through internal/inject
svc/vpnvpnIP packets through the session (TUN on Linux, utun on macOS, Wintun on Windows)
svc/serialseriala host serial port as a local virtual port
svc/usbusbUSB/IP export of allowed host devices (Linux)
svc/wakewake, wolWake-on-LAN, sent locally or by the host
svc/sysinfoinfowhat kind of machine the host is

The desktop service is the one place the binary leans on an external program: capturing and encoding in ffmpeg is what makes hardware video encoders reachable without cgo. The host needs ffmpeg only for desktop.

Session model

A peer.Conn is one QUIC connection. Every feature opens its own bidirectional streams with conn.Open(ctx, "service", req):

  1. opener writes a JSON header {"service": "...", "req": {...}}
  2. acceptor looks the service up and answers {"ok": true} or {"ok": false, "error": "..."}
  3. from there the stream carries whatever the service defines, built from wire.WriteJSON/ReadJSON and wire.WriteFrame/ReadFrame

Hosts expose peer.HostServices (services register with peer.Handle from init()). Clients expose nothing unless they opt in per session with conn.HandleLocal, so a host can never open a shell on the machine that is controlling it.

Connection establishment

  1. Host generates an Ed25519 identity, opens one UDP socket and connects to the rendezvous server over QUIC from that socket. The server sees the socket's public (reflexive) address, verifies key possession and assigns a stable 9-digit ID to the key.
  2. Client does the same from its own socket and asks for the ID.
  3. The server sends each side the other's candidates (reflexive address plus local interface addresses). It never sees session traffic.
  4. Both sides send punch probes to every candidate from the same socket, then the client opens a QUIC connection to the host on the first path that answers. Both ends of that connection reuse the punched socket.
  5. Authentication: QUIC's TLS 1.3 gives encryption but the peers have no PKI, so on the first stream they run CPace (a balanced PAKE) over the password, with the TLS exporter of this exact connection mixed in. A man-in-the-middle — including a malicious rendezvous server — ends up with different exporters on its two legs and fails the key confirmation, and learns nothing that helps guess the password offline. The host rate-limits failed attempts.
  6. The credential is either the host's temporary password or a high-entropy token minted by remohop <ID> pair, so paired clients (and AI agents) reconnect without prompts.

If no direct path can be punched (for example two symmetric NATs), the client uses the rendezvous server's relay when its operator enabled one (remohop signal --relay); the relay carries the same QUIC session and sees only ciphertext. Without a relay the connection fails with a diagnostic. A peer whose network blocks UDP can reach the server through its websocket bridge (internal/wsdgram); such sessions always use the relay. A shared Tailscale tailnet is used as one more candidate path when both machines are on it.

Trust boundaries

Testing

Conventions for feature packages