]> git.meshlink.io Git - meshlink/blobdiff - src/net_socket.c
Add meta-connection attempt callback feature
[meshlink] / src / net_socket.c
index 6d1d8fb386952f1e49ea12fc0d9e7ca5740efe30..3047ccbd8bfedeae2debdeb717bdf441c7bb040f 100644 (file)
@@ -481,14 +481,18 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo
        }
 
        if(outgoing->state == OUTGOING_KNOWN) {
-               if(outgoing->aip || get_recent(mesh, outgoing)) {
-                       if(get_next_ai(mesh, outgoing)) {
-                               return true;
-                       } else {
-                               free_known_addresses(outgoing->ai);
-                               outgoing->ai = NULL;
-                               outgoing->aip = NULL;
-                       }
+               if(!outgoing->aip) {
+                       get_recent(mesh, outgoing);
+               } else {
+                       outgoing->aip = outgoing->aip->ai_next;
+               }
+
+               if(outgoing->aip) {
+                       return true;
+               } else {
+                       free_known_addresses(outgoing->ai);
+                       outgoing->ai = NULL;
+                       outgoing->aip = NULL;
                }
 
                outgoing->state = OUTGOING_END;
@@ -633,6 +637,11 @@ void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
                return;
        }
 
+       if(mesh->connection_try_cb) {
+               node_t *n = lookup_node(mesh, outgoing->name);
+               mesh->connection_try_cb(mesh, (struct meshlink_node *)n);
+       }
+
        do_outgoing_connection(mesh, outgoing);
 }