# GopherNode **Repository Path**: Lin-carp/GopherNode ## Basic Information - **Project Name**: GopherNode - **Description**: 这个是GopherHub的搭配节点端代码,节点代码 - **Primary Language**: Go - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-01 - **Last Updated**: 2026-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GopherNode (MQTT + WSPipe Device Client) 当前程序通过 `go run .` 同时启动: - MQTT 客户端(订阅命令主题) - WSPipe 设备端客户端(将本地 shell 通过 WebSocket 透传到服务端) ## 运行 ```bash go mod tidy go run . ``` 可选指定配置文件: ```bash go run . ./config.yaml ``` ## 配置参数 配置文件为 `config.yaml`。 ### MQTT - `mqtt_client.enabled` - `mqtt_client.host` - `mqtt_client.port` - `mqtt_client.client_id` - `mqtt_client.device_id` - `mqtt_client.username` - `mqtt_client.password` ### WSPipe Device Client - `wspipe_client.enabled`:是否启用 wspipe 客户端 - `wspipe_client.server_ws_url`:例如 `ws://127.0.0.1:8088/api/wspipe/device` - `wspipe_client.device_id`:设备 ID - `wspipe_client.secret`:注册密钥(register 第一包) - `wspipe_client.shell_path`:本地 shell 路径 ## 协议行为 设备端连接后发送: ```json {"type":"register","device_id":"aicvs002","secret":""} ``` 支持接收: - `input`:`data` 为 base64,写入对应 `session_id` 的 stdin - `resize`:当前实现记录日志(未启用 pty 时不崩溃) - `registered` - `kick`:收到后主动断开并触发重连 支持上报: - `output`:stdout/stderr 分块读取,base64 编码后上报 - `pong`(收到 `ping` 时回复) ## Linux 示例 ```yaml wspipe_client: enabled: true server_ws_url: "ws://127.0.0.1:8088/api/wspipe/device" device_id: "aicvs002" secret: "your-wspipe-secret" shell_path: "/bin/bash" ``` ## Windows 示例 ```yaml wspipe_client: enabled: true server_ws_url: "ws://127.0.0.1:8088/api/wspipe/device" device_id: "aicvs002" secret: "your-wspipe-secret" shell_path: "powershell.exe" ``` ## 本地联调步骤 1. 启动你的服务端(含 `/api/wspipe/device` 和前端终端页) 2. 启动本程序: ```bash go run . ``` 3. 观察日志出现: - `connecting ...` - `connected` - `register sent ...` - `registered ok` 4. 在前端打开设备终端,输入命令(如 `ls`) 5. 前端发送 `input` 到某个 `session_id` 后,设备端会自动创建该会话 shell 并回传 `output` ## 说明 - 断线自动重连:指数退避(1s -> 2s -> 4s ... 最大 30s) - 支持多 `session_id` 并发,每个会话独立 shell 进程 - 若服务端踢下线(`kick`),客户端会立即重连并重新注册