From a569797b9cbd3db571ea9216fd103347acd6ccff Mon Sep 17 00:00:00 2001 From: Niklas Hofmann Date: Wed, 13 Aug 2014 17:02:28 +0200 Subject: [PATCH] "last successfull connect" introduced --- examples/manynodes.c | 2 +- src/net.c | 28 ++++++++++++++-------------- src/node.h | 1 + src/protocol_auth.c | 2 ++ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/examples/manynodes.c b/examples/manynodes.c index 22ebad21..2e26739c 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -241,7 +241,7 @@ int main(int argc, char *argv[]) { snprintf(nodename, sizeof nodename, "%snode%d", namesprefix,i); snprintf(filename, sizeof filename, "%s/%s", basebase, nodename); bool itsnew = access(filename, R_OK); - mesh[i] = meshlink_open(filename, nodename, "manynodes", DEV_CLASS_PORTABLE); + mesh[i] = meshlink_open(filename, nodename, "manynodes", i%_DEV_CLASS_MAX); meshlink_set_log_cb(mesh[i], MESHLINK_INFO, log_message); if(itsnew) meshlink_add_address(mesh[i], "localhost"); diff --git a/src/net.c b/src/net.c index 146f95f3..8400b936 100644 --- a/src/net.c +++ b/src/net.c @@ -131,8 +131,8 @@ static void timeout_handler(event_loop_t *loop, void *data) { timeout_set(&mesh->loop, data, &(struct timeval){mesh->pingtimeout, rand() % 100000}); } -// devclass asc, last_connect_try desc -static int node_compare_devclass_asc_last_connect_try_desc(const void *a, const void *b) +// devclass asc, last_successfull_connection desc +static int node_compare_devclass_asc_lsc_desc(const void *a, const void *b) { const node_t *na = a, *nb = b; @@ -142,13 +142,13 @@ static int node_compare_devclass_asc_last_connect_try_desc(const void *a, const if(na->devclass > nb->devclass) { return 1; } - if(na->last_connect_try == nb->last_connect_try) + if(na->last_successfull_connection == nb->last_successfull_connection) return 0; - if(na->last_connect_try == 0 || na->last_connect_try > nb->last_connect_try) + if(na->last_successfull_connection == 0 || na->last_successfull_connection > nb->last_successfull_connection) return -1; - if(nb->last_connect_try == 0 || na->last_connect_try < nb->last_connect_try) + if(nb->last_successfull_connection == 0 || na->last_successfull_connection < nb->last_successfull_connection) return 1; if(na < nb) @@ -160,18 +160,18 @@ static int node_compare_devclass_asc_last_connect_try_desc(const void *a, const return 0; } -// last_connect_try desc -static int node_compare_last_connect_try_desc(const void *a, const void *b) +// last_successfull_connection desc +static int node_compare_lsc_desc(const void *a, const void *b) { const node_t *na = a, *nb = b; - if(na->last_connect_try == nb->last_connect_try) + if(na->last_successfull_connection == nb->last_successfull_connection) return 0; - if(na->last_connect_try == 0 || na->last_connect_try > nb->last_connect_try) + if(na->last_successfull_connection == 0 || na->last_successfull_connection > nb->last_successfull_connection) return -1; - if(nb->last_connect_try == 0 || na->last_connect_try < nb->last_connect_try) + if(nb->last_successfull_connection == 0 || na->last_successfull_connection < nb->last_successfull_connection) return 1; if(na < nb) @@ -372,7 +372,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if(cur_connects < min_connects) { - splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_last_connect_try_desc, NULL); + splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL); for splay_each(node_t, n, mesh->nodes) { @@ -411,7 +411,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if( connects < min_connects ) { - splay_tree_t *nodes = splay_alloc_tree(node_compare_last_connect_try_desc, NULL); + splay_tree_t *nodes = splay_alloc_tree(node_compare_lsc_desc, NULL); for splay_each(node_t, n, mesh->nodes) { @@ -443,7 +443,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) { - splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_last_connect_try_desc, NULL); + splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL); for splay_each(node_t, n, mesh->nodes) { @@ -487,7 +487,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { outgoing->mesh = mesh; outgoing->name = xstrdup(connect_to->name); list_insert_tail(mesh->outgoings, outgoing); - setup_outgoing_connection(mesh, outgoing); + setup_outgoing_connection(mesh, outgoing); } else { logger(mesh, MESHLINK_INFO, "* skip autoconnect since it is an outgoing connection already"); } diff --git a/src/node.h b/src/node.h index 409449c9..b669b5da 100644 --- a/src/node.h +++ b/src/node.h @@ -70,6 +70,7 @@ typedef struct node_t { struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */ time_t last_connect_try; + time_t last_successfull_connection; uint32_t sent_seqno; /* Sequence number last sent to this node */ uint32_t received_seqno; /* Sequence number last received from this node */ diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 9cb96b65..404a81c8 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -433,6 +433,8 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { n->devclass = devclass; node_write_devclass(mesh, n); + n->last_successfull_connection = time(NULL); + n->connection = c; c->node = n; if(!(c->options & options & OPTION_PMTU_DISCOVERY)) { -- 2.39.5