aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorbartpolot <bartpolot@140774ce-b5e7-0310-ab8b-a85725594a96>2012-12-12 10:59:37 +0000
committerbartpolot <bartpolot@140774ce-b5e7-0310-ab8b-a85725594a96>2012-12-12 10:59:37 +0000
commitf0bd2398d59b8c0cc8d04df26dcd217301de1e6c (patch)
tree1e154c395c4cf32dae94ee1a564b365eb113a1db /src/mesh
parent17fb33ed06668777a03eba3f5e5701bfbabf5109 (diff)
- break regex into multiple messages
git-svn-id: https://gnunet.org/svn/gnunet@25418 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh.h7
-rw-r--r--src/mesh/mesh_api.c32
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], &regex[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);
}
/**