- 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);
+ if(connect_to && !connect_to->connection) {
+ connect_to->last_connect_try = time(NULL);
+
+ /* 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_DEBUG, "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);
+ } else {
+ logger(mesh, MESHLINK_DEBUG, "* skip autoconnect since it is an outgoing connection already");
+ }