From 257a91106e0630736cbb93d5d027f58414105b36 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 22 Jun 2012 15:10:45 +0000 Subject: [PATCH] - more regex in mesh --- src/mesh/Makefile.am | 1 + src/mesh/gnunet-service-mesh_new.c | 66 +++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 59131f2b1..d32e79c92 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am @@ -57,6 +57,7 @@ gnunet_service_mesh_new_SOURCES = \ gnunet_service_mesh_new_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la\ $(top_builddir)/src/dht/libgnunetdht.la \ + $(top_builddir)/src/regex/libgnunetregex.la \ $(top_builddir)/src/util/libgnunetutil.la gnunet_service_mesh_new_DEPENDENCIES = \ $(top_builddir)/src/core/libgnunetcore.la\ diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c index ccf26b59f..c6ffa1402 100644 --- a/src/mesh/gnunet-service-mesh_new.c +++ b/src/mesh/gnunet-service-mesh_new.c @@ -48,9 +48,10 @@ #include "platform.h" #include "mesh.h" #include "mesh_protocol.h" +#include "mesh_tunnel_tree.h" #include "block_mesh.h" #include "gnunet_dht_service.h" -#include "mesh_tunnel_tree.h" +#include "gnunet_regex_lib.h" /* TODO: move into configuration file */ #define REFRESH_PATH_TIME GNUNET_TIME_relative_multiply(\ @@ -495,6 +496,21 @@ struct MeshClient * ID of the client, mainly for debug messages */ unsigned int id; + + /** + * Regular expressions describing the services offered by this client. + */ + char **regexes; // FIXME add timeout? API to remove a regex? + + /** + * Number of regular expressions in regexes. + */ + unsigned int n_regex; + + /** + * Task to refresh all regular expresions in the DHT. + */ + GNUNET_SCHEDULER_TaskIdentifier regex_announce_task; }; @@ -2590,6 +2606,24 @@ tunnel_reset_timeout (struct MeshTunnel *t) (REFRESH_PATH_TIME, 4), &tunnel_timeout, t); } +/** + * Regex callback iterator to store own service description in the DHT. + * + * @param cls closure. + * @param key hash for current state. + * @param proof proof for current state. + * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. + * @param num_edges number of edges leaving current state. + * @param edges edges leaving current state. + */ +void +regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, + int accepting, unsigned int num_edges, + const struct GNUNET_REGEX_Edge *edges) +{ + +} + /******************************************************************************/ /**************** MESH NETWORK HANDLER HELPERS ***********************/ @@ -3832,6 +3866,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { struct MeshClient *c; struct MeshClient *next; + unsigned int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n"); if (client == NULL) @@ -3878,6 +3913,12 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) } if (NULL != c->types) GNUNET_CONTAINER_multihashmap_destroy (c->types); + for (i = 0; i < c->n_regex; i++) + { + GNUNET_free (c->regexes[i]); + } + if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task) + GNUNET_SCHEDULER_cancel (c->regex_announce_task); next = c->next; GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT FREE at %p\n", c); @@ -3999,10 +4040,31 @@ static void handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { + struct GNUNET_REGEX_Automaton *dfa; + struct MeshClient *c; + char *regex; + size_t len; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex started\n"); - // FIXME complete + /* Sanity check for client registration */ + if (NULL == (c = client_get (client))) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); + + len = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader); + regex = GNUNET_malloc (len + 1); + memcpy (regex, &message[1], len); + regex[len] = '\0'; + GNUNET_array_append (c->regexes, c->n_regex, regex); + dfa = GNUNET_REGEX_construct_dfa (regex, len); + GNUNET_REGEX_iterate_all_edges (dfa, ®ex_iterator, NULL); + GNUNET_REGEX_automaton_destroy (dfa); GNUNET_SERVER_receive_done (client, GNUNET_OK); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n"); } -- 2.25.1