gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r25418 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r25418 - gnunet/src/mesh
Date: Wed, 12 Dec 2012 11:59:37 +0100

Author: bartpolot
Date: 2012-12-12 11:59:37 +0100 (Wed, 12 Dec 2012)
New Revision: 25418

Modified:
   gnunet/src/mesh/mesh.h
   gnunet/src/mesh/mesh_api.c
Log:
- break regex into multiple messages

Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h      2012-12-12 10:48:41 UTC (rev 25417)
+++ gnunet/src/mesh/mesh.h      2012-12-12 10:59:37 UTC (rev 25418)
@@ -193,7 +193,12 @@
      */
   uint16_t compression_characters;
 
-  /* regex  */
+    /**
+     * Is this the last message for this regex? (for regex > 65k)
+     */
+  int16_t last;
+
+  /* regex payload  */
 };
 
 

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2012-12-12 10:48:41 UTC (rev 25417)
+++ gnunet/src/mesh/mesh_api.c  2012-12-12 10:59:37 UTC (rev 25418)
@@ -1829,30 +1829,30 @@
                             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();
-  }
+    msgsize = (len > offset + payload) ? payload : len;
+    memcpy (&msg[1], &regex[offset], msgsize);
+    offset += msgsize;
+    msgsize += sizeof(struct GNUNET_MESH_RegexAnnounce);
 
-  {
-    char buffer[msgsize];
-
-    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);
 }
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]