From b3e54688ae46b901bdbf6aa3020d93a04deda9e8 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Tue, 7 May 2013 12:14:11 +0000 Subject: - remove regex integration from mesh2 --- src/mesh/gnunet-service-mesh-new.c | 444 ------------------------------------- 1 file changed, 444 deletions(-) (limited to 'src') diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 72295b0bb..e42be9142 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c @@ -1247,187 +1247,6 @@ queue_get_next (const struct MeshPeerInfo *peer); static size_t queue_send (void *cls, size_t size, void *buf); -/******************************************************************************/ -/************************ REGEX INTEGRATION ****************************/ -/******************************************************************************/ - -/** - * Cancel a mesh regex search and free resources. - */ -static void -regex_cancel_search (struct MeshRegexSearchInfo *regex_search) -{ - DEBUG_REGEX ("Search for %s canelled.\n", regex_search->description); - GNUNET_REGEX_search_cancel (regex_search->search_handle); - if (0 < regex_search->n_peers) - GNUNET_free (regex_search->peers); - if (GNUNET_SCHEDULER_NO_TASK != regex_search->timeout) - { - GNUNET_SCHEDULER_cancel(regex_search->timeout); - } - GNUNET_free (regex_search); -} - - -/** - * Function called if the connect attempt to a peer found via - * connect_by_string times out. Try to connect to another peer, if any. - * Otherwise try to reconnect to the same peer. - * - * @param cls Closure (info about regex search). - * @param tc TaskContext. - */ -static void -regex_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct MeshRegexSearchInfo *info = cls; - struct MeshPeerInfo *peer_info; - GNUNET_PEER_Id id; - GNUNET_PEER_Id old; - - DEBUG_REGEX ("Regex connect timeout\n"); - info->timeout = GNUNET_SCHEDULER_NO_TASK; - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { - DEBUG_REGEX (" due to shutdown\n"); - return; - } - - old = info->peer; - DEBUG_REGEX (" timed out: %u\n", old); - - if (0 < info->n_peers) - { - // Select next peer, put current in that spot. - id = info->peers[info->i_peer]; - info->peers[info->i_peer] = info->peer; - info->i_peer = (info->i_peer + 1) % info->n_peers; - } - else - { - // Try to connect to same peer again. - id = info->peer; - } - DEBUG_REGEX (" trying: %u\n", id); - - peer_info = peer_info_get_short(id); - tunnel_add_peer (info->t, peer_info); - if (old != id) - tunnel_delete_peer (info->t, old); - peer_info_connect (peer_info, info->t); - info->timeout = GNUNET_SCHEDULER_add_delayed (connect_timeout, - ®ex_connect_timeout, - info); - DEBUG_REGEX ("Regex connect timeout END\n"); -} - - -/** - * Function to process DHT string to regex matching. - * Called on each result obtained for the DHT search. - * - * @param cls Closure provided in GNUNET_REGEX_search. - * @param id Peer providing a regex that matches the string. - * @param get_path Path of the get request. - * @param get_path_length Lenght of get_path. - * @param put_path Path of the put request. - * @param put_path_length Length of the put_path. - */ -static void -regex_found_handler (void *cls, - const struct GNUNET_PeerIdentity *id, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length) -{ - struct MeshRegexSearchInfo *info = cls; - struct MeshPeerPath *p; - struct MeshPeerInfo *peer_info; - - DEBUG_REGEX ("Got regex results from DHT!\n"); - DEBUG_REGEX (" for %s\n", info->description); - - peer_info = peer_info_get (id); - p = path_build_from_dht (get_path, get_path_length, - put_path, put_path_length); - path_add_to_peers (p, GNUNET_NO); - path_destroy(p); - - tunnel_add_peer (info->t, peer_info); - peer_info_connect (peer_info, info->t); - if (0 == info->peer) - { - info->peer = peer_info->id; - } - else - { - GNUNET_array_append (info->peers, info->n_peers, peer_info->id); - } - - if (GNUNET_SCHEDULER_NO_TASK != info->timeout) - return; - - info->timeout = GNUNET_SCHEDULER_add_delayed (connect_timeout, - ®ex_connect_timeout, - info); - - return; -} - - -/** - * Store the regular expression describing a local service into the DHT. - * - * @param regex The regular expresion. - */ -static void -regex_put (struct MeshRegexDescriptor *regex) -{ - DEBUG_REGEX (" regex_put (%s) start\n", regex->regex); - if (NULL == regex->h) - { - DEBUG_REGEX (" first put, creating DFA\n"); - regex->h = GNUNET_REGEX_announce (dht_handle, - &my_full_id, - regex->regex, - regex->compression, - stats); - } - else - { - DEBUG_REGEX (" not first put, using cached data\n"); - GNUNET_REGEX_reannounce (regex->h); - } - DEBUG_REGEX (" regex_put (%s) end\n", regex->regex); -} - - -/** - * Periodically announce what applications are provided by local clients - * (by regex) - * - * @param cls closure - * @param tc task context - */ -static void -regex_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct MeshClient *c = cls; - unsigned int i; - - c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK; - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; - DEBUG_REGEX ("Starting announce for regex\n"); - for (i = 0; i < c->n_regex; i++) - regex_put (&c->regexes[i]); - c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time, - ®ex_announce, - cls); - DEBUG_REGEX ("Finished announce for regex\n"); -} - /******************************************************************************/ /************************ PERIODIC FUNCTIONS ****************************/ @@ -6178,63 +5997,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, } -/** - * Function to process paths received for a new peer addition. The recorded - * paths form the initial tunnel, which can be optimized later. - * Called on each result obtained for the DHT search. - * - * @param cls closure - * @param exp when will this value expire - * @param key key of the result - * @param get_path path of the get request - * @param get_path_length lenght of get_path - * @param put_path path of the put request - * @param put_path_length length of the put_path - * @param type type of the result - * @param size number of bytes in data - * @param data pointer to the result data - */ -static void -dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, enum GNUNET_BLOCK_Type type, - size_t size, const void *data) -{ - const struct PBlock *pb = data; - const struct GNUNET_PeerIdentity *pi = &pb->id; - struct MeshTunnel *t = cls; - struct MeshPeerInfo *peer_info; - struct MeshPeerPath *p; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got type DHT result!\n"); - if (size != sizeof (struct PBlock)) - { - GNUNET_break_op (0); - return; - } - if (ntohl(pb->type) != t->type) - { - GNUNET_break_op (0); - return; - } - GNUNET_assert (NULL != t->owner); - peer_info = peer_info_get (pi); - (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, - peer_info, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - - p = path_build_from_dht (get_path, get_path_length, put_path, - put_path_length); - path_add_to_peers (p, GNUNET_NO); - path_destroy(p); - tunnel_add_peer (t, peer_info); - peer_info_connect (peer_info, t); -} - - /******************************************************************************/ /********************* MESH LOCAL HANDLES **************************/ /******************************************************************************/ @@ -7026,209 +6788,6 @@ handle_local_unblacklist (void *cls, struct GNUNET_SERVER_Client *client, } -/** - * Handler for connection requests to new peers by type - * - * @param cls closure - * @param client identification of the client - * @param message the actual message (ConnectPeerByType) - */ -static void -handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - struct GNUNET_MESH_ConnectPeerByType *connect_msg; - struct MeshClient *c; - struct MeshTunnel *t; - struct GNUNET_HashCode hash; - MESH_TunnelNumber tid; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got connect by type request\n"); - /* 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); - - connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message; - - /* Sanity check for message size */ - if (sizeof (struct GNUNET_MESH_ConnectPeerByType) != - ntohs (connect_msg->header.size)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Tunnel exists? */ - tid = ntohl (connect_msg->tunnel_id); - t = tunnel_get_by_local_id (c, tid); - if (NULL == t) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Does client own tunnel? */ - if (t->owner->handle != client) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Do WE have the service? */ - t->type = ntohl (connect_msg->type); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type requested: %u\n", t->type); - GNUNET_CRYPTO_hash (&t->type, sizeof (GNUNET_MESH_ApplicationType), &hash); - if (GNUNET_CONTAINER_multihashmap_contains (applications, &hash) == - GNUNET_YES) - { - /* Yes! Fast forward, add ourselves to the tunnel and send the - * good news to the client, and alert the destination client of - * an incoming tunnel. - * - * FIXME send a path create to self, avoid code duplication - */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " available locally\n"); - GNUNET_CONTAINER_multihashmap_put (t->peers, &my_full_id.hashPubKey, - peer_info_get (&my_full_id), - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " notifying client\n"); - send_client_peer_connected (t, myid); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Done\n"); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - - t->local_tid_dest = next_local_tid++; - GNUNET_CRYPTO_hash (&t->local_tid_dest, sizeof (MESH_TunnelNumber), &hash); - GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - - return; - } - /* Ok, lets find a peer offering the service */ - if (NULL != t->dht_get_type) - { - GNUNET_DHT_get_stop (t->dht_get_type); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " looking in DHT for %s\n", - GNUNET_h2s (&hash)); - t->dht_get_type = - GNUNET_DHT_get_start (dht_handle, - GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE, - &hash, - dht_replication_level, - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, 0, - &dht_get_type_handler, t); - - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; -} - - -/** - * Handler for connection requests to new peers by a string service description. - * - * @param cls closure - * @param client identification of the client - * @param message the actual message, which includes messages the client wants - */ -static void -handle_local_connect_by_string (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - struct GNUNET_MESH_ConnectPeerByString *msg; - struct MeshRegexSearchInfo *info; - struct MeshTunnel *t; - struct MeshClient *c; - MESH_TunnelNumber tid; - const char *string; - size_t size; - size_t len; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connect by string started\n"); - msg = (struct GNUNET_MESH_ConnectPeerByString *) message; - size = htons (message->size); - - /* 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); - - /* Message size sanity check */ - if (sizeof(struct GNUNET_MESH_ConnectPeerByString) >= size) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Tunnel exists? */ - tid = ntohl (msg->tunnel_id); - t = tunnel_get_by_local_id (c, tid); - if (NULL == t) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Does client own tunnel? */ - if (t->owner->handle != client) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - " on tunnel %s [%u]\n", - GNUNET_i2s(&my_full_id), - t->id.tid); - - /* Only one connect_by_string allowed at the same time! */ - /* FIXME: allow more, return handle at api level to cancel, document */ - if (NULL != t->regex_search) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - - /* Find string itself */ - len = size - sizeof(struct GNUNET_MESH_ConnectPeerByString); - string = (const char *) &msg[1]; - - info = GNUNET_malloc (sizeof (struct MeshRegexSearchInfo)); - info->t = t; - info->description = GNUNET_strndup (string, len); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " string: %s\n", info->description); - - t->regex_search = info; - - info->search_handle = GNUNET_REGEX_search (dht_handle, - info->description, - ®ex_found_handler, info, - stats); - - GNUNET_SERVER_receive_done (client, GNUNET_OK); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect by string processed\n"); -} - - /** * Handler for client traffic directed to one peer * @@ -7922,9 +7481,6 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { {&handle_local_unblacklist, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST, sizeof (struct GNUNET_MESH_PeerControl)}, - {&handle_local_connect_by_type, NULL, - GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE, - sizeof (struct GNUNET_MESH_ConnectPeerByType)}, {&handle_local_connect_by_string, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING, 0}, {&handle_local_unicast, NULL, -- cgit v1.2.3