diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-10-26 15:54:15 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-10-26 15:54:15 +0000 |
commit | f73bdc3bef4de74c77d13e986242f93ad4df5460 (patch) | |
tree | fbb9b76cc1502454c49ef8551ae656543740ce10 /src/mesh/gnunet-service-mesh.c | |
parent | da1d0733027d98db9cf9e12af9af82f049f163bc (diff) | |
download | gnunet-f73bdc3bef4de74c77d13e986242f93ad4df5460.tar.gz gnunet-f73bdc3bef4de74c77d13e986242f93ad4df5460.zip |
- implementation of configurable regex compression
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 41 |
1 files changed, 32 insertions, 9 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 | */ | ||
176 | struct 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 | */ |
1588 | static void | 1604 | static void |
1589 | regex_put (const char *regex) | 1605 | regex_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, ®ex_iterator, NULL); | 1613 | GNUNET_REGEX_iterate_all_edges (dfa, ®ex_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 | |||
6695 | handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, | 6713 | handle_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"); |