]> git.meshlink.io Git - meshlink/commitdiff
create a new connection only in case there is none
authorNiklas Hofmann <niklas.hofmann@everbase.net>
Tue, 12 Aug 2014 15:34:50 +0000 (17:34 +0200)
committerNiklas Hofmann <niklas.hofmann@everbase.net>
Tue, 12 Aug 2014 15:34:50 +0000 (17:34 +0200)
src/net.c

index 9659a8f26236f19b8e0e7d8859744d5a7dd38673..a528eb43979c3f7ccf86cebf2fa164ee2559f24a 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -439,12 +439,24 @@ static void periodic_handler(event_loop_t *loop, void *data) {
 
                if(connect_to && !connect_to->connection)
                {
-                       logger(mesh, MESHLINK_INFO, "Autoconnecting to %s", connect_to->name);
-                       outgoing_t *outgoing = xzalloc(sizeof(outgoing_t));
-                       outgoing->mesh = mesh;
-                       outgoing->name = xstrdup(connect_to->name);
-                       list_insert_tail(mesh->outgoings, outgoing);
-                       setup_outgoing_connection(mesh, outgoing);
+                       /* check if there is already a connection attempt to this node */
+                       bool found = false;
+                       for list_each(outgoing_t, outgoing, mesh->outgoings) {
+                               if(!strcmp(outgoing->name, connect_to->name)) {
+                                       found = true;
+                                       break;
+                               }
+                       }
+
+                       if(!found)
+                       {
+                               logger(mesh, MESHLINK_INFO, "Autoconnecting to %s", connect_to->name);
+                               outgoing_t *outgoing = xzalloc(sizeof(outgoing_t));
+                               outgoing->mesh = mesh;
+                               outgoing->name = xstrdup(connect_to->name);
+                               list_insert_tail(mesh->outgoings, outgoing);
+                               setup_outgoing_connection(mesh, outgoing);      
+                       }
                }