From 9e921c69007ba709fee460751d7f20237dd56ed7 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Thu, 11 Nov 2010 11:18:34 +0000 Subject: [PATCH] Adding replication parameter for initiating GET and PUT requests to the DHT. --- src/dht/dht.h | 14 +- src/dht/dht_api_get_put.c | 12 +- src/dht/dhtlog.h | 15 +- src/dht/gnunet-dht-driver.c | 81 +++- src/dht/gnunet-dht-get.c | 1 + src/dht/gnunet-dht-put.c | 1 + src/dht/gnunet-service-dht.c | 488 ++++++++++++------------ src/dht/plugin_dhtlog_dummy.c | 8 +- src/dht/plugin_dhtlog_mysql.c | 13 +- src/dht/plugin_dhtlog_mysql_dump.c | 24 +- src/dht/plugin_dhtlog_mysql_dump_load.c | 23 +- src/dht/test_dht_api.c | 2 + src/dht/test_dht_multipeer.c | 2 + src/dht/test_dht_twopeer.c | 4 +- src/dht/test_dht_twopeer_put_get.c | 2 + src/dht/test_dhtlog.c | 2 +- src/fs/gnunet-service-fs.c | 2 + src/include/gnunet_dht_service.h | 63 ++- src/vpn/gnunet-service-dns.c | 2 + 19 files changed, 403 insertions(+), 356 deletions(-) diff --git a/src/dht/dht.h b/src/dht/dht.h index bcfc5abd4..094cfb7d8 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -27,7 +27,7 @@ #ifndef DHT_H_ #define DHT_H_ -#define DEBUG_DHT GNUNET_NO +#define DEBUG_DHT GNUNET_YES /** * Needs to be GNUNET_YES for logging to dhtlog to work! @@ -55,19 +55,11 @@ #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) /** - * FIXME: document. + * Priority for routing results from other peers through + * the DHT. */ #define DHT_SEND_PRIORITY 4 -/** - * FIXME: document. - */ -#define DEFAULT_GET_REPLICATION 5 - -/** - * FIXME: document. - */ -#define DEFAULT_PUT_REPLICATION 8 #define STAT_ROUTES "# DHT ROUTE Requests Seen" #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded" diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c index 98ee8d822..3b7a6d83a 100644 --- a/src/dht/dht_api_get_put.c +++ b/src/dht/dht_api_get_put.c @@ -39,6 +39,8 @@ * * @param handle handle to DHT service * @param key the key to store under + * @param desired_replication_level estimate of how many + * nearest peers this request should reach * @param options routing options for this message * @param type type of the value * @param size number of bytes in data; must be less than 64k @@ -52,6 +54,7 @@ void GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, + uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, @@ -82,7 +85,7 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, GNUNET_break (NULL == GNUNET_DHT_route_start (handle, key, - DEFAULT_PUT_REPLICATION, options, + desired_replication_level, options, &put_msg->header, timeout, NULL, NULL, @@ -168,10 +171,12 @@ get_reply_iterator (void *cls, * @param timeout how long to wait for transmission of this request to the service * @param type expected type of the response object * @param key the key to look up + * @param desired_replication_level estimate of how many + nearest peers this request should reach * @param options routing options for this message * @param bf bloom filter associated with query (can be NULL) * @param bf_mutator mutation value for bf - * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery extended query data (can be NULL, depending on type) * @param xquery_size number of bytes in xquery * @param iter function to call on each result * @param iter_cls closure for iter @@ -183,6 +188,7 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, struct GNUNET_TIME_Relative timeout, enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, + uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const struct GNUNET_CONTAINER_BloomFilter *bf, int32_t bf_mutator, @@ -232,7 +238,7 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, get_handle->route_handle = GNUNET_DHT_route_start (handle, key, - DEFAULT_GET_REPLICATION, + desired_replication_level, options, &get_msg->header, timeout, diff --git a/src/dht/dhtlog.h b/src/dht/dhtlog.h index a9608ffd2..d53167a5c 100644 --- a/src/dht/dhtlog.h +++ b/src/dht/dhtlog.h @@ -70,11 +70,6 @@ typedef enum struct GNUNET_DHTLOG_TrialInfo { - /** - * Trialuid, possibly set by insert call. - */ - unsigned long long trialuid; - /** * Outside of database identifier for the trial. */ @@ -142,7 +137,7 @@ struct GNUNET_DHTLOG_TrialInfo /** * Routing behaves as it would in Kademlia (modified to work recursively, - * and with our other GNUnet constraints. + * and with our other GNUnet constraints). */ unsigned int strict_kademlia; @@ -222,13 +217,11 @@ struct GNUNET_DHTLOG_Handle /* * Update dhttests.trials table with current server time as end time * - * @param trialuid trial to update * @param gets_succeeded how many gets did the trial report successful * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ - int (*update_trial) (unsigned long long trialuid, - unsigned int gets_succeeded); + int (*update_trial) (unsigned int gets_succeeded); /* * Update dhttests.nodes table setting the identified @@ -287,13 +280,11 @@ struct GNUNET_DHTLOG_Handle /* * Update dhttests.trials table with total connections information * - * @param trialuid the trialuid to update * @param totalConnections the number of connections * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ - int (*update_connections) (unsigned long long trialuid, - unsigned int totalConnections); + int (*update_connections) (unsigned int totalConnections); /* * Update dhttests.trials table with total connections information diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 39e5eec72..87836c3f5 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -369,7 +369,7 @@ enum DHT_ROUND_TYPES /* Globals */ /** - * Timeout to let all get requests happen. + * Timeout to let all GET requests happen. */ static struct GNUNET_TIME_Relative all_get_timeout; @@ -378,45 +378,114 @@ static struct GNUNET_TIME_Relative all_get_timeout; */ static struct GNUNET_TIME_Relative get_timeout; +/** + * Time to allow for GET requests to be sent to service. + */ static struct GNUNET_TIME_Relative get_delay; +/** + * Time to allow for PUT requests to be sent to service. + */ static struct GNUNET_TIME_Relative put_delay; +/** + * Delay between sending find peer requests (if + * handled by the driver, no effect if sent by service). + */ static struct GNUNET_TIME_Relative find_peer_delay; +/** + * Time between find peer requests + * (find_peer_delay / max_outstanding_find_peer) + */ static struct GNUNET_TIME_Relative find_peer_offset; +/** + * How many seconds to allow each peer to start. + */ static struct GNUNET_TIME_Relative seconds_per_peer_start; +/** + * Boolean value, should the driver issue find peer requests + * (GNUNET_YES) or should it be left to the service (GNUNET_NO) + */ static unsigned int do_find_peer; +/** + * Boolean value, should replication be done by the dht + * service (GNUNET_YES) or by the driver (GNUNET_NO) + */ static unsigned int in_dht_replication; +/** + * Size of test data to insert/retrieve during testing. + */ static unsigned long long test_data_size = DEFAULT_TEST_DATA_SIZE; +/** + * Maximum number of concurrent PUT requests. + */ static unsigned long long max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS; +/** + * Maximum number of concurrent GET requests. + */ static unsigned long long max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS; +/** + * Number of nodes issuing malicious GET messages. + */ static unsigned long long malicious_getters; +/** + * Maximum number of concurrent find peer messages being sent. + */ static unsigned long long max_outstanding_find_peers; +/** + * Number of nodes issuing malicious PUT messages. + */ static unsigned long long malicious_putters; +/** + * Time (in seconds) to delay between rounds. + */ static unsigned long long round_delay; +/** + * How many malicious droppers to seed in the network. + */ static unsigned long long malicious_droppers; +/** + * How often to send malicious GET messages. + */ static struct GNUNET_TIME_Relative malicious_get_frequency; +/** + * How often to send malicious PUT messages. + */ static struct GNUNET_TIME_Relative malicious_put_frequency; +/** + * How long to send find peer requests. + */ static unsigned long long settle_time; +/** + * Handle to the dhtlog service. + */ static struct GNUNET_DHTLOG_Handle *dhtlog_handle; -static unsigned long long trialuid; +/** + * Replication value for GET requests. + */ +static unsigned long long get_replication; + +/** + * Replication value for PUT requests. + */ +static unsigned long long put_replication; /** * If GNUNET_YES, insert data at the same peers every time. @@ -759,7 +828,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) if (dhtlog_handle != NULL) { fprintf(stderr, "Update trial endtime\n"); - dhtlog_handle->update_trial (trialuid, gets_completed); + dhtlog_handle->update_trial (gets_completed); GNUNET_DHTLOG_disconnect(dhtlog_handle); dhtlog_handle = NULL; } @@ -985,7 +1054,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) if (dhtlog_handle != NULL) { fprintf(stderr, "Update trial endtime\n"); - dhtlog_handle->update_trial (trialuid, gets_completed); + dhtlog_handle->update_trial (gets_completed); GNUNET_DHTLOG_disconnect(dhtlog_handle); dhtlog_handle = NULL; } @@ -1736,6 +1805,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) get_delay, GNUNET_BLOCK_TYPE_TEST, &known_keys[test_get->uid], + get_replication, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, @@ -1844,6 +1914,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) outstanding_puts++; GNUNET_DHT_put(test_put->dht_handle, &known_keys[test_put->uid], + put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, sizeof(data), data, @@ -2303,7 +2374,7 @@ topology_callback (void *cls, #endif if (dhtlog_handle != NULL) { - dhtlog_handle->update_connections (trialuid, total_connections); + dhtlog_handle->update_connections (total_connections); dhtlog_handle->insert_topology(expected_connections); } diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index b7dcb6a56..593009fa2 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c @@ -185,6 +185,7 @@ run (void *cls, timeout, query_type, &key, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index 469675409..54c915c15 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c @@ -151,6 +151,7 @@ run (void *cls, query_key, data); GNUNET_DHT_put (dht_handle, &key, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, query_type, strlen (data), data, diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 714ba4753..810997e4c 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -20,7 +20,7 @@ /** * @file dht/gnunet-service-dht.c - * @brief main DHT service shell, building block for DHT implementations + * @brief GNUnet DHT service * @author Christian Grothoff * @author Nathan Evans */ @@ -107,11 +107,6 @@ */ #define DHT_DEFAULT_FIND_PEER_IMPORTANCE 8 -/** - * Default replication parameter for find peer messages sent by the dht service. - */ -#define DHT_DEFAULT_PUT_REPLICATION 4 - /** * Default replication parameter for find peer messages sent by the dht service. */ @@ -1716,7 +1711,7 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PeerInfo *peer = cls; struct GNUNET_MessageHeader ping_message; - struct DHT_MessageContext message_context; + struct DHT_MessageContext msg_ctx; if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return; @@ -1724,11 +1719,11 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ping_message.size = htons(sizeof(struct GNUNET_MessageHeader)); ping_message.type = htons(GNUNET_MESSAGE_TYPE_DHT_P2P_PING); - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); #if DEBUG_PING GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n", my_short_id, "DHT", GNUNET_i2s(&peer->id)); #endif - forward_message(&ping_message, peer, &message_context); + forward_message(&ping_message, peer, &msg_ctx); peer->ping_task = GNUNET_SCHEDULER_add_delayed(DHT_DEFAULT_PING_DELAY, &periodic_ping_task, peer); } @@ -1958,13 +1953,13 @@ static int consider_peer (struct GNUNET_PeerIdentity *peer) * message to other peers, or to send to our local client. * * @param msg the result message to be routed - * @param message_context context of the message we are routing + * @param msg_ctx context of the message we are routing * * @return the number of peers the message was routed to, * GNUNET_SYSERR on failure */ static int route_result_message(struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { struct GNUNET_PeerIdentity new_peer; struct DHTQueryRecord *record; @@ -2005,32 +2000,32 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, if (malicious_dropper == GNUNET_YES) record = NULL; else - record = GNUNET_CONTAINER_multihashmap_get(forward_list.hashmap, &message_context->key); + record = GNUNET_CONTAINER_multihashmap_get(forward_list.hashmap, &msg_ctx->key); if (record == NULL) /* No record of this message! */ { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Have no record of response key %s uid %llu\n", my_short_id, - "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id); + "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id); #endif #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { dhtlog_handle->insert_route (NULL, - message_context->unique_id, + msg_ctx->unique_id, DHTLOG_RESULT, - message_context->hop_count, + msg_ctx->hop_count, GNUNET_SYSERR, &my_identity, - &message_context->key, - message_context->peer, NULL); + &msg_ctx->key, + msg_ctx->peer, NULL); } #endif - if (message_context->bloom != NULL) + if (msg_ctx->bloom != NULL) { - GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); - message_context->bloom = NULL; + GNUNET_CONTAINER_bloomfilter_free(msg_ctx->bloom); + msg_ctx->bloom = NULL; } return 0; } @@ -2057,15 +2052,15 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Sending response key %s uid %llu to client\n", my_short_id, - "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id); + "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id); #endif #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_RESULT, - message_context->hop_count, - GNUNET_YES, &my_identity, &message_context->key, - message_context->peer, NULL); + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT, + msg_ctx->hop_count, + GNUNET_YES, &my_identity, &msg_ctx->key, + msg_ctx->peer, NULL); } #endif increment_stats(STAT_RESULTS_TO_CLIENT); @@ -2073,8 +2068,8 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, increment_stats(STAT_GET_REPLY); send_reply_to_client(pos->client, msg, - message_context->unique_id, - &message_context->key); + msg_ctx->unique_id, + &msg_ctx->key); } else /* Send to peer */ { @@ -2085,41 +2080,41 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, continue; } - if (message_context->bloom == NULL) - message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); - GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); - if ((GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (message_context->bloom, &peer_info->id.hashPubKey))) + if (msg_ctx->bloom == NULL) + msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); + GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom, &my_identity.hashPubKey); + if ((GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom, &peer_info->id.hashPubKey))) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Forwarding response key %s uid %llu to peer %s\n", my_short_id, - "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); + "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id, GNUNET_i2s(&peer_info->id)); #endif #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT, - message_context->hop_count, - GNUNET_NO, &my_identity, &message_context->key, - message_context->peer, &pos->source); + msg_ctx->hop_count, + GNUNET_NO, &my_identity, &msg_ctx->key, + msg_ctx->peer, &pos->source); } #endif - forward_result_message(msg, peer_info, message_context); + forward_result_message(msg, peer_info, msg_ctx); } else { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n", my_short_id, - "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); + "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id, GNUNET_i2s(&peer_info->id)); #endif } } pos = pos->next; } - if (message_context->bloom != NULL) - GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); + if (msg_ctx->bloom != NULL) + GNUNET_CONTAINER_bloomfilter_free(msg_ctx->bloom); return 0; } @@ -2179,7 +2174,7 @@ datacache_get_iterator (void *cls, new_msg_ctx->peer = &my_identity; new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); new_msg_ctx->hop_count = 0; - new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */ + new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */ new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; increment_stats(STAT_GET_RESPONSE_START); route_result_message(&get_result->header, new_msg_ctx); @@ -2226,11 +2221,11 @@ datacache_get_iterator (void *cls, * peers. * * @param msg the message to be routed - * @param message_context the context containing all pertinent information about the message + * @param msg_ctx the context containing all pertinent information about the message */ static void route_message(const struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context); + struct DHT_MessageContext *msg_ctx); /** @@ -2238,13 +2233,13 @@ route_message(const struct GNUNET_MessageHeader *msg, * if found, send response either to clients or other peers. * * @param msg the actual get message - * @param message_context struct containing pertinent information about the get request + * @param msg_ctx struct containing pertinent information about the get request * * @return number of items found for GET request */ static unsigned int handle_dht_get (const struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { const struct GNUNET_DHT_GetMessage *get_msg; uint16_t msize; @@ -2261,30 +2256,30 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg, } get_msg = (const struct GNUNET_DHT_GetMessage *) msg; bf_size = ntohs (get_msg->bf_size); - message_context->xquery_size = ntohs (get_msg->xquery_size); - message_context->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */ - if (msize != sizeof (struct GNUNET_DHT_GetMessage) + bf_size + message_context->xquery_size) + msg_ctx->xquery_size = ntohs (get_msg->xquery_size); + msg_ctx->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */ + if (msize != sizeof (struct GNUNET_DHT_GetMessage) + bf_size + msg_ctx->xquery_size) { GNUNET_break (0); return 0; } end = (const char*) &get_msg[1]; - if (message_context->xquery_size == 0) + if (msg_ctx->xquery_size == 0) { - message_context->xquery = NULL; + msg_ctx->xquery = NULL; } else { - message_context->xquery = (const void*) end; - end += message_context->xquery_size; + msg_ctx->xquery = (const void*) end; + end += msg_ctx->xquery_size; } if (bf_size == 0) { - message_context->reply_bf = NULL; + msg_ctx->reply_bf = NULL; } else { - message_context->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end, + msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end, bf_size, GNUNET_DHT_GET_BLOOMFILTER_K); } @@ -2295,45 +2290,45 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg, my_short_id, "DHT", "GET", type, - GNUNET_h2s (&message_context->key), - message_context->unique_id); + GNUNET_h2s (&msg_ctx->key), + msg_ctx->unique_id); #endif increment_stats(STAT_GETS); results = 0; #if HAVE_MALICIOUS if (type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE) { - GNUNET_CONTAINER_bloomfilter_free (message_context->reply_bf); + GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf); return results; } #endif - message_context->do_forward = GNUNET_YES; + msg_ctx->do_forward = GNUNET_YES; if (datacache != NULL) results = GNUNET_DATACACHE_get (datacache, - &message_context->key, type, + &msg_ctx->key, type, &datacache_get_iterator, - message_context); + msg_ctx); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Found %d results for `%s' request uid %llu\n", my_short_id, "DHT", - results, "GET", message_context->unique_id); + results, "GET", msg_ctx->unique_id); #endif if (results >= 1) { #if DEBUG_DHT_ROUTING if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_GET, - message_context->hop_count, GNUNET_YES, &my_identity, - &message_context->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, + msg_ctx->hop_count, GNUNET_YES, &my_identity, + &msg_ctx->key); } if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_ROUTE, - message_context->hop_count, GNUNET_YES, - &my_identity, &message_context->key, message_context->peer, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, + msg_ctx->hop_count, GNUNET_YES, + &my_identity, &msg_ctx->key, msg_ctx->peer, NULL); } #endif @@ -2344,32 +2339,32 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg, if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID == GNUNET_BLOCK_evaluate (block_context, type, - &message_context->key, - &message_context->reply_bf, - message_context->reply_bf_mutator, - message_context->xquery, - message_context->xquery_size, + &msg_ctx->key, + &msg_ctx->reply_bf, + msg_ctx->reply_bf_mutator, + msg_ctx->xquery, + msg_ctx->xquery_size, NULL, 0)) { GNUNET_break_op (0); - message_context->do_forward = GNUNET_NO; + msg_ctx->do_forward = GNUNET_NO; } } - if (message_context->hop_count == 0) /* Locally initiated request */ + if (msg_ctx->hop_count == 0) /* Locally initiated request */ { #if DEBUG_DHT_ROUTING if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_GET, - message_context->hop_count, GNUNET_NO, &my_identity, - &message_context->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, + msg_ctx->hop_count, GNUNET_NO, &my_identity, + &msg_ctx->key); } #endif } - if (message_context->do_forward == GNUNET_YES) - route_message (msg, message_context); - GNUNET_CONTAINER_bloomfilter_free (message_context->reply_bf); + if (msg_ctx->do_forward == GNUNET_YES) + route_message (msg, msg_ctx); + GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf); return results; } @@ -2386,12 +2381,12 @@ remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc * Server handler for initiating local dht find peer requests * * @param find_msg the actual find peer message - * @param message_context struct containing pertinent information about the request + * @param msg_ctx struct containing pertinent information about the request * */ static void handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { struct GNUNET_MessageHeader *find_peer_result; struct GNUNET_DHT_FindPeerMessage *find_peer_message; @@ -2427,13 +2422,13 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, increment_stats(STAT_HELLOS_PROVIDED); GNUNET_TRANSPORT_offer_hello(transport_handle, other_hello); GNUNET_CORE_peer_request_connect(cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &peer_id, NULL, NULL); - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); GNUNET_free (other_hello); return; } else /* We don't want this peer! */ { - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); GNUNET_free (other_hello); return; } @@ -2443,7 +2438,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", - my_short_id, "DHT", "FIND PEER", GNUNET_h2s (&message_context->key), + my_short_id, "DHT", "FIND PEER", GNUNET_h2s (&msg_ctx->key), ntohs (find_msg->size), sizeof (struct GNUNET_MessageHeader)); #endif @@ -2455,7 +2450,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, "DHT"); #endif GNUNET_free_non_null (other_hello); - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); return; } @@ -2465,7 +2460,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, increment_stats(STAT_BLOOM_FIND_PEER); GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); GNUNET_free_non_null(other_hello); - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ } GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); @@ -2475,7 +2470,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, /** * Ignore any find peer requests from a peer we have seen very recently. */ - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent_find_peer_requests, &message_context->key)) /* We have recently responded to a find peer request for this peer! */ + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent_find_peer_requests, &msg_ctx->key)) /* We have recently responded to a find peer request for this peer! */ { increment_stats("# dht find peer requests ignored (recently seen!)"); GNUNET_free_non_null(other_hello); @@ -2490,23 +2485,23 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, * the network and has no other peers this is a problem (assume all buckets * full, no one will respond!). */ - memcpy(&peer_id.hashPubKey, &message_context->key, sizeof(GNUNET_HashCode)); + memcpy(&peer_id.hashPubKey, &msg_ctx->key, sizeof(GNUNET_HashCode)); if (GNUNET_NO == consider_peer(&peer_id)) { increment_stats("# dht find peer requests ignored (do not need!)"); GNUNET_free_non_null(other_hello); - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); return; } #endif recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); - memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); + memcpy(recent_hash, &msg_ctx->key, sizeof(GNUNET_HashCode)); if (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, - &message_context->key, NULL, + &msg_ctx->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding recent remove task for key `%s`!\n", GNUNET_h2s(&message_context->key)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding recent remove task for key `%s`!\n", GNUNET_h2s(&msg_ctx->key)); /* Only add a task if there wasn't one for this key already! */ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), &remove_recent_find_peer, recent_hash); @@ -2538,11 +2533,11 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, "DHT", hello_size); new_msg_ctx = GNUNET_malloc(sizeof(struct DHT_MessageContext)); - memcpy(new_msg_ctx, message_context, sizeof(struct DHT_MessageContext)); + memcpy(new_msg_ctx, msg_ctx, sizeof(struct DHT_MessageContext)); new_msg_ctx->peer = &my_identity; new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); new_msg_ctx->hop_count = 0; - new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make find peer requests a higher priority */ + new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make find peer requests a higher priority */ new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; increment_stats(STAT_FIND_PEER_ANSWER); route_result_message(find_peer_result, new_msg_ctx); @@ -2550,14 +2545,14 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, #if DEBUG_DHT_ROUTING if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_FIND_PEER, - message_context->hop_count, GNUNET_YES, &my_identity, - &message_context->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER, + msg_ctx->hop_count, GNUNET_YES, &my_identity, + &msg_ctx->key); } #endif GNUNET_free_non_null(other_hello); GNUNET_free(find_peer_result); - route_message (find_msg, message_context); + route_message (find_msg, msg_ctx); } /** @@ -2574,11 +2569,11 @@ republish_content(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); * Server handler for initiating local dht put requests * * @param msg the actual put message - * @param message_context struct containing pertinent information about the request + * @param msg_ctx struct containing pertinent information about the request */ static void handle_dht_put (const struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { const struct GNUNET_DHT_PutMessage *put_msg; enum GNUNET_BLOCK_Type put_type; @@ -2611,7 +2606,7 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, } if ( (GNUNET_YES == ret) && (0 != memcmp (&key, - &message_context->key, + &msg_ctx->key, sizeof (GNUNET_HashCode))) ) { /* invalid wrapper: key mismatch! */ @@ -2623,60 +2618,60 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", - my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&message_context->key), message_context->unique_id); + my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id); #endif #if DEBUG_DHT_ROUTING - if (message_context->hop_count == 0) /* Locally initiated request */ + if (msg_ctx->hop_count == 0) /* Locally initiated request */ { if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_PUT, - message_context->hop_count, GNUNET_NO, &my_identity, - &message_context->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, + msg_ctx->hop_count, GNUNET_NO, &my_identity, + &msg_ctx->key); } } #endif - if (message_context->closest != GNUNET_YES) + if (msg_ctx->closest != GNUNET_YES) { - route_message (msg, message_context); + route_message (msg, msg_ctx); return; } #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", - my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&message_context->key), message_context->unique_id); + my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id); #endif #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_ROUTE, - message_context->hop_count, GNUNET_YES, - &my_identity, &message_context->key, message_context->peer, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, + msg_ctx->hop_count, GNUNET_YES, + &my_identity, &msg_ctx->key, msg_ctx->peer, NULL); } if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_PUT, - message_context->hop_count, GNUNET_YES, &my_identity, - &message_context->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, + msg_ctx->hop_count, GNUNET_YES, &my_identity, + &msg_ctx->key); } #endif increment_stats(STAT_PUTS_INSERTED); if (datacache != NULL) { - ret = GNUNET_DATACACHE_put (datacache, &message_context->key, data_size, + ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, data_size, (char *) &put_msg[1], put_type, GNUNET_TIME_absolute_ntoh(put_msg->expiration)); if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES)) { put_context = GNUNET_malloc(sizeof(struct RepublishContext)); - memcpy(&put_context->key, &message_context->key, sizeof(GNUNET_HashCode)); + memcpy(&put_context->key, &msg_ctx->key, sizeof(GNUNET_HashCode)); put_context->type = put_type; GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, &republish_content, put_context); } @@ -2687,7 +2682,7 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, my_short_id, "DHT", "PUT"); if (stop_on_closest == GNUNET_NO) - route_message (msg, message_context); + route_message (msg, msg_ctx); } /** @@ -3436,11 +3431,11 @@ static int cache_response(struct DHT_MessageContext *msg_ctx) * peers. * * @param msg the message to be routed - * @param message_context the context containing all pertinent information about the message + * @param msg_ctx the context containing all pertinent information about the message */ static void route_message(const struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { int i; struct PeerInfo *selected; @@ -3461,29 +3456,26 @@ route_message(const struct GNUNET_MessageHeader *msg, #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_ROUTE, - message_context->hop_count, GNUNET_SYSERR, - &my_identity, &message_context->key, message_context->peer, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, + msg_ctx->hop_count, GNUNET_SYSERR, + &my_identity, &msg_ctx->key, msg_ctx->peer, NULL); } #endif - if (message_context->bloom != NULL) - GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); + if (msg_ctx->bloom != NULL) + GNUNET_CONTAINER_bloomfilter_free(msg_ctx->bloom); return; } increment_stats(STAT_ROUTES); - /* Semantics of this call means we find whether we are the closest peer out of those already - * routed to on this messages path. - */ - forward_count = get_forward_count(message_context->hop_count, message_context->replication); + forward_count = get_forward_count(msg_ctx->hop_count, msg_ctx->replication); GNUNET_asprintf(&stat_forward_count, "# forward counts of %d", forward_count); increment_stats(stat_forward_count); GNUNET_free(stat_forward_count); - if (message_context->bloom == NULL) - message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); + if (msg_ctx->bloom == NULL) + msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); - if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) + if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) forward_count = 0; /** @@ -3501,7 +3493,7 @@ route_message(const struct GNUNET_MessageHeader *msg, * testing driver) we will ignore this restriction for FIND_PEER messages so that * routing tables still get constructed. */ - if ((GNUNET_YES == strict_kademlia) && (message_context->closest == GNUNET_YES) && (message_context->hop_count > 0) && (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) + if ((GNUNET_YES == strict_kademlia) && (msg_ctx->closest == GNUNET_YES) && (msg_ctx->hop_count > 0) && (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) forward_count = 0; #if DEBUG_DHT_ROUTING @@ -3512,33 +3504,33 @@ route_message(const struct GNUNET_MessageHeader *msg, if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_ROUTE, - message_context->hop_count, ret, - &my_identity, &message_context->key, message_context->peer, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, + msg_ctx->hop_count, ret, + &my_identity, &msg_ctx->key, msg_ctx->peer, NULL); } #endif - GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); - hash_from_uid (message_context->unique_id, &unique_hash); + GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom, &my_identity.hashPubKey); + hash_from_uid (msg_ctx->unique_id, &unique_hash); if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (recent.hashmap, &unique_hash)) { recent_req = GNUNET_CONTAINER_multihashmap_get(recent.hashmap, &unique_hash); GNUNET_assert(recent_req != NULL); - if (0 != memcmp(&recent_req->key, &message_context->key, sizeof(GNUNET_HashCode))) + if (0 != memcmp(&recent_req->key, &msg_ctx->key, sizeof(GNUNET_HashCode))) increment_stats(STAT_DUPLICATE_UID); else { increment_stats(STAT_RECENT_SEEN); - GNUNET_CONTAINER_bloomfilter_or2(message_context->bloom, recent_req->bloom, DHT_BLOOM_SIZE); + GNUNET_CONTAINER_bloomfilter_or2(msg_ctx->bloom, recent_req->bloom, DHT_BLOOM_SIZE); } } else { recent_req = GNUNET_malloc(sizeof(struct RecentRequest)); - recent_req->uid = message_context->unique_id; - memcpy(&recent_req->key, &message_context->key, sizeof(GNUNET_HashCode)); + recent_req->uid = msg_ctx->unique_id; + memcpy(&recent_req->key, &msg_ctx->key, sizeof(GNUNET_HashCode)); recent_req->remove_task = GNUNET_SCHEDULER_add_delayed(DEFAULT_RECENT_REMOVAL, &remove_recent, recent_req); recent_req->heap_node = GNUNET_CONTAINER_heap_insert(recent.minHeap, recent_req, GNUNET_TIME_absolute_get().abs_value); recent_req->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); @@ -3555,45 +3547,45 @@ route_message(const struct GNUNET_MessageHeader *msg, for (i = 0; i < forward_count; i++) { - selected = select_peer(&message_context->key, message_context->bloom, message_context->hop_count); + selected = select_peer(&msg_ctx->key, msg_ctx->bloom, msg_ctx->hop_count); if (selected != NULL) { - if (GNUNET_CRYPTO_hash_matching_bits(&selected->id.hashPubKey, &message_context->key) >= GNUNET_CRYPTO_hash_matching_bits(&my_identity.hashPubKey, &message_context->key)) - GNUNET_asprintf(&temp_stat_str, "# requests routed to close(r) peer hop %u", message_context->hop_count); + if (GNUNET_CRYPTO_hash_matching_bits(&selected->id.hashPubKey, &msg_ctx->key) >= GNUNET_CRYPTO_hash_matching_bits(&my_identity.hashPubKey, &msg_ctx->key)) + GNUNET_asprintf(&temp_stat_str, "# requests routed to close(r) peer hop %u", msg_ctx->hop_count); else - GNUNET_asprintf(&temp_stat_str, "# requests routed to less close peer hop %u", message_context->hop_count); + GNUNET_asprintf(&temp_stat_str, "# requests routed to less close peer hop %u", msg_ctx->hop_count); if (temp_stat_str != NULL) { increment_stats(temp_stat_str); GNUNET_free(temp_stat_str); } - GNUNET_CONTAINER_bloomfilter_add(message_context->bloom, &selected->id.hashPubKey); + GNUNET_CONTAINER_bloomfilter_add(msg_ctx->bloom, &selected->id.hashPubKey); #if DEBUG_DHT_ROUTING > 1 - nearest = find_closest_peer(&message_context->key); + nearest = find_closest_peer(&msg_ctx->key); nearest_buf = GNUNET_strdup(GNUNET_i2s(&nearest->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", my_short_id, - "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&selected->id), nearest_buf, GNUNET_CRYPTO_hash_matching_bits(&nearest->id.hashPubKey, message_context->key), distance(&nearest->id.hashPubKey, message_context->key)); + "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id, GNUNET_i2s(&selected->id), nearest_buf, GNUNET_CRYPTO_hash_matching_bits(&nearest->id.hashPubKey, msg_ctx->key), distance(&nearest->id.hashPubKey, msg_ctx->key)); GNUNET_free(nearest_buf); #endif #if DEBUG_DHT_ROUTING if ((debug_routes_extended) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_route (NULL, message_context->unique_id, DHTLOG_ROUTE, - message_context->hop_count, GNUNET_NO, - &my_identity, &message_context->key, message_context->peer, + dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, + msg_ctx->hop_count, GNUNET_NO, + &my_identity, &msg_ctx->key, msg_ctx->peer, &selected->id); } #endif - forward_message(msg, selected, message_context); + forward_message(msg, selected, msg_ctx); } } - if (message_context->bloom != NULL) + if (msg_ctx->bloom != NULL) { - GNUNET_CONTAINER_bloomfilter_or2(recent_req->bloom, message_context->bloom, DHT_BLOOM_SIZE); - GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); + GNUNET_CONTAINER_bloomfilter_or2(recent_req->bloom, msg_ctx->bloom, DHT_BLOOM_SIZE); + GNUNET_CONTAINER_bloomfilter_free(msg_ctx->bloom); } } @@ -3604,42 +3596,42 @@ route_message(const struct GNUNET_MessageHeader *msg, * peers. * * @param msg the message to be routed - * @param message_context the context containing all pertinent information about the message + * @param msg_ctx the context containing all pertinent information about the message */ static void demultiplex_message(const struct GNUNET_MessageHeader *msg, - struct DHT_MessageContext *message_context) + struct DHT_MessageContext *msg_ctx) { - message_context->closest = am_closest_peer(&message_context->key, NULL); + msg_ctx->closest = am_closest_peer(&msg_ctx->key, NULL); switch (ntohs(msg->type)) { case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */ - cache_response (message_context); - handle_dht_get (msg, message_context); + cache_response (msg_ctx); + handle_dht_get (msg, msg_ctx); break; case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. */ increment_stats(STAT_PUTS); - handle_dht_put (msg, message_context); + handle_dht_put (msg, msg_ctx); break; case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ increment_stats(STAT_FIND_PEER); - if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL)) + if (((msg_ctx->hop_count > 0) && (0 != memcmp(msg_ctx->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (msg_ctx->client != NULL)) { - cache_response (message_context); - if ((message_context->closest == GNUNET_YES) || (message_context->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) - handle_dht_find_peer (msg, message_context); + cache_response (msg_ctx); + if ((msg_ctx->closest == GNUNET_YES) || (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) + handle_dht_find_peer (msg, msg_ctx); } else - route_message (msg, message_context); + route_message (msg, msg_ctx); #if DEBUG_DHT_ROUTING - if (message_context->hop_count == 0) /* Locally initiated request */ + if (msg_ctx->hop_count == 0) /* Locally initiated request */ { if ((debug_routes) && (dhtlog_handle != NULL)) { - dhtlog_handle->insert_dhtkey(NULL, &message_context->key); - dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_FIND_PEER, - message_context->hop_count, GNUNET_NO, &my_identity, - &message_context->key); + dhtlog_handle->insert_dhtkey(NULL, &msg_ctx->key); + dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER, + msg_ctx->hop_count, GNUNET_NO, &my_identity, + &msg_ctx->key); } } #endif @@ -3647,7 +3639,7 @@ demultiplex_message(const struct GNUNET_MessageHeader *msg, default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "`%s': Message type (%d) not handled, forwarding anyway!\n", "DHT", ntohs(msg->type)); - route_message (msg, message_context); + route_message (msg, msg_ctx); } } @@ -3690,7 +3682,7 @@ republish_content_iterator (void *cls, put_msg->type = htons (type); memcpy (&put_msg[1], data, size); new_msg_ctx->unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1)); - new_msg_ctx->replication = ntohl (DHT_DEFAULT_PUT_REPLICATION); + new_msg_ctx->replication = ntohl (DEFAULT_PUT_REPLICATION); new_msg_ctx->msg_options = ntohl (0); new_msg_ctx->network_size = estimate_diameter(); new_msg_ctx->peer = &my_identity; @@ -3861,7 +3853,7 @@ static void malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { static struct GNUNET_DHT_PutMessage put_message; - static struct DHT_MessageContext message_context; + static struct DHT_MessageContext msg_ctx; static GNUNET_HashCode key; uint32_t random_key; @@ -3871,24 +3863,24 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) put_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_PUT); put_message.type = htonl(GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE); put_message.expiration = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_forever()); - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); random_key = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1); GNUNET_CRYPTO_hash(&random_key, sizeof(uint32_t), &key); - memcpy(&message_context.key, &key, sizeof(GNUNET_HashCode)); - message_context.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1)); - message_context.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); - message_context.msg_options = ntohl (0); - message_context.network_size = estimate_diameter(); - message_context.peer = &my_identity; - message_context.importance = DHT_DEFAULT_P2P_IMPORTANCE; /* Make result routing a higher priority */ - message_context.timeout = DHT_DEFAULT_P2P_TIMEOUT; + memcpy(&msg_ctx.key, &key, sizeof(GNUNET_HashCode)); + msg_ctx.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1)); + msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); + msg_ctx.msg_options = ntohl (0); + msg_ctx.network_size = estimate_diameter(); + msg_ctx.peer = &my_identity; + msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE; + msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; #if DEBUG_DHT_ROUTING if (dhtlog_handle != NULL) dhtlog_handle->insert_dhtkey(NULL, &key); #endif increment_stats(STAT_PUT_START); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s Sending malicious PUT message with hash %s\n", my_short_id, "DHT", GNUNET_h2s(&key)); - demultiplex_message(&put_message.header, &message_context); + demultiplex_message(&put_message.header, &msg_ctx); GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, malicious_put_frequency), &malicious_put_task, NULL); } @@ -3903,7 +3895,7 @@ static void malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { static struct GNUNET_DHT_GetMessage get_message; - struct DHT_MessageContext message_context; + struct DHT_MessageContext msg_ctx; static GNUNET_HashCode key; uint32_t random_key; @@ -3913,24 +3905,24 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) get_message.header.size = htons(sizeof(struct GNUNET_DHT_GetMessage)); get_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET); get_message.type = htonl(GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE); - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); random_key = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1); GNUNET_CRYPTO_hash(&random_key, sizeof(uint32_t), &key); - memcpy(&message_context.key, &key, sizeof(GNUNET_HashCode)); - message_context.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1)); - message_context.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); - message_context.msg_options = ntohl (0); - message_context.network_size = estimate_diameter(); - message_context.peer = &my_identity; - message_context.importance = DHT_DEFAULT_P2P_IMPORTANCE; /* Make result routing a higher priority */ - message_context.timeout = DHT_DEFAULT_P2P_TIMEOUT; + memcpy(&msg_ctx.key, &key, sizeof(GNUNET_HashCode)); + msg_ctx.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1)); + msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); + msg_ctx.msg_options = ntohl (0); + msg_ctx.network_size = estimate_diameter(); + msg_ctx.peer = &my_identity; + msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE; + msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; #if DEBUG_DHT_ROUTING if (dhtlog_handle != NULL) dhtlog_handle->insert_dhtkey(NULL, &key); #endif increment_stats(STAT_GET_START); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s Sending malicious GET message with hash %s\n", my_short_id, "DHT", GNUNET_h2s(&key)); - demultiplex_message (&get_message.header, &message_context); + demultiplex_message (&get_message.header, &msg_ctx); GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, malicious_get_frequency), &malicious_get_task, NULL); } #endif @@ -3968,7 +3960,7 @@ static void send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_DHT_FindPeerMessage *find_peer_msg; - struct DHT_MessageContext message_context; + struct DHT_MessageContext msg_ctx; struct GNUNET_TIME_Relative next_send_time; struct GNUNET_CONTAINER_BloomFilter *temp_bloom; #if COUNT_INTERVAL @@ -4018,17 +4010,17 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc temp_bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); GNUNET_CONTAINER_multihashmap_iterate(all_known_peers, &add_known_to_bloom, temp_bloom); GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_bloomfilter_get_raw_data(temp_bloom, find_peer_msg->bloomfilter, DHT_BLOOM_SIZE)); - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); - memcpy(&message_context.key, &my_identity.hashPubKey, sizeof(GNUNET_HashCode)); - message_context.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, (uint64_t)-1)); - message_context.replication = DHT_DEFAULT_FIND_PEER_REPLICATION; - message_context.msg_options = DHT_DEFAULT_FIND_PEER_OPTIONS; - message_context.network_size = estimate_diameter(); - message_context.peer = &my_identity; - message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; - message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; - - demultiplex_message(&find_peer_msg->header, &message_context); + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); + memcpy(&msg_ctx.key, &my_identity.hashPubKey, sizeof(GNUNET_HashCode)); + msg_ctx.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, (uint64_t)-1)); + msg_ctx.replication = DHT_DEFAULT_FIND_PEER_REPLICATION; + msg_ctx.msg_options = DHT_DEFAULT_FIND_PEER_OPTIONS; + msg_ctx.network_size = estimate_diameter(); + msg_ctx.peer = &my_identity; + msg_ctx.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; + msg_ctx.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; + + demultiplex_message(&find_peer_msg->header, &msg_ctx); GNUNET_free(find_peer_msg); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id, "DHT", @@ -4072,7 +4064,7 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client, { const struct GNUNET_DHT_RouteMessage *dht_msg = (const struct GNUNET_DHT_RouteMessage *) message; const struct GNUNET_MessageHeader *enc_msg; - struct DHT_MessageContext message_context; + struct DHT_MessageContext msg_ctx; enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1]; #if DEBUG_DHT @@ -4089,16 +4081,16 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client, if (dhtlog_handle != NULL) dhtlog_handle->insert_dhtkey (NULL, &dht_msg->key); #endif - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); - message_context.client = find_active_client (client); - memcpy(&message_context.key, &dht_msg->key, sizeof(GNUNET_HashCode)); - message_context.unique_id = GNUNET_ntohll (dht_msg->unique_id); - message_context.replication = ntohl (dht_msg->desired_replication_level); - message_context.msg_options = ntohl (dht_msg->options); - message_context.network_size = estimate_diameter(); - message_context.peer = &my_identity; - message_context.importance = DHT_DEFAULT_P2P_IMPORTANCE * 4; /* Make local routing a higher priority */ - message_context.timeout = DHT_DEFAULT_P2P_TIMEOUT; + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); + msg_ctx.client = find_active_client (client); + memcpy(&msg_ctx.key, &dht_msg->key, sizeof(GNUNET_HashCode)); + msg_ctx.unique_id = GNUNET_ntohll (dht_msg->unique_id); + msg_ctx.replication = ntohl (dht_msg->desired_replication_level); + msg_ctx.msg_options = ntohl (dht_msg->options); + msg_ctx.network_size = estimate_diameter(); + msg_ctx.peer = &my_identity; + msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing a higher priority */ + msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET) increment_stats(STAT_GET_START); else if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT) @@ -4106,7 +4098,7 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client, else if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER) increment_stats(STAT_FIND_PEER_START); - demultiplex_message(enc_msg, &message_context); + demultiplex_message(enc_msg, &msg_ctx); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -4242,7 +4234,7 @@ handle_dht_p2p_route_request (void *cls, #endif struct GNUNET_DHT_P2PRouteMessage *incoming = (struct GNUNET_DHT_P2PRouteMessage *)message; struct GNUNET_MessageHeader *enc_msg = (struct GNUNET_MessageHeader *)&incoming[1]; - struct DHT_MessageContext *message_context; + struct DHT_MessageContext *msg_ctx; if (get_max_send_delay().rel_value > MAX_REQUEST_TIME.rel_value) { @@ -4265,20 +4257,20 @@ handle_dht_p2p_route_request (void *cls, GNUNET_break_op(0); return GNUNET_YES; } - message_context = GNUNET_malloc(sizeof (struct DHT_MessageContext)); - message_context->bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); - GNUNET_assert(message_context->bloom != NULL); - message_context->hop_count = ntohl(incoming->hop_count); - memcpy(&message_context->key, &incoming->key, sizeof(GNUNET_HashCode)); - message_context->replication = ntohl(incoming->desired_replication_level); - message_context->unique_id = GNUNET_ntohll(incoming->unique_id); - message_context->msg_options = ntohl(incoming->options); - message_context->network_size = ntohl(incoming->network_size); - message_context->peer = peer; - message_context->importance = DHT_DEFAULT_P2P_IMPORTANCE; - message_context->timeout = DHT_DEFAULT_P2P_TIMEOUT; - demultiplex_message(enc_msg, message_context); - GNUNET_free(message_context); + msg_ctx = GNUNET_malloc(sizeof (struct DHT_MessageContext)); + msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); + GNUNET_assert(msg_ctx->bloom != NULL); + msg_ctx->hop_count = ntohl(incoming->hop_count); + memcpy(&msg_ctx->key, &incoming->key, sizeof(GNUNET_HashCode)); + msg_ctx->replication = ntohl(incoming->desired_replication_level); + msg_ctx->unique_id = GNUNET_ntohll(incoming->unique_id); + msg_ctx->msg_options = ntohl(incoming->options); + msg_ctx->network_size = ntohl(incoming->network_size); + msg_ctx->peer = peer; + msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE; + msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; + demultiplex_message(enc_msg, msg_ctx); + GNUNET_free(msg_ctx); return GNUNET_YES; } @@ -4298,7 +4290,7 @@ handle_dht_p2p_route_result (void *cls, #endif struct GNUNET_DHT_P2PRouteResultMessage *incoming = (struct GNUNET_DHT_P2PRouteResultMessage *)message; struct GNUNET_MessageHeader *enc_msg = (struct GNUNET_MessageHeader *)&incoming[1]; - struct DHT_MessageContext message_context; + struct DHT_MessageContext msg_ctx; if (ntohs(enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) { @@ -4306,18 +4298,18 @@ handle_dht_p2p_route_result (void *cls, return GNUNET_YES; } - memset(&message_context, 0, sizeof(struct DHT_MessageContext)); + memset(&msg_ctx, 0, sizeof(struct DHT_MessageContext)); // FIXME: call GNUNET_BLOCK_evaluate (...) -- instead of doing your own bloomfilter! - message_context.bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); - GNUNET_assert(message_context.bloom != NULL); - memcpy(&message_context.key, &incoming->key, sizeof(GNUNET_HashCode)); - message_context.unique_id = GNUNET_ntohll(incoming->unique_id); - message_context.msg_options = ntohl(incoming->options); - message_context.hop_count = ntohl(incoming->hop_count); - message_context.peer = peer; - message_context.importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */ - message_context.timeout = DHT_DEFAULT_P2P_TIMEOUT; - route_result_message(enc_msg, &message_context); + msg_ctx.bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); + GNUNET_assert(msg_ctx.bloom != NULL); + memcpy(&msg_ctx.key, &incoming->key, sizeof(GNUNET_HashCode)); + msg_ctx.unique_id = GNUNET_ntohll(incoming->unique_id); + msg_ctx.msg_options = ntohl(incoming->options); + msg_ctx.hop_count = ntohl(incoming->hop_count); + msg_ctx.peer = peer; + msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */ + msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; + route_result_message(enc_msg, &msg_ctx); return GNUNET_YES; } diff --git a/src/dht/plugin_dhtlog_dummy.c b/src/dht/plugin_dhtlog_dummy.c index 803ad92ac..3f3cd8de1 100644 --- a/src/dht/plugin_dhtlog_dummy.c +++ b/src/dht/plugin_dhtlog_dummy.c @@ -41,7 +41,6 @@ */ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) { - trial_info->trialuid = 42; return GNUNET_OK; } @@ -93,14 +92,12 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) /* * Update dhttests.trials table with current server time as end time * - * @param trialuid trial to update * @param gets_succeeded how many gets did the testcase report as successful * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -update_trials (unsigned long long trialuid, - unsigned int gets_succeeded) +update_trials (unsigned int gets_succeeded) { return GNUNET_OK; } @@ -127,13 +124,12 @@ add_generic_stat (const struct GNUNET_PeerIdentity *peer, /* * Update dhttests.trials table with total connections information * - * @param trialuid the trialuid to update * @param totalConnections the number of connections * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -add_connections (unsigned long long trialuid, unsigned int totalConnections) +add_connections (unsigned int totalConnections) { return GNUNET_OK; } diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c index 127db015d..5510163b0 100644 --- a/src/dht/plugin_dhtlog_mysql.c +++ b/src/dht/plugin_dhtlog_mysql.c @@ -850,7 +850,7 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) stmt = mysql_stmt_init(conn); if (GNUNET_OK != - (ret = prepared_statement_run (insert_trial, &trial_info->trialuid, + (ret = prepared_statement_run (insert_trial, ¤t_trial, MYSQL_TYPE_LONG, &trial_info->other_identifier, GNUNET_YES, MYSQL_TYPE_LONG, &trial_info->num_nodes, GNUNET_YES, MYSQL_TYPE_LONG, &trial_info->topology, GNUNET_YES, @@ -1149,14 +1149,12 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) /* * Update dhttests.trials table with current server time as end time * - * @param trialuid trial to update * @param gets_succeeded how many gets did the testcase report as successful * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -update_trials (unsigned long long trialuid, - unsigned int gets_succeeded) +update_trials (unsigned int gets_succeeded) { int ret; @@ -1164,7 +1162,7 @@ update_trials (unsigned long long trialuid, (ret = prepared_statement_run (update_trial, NULL, MYSQL_TYPE_LONG, &gets_succeeded, GNUNET_YES, - MYSQL_TYPE_LONGLONG, &trialuid, GNUNET_YES, + MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES, -1))) { if (ret == GNUNET_SYSERR) @@ -1215,13 +1213,12 @@ int set_malicious (struct GNUNET_PeerIdentity *peer) /* * Update dhttests.trials table with total connections information * - * @param trialuid the trialuid to update * @param totalConnections the number of connections * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -add_connections (unsigned long long trialuid, unsigned int totalConnections) +add_connections (unsigned int totalConnections) { int ret; @@ -1232,7 +1229,7 @@ add_connections (unsigned long long trialuid, unsigned int totalConnections) &totalConnections, GNUNET_YES, MYSQL_TYPE_LONGLONG, - &trialuid, GNUNET_YES, -1))) + ¤t_trial, GNUNET_YES, -1))) { if (ret == GNUNET_SYSERR) { diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c index 6b6133068..1e549d115 100644 --- a/src/dht/plugin_dhtlog_mysql_dump.c +++ b/src/dht/plugin_dhtlog_mysql_dump.c @@ -289,7 +289,7 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) { int ret; - trial_info->trialuid = 0; + if (outfile == NULL) return GNUNET_SYSERR; @@ -505,23 +505,14 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) /* * Update dhttests.trials table with current server time as end time * - * @param trialuid trial to update * @param gets_succeeded how many gets did the testcase report as successful * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -update_trials (unsigned long long trialuid, - unsigned int gets_succeeded) +update_trials (unsigned int gets_succeeded) { int ret; -#if DEBUG_DHTLOG -/* if (trialuid != current_trial) - { - fprintf (stderr, - _("Trialuid to update is not equal to current_trial\n")); - }*/ -#endif if (outfile == NULL) return GNUNET_SYSERR; @@ -573,22 +564,15 @@ set_malicious (struct GNUNET_PeerIdentity *peer) /* * Update dhttests.trials table with total connections information * - * @param trialuid the trialuid to update * @param totalConnections the number of connections * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -add_connections (unsigned long long trialuid, unsigned int totalConnections) +add_connections (unsigned int totalConnections) { int ret; -#if DEBUG_DHTLOG -/* if (trialuid != current_trial) - { - fprintf (stderr, - _("Trialuid to update is not equal to current_trial(!)(?)\n")); - }*/ -#endif + if (outfile == NULL) return GNUNET_SYSERR; diff --git a/src/dht/plugin_dhtlog_mysql_dump_load.c b/src/dht/plugin_dhtlog_mysql_dump_load.c index a5231d9eb..973b20908 100644 --- a/src/dht/plugin_dhtlog_mysql_dump_load.c +++ b/src/dht/plugin_dhtlog_mysql_dump_load.c @@ -167,7 +167,6 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) { int ret; - trial_info->trialuid = 0; if (outfile == NULL) return GNUNET_SYSERR; @@ -336,23 +335,14 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) /* * Update dhttests.trials table with current server time as end time * - * @param trialuid trial to update * @param gets_succeeded how many gets did the testcase report as successful * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -update_trials (unsigned long long trialuid, - unsigned int gets_succeeded) +update_trials (unsigned int gets_succeeded) { int ret; -#if DEBUG_DHTLOG -/* if (trialuid != current_trial) - { - fprintf (stderr, - _("Trialuid to update is not equal to current_trial\n")); - }*/ -#endif if (outfile == NULL) return GNUNET_SYSERR; @@ -394,22 +384,15 @@ set_malicious (struct GNUNET_PeerIdentity *peer) /* * Update dhttests.trials table with total connections information * - * @param trialuid the trialuid to update * @param totalConnections the number of connections * * @return GNUNET_OK on success, GNUNET_SYSERR on failure. */ int -add_connections (unsigned long long trialuid, unsigned int totalConnections) +add_connections (unsigned int totalConnections) { int ret; -#if DEBUG_DHTLOG -/* if (trialuid != current_trial) - { - fprintf (stderr, - _("Trialuid to update is not equal to current_trial(!)(?)\n")); - }*/ -#endif + if (outfile == NULL) return GNUNET_SYSERR; diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index de3d97647..b82d8cd7e 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -400,6 +400,7 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) TOTAL_TIMEOUT, GNUNET_BLOCK_TYPE_TEST, &hash, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, @@ -438,6 +439,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (peer->dht_handle != NULL); GNUNET_DHT_put (peer->dht_handle, &hash, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 9c18c4f2e..24618230a 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c @@ -447,6 +447,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_TEST, &key, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, @@ -515,6 +516,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) outstanding_puts++; GNUNET_DHT_put(test_put->dht_handle, &key, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, sizeof(data), data, diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 6f3d5060d..d5923dc11 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c @@ -220,7 +220,8 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) &stop_retry_get, get_context); get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - 0 /* fixme: use real type */, &get_context->peer->hashPubKey, + 0 /* FIXME: use real type */, &get_context->peer->hashPubKey, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, @@ -250,6 +251,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), GNUNET_BLOCK_TYPE_DHT_HELLO, &get_context->peer->hashPubKey, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 0f61f4930..8e10eea6b 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c @@ -239,6 +239,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), GNUNET_BLOCK_TYPE_TEST, &key, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, NULL, 0, @@ -272,6 +273,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) /* Insert the data at the first peer */ GNUNET_DHT_put(peer1dht, &key, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, sizeof(data), data, diff --git a/src/dht/test_dhtlog.c b/src/dht/test_dhtlog.c index 06e2db2c4..c8601b191 100644 --- a/src/dht/test_dhtlog.c +++ b/src/dht/test_dhtlog.c @@ -168,7 +168,7 @@ test (struct GNUNET_DHTLOG_Handle * api) #if VERBOSE fprintf(stderr, "Insert stat succeeded!\n"); #endif - ret = api->update_trial (trial_info.trialuid, 787); + ret = api->update_trial (787); CHECK(ret); #if VERBOSE fprintf(stderr, "Update trial succeeded!\n"); diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 1cb5432c7..fd4ec74ed 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -1341,6 +1341,7 @@ process_dht_put_content (void *cls, #endif GNUNET_DHT_put (dht_handle, key, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, type, size, @@ -2924,6 +2925,7 @@ forward_request_task (void *cls, GNUNET_TIME_UNIT_FOREVER_REL, pr->type, &pr->query, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, pr->bf, pr->mingle, diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 7ab818de7..18eab8a9f 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -51,6 +51,20 @@ extern "C" */ #define GNUNET_DHT_GET_BLOOMFILTER_K 16 +/** + * Non-intelligent default DHT GET replication. + * Should be chosen by application if anything about + * the network is known. + */ +#define DEFAULT_GET_REPLICATION 5 + +/** + * Non-intelligent default DHT PUT replication. + * Should be chosen by application if anything about + * the network is known. + */ +#define DEFAULT_PUT_REPLICATION 8 + /** * Connection to the DHT service. */ @@ -121,33 +135,34 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); /* *************** Standard API: get and put ******************* */ /** - * Perform a PUT operation on the DHT identified by 'table' storing - * a binding of 'key' to 'value'. The peer does not have to be part - * of the table (if so, we will attempt to locate a peer that is!) + * Perform a PUT operation storing data in the DHT. * * @param handle handle to DHT service - * @param key the key to store data under + * @param key the key to store under + * @param desired_replication_level estimate of how many + * nearest peers this request should reach * @param options routing options for this message * @param type type of the value * @param size number of bytes in data; must be less than 64k * @param data the data to store - * @param exp desired expiration time for the data - * @param timeout when to abort if we fail to transmit the request - * for the PUT to the local DHT service + * @param exp desired expiration time for the value + * @param timeout how long to wait for transmission of this request * @param cont continuation to call when done (transmitting request to service) * @param cont_cls closure for cont + * @return GNUNET_YES if put message is queued for transmission */ void GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, - enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const char *data, struct GNUNET_TIME_Absolute exp, struct GNUNET_TIME_Relative timeout, - GNUNET_SCHEDULER_Task cont, - void *cont_cls); + GNUNET_SCHEDULER_Task cont, + void *cont_cls); /** @@ -177,33 +192,36 @@ typedef void (*GNUNET_DHT_GetIterator)(void *cls, /** - * Perform an asynchronous GET operation on the DHT. See + * Perform an asynchronous GET operation on the DHT identified. See * also "GNUNET_BLOCK_evaluate". * * @param handle handle to the DHT service - * @param timeout timeout for this request to be sent to the - * service (this is NOT a timeout for receiving responses) - * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*) + * @param timeout how long to wait for transmission of this request to the service + * @param type expected type of the response object * @param key the key to look up + * @param desired_replication_level estimate of how many + nearest peers this request should reach * @param options routing options for this message * @param bf bloom filter associated with query (can be NULL) * @param bf_mutator mutation value for bf - * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery extended query data (can be NULL, depending on type) * @param xquery_size number of bytes in xquery * @param iter function to call on each result * @param iter_cls closure for iter - * @return handle to stop the async get, NULL on error + * + * @return handle to stop the async get */ struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, struct GNUNET_TIME_Relative timeout, enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, - enum GNUNET_DHT_RouteOption options, - const struct GNUNET_CONTAINER_BloomFilter *bf, - int32_t bf_mutator, - const void *xquery, - size_t xquery_size, + uint32_t desired_replication_level, + enum GNUNET_DHT_RouteOption options, + const struct GNUNET_CONTAINER_BloomFilter *bf, + int32_t bf_mutator, + const void *xquery, + size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls); @@ -212,6 +230,9 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, * Stop async DHT-get. Frees associated resources. * * @param get_handle GET operation to stop. + * + * On return get_handle will no longer be valid, caller + * must not use again!!! */ void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle); diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index d807df29b..3fd4db534 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -391,6 +391,7 @@ receive_query(void *cls, GNUNET_TIME_UNIT_MINUTES, GNUNET_BLOCK_TYPE_DNS, &key, + DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, 0, @@ -552,6 +553,7 @@ publish_name (void *cls, GNUNET_DHT_put(dht, &data.service_descriptor, + DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, -- 2.25.1