aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-10-26 15:54:15 +0000
committerBart Polot <bart@net.in.tum.de>2012-10-26 15:54:15 +0000
commitf73bdc3bef4de74c77d13e986242f93ad4df5460 (patch)
treefbb9b76cc1502454c49ef8551ae656543740ce10
parentda1d0733027d98db9cf9e12af9af82f049f163bc (diff)
downloadgnunet-f73bdc3bef4de74c77d13e986242f93ad4df5460.tar.gz
gnunet-f73bdc3bef4de74c77d13e986242f93ad4df5460.zip
- implementation of configurable regex compression
-rw-r--r--src/mesh/gnunet-service-mesh.c41
-rw-r--r--src/mesh/mesh.h21
-rw-r--r--src/mesh/mesh_api.c11
3 files changed, 59 insertions, 14 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 3f6fa5fd8..5cc0d8c0d 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -171,6 +171,22 @@ struct MeshPeerQueue
171 171
172 172
173/** 173/**
174 * Struct to store regex information announced by clients.
175 */
176struct MeshRegexDescriptor
177{
178 /**
179 * Regular expression itself.
180 */
181 char *regex;
182
183 /**
184 * How many characters per edge can we squeeze?
185 */
186 uint16_t compression;
187};
188
189/**
174 * Struct containing all info possibly needed to build a package when called 190 * Struct containing all info possibly needed to build a package when called
175 * back by core. 191 * back by core.
176 */ 192 */
@@ -691,7 +707,7 @@ struct MeshClient
691 /** 707 /**
692 * Regular expressions describing the services offered by this client. 708 * Regular expressions describing the services offered by this client.
693 */ 709 */
694 char **regexes; // FIXME add timeout? API to remove a regex? 710 struct MeshRegexDescriptor *regexes; // FIXME regex add timeout? API to remove a regex?
695 711
696 /** 712 /**
697 * Number of regular expressions in regexes. 713 * Number of regular expressions in regexes.
@@ -1586,12 +1602,14 @@ regex_iterator (void *cls,
1586 * @param regex The regular expresion. 1602 * @param regex The regular expresion.
1587 */ 1603 */
1588static void 1604static void
1589regex_put (const char *regex) 1605regex_put (const struct MeshRegexDescriptor *regex)
1590{ 1606{
1591 struct GNUNET_REGEX_Automaton *dfa; 1607 struct GNUNET_REGEX_Automaton *dfa;
1592 1608
1593 DEBUG_DHT (" regex_put (%s) start\n", regex); 1609 DEBUG_DHT (" regex_put (%s) start\n", regex->regex);
1594 dfa = GNUNET_REGEX_construct_dfa (regex, strlen(regex)); 1610 dfa = GNUNET_REGEX_construct_dfa (regex->regex,
1611 strlen(regex->regex),
1612 regex->compression);
1595 GNUNET_REGEX_iterate_all_edges (dfa, &regex_iterator, NULL); 1613 GNUNET_REGEX_iterate_all_edges (dfa, &regex_iterator, NULL);
1596 GNUNET_REGEX_automaton_destroy (dfa); 1614 GNUNET_REGEX_automaton_destroy (dfa);
1597 DEBUG_DHT (" regex_put (%s) end\n", regex); 1615 DEBUG_DHT (" regex_put (%s) end\n", regex);
@@ -1785,7 +1803,7 @@ announce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1785 1803
1786 for (i = 0; i < c->n_regex; i++) 1804 for (i = 0; i < c->n_regex; i++)
1787 { 1805 {
1788 regex_put (c->regexes[i]); 1806 regex_put (&c->regexes[i]);
1789 } 1807 }
1790 c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time, 1808 c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time,
1791 &announce_regex, 1809 &announce_regex,
@@ -6567,7 +6585,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
6567 GNUNET_CONTAINER_multihashmap_destroy (c->types); 6585 GNUNET_CONTAINER_multihashmap_destroy (c->types);
6568 for (i = 0; i < c->n_regex; i++) 6586 for (i = 0; i < c->n_regex; i++)
6569 { 6587 {
6570 GNUNET_free (c->regexes[i]); 6588 GNUNET_free (c->regexes[i].regex);
6571 } 6589 }
6572 GNUNET_free_non_null (c->regexes); 6590 GNUNET_free_non_null (c->regexes);
6573 if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task) 6591 if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task)
@@ -6695,6 +6713,8 @@ static void
6695handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, 6713handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6696 const struct GNUNET_MessageHeader *message) 6714 const struct GNUNET_MessageHeader *message)
6697{ 6715{
6716 struct GNUNET_MESH_RegexAnnounce *msg;
6717 struct MeshRegexDescriptor rd;
6698 struct MeshClient *c; 6718 struct MeshClient *c;
6699 char *regex; 6719 char *regex;
6700 size_t len; 6720 size_t len;
@@ -6710,18 +6730,21 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6710 } 6730 }
6711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); 6731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6712 6732
6713 len = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader); 6733 msg = (struct GNUNET_MESH_RegexAnnounce *) message;
6734 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce);
6714 regex = GNUNET_malloc (len + 1); 6735 regex = GNUNET_malloc (len + 1);
6715 memcpy (regex, &message[1], len); 6736 memcpy (regex, &message[1], len);
6716 regex[len] = '\0'; 6737 regex[len] = '\0';
6717 GNUNET_array_append (c->regexes, c->n_regex, regex); 6738 rd.regex = regex;
6739 rd.compression = ntohs (msg->compression_characters);
6740 GNUNET_array_append (c->regexes, c->n_regex, rd);
6718 if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task) 6741 if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task)
6719 { 6742 {
6720 c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c); 6743 c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c);
6721 } 6744 }
6722 else 6745 else
6723 { 6746 {
6724 regex_put(regex); 6747 regex_put(&rd);
6725 } 6748 }
6726 GNUNET_SERVER_receive_done (client, GNUNET_OK); 6749 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n"); 6750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n");
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index 27f2238bf..b85a8d158 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -177,6 +177,27 @@ struct GNUNET_MESH_TunnelNotification
177}; 177};
178 178
179/** 179/**
180 * Message for announce of regular expressions.
181 */
182struct GNUNET_MESH_RegexAnnounce
183{
184 /**
185 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX
186 *
187 * Size: sizeof(struct GNUNET_MESH_RegexAnnounce) + strlen (regex)
188 */
189 struct GNUNET_MessageHeader header;
190
191 /**
192 * How many characters do we want to put in an edge label.
193 */
194 uint16_t compression_characters;
195
196 /* regex */
197};
198
199
200/**
180 * Message for: 201 * Message for:
181 * - request adding and deleting peers from a tunnel 202 * - request adding and deleting peers from a tunnel
182 * - notify the client that peers have connected: 203 * - notify the client that peers have connected:
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 9c20b4268..479203f45 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -1680,20 +1680,21 @@ GNUNET_MESH_announce_regex (struct GNUNET_MESH_Handle *h,
1680 const char *regex, 1680 const char *regex,
1681 unsigned int compression_characters) 1681 unsigned int compression_characters)
1682{ 1682{
1683 struct GNUNET_MessageHeader *msg; 1683 struct GNUNET_MESH_RegexAnnounce *msg;
1684 size_t len; 1684 size_t len;
1685 size_t msgsize; 1685 size_t msgsize;
1686 1686
1687 len = strlen (regex); 1687 len = strlen (regex);
1688 msgsize = sizeof(struct GNUNET_MessageHeader) + len; 1688 msgsize = sizeof(struct GNUNET_MESH_RegexAnnounce) + len;
1689 GNUNET_assert (UINT16_MAX > msgsize); 1689 GNUNET_assert (UINT16_MAX > msgsize);
1690 1690
1691 { 1691 {
1692 char buffer[msgsize]; 1692 char buffer[msgsize];
1693 1693
1694 msg = (struct GNUNET_MessageHeader *) buffer; 1694 msg = (struct GNUNET_MESH_RegexAnnounce *) buffer;
1695 msg->size = htons (msgsize); 1695 msg->header.size = htons (msgsize);
1696 msg->type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX); 1696 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX);
1697 msg->compression_characters = htons (compression_characters);
1697 memcpy (&msg[1], regex, len); 1698 memcpy (&msg[1], regex, len);
1698 1699
1699 send_packet(h, msg, NULL); 1700 send_packet(h, msg, NULL);