diff options
-rw-r--r-- | src/mesh/mesh.h | 7 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 32 |
2 files changed, 22 insertions, 17 deletions
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 873b7f17a9..e562846f0d 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -193,7 +193,12 @@ struct GNUNET_MESH_RegexAnnounce */ uint16_t compression_characters; - /* regex */ + /** + * Is this the last message for this regex? (for regex > 65k) + */ + int16_t last; + + /* regex payload */ }; diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 0da4d3e93b..7564a7ec58 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1829,30 +1829,30 @@ GNUNET_MESH_announce_regex (struct GNUNET_MESH_Handle *h, unsigned int compression_characters) { struct GNUNET_MESH_RegexAnnounce *msg; + size_t payload; size_t len; size_t msgsize; + size_t offset; + char buffer[UINT16_MAX]; len = strlen (regex); - msgsize = sizeof(struct GNUNET_MESH_RegexAnnounce) + len; - if (UINT16_MAX < msgsize) + payload = UINT16_MAX - sizeof(struct GNUNET_MESH_RegexAnnounce); + msg = (struct GNUNET_MESH_RegexAnnounce *) buffer; + msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX); + msg->compression_characters = htons (compression_characters); + offset = 0; + do { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Regex size %u (%u) too big.\n", - len, msgsize); - GNUNET_abort(); - } - - { - char buffer[msgsize]; + msgsize = (len > offset + payload) ? payload : len; + memcpy (&msg[1], ®ex[offset], msgsize); + offset += msgsize; + msgsize += sizeof(struct GNUNET_MESH_RegexAnnounce); - msg = (struct GNUNET_MESH_RegexAnnounce *) buffer; msg->header.size = htons (msgsize); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX); - msg->compression_characters = htons (compression_characters); - memcpy (&msg[1], regex, len); + msg->last = htons (offset >= len); - send_packet(h, &msg->header, NULL); - } + send_packet (h, &msg->header, NULL); + } while (len > offset); } /** |