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)
| 215 | // "routing" key) via the RoutingService gRPC API. Note that this cannot change |
| 216 | // routing.domainStrategy/domainMatcher — those are fixed at process start. |
| 217 | func (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. |
| 248 | type BalancerInfo struct { |