chore: rebuild slowdown code

This commit is contained in:
wwqgtxx
2024-01-30 19:41:34 +08:00
parent 947ad9b308
commit e6011301b2
8 changed files with 223 additions and 70 deletions

View File

@@ -11,12 +11,11 @@ import (
"sync"
"time"
"github.com/jpillora/backoff"
N "github.com/metacubex/mihomo/common/net"
"github.com/metacubex/mihomo/component/nat"
P "github.com/metacubex/mihomo/component/process"
"github.com/metacubex/mihomo/component/resolver"
"github.com/metacubex/mihomo/component/slowdown"
"github.com/metacubex/mihomo/component/sniffer"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/features"
@@ -699,12 +698,7 @@ func shouldStopRetry(err error) bool {
}
func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe func(err error)) (t T, err error) {
b := &backoff.Backoff{
Min: 10 * time.Millisecond,
Max: 1 * time.Second,
Factor: 2,
Jitter: true,
}
s := slowdown.New()
for i := 0; i < 10; i++ {
t, err = ft(ctx)
if err != nil {
@@ -714,10 +708,9 @@ func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe f
if shouldStopRetry(err) {
return
}
select {
case <-time.After(b.Duration()):
if s.Wait(ctx) == nil {
continue
case <-ctx.Done():
} else {
return
}
} else {