Fix guard pattern for max parallel DNS requests
This commit is contained in:
@@ -38,7 +38,6 @@ func findCyberghostServers(ctx context.Context, lookupIP lookupIPFunc) (servers
|
|||||||
}
|
}
|
||||||
const domain = "cg-dialup.net"
|
const domain = "cg-dialup.net"
|
||||||
host := fmt.Sprintf("%s-%s.%s", groupID, countryCode, domain)
|
host := fmt.Sprintf("%s-%s.%s", groupID, countryCode, domain)
|
||||||
guard <- struct{}{}
|
|
||||||
go tryCyberghostHostname(ctx, lookupIP, host, groupName, region, results, guard)
|
go tryCyberghostHostname(ctx, lookupIP, host, groupName, region, results, guard)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,9 +59,10 @@ func findCyberghostServers(ctx context.Context, lookupIP lookupIPFunc) (servers
|
|||||||
|
|
||||||
func tryCyberghostHostname(ctx context.Context, lookupIP lookupIPFunc,
|
func tryCyberghostHostname(ctx context.Context, lookupIP lookupIPFunc,
|
||||||
host, groupName, region string,
|
host, groupName, region string,
|
||||||
results chan<- models.CyberghostServer, guard chan<- struct{}) {
|
results chan<- models.CyberghostServer, guard chan struct{}) {
|
||||||
|
guard <- struct{}{}
|
||||||
defer func() {
|
defer func() {
|
||||||
guard <- struct{}{}
|
<-guard
|
||||||
}()
|
}()
|
||||||
IPs, err := resolveRepeat(ctx, lookupIP, host, 2)
|
IPs, err := resolveRepeat(ctx, lookupIP, host, 2)
|
||||||
if err != nil || len(IPs) == 0 {
|
if err != nil || len(IPs) == 0 {
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ func (u *updater) updatePIAOld(ctx context.Context) (err error) {
|
|||||||
return fmt.Errorf("cannot find any hosts in %s", fileName)
|
return fmt.Errorf("cannot find any hosts in %s", fileName)
|
||||||
}
|
}
|
||||||
region := strings.TrimSuffix(fileName, ".ovpn")
|
region := strings.TrimSuffix(fileName, ".ovpn")
|
||||||
guard <- struct{}{}
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go resolvePIAHostname(ctx, wg, region, hosts, u.lookupIP, errors, serversCh, guard)
|
go resolvePIAHostname(ctx, wg, region, hosts, u.lookupIP, errors, serversCh, guard)
|
||||||
}
|
}
|
||||||
@@ -100,9 +99,10 @@ func (u *updater) updatePIAOld(ctx context.Context) (err error) {
|
|||||||
|
|
||||||
func resolvePIAHostname(ctx context.Context, wg *sync.WaitGroup,
|
func resolvePIAHostname(ctx context.Context, wg *sync.WaitGroup,
|
||||||
region string, hosts []string, lookupIP lookupIPFunc,
|
region string, hosts []string, lookupIP lookupIPFunc,
|
||||||
errors chan<- error, serversCh chan<- models.PIAServer, guard chan<- struct{}) {
|
errors chan<- error, serversCh chan<- models.PIAServer, guard chan struct{}) {
|
||||||
|
guard <- struct{}{}
|
||||||
defer func() {
|
defer func() {
|
||||||
guard <- struct{}{}
|
<-guard
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
var IPs []net.IP //nolint:prealloc
|
var IPs []net.IP //nolint:prealloc
|
||||||
|
|||||||
Reference in New Issue
Block a user