]> git.meshlink.io Git - meshlink/commitdiff
Extend the timeout period of the authentication phase on progress.
authorGuus Sliepen <guus@meshlink.io>
Fri, 25 Sep 2020 20:00:55 +0000 (22:00 +0200)
committerGuus Sliepen <guus@meshlink.io>
Fri, 25 Sep 2020 20:00:55 +0000 (22:00 +0200)
If there is progress during the authentication phase of connections, we reset
the ping timer to give extra time to complete the authentication.

We do the same for invitation connections.

src/protocol_auth.c

index 4165bb1b987cfbfa4dae0d5362a8137ef7eeaece..7db41d51eb0d54159955fdbf0f74705ac7fe3095 100644 (file)
@@ -146,6 +146,9 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
        connection_t *c = handle;
        meshlink_handle_t *mesh = c->mesh;
 
+       // Extend the time for the invitation exchange upon receiving a valid message
+       c->last_ping_time = mesh->loop.now.tv_sec;
+
        if(type == SPTPS_HANDSHAKE) {
                // The peer should send its cookie first.
                return true;
@@ -207,6 +210,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 
                c->protocol_minor = 2;
                c->allow_request = 1;
+               c->last_ping_time = mesh->loop.now.tv_sec;
 
                return sptps_start(&c->sptps, c, false, false, mesh->invitation_key, c->ecdsa, meshlink_invitation_label, sizeof(meshlink_invitation_label), send_meta_sptps, receive_invitation_sptps);
        }
@@ -275,6 +279,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        }
 
        c->allow_request = ACK;
+       c->last_ping_time = mesh->loop.now.tv_sec;
        char label[sizeof(meshlink_tcp_label) + strlen(mesh->self->name) + strlen(c->name) + 2];
 
        if(c->outgoing) {
@@ -291,6 +296,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 }
 
 bool send_ack(meshlink_handle_t *mesh, connection_t *c) {
+       c->last_ping_time = mesh->loop.now.tv_sec;
        return send_request(mesh, c, NULL, "%d %s %d %x", ACK, mesh->myport, mesh->devclass, OPTION_PMTU_DISCOVERY | (PROT_MINOR << 24));
 }