* Support for all VPN providers * Update all VPN providers servers information * Remove old tooling binaries
42 lines
953 B
Go
42 lines
953 B
Go
package updater
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
)
|
|
|
|
func newResolver(resolverAddress string) *net.Resolver {
|
|
return &net.Resolver{
|
|
PreferGo: true,
|
|
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
d := net.Dialer{}
|
|
return d.DialContext(ctx, "udp", net.JoinHostPort(resolverAddress, "53"))
|
|
},
|
|
}
|
|
}
|
|
|
|
func newLookupIP(r *net.Resolver) lookupIPFunc {
|
|
return func(ctx context.Context, host string) (ips []net.IP, err error) {
|
|
addresses, err := r.LookupIPAddr(ctx, host)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ips = make([]net.IP, len(addresses))
|
|
for i := range addresses {
|
|
ips[i] = addresses[i].IP
|
|
}
|
|
return ips, nil
|
|
}
|
|
}
|
|
|
|
func resolveRepeat(ctx context.Context, lookupIP lookupIPFunc, host string, n int) (ips []net.IP, err error) {
|
|
for i := 0; i < n; i++ {
|
|
newIPs, err := lookupIP(ctx, host)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ips = append(ips, newIPs...)
|
|
}
|
|
return uniqueSortedIPs(ips), nil
|
|
}
|