diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2023-03-08 11:26:20 +0100 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2023-03-08 11:58:12 +0100 |
commit | ffa9ab61f478e0ddfd03f00f3dbc3975c7652a8d (patch) | |
tree | b497a9bdcc863b802bb1ee55e5e7337bc827e661 /pkg/vpn/bonafide/gateways.go | |
parent | da0621717b7bf16144be5c01dddbee4747a82867 (diff) |
bug: avoid crash when gateways not initialzedmain
fix also wrong call to sort by tz - should prefer menshen.
Diffstat (limited to 'pkg/vpn/bonafide/gateways.go')
-rw-r--r-- | pkg/vpn/bonafide/gateways.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go index 4b7e6dd..b8690c6 100644 --- a/pkg/vpn/bonafide/gateways.go +++ b/pkg/vpn/bonafide/gateways.go @@ -317,7 +317,7 @@ func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) { } log.Println("seems to be initialized...") - if len(p.recommended) == 0 { + if len(p.recommended) != 0 { return p.getGatewaysFromMenshen(transport, 999) } return p.getGatewaysByTimezone(transport, tz, 999) @@ -340,6 +340,7 @@ func (p *gatewayPool) getGatewaysFromMenshen(transport string, max int) ([]Gatew /* the old timezone based heuristic, when everything goes wrong */ func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max int) ([]Gateway, error) { + log.Println("Sorting gateways by timezone") gws := make([]Gateway, 0) gwVector := []gatewayDistance{} @@ -348,9 +349,10 @@ func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max continue } distance := 13 - gwOffset, err := strconv.Atoi(p.locations[gw.Location].Timezone) + tz := p.locations[gw.Location].Timezone + gwOffset, err := strconv.Atoi(tz) if err != nil { - log.Printf("Error sorting gateways: %v", err) + log.Printf("Error sorting gateways: loc=%s, tz=%s; %v", gw.Location, tz, err) return gws, err } distance = tzDistance(tzOffsetHours, gwOffset) |