clash icon indicating copy to clipboard operation
clash copied to clipboard

proxy-provider should parse proxy-group and rules

Open katsusan opened this issue 2 years ago • 2 comments

Verify steps

  • [X] 如果你可以自己 debug 并解决的话,提交 PR 吧 Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • [X] 我已经在 Issue Tracker 中找过我要提出的问题 I have searched on the issue tracker for a related issue.
  • [X] 我已经使用 dev 分支版本测试过,问题依旧存在 I have tested using the dev branch, and the issue still exists.
  • [X] 我已经仔细看过 Documentation 并无法自行解决问题 I have read the documentation and was unable to solve the issue.
  • [X] 这是 Clash 核心的问题,并非我所使用的 Clash 衍生版本(如 OpenClash、KoolClash 等)的特定问题 This is an issue of the Clash core per se, not to the derivatives of Clash, like OpenClash or KoolClash.

Clash version

latest master branch

What OS are you seeing the problem on?

Linux

Clash config

port: 17890
socks-port: 17891
allow-lan: true
mode: Rule
log-level: info
bind-address: '192.168.1.x'
external-controller: '192.168.1.x:19090'

proxy-providers:
  rz:
    type: http
    url: "<subscribing url>"
    interval: 3600
    path: "./rz-server.yaml"
    health-check:
      enable: true
      interval: 600
      url: http://www.gstatic.com/generate_204

proxy-groups:
  -
    name: 'manual select'
    type: select
    proxies:
      - HK1...
      - HK2...

rules:
  ...

Clash log

~/pr/clash | providers ?4  ./clashx -d /usr/local/src/clash/ground/         
INFO[0000] Start initial provider rz
FATA[0000] Parse config error: proxy group[0]: 'Standard|HK|IEPL|01' not found

Description

Currently clash only parses proxies field from the fetched result of subscribing url. However proxy-group and rules may reply on the proxy servers, which made proxy-provider had to work in effect.

// 目前clash对于proxy-provider只给其提供proxy server list的功能(只解析proxies字段), // 但proxy-groups和rules都可能依赖下层具体的proxy server. // 如果仅仅提供proxy server list的话,只能自己在config.yaml中固定proxy-groups和rules,在 // config/config.go:parseProxies函数中可以看到传入的proxyMap参数只包含配置文件中的proxies以及 // DIRECT和REJECT.

func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider) (C.ProxyAdapter, error) {
...
    if len(groupOption.Proxies) != 0 { // 在我的config情况下这里的Proxies应该是[]string{"HK1", "HK2"}
        ps, err := getProxies(proxyMap, groupOption.Proxies) // 这里的proxyMap不包含proxy-provider中的server
...

由于proxy-provider返回的server list还会变化,所以hardcoding这些proxy-group和rules仍然有不一致的可能. 对于这种情况可以让proxy-provider返回对应的proxies/proxy-groups/rules三者.如果maintainer同意这个想法的话我可以尝试提PR.

katsusan avatar Jun 19 '22 18:06 katsusan

I face the same problem 我遇到了相同问题

Workaroud

Copy rule-providers, rule from your subscription file to config.tomlconfig.toml 中添加 订阅文件 中的 rule-providers, rule

Add proxy-groups of the same name in the subscription file as follows: 添加与 订阅文件 中相同名称的 proxy-groups 如下:

proxy-groups:
  - name: 🚀 节点选择
    type: select
    use:
      - flareix
  ...
proxy-providers:
  flareix:
    type: http
    url: "https://sub-1.flareix.us/api/subscription/xxxxxxxx/clash"
    interval: 43200
    path: ./profiles/flareix.yaml
    health-check:
      enable: true
      interval: 600
      url: http://www.gstatic.com/generate_204

Basically, rule-providers, rule, proxy-groups are unlikely to change, so it's enough for now 通常 rule-providers, rule, proxy-groups 不太可能变化, 所以暂时可以凑合下

mtt0 avatar Jun 26 '22 15:06 mtt0

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Aug 26 '22 02:08 github-actions[bot]

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Nov 02 '22 02:11 github-actions[bot]