XrayR-project / XrayR

A Xray backend framework that can easily support many panels. 一个基于Xray的后端框架,支持V2ay,Trojan,Shadowsocks协议,极易扩展,支持多面板对接
https://xrayr-project.github.io/XrayR-doc/
Mozilla Public License 2.0
1.9k stars 783 forks source link

least ping strategy in load balancer #557

Closed MrVb0 closed 7 months ago

MrVb0 commented 7 months ago

Hello, I was using the xray load balancer through the following configuration in the route, which I think uses the random strategy by default (it worked well) :

{

      "balancers": [
{
  "tag": "balancerreality",
   "selector": [
                 "TUN1",
                 "TUN2",
                 "TUN3",
                 "TUN4",
                 "TUN5",
                 "TUN6",
                 "TUN7",
                 "TUN8",
                 "TUN9",
                 "TUN10",
                 "TUN11",
                 "TUN12",
                 "TUN13"
              ]
    }
],

  "domainStrategy": "IPOnDemand",

  "rules": [ 
      {
      "type": "field",
      "domain": [
        "geosite:category-ads-all"
      ],
      "outboundTag": "block"
    },    
    {
      "type": "field",
      "network": "udp,tcp",
      "balancerTag": "balancerreality"
    }
  ]
} 

Now I want to use the leastPing strategy, but by adding the strategy section, xrayr gives an error. i tested this :

{

      "balancers": [
        {
  "tag": "balancerreality",
  "selector": [
                 "TUN1",
                 "TUN2",
                 "TUN3",
                 "TUN4",
                 "TUN5",
                 "TUN6",
                 "TUN7",
                 "TUN8",
                 "TUN9",
                 "TUN10",
                 "TUN11",
                 "TUN12",
                 "TUN13"
              ], 
    "strategy": {
          "type": "leastPing"
                }
        }
  ],

  "domainStrategy": "IPOnDemand",

  "rules": [
      {
      "type": "field",
      "domain": [
        "geosite:category-ads-all"
      ],
      "outboundTag": "block"
    },    
    {
      "type": "field",
      "network": "udp,tcp",
      "balancerTag": "balancerreality"
    }
  ]
}

and , also i tested this :

{

      "balancers": [
        {
  "tag": "balancerreality",
  "selector": [
                 "TUN1",
                 "TUN2",
                 "TUN3",
                 "TUN4",
                 "TUN5",
                 "TUN6",
                 "TUN7",
                 "TUN8",
                 "TUN9",
                 "TUN10",
                 "TUN11",
                 "TUN12",
                 "TUN13"
              ], 
    "strategy": {
          "type": "leastPing"
                }
        }
  ],

  "domainStrategy": "IPOnDemand",

  "rules": [
      {
      "type": "field",
      "domain": [
        "geosite:category-ads-all"
      ],
      "outboundTag": "block"
    },    
    {
      "type": "field",
      "network": "udp,tcp",
      "balancerTag": "balancerreality"
    }
  ]
},
   "observatory": {
        "subjectSelector":[
                 "TUN1",
                 "TUN2",
                 "TUN3",
                 "TUN4",
                 "TUN5",
                 "TUN6",
                 "TUN7",
                 "TUN8",
                 "TUN9",
                 "TUN10",
                 "TUN11",
                 "TUN12",
                 "TUN13"
        ],
        "probeURL": "https://www.google.com/generate_204",
        "probeInterval": "1m"
      }

Error on xrayr log :

Dec 20 13:33:50 khs.khs XrayR[1014618]: 2023/12/20 13:33:50 Failed to unmarshal Routing config: /etc/XrayR/route.json
Dec 20 13:33:50 khs.khs XrayR[1014618]: panic: Failed to unmarshal Routing config: /etc/XrayR/route.json
Septrum101 commented 7 months ago

https://github.com/XTLS/Xray-core/issues/2777

Septrum101 commented 7 months ago
{
  "balancers": [
    {
      "tag": "balancerreality",
      "selector": [
        "TUN1",
        "TUN2",
        "TUN3",
        "TUN4",
        "TUN5",
        "TUN6",
        "TUN7",
        "TUN8",
        "TUN9",
        "TUN10",
        "TUN11",
        "TUN12",
        "TUN13"
      ],
      "strategy": {
        "type": "leastPing"
      }
    }
  ],
  "domainStrategy": "IPOnDemand",
  "rules": [
    {
      "type": "field",
      "domain": [
        "geosite:category-ads-all"
      ],
      "outboundTag": "block"
    },
    {
      "type": "field",
      "network": "udp,tcp",
      "balancerTag": "balancerreality"
    }
  ]
}

This config can be start.

MrVb0 commented 7 months ago

@thank243 error :

Dec 20 14:48:58 khs.khs XrayR[1055283]: panic: runtime error: invalid memory address or nil pointer dereference
Dec 20 14:48:58 khs.khs XrayR[1055283]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xc50a68]
Dec 20 14:48:58 khs.khs XrayR[1055283]: goroutine 58 [running]:
Dec 20 14:48:58 khs.khs XrayR[1055283]: github.com/xtls/xray-core/app/router.(*LeastPingStrategy).PickOutbound(0xc001801b40?, {0xc001ee20d0, 0xd, 0x3580e20?})
Dec 20 14:48:58 khs.khs XrayR[1055283]:         github.com/xtls/xray-core@v1.8.7-0.20231128163007-be21b1194b04/app/router/strategy_leastping.go:29 +0xa8
Dec 20 14:48:58 khs.khs XrayR[1055283]: github.com/xtls/xray-core/app/router.(*Balancer).PickOutbound(0xc000159700)
Dec 20 14:48:58 khs.khs XrayR[1055283]:         github.com/xtls/xray-core@v1.8.7-0.20231128163007-be21b1194b04/app/router/balancing.go:41 +0x10d
Dec 20 14:48:58 khs.khs XrayR[1055283]: github.com/xtls/xray-core/app/router.(*Rule).GetTag(...)
Dec 20 14:48:58 khs.khs XrayR[1055283]:         github.com/xtls/xray-core@v1.8.7-0.20231128163007-be21b1194b04/app/router/config.go:20
Dec 20 14:48:58 khs.khs XrayR[1055283]: github.com/xtls/xray-core/app/router.(*Router).PickRoute(0x4820dd8?, {0x4836b88?, 0xc001cba2a0?})
Dec 20 14:48:58 khs.khs XrayR[1055283]:         github.com/xtls/xray-core@v1.8.7-0.20231128163007-be21b1194b04/app/router/router.go:76 +0x5a
..............
Septrum101 commented 7 months ago

You can Goto xray-core for helping.

MrVb0 commented 7 months ago

@thank243 I noticed that for the least ping strategy to work, "observatory" must be in the configuration. Where and which file should I place this observatory section?