MCPcopy
hub / github.com/MHSanaei/3x-ui / ApplyRoutingConfig

Method ApplyRoutingConfig

internal/xray/api.go:217–245  ·  view source on GitHub ↗

ApplyRoutingConfig replaces the routing rules and balancers of the running Xray core with the given routing section (the JSON value of the top-level "routing" key) via the RoutingService gRPC API. Note that this cannot change routing.domainStrategy/domainMatcher — those are fixed at process start.

(routing []byte)

Source from the content-addressed store, hash-verified

215// "routing" key) via the RoutingService gRPC API. Note that this cannot change
216// routing.domainStrategy/domainMatcher — those are fixed at process start.
217func (x *XrayAPI) ApplyRoutingConfig(routing []byte) error {
218 if x.RoutingServiceClient == nil {
219 return common.NewError("xray RoutingServiceClient is not initialized")
220 }
221
222 // Rules referencing geoip:/geosite: need the dat files; point xray-core's
223 // in-process loader at the panel's bin folder where they live.
224 ensureXrayAssetLocation()
225
226 routerConf := new(conf.RouterConfig)
227 if err := json.Unmarshal(routing, routerConf); err != nil {
228 logger.Debug("Failed to unmarshal routing config:", err)
229 return err
230 }
231 config, err := routerConf.Build()
232 if err != nil {
233 logger.Debug("Failed to build routing config:", err)
234 return err
235 }
236
237 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
238 defer cancel()
239
240 _, err = (*x.RoutingServiceClient).AddRule(ctx, &routerService.AddRuleRequest{
241 ShouldAppend: false,
242 Config: serial.ToTypedMessage(config),
243 })
244 return err
245}
246
247// BalancerInfo is the live state of one balancer inside the running core.
248type BalancerInfo struct {

Callers 3

TestXrayAPI_E2EFunction · 0.95
withOutboundBridgeMethod · 0.95
tryHotApplyMethod · 0.95

Calls 3

NewErrorFunction · 0.92
DebugFunction · 0.92
ensureXrayAssetLocationFunction · 0.85

Tested by 1

TestXrayAPI_E2EFunction · 0.76