写了个 clash.META 插件使用 HTTP2 ping frame 进行最快(min rtt)线路选择

170 天前
 zckevin

https://github.com/zckevin/Clash.Meta/tree/http2ping_new/adapter/outboundgroup/http2ping

http2ping for Clash.META

使用 HTTP2 Ping Frame 监测链路 rtt, 并从中选择 rtt 最优的链路

为什么

相比于url-test, http2ping 针对每个 endpoint 建立一条 HTTP2 长连接, 避免了频繁建立/断开连接, 因此我们可以使用更低的 interval(1s) 进行接近实时的 rtt 监测.

相比于使用ICMP ping进行延迟检测, 对于某些使用中转服务的网络接入供应商, ICMP packets 只能检测用户->中转->落地这条链路的第一部分而非整条链路的完整 RTT.

相比于使用http://www.gstatic.com/generate_204这类常见的基于 HTTP 的 health check, 如果使用 HTTP 协议, 部分鸡贼的网络接入供应商会在中转服务器进行 MITM 直接返回 HTTP 204 response, 以试图欺骗客户.

配置

# enable verbose logging for more infomation
log-level: debug
proxy-groups:
  - name: min-rtt-group
    type: http2-ping
    filter: "hk"
    use:
      - airport_1
    # interval milliseconds for sending Ping frame, default value: 1000ms
    interval: 1000
    # tolerance for changing current best route, default value: 0ms
    tolerance: 0
    # target server, default server: https://cloudflare.com
    server: https://cloudflare.com

开发/测试

for debugging:

#!/bin/bash

interface=enp1s0
ip=1.1.1.1
delay=100ms

# add latency to ip address
tc qdisc add dev $interface root handle 1: prio
tc filter add dev $interface parent 1:0 protocol ip prio 1 u32 match ip dst $ip flowid 2:1
tc qdisc add dev $interface parent 1:1 handle 2: netem delay $delay

# remove tc rules
tc qdisc del dev $interface root
1776 次点击
所在节点    分享创造
13 条回复
yyysuo
170 天前
这么好的东西,能给 mihomo 提 pr 么,大佬们正对 healthy check 不满意呢。
NouveauNom
170 天前
cfw mac 能用吗
issakchill
170 天前
支持提 pr
zckevin
170 天前
@yyysuo
@issakchill

感谢支持, 准备试试

@NouveauNom
暂时没在 cfw 测试过
zckevin
170 天前
shunia
169 天前
惊了,我以为这个 mihomo 还真是个星铁的工具呢。心说给游戏工具提这种 PR 干啥哈哈哈哈哈。
mapperv
169 天前
airport_1 未定义是啥原因?
mapperv
169 天前
zckevin
169 天前
@mapperv

很明显你不太会写 clash 配置, 这个 `airport_1` 只是个示意, 需要改成你用的 proxy provider
mapperv
169 天前
确实不太会。现在改过之后没有这个 type
mapperv
169 天前
- {name: 自动选择, <<: *use, tolerance: 2, type: url-test}
自带的 url-test 是这么配置的,是不是更改实际上是不是更改 type 然后加上 server 配置应该就可以了,但是好像没有这个 type
zckevin
169 天前
@mapperv

因为没有被上游 merge, 你需要自己 clone 代码编译
mapperv
169 天前
@zckevin 好的 谢谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1007227

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX