chore: adjust the configuration loading order
This commit is contained in:
parent
f586f22ce3
commit
7fecd20a1d
1 changed files with 26 additions and 34 deletions
|
@ -81,13 +81,13 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
||||||
updateSniffer(cfg.Sniffer)
|
updateSniffer(cfg.Sniffer)
|
||||||
updateHosts(cfg.Hosts)
|
updateHosts(cfg.Hosts)
|
||||||
|
updateGeneral(cfg.General)
|
||||||
initInnerTcp()
|
initInnerTcp()
|
||||||
updateDNS(cfg.DNS, cfg.General.IPv6)
|
updateDNS(cfg.DNS, cfg.General.IPv6)
|
||||||
loadProxyProvider(cfg.Providers)
|
loadProxyProvider(cfg.Providers)
|
||||||
updateProfile(cfg)
|
updateProfile(cfg)
|
||||||
loadRuleProvider(cfg.RuleProviders)
|
loadRuleProvider(cfg.RuleProviders)
|
||||||
updateGeneral(cfg.General, force)
|
updateListeners(cfg.General, cfg.Listeners, force)
|
||||||
updateListeners(cfg.Listeners)
|
|
||||||
updateIPTables(cfg)
|
updateIPTables(cfg)
|
||||||
updateTun(cfg.General)
|
updateTun(cfg.General)
|
||||||
updateExperimental(cfg)
|
updateExperimental(cfg)
|
||||||
|
@ -134,12 +134,31 @@ func GetGeneral() *config.General {
|
||||||
return general
|
return general
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateListeners(listeners map[string]C.InboundListener) {
|
func updateListeners(general *config.General, listeners map[string]C.InboundListener, force bool) {
|
||||||
tcpIn := tunnel.TCPIn()
|
tcpIn := tunnel.TCPIn()
|
||||||
udpIn := tunnel.UDPIn()
|
udpIn := tunnel.UDPIn()
|
||||||
natTable := tunnel.NatTable()
|
natTable := tunnel.NatTable()
|
||||||
|
|
||||||
listener.PatchInboundListeners(listeners, tcpIn, udpIn, natTable, true)
|
listener.PatchInboundListeners(listeners, tcpIn, udpIn, natTable, true)
|
||||||
|
if !force {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
inbound.SetTfo(general.InboundTfo)
|
||||||
|
allowLan := general.AllowLan
|
||||||
|
listener.SetAllowLan(allowLan)
|
||||||
|
|
||||||
|
bindAddress := general.BindAddress
|
||||||
|
listener.SetBindAddress(bindAddress)
|
||||||
|
listener.ReCreateHTTP(general.Port, tcpIn)
|
||||||
|
listener.ReCreateSocks(general.SocksPort, tcpIn, udpIn)
|
||||||
|
listener.ReCreateRedir(general.RedirPort, tcpIn, udpIn, natTable)
|
||||||
|
listener.ReCreateAutoRedir(general.EBpf.AutoRedir, tcpIn, udpIn)
|
||||||
|
listener.ReCreateTProxy(general.TProxyPort, tcpIn, udpIn, natTable)
|
||||||
|
listener.ReCreateMixed(general.MixedPort, tcpIn, udpIn)
|
||||||
|
listener.ReCreateShadowSocks(general.ShadowSocksConfig, tcpIn, udpIn)
|
||||||
|
listener.ReCreateVmess(general.VmessConfig, tcpIn, udpIn)
|
||||||
|
listener.ReCreateTuic(LC.TuicServer(general.TuicServer), tcpIn, udpIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateExperimental(c *config.Config) {
|
func updateExperimental(c *config.Config) {
|
||||||
|
@ -304,7 +323,7 @@ func updateTunnels(tunnels []LC.Tunnel) {
|
||||||
listener.PatchTunnel(tunnels, tunnel.TCPIn(), tunnel.UDPIn())
|
listener.PatchTunnel(tunnels, tunnel.TCPIn(), tunnel.UDPIn())
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateGeneral(general *config.General, force bool) {
|
func updateGeneral(general *config.General) {
|
||||||
tunnel.SetMode(general.Mode)
|
tunnel.SetMode(general.Mode)
|
||||||
tunnel.SetFindProcessMode(general.FindProcessMode)
|
tunnel.SetFindProcessMode(general.FindProcessMode)
|
||||||
dialer.DisableIPv6 = !general.IPv6
|
dialer.DisableIPv6 = !general.IPv6
|
||||||
|
@ -319,9 +338,9 @@ func updateGeneral(general *config.General, force bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.UnifiedDelay.Store(general.UnifiedDelay)
|
adapter.UnifiedDelay.Store(general.UnifiedDelay)
|
||||||
dialer.DefaultInterface.Store(general.Interface)
|
// Avoid reload configuration clean the value, causing traffic loops
|
||||||
|
if general.Interface != "" && general.Tun.Enable && !general.Tun.AutoDetectInterface {
|
||||||
if dialer.DefaultInterface.Load() != "" {
|
dialer.DefaultInterface.Store(general.Interface)
|
||||||
log.Infoln("Use interface name: %s", general.Interface)
|
log.Infoln("Use interface name: %s", general.Interface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,35 +350,8 @@ func updateGeneral(general *config.General, force bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
iface.FlushCache()
|
iface.FlushCache()
|
||||||
|
|
||||||
if !force {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
geodataLoader := general.GeodataLoader
|
geodataLoader := general.GeodataLoader
|
||||||
G.SetLoader(geodataLoader)
|
G.SetLoader(geodataLoader)
|
||||||
|
|
||||||
allowLan := general.AllowLan
|
|
||||||
listener.SetAllowLan(allowLan)
|
|
||||||
|
|
||||||
bindAddress := general.BindAddress
|
|
||||||
listener.SetBindAddress(bindAddress)
|
|
||||||
|
|
||||||
inbound.SetTfo(general.InboundTfo)
|
|
||||||
|
|
||||||
tcpIn := tunnel.TCPIn()
|
|
||||||
udpIn := tunnel.UDPIn()
|
|
||||||
natTable := tunnel.NatTable()
|
|
||||||
|
|
||||||
listener.ReCreateHTTP(general.Port, tcpIn)
|
|
||||||
listener.ReCreateSocks(general.SocksPort, tcpIn, udpIn)
|
|
||||||
listener.ReCreateRedir(general.RedirPort, tcpIn, udpIn, natTable)
|
|
||||||
listener.ReCreateAutoRedir(general.EBpf.AutoRedir, tcpIn, udpIn)
|
|
||||||
listener.ReCreateTProxy(general.TProxyPort, tcpIn, udpIn, natTable)
|
|
||||||
listener.ReCreateMixed(general.MixedPort, tcpIn, udpIn)
|
|
||||||
listener.ReCreateShadowSocks(general.ShadowSocksConfig, tcpIn, udpIn)
|
|
||||||
listener.ReCreateVmess(general.VmessConfig, tcpIn, udpIn)
|
|
||||||
listener.ReCreateTuic(LC.TuicServer(general.TuicServer), tcpIn, udpIn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUsers(users []auth.AuthUser) {
|
func updateUsers(users []auth.AuthUser) {
|
||||||
|
|
Loading…
Reference in a new issue