From 2d9f4facf795938b3a19ba65431bc5b3ddd824eb Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 24 Feb 2014 20:08:51 -0500 Subject: [PATCH] connect to limited number of nodes on init instead of all of them --- src/main.c | 9 ++++++--- src/misc_tools.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index b00ed88..448e22b 100644 --- a/src/main.c +++ b/src/main.c @@ -205,6 +205,8 @@ int init_connection_helper(Tox *m, int line) */ static bool srvlist_loaded = false; +#define NUM_INIT_NODES 5 + int init_connection(Tox *m) { if (linecnt > 0) /* already loaded serverlist */ @@ -231,10 +233,11 @@ int init_connection(Tox *m) return 2; res = 3; - int line; + int i; + int n = MIN(NUM_INIT_NODES, linecnt); - for(line = 0; line < linecnt; line++) - if (init_connection_helper(m, line)) + for(i = 0; i < n; ++i) + if (init_connection_helper(m, rand() % linecnt)) res = 0; return res; diff --git a/src/misc_tools.h b/src/misc_tools.h index a3f223c..0aa203f 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -2,8 +2,8 @@ * Toxic -- Tox Curses Client */ -// #define MIN(x, y) (((x) < (y)) ? (x) : (y)) - #define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) /* convert a hex string to binary */ unsigned char *hex_string_to_bin(char hex_string[]);