X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnet.c;h=a42d933bef822a375fea4c5b4e823d4f6553f683;hb=3bcd5ec746a5575c0c66f8b34922c038eb363b0a;hp=ce7e00d862a931bf21490e7582d5bb8afe7de327;hpb=fa05f996c5500c056a36c1d43e33a407f876643c;p=meshlink diff --git a/src/net.c b/src/net.c index ce7e00d8..a42d933b 100644 --- a/src/net.c +++ b/src/net.c @@ -490,23 +490,27 @@ static void periodic_handler(event_loop_t *loop, void *data) { logger(mesh, MESHLINK_DEBUG, "Autoconnect trying to connect to %s", connect_to->name); /* check if there is already a connection attempt to this node */ - bool found = false; + bool skip = false; for list_each(outgoing_t, outgoing, mesh->outgoings) { if(outgoing->node == connect_to) { - found = true; + logger(mesh, MESHLINK_DEBUG, "* skip autoconnect since it is an outgoing connection already"); + skip = true; break; } } - if(!found) { + if(!connect_to->status.reachable && !node_read_public_key(mesh, connect_to)) { + logger(mesh, MESHLINK_DEBUG, "* skip autoconnect since we don't know this node's public key"); + skip = true; + } + + if(!skip) { logger(mesh, MESHLINK_DEBUG, "Autoconnecting to %s", connect_to->name); outgoing_t *outgoing = xzalloc(sizeof(outgoing_t)); outgoing->node = connect_to; 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"); } } @@ -581,12 +585,23 @@ static void periodic_handler(event_loop_t *loop, void *data) { terminate_connection(mesh, disconnect_from->connection, disconnect_from->connection->status.active); } + // reduce timeout if we don't have enough connections + outgoings + if(cur_connects + mesh->outgoings->count < 3) { + timeout = 1; + } // done! logger(mesh, MESHLINK_DEBUG, "--- autoconnect end ---"); } + for splay_each(node_t, n, mesh->nodes) { + if(n->status.dirty) { + node_write_config(mesh, n); + n->status.dirty = false; + } + } + timeout_set(&mesh->loop, data, &(struct timeval) { timeout, rand() % 100000 });