asdlokj1qpi23 / subconverter

Utility to convert between various subscription format.Support hy2、hy and vless for singbox and clash meta
GNU General Public License v3.0
180 stars 32 forks source link

[Feature] 请求给loon添加hysteria2转换功能 #22

Closed bigoovip closed 1 week ago

bigoovip commented 4 weeks ago

verify

功能描述

IOS上使用的是LOON客户端,该客户端支持hysteria2,请求支持转换到LOON的hysteria2的格式,subconverter 目前只支持sing-box和clash_meta的hysteria2转换。

可能的解决方案

No response

asdlokj1qpi23 commented 4 weeks ago

Please provide an example configuration, thank you.

bigoovip commented 3 weeks ago

@asdlokj1qpi23 你好,这是loon官方文档链接节点格式,其中tls-name参数已被改为sni,新增download-bandwidth参数,是指客户端的下载带宽(同时是服务器的上传带宽),只有指定了这个参数,才能启用Brutal拥塞控制算法,因此实际模板如下

#Hysteria2
# 节点名称 = Hysteria2,服务器地址,端口,密码,sni=SNI,skip-cert-verify=是否跳过证书校验(默认否),fast-open=是否开启fast open,udp=是否在UDP中使用(需要节点支持),download-bandwidth=带宽限制(单位Mbps)

以下是实际测试能成功使用的节点,其中example.com是已模糊处理的服务器域名或ip,实际密码就是实际密码(两边有双引号),skip-cert-verify和fast-open默认值是否,所以被省略了

hysteria2Node = Hysteria2,example.com,9898,"实际密码",sni=example.com,udp=true,download-bandwidth=100
asdlokj1qpi23 commented 3 weeks ago

Please test the latest version of the image.

bigoovip commented 3 weeks ago

@asdlokj1qpi23 最新版本执行Actions好像失败了,我自行编译了最新的Commit 598f6ac,hy2链接仍然无法转换为loon格式,同一个hy2节点,生成类型是sing-box和clash时可以正确转换,而生成类型是loon时,hy2节点仍然表现为丢失。

asdlokj1qpi23 commented 3 weeks ago

Please test the latest version of the image.

bigoovip commented 3 weeks ago

@asdlokj1qpi23 后台显示版本号为“subconverter v0.9.4-2ee7c3a backend”,hy2链接仍然无法转换为loon格式,同一个hy2节点,生成类型是sing-box和clash时可以正确转换,而生成类型是loon时,hy2节点仍然表现为丢失,生成类型是loon时的docker日志内容如下(节点已脱敏):

2024/06/14 Fri 07:57:15.459938 [1 Thread-12][VERB] handle_cmd:    GET handle_uri:    /sub?target=loon&url=hysteria2%3A%2F%2Fpassword%40test.com%3A60009%2F%3Fsni%3Dtest.com%26alpn%3Dh3%252Ch2%252Chttp%252F1.1%26insecure%3D0%23hy2&insert=false&emoji=true&list=true&xudp=false&udp=false&tfo=false&expand=false&scv=false&fdn=false
2024/06/14 Fri 07:57:15.459954 [1 Thread-12][VERB] handle_header: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7|Accept-Encoding: gzip, deflate|Accept-Language: zh-CN,zh;q=0.9,en;q=0.8|Connection: keep-alive|DNT: 1|Host: 192.168.0.100:15051|Upgrade-Insecure-Requests: 1|User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36|
2024/06/14 Fri 07:57:15.460046 [1 Thread-12][VERB] Imported 0 item(s).
2024/06/14 Fri 07:57:15.460126 [1 Thread-12][INFO] Fetching node data from url 'hysteria2://password@test.com:60009/?sni=test.com&alpn=h3%2Ch2%2Chttp%2F1.1&insecure=0#hy2'.
2024/06/14 Fri 07:57:15.461438 [1 Thread-12][VERB] Received Link.
2024/06/14 Fri 07:57:15.461982 [1 Thread-12][INFO] Generate target: Loon
2024/06/14 Fri 07:57:15.462041 [1 Thread-12][INFO] Generate completed.
2024/06/14 Fri 07:57:16.196855 [1 Thread-4][DEBG] Accept connection from client 172.21.0.1:50226
2024/06/14 Fri 07:57:16.196927 [1 Thread-4][VERB] handle_cmd:    GET handle_uri:    /sub?target=loon&url=hysteria2%3A%2F%2Fpassword%40test.com%3A60009%2F%3Fsni%3Dtest.com%26alpn%3Dh3%252Ch2%252Chttp%252F1.1%26insecure%3D0%23hy2&insert=false&emoji=true&list=true&xudp=false&udp=false&tfo=false&expand=false&scv=false&fdn=false/page/2
2024/06/14 Fri 07:57:16.196943 [1 Thread-4][VERB] handle_header: Accept: */*|Accept-Encoding: gzip, deflate|Accept-Language: zh-CN,zh;q=0.9,en;q=0.8|Connection: keep-alive|DNT: 1|Host: 192.168.0.100:15051|referer: http://192.168.0.100:15051/sub?target=loon&url=hysteria2://password@test.com:60009/?sni=test.com&alpn=h3%2Ch2%2Chttp%2F1.1&insecure=0#hy2&insert=false&emoji=true&list=true&xudp=false&udp=false&tfo=false&expand=false&scv=false&fdn=false|User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36|
2024/06/14 Fri 07:57:16.197028 [1 Thread-4][VERB] Imported 0 item(s).
2024/06/14 Fri 07:57:16.197282 [1 Thread-4][INFO] Fetching node data from url 'hysteria2://password@test.com:60009/?sni=test.com&alpn=h3%2Ch2%2Chttp%2F1.1&insecure=0#hy2'.
2024/06/14 Fri 07:57:16.198487 [1 Thread-4][VERB] Received Link.
2024/06/14 Fri 07:57:16.198996 [1 Thread-4][INFO] Generate target: Loon
2024/06/14 Fri 07:57:16.199036 [1 Thread-4][INFO] Generate completed.

另外,可否考虑给sing-box和clash的hy2结点添加上传和下载带宽限制参数,只有启用这两个参数才能启用Brutal拥塞控制算法,hy2官方文档中有提到如果仅启用上传带宽限制参数,则仅上传启用Brutal拥塞控制算法,下载启用传统bbr算法;如果仅启用下载带宽限制参数,则下载启用Brutal拥塞控制算法,上传则启用传统bbr算法,如果上传和下载带宽限制参数都未启用,则上传和下载都启用传统bbr算法。

此链接是sing-box官方hy2文档,以下是sing-box模板,up_mbps是上传带宽限制参数,down_mbps是下载带宽限制参数,默认v2rayn导出的hy2链接没有这两个参数,可以考虑将这两个参数固定,比如up_mbps为30,down_mbps为200(默认单位Mbps)

{
  "type": "hysteria2",
  "tag": "hy2-out",

  "server": "127.0.0.1",
  "server_port": 1080,
  "up_mbps": 100,
  "down_mbps": 100,
  "obfs": {
    "type": "salamander",
    "password": "cry_me_a_r1ver"
  },
  "password": "goofy_ahh_password",
  "network": "tcp",
  "tls": {},
  "brutal_debug": false,

  ... // 拨号字段
}

此链接是clash_meta官方hy2文档,以下是clash_meta模板,up是上传带宽限制参数,down是下载带宽限制参数,默认v2rayn导出的hy2链接没有这两个参数,可以考虑将这两个参数固定,比如up为30 Mbps,down为200 Mbps

proxies:
- name: "hysteria2"
  type: hysteria2
  server: server.com
  port: 443
  ports: 443-8443
  password: yourpassword
  up: "30 Mbps"
  down: "200 Mbps"
  obfs: salamander # 默认为空,如果填写则开启obfs,目前仅支持salamander
  obfs-password: yourpassword

  sni: server.com
  skip-cert-verify: false
  fingerprint: xxxx
  alpn:
    - h3
  ca: "./my.ca"
  ca-str: "xyz"
asdlokj1qpi23 commented 3 weeks ago

Please test the latest version of the image.

bigoovip commented 3 weeks ago

@asdlokj1qpi23 后台显示版本号为“subconverter v0.9.4-8a18d35 backend”,hy2链接已可以转换为loon格式,但是只生成了如下所示的前5个参数:

# hy2参数解释
节点名称 = Hysteria2,服务器地址,端口,密码,sni=SNI

# 生成的hy2链接
hysteria2Node = Hysteria2,example.com,9898,"实际密码",sni=example.com

其它未包含的参数如下:

# hy2参数解释
skip-cert-verify=是否跳过证书校验(默认否),fast-open=是否开启fast open,udp=是否在UDP中使用(需要节点支持),download-bandwidth=带宽限制(单位Mbps)

# hy2链接未包含的参数
skip-cert-verify=false,fast-open=false,udp=true,download-bandwidth=100

原hy2链接来自v2rayn软件的分享链接,格式如下,目前v2rayn软件分享的hy2链接只支持以下参数,其中alpn的值是经过URL编码的值(下方示例中的值h3%2Ch2%2Chttp%2F1.1即为 h3,h2,http/1.1经过URL编码后的值)、obfs=salamander是个有固定值salamander的参数、obfs-password的值是混淆密码、insecure表示是否跳过证书校验(默认值0为否,1为是),上传及下载的带宽限制参数暂不支持

# v2rayn的hy2分享链接参数
hysteria2://密码@服务器地址:端口/?sni=SNI&alpn=h3%2Ch2%2Chttp%2F1.1&obfs=salamander&obfs-password=混淆密码&insecure=0#节点名称

# v2rayn的hy2分享链接
hysteria2://password@example.com:9898/?sni=example.com&alpn=h3%2Ch2%2Chttp%2F1.1&obfs=salamander&obfs-password=hxpw&insecure=0#hysteria2Node

nekoray软件虽然ui设置hy2链接时支持很多参数,格式如下,其中obfs=salamander是个有固定值salamander的参数、obfs-password的值是混淆密码、mport是端口跳跃范围,但实际分享链接也不支持上传及下载的带宽限制参数

# nekoray的hy2分享链接参数
hy2://密码@服务器地址:端口?obfs=salamander&obfs-password=混淆密码&mport=端口范围&sni=example.com#节点名称

# nekoray的hy2分享链接
hy2://password@example.com:9898?obfs=salamander&obfs-password=hxpw&mport=50000-51000&sni=example.com#hysteria2Node

所以转换为loon时,skip-cert-verifys可以直接从原链接参数insecure的值中获取,或者和这些v2rayn、nekoray软件分享链接所不支持的参数fast-open=false,udp=true,download-bandwidth=100一样,在链接转换时直接设置为默认值,同理sing-box和clash也可以直接增加相应的固定值。

bigoovip commented 1 week ago

@asdlokj1qpi23 经测试,已正确转换为loon的hysteria2节点。