🔨 Refactor client and request generation to use random value cycling

This commit is contained in:
2024-09-15 17:34:24 +04:00
parent de5a5dc96e
commit 2f37f8c2c1
3 changed files with 28 additions and 44 deletions

View File

@ -280,23 +280,7 @@ func getDialFunc(proxy *config.Proxy, timeout time.Duration) (fasthttp.DialFunc,
// getSharedClientFuncMultiple returns a ClientGeneratorFunc that cycles through a list of fasthttp.HostClient instances.
// The function uses a local random number generator to determine the starting index and stop index for cycling through the clients.
func getSharedClientFuncMultiple(clients []*fasthttp.HostClient, localRand *rand.Rand) ClientGeneratorFunc {
var (
clientsCount int = len(clients)
currentIndex int = localRand.Intn(clientsCount)
stopIndex int = clientsCount
)
return func() *fasthttp.HostClient {
client := clients[currentIndex%clientsCount]
if currentIndex == stopIndex {
currentIndex = localRand.Intn(clientsCount)
stopIndex = currentIndex - 1
} else {
currentIndex = (currentIndex + 1) % clientsCount
}
return client
}
return utils.RandomValueCycle(clients, localRand)
}
// getSharedClientFuncSingle returns a ClientGeneratorFunc that always returns the provided fasthttp.HostClient instance.