V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
zckevin
V2EX  ›  分享创造

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

  •  2
     
  •   zckevin · 109 天前 · 1583 次点击
    这是一个创建于 109 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
    
    13 条回复    2024-01-10 14:19:39 +08:00
    yyysuo
        1
    yyysuo  
       109 天前
    这么好的东西,能给 mihomo 提 pr 么,大佬们正对 healthy check 不满意呢。
    NouveauNom
        2
    NouveauNom  
       109 天前
    cfw mac 能用吗
    issakchill
        3
    issakchill  
       109 天前
    支持提 pr
    zckevin
        4
    zckevin  
    OP
       109 天前
    @yyysuo
    @issakchill

    感谢支持, 准备试试

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

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

    因为没有被上游 merge, 你需要自己 clone 代码编译
    mapperv
        13
    mapperv  
       108 天前
    @zckevin 好的 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2923 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:28 · PVG 22:28 · LAX 07:28 · JFK 10:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.