]> git.meshlink.io Git - meshlink/commitdiff
"last successfull connect" introduced
authorNiklas Hofmann <niklas.hofmann@everbase.net>
Wed, 13 Aug 2014 15:02:28 +0000 (17:02 +0200)
committerNiklas Hofmann <niklas.hofmann@everbase.net>
Wed, 13 Aug 2014 15:02:28 +0000 (17:02 +0200)
examples/manynodes.c
src/net.c
src/node.h
src/protocol_auth.c

index 22ebad2145e52ae1cb5d75b595f9c6f756e06c1a..2e26739c5e03dd3c18a2bcca773fb54a9dbff298 100644 (file)
@@ -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");
index 146f95f38753a5f5164213c5f7208dd9d94fb9be..8400b936bd4f08d18ed8c5fe44a31e053098ed1c 100644 (file)
--- 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"); }
index 409449c94e80ed1c382d82522c275474ee86d7dc..b669b5daf9f02ee622f168f2098bfd310c6870cb 100644 (file)
@@ -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 */
index 9cb96b6590aecd6dd47f1af1fb23fc2ca694178c..404a81c88de8ec09fddc65f58d926a09f4935eda 100644 (file)
@@ -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)) {