diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-11-12 17:05:25 -0600 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-11-12 17:05:25 -0600 |
commit | 66134bc4a2f161f9909e0e71d8e3dfbc5ea97d35 (patch) | |
tree | c9e71f4e326d4e5d91c5c718dac9618cdf4f1e39 /standalone | |
parent | 32c9657ed90563a7f2988496382818436d5e012e (diff) |
[feat] select randomly the gateway if the have the same distance
This commit includes a hack to prioritize giraffe, a new riseup gateway
in europe to reduce the load in the existing node.
- Resolves: #81
Diffstat (limited to 'standalone')
-rw-r--r-- | standalone/bonafide.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/standalone/bonafide.go b/standalone/bonafide.go index 84250ea..b46d9bb 100644 --- a/standalone/bonafide.go +++ b/standalone/bonafide.go @@ -22,6 +22,7 @@ import ( "fmt" "io/ioutil" "log" + "math/rand" "net/http" "sort" "strconv" @@ -211,7 +212,22 @@ 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 }) + rand.Seed(time.Now().UnixNano()) + cmp := func(i, j int) bool { + if gws[i].distance == gws[j].distance { + // TODO: a hack to distribute more the load into the new gw. + // Let's delete it as soon as is more spread the load. + if gws[i].gateway.Host == "giraffe.riseup.net" { + return rand.Intn(4) != 0 + } else if gws[j].gateway.Host == "giraffe.riseup.net" { + return rand.Intn(4) == 0 + } + + return rand.Intn(2) == 1 + } + return gws[i].distance < gws[j].distance + } + sort.Slice(gws, cmp) for i, gw := range gws { b.eip.Gateways[i] = gw.gateway } |