fix: provider auto update
This commit is contained in:
parent
663bf4fbb0
commit
2fbbf7519f
6 changed files with 30 additions and 14 deletions
|
@ -43,6 +43,14 @@ func (f *fetcher) Initial() (any, error) {
|
||||||
err error
|
err error
|
||||||
isLocal bool
|
isLocal bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
// pull proxies automatically
|
||||||
|
if f.ticker != nil {
|
||||||
|
go f.pullLoop()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil {
|
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil {
|
||||||
buf, err = os.ReadFile(f.vehicle.Path())
|
buf, err = os.ReadFile(f.vehicle.Path())
|
||||||
modTime := stat.ModTime()
|
modTime := stat.ModTime()
|
||||||
|
@ -84,11 +92,6 @@ func (f *fetcher) Initial() (any, error) {
|
||||||
|
|
||||||
f.hash = md5.Sum(buf)
|
f.hash = md5.Sum(buf)
|
||||||
|
|
||||||
// pull proxies automatically
|
|
||||||
if f.ticker != nil {
|
|
||||||
go f.pullLoop()
|
|
||||||
}
|
|
||||||
|
|
||||||
return proxies, nil
|
return proxies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (h *HTTPVehicle) Read() ([]byte, error) {
|
||||||
// from http.DefaultTransport
|
// from http.DefaultTransport
|
||||||
MaxIdleConns: 100,
|
MaxIdleConns: 100,
|
||||||
IdleConnTimeout: 30 * time.Second,
|
IdleConnTimeout: 30 * time.Second,
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
ExpectContinueTimeout: 1 * time.Second,
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
conn := inner.HandleTcp(address, uri.Hostname())
|
conn := inner.HandleTcp(address, uri.Hostname())
|
||||||
|
|
|
@ -78,8 +78,8 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
updateSniffer(cfg.Sniffer)
|
updateSniffer(cfg.Sniffer)
|
||||||
updateHosts(cfg.Hosts)
|
updateHosts(cfg.Hosts)
|
||||||
updateDNS(cfg.DNS)
|
updateDNS(cfg.DNS)
|
||||||
loadProxyProvider(cfg.Providers)
|
|
||||||
loadRuleProvider(cfg.RuleProviders)
|
loadProviders(cfg)
|
||||||
updateGeneral(cfg.General, force)
|
updateGeneral(cfg.General, force)
|
||||||
updateIPTables(cfg)
|
updateIPTables(cfg)
|
||||||
updateTun(cfg.Tun, cfg.DNS)
|
updateTun(cfg.Tun, cfg.DNS)
|
||||||
|
@ -89,6 +89,12 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
log.SetLevel(cfg.General.LogLevel)
|
log.SetLevel(cfg.General.LogLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadProviders(cfg *config.Config) {
|
||||||
|
P.NewInner(tunnel.TCPIn())
|
||||||
|
loadProxyProvider(cfg.Providers)
|
||||||
|
loadRuleProvider(cfg.RuleProviders)
|
||||||
|
}
|
||||||
|
|
||||||
func GetGeneral() *config.General {
|
func GetGeneral() *config.General {
|
||||||
ports := P.GetPorts()
|
ports := P.GetPorts()
|
||||||
var authenticator []string
|
var authenticator []string
|
||||||
|
@ -188,7 +194,7 @@ func loadProvider(pv provider.Provider) {
|
||||||
log.Infoln("Start initial provider %s", (pv).Name())
|
log.Infoln("Start initial provider %s", (pv).Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := (pv).Initial(); err != nil {
|
if err := pv.Initial(); err != nil {
|
||||||
switch pv.Type() {
|
switch pv.Type() {
|
||||||
case provider.Proxy:
|
case provider.Proxy:
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,6 +83,10 @@ func SetBindAddress(host string) {
|
||||||
bindAddress = host
|
bindAddress = host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewInner(tcpIn chan<- C.ConnContext) {
|
||||||
|
inner.New(tcpIn)
|
||||||
|
}
|
||||||
|
|
||||||
func ReCreateHTTP(port int, tcpIn chan<- C.ConnContext) {
|
func ReCreateHTTP(port int, tcpIn chan<- C.ConnContext) {
|
||||||
httpMux.Lock()
|
httpMux.Lock()
|
||||||
defer httpMux.Unlock()
|
defer httpMux.Unlock()
|
||||||
|
@ -127,7 +131,6 @@ func ReCreateSocks(port int, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
||||||
log.Errorln("Start SOCKS server error: %s", err.Error())
|
log.Errorln("Start SOCKS server error: %s", err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
inner.New(tcpIn)
|
|
||||||
|
|
||||||
addr := genAddr(bindAddress, port, allowLan)
|
addr := genAddr(bindAddress, port, allowLan)
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,12 @@ func (f *fetcher) Initial() (interface{}, error) {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if f.ticker != nil {
|
||||||
|
go f.pullLoop()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil {
|
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil {
|
||||||
buf, err = ioutil.ReadFile(f.vehicle.Path())
|
buf, err = ioutil.ReadFile(f.vehicle.Path())
|
||||||
modTime := stat.ModTime()
|
modTime := stat.ModTime()
|
||||||
|
@ -83,9 +89,6 @@ func (f *fetcher) Initial() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f.hash = md5.Sum(buf)
|
f.hash = md5.Sum(buf)
|
||||||
if f.ticker != nil {
|
|
||||||
go f.pullLoop()
|
|
||||||
}
|
|
||||||
|
|
||||||
return rules, nil
|
return rules, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,8 @@ func NewRuleSetProvider(name string, behavior P.RuleType, interval time.Duration
|
||||||
rp,
|
rp,
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.SetFinalizer(wrapper, rp.fetcher.Destroy())
|
final := func(provider *RuleSetProvider) { rp.fetcher.Destroy() }
|
||||||
|
runtime.SetFinalizer(wrapper, final)
|
||||||
return wrapper
|
return wrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue