Skip to content

Automatic client-side balancing #517

@dev-kick

Description

@dev-kick

Hello developers!

I would really like to implement automatic client-side balancing, since it is extremely convenient for automatically selecting the server with the best latency/ping for the user.

However, currently this is difficult to achieve because:

  1. Generated outbounds always use a fixed tag:

"tag": "proxy"

This makes it impossible to use Xray balancers properly, because each outbound must have a unique tag.

  1. When adding multiple custom outbounds in client templates, the vnext.users section is not populated automatically with user UUID, which makes such configs unusable.

As an example, this is the type of balancing configuration I would like to build:

{
  "outbounds": [
    {
      "tag": "node-1",
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "1.1.1.1",
            "port": 443,
            "users": [
              {
                "id": "UUID",
                "encryption": "none",
                "flow": "xtls-rprx-vision"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          "serverName": "example.com",
          "publicKey": "PUBLIC_KEY",
          "shortId": "SHORT_ID",
          "fingerprint": "chrome"
        }
      }
    },
    {
      "tag": "node-2",
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "2.2.2.2",
            "port": 443,
            "users": [
              {
                "id": "UUID",
                "encryption": "none",
                "flow": "xtls-rprx-vision"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          "serverName": "example.com",
          "publicKey": "PUBLIC_KEY",
          "shortId": "SHORT_ID",
          "fingerprint": "chrome"
        }
      }
    }
  ],
  "routing": {
    "balancers": [
      {
        "tag": "proxy-balance",
        "selector": [
          "node-1",
          "node-2"
        ],
        "strategy": {
          "type": "roundRobin"
        }
      }
    ],
    "rules": [
      {
        "type": "field",
        "network": "tcp,udp",
        "balancerTag": "proxy-balance"
      }
    ]
  }
}

Would it be possible to implement automatic generation of unique outbound tags for balancing purposes?

Or alternatively, allow vnext.users to be used in custom templates, for example:

"users": [
  {
    "id": "{{uuid}}",
    "encryption": "none",
    "flow": "xtls-rprx-vision"
  }
]

This would make it possible to build advanced client-side balancing configurations using Xray balancers, observatory, and leastPing.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions