mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-02 00:16:20 +00:00
🔨 Refactor config types
This commit is contained in:
@ -32,7 +32,7 @@ func getClientDoFunc(
|
||||
ctx context.Context,
|
||||
timeout time.Duration,
|
||||
proxies []config.Proxy,
|
||||
dodosCount int,
|
||||
dodosCount uint,
|
||||
maxConns uint,
|
||||
yes bool,
|
||||
URL *url.URL,
|
||||
@ -46,7 +46,7 @@ func getClientDoFunc(
|
||||
if ctx.Err() != nil {
|
||||
return nil
|
||||
}
|
||||
activeProxyClientsCount := len(activeProxyClients)
|
||||
activeProxyClientsCount := uint(len(activeProxyClients))
|
||||
var yesOrNoMessage string
|
||||
var yesOrNoDefault bool
|
||||
if activeProxyClientsCount == 0 {
|
||||
@ -114,18 +114,19 @@ func getActiveProxyClients(
|
||||
ctx context.Context,
|
||||
proxies []config.Proxy,
|
||||
timeout time.Duration,
|
||||
dodosCount int,
|
||||
dodosCount uint,
|
||||
maxConns uint,
|
||||
URL *url.URL,
|
||||
) []*fasthttp.HostClient {
|
||||
activeProxyClientsArray := make([][]*fasthttp.HostClient, dodosCount)
|
||||
proxiesCount := len(proxies)
|
||||
dodosCountInt := int(dodosCount)
|
||||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
streamWG sync.WaitGroup
|
||||
)
|
||||
wg.Add(dodosCount)
|
||||
wg.Add(dodosCountInt)
|
||||
streamWG.Add(1)
|
||||
var proxiesSlice []config.Proxy
|
||||
increase := make(chan int64, proxiesCount)
|
||||
@ -133,11 +134,11 @@ func getActiveProxyClients(
|
||||
streamCtx, streamCtxCancel := context.WithCancel(context.Background())
|
||||
go streamProgress(streamCtx, &streamWG, int64(proxiesCount), "Searching for active proxies🌐", increase)
|
||||
|
||||
for i := 0; i < dodosCount; i++ {
|
||||
if i+1 == dodosCount {
|
||||
proxiesSlice = proxies[i*proxiesCount/dodosCount:]
|
||||
for i := range dodosCountInt {
|
||||
if i+1 == dodosCountInt {
|
||||
proxiesSlice = proxies[i*proxiesCount/dodosCountInt:]
|
||||
} else {
|
||||
proxiesSlice = proxies[i*proxiesCount/dodosCount : (i+1)*proxiesCount/dodosCount]
|
||||
proxiesSlice = proxies[i*proxiesCount/dodosCountInt : (i+1)*proxiesCount/dodosCountInt]
|
||||
}
|
||||
go findActiveProxyClients(
|
||||
ctx,
|
||||
@ -305,11 +306,12 @@ func getDialFunc(proxy *config.Proxy, timeout time.Duration) (fasthttp.DialFunc,
|
||||
// getSharedRandomClientDoFunc is equivalent to getSharedClientDoFunc but uses a random client from the provided slice.
|
||||
func getSharedRandomClientDoFunc(
|
||||
clients []*fasthttp.HostClient,
|
||||
clientsCount int,
|
||||
clientsCount uint,
|
||||
timeout time.Duration,
|
||||
) ClientDoFunc {
|
||||
clientsCountInt := int(clientsCount)
|
||||
return func(ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) {
|
||||
client := clients[rand.Intn(clientsCount)]
|
||||
client := clients[rand.Intn(clientsCountInt)]
|
||||
defer client.CloseIdleConnections()
|
||||
response := fasthttp.AcquireResponse()
|
||||
ch := make(chan error)
|
||||
|
@ -67,16 +67,17 @@ func releaseDodos(
|
||||
ctx context.Context,
|
||||
mainRequest *fasthttp.Request,
|
||||
clientDoFunc ClientDoFunc,
|
||||
dodosCount int,
|
||||
requestCount int,
|
||||
dodosCount uint,
|
||||
requestCount uint,
|
||||
) Responses {
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
streamWG sync.WaitGroup
|
||||
requestCountPerDodo int
|
||||
requestCountPerDodo uint
|
||||
dodosCountInt = int(dodosCount)
|
||||
)
|
||||
|
||||
wg.Add(dodosCount)
|
||||
wg.Add(dodosCountInt)
|
||||
streamWG.Add(1)
|
||||
responses := make([][]Response, dodosCount)
|
||||
increase := make(chan int64, requestCount)
|
||||
@ -84,10 +85,9 @@ func releaseDodos(
|
||||
streamCtx, streamCtxCancel := context.WithCancel(context.Background())
|
||||
go streamProgress(streamCtx, &streamWG, int64(requestCount), "Dodos Working🔥", increase)
|
||||
|
||||
for i := 0; i < dodosCount; i++ {
|
||||
for i := range dodosCount {
|
||||
if i+1 == dodosCount {
|
||||
requestCountPerDodo = requestCount -
|
||||
(i * requestCount / dodosCount)
|
||||
requestCountPerDodo = requestCount - (i * requestCount / dodosCount)
|
||||
} else {
|
||||
requestCountPerDodo = ((i + 1) * requestCount / dodosCount) -
|
||||
(i * requestCount / dodosCount)
|
||||
@ -129,7 +129,7 @@ func sendRequest(
|
||||
request *fasthttp.Request,
|
||||
responseData *[]Response,
|
||||
increase chan<- int64,
|
||||
requestCount int,
|
||||
requestCount uint,
|
||||
clientDo ClientDoFunc,
|
||||
wg *sync.WaitGroup,
|
||||
) {
|
||||
|
Reference in New Issue
Block a user