Files
Meshray-Manager/docs/core 重构状态_v2.2.md
T
2026-06-30 15:14:37 +08:00

154 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Core 模块重构状态报告 - v2.2.0
## ✅ 已完成的目录结构调整
### connect/ 目录 ✅
```
✅ strategy.go - 9 层策略调度
✅ stun.go - STUN 协议实现(新建,120 行)
✅ direct.go - Direct-UDP 工厂(重构,86 行)
✅ fake_tcp.go - FakeTCP 工厂(保留)
✅ real_tcp.go - RealTCP 工厂(保留)
✅ turn.go - TURN 工厂(重构,310 行)
✅ turn_quic.go - TURN-QUIC 工厂(保留)
✅ ice.go - ICE 工厂(待更新)
✅ ws.go - WS 工厂(待完善)
```
### transport/ 目录 ✅
```
✅ bind_port.go - 本地端口 Bind
✅ relay.go - Read/Write 循环(重构)
✅ wgparse.go - WG 包解析(新建)
```
### pool/ 目录 ✅
```
✅ connpool.go - 连接池(新建)
```
### proto/ 目录 ✅
```
✅ core.proto - gRPC 接口定义(新建)
✅ core_grpc.go - gRPC 服务实现(移动)
```
### 根目录 ✅
```
✅ core.go - Core 主实例(⏳ 待修复)
✅ engine.go - Core 引擎(新建)
✅ bind.go - 连接管理(重命名)
✅ metrics.go - 监控指标(新建)
```
---
## ⏳ 待修复的文件
### core.go(阻塞编译)
**问题列表**
1.`interceptor *transport.Interceptor` - Interceptor 已废弃
2.`NewCoreServiceServer()` - 应该从 `proto/` 包导入
3.`c.relay.Dial()` - Relay 没有 Dial 方法
4.`transport.NewInterceptor()` - 已废弃
5.`c.relay.SetInterceptor()` - 已废弃
**需要修改为**
```go
// 1. 删除 Interceptor 字段
type Core struct {
// ...
// interceptor *transport.Interceptor ❌ 删除
}
// 2. 使用正确的 gRPC 服务注册
import "git.zkcoi.com/zkcoi/meshray/proto"
coreServiceServer := proto.NewCoreServiceServer(c, c.logger)
// 3. 使用 Relay.DialPeer 或其他正确方法
conn, err := c.relay.DialPeer(ctx, peerID, config)
// 4-5. 删除 Interceptor 相关代码
// 直接使用 CoreBind 替代
```
---
## 📊 重构进度
### 已完成 ✅ (80%)
| 模块 | 状态 | 说明 |
|------|------|------|
| **connect/stun.go** | ✅ 完成 | STUN 协议实现 |
| **connect/direct.go** | ✅ 完成 | Direct-UDP 工厂 |
| **connect/turn.go** | ✅ 完成 | TURN 工厂(自包含) |
| **proto/core.proto** | ✅ 完成 | gRPC 接口定义 |
| **proto/core_service_server.go** | ✅ 完成 | gRPC 服务实现 |
| **engine.go** | ✅ 完成 | Core 引擎 |
| **metrics.go** | ✅ 完成 | 监控指标 |
| **pool/connpool.go** | ✅ 完成 | 连接池 |
### 待完善 ⏳ (20%)
| 文件 | 状态 | 需要完成 |
|------|------|----------|
| **core.go** | ⏳ 阻塞 | 修复旧 API 引用 |
| **connect/ice.go** | ⏳ 待更新 | 调用新的 stun.go |
| **connect/ws.go** | ⏳ 待完善 | 完整 WS 协议实现 |
| **fake_tcp.go** | ⏳ 待验证 | 确认工厂函数名 |
| **real_tcp.go** | ⏳ 待验证 | 确认工厂函数名 |
---
## 🎯 下一步行动
### P0 - 立即修复(阻塞编译)
1. **修复 core.go**
```go
// 删除 Interceptor 相关代码
// 修复 gRPC 服务注册
// 修复 Relay 调用
```
2. **生成 proto 代码** ⏳
```bash
protoc --go_out=. --go-grpc_out=. core/proto/core.proto
```
### P1 - 后续完善
3. **更新 ice.go** ⏳
- 调用新的 `stun.go`
4. **完善 ws.go** ⏳
- 添加完整的 WS 协议实现
5. **添加单元测试** ⏳
- `stun_test.go`
- `direct_test.go`
- `turn_test.go`
---
## 🎉 重构成果
### 代码质量提升
-**减少目录层级**3 层 → 2 层
-**消除过度抽象**:删除 client/ 目录
-**实事求是**:按"是否被多处调用"组织文件
-**职责清晰**connect/ 管建连,transport/ 管传输
### 代码统计
- **新增文件**7 个(stun.go, direct.go, turn.go, engine.go, metrics.go, connpool.go, wgparse.go
- **重构文件**3 个(relay.go, bind.go, core_service_server.go
- **删除文件**4 个(整个 client/ 目录)
- **净减少**~20KB 代码
---
*更新时间:2026-03-24 03:00*
*版本:v2.2.0*
*状态:⏳ 目录结构完全对齐,代码重构 80% 完成*