# 第九章 Gateway 控制平面与协议机制

本章切换到系统内核视角，讨论 OpenClaw Gateway 的控制平面职责、连接生命周期、事件一致性与设备配对及信任建立。通过本章，你将理解一个健壮的 Gateway 如何通过精心设计的协议与状态机，让分布式智能体系统变得“可预测、可恢复、可审计”。

理解这一章的价值在于：同样的模型能力，在不同控制平面设计下会呈现完全不同的稳定性与安全性。

## 本章内容导读

本章包括以下几个小节：

* [**9.1 架构全景与五平面框架**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/9.1_architecture_overview.md)：用五平面架构（控制、数据、上下文、信任、可观测性）建立统一的系统设计视角。
* [**9.2 控制平面职责与边界**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/9.2_control_plane.md)：深入控制平面的五大职责——认证、路由、会话管理、策略执行与故障恢复。
* [**9.3 连接生命周期：握手、认证与心跳**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/9.3_ws_handshake.md)：理解 WebSocket 长连接的完整生命周期、握手、认证与保活机制。
* [**9.4 事件幂等与一致性保障**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/9.4_event_idempotency.md)：掌握事件驱动系统的幂等与一致性：用 `idempotencyKey` 处理副作用重试，用 `seq` gap 触发状态刷新。
* [**9.5 渠道配对与本地信任建立**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/9.5_pairing_trust.md)：理解渠道 sender 配对、设备配对与 setup code / bootstrap token 的边界，以及吊销与轮换的治理方法。
* [**9.6 本章小结**](/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol/summary.md)：关键结论与读者自检。

## 学习目标

完成本章的阅读后，你将能够：

1. **理解架构**：从控制平面的视角看 Gateway 的整体设计。
2. **掌握协议**：理解 WebSocket 连接的完整生命周期。
3. **保障一致性**：设计事件驱动系统中的幂等与一致性机制。
4. **建立信任**：通过设备配对与密钥管理建立安全的信任基础。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/openclaw_guide/di-san-bu-fen-shi-xian-yuan-li-yu-gong-cheng-luo-di/09_gateway_protocol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
