diff options
author | sin <sin@2f30.org> | 2014-11-30 17:14:26 +0000 |
---|---|---|
committer | sin <sin@2f30.org> | 2014-11-30 17:19:15 +0000 |
commit | 7719eafe2a566c8998901e75cca6545f5afa419c (patch) | |
tree | 5e7d0180f5b2972e390b8cfebd985334b16ebc54 /ratox.c | |
parent | 5777da3a2865fb640cebf49cc6a4dbc476faafbe (diff) |
Connect to nodes in a random order to minimize load on any given node
Diffstat (limited to 'ratox.c')
-rw-r--r-- | ratox.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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) |