]> git.meshlink.io Git - meshlink/commitdiff
Ensure consistent use of SPTPS session labels.
authorGuus Sliepen <guus@meshlink.io>
Sun, 25 Jun 2017 18:54:12 +0000 (20:54 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 25 Jun 2017 18:54:12 +0000 (20:54 +0200)
src/meshlink.c
src/meshlink_internal.h
src/protocol_auth.c
src/protocol_key.c

index 8b0c0621a9bd2a84d2abaf3c62a77f165b9a4ebd..0f1e2738762e6a93ed898d2951b363ac721029b3 100644 (file)
@@ -1838,7 +1838,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
        }
 
        // Start an SPTPS session
-       if(!sptps_start(&mesh->sptps, mesh, true, false, key, hiskey, "meshlink invitation", 15, invitation_send, invitation_receive)) {
+       if(!sptps_start(&mesh->sptps, mesh, true, false, key, hiskey, meshlink_invitation_label, sizeof meshlink_invitation_label, invitation_send, invitation_receive)) {
                meshlink_errno = MESHLINK_EINTERNAL;
                pthread_mutex_unlock(&(mesh->mesh_mutex));
                return false;
index 9abe19e0a20a3e65f4deee53fcfbaa3b2a34274d..08f740719a769e17c4a664509254f539222a7f22 100644 (file)
 
 #define MAXSOCKETS 8    /* Probably overkill... */
 
+static const char meshlink_invitation_label[] = "MeshLink invitation";
+static const char meshlink_tcp_label[] = "MeshLink TCP";
+static const char meshlink_udp_label[] = "MeshLink UDP";
+
 struct CattaServer;
 struct CattaSServiceBrowser;
 struct CattaSimplePoll;
index 7a405fe4d8ea3436326ad9ba872de02a0b59b971..4a380e77100c3aa828859316fca67cf6bc51d599 100644 (file)
@@ -289,9 +289,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                c->protocol_minor = 2;
                c->allow_request = 1;
 
-               static const char label[] = "MeshLink invitation";
-
-               return sptps_start(&c->sptps, c, false, false, mesh->invitation_key, c->ecdsa, label, sizeof label - 1, send_meta_sptps, receive_invitation_sptps);
+               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);
        }
 
        /* Check if identity is a valid name */
@@ -356,12 +354,12 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        }
 
        c->allow_request = ACK;
-       char label[14 + strlen(mesh->self->name) + strlen(c->name) + 1];
+       char label[sizeof meshlink_tcp_label + strlen(mesh->self->name) + strlen(c->name) + 2];
 
        if(c->outgoing)
-               snprintf(label, sizeof label, "MeshLink TCP %s %s", mesh->self->name, c->name);
+               snprintf(label, sizeof label, "%s %s %s", meshlink_tcp_label, mesh->self->name, c->name);
        else
-               snprintf(label, sizeof label, "MeshLink TCP %s %s", c->name, mesh->self->name);
+               snprintf(label, sizeof label, "%s %s %s", meshlink_tcp_label, c->name, mesh->self->name);
 
        return sptps_start(&c->sptps, c, c->outgoing, false, mesh->self->connection->ecdsa, c->ecdsa, label, sizeof label - 1, send_meta_sptps, receive_meta_sptps);
 }
index 7f62b5fa59913fa536c58a3a2ff561ed109bf26d..f493cde731a3029c06b6d1e9512ac0be86a6b607 100644 (file)
@@ -88,8 +88,8 @@ bool send_req_key(meshlink_handle_t *mesh, node_t *to) {
        if(to->sptps.label)
                logger(mesh, MESHLINK_DEBUG, "send_req_key(%s) called while sptps->label != NULL!", to->name);
 
-       char label[14 + strlen(mesh->self->name) + strlen(to->name) + 1];
-       snprintf(label, sizeof label, "MeshLink UDP %s %s", mesh->self->name, to->name);
+       char label[sizeof meshlink_udp_label + strlen(mesh->self->name) + strlen(to->name) + 2];
+       snprintf(label, sizeof label, "%s %s %s", meshlink_udp_label, mesh->self->name, to->name);
        sptps_stop(&to->sptps);
        to->status.validkey = false;
        to->status.waitingforkey = true;
@@ -149,8 +149,8 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *
                                return true;
                        }
 
-                       char label[14 + strlen(from->name) + strlen(mesh->self->name) + 1];
-                       snprintf(label, sizeof label, "MeshLink UDP %s %s", from->name, mesh->self->name);
+                       char label[sizeof meshlink_udp_label + strlen(from->name) + strlen(mesh->self->name) + 2];
+                       snprintf(label, sizeof label, "%s %s %s", meshlink_udp_label, from->name, mesh->self->name);
                        sptps_stop(&from->sptps);
                        from->status.validkey = false;
                        from->status.waitingforkey = true;