This commit is contained in:
root 2020-04-18 00:19:20 -04:00
parent 544aacf0fd
commit b0b783f7c8
3 changed files with 7 additions and 7 deletions

View File

@ -2,6 +2,6 @@ proxy:{% for i in instances %}
- url: "socks5://192.168.122.128:{{1080+i["idx"]}}"
weight: {{i["weight"]}}
{% end %}
load-balance-mode: "cached-shuffle"
load-balance-mode: "{{load_balance_mode}}"
cache-max-length: 256
dynamic-weight-file: "{{dynamic_weight_fp}}"

View File

@ -152,6 +152,8 @@ func (pm *ProxyManager) DescribeLoadBalanceMode() string {
return fmt.Sprintf("sticky with maximum cache size of %d", pm.CacheMaxLength)
} else if pm.LoadBalanceMode == cachedShuffle {
return fmt.Sprintf("cached shuffle with maximum cache size of %d", pm.CacheMaxLength)
} else if pm.LoadBalanceMode == fallback {
return "fallback mode"
} else {
return "randomize every connection"
}
@ -214,12 +216,10 @@ func (pm *ProxyManager) Get(addr string) (string, bool) {
} else if pm.LoadBalanceMode == fallback {
addr := "*"
idx, ok := pm.Cache.Get(addr)
if ok {
idx = (idx + 1) % (len(pm.enabledIndics))
} else {
if !ok {
idx = pm.Chooser.Pick().(int)
}
pm.Cache.SetTrim(addr, idx, pm.CacheMaxLength)
}
return pm.Proxys[pm.enabledIndics[idx]].URL, true
} else {
idx := pm.Chooser.Pick().(int)

View File

@ -41,10 +41,10 @@ class OManager:
def generate_lb_cfg(self, load_balance_mode):
lb_cfg_fp = os.path.join(
self.base_folder, "go-socks-lb.yml")
self.base_folder, f"go-socks-lb-{load_balance_mode}.yml")
self.dynamic_weight_fp = os.path.join(self.base_folder, "weights.json")
with open(f"go-socks-lb-{load_balance_mode}.yml.template", "r") as template_f:
with open(f"go-socks-lb.yml.template", "r") as template_f:
buf = template_f.read()
template = Template(buf)
items = {