Skip to content

Commit

Permalink
move TouchAfterLazyPassNum to yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Nov 26, 2020
1 parent 07e6b30 commit eabf0fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions adapters/provider/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
const (
defaultURLTestTimeout = time.Second * 5
waitAfterAURLTest = time.Second * 1
touchAfterLazyPassNum = 10
)

var (
healthCheckLazyDefault = true
touchAfterLazyPassNum = 0
)

type HealthCheckOption struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (hc *HealthCheck) process() {
}
} else {
passNum++
if passNum > touchAfterLazyPassNum {
if passNum > 0 && passNum > touchAfterLazyPassNum {
hc.touch()
}
}
Expand Down Expand Up @@ -166,3 +166,11 @@ func HealthCheckLazyDefault() bool {
func SetHealthCheckLazyDefault(newHealthCheckLazyDefault bool) {
healthCheckLazyDefault = newHealthCheckLazyDefault
}

func TouchAfterLazyPassNum() int {
return touchAfterLazyPassNum
}

func SetTouchAfterLazyPassNum(newTouchAfterLazyPassNum int) {
touchAfterLazyPassNum = newTouchAfterLazyPassNum
}
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type General struct {
IPv6 bool `json:"ipv6"`
Interface string `json:"interface-name"`
HealthCheckLazyDefault bool `json:"health-check-lazy-default"`
TouchAfterLazyPassNum int `json:"touch-after-lazy-pass-num"`
}

// Inbound
Expand Down Expand Up @@ -132,6 +133,7 @@ type RawConfig struct {
Secret string `yaml:"secret"`
Interface string `yaml:"interface-name"`
HealthCheckLazyDefault bool `yaml:"health-check-lazy-default"`
TouchAfterLazyPassNum int `yaml:"touch-after-lazy-pass-num"`

ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
Hosts map[string]string `yaml:"hosts"`
Expand Down Expand Up @@ -161,6 +163,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
Authentication: []string{},
LogLevel: log.INFO,
HealthCheckLazyDefault: true,
TouchAfterLazyPassNum: 0,
Hosts: map[string]string{},
Rule: []string{},
Proxy: []map[string]interface{}{},
Expand Down Expand Up @@ -263,6 +266,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
IPv6: cfg.IPv6,
Interface: cfg.Interface,
HealthCheckLazyDefault: cfg.HealthCheckLazyDefault,
TouchAfterLazyPassNum: cfg.TouchAfterLazyPassNum,
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func GetGeneral() *config.General {
Mode: tunnel.Mode(),
LogLevel: log.Level(),
HealthCheckLazyDefault: provider.HealthCheckLazyDefault(),
TouchAfterLazyPassNum: provider.TouchAfterLazyPassNum(),
}

return general
Expand Down Expand Up @@ -165,6 +166,7 @@ func updateGeneral(general *config.General, force bool) {
tunnel.SetMode(general.Mode)
resolver.DisableIPv6 = !general.IPv6
provider.SetHealthCheckLazyDefault(general.HealthCheckLazyDefault)
provider.SetTouchAfterLazyPassNum(general.TouchAfterLazyPassNum)

if general.Interface != "" {
dialer.DialHook = dialer.DialerWithInterface(general.Interface)
Expand Down
5 changes: 5 additions & 0 deletions hub/route/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type configSchema struct {
Mode *tunnel.TunnelMode `json:"mode"`
LogLevel *log.LogLevel `json:"log-level"`
HealthCheckLazyDefault *bool `json:"health-check-lazy-default"`
TouchAfterLazyPassNum *int `json:"touch-after-lazy-pass-num"`
}

func getConfigs(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -98,6 +99,10 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
provider.SetHealthCheckLazyDefault(*general.HealthCheckLazyDefault)
}

if general.TouchAfterLazyPassNum != nil {
provider.SetTouchAfterLazyPassNum(*general.TouchAfterLazyPassNum)
}

render.NoContent(w, r)
}

Expand Down

0 comments on commit eabf0fc

Please sign in to comment.