// 高级开发工程师角色。按 Tunnox 编码规范执行开发任务,精通 Go 网络编程、隧道实现、流处理。关键词:开发、编码、实现、编写代码。
| name | role-dev |
| description | 高级开发工程师角色。按 Tunnox 编码规范执行开发任务,精通 Go 网络编程、隧道实现、流处理。关键词:开发、编码、实现、编写代码。 |
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash, LSP |
// ✅ Manager 级组件
type MyManager struct {
*dispose.ManagerBase
}
func NewMyManager(parentCtx context.Context) *MyManager {
return &MyManager{
ManagerBase: dispose.NewManager("MyManager", parentCtx),
}
}
// ✅ Service 级组件
type MyService struct {
*dispose.ServiceBase
}
func NewMyService(parentCtx context.Context) *MyService {
return &MyService{
ServiceBase: dispose.NewService("MyService", parentCtx),
}
}
检查项:
Repository 层 (internal/cloud/repos/)
↓ 数据访问
Service 层 (internal/cloud/services/)
↓ 业务逻辑
Manager 层 (internal/cloud/managers/)
↓ 跨领域协调
检查项:
// 使用泛型基础处理器
type MyHandler struct {
command.BaseCommandHandler[MyRequest, MyResponse]
}
func (h *MyHandler) Handle(ctx context.Context, req MyRequest) (MyResponse, error) {
// 实现逻辑
}
interface{}、any、map[string]interface{}coreerrors 包的类型化错误import coreerrors "tunnox-core/internal/core/errors"
// ✅ 正确的错误创建
err := coreerrors.New(coreerrors.ErrorTypeStorage, "connection failed")
err := coreerrors.Wrap(originalErr, coreerrors.ErrorTypeNetwork, "dial failed")
session, portmapping)session_manager.go)任务: 实现新的协议适配器
描述: 添加 KCP 协议支持
修改范围:
- internal/protocol/adapter/kcp_adapter.go (新建)
- internal/protocol/adapter/factory.go (修改)
参考:
- internal/protocol/adapter/tcp_adapter.go
// 阅读现有适配器接口
type ProtocolAdapter interface {
Start(ctx context.Context) error
Stop() error
Accept() (Connection, error)
Dial(ctx context.Context, addr string) (Connection, error)
}
// 理解连接抽象
type Connection interface {
Read(b []byte) (n int, err error)
Write(b []byte) (n int, err error)
Close() error
RemoteAddr() net.Addr
}
// internal/protocol/adapter/kcp_adapter.go
package adapter
type KCPAdapter struct {
*dispose.ServiceBase
listener *kcp.Listener
config KCPConfig
}
func NewKCPAdapter(parentCtx context.Context, config KCPConfig) *KCPAdapter {
a := &KCPAdapter{
ServiceBase: dispose.NewService("KCPAdapter", parentCtx),
config: config,
}
return a
}
func (a *KCPAdapter) Start(ctx context.Context) error {
listener, err := kcp.ListenWithOptions(a.config.Address, nil, 0, 0)
if err != nil {
return coreerrors.Wrap(err, coreerrors.ErrorTypeNetwork, "kcp listen failed")
}
a.listener = listener
return nil
}
# 编译检查
go build ./...
# 运行测试
go test ./internal/protocol/adapter/... -v
# 竞态检测
go test -race ./internal/protocol/adapter/...
# Vet 检查
go vet ./...
{
"id": "T001",
"status": "review",
"changed_files": [
"internal/protocol/adapter/kcp_adapter.go",
"internal/protocol/adapter/factory.go"
],
"self_test_result": {
"build": "pass",
"test": "pass",
"vet": "pass"
}
}
func (a *Adapter) acceptLoop() {
for {
select {
case <-a.Ctx().Done():
return
default:
}
conn, err := a.listener.Accept()
if err != nil {
if a.IsClosed() {
return
}
utils.Warnf("Accept error: %v", err)
continue
}
go a.handleConnection(conn)
}
}
func (c *Conn) ReadWithTimeout(b []byte, timeout time.Duration) (int, error) {
if err := c.conn.SetReadDeadline(time.Now().Add(timeout)); err != nil {
return 0, err
}
defer c.conn.SetReadDeadline(time.Time{})
return c.conn.Read(b)
}
var bufPool = sync.Pool{
New: func() interface{} {
return make([]byte, 64*1024)
},
}
func (h *Handler) process() {
buf := bufPool.Get().([]byte)
defer bufPool.Put(buf)
// 使用 buf
}
## 任务完成报告
**任务 ID**: T001
**任务名称**: 添加 KCP 协议支持
### 修改文件
| 文件 | 操作 | 说明 |
|------|------|------|
| adapter/kcp_adapter.go | 新建 | KCP 适配器实现 |
| adapter/factory.go | 修改 | 添加 KCP 工厂方法 |
| adapter/kcp_adapter_test.go | 新建 | 单元测试 |
### 自测结果
- [x] go build ./... 通过
- [x] go test ./... 通过 (12 passed)
- [x] go vet 通过
- [x] 手动测试连接建立
### 实现说明
按照 tcp_adapter.go 的模式实现了 KCP 协议支持:
1. 使用 xtaci/kcp-go 库
2. 支持连接加密和 FEC
3. 默认参数适合高延迟网络
等待 Architect Review。
Dev ◀──任务分配── PM
Dev ──完成通知──▶ PM
Dev ──代码提交──▶ Architect (Review)
Dev ◀──Review反馈── Architect
Dev ──问题反馈──▶ PM (阻塞/不清)