aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-12-12 11:25:13 +0000
committerBart Polot <bart@net.in.tum.de>2012-12-12 11:25:13 +0000
commit005a0fa580eee02d59fe631784fc8b7895b4f58b (patch)
tree327af3a69ebc9546e742c92a07b5d802b73dae98 /src/mesh/gnunet-service-mesh.c
parent24945b56d1b9a7ea42ac10b883e0c2e0ab20ee0d (diff)
downloadgnunet-005a0fa580eee02d59fe631784fc8b7895b4f58b.tar.gz
gnunet-005a0fa580eee02d59fe631784fc8b7895b4f58b.zip
mesh now accepts REGEXes longer than 64KiB
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index dddb6283f..dda48c810 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -748,6 +748,11 @@ struct MeshClient
748 */ 748 */
749 GNUNET_SCHEDULER_TaskIdentifier regex_announce_task; 749 GNUNET_SCHEDULER_TaskIdentifier regex_announce_task;
750 750
751 /**
752 * Tmp store for partially retrieved regex.
753 */
754 char *partial_regex;
755
751}; 756};
752 757
753 758
@@ -6982,6 +6987,7 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6982 struct MeshClient *c; 6987 struct MeshClient *c;
6983 char *regex; 6988 char *regex;
6984 size_t len; 6989 size_t len;
6990 size_t offset;
6985 6991
6986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex started\n"); 6992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex started\n");
6987 6993
@@ -6995,10 +7001,34 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); 7001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6996 7002
6997 msg = (const struct GNUNET_MESH_RegexAnnounce *) message; 7003 msg = (const struct GNUNET_MESH_RegexAnnounce *) message;
7004
6998 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce); 7005 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce);
6999 regex = GNUNET_malloc (len + 1); 7006 if (NULL != c->partial_regex)
7000 memcpy (regex, &msg[1], len); 7007 {
7001 regex[len] = '\0'; 7008 regex = c->partial_regex;
7009 offset = strlen (c->partial_regex);
7010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7011 " continuation, already have %u bytes\n",
7012 offset);
7013 }
7014 else
7015 {
7016 regex = NULL;
7017 offset = 0;
7018 }
7019
7020 regex = GNUNET_realloc (regex, offset + len + 1);
7021 memcpy (&regex[offset], &msg[1], len);
7022 regex[offset + len] = '\0';
7023 if (0 == ntohs (msg->last))
7024 {
7025 c->partial_regex = regex;
7026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7027 " not ended, stored %u bytes for later\n",
7028 len);
7029 GNUNET_SERVER_receive_done (client, GNUNET_OK);
7030 return;
7031 }
7002 rd.regex = regex; 7032 rd.regex = regex;
7003 rd.compression = ntohs (msg->compression_characters); 7033 rd.compression = ntohs (msg->compression_characters);
7004 rd.dfa = NULL; 7034 rd.dfa = NULL;
@@ -7006,6 +7036,7 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
7006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex); 7036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex);
7007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " cm %u\n", ntohs(rd.compression)); 7037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " cm %u\n", ntohs(rd.compression));
7008 GNUNET_array_append (c->regexes, c->n_regex, rd); 7038 GNUNET_array_append (c->regexes, c->n_regex, rd);
7039 c->partial_regex = NULL;
7009 if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task) 7040 if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task)
7010 { 7041 {
7011 c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c); 7042 c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c);