diff options
Diffstat (limited to 'standalone/bonafide.go')
-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 } |