v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
28.83k stars 4.57k forks source link

v5 config balancer not working #3079

Open mkmark opened 1 month ago

mkmark commented 1 month ago

v 5.16.1

v5 config balancer not working

See below for client configuration for minimum reproduction. Since it's using only freedom, there's no server config.

// client configuration
{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    }
  },
  "router": {
    "rule": [
      {
        "balancingTag": "balancer",
        "networks": "tcp,udp"
      }
    ],
    "balancingRule": [
      {
        "tag": "balancer",
        "outboundSelector": [
          "a",
          "b"
        ]
      }
    ]
  },
  "inbounds": [
    {
      "protocol": "socks",
      "port": 1080,
      "listen": "127.0.0.1",
      "tag": "1080"
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "a"
    },
    {
      "protocol": "freedom",
      "tag": "b"
    }
  ],
  "stats": {}
}

debug log, the default route warning lines are marked red.

$ .\v2ray.exe run -c .\test_v51.json -format=jsonv5
V2Ray 5.16.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.22.2 windows/amd64)
A unified platform for anti-censorship.
2024/07/17 07:50:43 [Debug] app/log: Logger started
2024/07/17 07:50:43 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1080
2024/07/17 07:50:43 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080
2024/07/17 07:50:43 [Warning] V2Ray 5.16.1 started
2024/07/17 07:50:47 [Info] [725577340] proxy/socks: TCP Connect request to tcp:www.example.com:443
- 2024/07/17 07:50:47 [Warning] [725577340] app/dispatcher: default route for tcp:www.example.com:443
2024/07/17 07:50:47 [Info] [725577340] proxy/freedom: opening connection to tcp:www.example.com:443
2024/07/17 07:50:47 [Info] [725577340] transport/internet/tcp: dialing TCP to tcp:www.example.com:443
2024/07/17 07:50:48 [Info] [3003456230] proxy/socks: TCP Connect request to tcp:www.example.com:443
- 2024/07/17 07:50:48 [Warning] [3003456230] app/dispatcher: default route for tcp:www.example.com:443
2024/07/17 07:50:48 [Info] [3003456230] proxy/freedom: opening connection to tcp:www.example.com:443
2024/07/17 07:50:48 [Info] [3003456230] transport/internet/tcp: dialing TCP to tcp:www.example.com:443
2024/07/17 07:50:51 [Debug] app/log: Logger closing

in comparison, v4 config works.

{
  "log": {
    "loglevel": "debug"
  },
  "routing": {
    "rules": [
      {
        "balancerTag": "balancer",
        "network": "tcp,udp",
        "type": "field"
      }
    ],
    "balancers": [
      {
        "tag": "balancer",
        "selector": [
          "a",
          "b"
        ]
      }
    ]
  },
  "inbounds": [
    {
      "protocol": "socks",
      "port": 1080,
      "listen": "127.0.0.1",
      "tag": "1080"
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "a"
    },
    {
      "protocol": "freedom",
      "tag": "b"
    }
  ],
  "stats": {}
}
$ .\v2ray.exe run -c .\test_v4.json
V2Ray 5.16.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.22.2 windows/amd64)
A unified platform for anti-censorship.
2024/07/17 07:46:48 [Debug] app/log: Logger started
2024/07/17 07:46:48 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1080
2024/07/17 07:46:48 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080
2024/07/17 07:46:48 [Warning] V2Ray 5.16.1 started
2024/07/17 07:46:51 [Info] [1892315910] proxy/socks: TCP Connect request to tcp:www.example.com:443
2024/07/17 07:46:51 tcp:127.0.0.1:5285 accepted tcp:www.example.com:443 [a]
2024/07/17 07:46:51 [Info] [1892315910] app/dispatcher: taking detour [a] for [tcp:www.example.com:443]
2024/07/17 07:46:51 [Info] [1892315910] proxy/freedom: opening connection to tcp:www.example.com:443
2024/07/17 07:46:51 [Info] [1892315910] transport/internet/tcp: dialing TCP to tcp:www.example.com:443
2024/07/17 07:46:51 [Info] [1224250282] proxy/socks: TCP Connect request to tcp:www.example.com:443
2024/07/17 07:46:51 tcp:127.0.0.1:5287 accepted tcp:www.example.com:443 [a]
2024/07/17 07:46:51 [Info] [1224250282] app/dispatcher: taking detour [a] for [tcp:www.example.com:443]
2024/07/17 07:46:51 [Info] [1224250282] proxy/freedom: opening connection to tcp:www.example.com:443
2024/07/17 07:46:51 [Info] [1224250282] transport/internet/tcp: dialing TCP to tcp:www.example.com:443
2024/07/17 07:46:58 [Debug] app/log: Logger closing
mkmark commented 1 month ago

The reason is here

https://github.com/v2fly/v2ray-core/blob/8191faa6e0951fd1c84864ce7780863142104b22/app/router/config.go#L192

but the docs are using camel style

https://github.com/v2fly/v2fly-github-io/blob/0d21b77f062a92c4f5fd1cdede9d88a3368712b2/docs/v5/config/router.md?plain=1#L112

it's snake and camel problem, again...

The project is using both snake and camel style variable randomly. Some of the keys seem immune to underscore and upper/lower case while some are not. How come?