mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-28 00:24:19 +00:00
6b16d8c37a
Add a hot-apply layer that computes a diff between the old and new generated config and applies only the changed parts through the Xray gRPC HandlerService and RoutingService, avoiding a full process restart whenever possible. A restart is still performed when sections that have no reload API (log, dns, policy, observatory, ...) actually change. Key additions: - internal/xray/hot_diff.go: ComputeHotDiff with canonical-JSON comparison (sorted keys, null=absent, full number precision) so UI reformatting never triggers a spurious restart - internal/xray/api.go: AddOutbound/DelOutbound, ApplyRoutingConfig, GetBalancerInfo, SetBalancerTarget, TestRoute gRPC wrappers - internal/web/service/xray.go: tryHotApply, ensureAPIServices, GetBalancersStatus, OverrideBalancer, TestRoute service methods - internal/web/controller/xray_setting.go: balancerStatus, balancerOverride, routeTest API endpoints - frontend: BalancersTab live-status/override columns, RouteTester component, Restart button removed (Save now hot-applies) - balancer-helpers.ts: syncObservatories never creates observatory sections for random/roundRobin balancers (no reload API → restart) - i18n: balancerLive/Override/routeTester keys added to all 13 locales
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package xray
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
|
|
)
|
|
|
|
// Config represents the complete Xray configuration structure.
|
|
// It contains all sections of an Xray config file including inbounds, outbounds, routing, etc.
|
|
type Config struct {
|
|
LogConfig json_util.RawMessage `json:"log"`
|
|
RouterConfig json_util.RawMessage `json:"routing"`
|
|
DNSConfig json_util.RawMessage `json:"dns,omitempty"`
|
|
InboundConfigs []InboundConfig `json:"inbounds"`
|
|
OutboundConfigs json_util.RawMessage `json:"outbounds"`
|
|
Transport json_util.RawMessage `json:"transport,omitempty"`
|
|
Policy json_util.RawMessage `json:"policy"`
|
|
API json_util.RawMessage `json:"api"`
|
|
Stats json_util.RawMessage `json:"stats"`
|
|
Reverse json_util.RawMessage `json:"reverse,omitempty"`
|
|
FakeDNS json_util.RawMessage `json:"fakedns,omitempty"`
|
|
Observatory json_util.RawMessage `json:"observatory,omitempty"`
|
|
BurstObservatory json_util.RawMessage `json:"burstObservatory,omitempty"`
|
|
Metrics json_util.RawMessage `json:"metrics"`
|
|
Geodata json_util.RawMessage `json:"geodata,omitempty"`
|
|
}
|
|
|
|
// Equals compares two Config instances for deep equality.
|
|
func (c *Config) Equals(other *Config) bool {
|
|
if len(c.InboundConfigs) != len(other.InboundConfigs) {
|
|
return false
|
|
}
|
|
for i, inbound := range c.InboundConfigs {
|
|
if !inbound.Equals(&other.InboundConfigs[i]) {
|
|
return false
|
|
}
|
|
}
|
|
if !bytes.Equal(c.LogConfig, other.LogConfig) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.RouterConfig, other.RouterConfig) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.DNSConfig, other.DNSConfig) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.OutboundConfigs, other.OutboundConfigs) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Transport, other.Transport) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Policy, other.Policy) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.API, other.API) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Stats, other.Stats) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Reverse, other.Reverse) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.FakeDNS, other.FakeDNS) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Observatory, other.Observatory) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.BurstObservatory, other.BurstObservatory) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Metrics, other.Metrics) {
|
|
return false
|
|
}
|
|
if !bytes.Equal(c.Geodata, other.Geodata) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|