From 83b19539f4d322b43683f5838b72e9ec2c8e6073 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 4 Nov 2011 14:00:32 +0000 Subject: curly wars / auto-indentation --- src/dht/dht_api.c | 52 +- src/dht/gnunet-dht-get.c | 12 +- src/dht/gnunet-dht-put.c | 6 +- src/dht/gnunet-service-dht.c | 44 +- src/dht/gnunet-service-dht_clients.c | 491 +++++++--------- src/dht/gnunet-service-dht_clients.h | 17 +- src/dht/gnunet-service-dht_datacache.c | 121 ++-- src/dht/gnunet-service-dht_datacache.h | 28 +- src/dht/gnunet-service-dht_hello.c | 36 +- src/dht/gnunet-service-dht_neighbours.c | 982 ++++++++++++++----------------- src/dht/gnunet-service-dht_neighbours.h | 52 +- src/dht/gnunet-service-dht_nse.c | 10 +- src/dht/gnunet-service-dht_routing.c | 144 ++--- src/dht/gnunet-service-dht_routing.h | 27 +- src/dht/test_dht_2dtorus.c | 208 +++---- src/dht/test_dht_api.c | 16 +- src/dht/test_dht_multipeer.c | 210 +++---- src/dht/test_dht_twopeer.c | 30 +- src/dht/test_dht_twopeer_get_put.c | 22 +- src/dht/test_dht_twopeer_path_tracking.c | 24 +- src/dht/test_dht_twopeer_put_get.c | 21 +- 21 files changed, 1140 insertions(+), 1413 deletions(-) (limited to 'src/dht') diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 720e82a41..ac69b7a4e 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -249,12 +249,11 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) struct GNUNET_DHT_GetHandle *rh = value; if (GNUNET_NO == rh->message->in_pending_queue) - { + { #if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, - "Retransmitting request related to %s to DHT %p\n", - GNUNET_h2s (key), - handle); + "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key), + handle); #endif GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, rh->message); @@ -284,9 +283,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_DHT_Handle *handle = cls; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reconnecting with DHT %p\n", - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle); #endif handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) @@ -324,8 +321,8 @@ do_disconnect (struct GNUNET_DHT_Handle *handle) GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); handle->th = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from DHT service, will try to reconnect in %llu ms\n", - (unsigned long long) handle->retry_time.rel_value); + "Disconnecting from DHT service, will try to reconnect in %llu ms\n", + (unsigned long long) handle->retry_time.rel_value); GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); handle->client = NULL; handle->reconnect_task = @@ -351,7 +348,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) if (handle->client == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "process_pending_messages called, but client is null, reconnecting\n"); + "process_pending_messages called, but client is null, reconnecting\n"); do_disconnect (handle); return; } @@ -368,7 +365,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) if (NULL != handle->th) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "notify_transmit_ready returned NULL, reconnecting\n"); + "notify_transmit_ready returned NULL, reconnecting\n"); do_disconnect (handle); } @@ -432,7 +429,7 @@ transmit_pending (void *cls, size_t size, void *buf) #endif handle->in_receive = GNUNET_YES; GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TIME_UNIT_FOREVER_REL); } return tsize; } @@ -466,9 +463,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) { /* UID mismatch */ #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Ignoring reply for %s: UID mismatch: %llu/%llu\n", - GNUNET_h2s (key), + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key), dht_msg->unique_id, get_handle->unique_id); #endif return GNUNET_YES; @@ -490,10 +486,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) } data_length = msize - meta_length; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Giving %u byte reply for %s to application\n", - (unsigned int) data_length, - GNUNET_h2s (key)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", + (unsigned int) data_length, GNUNET_h2s (key)); #endif put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; get_path = &put_path[put_path_length]; @@ -542,10 +536,8 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) } dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received reply for `%s' from DHT service %p\n", - GNUNET_h2s (&dht_msg->key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n", + GNUNET_h2s (&dht_msg->key), handle); #endif GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, &dht_msg->key, &process_reply, @@ -641,7 +633,7 @@ timeout_put_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_DHT_Handle *handle; handle = pending->handle; - GNUNET_assert (GNUNET_YES == pending->in_pending_queue); + GNUNET_assert (GNUNET_YES == pending->in_pending_queue); GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, pending); pending->in_pending_queue = GNUNET_NO; @@ -752,10 +744,8 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, return NULL; } #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending query for %s to DHT %p\n", - GNUNET_h2s (key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n", + GNUNET_h2s (key), handle); #endif pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; @@ -803,10 +793,8 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) get_msg = (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending STOP for %s to DHT via %p\n", - GNUNET_h2s (&get_msg->key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n", + GNUNET_h2s (&get_msg->key), handle); #endif /* generate STOP */ pending = diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 8720e76aa..763ff8e6f 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c @@ -124,10 +124,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, (unsigned int) size, (char *) data); @@ -186,9 +186,9 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (absolute_timeout), &cleanup_task, NULL); get_handle = - GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, - replication, GNUNET_DHT_RO_NONE, NULL, - 0, &get_result_iterator, NULL); + GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, replication, + GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, + NULL); } diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index f165aa4a4..079a8866e 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c @@ -151,9 +151,9 @@ run (void *cls, char *const *args, const char *cfgfile, if (verbose) fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), query_key, data); - GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, - query_type, strlen (data), data, expiration, timeout, - &message_sent_cont, NULL); + GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, query_type, + strlen (data), data, expiration, timeout, &message_sent_cont, + NULL); } diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 3e0f3c8d9..72575acae 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -81,8 +81,7 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh; * @param message HELLO message of peer */ static void -process_hello (void *cls, - const struct GNUNET_MessageHeader *message) +process_hello (void *cls, const struct GNUNET_MessageHeader *message) { GNUNET_assert (message != NULL); GNUNET_free_non_null (GDS_my_hello); @@ -149,24 +148,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GDS_DATACACHE_init (); GDS_HELLO_init (); GDS_CLIENTS_init (server); - if (GNUNET_OK != - GDS_NEIGHBOURS_init ()) - { - shutdown_task (NULL, NULL); - return; - } - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &shutdown_task, NULL); + if (GNUNET_OK != GDS_NEIGHBOURS_init ()) + { + shutdown_task (NULL, NULL); + return; + } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + NULL); GDS_transport_handle = - GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); + GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); if (GDS_transport_handle == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to connect to transport service!\n")); - return; - } - ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, - &process_hello, NULL); + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to connect to transport service!\n")); + return; + } + ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL); } @@ -181,12 +178,11 @@ int main (int argc, char *const *argv) { int ret; - - ret = (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, - "dht", - GNUNET_SERVICE_OPTION_NONE, - &run, NULL)) ? 0 : 1; + + ret = + (GNUNET_OK == + GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, + NULL)) ? 0 : 1; GDS_CLIENTS_done (); return ret; } diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 4b9eecc58..dde8c6d7a 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c @@ -53,7 +53,7 @@ struct PendingMessage /** * Actual message to be sent, allocated at the end of the struct: - * // msg = (cast) &pm[1]; + * // msg = (cast) &pm[1]; * // memcpy (&pm[1], data, len); */ const struct GNUNET_MessageHeader *msg; @@ -224,15 +224,13 @@ find_active_client (struct GNUNET_SERVER_Client *client) } ret = GNUNET_malloc (sizeof (struct ClientList)); ret->client_handle = client; - GNUNET_CONTAINER_DLL_insert (client_head, - client_tail, - ret); + GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret); return ret; } /** - * Iterator over hash map entries that frees all entries + * Iterator over hash map entries that frees all entries * associated with the given client. * * @param cls client to search for in source routes @@ -250,18 +248,15 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_YES; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing client %p's record for key %s\n", - client, - GNUNET_h2s (key)); + "Removing client %p's record for key %s\n", client, + GNUNET_h2s (key)); #endif GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (forward_map, - key, record)); + GNUNET_CONTAINER_multihashmap_remove (forward_map, key, + record)); if (NULL != record->hnode) GNUNET_CONTAINER_heap_remove_node (record->hnode); - GNUNET_array_grow (record->seen_replies, - record->seen_replies_count, - 0); + GNUNET_array_grow (record->seen_replies, record->seen_replies_count, 0); GNUNET_free (record); return GNUNET_YES; } @@ -276,37 +271,31 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) * for the last call when the server is destroyed */ static void -handle_client_disconnect (void *cls, - struct GNUNET_SERVER_Client *client) +handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { struct ClientList *pos; struct PendingMessage *reply; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Local client %p disconnects\n", - client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client); #endif pos = find_active_client (client); - GNUNET_CONTAINER_DLL_remove (client_head, - client_tail, - pos); + GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos); if (pos->transmit_handle != NULL) GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle); while (NULL != (reply = pos->pending_head)) - { - GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, - reply); - GNUNET_free (reply); - } - GNUNET_CONTAINER_multihashmap_iterate (forward_map, - &remove_client_records, pos); + { + GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, reply); + GNUNET_free (reply); + } + GNUNET_CONTAINER_multihashmap_iterate (forward_map, &remove_client_records, + pos); GNUNET_free (pos); } /** - * Route the given request via the DHT. This includes updating + * Route the given request via the DHT. This includes updating * the bloom filter and retransmission times, building the P2P * message and initiating the routing operation. */ @@ -318,33 +307,30 @@ transmit_request (struct ClientQueryRecord *cqr) struct GNUNET_CONTAINER_BloomFilter *peer_bf; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests from clients injected"), 1, + gettext_noop + ("# GET requests from clients injected"), 1, GNUNET_NO); - reply_bf_mutator = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, - cqr->seen_replies, - cqr->seen_replies_count); - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GDS_NEIGHBOURS_handle_get (cqr->type, - cqr->msg_options, - cqr->replication, - 0 /* hop count */, - &cqr->key, - cqr->xquery, - cqr->xquery_size, - reply_bf, - reply_bf_mutator, - peer_bf); + reply_bf_mutator = + (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); + reply_bf = + GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies, + cqr->seen_replies_count); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, + 0 /* hop count */ , + &cqr->key, cqr->xquery, cqr->xquery_size, reply_bf, + reply_bf_mutator, peer_bf); GNUNET_CONTAINER_bloomfilter_free (reply_bf); GNUNET_CONTAINER_bloomfilter_free (peer_bf); /* exponential back-off for retries, max 1h */ - cqr->retry_frequency = - GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, - GNUNET_TIME_relative_multiply (cqr->retry_frequency, 2)); + cqr->retry_frequency = + GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, + GNUNET_TIME_relative_multiply + (cqr->retry_frequency, 2)); cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); } @@ -359,7 +345,7 @@ transmit_request (struct ClientQueryRecord *cqr) */ static void transmit_next_request_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ClientQueryRecord *cqr; struct GNUNET_TIME_Relative delay; @@ -368,22 +354,24 @@ transmit_next_request_task (void *cls, if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) + { + cqr->hnode = NULL; + delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); + if (delay.rel_value > 0) { - cqr->hnode = NULL; - delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); - if (delay.rel_value > 0) - { - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, - cqr->retry_time.abs_value); - retry_task = GNUNET_SCHEDULER_add_delayed (delay, - &transmit_next_request_task, - NULL); - return; - } - transmit_request (cqr); - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, - cqr->retry_time.abs_value); + cqr->hnode = + GNUNET_CONTAINER_heap_insert (retry_heap, cqr, + cqr->retry_time.abs_value); + retry_task = + GNUNET_SCHEDULER_add_delayed (delay, &transmit_next_request_task, + NULL); + return; } + transmit_request (cqr); + cqr->hnode = + GNUNET_CONTAINER_heap_insert (retry_heap, cqr, + cqr->retry_time.abs_value); + } } @@ -396,58 +384,52 @@ transmit_next_request_task (void *cls, */ static void handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientPutMessage *dht_msg; struct GNUNET_CONTAINER_BloomFilter *peer_bf; uint16_t size; - + size = ntohs (message->size); if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT requests received from clients"), 1, + gettext_noop + ("# PUT requests received from clients"), 1, GNUNET_NO); dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; /* give to local clients */ #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Handling local PUT of %u-bytes for query %s\n", - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - GNUNET_h2s (&dht_msg->key)); + "Handling local PUT of %u-bytes for query %s\n", + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + GNUNET_h2s (&dht_msg->key)); #endif GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - &dht_msg->key, - 0, NULL, - 0, NULL, - ntohl (dht_msg->type), - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - &dht_msg[1]); + &dht_msg->key, 0, NULL, 0, NULL, + ntohl (dht_msg->type), + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + &dht_msg[1]); /* store locally */ GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - &dht_msg->key, - 0, NULL, - ntohl (dht_msg->type), - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - &dht_msg[1]); + &dht_msg->key, 0, NULL, ntohl (dht_msg->type), + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + &dht_msg[1]); /* route to other peers */ - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), - ntohl (dht_msg->options), - ntohl (dht_msg->desired_replication_level), - GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - 0 /* hop count */, - peer_bf, - &dht_msg->key, - 0, NULL, - &dht_msg[1], - size - sizeof (struct GNUNET_DHT_ClientPutMessage)); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options), + ntohl (dht_msg->desired_replication_level), + GNUNET_TIME_absolute_ntoh (dht_msg->expiration), + 0 /* hop count */ , + peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1], + size - + sizeof (struct GNUNET_DHT_ClientPutMessage)); GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -464,58 +446,55 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, */ static void handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientGetMessage *get; struct ClientQueryRecord *cqr; size_t xquery_size; - const char* xquery; + const char *xquery; uint16_t size; size = ntohs (message->size); if (size < sizeof (struct GNUNET_DHT_ClientGetMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); get = (const struct GNUNET_DHT_ClientGetMessage *) message; - xquery = (const char*) &get[1]; + xquery = (const char *) &get[1]; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests received from clients"), 1, + gettext_noop + ("# GET requests received from clients"), 1, GNUNET_NO); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received request for %s from local client %p\n", - GNUNET_h2s (&get->key), - client); + "Received request for %s from local client %p\n", + GNUNET_h2s (&get->key), client); #endif cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); cqr->key = get->key; cqr->client = find_active_client (client); - cqr->xquery = (void*) &cqr[1]; + cqr->xquery = (void *) &cqr[1]; memcpy (&cqr[1], xquery, xquery_size); - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); + cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS; cqr->retry_time = GNUNET_TIME_absolute_get (); cqr->unique_id = get->unique_id; cqr->xquery_size = xquery_size; cqr->replication = ntohl (get->desired_replication_level); cqr->msg_options = ntohl (get->options); - cqr->type = ntohl (get->type); + cqr->type = ntohl (get->type); GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); /* start remote requests */ if (GNUNET_SCHEDULER_NO_TASK != retry_task) GNUNET_SCHEDULER_cancel (retry_task); retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); /* perform local lookup */ - GDS_DATACACHE_handle_get (&get->key, - cqr->type, - cqr->xquery, - xquery_size, - NULL, 0); + GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size, + NULL, 0); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -538,7 +517,7 @@ struct RemoveByUniqueIdContext /** - * Iterator over hash map entries that frees all entries + * Iterator over hash map entries that frees all entries * that match the given client and unique ID. * * @param cls unique ID and client to search for in source routes @@ -556,9 +535,8 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_YES; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing client %p's record for key %s (by unique id)\n", - ctx->client->client_handle, - GNUNET_h2s (key)); + "Removing client %p's record for key %s (by unique id)\n", + ctx->client->client_handle, GNUNET_h2s (key)); #endif return remove_client_records (ctx->client, key, record); } @@ -575,27 +553,24 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) */ static void handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg = - (const struct GNUNET_DHT_ClientGetStopMessage *) message; + (const struct GNUNET_DHT_ClientGetStopMessage *) message; struct RemoveByUniqueIdContext ctx; - + GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET STOP requests received from clients"), 1, + gettext_noop + ("# GET STOP requests received from clients"), 1, GNUNET_NO); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p stopped request for key %s\n", - client, - GNUNET_h2s (&dht_stop_msg->key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n", + client, GNUNET_h2s (&dht_stop_msg->key)); #endif ctx.client = find_active_client (client); ctx.unique_id = dht_stop_msg->unique_id; - GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, - &dht_stop_msg->key, - &remove_by_unique_id, - &ctx); + GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key, + &remove_by_unique_id, &ctx); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -636,8 +611,8 @@ send_reply_to_client (void *cls, size_t size, void *buf) /* client disconnected */ #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p disconnected, pending messages will be discarded\n", - client->client_handle); + "Client %p disconnected, pending messages will be discarded\n", + client->client_handle); #endif return 0; } @@ -650,20 +625,15 @@ send_reply_to_client (void *cls, size_t size, void *buf) memcpy (&cbuf[off], reply->msg, msize); GNUNET_free (reply); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting %u bytes to client %p\n", - msize, - client->client_handle); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n", + msize, client->client_handle); #endif off += msize; } process_pending_messages (client); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitted %u/%u bytes to client %p\n", - (unsigned int) off, - (unsigned int) size, - client->client_handle); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n", + (unsigned int) off, (unsigned int) size, client->client_handle); #endif return off; } @@ -681,20 +651,17 @@ process_pending_messages (struct ClientList *client) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not asking for transmission to %p now: %s\n", - client->client_handle, - client->pending_head == NULL - ? "no more messages" - : "request already pending"); + "Not asking for transmission to %p now: %s\n", + client->client_handle, + client->pending_head == + NULL ? "no more messages" : "request already pending"); #endif return; } #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking for transmission of %u bytes to client %p\n", - ntohs (client->pending_head-> - msg->size), - client->client_handle); + "Asking for transmission of %u bytes to client %p\n", + ntohs (client->pending_head->msg->size), client->client_handle); #endif client->transmit_handle = GNUNET_SERVER_notify_transmit_ready (client->client_handle, @@ -716,7 +683,7 @@ add_pending_message (struct ClientList *client, struct PendingMessage *pending_message) { GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, - pending_message); + pending_message); process_pending_messages (client); } @@ -728,7 +695,7 @@ struct ForwardReplyContext { /** - * Actual message to send to matching clients. + * Actual message to send to matching clients. */ struct PendingMessage *pm; @@ -777,51 +744,43 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) int do_free; GNUNET_HashCode ch; unsigned int i; - - if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && - (record->type != frc->type) ) + + if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type)) + { +#if DEBUG_DHT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Record type missmatch, not passing request for key %s to local client\n", + GNUNET_h2s (key)); +#endif + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Key match, type mismatches in REPLY to CLIENT"), + 1, GNUNET_NO); + return GNUNET_YES; /* type mismatch */ + } + GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); + for (i = 0; i < record->seen_replies_count; i++) + if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode))) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Record type missmatch, not passing request for key %s to local client\n", - GNUNET_h2s (key)); + "Duplicate reply, not passing request for key %s to local client\n", + GNUNET_h2s (key)); #endif GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, - GNUNET_NO); - return GNUNET_YES; /* type mismatch */ + gettext_noop + ("# Duplicate REPLIES to CLIENT request dropped"), + 1, GNUNET_NO); + return GNUNET_YES; /* duplicate */ } - GNUNET_CRYPTO_hash (frc->data, - frc->data_size, - &ch); - for (i=0;iseen_replies_count;i++) - if (0 == memcmp (&record->seen_replies[i], - &ch, - sizeof (GNUNET_HashCode))) - { -#if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Duplicate reply, not passing request for key %s to local client\n", - GNUNET_h2s (key)); -#endif - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1, - GNUNET_NO); - return GNUNET_YES; /* duplicate */ - } eval = - GNUNET_BLOCK_evaluate (GDS_block_context, - record->type, key, - NULL, 0, - record->xquery, - record->xquery_size, - frc->data, - frc->data_size); + GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0, + record->xquery, record->xquery_size, frc->data, + frc->data_size); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Evaluation result is %d for key %s for local client's query\n", - (int) eval, - GNUNET_h2s (key)); + "Evaluation result is %d for key %s for local client's query\n", + (int) eval, GNUNET_h2s (key)); #endif switch (eval) { @@ -829,9 +788,7 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) do_free = GNUNET_YES; break; case GNUNET_BLOCK_EVALUATION_OK_MORE: - GNUNET_array_append (record->seen_replies, - record->seen_replies_count, - ch); + GNUNET_array_append (record->seen_replies, record->seen_replies_count, ch); do_free = GNUNET_NO; break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: @@ -849,38 +806,36 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_NO; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Unsupported block type (%u) in request!\n"), - record->type); + _("Unsupported block type (%u) in request!\n"), record->type); return GNUNET_NO; default: GNUNET_break (0); return GNUNET_NO; } if (GNUNET_NO == frc->do_copy) - { - /* first time, we can use the original data */ - pm = frc->pm; - frc->do_copy = GNUNET_YES; - } + { + /* first time, we can use the original data */ + pm = frc->pm; + frc->do_copy = GNUNET_YES; + } else - { - /* two clients waiting for same reply, must copy for queueing */ - pm = GNUNET_malloc (sizeof (struct PendingMessage) + - ntohs (frc->pm->msg->size)); - memcpy (pm, frc->pm, - sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); - pm->next = pm->prev = NULL; - } + { + /* two clients waiting for same reply, must copy for queueing */ + pm = GNUNET_malloc (sizeof (struct PendingMessage) + + ntohs (frc->pm->msg->size)); + memcpy (pm, frc->pm, + sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); + pm->next = pm->prev = NULL; + } GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# RESULTS queued for clients"), 1, GNUNET_NO); - reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; + reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; reply->unique_id = record->unique_id; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing reply to query %s for client %p\n", - GNUNET_h2s (key), - record->client->client_handle); + "Queueing reply to query %s for client %p\n", GNUNET_h2s (key), + record->client->client_handle); #endif add_pending_message (record->client, pm); if (GNUNET_YES == do_free) @@ -906,14 +861,13 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) */ void GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data) + const GNUNET_HashCode * key, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data) { struct ForwardReplyContext frc; struct PendingMessage *pm; @@ -921,57 +875,57 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, struct GNUNET_PeerIdentity *paths; size_t msize; - if (NULL == - GNUNET_CONTAINER_multihashmap_get (forward_map, key)) + if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, - GNUNET_NO); - return; /* no matching request, fast exit! */ + gettext_noop + ("# REPLIES ignored for CLIENTS (no match)"), 1, + GNUNET_NO); + return; /* no matching request, fast exit! */ } - msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); + msize = + sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size + + (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not pass reply to client, message too big!\n")); - return; - } - pm = (struct PendingMessage *) GNUNET_malloc (msize + sizeof (struct PendingMessage)); - reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Could not pass reply to client, message too big!\n")); + return; + } + pm = (struct PendingMessage *) GNUNET_malloc (msize + + sizeof (struct PendingMessage)); + reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; pm->msg = &reply->header; reply->header.size = htons ((uint16_t) msize); reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); reply->type = htonl (type); reply->get_path_length = htonl (get_path_length); reply->put_path_length = htonl (put_path_length); - reply->unique_id = 0; /* filled in later */ + reply->unique_id = 0; /* filled in later */ reply->expiration = GNUNET_TIME_absolute_hton (expiration); reply->key = *key; - paths = (struct GNUNET_PeerIdentity*) &reply[1]; - memcpy (paths, put_path, - sizeof (struct GNUNET_PeerIdentity) * put_path_length); - memcpy (&paths[put_path_length], - get_path, sizeof (struct GNUNET_PeerIdentity) * get_path_length); - memcpy (&paths[get_path_length + put_path_length], - data, - data_size); + paths = (struct GNUNET_PeerIdentity *) &reply[1]; + memcpy (paths, put_path, + sizeof (struct GNUNET_PeerIdentity) * put_path_length); + memcpy (&paths[put_path_length], get_path, + sizeof (struct GNUNET_PeerIdentity) * get_path_length); + memcpy (&paths[get_path_length + put_path_length], data, data_size); frc.do_copy = GNUNET_NO; frc.pm = pm; frc.data = data; frc.data_size = data_size; frc.type = type; - GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, - &forward_reply, - &frc); + GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, + &frc); if (GNUNET_NO == frc.do_copy) - { - /* did not match any of the requests, free! */ - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, - GNUNET_NO); - GNUNET_free (pm); - } + { + /* did not match any of the requests, free! */ + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# REPLIES ignored for CLIENTS (no match)"), 1, + GNUNET_NO); + GNUNET_free (pm); + } } @@ -980,17 +934,17 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, * * @param server the initialized server */ -void +void GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) { static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { - {&handle_dht_local_put, NULL, + {&handle_dht_local_put, NULL, GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0}, - {&handle_dht_local_get, NULL, + {&handle_dht_local_get, NULL, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0}, {&handle_dht_local_get_stop, NULL, - GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, - sizeof (struct GNUNET_DHT_ClientGetStopMessage) }, + GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, + sizeof (struct GNUNET_DHT_ClientGetStopMessage)}, {NULL, NULL, 0, 0} }; forward_map = GNUNET_CONTAINER_multihashmap_create (1024); @@ -1009,10 +963,10 @@ GDS_CLIENTS_done () GNUNET_assert (client_head == NULL); GNUNET_assert (client_tail == NULL); if (GNUNET_SCHEDULER_NO_TASK != retry_task) - { - GNUNET_SCHEDULER_cancel (retry_task); - retry_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (retry_task); + retry_task = GNUNET_SCHEDULER_NO_TASK; + } GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); GNUNET_CONTAINER_heap_destroy (retry_heap); retry_heap = NULL; @@ -1022,4 +976,3 @@ GDS_CLIENTS_done () } /* end of gnunet-service-dht_clients.c */ - diff --git a/src/dht/gnunet-service-dht_clients.h b/src/dht/gnunet-service-dht_clients.h index 66fa433c0..21b2343e7 100644 --- a/src/dht/gnunet-service-dht_clients.h +++ b/src/dht/gnunet-service-dht_clients.h @@ -47,14 +47,13 @@ */ void GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data); + const GNUNET_HashCode * key, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data); /** @@ -62,7 +61,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, * * @param server the initialized server */ -void +void GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index f3b2e5b2f..82cd06727 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c @@ -74,44 +74,42 @@ struct DHTPutEntry */ void GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data) + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data) { - size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry); + size_t plen = + data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) + + sizeof (struct DHTPutEntry); char buf[plen]; struct DHTPutEntry *pe; struct GNUNET_PeerIdentity *pp; if (datacache == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("%s request received, but have no datacache!\n"), - "PUT"); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("%s request received, but have no datacache!\n"), "PUT"); + return; + } if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } + { + GNUNET_break (0); + return; + } /* Put size is actual data size plus struct overhead plus path length (if any) */ GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# ITEMS stored in datacache"), 1, - GNUNET_NO); + gettext_noop ("# ITEMS stored in datacache"), 1, + GNUNET_NO); pe = (struct DHTPutEntry *) buf; pe->data_size = htons (data_size); pe->path_length = htons ((uint16_t) put_path_length); pp = (struct GNUNET_PeerIdentity *) &pe[1]; memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&pp[put_path_length], - data, data_size); - (void) GNUNET_DATACACHE_put (datacache, key, - plen, (const char *) pe, type, - expiration); + memcpy (&pp[put_path_length], data, data_size); + (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type, + expiration); } @@ -190,20 +188,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, return GNUNET_OK; } pp = (const struct GNUNET_PeerIdentity *) &pe[1]; - rdata = (const char*) &pp[put_path_length]; + rdata = (const char *) &pp[put_path_length]; eval = - GNUNET_BLOCK_evaluate (GDS_block_context, type, key, - ctx->reply_bf, - ctx->reply_bf_mutator, - ctx->xquery, - ctx->xquery_size, - rdata, - rdata_size); + GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, + ctx->reply_bf_mutator, ctx->xquery, + ctx->xquery_size, rdata, rdata_size); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found reply for query %s in datacache, evaluation result is %d\n", - GNUNET_h2s (key), - (int) eval); + "Found reply for query %s in datacache, evaluation result is %d\n", + GNUNET_h2s (key), (int) eval); #endif ctx->eval = eval; switch (eval) @@ -212,27 +205,26 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, case GNUNET_BLOCK_EVALUATION_OK_MORE: /* forward to local clients */ GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Good RESULTS found in datacache"), 1, - GNUNET_NO); - GDS_CLIENTS_handle_reply (exp, - key, - 0, NULL, - put_path_length, pp, - type, rdata_size, rdata); + gettext_noop + ("# Good RESULTS found in datacache"), 1, + GNUNET_NO); + GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type, + rdata_size, rdata); /* forward to other peers */ - GDS_ROUTING_process (type, exp, - key, put_path_length, pp, - 0, NULL, rdata, rdata_size); + GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata, + rdata_size); break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Duplicate RESULTS found in datacache"), 1, + GNUNET_NO); break; case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Invalid RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Invalid RESULTS found in datacache"), 1, + GNUNET_NO); break; case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: GNUNET_break (0); @@ -242,11 +234,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, return GNUNET_SYSERR; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Unsupported RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Unsupported RESULTS found in datacache"), 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Unsupported block type (%u) in local response!\n"), - type); + _("Unsupported block type (%u) in local response!\n"), type); break; } return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; @@ -256,7 +248,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, /** * Handle a GET request we've received from another peer. * - * @param key the query + * @param key the query * @param type requested data type * @param xquery extended query * @param xquery_size number of bytes in xquery @@ -265,28 +257,27 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, * @return evaluation result for the local replies */ enum GNUNET_BLOCK_EvaluationResult -GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type type, - const void *xquery, - size_t xquery_size, - struct GNUNET_CONTAINER_BloomFilter **reply_bf, - uint32_t reply_bf_mutator) +GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, const void *xquery, + size_t xquery_size, + struct GNUNET_CONTAINER_BloomFilter **reply_bf, + uint32_t reply_bf_mutator) { struct GetRequestContext ctx; if (datacache == NULL) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests given to datacache"), 1, - GNUNET_NO); + gettext_noop ("# GET requests given to datacache"), + 1, GNUNET_NO); ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; ctx.key = *key; ctx.xquery = xquery; ctx.xquery_size = xquery_size; ctx.reply_bf = reply_bf; ctx.reply_bf_mutator = reply_bf_mutator; - (void) GNUNET_DATACACHE_get (datacache, key, type, - &datacache_get_iterator, &ctx); + (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator, + &ctx); return ctx.eval; } @@ -294,7 +285,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, /** * Initialize datacache subsystem. */ -void +void GDS_DATACACHE_init () { datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index ccd854570..926ad5326 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h @@ -44,18 +44,17 @@ */ void GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data); + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data); /** * Handle a GET request we've received from another peer. * - * @param key the query + * @param key the query * @param type requested data type * @param xquery extended query * @param xquery_size number of bytes in xquery @@ -63,19 +62,18 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, * @param reply_bf_mutator mutation value for reply_bf * @return evaluation result for the local replies */ -enum GNUNET_BLOCK_EvaluationResult -GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type type, - const void *xquery, - size_t xquery_size, - struct GNUNET_CONTAINER_BloomFilter **reply_bf, - uint32_t reply_bf_mutator); +enum GNUNET_BLOCK_EvaluationResult +GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, const void *xquery, + size_t xquery_size, + struct GNUNET_CONTAINER_BloomFilter **reply_bf, + uint32_t reply_bf_mutator); /** * Initialize datacache subsystem. */ -void +void GDS_DATACACHE_init (void); diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c index 5be0cbfec..578e651f8 100644 --- a/src/dht/gnunet-service-dht_hello.c +++ b/src/dht/gnunet-service-dht_hello.c @@ -54,8 +54,7 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) { if (NULL == peer_to_hello) return NULL; - return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, - &peer->hashPubKey); + return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); } @@ -68,11 +67,8 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) * @param error message */ static void -process_hello (void *cls, - const struct GNUNET_PeerIdentity * - peer, - const struct GNUNET_HELLO_Message * - hello, const char *err_msg) +process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct GNUNET_TIME_Absolute ex; struct GNUNET_HELLO_Message *hm; @@ -83,18 +79,16 @@ process_hello (void *cls, if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) return; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# HELLOs obtained from peerinfo"), 1, - GNUNET_NO); - hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, - &peer->hashPubKey); + gettext_noop ("# HELLOs obtained from peerinfo"), 1, + GNUNET_NO); + hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); GNUNET_free_non_null (hm); hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); memcpy (hm, hello, GNUNET_HELLO_size (hello)); GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_put (peer_to_hello, - &peer->hashPubKey, - hm, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); + GNUNET_CONTAINER_multihashmap_put (peer_to_hello, + &peer->hashPubKey, hm, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); } @@ -104,9 +98,7 @@ process_hello (void *cls, void GDS_HELLO_init () { - pnc = GNUNET_PEERINFO_notify (GDS_cfg, - &process_hello, - NULL); + pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL); peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); } @@ -115,9 +107,7 @@ GDS_HELLO_init () * Free memory occopied by the HELLO. */ static int -free_hello (void *cls, - const GNUNET_HashCode *key, - void *hello) +free_hello (void *cls, const GNUNET_HashCode * key, void *hello) { GNUNET_free (hello); return GNUNET_OK; @@ -137,9 +127,7 @@ GDS_HELLO_done () } if (NULL != peer_to_hello) { - GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, - &free_hello, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL); GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); } } diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 02124b488..9ebf16400 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -275,7 +275,7 @@ struct P2PPendingMessage /** * Actual message to be sent, allocated at the end of the struct: - * // msg = (cast) &pm[1]; + * // msg = (cast) &pm[1]; * // memcpy (&pm[1], data, len); */ const struct GNUNET_MessageHeader *msg; @@ -399,7 +399,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task; /** * Identity of this peer. - */ + */ static struct GNUNET_PeerIdentity my_identity; /** @@ -428,11 +428,11 @@ find_bucket (const GNUNET_HashCode * hc) bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); if (bits == MAX_BUCKETS) - { - /* How can all bits match? Got my own ID? */ - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + /* How can all bits match? Got my own ID? */ + GNUNET_break (0); + return GNUNET_SYSERR; + } return MAX_BUCKETS - bits - 1; } @@ -442,7 +442,7 @@ find_bucket (const GNUNET_HashCode * hc) * * @param cls the 'struct PeerInfo' of the peer * @param tc scheduler context. - */ + */ static void update_core_preference (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) @@ -454,10 +454,10 @@ update_core_preference (void *cls, peer->preference_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) - return; + return; matching = - GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, - &peer->id.hashPubKey); + GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, + &peer->id.hashPubKey); if (matching >= 64) matching = 63; bucket = find_bucket (&peer->id.hashPubKey); @@ -469,22 +469,21 @@ update_core_preference (void *cls, preference = (1LL << matching) / k_buckets[bucket].peers_size; } if (preference == 0) - { - peer->preference_task - = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, - &update_core_preference, peer); - return; - } + { + peer->preference_task = + GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, + &update_core_preference, peer); + return; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Preference updates given to core"), 1, - GNUNET_NO); + gettext_noop ("# Preference updates given to core"), + 1, GNUNET_NO); GNUNET_ATS_change_preference (atsAPI, &peer->id, - GNUNET_ATS_PREFERENCE_BANDWIDTH, - (double) preference, - GNUNET_ATS_PREFERENCE_END); - peer->preference_task - = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, - &update_core_preference, peer); + GNUNET_ATS_PREFERENCE_BANDWIDTH, + (double) preference, GNUNET_ATS_PREFERENCE_END); + peer->preference_task = + GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, + &update_core_preference, peer); } @@ -525,9 +524,8 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", - GNUNET_h2s (key), - ctx->bf_mutator); + "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", + GNUNET_h2s (key), ctx->bf_mutator); #endif GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); return GNUNET_YES; @@ -553,46 +551,46 @@ send_find_peer_message (void *cls, find_peer_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - if (newly_found_peers > bucket_size) + if (newly_found_peers > bucket_size) { /* If we are finding many peers already, no need to send out our request right now! */ - find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &send_find_peer_message, NULL); + find_peer_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &send_find_peer_message, NULL); newly_found_peers = 0; return; } - bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + bcc.bf_mutator = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); bcc.bloom = - GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, - &add_known_to_bloom, + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom, &bcc); GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER messages initiated"), 1, - GNUNET_NO); - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); + gettext_noop ("# FIND PEER messages initiated"), 1, + GNUNET_NO); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); // FIXME: pass priority!? GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_DHT_RO_FIND_PEER, - FIND_PEER_REPLICATION_LEVEL, - 0, - &my_identity.hashPubKey, - NULL, 0, - bcc.bloom, bcc.bf_mutator, - peer_bf); + GNUNET_DHT_RO_FIND_PEER, + FIND_PEER_REPLICATION_LEVEL, 0, + &my_identity.hashPubKey, NULL, 0, bcc.bloom, + bcc.bf_mutator, peer_bf); GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); /* schedule next round */ next_send_time.rel_value = - DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); + DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, + DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / + (newly_found_peers + 1)); newly_found_peers = 0; - find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, - &send_find_peer_message, - NULL); + find_peer_task = + GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message, + NULL); } @@ -607,7 +605,7 @@ send_find_peer_message (void *cls, static void handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct PeerInfo *ret; int peer_bucket; @@ -616,10 +614,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connected %s to %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (&peer->hashPubKey)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); #endif if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (all_known_peers, @@ -628,11 +624,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break (0); return; } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers connected"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1, + GNUNET_NO); peer_bucket = find_bucket (&peer->hashPubKey); - GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) ); + GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS)); ret = GNUNET_malloc (sizeof (struct PeerInfo)); #if 0 ret->latency = latency; @@ -640,25 +635,23 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, #endif ret->id = *peer; GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, - k_buckets[peer_bucket].tail, ret); + k_buckets[peer_bucket].tail, ret); k_buckets[peer_bucket].peers_size++; - closest_bucket = GNUNET_MAX (closest_bucket, - peer_bucket); - if ( (peer_bucket > 0) && - (k_buckets[peer_bucket].peers_size <= bucket_size) ) + closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket); + if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size)) { - ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); + ret->preference_task = + GNUNET_SCHEDULER_add_now (&update_core_preference, ret); newly_found_peers++; } GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (all_known_peers, - &peer->hashPubKey, ret, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (all_known_peers, + &peer->hashPubKey, ret, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) { /* got a first connection, good time to start with FIND PEER requests... */ - find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, - NULL); + find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL); } } @@ -681,21 +674,18 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnected %s from %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (&peer->hashPubKey)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); #endif to_remove = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); if (NULL == to_remove) - { - GNUNET_break (0); - return; - } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers connected"), -1, - GNUNET_NO); + { + GNUNET_break (0); + return; + } + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1, + GNUNET_NO); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (all_known_peers, &peer->hashPubKey, @@ -708,15 +698,13 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) current_bucket = find_bucket (&to_remove->id.hashPubKey); GNUNET_assert (current_bucket >= 0); GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, - k_buckets[current_bucket].tail, - to_remove); + k_buckets[current_bucket].tail, to_remove); GNUNET_assert (k_buckets[current_bucket].peers_size > 0); k_buckets[current_bucket].peers_size--; - while ( (closest_bucket > 0) && - (k_buckets[closest_bucket].peers_size == 0) ) + while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0)) closest_bucket--; - if (to_remove->th != NULL) + if (to_remove->th != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); to_remove->th = NULL; @@ -724,15 +712,14 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) discarded = 0; while (NULL != (pos = to_remove->head)) { - GNUNET_CONTAINER_DLL_remove (to_remove->head, - to_remove->tail, - pos); + GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos); discarded++; GNUNET_free (pos); } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded, - GNUNET_NO); + gettext_noop + ("# Queued messages discarded (peer disconnected)"), + discarded, GNUNET_NO); GNUNET_free (to_remove); } @@ -756,8 +743,8 @@ core_transmit_notify (void *cls, size_t size, void *buf) size_t msize; peer->th = NULL; - while ( (NULL != (pending = peer->head)) && - (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) + while ((NULL != (pending = peer->head)) && + (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0)) { peer->pending_count--; GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); @@ -770,22 +757,24 @@ core_transmit_notify (void *cls, size_t size, void *buf) } if (buf == NULL) { - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, ntohs (pending->msg->size), - &core_transmit_notify, peer); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, + ntohs (pending->msg->size), + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); return 0; } off = 0; - while ( (NULL != (pending = peer->head)) && - (size - off >= (msize = ntohs (pending->msg->size))) ) + while ((NULL != (pending = peer->head)) && + (size - off >= (msize = ntohs (pending->msg->size)))) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Bytes transmitted to other peers"), msize, - GNUNET_NO); + gettext_noop + ("# Bytes transmitted to other peers"), msize, + GNUNET_NO); memcpy (&cbuf[off], pending->msg, msize); off += msize; peer->pending_count--; @@ -794,12 +783,12 @@ core_transmit_notify (void *cls, size_t size, void *buf) } if (peer->head != NULL) { - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, msize, - &core_transmit_notify, peer); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, msize, + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); } return off; @@ -821,16 +810,16 @@ process_peer_queue (struct PeerInfo *peer) if (NULL != peer->th) return; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Bytes of bandwdith requested from core"), - ntohs (pending->msg->size), - GNUNET_NO); - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, - ntohs (pending->msg->size), - &core_transmit_notify, peer); + gettext_noop + ("# Bytes of bandwdith requested from core"), + ntohs (pending->msg->size), GNUNET_NO); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, + ntohs (pending->msg->size), + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); } @@ -844,8 +833,7 @@ process_peer_queue (struct PeerInfo *peer) * @return Some number of peers to forward the message to */ static unsigned int -get_forward_count (uint32_t hop_count, - uint32_t target_replication) +get_forward_count (uint32_t hop_count, uint32_t target_replication) { uint32_t random_value; uint32_t forward_count; @@ -862,18 +850,18 @@ get_forward_count (uint32_t hop_count, return 1; } /* bound by system-wide maximum */ - target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, - target_replication); + target_replication = + GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); target_value = - 1 + (target_replication - 1.0) / (GDS_NSE_get () + - ((float) (target_replication - 1.0) * - hop_count)); + 1 + (target_replication - 1.0) / (GDS_NSE_get () + + ((float) (target_replication - 1.0) * + hop_count)); /* Set forward count to floor of target_value */ forward_count = (uint32_t) target_value; /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ target_value = target_value - forward_count; random_value = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); if (random_value < (target_value * UINT32_MAX)) forward_count++; return forward_count; @@ -950,7 +938,7 @@ get_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have) * GNUNET_NO otherwise. */ static int -am_closest_peer (const GNUNET_HashCode *key, +am_closest_peer (const GNUNET_HashCode * key, const struct GNUNET_CONTAINER_BloomFilter *bloom) { int bits; @@ -978,7 +966,7 @@ am_closest_peer (const GNUNET_HashCode *key, other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); if (other_bits > bits) return GNUNET_NO; - if (other_bits == bits) /* We match the same number of bits */ + if (other_bits == bits) /* We match the same number of bits */ return GNUNET_YES; pos = pos->next; } @@ -997,7 +985,7 @@ am_closest_peer (const GNUNET_HashCode *key, * exponentially declining probability. * * FIXME: double-check that this is fine - * + * * * @param key the key we are selecting a peer to route to * @param bloom a bloomfilter containing entries this request has seen already @@ -1005,9 +993,8 @@ am_closest_peer (const GNUNET_HashCode *key, * @return Peer to route to, or NULL on error */ static struct PeerInfo * -select_peer (const GNUNET_HashCode *key, - const struct GNUNET_CONTAINER_BloomFilter *bloom, - uint32_t hops) +select_peer (const GNUNET_HashCode * key, + const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops) { unsigned int bc; unsigned int count; @@ -1028,10 +1015,10 @@ select_peer (const GNUNET_HashCode *key, count = 0; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom == NULL) || - (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) - { + if ((bloom == NULL) || + (GNUNET_NO == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) + { dist = get_distance (key, &pos->id.hashPubKey); if (dist < smallest_distance) { @@ -1040,25 +1027,25 @@ select_peer (const GNUNET_HashCode *key, } } else - { + { #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Excluded peer `%s' due to BF match in greedy routing for %s\n", - GNUNET_i2s (&pos->id), - GNUNET_h2s (key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Excluded peer `%s' due to BF match in greedy routing for %s\n", + GNUNET_i2s (&pos->id), GNUNET_h2s (key)); #endif - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Peers excluded from routing due to Bloomfilter"), + 1, GNUNET_NO); + } count++; pos = pos->next; } } if (NULL == chosen) GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peer selection failed"), 1, - GNUNET_NO); + gettext_noop ("# Peer selection failed"), 1, + GNUNET_NO); return chosen; } @@ -1070,18 +1057,18 @@ select_peer (const GNUNET_HashCode *key, pos = k_buckets[bc].head; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom != NULL) && - (GNUNET_YES == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) + if ((bloom != NULL) && + (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) { - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Peers excluded from routing due to Bloomfilter"), + 1, GNUNET_NO); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Excluded peer `%s' due to BF match in random routing for %s\n", - GNUNET_i2s (&pos->id), - GNUNET_h2s (key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Excluded peer `%s' due to BF match in random routing for %s\n", + GNUNET_i2s (&pos->id), GNUNET_h2s (key)); #endif pos = pos->next; continue; /* Ignore bloomfiltered peers */ @@ -1093,8 +1080,8 @@ select_peer (const GNUNET_HashCode *key, if (count == 0) /* No peers to select from! */ { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peer selection failed"), 1, - GNUNET_NO); + gettext_noop ("# Peer selection failed"), 1, + GNUNET_NO); return NULL; } /* Now actually choose a peer */ @@ -1105,9 +1092,9 @@ select_peer (const GNUNET_HashCode *key, pos = k_buckets[bc].head; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom != NULL) && - (GNUNET_YES == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) + if ((bloom != NULL) && + (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) { pos = pos->next; continue; /* Ignore bloomfiltered peers */ @@ -1136,11 +1123,10 @@ select_peer (const GNUNET_HashCode *key, * @return number of peers returned in 'targets'. */ static unsigned int -get_target_peers (const GNUNET_HashCode *key, - struct GNUNET_CONTAINER_BloomFilter *bloom, - uint32_t hop_count, - uint32_t target_replication, - struct PeerInfo ***targets) +get_target_peers (const GNUNET_HashCode * key, + struct GNUNET_CONTAINER_BloomFilter *bloom, + uint32_t hop_count, uint32_t target_replication, + struct PeerInfo ***targets) { unsigned int ret; unsigned int off; @@ -1154,25 +1140,23 @@ get_target_peers (const GNUNET_HashCode *key, *targets = NULL; return 0; } - rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret); + rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret); for (off = 0; off < ret; off++) { nxt = select_peer (key, bloom, hop_count); if (nxt == NULL) - break; + break; rtargets[off] = nxt; GNUNET_break (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); + GNUNET_CONTAINER_bloomfilter_test (bloom, + &nxt->id.hashPubKey)); GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); } #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Selected %u/%u peers at hop %u for %s (target was %u)\n", - off, - GNUNET_CONTAINER_multihashmap_size (all_known_peers), - (unsigned int) hop_count, - GNUNET_h2s (key), - ret); + "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, + GNUNET_CONTAINER_multihashmap_size (all_known_peers), + (unsigned int) hop_count, GNUNET_h2s (key), ret); #endif if (0 == off) { @@ -1206,16 +1190,15 @@ get_target_peers (const GNUNET_HashCode *key, */ void GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - struct GNUNET_TIME_Absolute expiration_time, - uint32_t hop_count, - struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode *key, - unsigned int put_path_length, - struct GNUNET_PeerIdentity *put_path, - const void *data, - size_t data_size) + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + struct GNUNET_TIME_Absolute expiration_time, + uint32_t hop_count, + struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * key, + unsigned int put_path_length, + struct GNUNET_PeerIdentity *put_path, + const void *data, size_t data_size) { unsigned int target_count; unsigned int i; @@ -1225,33 +1208,32 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, size_t msize; struct PeerPutMessage *ppm; struct GNUNET_PeerIdentity *pp; - + GNUNET_assert (NULL != bf); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding myself (%s) to PUT bloomfilter for %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (key)); + "Adding myself (%s) to PUT bloomfilter for %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (key)); #endif GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT requests routed"), 1, - GNUNET_NO); - target_count = get_target_peers (key, bf, hop_count, - desired_replication_level, - &targets); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), + 1, GNUNET_NO); + target_count = + get_target_peers (key, bf, hop_count, desired_replication_level, + &targets); if (0 == target_count) - { + { #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing PUT for %s terminates after %u hops at %s\n", - GNUNET_h2s (key), - (unsigned int) hop_count, - GNUNET_i2s (&my_identity)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing PUT for %s terminates after %u hops at %s\n", + GNUNET_h2s (key), (unsigned int) hop_count, + GNUNET_i2s (&my_identity)); #endif - return; - } - msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); + return; + } + msize = + put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + + sizeof (struct PeerPutMessage); if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { put_path_length = 0; @@ -1264,22 +1246,21 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT messages queued for transmission"), target_count, - GNUNET_NO); - for (i=0;iid)); + "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key), + (unsigned int) hop_count, GNUNET_i2s (&target->id)); #endif pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ - pending->timeout = expiration_time; - ppm = (struct PeerPutMessage*) &pending[1]; + pending->importance = 0; /* FIXME */ + pending->timeout = expiration_time; + ppm = (struct PeerPutMessage *) &pending[1]; pending->msg = &ppm->header; ppm->header.size = htons (msize); ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); @@ -1289,18 +1270,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, ppm->desired_replication_level = htonl (desired_replication_level); ppm->put_path_length = htonl (put_path_length); ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); - GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bf, + &target->id.hashPubKey)); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, - ppm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, + ppm->bloomfilter, + DHT_BLOOM_SIZE)); ppm->key = *key; - pp = (struct GNUNET_PeerIdentity*) &ppm[1]; - memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); + pp = (struct GNUNET_PeerIdentity *) &ppm[1]; + memcpy (pp, put_path, + sizeof (struct GNUNET_PeerIdentity) * put_path_length); memcpy (&pp[put_path_length], data, data_size); - GNUNET_CONTAINER_DLL_insert_tail (target->head, - target->tail, - pending); + GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); target->pending_count++; process_peer_queue (target); } @@ -1327,15 +1309,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - uint32_t hop_count, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator, - struct GNUNET_CONTAINER_BloomFilter *peer_bf) + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + uint32_t hop_count, const GNUNET_HashCode * key, + const void *xquery, size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator, + struct GNUNET_CONTAINER_BloomFilter *peer_bf) { unsigned int target_count; unsigned int i; @@ -1347,28 +1327,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, char *xq; size_t reply_bf_size; - GNUNET_assert (NULL != peer_bf); - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests routed"), 1, - GNUNET_NO); - target_count = get_target_peers (key, peer_bf, hop_count, - desired_replication_level, - &targets); + GNUNET_assert (NULL != peer_bf); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"), + 1, GNUNET_NO); + target_count = + get_target_peers (key, peer_bf, hop_count, desired_replication_level, + &targets); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding myself (%s) to GET bloomfilter for %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (key)); + "Adding myself (%s) to GET bloomfilter for %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (key)); #endif GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); if (0 == target_count) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing GET for %s terminates after %u hops at %s\n", - GNUNET_h2s (key), - (unsigned int) hop_count, - GNUNET_i2s (&my_identity)); + "Routing GET for %s terminates after %u hops at %s\n", + GNUNET_h2s (key), (unsigned int) hop_count, + GNUNET_i2s (&my_identity)); #endif return; } @@ -1381,23 +1358,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET messages queued for transmission"), target_count, - GNUNET_NO); + gettext_noop + ("# GET messages queued for transmission"), + target_count, GNUNET_NO); /* forward request */ - for (i=0;iid)); + "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key), + (unsigned int) hop_count, GNUNET_i2s (&target->id)); #endif - pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ + pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); + pending->importance = 0; /* FIXME */ pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); - pgm = (struct PeerGetMessage*) &pending[1]; + pgm = (struct PeerGetMessage *) &pending[1]; pending->msg = &pgm->header; pgm->header.size = htons (msize); pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); @@ -1406,23 +1382,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, pgm->hop_count = htonl (hop_count + 1); pgm->desired_replication_level = htonl (desired_replication_level); pgm->xquery_size = htonl (xquery_size); - pgm->bf_mutator = reply_bf_mutator; - GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); + pgm->bf_mutator = reply_bf_mutator; + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (peer_bf, + &target->id.hashPubKey)); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, - pgm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, + pgm->bloomfilter, + DHT_BLOOM_SIZE)); pgm->key = *key; xq = (char *) &pgm[1]; memcpy (xq, xquery, xquery_size); if (NULL != reply_bf) GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, - &xq[xquery_size], - reply_bf_size)); - GNUNET_CONTAINER_DLL_insert_tail (target->head, - target->tail, - pending); + GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, + &xq + [xquery_size], + reply_bf_size)); + GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); target->pending_count++; process_peer_queue (target); } @@ -1448,46 +1425,49 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, - enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size) + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size) { struct PeerInfo *pi; struct P2PPendingMessage *pending; size_t msize; struct PeerResultMessage *prm; struct GNUNET_PeerIdentity *paths; - - msize = data_size + sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); - if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) ) + + msize = + data_size + sizeof (struct PeerResultMessage) + (get_path_length + + put_path_length) * + sizeof (struct GNUNET_PeerIdentity); + if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (get_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (put_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); return; } - pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, - &target->hashPubKey); + pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey); if (NULL == pi) { /* peer disconnected in the meantime, drop reply */ return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# RESULT messages queued for transmission"), 1, - GNUNET_NO); - pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ + gettext_noop + ("# RESULT messages queued for transmission"), 1, + GNUNET_NO); + pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); + pending->importance = 0; /* FIXME */ pending->timeout = expiration_time; - prm = (struct PeerResultMessage*) &pending[1]; + prm = (struct PeerResultMessage *) &pending[1]; pending->msg = &prm->header; prm->header.size = htons (msize); prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); @@ -1496,15 +1476,13 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, prm->get_path_length = htonl (get_path_length); prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); prm->key = *key; - paths = (struct GNUNET_PeerIdentity*) &prm[1]; - memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&paths[put_path_length], - get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&paths[put_path_length + get_path_length], - data, data_size); - GNUNET_CONTAINER_DLL_insert (pi->head, - pi->tail, - pending); + paths = (struct GNUNET_PeerIdentity *) &prm[1]; + memcpy (paths, put_path, + put_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (&paths[put_path_length], get_path, + get_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (&paths[put_path_length + get_path_length], data, data_size); + GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending); pi->pending_count++; process_peer_queue (pi); } @@ -1539,12 +1517,10 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, * GNUNET_SYSERR to close it (signal serious error) */ static int -handle_dht_p2p_put (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) +handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct PeerPutMessage *put; const struct GNUNET_PeerIdentity *put_path; @@ -1555,33 +1531,36 @@ handle_dht_p2p_put (void *cls, enum GNUNET_DHT_RouteOption options; struct GNUNET_CONTAINER_BloomFilter *bf; GNUNET_HashCode test_key; - + msize = ntohs (message->size); if (msize < sizeof (struct PeerPutMessage)) { GNUNET_break_op (0); return GNUNET_YES; } - put = (const struct PeerPutMessage*) message; + put = (const struct PeerPutMessage *) message; putlen = ntohl (put->put_path_length); - if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) || - (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) - { - GNUNET_break_op (0); - return GNUNET_YES; - } + if ((msize < + sizeof (struct PeerPutMessage) + + putlen * sizeof (struct GNUNET_PeerIdentity)) || + (putlen > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) + { + GNUNET_break_op (0); + return GNUNET_YES; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P PUT requests received"), 1, - GNUNET_NO); - put_path = (const struct GNUNET_PeerIdentity*) &put[1]; + gettext_noop ("# P2P PUT requests received"), 1, + GNUNET_NO); + put_path = (const struct GNUNET_PeerIdentity *) &put[1]; payload = &put_path[putlen]; options = ntohl (put->options); - payload_size = msize - (sizeof (struct PeerPutMessage) + - putlen * sizeof (struct GNUNET_PeerIdentity)); - switch (GNUNET_BLOCK_get_key (GDS_block_context, - ntohl (put->type), - payload, payload_size, - &test_key)) + payload_size = + msize - (sizeof (struct PeerPutMessage) + + putlen * sizeof (struct GNUNET_PeerIdentity)); + switch (GNUNET_BLOCK_get_key + (GDS_block_context, ntohl (put->type), payload, payload_size, + &test_key)) { case GNUNET_YES: if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) @@ -1598,18 +1577,16 @@ handle_dht_p2p_put (void *cls, break; } #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "PUT for %s at %s\n", - GNUNET_h2s (&put->key), - GNUNET_i2s (&my_identity)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n", + GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity)); #endif - bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); + bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_break_op (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); { - struct GNUNET_PeerIdentity pp[putlen+1]; - + struct GNUNET_PeerIdentity pp[putlen + 1]; + /* extend 'put path' by sender */ if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) { @@ -1619,37 +1596,23 @@ handle_dht_p2p_put (void *cls, } else putlen = 0; - + /* give to local clients */ GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), - &put->key, - 0, NULL, - putlen, - pp, - ntohl (put->type), - payload_size, - payload); + &put->key, 0, NULL, putlen, pp, ntohl (put->type), + payload_size, payload); /* store locally */ - if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&put->key, - bf) ) ) - GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), - &put->key, - putlen, pp, - ntohl (put->type), - payload_size, - payload); + if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || + (am_closest_peer (&put->key, bf))) + GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh + (put->expiration_time), &put->key, putlen, pp, + ntohl (put->type), payload_size, payload); /* route to other peers */ - GDS_NEIGHBOURS_handle_put (ntohl (put->type), - options, - ntohl (put->desired_replication_level), - GNUNET_TIME_absolute_ntoh (put->expiration_time), - ntohl (put->hop_count), - bf, - &put->key, - putlen, pp, - payload, - payload_size); + GDS_NEIGHBOURS_handle_put (ntohl (put->type), options, + ntohl (put->desired_replication_level), + GNUNET_TIME_absolute_ntoh (put->expiration_time), + ntohl (put->hop_count), bf, &put->key, putlen, + pp, payload, payload_size); } GNUNET_CONTAINER_bloomfilter_free (bf); return GNUNET_YES; @@ -1667,9 +1630,8 @@ handle_dht_p2p_put (void *cls, */ static void handle_find_peer (const struct GNUNET_PeerIdentity *sender, - const GNUNET_HashCode *key, - struct GNUNET_CONTAINER_BloomFilter *bf, - uint32_t bf_mutator) + const GNUNET_HashCode * key, + struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator) { int bucket_idx; struct PeerBucket *bucket; @@ -1682,30 +1644,31 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, if (NULL != GDS_my_hello) { GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); - if ( (NULL == bf) || - (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ) + if ((NULL == bf) || + (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))) { - GDS_NEIGHBOURS_handle_reply (sender, - GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), - key, - 0, NULL, - 0, NULL, - GDS_my_hello, - GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello)); + GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), + key, 0, NULL, 0, NULL, GDS_my_hello, + GNUNET_HELLO_size ((const struct + GNUNET_HELLO_Message *) + GDS_my_hello)); } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1, - GNUNET_NO); + gettext_noop + ("# FIND PEER requests ignored due to Bloomfilter"), + 1, GNUNET_NO); } } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1, - GNUNET_NO); + gettext_noop + ("# FIND PEER requests ignored due to lack of HELLO"), + 1, GNUNET_NO); } /* then, also consider sending a random HELLO from the closest bucket */ @@ -1718,8 +1681,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, bucket = &k_buckets[bucket_idx]; if (bucket->peers_size == 0) return; - choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - bucket->peers_size); + choice = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size); peer = bucket->head; while (choice > 0) { @@ -1729,25 +1692,22 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, } choice = bucket->peers_size; do - { - peer = peer->next; - if (choice-- == 0) - return; /* no non-masked peer available */ - if (peer == NULL) - peer = bucket->head; - GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); - hello = GDS_HELLO_get (&peer->id); - } - while ( (hello == NULL) || - (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); - GDS_NEIGHBOURS_handle_reply (sender, - GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), - key, - 0, NULL, - 0, NULL, - hello, - GNUNET_HELLO_size (hello)); + { + peer = peer->next; + if (choice-- == 0) + return; /* no non-masked peer available */ + if (peer == NULL) + peer = bucket->head; + GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); + hello = GDS_HELLO_get (&peer->id); + } + while ((hello == NULL) || + (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))); + GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key, + 0, NULL, 0, NULL, hello, + GNUNET_HELLO_size (hello)); } @@ -1765,10 +1725,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, */ static int handle_dht_p2p_get (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, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct PeerGetMessage *get; uint32_t xquery_size; @@ -1781,7 +1740,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_BloomFilter *peer_bf; const char *xquery; - GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); + GNUNET_break (0 != + memcmp (peer, &my_identity, + sizeof (struct GNUNET_PeerIdentity))); /* parse and validate message */ msize = ntohs (message->size); if (msize < sizeof (struct PeerGetMessage)) @@ -1797,24 +1758,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P GET requests received"), 1, - GNUNET_NO); + gettext_noop ("# P2P GET requests received"), 1, + GNUNET_NO); reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); type = ntohl (get->type); options = ntohl (get->options); - xquery = (const char*) &get[1]; + xquery = (const char *) &get[1]; reply_bf = NULL; if (reply_bf_size > 0) - reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], - reply_bf_size, - GNUNET_CONSTANTS_BLOOMFILTER_K); - eval = GNUNET_BLOCK_evaluate (GDS_block_context, - type, - &get->key, - &reply_bf, - get->bf_mutator, - xquery, xquery_size, - NULL, 0); + reply_bf = + GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size, + GNUNET_CONSTANTS_BLOOMFILTER_K); + eval = + GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf, + get->bf_mutator, xquery, xquery_size, NULL, 0); if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) { /* request invalid or block type not supported */ @@ -1824,70 +1781,55 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } peer_bf = - GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); + GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_break_op (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (peer_bf, + &peer->hashPubKey)); /* remember request for routing replies */ - GDS_ROUTING_add (peer, - type, - options, - &get->key, - xquery, xquery_size, - reply_bf, get->bf_mutator); + GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size, + reply_bf, get->bf_mutator); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GET for %s at %s after %u hops\n", - GNUNET_h2s (&get->key), - GNUNET_i2s (&my_identity), - (unsigned int) ntohl (get->hop_count)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", + GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), + (unsigned int) ntohl (get->hop_count)); #endif /* local lookup (this may update the reply_bf) */ - if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&get->key, - peer_bf) ) ) - { - if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER))) + if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || + (am_closest_peer (&get->key, peer_bf))) + { + if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P FIND PEER requests processed"), 1, - GNUNET_NO); - handle_find_peer (peer, - &get->key, - reply_bf, - get->bf_mutator); + gettext_noop + ("# P2P FIND PEER requests processed"), 1, + GNUNET_NO); + handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator); } else { - eval = GDS_DATACACHE_handle_get (&get->key, - type, - xquery, xquery_size, - &reply_bf, - get->bf_mutator); + eval = + GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size, + &reply_bf, get->bf_mutator); } } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P GET requests ONLY routed"), 1, - GNUNET_NO); + gettext_noop ("# P2P GET requests ONLY routed"), + 1, GNUNET_NO); } - + /* P2P forwarding */ if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) - GDS_NEIGHBOURS_handle_get (type, - options, - ntohl (get->desired_replication_level), - ntohl (get->hop_count), - &get->key, - xquery, xquery_size, - reply_bf, - get->bf_mutator, - peer_bf); + GDS_NEIGHBOURS_handle_get (type, options, + ntohl (get->desired_replication_level), + ntohl (get->hop_count), &get->key, xquery, + xquery_size, reply_bf, get->bf_mutator, peer_bf); /* clean up */ if (NULL != reply_bf) GNUNET_CONTAINER_bloomfilter_free (reply_bf); - GNUNET_CONTAINER_bloomfilter_free (peer_bf); + GNUNET_CONTAINER_bloomfilter_free (peer_bf); return GNUNET_YES; } @@ -1904,10 +1846,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, */ static int handle_dht_p2p_result (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, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct PeerResultMessage *prm; const struct GNUNET_PeerIdentity *put_path; @@ -1918,7 +1859,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, uint16_t msize; size_t data_size; enum GNUNET_BLOCK_Type type; - + /* parse and validate message */ msize = ntohs (message->size); if (msize < sizeof (struct PeerResultMessage)) @@ -1929,23 +1870,28 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, prm = (struct PeerResultMessage *) message; put_path_length = ntohl (prm->put_path_length); get_path_length = ntohl (prm->get_path_length); - if ( (msize < sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) || - (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) + if ((msize < + sizeof (struct PeerResultMessage) + (get_path_length + + put_path_length) * + sizeof (struct GNUNET_PeerIdentity)) || + (get_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (put_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break_op (0); return GNUNET_YES; - } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P RESULTS received"), 1, - GNUNET_NO); - put_path = (const struct GNUNET_PeerIdentity*) &prm[1]; + } + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"), + 1, GNUNET_NO); + put_path = (const struct GNUNET_PeerIdentity *) &prm[1]; get_path = &put_path[put_path_length]; type = ntohl (prm->type); - data = (const void*) &get_path[get_path_length]; - data_size = msize - (sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); + data = (const void *) &get_path[get_path_length]; + data_size = + msize - (sizeof (struct PeerResultMessage) + + (get_path_length + + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); /* if we got a HELLO, consider it for our own routing table */ if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) @@ -1967,8 +1913,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } if (GNUNET_OK != - GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h, - &pid)) + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid)) { GNUNET_break_op (0); return GNUNET_YES; @@ -1976,49 +1921,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) { bucket = find_bucket (&pid.hashPubKey); - if ( (bucket >= 0) && - (k_buckets[bucket].peers_size < bucket_size) ) - { - if (NULL != GDS_transport_handle) - { - GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, - h, NULL, NULL); - GNUNET_TRANSPORT_try_connect (GDS_transport_handle, - &pid); - } - } + if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size)) + { + if (NULL != GDS_transport_handle) + { + GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL); + GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid); + } + } } } /* append 'peer' to 'get_path' */ - { - struct GNUNET_PeerIdentity xget_path[get_path_length+1]; + { + struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; - memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (xget_path, get_path, + get_path_length * sizeof (struct GNUNET_PeerIdentity)); xget_path[get_path_length] = *peer; get_path_length++; - /* forward to local clients */ + /* forward to local clients */ GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), - &prm->key, - get_path_length, - xget_path, - put_path_length, - put_path, - type, - data_size, - data); + &prm->key, get_path_length, xget_path, + put_path_length, put_path, type, data_size, data); /* forward to other peers */ - GDS_ROUTING_process (type, - GNUNET_TIME_absolute_ntoh (prm->expiration_time), - &prm->key, - put_path_length, - put_path, - get_path_length, - xget_path, - data, - data_size); + GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time), + &prm->key, put_path_length, put_path, get_path_length, + xget_path, data, data_size); } return GNUNET_YES; } @@ -2039,21 +1970,16 @@ GDS_NEIGHBOURS_init () {NULL, 0, 0} }; unsigned long long temp_config_num; - + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", &temp_config_num)) - bucket_size = (unsigned int) temp_config_num; + bucket_size = (unsigned int) temp_config_num; atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); - coreAPI = GNUNET_CORE_connect (GDS_cfg, - 1, - NULL, - &core_init, - &handle_core_connect, - &handle_core_disconnect, - NULL, GNUNET_NO, - NULL, GNUNET_NO, - core_handlers); + coreAPI = + GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect, + &handle_core_disconnect, NULL, GNUNET_NO, NULL, + GNUNET_NO, core_handlers); if (coreAPI == NULL) return GNUNET_SYSERR; all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); @@ -2070,9 +1996,9 @@ GDS_NEIGHBOURS_done () if (coreAPI == NULL) return; GNUNET_CORE_disconnect (coreAPI); - coreAPI = NULL; + coreAPI = NULL; GNUNET_ATS_performance_done (atsAPI); - atsAPI = NULL; + atsAPI = NULL; GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); all_known_peers = NULL; diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index d23ea10ab..b6e0f0ec0 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h @@ -52,16 +52,15 @@ */ void GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - struct GNUNET_TIME_Absolute expiration_time, - uint32_t hop_count, - struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode *key, - unsigned int put_path_length, - struct GNUNET_PeerIdentity *put_path, - const void *data, - size_t data_size); + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + struct GNUNET_TIME_Absolute expiration_time, + uint32_t hop_count, + struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * key, + unsigned int put_path_length, + struct GNUNET_PeerIdentity *put_path, + const void *data, size_t data_size); /** @@ -83,15 +82,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - uint32_t hop_count, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator, - struct GNUNET_CONTAINER_BloomFilter *peer_bf); + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + uint32_t hop_count, const GNUNET_HashCode * key, + const void *xquery, size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator, + struct GNUNET_CONTAINER_BloomFilter *peer_bf); /** @@ -112,15 +109,14 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, - enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size); + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size); /** diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c index 0a662ec7b..777998967 100644 --- a/src/dht/gnunet-service-dht_nse.c +++ b/src/dht/gnunet-service-dht_nse.c @@ -56,10 +56,10 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Network size estimates received"), 1, - GNUNET_NO); + gettext_noop ("# Network size estimates received"), + 1, GNUNET_NO); /* do not allow estimates < 0.5 */ - log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); + log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); } @@ -90,9 +90,9 @@ GDS_NSE_init () */ void GDS_NSE_done () -{ +{ if (NULL != nse) - { + { GNUNET_NSE_disconnect (nse); nse = NULL; } diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index 607c756c6..a880bf7cd 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c @@ -66,7 +66,7 @@ struct RecentRequest * Type of the requested block. */ enum GNUNET_BLOCK_Type type; - + /** * extended query (see gnunet_block_lib.h). Allocated at the * end of this struct. @@ -114,7 +114,7 @@ struct ProcessContext /** * Path of the reply. - */ + */ const struct GNUNET_PeerIdentity *get_path; /** @@ -156,13 +156,11 @@ struct ProcessContext * @param cls the 'struct ProcessContext' with the result * @param key the query * @param value the 'struct RecentRequest' with the request - * @return GNUNET_OK (continue to iterate), + * @return GNUNET_OK (continue to iterate), * GNUNET_SYSERR if the result is malformed or type unsupported */ static int -process (void *cls, - const GNUNET_HashCode *key, - void *value) +process (void *cls, const GNUNET_HashCode * key, void *value) { struct ProcessContext *pc = cls; struct RecentRequest *rr = value; @@ -172,9 +170,8 @@ process (void *cls, GNUNET_HashCode hc; const GNUNET_HashCode *eval_key; - if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && - (rr->type != pc->type) ) - return GNUNET_OK; /* type missmatch */ + if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type)) + return GNUNET_OK; /* type missmatch */ if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) { @@ -186,59 +183,48 @@ process (void *cls, gpl = 0; ppl = 0; } - if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && - (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) + if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && + (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) { /* key may not match HELLO, which is OK since - the search is approximate. Still, the evaluation - would fail since the match is not exact. So - we fake it by changing the key to the actual PID ... */ - GNUNET_BLOCK_get_key (GDS_block_context, - GNUNET_BLOCK_TYPE_DHT_HELLO, - pc->data, pc->data_size, - &hc); + * the search is approximate. Still, the evaluation + * would fail since the match is not exact. So + * we fake it by changing the key to the actual PID ... */ + GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO, + pc->data, pc->data_size, &hc); eval_key = &hc; } else { eval_key = key; } - eval = GNUNET_BLOCK_evaluate (GDS_block_context, - pc->type, - eval_key, - &rr->reply_bf, - rr->reply_bf_mutator, - rr->xquery, - rr->xquery_size, - pc->data, - pc->data_size); + eval = + GNUNET_BLOCK_evaluate (GDS_block_context, pc->type, eval_key, + &rr->reply_bf, rr->reply_bf_mutator, rr->xquery, + rr->xquery_size, pc->data, pc->data_size); switch (eval) { case GNUNET_BLOCK_EVALUATION_OK_MORE: case GNUNET_BLOCK_EVALUATION_OK_LAST: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Good REPLIES matched against routing table"), 1, - GNUNET_NO); - GDS_NEIGHBOURS_handle_reply (&rr->peer, - pc->type, - pc->expiration_time, - key, - ppl, - pc->put_path, - gpl, - pc->get_path, - pc->data, - pc->data_size); + gettext_noop + ("# Good REPLIES matched against routing table"), + 1, GNUNET_NO); + GDS_NEIGHBOURS_handle_reply (&rr->peer, pc->type, pc->expiration_time, key, + ppl, pc->put_path, gpl, pc->get_path, pc->data, + pc->data_size); break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Duplicate REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_OK; case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Invalid REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Invalid REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_SYSERR; case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: @@ -246,12 +232,13 @@ process (void *cls, return GNUNET_OK; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Unsupported REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Unsupported REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_SYSERR; default: GNUNET_break (0); - return GNUNET_SYSERR; + return GNUNET_SYSERR; } return GNUNET_OK; } @@ -276,14 +263,12 @@ process (void *cls, */ void GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size) + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size) { struct ProcessContext pc; @@ -295,10 +280,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, pc.get_path = get_path; pc.data = data; pc.data_size = data_size; - GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, - key, - &process, - &pc); + GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc); } @@ -316,21 +298,21 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, */ void GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, - enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator) + enum GNUNET_BLOCK_Type type, + enum GNUNET_DHT_RouteOption options, + const GNUNET_HashCode * key, const void *xquery, + size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator) { struct RecentRequest *recent_req; while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries removed from routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Entries removed from routing table"), 1, + GNUNET_NO); recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); GNUNET_assert (recent_req != NULL); GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); @@ -339,25 +321,22 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries added to routing table"), 1, - GNUNET_NO); + gettext_noop ("# Entries added to routing table"), + 1, GNUNET_NO); recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); recent_req->peer = *sender; recent_req->key = *key; recent_req->heap_node = - GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, - GNUNET_TIME_absolute_get ().abs_value); - recent_req->reply_bf = - GNUNET_CONTAINER_bloomfilter_copy (reply_bf); + GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, + GNUNET_TIME_absolute_get ().abs_value); + recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf); recent_req->type = type; recent_req->options = options; recent_req->xquery = &recent_req[1]; recent_req->xquery_size = xquery_size; recent_req->reply_bf_mutator = reply_bf_mutator; - GNUNET_CONTAINER_multihashmap_put (recent_map, - key, - recent_req, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } @@ -369,10 +348,8 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, void GDS_ROUTING_init () { - recent_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); - recent_map = - GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); + recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); } @@ -387,8 +364,9 @@ GDS_ROUTING_done () while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries removed from routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Entries removed from routing table"), 1, + GNUNET_NO); recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); GNUNET_assert (recent_req != NULL); GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h index a2576a3bb..9b12c71de 100644 --- a/src/dht/gnunet-service-dht_routing.h +++ b/src/dht/gnunet-service-dht_routing.h @@ -50,14 +50,12 @@ */ void GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size); + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size); /** @@ -74,13 +72,12 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, */ void GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, - enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator); + enum GNUNET_BLOCK_Type type, + enum GNUNET_DHT_RouteOption options, + const GNUNET_HashCode * key, const void *xquery, + size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator); /** diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c index 220554e15..1db351841 100644 --- a/src/dht/test_dht_2dtorus.c +++ b/src/dht/test_dht_2dtorus.c @@ -138,7 +138,8 @@ shutdown_callback (void *cls, const char *emsg) else { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "test: All peers successfully shut down!\n"); #endif } } @@ -169,22 +170,21 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { unsigned int i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: disconnecting peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); disconnect_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_SCHEDULER_cancel (put_task); if (NULL != get_h) - GNUNET_DHT_get_stop(get_h); + GNUNET_DHT_get_stop (get_h); if (NULL != get_h_2) - GNUNET_DHT_get_stop(get_h_2); + GNUNET_DHT_get_stop (get_h_2); if (NULL != get_h_far) - GNUNET_DHT_get_stop(get_h_far); - for (i = 0; i < num_peers; i++) + GNUNET_DHT_get_stop (get_h_far); + for (i = 0; i < num_peers; i++) { - GNUNET_DHT_disconnect(hs[i]); + GNUNET_DHT_disconnect (hs[i]); } GNUNET_SCHEDULER_cancel (shutdown_handle); - shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); + shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } static void @@ -193,44 +193,39 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: ************* FOUND!!! ***********\n"); - if (sizeof(GNUNET_HashCode) == size) + "test: ************* FOUND!!! ***********\n"); + if (sizeof (GNUNET_HashCode) == size) { const GNUNET_HashCode *h = data; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Contents: %s\n", + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", GNUNET_h2s_full (h)); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: PATH: (get %u, put %u)\n", - get_path_length, - put_path_length); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: LOCAL\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", + get_path_length, put_path_length); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); for (i = get_path_length - 1; i >= 0; i--) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: %s\n", - GNUNET_i2s (&get_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", + GNUNET_i2s (&get_path[i])); } for (i = put_path_length - 1; i >= 0; i--) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: %s\n", - GNUNET_i2s (&put_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", + GNUNET_i2s (&put_path[i])); } found++; if (found < 3) return; ok = 0; - GNUNET_SCHEDULER_cancel(disconnect_task); + GNUNET_SCHEDULER_cancel (disconnect_task); disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); } @@ -263,7 +258,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (strcmp (id_aux, id_near2) == 0) d2 = aux; } - if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) + if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: Peers not found (hostkey file changed?)\n"); @@ -272,55 +267,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d2->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d_far->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: from %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", GNUNET_h2s_full (&o->id.hashPubKey)); found = 0; - get_h = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); - get_h_2 = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ + get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); + get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ &d2->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); - get_h_far = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d_far->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); + get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d_far->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, - &disconnect_peers, NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); } @@ -331,28 +310,20 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); - for (i = 0; i < num_peers; i++) + for (i = 0; i < num_peers; i++) { d = GNUNET_TESTING_daemon_get (pg, i); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: putting into DHT: %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", GNUNET_h2s_full (&d->id.hashPubKey)); - GNUNET_DHT_put(hs[i], - &d->id.hashPubKey, - 10U, - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - GNUNET_BLOCK_TYPE_TEST, - sizeof(struct GNUNET_PeerIdentity), - (const char *) &d->id, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_REL, - NULL, - NULL); + GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U, + GNUNET_DHT_RO_RECORD_ROUTE | + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), + (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); } - put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, - &put_id, NULL); + put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); } @@ -373,8 +344,8 @@ peergroup_ready (void *cls, const char *emsg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peergroup callback called with error, aborting test!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Error from testing: `%s'\n", emsg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", + emsg); ok++; GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); return; @@ -384,8 +355,7 @@ peergroup_ready (void *cls, const char *emsg) "************************************************************\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer Group started successfully!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Have %u connections\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", total_connections); #endif @@ -398,24 +368,22 @@ peergroup_ready (void *cls, const char *emsg) GNUNET_free (buf); } peers_running = GNUNET_TESTING_daemons_running (pg); - + GNUNET_assert (peers_running == num_peers); - hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *)); - for (i = 0; i < num_peers; i++) + hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); + for (i = 0; i < num_peers; i++) { d = GNUNET_TESTING_daemon_get (pg, i); - hs[i] = GNUNET_DHT_connect(d->cfg, 32); + hs[i] = GNUNET_DHT_connect (d->cfg, 32); } - put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL); + put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); test_task = - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), - &do_test, NULL); - disconnect_task = - GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, - &disconnect_peers, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); } @@ -446,14 +414,13 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, if (emsg == NULL) { total_connections++; - GNUNET_PEER_intern(first); - GNUNET_PEER_intern(second); + GNUNET_PEER_intern (first); + GNUNET_PEER_intern (second); } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Problem with new connection (%s)\n", - emsg); + "test: Problem with new connection (%s)\n", emsg); } } @@ -496,7 +463,7 @@ run (void *cls, char *const *args, const char *cfgfile, "num_peers", &num_peers)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Option TESTING:NUM_PEERS is required!\n"); + "Option TESTING:NUM_PEERS is required!\n"); return; } @@ -516,17 +483,17 @@ run (void *cls, char *const *args, const char *cfgfile, &data_filename)) { data_file = - GNUNET_DISK_file_open (data_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (data_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (data_file == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", - data_filename); - GNUNET_free (data_filename); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", + data_filename); + GNUNET_free (data_filename); + } } if (GNUNET_YES == @@ -552,7 +519,7 @@ run (void *cls, char *const *args, const char *cfgfile, hosts); GNUNET_assert (pg != NULL); shutdown_handle = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); } @@ -584,7 +551,8 @@ main (int xargc, char *xargv[]) NULL }; - GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", + GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, + "test_dht_2dtorus", gettext_noop ("Test dht in a small 2D torus."), options, &run, NULL); #if REMOVE_DIR diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 51f7d947c..e636c08ba 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -179,10 +179,10 @@ static void test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_get_iterator called (we got a result), stopping get request!\n"); @@ -213,9 +213,9 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) peer->get_handle = GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, - GNUNET_BLOCK_TYPE_TEST, &hash, - 1, GNUNET_DHT_RO_NONE, NULL, - 0, &test_get_iterator, NULL); + GNUNET_BLOCK_TYPE_TEST, &hash, 1, + GNUNET_DHT_RO_NONE, NULL, 0, &test_get_iterator, + NULL); if (peer->get_handle == NULL) { @@ -250,8 +250,8 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (peer->dht_handle != NULL); - GNUNET_DHT_put (peer->dht_handle, &hash, 1, - GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, + GNUNET_DHT_put (peer->dht_handle, &hash, 1, GNUNET_DHT_RO_NONE, + GNUNET_BLOCK_TYPE_TEST, data_size, data, GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), TOTAL_TIMEOUT, &test_get, &p1); GNUNET_free (data); diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 62833a583..f6519239b 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c @@ -95,12 +95,12 @@ struct TestPutContext struct TestGetContext { /** - * This is a linked list + * This is a linked list */ struct TestGetContext *next; /** - * This is a linked list + * This is a linked list */ struct TestGetContext *prev; @@ -220,9 +220,7 @@ shutdown_callback (void *cls, const char *emsg) { if (emsg != NULL) { - fprintf (stderr, - "Failed to shutdown testing topology: %s\n", - emsg); + fprintf (stderr, "Failed to shutdown testing topology: %s\n", emsg); if (ok == 0) ok = 2; } @@ -370,18 +368,18 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (sm); i = 0; while (stats[i].name != NULL) - { - fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, - stats[i].name, (unsigned long long) stats[i].total); - i++; - } + { + fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, + stats[i].name, (unsigned long long) stats[i].total); + i++; + } die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL); return; } sm->stat = GNUNET_STATISTICS_create ("", - GNUNET_TESTING_daemon_get (pg, - sm->daemon)->cfg); + GNUNET_TESTING_daemon_get (pg, + sm->daemon)->cfg); die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); } @@ -404,9 +402,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_cancel (test_put->task); if (test_put->dht_handle != NULL) GNUNET_DHT_disconnect (test_put->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -418,16 +414,14 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_get_stop (test_get->get_handle); if (test_get->dht_handle != NULL) GNUNET_DHT_disconnect (test_get->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); } sm = GNUNET_malloc (sizeof (struct StatMaster)); sm->stat = - GNUNET_STATISTICS_create ("", - GNUNET_TESTING_daemon_get (pg, - sm->daemon)->cfg); + GNUNET_STATISTICS_create ("", + GNUNET_TESTING_daemon_get (pg, + sm->daemon)->cfg); die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); } @@ -445,18 +439,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct TestGetContext *test_get; die_task = GNUNET_SCHEDULER_NO_TASK; - fprintf (stderr, - "Failing test with error: `%s'!\n", - emsg); + fprintf (stderr, "Failing test with error: `%s'!\n", emsg); while (NULL != (test_put = all_puts_head)) { if (test_put->task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (test_put->task); if (test_put->dht_handle != NULL) GNUNET_DHT_disconnect (test_put->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -468,9 +458,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_get_stop (test_get->get_handle); if (test_get->dht_handle != NULL) GNUNET_DHT_disconnect (test_get->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); } ok = 1; @@ -495,10 +483,8 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (test_get->succeeded != GNUNET_YES) { gets_failed++; - fprintf (stderr, - "Get from peer %s for key %s failed!\n", - GNUNET_i2s (&test_get->daemon->id), - GNUNET_h2s (&search_key)); + fprintf (stderr, "Get from peer %s for key %s failed!\n", + GNUNET_i2s (&test_get->daemon->id), GNUNET_h2s (&search_key)); } GNUNET_assert (test_get->get_handle != NULL); GNUNET_DHT_get_stop (test_get->get_handle); @@ -508,29 +494,25 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_disconnect (test_get->dht_handle); test_get->dht_handle = NULL; - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); - if ((gets_failed > 10) && (outstanding_gets == 0)) + if ((gets_failed > 10) && (outstanding_gets == 0)) { /* Had more than 10% failures */ - fprintf (stderr, - "%llu gets succeeded, %llu gets failed!\n", - gets_completed, gets_failed); + fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, + gets_failed); GNUNET_SCHEDULER_cancel (die_task); - ok = 1; - die_task = GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); + ok = 1; + die_task = + GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); return; } - if ( (gets_completed + gets_failed == num_peers * num_peers) && - (outstanding_gets == 0) ) /* All gets successful */ + if ((gets_completed + gets_failed == num_peers * num_peers) && (outstanding_gets == 0)) /* All gets successful */ { - fprintf (stderr, - "%llu gets succeeded, %llu gets failed!\n", - gets_completed, gets_failed); + fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, + gets_failed); GNUNET_SCHEDULER_cancel (die_task); - ok = 0; + ok = 0; die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); } } @@ -550,10 +532,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct TestGetContext *test_get = cls; GNUNET_HashCode search_key; /* Key stored under */ @@ -569,9 +551,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, { unsigned int i; - fprintf (stderr, "PUT (%u) Path: ", - test_get->uid); - for (i = 0; iuid); + for (i = 0; i < put_path_length; i++) fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); fprintf (stderr, "\n"); } @@ -579,25 +560,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, { unsigned int i; - fprintf (stderr, "GET (%u) Path: ", - test_get->uid); + fprintf (stderr, "GET (%u) Path: ", test_get->uid); for (i = 0; i < get_path_length; i++) fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); - fprintf (stderr, "%s%s\n", - get_path_length > 0 ? "->":"", - GNUNET_i2s (&test_get->daemon->id)); + fprintf (stderr, "%s%s\n", get_path_length > 0 ? "->" : "", + GNUNET_i2s (&test_get->daemon->id)); } #endif if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp (original_data, data, sizeof (original_data)))) { - fprintf (stderr, - "Key or data is not the same as was inserted!\n"); + fprintf (stderr, "Key or data is not the same as was inserted!\n"); return; } gets_completed++; - test_get->succeeded = GNUNET_YES; + test_get->succeeded = GNUNET_YES; GNUNET_SCHEDULER_cancel (test_get->task); test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); } @@ -615,7 +593,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (outstanding_gets > MAX_OUTSTANDING_GETS) { - test_get->task = GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); + test_get->task = + GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); return; } memset (data, test_get->uid, sizeof (data)); @@ -624,12 +603,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (test_get->dht_handle != NULL); outstanding_gets++; test_get->get_handle = - GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_BLOCK_TYPE_TEST, &key, - 1, route_option, NULL, 0, - &get_result_iterator, test_get); + GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_BLOCK_TYPE_TEST, &key, 1, route_option, NULL, + 0, &get_result_iterator, test_get); test_get->task = - GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); } @@ -644,9 +622,7 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) test_put->task = GNUNET_SCHEDULER_NO_TASK; GNUNET_DHT_disconnect (test_put->dht_handle); test_put->dht_handle = NULL; - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -661,23 +637,19 @@ start_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned long long j; struct TestGetContext *test_get; -#if VERBOSE - fprintf (stderr, - "Issuing %llu GETs\n", - (unsigned long long) (num_peers * num_peers)); +#if VERBOSE + fprintf (stderr, "Issuing %llu GETs\n", + (unsigned long long) (num_peers * num_peers)); #endif for (i = 0; i < num_peers; i++) for (j = 0; j < num_peers; j++) - { - test_get = GNUNET_malloc (sizeof (struct TestGetContext)); - test_get->uid = i + j*num_peers; - test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); - GNUNET_CONTAINER_DLL_insert (all_gets_head, - all_gets_tail, - test_get); - test_get->task = GNUNET_SCHEDULER_add_now (&do_get, - test_get); - } + { + test_get = GNUNET_malloc (sizeof (struct TestGetContext)); + test_get->uid = i + j * num_peers; + test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); + GNUNET_CONTAINER_DLL_insert (all_gets_head, all_gets_tail, test_get); + test_get->task = GNUNET_SCHEDULER_add_now (&do_get, test_get); + } } @@ -692,15 +664,12 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) outstanding_puts--; puts_completed++; GNUNET_SCHEDULER_cancel (test_put->task); - test_put->task = - GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); + test_put->task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); if (puts_completed != num_peers * num_peers) return; - + GNUNET_assert (outstanding_puts == 0); - GNUNET_SCHEDULER_add_delayed (START_DELAY, - &start_gets, - NULL); + GNUNET_SCHEDULER_add_delayed (START_DELAY, &start_gets, NULL); } @@ -717,7 +686,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) test_put->task = GNUNET_SCHEDULER_NO_TASK; if (outstanding_puts > MAX_OUTSTANDING_PUTS) { - test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); + test_put->task = + GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); return; } memset (data, test_put->uid, sizeof (data)); @@ -726,46 +696,43 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (test_put->dht_handle != NULL); outstanding_puts++; #if VERBOSE > 2 - fprintf (stderr, "PUT %u at `%s'\n", - test_put->uid, - GNUNET_i2s (&test_put->daemon->id)); + fprintf (stderr, "PUT %u at `%s'\n", test_put->uid, + GNUNET_i2s (&test_put->daemon->id)); #endif - GNUNET_DHT_put (test_put->dht_handle, &key, 1, - route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, + GNUNET_DHT_put (test_put->dht_handle, &key, 1, route_option, + GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, test_put); test_put->task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &put_disconnect_task, test_put); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &put_disconnect_task, test_put); } static void run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ +{ unsigned long long i; struct TestPutContext *test_put; #if PATH_TRACKING - route_option = GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; + route_option = + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; #else route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; #endif die_task = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, - "from setup puts/gets"); - fprintf (stderr, - "Issuing %llu PUTs (one per peer)\n", - (unsigned long long) (num_peers * num_peers)); + GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, + "from setup puts/gets"); + fprintf (stderr, "Issuing %llu PUTs (one per peer)\n", + (unsigned long long) (num_peers * num_peers)); for (i = 0; i < num_peers * num_peers; i++) { test_put = GNUNET_malloc (sizeof (struct TestPutContext)); test_put->uid = i; - test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); + test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); - GNUNET_CONTAINER_DLL_insert (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_insert (all_puts_head, all_puts_tail, test_put); } } @@ -782,17 +749,13 @@ startup_done (void *cls, const char *emsg) { if (emsg != NULL) { - fprintf (stderr, - "Failed to setup topology: %s\n", - emsg); - die_task = - GNUNET_SCHEDULER_add_now (&end_badly, - "topology setup failed"); + fprintf (stderr, "Failed to setup topology: %s\n", emsg); + die_task = GNUNET_SCHEDULER_add_now (&end_badly, "topology setup failed"); return; } die_task = - GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, - "from setup puts/gets"); + GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, + "from setup puts/gets"); } @@ -813,13 +776,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", &num_peers)) num_peers = DEFAULT_NUM_PEERS; - pg = GNUNET_TESTING_peergroup_start (cfg, - num_peers, - TIMEOUT, - NULL, - &startup_done, - NULL, - NULL); + pg = GNUNET_TESTING_peergroup_start (cfg, num_peers, TIMEOUT, NULL, + &startup_done, NULL, NULL); GNUNET_assert (NULL != pg); } diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 8947739c4..04198b48b 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c @@ -138,9 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { const char *emsg = cls; - fprintf (stderr, - "Error: %s\n", - emsg); + fprintf (stderr, "Error: %s\n", emsg); if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task); @@ -175,10 +173,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct PeerGetContext *get_context = cls; @@ -257,9 +255,9 @@ get_stop_finished (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, - 1, GNUNET_DHT_RO_NONE, NULL, - 0, &get_result_iterator, get_context); + &get_context->peer->hashPubKey, 1, + GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, + get_context); } @@ -292,9 +290,9 @@ 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, - 1, GNUNET_DHT_RO_FIND_PEER, NULL, - 0, &get_result_iterator, get_context); + &get_context->peer->hashPubKey, 1, + GNUNET_DHT_RO_FIND_PEER, NULL, 0, + &get_result_iterator, get_context); } @@ -335,8 +333,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, #endif GNUNET_SCHEDULER_cancel (die_task); die_task = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &end_badly, "Timeout trying to GET"); + GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, + "Timeout trying to GET"); curr_get_ctx.dht_handle = peer1dht; curr_get_ctx.peer = &peer2id; @@ -383,9 +381,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, { if (emsg != NULL) { - fprintf (stderr, - "Failed to start daemon: `%s'\n", - emsg); + fprintf (stderr, "Failed to start daemon: `%s'\n", emsg); return; } GNUNET_assert (id != NULL); diff --git a/src/dht/test_dht_twopeer_get_put.c b/src/dht/test_dht_twopeer_get_put.c index 2a79c9ffb..d0da778ea 100644 --- a/src/dht/test_dht_twopeer_get_put.c +++ b/src/dht/test_dht_twopeer_get_put.c @@ -215,12 +215,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_size, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_size, - enum GNUNET_BLOCK_Type type, size_t size, - const void *result_data) + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_size, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_size, enum GNUNET_BLOCK_Type type, + size_t size, const void *result_data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -279,8 +278,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #else GNUNET_BLOCK_TYPE_TEST, #endif - &key, 1, GNUNET_DHT_RO_NONE, - NULL, 0, &get_result_iterator, NULL); + &key, 1, GNUNET_DHT_RO_NONE, NULL, 0, + &get_result_iterator, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL); } @@ -313,10 +312,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, - GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, - GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, - &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, + sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); } #else diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c index f2d86e38e..61a3df0a4 100644 --- a/src/dht/test_dht_twopeer_path_tracking.c +++ b/src/dht/test_dht_twopeer_path_tracking.c @@ -191,10 +191,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + 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) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -220,14 +220,14 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, if (put_path != NULL) { fprintf (stderr, "PUT Path: "); - for (i = 0; i", GNUNET_i2s (&put_path[i])); fprintf (stderr, "\n"); } if (get_path != NULL) { fprintf (stderr, "GET Path: "); - for (i = 0; i", GNUNET_i2s (&get_path[i])); fprintf (stderr, "\n"); } @@ -256,9 +256,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ global_get_handle = GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (), - GNUNET_BLOCK_TYPE_TEST, &key, - 1, GNUNET_DHT_RO_RECORD_ROUTE, - NULL, 0, &get_result_iterator, NULL); + GNUNET_BLOCK_TYPE_TEST, &key, 1, + GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, + &get_result_iterator, NULL); } /** @@ -274,10 +274,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, - GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST, - sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_RECORD_ROUTE, + GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, + GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, + &put_finished, NULL); } /** diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 44009c257..275a01a32 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c @@ -207,11 +207,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_size, + unsigned int get_path_size, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_size, - enum GNUNET_BLOCK_Type type, size_t size, - const void *result_data) + unsigned int put_path_size, enum GNUNET_BLOCK_Type type, + size_t size, const void *result_data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -254,10 +253,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ global_get_handle = - GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_BLOCK_TYPE_TEST, - &key, 1, GNUNET_DHT_RO_NONE, - NULL, 0, &get_result_iterator, NULL); + GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE, + NULL, 0, &get_result_iterator, NULL); } @@ -274,10 +272,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, - GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, - GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, - &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, + sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); } -- cgit v1.2.3