From 7719eafe2a566c8998901e75cca6545f5afa419c Mon Sep 17 00:00:00 2001 From: sin Date: Sun, 30 Nov 2014 17:14:26 +0000 Subject: Connect to nodes in a random order to minimize load on any given node --- ratox.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ratox.c b/ratox.c index 5f40ecc..fa78f13 100644 --- a/ratox.c +++ b/ratox.c @@ -1258,10 +1258,21 @@ static int toxconnect(void) { struct node *n; + struct node tmp; uint8_t id[TOX_CLIENT_ID_SIZE]; - size_t i; + size_t i, j; int r; + srand(time(NULL)); + + /* shuffle it to minimize load on nodes */ + for (i = LEN(nodes) - 1; i > 0; i--) { + j = rand() % LEN(nodes); + tmp = nodes[j]; + nodes[j] = nodes[i]; + nodes[i] = tmp; + } + for (i = 0; i < LEN(nodes); i++) { n = &nodes[i]; if (ipv6 == 1 && !n->addr6) -- cgit v1.2.3