]> git.meshlink.io Git - meshlink/blobdiff - src/net_socket.c
Add a configurable fast connection retry period.
[meshlink] / src / net_socket.c
index 51e0caccfd19c1696cf5bf69c8c0aa4f7ed87189..eb9e3fc41f98fca0fe15bf8d0b998425e69553fd 100644 (file)
@@ -246,14 +246,18 @@ static void retry_outgoing_handler(event_loop_t *loop, void *data) {
 }
 
 void retry_outgoing(meshlink_handle_t *mesh, outgoing_t *outgoing) {
-       outgoing->timeout += 5;
+       if(!mesh->reachable && mesh->loop.now.tv_sec < mesh->last_unreachable + mesh->dev_class_traits[mesh->devclass].fast_retry_period) {
+               outgoing->timeout = 1;
+       } else {
+               outgoing->timeout += 5;
+       }
 
        if(outgoing->timeout > mesh->maxtimeout) {
                outgoing->timeout = mesh->maxtimeout;
        }
 
        timeout_add(&mesh->loop, &outgoing->ev, retry_outgoing_handler, outgoing, &(struct timeval) {
-               outgoing->timeout, rand() % 100000
+               outgoing->timeout, prng(mesh, TIMER_FUDGE)
        });
 
        logger(mesh, MESHLINK_INFO, "Trying to re-establish outgoing connection in %d seconds", outgoing->timeout);
@@ -493,7 +497,7 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo
        return false;
 }
 
-bool do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+void do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
        struct addrinfo *proxyai = NULL;
        int result;
 
@@ -507,7 +511,7 @@ begin:
                        retry_outgoing(mesh, outgoing);
                }
 
-               return false;
+               return;
        }
 
        connection_t *c = new_connection();
@@ -586,8 +590,6 @@ begin:
        connection_add(mesh, c);
 
        io_add(&mesh->loop, &c->io, handle_meta_io, c, c->socket, IO_READ | IO_WRITE);
-
-       return true;
 }
 
 void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {