]> 127.0.0.1 Git - front/.git/commitdiff
1 v0.1.20241021020553
authorqydysky <qydysky@foxmail.com>
Mon, 21 Oct 2024 02:04:09 +0000 (02:04 +0000)
committerGitHub <noreply@github.com>
Mon, 21 Oct 2024 02:04:09 +0000 (02:04 +0000)
config.go
rollRule.go

index 3d1f521f4233b9c7197e173de98e5cf2cb639670..391679369caad6228596ddb992a6816972cd7aab 100755 (executable)
--- a/config.go
+++ b/config.go
@@ -399,6 +399,9 @@ func (t *Back) SwapSign(logger Logger) {
        } else {
                t.verifyPeerCer, t.verifyPeerCerErr = os.ReadFile(path)
        }
+       if t.lastChosenT.IsZero() {
+               t.lastChosenT = time.Now()
+       }
        t.AlwaysUp = len(t.route.Backs) == 1 || t.AlwaysUp
 }
 
index fc9d00d5765211f5255c67c70a51bd18bb0f6c7c..e840532117a7ac266f6591b943292964eb643bc4 100644 (file)
@@ -3,6 +3,7 @@ package front
 import (
        "math/rand/v2"
        "slices"
+       "time"
 )
 
 var rollRuleMap = make(map[string]func(backLink []*Back))
@@ -30,7 +31,7 @@ func init() {
 
        rollRuleMap[`loop`] = func(backLink []*Back) {
                slices.SortStableFunc(backLink, func(a, b *Back) int {
-                       return a.lastChosenT.Compare(b.lastChosenT)
+                       return int(time.Since(a.lastChosenT).Milliseconds()/int64(a.Weight+1) - time.Since(b.lastChosenT).Milliseconds()/int64(b.Weight+1))
                })
        }
 }