#include "mesh_protocol.h"
#include "mesh_tunnel_tree.h"
#include "block_mesh.h"
-#include "mesh_block_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_regex_lib.h"
#define MESH_BLOOM_SIZE 128
+#define MESH_DEBUG_REGEX GNUNET_YES
#define MESH_DEBUG_DHT GNUNET_NO
#define MESH_DEBUG_CONNECTION GNUNET_NO
#define MESH_DEBUG_TIMING __LINUX__ && GNUNET_NO
#define DEBUG_DHT(...)
#endif
+#if MESH_DEBUG_REGEX
+#define DEBUG_REGEX(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#else
+#define DEBUG_REGEX(...)
+#endif
+
#if MESH_DEBUG_TIMING
#include <time.h>
double __sum;
*/
char *regex;
- /**
- * Cached DFA for regular expression 'regex'.
- */
- struct GNUNET_REGEX_Automaton *dfa;
-
/**
* How many characters per edge can we squeeze?
*/
uint16_t compression;
+
+ /**
+ * Handle to announce the regex.
+ */
+ struct GNUNET_REGEX_announce_handle *h;
};
+
+/**
+ * Struct to keep information of searches of services described by a regex
+ * using a user-provided string service description.
+ */
+struct MeshRegexSearchInfo
+{
+ /**
+ * Which tunnel is this for
+ */
+ struct MeshTunnel *t;
+
+ /**
+ * User provided description of the searched service.
+ */
+ char *description;
+
+ /**
+ * Regex search handle.
+ */
+ struct GNUNET_REGEX_search_handle *search_handle;
+
+ /**
+ * Peer that is connecting via connect_by_string. When connected, free ctx.
+ */
+ GNUNET_PEER_Id peer;
+
+ /**
+ * Other peers that are found but not yet being connected to.
+ */
+ GNUNET_PEER_Id *peers;
+
+ /**
+ * Number of elements in peers.
+ */
+ unsigned int n_peers;
+
+ /**
+ * Next peer to try to connect to.
+ */
+ unsigned int i_peer;
+
+ /**
+ * Timeout for a connect attempt.
+ * When reached, try to connect to a different peer, if any. If not,
+ * try the same peer again.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier timeout;
+
+};
+
+
/**
* Struct containing all info possibly needed to build a package when called
* back by core.
*/
uint32_t last_fwd_ack;
- /**
- * BCK ACK value received from the hop towards the owner of the tunnel,
- * (previous node / owner): up to what message PID can we sent back to him.
- */
+ /**
+ * BCK ACK value received from the hop towards the owner of the tunnel,
+ * (previous node / owner): up to what message PID can we sent back to him.
+ */
uint32_t bck_ack;
/**
*/
unsigned int peers_ready;
- /**
- * Number of peers that have been added to the tunnel
- */
- unsigned int peers_total;
-
/**
* Client owner of the tunnel, if any
*/
struct GNUNET_DHT_GetHandle *dht_get_type;
/**
- * Initial context of the regex search for a connect_by_string
+ * Handle for the regex search for a connect_by_string
*/
- struct MeshRegexSearchContext *regex_ctx;
+ struct MeshRegexSearchInfo *regex_search;
/**
* Task to keep the used paths alive
struct GNUNET_SERVER_Client *handle;
/**
- * Applications that this client has claimed to provide
+ * Applications that this client has claimed to provide: H(app) = app.
*/
struct GNUNET_CONTAINER_MultiHashMap *apps;
};
-/**
- * Struct to keep information of searches of services described by a regex
- * using a user-provided string service description.
- */
-struct MeshRegexSearchInfo
-{
- /**
- * Which tunnel is this for
- */
- struct MeshTunnel *t;
-
- /**
- * User provided description of the searched service.
- */
- char *description;
-
- /**
- * Part of the description already consumed by the search.
- */
- size_t position;
-
- /**
- * Running DHT GETs.
- */
- struct GNUNET_CONTAINER_MultiHashMap *dht_get_handles;
-
- /**
- * Results from running DHT GETs.
- */
- struct GNUNET_CONTAINER_MultiHashMap *dht_get_results;
-
- /**
- * Contexts, for each running DHT GET. Free all on end of search.
- */
- struct MeshRegexSearchContext **contexts;
-
- /**
- * Number of contexts (branches/steps in search).
- */
- unsigned int n_contexts;
-
- /**
- * Peer that is connecting via connect_by_string. When connected, free ctx.
- */
- GNUNET_PEER_Id peer;
-
- /**
- * Other peers that are found but not yet being connected to.
- */
- GNUNET_PEER_Id *peers;
-
- /**
- * Number of elements in peers.
- */
- unsigned int n_peers;
-
- /**
- * Next peer to try to connect to.
- */
- unsigned int i_peer;
-
- /**
- * Timeout for a connect attempt.
- * When reached, try to connect to a different peer, if any. If not,
- * try the same peer again.
- */
- GNUNET_SCHEDULER_TaskIdentifier timeout;
-
-};
-
-/**
- * Struct to keep state of running searches that have consumed a part of
- * the inital string.
- */
-struct MeshRegexSearchContext
-{
- /**
- * Part of the description already consumed by
- * this particular search branch.
- */
- size_t position;
-
- /**
- * Information about the search.
- */
- struct MeshRegexSearchInfo *info;
-
- /**
- * We just want to look for one edge, the longer the better.
- * Keep its length.
- */
- unsigned int longest_match;
-
- /**
- * Destination hash of the longest match.
- */
- struct GNUNET_HashCode hash;
-};
-
/******************************************************************************/
/************************ DEBUG FUNCTIONS ****************************/
/******************************************************************************/
/**
* Hostkey generation context
*/
-static struct GNUNET_CRYPTO_RsaKeyGenerationContext *keygen;
+static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen;
/**
* DLL with all the clients, head.
/**
* Own private key.
*/
-static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
+static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
/**
* Own public key.
*/
-static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
/**
* Tunnel ID for the next created tunnel (global tunnel number).
static MESH_TunnelNumber next_local_tid;
/**
- * All application types provided by this peer.
+ * All application types provided by this peer: H(app) = *Client.
*/
static struct GNUNET_CONTAINER_MultiHashMap *applications;
/**
- * Function to process DHT string to regex matching.
- * Called on each result obtained for the DHT search.
- *
- * @param cls closure (search context)
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path path of the get request (not used)
- * @param get_path_length lenght of get_path (not used)
- * @param put_path path of the put request (not used)
- * @param put_path_length length of the put_path (not used)
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * Retrieve the MeshPeerInfo stucture associated with the peer, create one
+ * and insert it in the appropiate structures if the peer is not known yet.
*
- * TODO: re-issue the request after certain time? cancel after X results?
- */
-static void
-dht_get_string_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);
-
-
-/**
- * Function to process DHT string to regex matching.
- * Called on each result obtained for the DHT search.
+ * @param peer Full identity of the peer.
*
- * @param cls closure (search context)
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path path of the get request (not used)
- * @param get_path_length lenght of get_path (not used)
- * @param put_path path of the put request (not used)
- * @param put_path_length length of the put_path (not used)
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * @return Existing or newly created peer info.
*/
-static void
-dht_get_string_accept_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);
+static struct MeshPeerInfo *
+peer_info_get (const struct GNUNET_PeerIdentity *peer);
/**
peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t);
+/**
+ * Build a PeerPath from the paths returned from the DHT, reversing the paths
+ * to obtain a local peer -> destination path and interning the peer ids.
+ *
+ * @return Newly allocated and created path
+ */
+static struct MeshPeerPath *
+path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length);
+
+
+/**
+ * Adds a path to the peer_infos of all the peers in the path
+ *
+ * @param p Path to process.
+ * @param confirmed Whether we know if the path works or not.
+ */
+static void
+path_add_to_peers (struct MeshPeerPath *p, int confirmed);
+
+
/**
* Add a peer to a tunnel, accomodating paths accordingly and initializing all
* needed rescources.
tunnel_add_client (struct MeshTunnel *t, struct MeshClient *c);
-/**
- * Jump to the next edge, with the longest matching token.
- *
- * @param block Block found in the DHT.
- * @param size Size of the block.
- * @param ctx Context of the search.
- *
- * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
- */
-static void
-regex_next_edge (const struct MeshRegexBlock *block,
- size_t size,
- struct MeshRegexSearchContext *ctx);
-
-
-/**
- * Find a path to a peer that offers a regex servcie compatible
- * with a given string.
- *
- * @param key The key of the accepting state.
- * @param ctx Context containing info about the string, tunnel, etc.
- */
-static void
-regex_find_path (const struct GNUNET_HashCode *key,
- struct MeshRegexSearchContext *ctx);
-
-
/**
* @brief Queue and pass message to core when possible.
*
queue_send (void *cls, size_t size, void *buf);
/******************************************************************************/
-/************************ ITERATORS ****************************/
+/************************ REGEX INTEGRATION ****************************/
/******************************************************************************/
/**
- * Iterator over found existing mesh regex blocks that match an ongoing search.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return GNUNET_YES if we should continue to iterate,
- * GNUNET_NO if not.
- */
-static int
-regex_result_iterator (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
-{
- struct MeshRegexBlock *block = value;
- struct MeshRegexSearchContext *ctx = cls;
-
- if (GNUNET_YES == ntohl(block->accepting) &&
- ctx->position == strlen (ctx->info->description))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Found accepting known block\n");
- regex_find_path (key, ctx);
- return GNUNET_YES; // We found an accept state!
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n",
- ctx->position, strlen(ctx->info->description),
- ntohl(block->accepting));
-
- }
- regex_next_edge(block, SIZE_MAX, ctx);
-
- GNUNET_STATISTICS_update (stats, "# regex mesh blocks iterated", 1, GNUNET_NO);
-
- return GNUNET_YES;
-}
-
-
-/**
- * Iterator over edges in a regex block retrieved from the DHT.
- *
- * @param cls Closure (context of the search).
- * @param token Token that follows to next state.
- * @param len Lenght of token.
- * @param key Hash of next state.
- *
- * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
- */
-static int
-regex_edge_iterator (void *cls,
- const char *token,
- size_t len,
- const struct GNUNET_HashCode *key)
-{
- struct MeshRegexSearchContext *ctx = cls;
- struct MeshRegexSearchInfo *info = ctx->info;
- char *current;
- size_t current_len;
-
- GNUNET_STATISTICS_update (stats, "# regex edges iterated", 1, GNUNET_NO);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Start of regex edge iterator\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* descr : %s\n", info->description);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* posit : %u\n", ctx->position);
- current = &info->description[ctx->position];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* currt : %s\n", current);
- current_len = strlen (info->description) - ctx->position;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* ctlen : %u\n", current_len);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tklen : %u\n", len);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* token : %.*s\n", len, token);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* nextk : %s\n", GNUNET_h2s(key));
- if (len > current_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token too long, END\n");
- return GNUNET_YES; // Token too long, wont match
- }
- if (0 != strncmp (current, token, len))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token doesn't match, END\n");
- return GNUNET_YES; // Token doesn't match
- }
-
- if (len > ctx->longest_match)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token is longer, KEEP\n");
- ctx->longest_match = len;
- ctx->hash = *key;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token is not longer, IGNORE\n");
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
- return GNUNET_YES;
-}
-
-
-/**
- * Jump to the next edge, with the longest matching token.
- *
- * @param block Block found in the DHT.
- * @param size Size of the block.
- * @param ctx Context of the search.
- *
- * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
+ * Cancel a mesh regex search and free resources.
*/
static void
-regex_next_edge (const struct MeshRegexBlock *block,
- size_t size,
- struct MeshRegexSearchContext *ctx)
-{
- struct MeshRegexSearchContext *new_ctx;
- struct MeshRegexSearchInfo *info = ctx->info;
- struct GNUNET_DHT_GetHandle *get_h;
- const char *rest;
- int result;
-
- /* Find the longest match for the current string position,
- * among tokens in the given block */
- ctx->longest_match = 0;
- result = GNUNET_MESH_regex_block_iterate (block, size,
- ®ex_edge_iterator, ctx);
- GNUNET_break (GNUNET_OK == result);
-
- /* Did anything match? */
- if (0 == ctx->longest_match)
- return;
-
- new_ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext));
- new_ctx->info = info;
- new_ctx->position = ctx->position + ctx->longest_match;
- GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
-
- /* Check whether we already have a DHT GET running for it */
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, &ctx->hash))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* GET running, END\n");
- GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results,
- &ctx->hash,
- ®ex_result_iterator,
- new_ctx);
- // FIXME: "leaks" new_ctx? avoid keeping it around?
- return; // We are already looking for it
- }
-
- GNUNET_STATISTICS_update (stats, "# regex nodes traversed", 1, GNUNET_NO);
-
- /* Start search in DHT */
- rest = &new_ctx->info->description[new_ctx->position];
- get_h =
- GNUNET_DHT_get_start (dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_MESH_REGEX, /* type */
- &ctx->hash, /* key to search */
- dht_replication_level, /* replication level */
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- rest, /* xquery */
- // FIXME add BLOOMFILTER to exclude filtered peers
- strlen(rest) + 1, /* xquery bits */
- // FIXME add BLOOMFILTER SIZE
- &dht_get_string_handler, new_ctx);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles,
- &ctx->hash,
- get_h,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+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_break (0);
- return;
+ GNUNET_SCHEDULER_cancel(regex_search->timeout);
}
-}
-
-
-/**
- * Iterator over hash map entries to cancel DHT GET requests after a
- * successful connect_by_string.
- *
- * @param cls Closure (unused).
- * @param key Current key code (unused).
- * @param value Value in the hash map (get handle).
- * @return GNUNET_YES if we should continue to iterate,
- * GNUNET_NO if not.
- */
-static int
-regex_cancel_dht_get (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
-{
- struct GNUNET_DHT_GetHandle *h = value;
-
- GNUNET_DHT_get_stop (h);
- return GNUNET_YES;
-}
-
-
-/**
- * Iterator over hash map entries to free MeshRegexBlocks stored during the
- * search for connect_by_string.
- *
- * @param cls Closure (unused).
- * @param key Current key code (unused).
- * @param value MeshRegexBlock in the hash map.
- * @return GNUNET_YES if we should continue to iterate,
- * GNUNET_NO if not.
- */
-static int
-regex_free_result (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
-{
-
- GNUNET_free (value);
- return GNUNET_YES;
-}
-
-
-/**
- * Find a path to a peer that offers a regex servcie compatible
- * with a given string.
- *
- * @param key The key of the accepting state.
- * @param ctx Context containing info about the string, tunnel, etc.
- */
-static void
-regex_find_path (const struct GNUNET_HashCode *key,
- struct MeshRegexSearchContext *ctx)
-{
- struct GNUNET_DHT_GetHandle *get_h;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n");
- get_h = GNUNET_DHT_get_start (dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* type */
- key, /* key to search */
- dht_replication_level, /* replication level */
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE/* |
- GNUNET_DHT_RO_RECORD_ROUTE*/,
- NULL, /* xquery */
- // FIXME add BLOOMFILTER to exclude filtered peers
- 0, /* xquery bits */
- // FIXME add BLOOMFILTER SIZE
- &dht_get_string_accept_handler, ctx);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles,
- key,
- get_h,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_free (regex_search);
}
GNUNET_PEER_Id id;
GNUNET_PEER_Id old;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex connect timeout\n");
+ 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;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " timed out: %u\n", old);
+ DEBUG_REGEX (" timed out: %u\n", old);
if (0 < info->n_peers)
{
// Try to connect to same peer again.
id = info->peer;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " trying: %u\n", id);
+ DEBUG_REGEX (" trying: %u\n", id);
peer_info = peer_info_get_short(id);
tunnel_add_peer (info->t, peer_info);
info->timeout = GNUNET_SCHEDULER_add_delayed (connect_timeout,
®ex_connect_timeout,
info);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex connect timeout END\n");
+ 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);
}
/**
- * Cancel an ongoing regex search in the DHT and free all resources.
+ * Periodically announce what applications are provided by local clients
+ * (by regex)
*
- * @param ctx The search context.
+ * @param cls closure
+ * @param tc task context
*/
static void
-regex_cancel_search(struct MeshRegexSearchContext *ctx)
+regex_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct MeshRegexSearchInfo *info = ctx->info;
- int i;
+ struct MeshClient *c = cls;
+ unsigned int i;
- GNUNET_free (info->description);
- GNUNET_CONTAINER_multihashmap_iterate (info->dht_get_handles,
- ®ex_cancel_dht_get, NULL);
- GNUNET_CONTAINER_multihashmap_iterate (info->dht_get_results,
- ®ex_free_result, NULL);
- GNUNET_CONTAINER_multihashmap_destroy (info->dht_get_results);
- GNUNET_CONTAINER_multihashmap_destroy (info->dht_get_handles);
- info->t->regex_ctx = NULL;
- for (i = 0; i < info->n_contexts; i++)
- {
- GNUNET_free (info->contexts[i]);
- }
- if (0 < info->n_contexts)
- GNUNET_free (info->contexts);
- if (0 < info->n_peers)
- GNUNET_free (info->peers);
- if (GNUNET_SCHEDULER_NO_TASK != info->timeout)
- {
- GNUNET_SCHEDULER_cancel(info->timeout);
- }
- GNUNET_free (info);
+ 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");
}
return GNUNET_YES;
}
block.type = htonl (block.type);
-
+ DEBUG_DHT ("Putting APP key: %s\n", GNUNET_h2s (key));
GNUNET_break (NULL !=
GNUNET_DHT_put (dht_handle, key,
dht_replication_level,
}
-#if 0
-/**
- * Function called when the DHT regex put is complete.
- *
- * @param the 'struct MeshClient' for which we were PUTting
- * @param success GNUNET_OK if the PUT was transmitted,
- * GNUNET_NO on timeout,
- * GNUNET_SYSERR on disconnect from service
- * after the PUT message was transmitted
- * (so we don't know if it was received or not)
- */
-static void
-announce_regex_done (void *cls,
- int success)
-{
- struct MeshClient *c = cls;
-
-}
-#endif
-
-
-/**
- * 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.
- */
-static 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)
-{
- struct MeshRegexBlock *block;
- struct MeshRegexEdge *block_edge;
- enum GNUNET_DHT_RouteOption opt;
- size_t size;
- size_t len;
- unsigned int i;
- unsigned int offset;
- char *aux;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " regex dht put for state %s\n",
- GNUNET_h2s(key));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " proof: %s\n",
- proof);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " num edges: %u\n",
- num_edges);
-
- opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
- if (GNUNET_YES == accepting)
- {
- struct MeshRegexAccept block;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " state %s is accepting, putting own id\n",
- GNUNET_h2s(key));
- size = sizeof (block);
- block.key = *key;
- block.id = my_full_id;
- GNUNET_STATISTICS_update (stats, "# regex accepting blocks stored",
- 1, GNUNET_NO);
- GNUNET_STATISTICS_update (stats, "# regex accepting block bytes stored",
- sizeof (block), GNUNET_NO);
- (void)
- GNUNET_DHT_put(dht_handle, key,
- dht_replication_level,
- opt/* | GNUNET_DHT_RO_RECORD_ROUTE*/,
- GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
- size,
- (char *) &block,
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: expiration time should be option */
- app_announce_time,
- NULL, NULL);
- }
- len = strlen(proof);
- size = sizeof (struct MeshRegexBlock) + len;
- block = GNUNET_malloc (size);
-
- block->key = *key;
- block->n_proof = htonl (len);
- block->n_edges = htonl (num_edges);
- block->accepting = htonl (accepting);
-
- /* Store the proof at the end of the block. */
- aux = (char *) &block[1];
- memcpy (aux, proof, len);
- aux = &aux[len];
-
- /* Store each edge in a variable length MeshEdge struct at the
- * very end of the MeshRegexBlock structure.
- */
- for (i = 0; i < num_edges; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " edge %s towards %s\n",
- edges[i].label,
- GNUNET_h2s(&edges[i].destination));
-
- /* aux points at the end of the last block */
- len = strlen (edges[i].label);
- size += sizeof (struct MeshRegexEdge) + len;
- // Calculate offset FIXME is this ok? use size instead?
- offset = aux - (char *) block;
- block = GNUNET_realloc (block, size);
- aux = &((char *) block)[offset];
- block_edge = (struct MeshRegexEdge *) aux;
- block_edge->key = edges[i].destination;
- block_edge->n_token = htonl (len);
- aux = (char *) &block_edge[1];
- memcpy (aux, edges[i].label, len);
- aux = &aux[len];
- }
- (void)
- GNUNET_DHT_put(dht_handle, key,
- dht_replication_level,
- opt,
- GNUNET_BLOCK_TYPE_MESH_REGEX, size,
- (char *) block,
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
- app_announce_time,
- NULL, NULL);
- GNUNET_STATISTICS_update (stats, "# regex blocks stored",
- 1, GNUNET_NO);
- GNUNET_STATISTICS_update (stats, "# regex block bytes stored",
- size, GNUNET_NO);
-
- GNUNET_free (block);
-}
-
-
-/**
- * Store the regular expression describing a local service into the DHT.
- *
- * @param regex The regular expresion.
- */
-static void
-regex_put (struct MeshRegexDescriptor *regex)
-{
- if (NULL == regex->dfa)
- {
- regex->dfa = GNUNET_REGEX_construct_dfa (regex->regex,
- strlen (regex->regex),
- regex->compression);
- }
-
- DEBUG_DHT (" regex_put (%s) start\n", regex->regex);
- GNUNET_REGEX_iterate_all_edges (regex->dfa, ®ex_iterator, NULL);
- DEBUG_DHT (" 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
-announce_regex (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_DHT ("Starting PUT 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,
- &announce_regex,
- cls);
- DEBUG_DHT ("Finished PUT for regex\n");
-}
-
-
/**
* Periodically announce what applications are provided by local clients
* (by type)
}
+/**
+ * Notify the owner of a tunnel that a peer has disconnected.
+ *
+ * @param c Client (owner of tunnel).
+ * @param t Tunnel this message is about.
+ * @param peer_id Short ID of the disconnected peer.
+ */
+void
+client_notify_peer_disconnected (struct MeshClient *c,
+ struct MeshTunnel *t,
+ GNUNET_PEER_Id peer_id)
+{
+ struct GNUNET_MESH_PeerControl msg;
+
+ if (NULL == t->owner || NULL == nc)
+ return;
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
+ msg.tunnel_id = htonl (t->local_tid);
+ GNUNET_PEER_resolve (peer_id, &msg.peer);
+ GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
+ &msg.header, GNUNET_NO);
+}
+
+
/**
* Send the message to all clients that have subscribed to its type
*
{
peer->ntunnels--;
peer->tunnels[i] = peer->tunnels[peer->ntunnels];
- peer->tunnels = GNUNET_realloc (peer->tunnels, peer->ntunnels);
+ peer->tunnels =
+ GNUNET_realloc (peer->tunnels,
+ peer->ntunnels * sizeof(struct MeshTunnel *));
return GNUNET_YES;
}
}
struct MeshPeerInfo *peer;
struct MeshPathInfo *path_info;
- if (NULL != t->owner && NULL != nc)
- {
- struct GNUNET_MESH_PeerControl msg;
+ client_notify_peer_disconnected (t->owner, t, peer_id);
- msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
- msg.tunnel_id = htonl (t->local_tid);
- GNUNET_PEER_resolve (peer_id, &msg.peer);
- GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
- &msg.header, GNUNET_NO);
- }
peer = peer_info_get_short (peer_id);
path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->peer = peer;
if (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
{
- t->peers_total++;
GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey,
* valid.
*
* @param t The tunnel whose peers to notify.
- * @param send_back Do we need to notify our parent node?
+ * @param parent ID of the parent, in case the tree is already destroyed.
*/
static void
-tunnel_send_destroy (struct MeshTunnel *t, int send_back)
+tunnel_send_destroy (struct MeshTunnel *t, GNUNET_PEER_Id parent)
{
struct GNUNET_MESH_TunnelDestroy msg;
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_Id parent;
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);
+ GNUNET_PEER_resolve (t->id.oid, &msg.oid);
+ msg.tid = htonl (t->id.tid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " sending tunnel destroy for tunnel: %s [%X]\n",
+ GNUNET_i2s (&msg.oid), t->id.tid);
if (tree_count_children(t->tree) > 0)
{
- msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);
- GNUNET_PEER_resolve (t->id.oid, &msg.oid);
- msg.tid = htonl (t->id.tid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending multicast to children\n");
tunnel_send_multicast (t, &msg.header);
}
- parent = tree_get_predecessor(t->tree);
- if (GNUNET_NO == send_back || 0 == parent)
+ if (0 == parent)
+ parent = tree_get_predecessor (t->tree);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " parent: %u\n", parent);
+ if (0 == parent)
return;
- msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);
- send_prebuilt_message(&msg.header, &id, t);
+ GNUNET_PEER_resolve (parent, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " sending back to %s\n",
+ GNUNET_i2s (&id));
+ send_prebuilt_message (&msg.header, &id, t);
}
(void) GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t);
GNUNET_free_non_null (t->clients);
+ GNUNET_free_non_null (t->ignore);
GNUNET_free_non_null (t->clients_fc);
if (NULL != t->peers)
tree_iterate_children (t->tree, &tunnel_cancel_queues, t);
tree_destroy (t->tree);
- if (NULL != t->regex_ctx)
- regex_cancel_search (t->regex_ctx);
+ if (NULL != t->regex_search)
+ GNUNET_REGEX_search_cancel (t->regex_search->search_handle);
if (NULL != t->dht_get_type)
GNUNET_DHT_get_stop (t->dht_get_type);
if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
*/
static void
tunnel_destroy_empty_delayed (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct MeshTunnel *t = cls;
}
#endif
- tunnel_destroy (t);
+ tunnel_send_destroy (t, 0);
+ if (0 == t->pending_messages)
+ tunnel_destroy (t);
+ else
+ t->destroy = GNUNET_YES;
}
return t;
}
+/**
+ * Callback when removing children from a tunnel tree. Notify owner.
+ *
+ * @param cls Closure (tunnel).
+ * @param peer_id Short ID of the peer deleted.
+ */
+void
+tunnel_child_removed (void *cls, GNUNET_PEER_Id peer_id)
+{
+ struct MeshTunnel *t = cls;
+
+ client_notify_peer_disconnected (t->owner, t, peer_id);
+}
/**
* Removes an explicit path from a tunnel, freeing all intermediate nodes
{
int r;
- r = tree_del_peer (t->tree, peer, NULL, NULL);
+ r = tree_del_peer (t->tree, peer, &tunnel_child_removed, t);
if (GNUNET_NO == r)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
tunnel_destroy_empty (t);
return GNUNET_OK;
}
- tunnel_send_destroy (t, GNUNET_YES);
+ tunnel_send_destroy (t, 0);
t->owner = NULL;
t->destroy = GNUNET_YES;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
unsigned int own_pos;
uint16_t size;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ManipulatePath *msg;
struct GNUNET_PeerIdentity *pi;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_PathBroken *msg;
struct MeshTunnel *t;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_TunnelDestroy *msg;
struct MeshTunnel *t;
+ GNUNET_PEER_Id parent;
+ GNUNET_PEER_Id pid;
msg = (struct GNUNET_MESH_TunnelDestroy *) message;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" for tunnel %s [%u]\n",
GNUNET_i2s (&msg->oid), ntohl (msg->tid));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
+ /* Check signature */
if (NULL == t)
{
/* Probably already got the message from another path,
1, GNUNET_NO);
return GNUNET_OK;
}
- if (t->id.oid == myid)
+ parent = tree_get_predecessor (t->tree);
+ pid = GNUNET_PEER_search (peer);
+ if (pid != parent)
{
- GNUNET_break_op (0);
- return GNUNET_OK;
+ unsigned int nc;
+
+ tree_del_peer (t->tree, pid, &tunnel_child_removed, t);
+ nc = tree_count_children (t->tree);
+ if (nc > 0 || NULL != t->owner || t->nclients > 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "still in use: %u cl, %u ch\n",
+ t->nclients, nc);
+ return GNUNET_OK;
+ }
}
if (t->local_tid_dest >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
t->local_tid, t->local_tid_dest);
send_clients_tunnel_destroy (t);
}
- tunnel_send_destroy (t, GNUNET_YES);
+ tunnel_send_destroy (t, parent);
t->destroy = GNUNET_YES;
// TODO: add timeout to destroy the tunnel anyway
return GNUNET_OK;
* @param cls closure
* @param peer peer identity this notification is about
* @param message message
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_Unicast *msg;
struct GNUNET_PeerIdentity *neighbor;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*
*/
static int
handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_Multicast *msg;
struct MeshTunnel *t;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ToOrigin *msg;
struct GNUNET_PeerIdentity id;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ACK *msg;
struct MeshTunnel *t;
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_Poll *msg;
struct MeshTunnel *t;
return GNUNET_OK;
}
-
/**
* Core handler for path ACKs
*
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
*
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_PathACK *msg;
struct GNUNET_PeerIdentity id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n",
GNUNET_i2s (peer));
- if (NULL != t->regex_ctx && t->regex_ctx->info->peer == peer_info->id)
+ if (NULL != t->regex_search && t->regex_search->peer == peer_info->id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"connect_by_string completed, stopping search\n");
- regex_cancel_search (t->regex_ctx);
- t->regex_ctx = NULL;
+ regex_cancel_search (t->regex_search);
+ t->regex_search = NULL;
}
/* Add paths to peers? */
tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
send_client_peer_connected (t, peer_info->id);
}
+ if (NULL != peer_info->dhtget)
+ {
+ GNUNET_DHT_get_stop (peer_info->dhtget);
+ peer_info->dhtget = NULL;
+ }
return GNUNET_OK;
}
" not for us, retransmitting...\n");
GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
peer_info = peer_info_get (&msg->oid);
- if (NULL == peer_info)
- {
- /* If we know the tunnel, we should DEFINITELY know the peer */
- GNUNET_break (0);
- return GNUNET_OK;
- }
send_prebuilt_message (message, &id, t);
return GNUNET_OK;
}
* @param cls closure
* @param message message
* @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*
*/
static int
handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_TunnelKeepAlive *msg;
struct MeshTunnel *t;
if (NULL == t)
{
/* TODO notify that we dont know that tunnel */
- GNUNET_STATISTICS_update (stats, "# keepalive on unknown tunnel", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# keepalive on unknown tunnel", 1,
+ GNUNET_NO);
return GNUNET_OK;
}
static int
deregister_app (void *cls, const struct GNUNET_HashCode * key, void *value)
{
- struct GNUNET_CONTAINER_MultiHashMap *h = cls;
+ struct MeshClient *c = cls;
+
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h, key, value));
+ GNUNET_CONTAINER_multihashmap_remove (applications, key, c));
return GNUNET_OK;
}
GNUNET_PEER_resolve (path_info->peer->id, &pi);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", GNUNET_i2s (&pi));
- p = path_build_from_dht (get_path, get_path_length, put_path,
- put_path_length);
+ 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);
+ path_destroy (p);
for (i = 0; i < path_info->peer->ntunnels; i++)
{
tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
}
-/**
- * Function to process DHT string to regex matching.
- * Called on each result obtained for the DHT search.
- *
- * @param cls closure (search context)
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path path of the get request (not used)
- * @param get_path_length lenght of get_path (not used)
- * @param put_path path of the put request (not used)
- * @param put_path_length length of the put_path (not used)
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
- */
-static void
-dht_get_string_accept_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 MeshRegexAccept *block = data;
- struct MeshRegexSearchContext *ctx = cls;
- struct MeshRegexSearchInfo *info = ctx->info;
-// struct MeshPeerPath *p;
- struct MeshPeerInfo *peer_info;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", info->description);
- GNUNET_STATISTICS_update (stats, "# regex accepting blocks found",
- 1, GNUNET_NO);
- GNUNET_STATISTICS_update (stats, "# regex accepting block bytes found",
- size, GNUNET_NO);
-
- peer_info = peer_info_get(&block->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;
-}
-
-
-/**
- * Function to process DHT string to regex matching.
- * Called on each result obtained for the DHT search.
- *
- * @param cls closure (search context)
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path path of the get request (not used)
- * @param get_path_length lenght of get_path (not used)
- * @param put_path path of the put request (not used)
- * @param put_path_length length of the put_path (not used)
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
- *
- * TODO: re-issue the request after certain time? cancel after X results?
- */
-static void
-dht_get_string_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 MeshRegexBlock *block = data;
- struct MeshRegexSearchContext *ctx = cls;
- struct MeshRegexSearchInfo *info = ctx->info;
- void *copy;
- size_t len;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DHT GET STRING RETURNED RESULTS\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " key: %s\n", GNUNET_h2s (key));
-
- GNUNET_STATISTICS_update (stats, "# regex blocks found",
- 1, GNUNET_NO);
- GNUNET_STATISTICS_update (stats, "# regex block bytes found",
- size, GNUNET_NO);
-
- copy = GNUNET_malloc (size);
- memcpy (copy, data, size);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put(info->dht_get_results, key, copy,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- len = ntohl (block->n_proof);
- {
- char proof[len + 1];
-
- memcpy (proof, &block[1], len);
- proof[len] = '\0';
- if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
- {
- GNUNET_break_op (0);
- return;
- }
- }
- len = strlen (info->description);
- if (len == ctx->position) // String processed
- {
- if (GNUNET_YES == ntohl (block->accepting))
- {
- regex_find_path(key, ctx);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " block not accepting!\n");
- // FIXME REGEX this block not successful, wait for more? start timeout?
- }
- return;
- }
-
- regex_next_edge (block, size, ctx);
-
- return;
-}
-
/******************************************************************************/
/********************* MESH LOCAL HANDLES **************************/
/******************************************************************************/
/* deregister clients applications */
if (NULL != c->apps)
{
- GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, c->apps);
+ GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, c);
GNUNET_CONTAINER_multihashmap_destroy (c->apps);
}
if (0 == GNUNET_CONTAINER_multihashmap_size (applications) &&
for (i = 0; i < c->n_regex; i++)
{
GNUNET_free (c->regexes[i].regex);
- if (NULL != c->regexes[i].dfa)
- GNUNET_REGEX_automaton_destroy (c->regexes[i].dfa);
+ if (NULL != c->regexes[i].h)
+ GNUNET_REGEX_announce_cancel (c->regexes[i].h);
}
GNUNET_free_non_null (c->regexes);
if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task)
}
rd.regex = regex;
rd.compression = ntohs (msg->compression_characters);
- rd.dfa = NULL;
+ rd.h = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " length %u\n", len);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " cm %u\n", ntohs(rd.compression));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " compr %u\n", ntohs (rd.compression));
GNUNET_array_append (c->regexes, c->n_regex, rd);
c->partial_regex = NULL;
if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task)
{
- c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c);
+ c->regex_announce_task = GNUNET_SCHEDULER_add_now (®ex_announce, c);
}
else
{
- regex_put(&rd);
+ regex_put (&rd);
}
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- send_client_tunnel_disconnect(t, c);
- client_delete_tunnel(c, t);
+ send_client_tunnel_disconnect (t, c);
+ client_delete_tunnel (c, t);
/* Don't try to ACK the client about the tunnel_destroy multicast packet */
t->owner = NULL;
- tunnel_send_destroy (t, GNUNET_YES);
+ tunnel_send_destroy (t, 0);
t->destroy = GNUNET_YES;
- // The tunnel will be destroyed when the last message is transmitted.
+ /* The tunnel will be destroyed when the last message is transmitted. */
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ConnectPeerByString *msg;
- struct MeshRegexSearchContext *ctx;
struct MeshRegexSearchInfo *info;
- struct GNUNET_DHT_GetHandle *get_h;
- struct GNUNET_HashCode key;
struct MeshTunnel *t;
struct MeshClient *c;
MESH_TunnelNumber 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_ctx)
+ if (NULL != t->regex_search)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
len = size - sizeof(struct GNUNET_MESH_ConnectPeerByString);
string = (const char *) &msg[1];
- /* Initialize context */
- size = GNUNET_REGEX_get_first_key (string, len, &key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " consumed %u bits out of %u\n", size, len);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " looking for %s\n", GNUNET_h2s (&key));
-
info = GNUNET_malloc (sizeof (struct MeshRegexSearchInfo));
info->t = t;
info->description = GNUNET_strndup (string, len);
- info->dht_get_handles = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO);
- info->dht_get_results = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " string: %s\n", info->description);
- ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext));
- ctx->position = size;
- ctx->info = info;
- t->regex_ctx = ctx;
-
- GNUNET_array_append (info->contexts, info->n_contexts, ctx);
-
- /* Start search in DHT */
- get_h = GNUNET_DHT_get_start (dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_MESH_REGEX, /* type */
- &key, /* key to search */
- dht_replication_level, /* replication level */
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- &info->description[size], /* xquery */
- // FIXME add BLOOMFILTER to exclude filtered peers
- len + 1 - size, /* xquery bits */
- // FIXME add BLOOMFILTER SIZE
- &dht_get_string_handler, ctx);
-
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles,
- &key,
- get_h,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ 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");
copy->ttl = htonl (default_ttl);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" calling generic handler...\n");
- handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL, 0);
+ handle_mesh_data_unicast (NULL, &my_full_id, ©->header);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
copy->sender = my_full_id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" calling generic handler...\n");
- handle_mesh_data_to_orig (NULL, &my_full_id, ©->header, NULL, 0);
+ handle_mesh_data_to_orig (NULL, &my_full_id, ©->header);
}
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_assert (ntohl (copy->pid) == (t->fwd_pid + 1));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" calling generic handler...\n");
- handle_mesh_data_multicast (client, &my_full_id, ©->header, NULL, 0);
+ handle_mesh_data_multicast (client, &my_full_id, ©->header);
}
GNUNET_SERVER_receive_done (t->owner->handle, GNUNET_OK);
*resp = *msg;
resp->npeers = 0;
ctx.msg = resp;
- ctx.lookup = GNUNET_CONTAINER_multihashmap_create (4 * t->peers_total,
- GNUNET_YES);
+ ctx.lookup = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
ctx.c = c;
/* Collect and send information */
*
* @param cls closure
* @param peer peer identity this notification is about
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
*/
static void
-core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct MeshPeerInfo *peer_info;
struct MeshPeerPath *path;
}
if (NULL != keygen)
{
- GNUNET_CRYPTO_rsa_key_create_stop (keygen);
+ GNUNET_CRYPTO_ecc_key_create_stop (keygen);
keygen = NULL;
}
GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL);
/**
- * Callback for hostkey read/generation
+ * Callback for hostkey read/generation.
*
* @param cls Closure (Configuration handle).
- * @param pk the private key
- * @param emsg error message
+ * @param pk The ECC private key.
+ * @param emsg Error message, if any.
*/
static void
key_generation_cb (void *cls,
- struct GNUNET_CRYPTO_RsaPrivateKey *pk,
+ struct GNUNET_CRYPTO_EccPrivateKey *pk,
const char *emsg)
{
const struct GNUNET_CONFIGURATION_Handle *c = cls;
keygen = NULL;
if (NULL == pk)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Mesh service could not access hostkey: %s. Exiting.\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Could not access hostkey: %s. Exiting.\n"),
emsg);
GNUNET_SCHEDULER_shutdown ();
return;
}
my_private_key = pk;
- GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
+ GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
&my_full_id.hashPubKey);
myid = GNUNET_PEER_intern (&my_full_id);
"Mesh for peer [%s] starting\n",
GNUNET_i2s(&my_full_id));
-// transport_handle = GNUNET_TRANSPORT_connect(c,
-// &my_full_id,
-// NULL,
-// NULL,
-// NULL,
-// NULL);
-
core_handle = GNUNET_CORE_connect (c, /* Main configuration */
NULL, /* Closure passed to MESH functions */
&core_init, /* Call core_init once connected */
server_handle = server;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
+ GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
&keyfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
("%s service is lacking key configuration settings (%s). Exiting.\n"),
- "mesh", "hostkey");
+ "mesh", "peer/privatekey");
GNUNET_SCHEDULER_shutdown ();
return;
}
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
- keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile,
+ keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile,
&key_generation_cb,
(void *) c);
GNUNET_free (keyfile);