Skip to content

添加 Unix domain socket 代理实现#78

Merged
imgk merged 1 commit intoimgk:mainfrom
0x1306a94:feature/unix_proxy
May 14, 2025
Merged

添加 Unix domain socket 代理实现#78
imgk merged 1 commit intoimgk:mainfrom
0x1306a94:feature/unix_proxy

Conversation

@0x1306a94
Copy link
Contributor

  • 在某些情况下,直接和目标服务器进行通信可能会直接被阻断。而这个时候可能需要调整部署方案。例如
sequenceDiagram
    participant Client
    participant CaddyTrojan
    participant LocalRelay
    participant TargetServer

    Client->>CaddyTrojan: 建立 trojan 连接
    CaddyTrojan->>LocalRelay: 使用 Unix Socket 转发请求
    LocalRelay->>TargetServer: 封装私有协议,请求目标服务
    TargetServer-->>LocalRelay: 返回响应数据
    LocalRelay-->>CaddyTrojan: 通过 Unix Socket 传回响应
    CaddyTrojan-->>Client: 返回最终数据
Loading
  • 虽然这类通信也可通过本地 loopback 地址实现(如 127.0.0.1:xxxx),但会引入不必要的网络栈开销。

// UnixProxy is ...
type UnixProxy struct {
Path string `json:"path"`
trojan.Dialer `json:"-,omitempty"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个trojan.Dialer没有必要吧,建议去掉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

// +------------------+--------+--------------+------------+-------------+-------------+--------+
//
// * AddrLen only exists when AddrType = 0x03 (domain)
func writeTrojanUnixHandshake(conn net.Conn, network, addr string) error {
Copy link
Owner

@imgk imgk May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我不太了解 magic "caddy-trojan" 设置的原因,那对应的服务端是不通用的吗?只有特定服务端才支持?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是为了标识来自于你这个插件。理论上来说这个是你这个插件特有的

@0x1306a94 0x1306a94 force-pushed the feature/unix_proxy branch from 751a23e to 23cef75 Compare May 14, 2025 02:58
@imgk
Copy link
Owner

imgk commented May 14, 2025

增加一下 caddyfile 解析的部分吧,现在应该还是不支持的

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名建议改成 proxy_unix

Copy link
Contributor Author

@0x1306a94 0x1306a94 May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名已改
caddyfile 解析也增加了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 下面这个去掉后面的json配置后,自动生成的json格式会存在 null。是否可以加上这个配置哇
trojan.Dialer `json:"-,omitempty"`
image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实我想说的是没有必要在结构体定义 trojan.Dialer,不仅仅是 json的部分,我看这个Dialer没在其他地方用到

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的懂你的意思了。这里自身已经满足trojan.Dialer要求了。
所以不需要了。已经去掉了你再看看还有没有需要修改的

image

@0x1306a94 0x1306a94 force-pushed the feature/unix_proxy branch from 23cef75 to 2a91b5e Compare May 14, 2025 03:36
@0x1306a94 0x1306a94 force-pushed the feature/unix_proxy branch from 2a91b5e to 3f2b7b2 Compare May 14, 2025 03:44
@imgk imgk merged commit 70ed2a7 into imgk:main May 14, 2025
@0x1306a94 0x1306a94 deleted the feature/unix_proxy branch May 14, 2025 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants