From: Guus Sliepen Date: Sun, 25 Jun 2017 18:54:12 +0000 (+0200) Subject: Ensure consistent use of SPTPS session labels. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=f09edd4a80eeb1f41060d596e48ef2303e05713f Ensure consistent use of SPTPS session labels. --- diff --git a/src/meshlink.c b/src/meshlink.c index 8b0c0621..0f1e2738 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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; diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 9abe19e0..08f74071 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -33,6 +33,10 @@ #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; diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 7a405fe4..4a380e77 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -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); } diff --git a/src/protocol_key.c b/src/protocol_key.c index 7f62b5fa..f493cde7 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -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;