Files
proxy/README.md
2025-05-12 15:13:48 +08:00

52 lines
1.3 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.
## 开发相关
### 目录结构
server/fwd: 服务端核心代码
- core: 核心代码,目前主要是连接管理
- dispatcher: 请求处理器,负责解析传入协议,并将请求分发到对应的处理器
- http: http 处理器,负责处理 http 请求
- socks: socks5 处理器,负责处理 socks5 请求
- repo: 状态仓库,所有有状态数据都通过 repo 中的接口与外部服务交互
### 更新测试环境
1. 构建项目
2. 使用测试配置 `.env.test` 远程启动 docker
### 转发服务结束时资源清理
1. 关闭接听端口防止新连接接入user, data, ctrl
2. 通知并等待所有正在运行的 conn 处理协程全部关闭user, data, ctrl
3. 结束所有保存且未使用的 conn 连接user, ctrl
### 代码清理
检查 slog 级别:
ERR: 除非有必要,否则全部 error 都使用 `errors.Wrap()` 包裹(如果下游有返回 err并附带本层业务信息return 到上层统一打印
其他级别日志就地打印Info 只用来跟踪关键流程
## 协议
### 建立连接
客户端(控制通道):
`version(1)` `id_len(1)` `id_buf(n)`
服务端(控制通道):
`status(1)`
### 开启代理
服务端(控制通道):
`dst_len(1)` `dst_buf(n)` `tag_len(1)` `tag_buf(n)`
客户端(数据通道):
`status(1)` `tag_len(1)` `tag_buf(n)`