Updater loop with period and http route (#240)

* Updater loop with period and http route
* Using DNS over TLS to update servers
* Better logging
* Remove goroutines for cyberghost updater
* Respects context for servers update (quite slow overall)
* Increase shutdown grace period to 5 seconds
* Update announcement
* Add log lines for each provider update start
This commit is contained in:
Quentin McGaw
2020-09-12 14:04:54 -04:00
committed by GitHub
parent ee64cbf1fd
commit a19efbd923
19 changed files with 358 additions and 82 deletions

View File

@@ -2,26 +2,34 @@ package updater
import (
"context"
"fmt"
"sort"
"github.com/qdm12/gluetun/internal/models"
)
func (u *updater) updateWindscribe(ctx context.Context) {
servers := findWindscribeServers(ctx, u.lookupIP)
func (u *updater) updateWindscribe(ctx context.Context) (err error) {
servers, err := findWindscribeServers(ctx, u.lookupIP)
if err != nil {
return fmt.Errorf("cannot update Windscribe servers: %w", err)
}
if u.options.Stdout {
u.println(stringifyWindscribeServers(servers))
}
u.servers.Windscribe.Timestamp = u.timeNow().Unix()
u.servers.Windscribe.Servers = servers
return nil
}
func findWindscribeServers(ctx context.Context, lookupIP lookupIPFunc) (servers []models.WindscribeServer) {
func findWindscribeServers(ctx context.Context, lookupIP lookupIPFunc) (servers []models.WindscribeServer, err error) {
allCountryCodes := getCountryCodes()
windscribeCountryCodes := getWindscribeSubdomainToRegion()
possibleCountryCodes := mergeCountryCodes(windscribeCountryCodes, allCountryCodes)
const domain = "windscribe.com"
for countryCode, region := range possibleCountryCodes {
if err := ctx.Err(); err != nil {
return nil, err
}
host := countryCode + "." + domain
ips, err := resolveRepeat(ctx, lookupIP, host, 2)
if err != nil || len(ips) == 0 {
@@ -35,7 +43,7 @@ func findWindscribeServers(ctx context.Context, lookupIP lookupIPFunc) (servers
sort.Slice(servers, func(i, j int) bool {
return servers[i].Region < servers[j].Region
})
return servers
return servers, nil
}
func mergeCountryCodes(base, extend map[string]string) (merged map[string]string) {