diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-10-08 11:30:16 -0500 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-10-08 11:50:57 -0500 |
commit | 5f24152b972f4e478e15f04b795e8943f8a559d7 (patch) | |
tree | 172b12be7548e1ff7659f582444f0c659e3a7613 /standalone | |
parent | 9f5a4d2daba9c5d27e8c451b19e17115b39184f9 (diff) |
[bug] fix gateway selection by timezone
Go time library returns the timezone offset in seconds and we where
using it as hours.
- Resolves: #72
Diffstat (limited to 'standalone')
-rw-r--r-- | standalone/bonafide.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/standalone/bonafide.go b/standalone/bonafide.go index 449383e..84250ea 100644 --- a/standalone/bonafide.go +++ b/standalone/bonafide.go @@ -30,8 +30,9 @@ import ( ) const ( - certAPI = "https://api.black.riseup.net/1/cert" - eipAPI = "https://api.black.riseup.net/1/config/eip-service.json" + certAPI = "https://api.black.riseup.net/1/cert" + eipAPI = "https://api.black.riseup.net/1/config/eip-service.json" + secondsPerHour = 60 * 60 ) var ( @@ -194,6 +195,7 @@ func (b *bonafide) sortGateways() { gws := []gatewayDistance{} _, tzOffset := time.Now().Zone() + tzOffset = tzOffset / secondsPerHour for _, gw := range b.eip.Gateways { distance := 13 if gw.Location == b.defaultGateway { @@ -209,7 +211,7 @@ func (b *bonafide) sortGateways() { gws = append(gws, gatewayDistance{gw, distance}) } - sort.Slice(gws, func(i, j int) bool { return gws[i].distance > gws[j].distance }) + sort.Slice(gws, func(i, j int) bool { return gws[i].distance < gws[j].distance }) for i, gw := range gws { b.eip.Gateways[i] = gw.gateway } @@ -219,9 +221,8 @@ func tzDistance(offset1, offset2 int) int { abs := func(x int) int { if x < 0 { return -x - } else { - return x } + return x } distance := abs(offset1 - offset2) if distance > 12 { |