From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/fs/fs.h | 43 +- src/fs/fs_api.c | 3372 ++++++++++++++------------- src/fs/fs_api.h | 231 +- src/fs/fs_directory.c | 612 +++-- src/fs/fs_dirmetascan.c | 473 ++-- src/fs/fs_download.c | 2574 ++++++++++---------- src/fs/fs_file_information.c | 324 +-- src/fs/fs_getopt.c | 239 +- src/fs/fs_list_indexed.c | 134 +- src/fs/fs_misc.c | 198 +- src/fs/fs_namespace.c | 663 +++--- src/fs/fs_publish.c | 1659 +++++++------ src/fs/fs_publish_ksk.c | 151 +- src/fs/fs_publish_ublock.c | 247 +- src/fs/fs_publish_ublock.h | 38 +- src/fs/fs_search.c | 1622 ++++++------- src/fs/fs_sharetree.c | 259 +- src/fs/fs_test_lib.c | 424 ++-- src/fs/fs_test_lib.h | 38 +- src/fs/fs_tree.c | 264 ++- src/fs/fs_tree.h | 38 +- src/fs/fs_unindex.c | 862 +++---- src/fs/fs_uri.c | 1774 +++++++------- src/fs/gnunet-auto-share.c | 602 +++-- src/fs/gnunet-daemon-fsprofiler.c | 565 ++--- src/fs/gnunet-directory.c | 171 +- src/fs/gnunet-download.c | 446 ++-- src/fs/gnunet-fs-profiler.c | 150 +- src/fs/gnunet-fs.c | 108 +- src/fs/gnunet-helper-fs-publish.c | 404 ++-- src/fs/gnunet-publish.c | 1076 ++++----- src/fs/gnunet-search.c | 376 +-- src/fs/gnunet-service-fs.c | 1124 +++++---- src/fs/gnunet-service-fs.h | 24 +- src/fs/gnunet-service-fs_cadet.h | 36 +- src/fs/gnunet-service-fs_cadet_client.c | 427 ++-- src/fs/gnunet-service-fs_cadet_server.c | 457 ++-- src/fs/gnunet-service-fs_cp.c | 1451 ++++++------ src/fs/gnunet-service-fs_cp.h | 85 +- src/fs/gnunet-service-fs_indexing.c | 480 ++-- src/fs/gnunet-service-fs_indexing.h | 40 +- src/fs/gnunet-service-fs_pe.c | 629 +++-- src/fs/gnunet-service-fs_pe.h | 22 +- src/fs/gnunet-service-fs_pr.c | 1845 +++++++-------- src/fs/gnunet-service-fs_pr.h | 93 +- src/fs/gnunet-service-fs_push.c | 468 ++-- src/fs/gnunet-service-fs_push.h | 12 +- src/fs/gnunet-service-fs_put.c | 176 +- src/fs/gnunet-service-fs_put.h | 8 +- src/fs/gnunet-unindex.c | 161 +- src/fs/perf_gnunet_service_fs_p2p.c | 312 ++- src/fs/perf_gnunet_service_fs_p2p_respect.c | 378 ++- src/fs/plugin_block_fs.c | 287 +-- src/fs/test_fs.c | 249 +- src/fs/test_fs_directory.c | 171 +- src/fs/test_fs_download.c | 419 ++-- src/fs/test_fs_download_persistence.c | 375 +-- src/fs/test_fs_file_information.c | 124 +- src/fs/test_fs_getopt.c | 14 +- src/fs/test_fs_list_indexed.c | 276 +-- src/fs/test_fs_namespace.c | 327 +-- src/fs/test_fs_namespace_list_updateable.c | 115 +- src/fs/test_fs_publish.c | 262 ++- src/fs/test_fs_publish_persistence.c | 324 +-- src/fs/test_fs_search.c | 257 +- src/fs/test_fs_search_persistence.c | 317 +-- src/fs/test_fs_search_probes.c | 264 ++- src/fs/test_fs_search_with_and.c | 285 +-- src/fs/test_fs_start_stop.c | 28 +- src/fs/test_fs_test_lib.c | 149 +- src/fs/test_fs_unindex.c | 248 +- src/fs/test_fs_unindex_persistence.c | 321 +-- src/fs/test_fs_uri.c | 420 ++-- src/fs/test_gnunet_service_fs_migration.c | 213 +- src/fs/test_gnunet_service_fs_p2p.c | 142 +- src/fs/test_plugin_block_fs.c | 74 +- 76 files changed, 17069 insertions(+), 16957 deletions(-) (limited to 'src/fs') diff --git a/src/fs/fs.h b/src/fs/fs.h index 25bc95e62..294a433fc 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs.h @@ -50,8 +50,7 @@ /** * @brief content hash key */ -struct ContentHashKey -{ +struct ContentHashKey { /** * Hash of the original content, used for encryption. */ @@ -71,9 +70,7 @@ GNUNET_NETWORK_STRUCT_BEGIN * Message sent from a GNUnet (fs) publishing activity to sign * a LOC URI. */ -struct RequestLocSignatureMessage -{ - +struct RequestLocSignatureMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN. */ @@ -105,9 +102,7 @@ struct RequestLocSignatureMessage /** * Message sent from the service with the signed LOC URI. */ -struct ResponseLocSignatureMessage -{ - +struct ResponseLocSignatureMessage { /** * Message type will be * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE. @@ -150,9 +145,7 @@ struct ResponseLocSignatureMessage * computing it; this is an optimization that should be safe given * that the client is not our adversary). */ -struct IndexStartMessage -{ - +struct IndexStartMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START. */ @@ -188,7 +181,6 @@ struct IndexStartMessage /* this is followed by a 0-terminated * filename of a file with the hash * "file_id" as seen by the client */ - }; @@ -196,8 +188,7 @@ struct IndexStartMessage * Message send by FS service in response to a request * asking for a list of all indexed files. */ -struct IndexInfoMessage -{ +struct IndexInfoMessage { /** * Message type will be * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY. @@ -217,7 +208,6 @@ struct IndexInfoMessage /* this is followed by a 0-terminated * filename of a file with the hash * "file_id" as seen by the client */ - }; @@ -228,9 +218,7 @@ struct IndexInfoMessage * files and response with a confirmation message (even if the file * was already not on the list). */ -struct UnindexMessage -{ - +struct UnindexMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX. */ @@ -245,7 +233,6 @@ struct UnindexMessage * Hash of the file that we will unindex. */ struct GNUNET_HashCode file_id; - }; @@ -272,9 +259,7 @@ struct UnindexMessage * Message sent from a GNUnet (fs) search activity to the * gnunet-service-fs to start a search. */ -struct SearchMessage -{ - +struct SearchMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH. */ @@ -333,9 +318,7 @@ struct SearchMessage * single response are considered done. This message is transmitted * between peers. */ -struct PutMessage -{ - +struct PutMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. */ @@ -352,7 +335,6 @@ struct PutMessage struct GNUNET_TIME_AbsoluteNBO expiration; /* this is followed by the actual encrypted content */ - }; /** @@ -361,9 +343,7 @@ struct PutMessage * single response are considered done. This message is transmitted * between the service and a client. */ -struct ClientPutMessage -{ - +struct ClientPutMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. */ @@ -398,7 +378,6 @@ struct ClientPutMessage uint32_t respect_offered; /* this is followed by the actual encrypted content */ - }; GNUNET_NETWORK_STRUCT_END diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index f7b64a5c9..45051ddcb 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_api.c @@ -47,23 +47,23 @@ * @param qe job to start */ static void -start_job (struct GNUNET_FS_QueueEntry *qe) +start_job(struct GNUNET_FS_QueueEntry *qe) { qe->active = GNUNET_YES; - qe->start (qe->cls); + qe->start(qe->cls); qe->start_times++; qe->h->active_blocks += qe->blocks; qe->h->active_downloads++; - qe->start_time = GNUNET_TIME_absolute_get (); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting job %p (%u active)\n", - qe, - qe->h->active_downloads); - GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); - GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, - qe->h->running_tail, - qe->h->running_tail, - qe); + qe->start_time = GNUNET_TIME_absolute_get(); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting job %p (%u active)\n", + qe, + qe->h->active_downloads); + GNUNET_CONTAINER_DLL_remove(qe->h->pending_head, qe->h->pending_tail, qe); + GNUNET_CONTAINER_DLL_insert_after(qe->h->running_head, + qe->h->running_tail, + qe->h->running_tail, + qe); } @@ -74,25 +74,25 @@ start_job (struct GNUNET_FS_QueueEntry *qe) * @param qe job to stop */ static void -stop_job (struct GNUNET_FS_QueueEntry *qe) +stop_job(struct GNUNET_FS_QueueEntry *qe) { qe->active = GNUNET_NO; - qe->stop (qe->cls); - GNUNET_assert (0 < qe->h->active_downloads); + qe->stop(qe->cls); + GNUNET_assert(0 < qe->h->active_downloads); qe->h->active_downloads--; qe->h->active_blocks -= qe->blocks; - qe->run_time = GNUNET_TIME_relative_add (qe->run_time, - GNUNET_TIME_absolute_get_duration ( - qe->start_time)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stopping job %p (%u active)\n", - qe, - qe->h->active_downloads); - GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); - GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, - qe->h->pending_tail, - qe->h->pending_tail, - qe); + qe->run_time = GNUNET_TIME_relative_add(qe->run_time, + GNUNET_TIME_absolute_get_duration( + qe->start_time)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Stopping job %p (%u active)\n", + qe, + qe->h->active_downloads); + GNUNET_CONTAINER_DLL_remove(qe->h->running_head, qe->h->running_tail, qe); + GNUNET_CONTAINER_DLL_insert_after(qe->h->pending_head, + qe->h->pending_tail, + qe->h->pending_tail, + qe); } @@ -103,7 +103,7 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) * @param cls the `struct GNUNET_FS_Handle *` */ static void -process_job_queue (void *cls) +process_job_queue(void *cls) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_FS_QueueEntry *qe; @@ -131,20 +131,22 @@ process_job_queue (void *cls) num_probes_waiting = 0; num_downloads_waiting = 0; for (qe = h->pending_head; NULL != qe; qe = qe->next) - { - switch (qe->priority) { - case GNUNET_FS_QUEUE_PRIORITY_PROBE: - num_probes_waiting++; - break; - case GNUNET_FS_QUEUE_PRIORITY_NORMAL: - num_downloads_waiting++; - break; - default: - GNUNET_break (0); - break; + switch (qe->priority) + { + case GNUNET_FS_QUEUE_PRIORITY_PROBE: + num_probes_waiting++; + break; + + case GNUNET_FS_QUEUE_PRIORITY_NORMAL: + num_downloads_waiting++; + break; + + default: + GNUNET_break(0); + break; + } } - } /* now, calculate some basic statistics on running jobs */ num_probes_active = 0; num_probes_expired = 0; @@ -152,161 +154,165 @@ process_job_queue (void *cls) num_downloads_expired = 0; next = h->running_head; while (NULL != (qe = next)) - { - next = qe->next; - switch (qe->priority) - { - case GNUNET_FS_QUEUE_PRIORITY_PROBE: - run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); - end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); - rst = GNUNET_TIME_absolute_get_remaining (end_time); - if (0 == rst.rel_value_us) - { - num_probes_expired++; - stop_job (qe); - } - else - { - num_probes_active++; - restart_at = GNUNET_TIME_relative_min (rst, restart_at); - } - break; - case GNUNET_FS_QUEUE_PRIORITY_NORMAL: - run_time = - GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency, - qe->blocks * qe->start_times); - end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); - rst = GNUNET_TIME_absolute_get_remaining (end_time); - if (0 == rst.rel_value_us) - { - num_downloads_expired++; - stop_job (qe); - } - else - { - num_downloads_active++; - restart_at = GNUNET_TIME_relative_min (rst, restart_at); - } - break; - default: - GNUNET_break (0); - break; + { + next = qe->next; + switch (qe->priority) + { + case GNUNET_FS_QUEUE_PRIORITY_PROBE: + run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); + end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); + rst = GNUNET_TIME_absolute_get_remaining(end_time); + if (0 == rst.rel_value_us) + { + num_probes_expired++; + stop_job(qe); + } + else + { + num_probes_active++; + restart_at = GNUNET_TIME_relative_min(rst, restart_at); + } + break; + + case GNUNET_FS_QUEUE_PRIORITY_NORMAL: + run_time = + GNUNET_TIME_relative_saturating_multiply(h->avg_block_latency, + qe->blocks * qe->start_times); + end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); + rst = GNUNET_TIME_absolute_get_remaining(end_time); + if (0 == rst.rel_value_us) + { + num_downloads_expired++; + stop_job(qe); + } + else + { + num_downloads_active++; + restart_at = GNUNET_TIME_relative_min(rst, restart_at); + } + break; + + default: + GNUNET_break(0); + break; + } } - } - GNUNET_break (h->active_downloads == - num_downloads_active + num_probes_active); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", - num_probes_active, - num_probes_expired, - num_probes_waiting, - num_downloads_active, - num_downloads_expired, - num_downloads_waiting); - GNUNET_break (h->active_downloads + num_probes_active <= - h->max_parallel_downloads); + GNUNET_break(h->active_downloads == + num_downloads_active + num_probes_active); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", + num_probes_active, + num_probes_expired, + num_probes_waiting, + num_downloads_active, + num_downloads_expired, + num_downloads_waiting); + GNUNET_break(h->active_downloads + num_probes_active <= + h->max_parallel_downloads); /* calculate start/stop decisions */ if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) - { - /* stop as many probes as there are downloads and probes */ - num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); - /* start as many downloads as there are free slots, including those - we just opened up */ - num_downloads_change = - h->max_parallel_downloads - h->active_downloads - num_probes_change; - } + { + /* stop as many probes as there are downloads and probes */ + num_probes_change = -GNUNET_MIN(num_probes_active, num_downloads_waiting); + /* start as many downloads as there are free slots, including those + we just opened up */ + num_downloads_change = + h->max_parallel_downloads - h->active_downloads - num_probes_change; + } else - { - /* start all downloads (we can) */ - num_downloads_change = num_downloads_waiting; - /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ - if (1 + h->max_parallel_downloads / 4 >= - (h->active_downloads + num_downloads_change)) - num_probes_change = - GNUNET_MIN (num_probes_waiting, - (1 + h->max_parallel_downloads / 4) - - (h->active_downloads + num_downloads_change)); - else - num_probes_change = 0; - } - GNUNET_break (num_downloads_change <= num_downloads_waiting); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Changing %d probes and %d/%u/%u downloads\n", - num_probes_change, - num_downloads_change, - (unsigned int) h->active_downloads, - (unsigned int) h->max_parallel_downloads); + { + /* start all downloads (we can) */ + num_downloads_change = num_downloads_waiting; + /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ + if (1 + h->max_parallel_downloads / 4 >= + (h->active_downloads + num_downloads_change)) + num_probes_change = + GNUNET_MIN(num_probes_waiting, + (1 + h->max_parallel_downloads / 4) - + (h->active_downloads + num_downloads_change)); + else + num_probes_change = 0; + } + GNUNET_break(num_downloads_change <= num_downloads_waiting); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Changing %d probes and %d/%u/%u downloads\n", + num_probes_change, + num_downloads_change, + (unsigned int)h->active_downloads, + (unsigned int)h->max_parallel_downloads); /* actually stop probes */ next = h->running_head; while (NULL != (qe = next)) - { - next = qe->next; - if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) - continue; - if (num_probes_change < 0) { - stop_job (qe); - num_probes_change++; - if (0 == num_probes_change) - break; + next = qe->next; + if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) + continue; + if (num_probes_change < 0) + { + stop_job(qe); + num_probes_change++; + if (0 == num_probes_change) + break; + } } - } - GNUNET_break (0 <= num_probes_change); + GNUNET_break(0 <= num_probes_change); /* start some more tasks if we now have empty slots */ block_limit_hit = GNUNET_NO; next = h->pending_head; while ((NULL != (qe = next)) && ((num_probes_change > 0) || (num_downloads_change > 0))) - { - next = qe->next; - switch (qe->priority) - { - case GNUNET_FS_QUEUE_PRIORITY_PROBE: - if (num_probes_change > 0) - { - start_job (qe); - num_probes_change--; - run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); - restart_at = GNUNET_TIME_relative_min (run_time, restart_at); - } - break; - case GNUNET_FS_QUEUE_PRIORITY_NORMAL: - if ((num_downloads_change > 0) && - ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || - ((qe->blocks > h->max_parallel_requests) && - (0 == h->active_downloads)))) - { - start_job (qe); - num_downloads_change--; - } - else if (num_downloads_change > 0) - block_limit_hit = GNUNET_YES; - break; - default: - GNUNET_break (0); - break; + { + next = qe->next; + switch (qe->priority) + { + case GNUNET_FS_QUEUE_PRIORITY_PROBE: + if (num_probes_change > 0) + { + start_job(qe); + num_probes_change--; + run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); + restart_at = GNUNET_TIME_relative_min(run_time, restart_at); + } + break; + + case GNUNET_FS_QUEUE_PRIORITY_NORMAL: + if ((num_downloads_change > 0) && + ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || + ((qe->blocks > h->max_parallel_requests) && + (0 == h->active_downloads)))) + { + start_job(qe); + num_downloads_change--; + } + else if (num_downloads_change > 0) + block_limit_hit = GNUNET_YES; + break; + + default: + GNUNET_break(0); + break; + } } - } - GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); - GNUNET_break (0 == num_probes_change); + GNUNET_break((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); + GNUNET_break(0 == num_probes_change); - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", h->active_downloads, h->max_parallel_requests, num_probes_change, num_downloads_change, - GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string(restart_at, GNUNET_YES)); /* make sure we run again, callbacks might have already re-scheduled the job, so cancel such an operation (if it exists) */ if (NULL != h->queue_job) - GNUNET_SCHEDULER_cancel (h->queue_job); + GNUNET_SCHEDULER_cancel(h->queue_job); h->queue_job = - GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); + GNUNET_SCHEDULER_add_delayed(restart_at, &process_job_queue, h); } @@ -322,31 +328,31 @@ process_job_queue (void *cls) * @return queue handle */ struct GNUNET_FS_QueueEntry * -GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, - GNUNET_SCHEDULER_TaskCallback start, - GNUNET_SCHEDULER_TaskCallback stop, - void *cls, - unsigned int blocks, - enum GNUNET_FS_QueuePriority priority) +GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, + GNUNET_SCHEDULER_TaskCallback start, + GNUNET_SCHEDULER_TaskCallback stop, + void *cls, + unsigned int blocks, + enum GNUNET_FS_QueuePriority priority) { struct GNUNET_FS_QueueEntry *qe; - qe = GNUNET_new (struct GNUNET_FS_QueueEntry); + qe = GNUNET_new(struct GNUNET_FS_QueueEntry); qe->h = h; qe->start = start; qe->stop = stop; qe->cls = cls; - qe->queue_time = GNUNET_TIME_absolute_get (); + qe->queue_time = GNUNET_TIME_absolute_get(); qe->blocks = blocks; qe->priority = priority; - GNUNET_CONTAINER_DLL_insert_after (h->pending_head, - h->pending_tail, - h->pending_tail, - qe); + GNUNET_CONTAINER_DLL_insert_after(h->pending_head, + h->pending_tail, + h->pending_tail, + qe); if (NULL != h->queue_job) - GNUNET_SCHEDULER_cancel (h->queue_job); - h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); + GNUNET_SCHEDULER_cancel(h->queue_job); + h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); return qe; } @@ -357,19 +363,19 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, * @param qe handle for the job */ void -GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) +GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe) { struct GNUNET_FS_Handle *h; h = qe->h; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); if (GNUNET_YES == qe->active) - stop_job (qe); - GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); - GNUNET_free (qe); + stop_job(qe); + GNUNET_CONTAINER_DLL_remove(h->pending_head, h->pending_tail, qe); + GNUNET_free(qe); if (NULL != h->queue_job) - GNUNET_SCHEDULER_cancel (h->queue_job); - h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); + GNUNET_SCHEDULER_cancel(h->queue_job); + h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); } @@ -382,16 +388,16 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) * @return fresh top-level activity handle */ struct TopLevelActivity * -GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, - SuspendSignalFunction ssf, - void *ssf_cls) +GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, + SuspendSignalFunction ssf, + void *ssf_cls) { struct TopLevelActivity *ret; - ret = GNUNET_new (struct TopLevelActivity); + ret = GNUNET_new(struct TopLevelActivity); ret->ssf = ssf; ret->ssf_cls = ssf_cls; - GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); + GNUNET_CONTAINER_DLL_insert(h->top_head, h->top_tail, ret); return ret; } @@ -403,18 +409,17 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, * @param top top level activity entry */ void -GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) +GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) { - GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); - GNUNET_free (top); + GNUNET_CONTAINER_DLL_remove(h->top_head, h->top_tail, top); + GNUNET_free(top); } /** * Closure for #GNUNET_FS_data_reader_file_(). */ -struct FileInfo -{ +struct FileInfo { /** * Name of the file to read. */ @@ -448,63 +453,63 @@ struct FileInfo * @return number of bytes written, usually @a max, 0 on error */ size_t -GNUNET_FS_data_reader_file_ (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg) +GNUNET_FS_data_reader_file_(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg) { struct FileInfo *fi = cls; ssize_t ret; if (UINT64_MAX == offset) - { - if (NULL != fi->fd) { - GNUNET_DISK_file_close (fi->fd); - fi->fd = NULL; + if (NULL != fi->fd) + { + GNUNET_DISK_file_close(fi->fd); + fi->fd = NULL; + } + return 0; } - return 0; - } if (0 == max) - { - if (NULL != fi->fd) - GNUNET_DISK_file_close (fi->fd); - GNUNET_free (fi->filename); - GNUNET_free (fi); - return 0; - } - if (NULL == fi->fd) - { - fi->fd = GNUNET_DISK_file_open (fi->filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - if (NULL == fi->fd) - { - GNUNET_asprintf (emsg, - _ ("Could not open file `%s': %s"), - fi->filename, - strerror (errno)); + { + if (NULL != fi->fd) + GNUNET_DISK_file_close(fi->fd); + GNUNET_free(fi->filename); + GNUNET_free(fi); return 0; } - } + if (NULL == fi->fd) + { + fi->fd = GNUNET_DISK_file_open(fi->filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); + if (NULL == fi->fd) + { + GNUNET_asprintf(emsg, + _("Could not open file `%s': %s"), + fi->filename, + strerror(errno)); + return 0; + } + } if ((GNUNET_SYSERR == - GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || - (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) - { - GNUNET_asprintf (emsg, - _ ("Could not read file `%s': %s"), - fi->filename, - strerror (errno)); - return 0; - } + GNUNET_DISK_file_seek(fi->fd, offset, GNUNET_DISK_SEEK_SET)) || + (-1 == (ret = GNUNET_DISK_file_read(fi->fd, buf, max)))) + { + GNUNET_asprintf(emsg, + _("Could not read file `%s': %s"), + fi->filename, + strerror(errno)); + return 0; + } if (ret != max) - { - GNUNET_asprintf (emsg, - _ ("Short read reading from file `%s'!"), - fi->filename); - return 0; - } + { + GNUNET_asprintf(emsg, + _("Short read reading from file `%s'!"), + fi->filename); + return 0; + } return max; } @@ -516,17 +521,17 @@ GNUNET_FS_data_reader_file_ (void *cls, * @return closure to use, NULL on error */ void * -GNUNET_FS_make_file_reader_context_ (const char *filename) +GNUNET_FS_make_file_reader_context_(const char *filename) { struct FileInfo *fi; - fi = GNUNET_new (struct FileInfo); - fi->filename = GNUNET_STRINGS_filename_expand (filename); + fi = GNUNET_new(struct FileInfo); + fi->filename = GNUNET_STRINGS_filename_expand(filename); if (NULL == fi->filename) - { - GNUNET_free (fi); - return NULL; - } + { + GNUNET_free(fi); + return NULL; + } return fi; } @@ -552,22 +557,22 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) * @return number of bytes written, usually @a max, 0 on error */ size_t -GNUNET_FS_data_reader_copy_ (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg) +GNUNET_FS_data_reader_copy_(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg) { char *data = cls; if (UINT64_MAX == offset) return 0; if (0 == max) - { - GNUNET_free_non_null (data); - return 0; - } - GNUNET_memcpy (buf, &data[offset], max); + { + GNUNET_free_non_null(data); + return 0; + } + GNUNET_memcpy(buf, &data[offset], max); return max; } @@ -582,30 +587,30 @@ GNUNET_FS_data_reader_copy_ (void *cls, * @return NULL on error */ static char * -get_serialization_file_name (struct GNUNET_FS_Handle *h, - const char *ext, - const char *ent) +get_serialization_file_name(struct GNUNET_FS_Handle *h, + const char *ext, + const char *ent) { char *basename; char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, - "fs", - "STATE_DIR", - &basename)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, + "fs", + "STATE_DIR", + &basename)) return NULL; - GNUNET_asprintf (&ret, - "%s%s%s%s%s%s%s", - basename, - DIR_SEPARATOR_STR, - h->client_name, - DIR_SEPARATOR_STR, - ext, - DIR_SEPARATOR_STR, - ent); - GNUNET_free (basename); + GNUNET_asprintf(&ret, + "%s%s%s%s%s%s%s", + basename, + DIR_SEPARATOR_STR, + h->client_name, + DIR_SEPARATOR_STR, + ext, + DIR_SEPARATOR_STR, + ent); + GNUNET_free(basename); return ret; } @@ -622,33 +627,33 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, * @return NULL on error */ static char * -get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni, - const char *ent) +get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni, + const char *ent) { char *basename; char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, - "fs", - "STATE_DIR", - &basename)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, + "fs", + "STATE_DIR", + &basename)) return NULL; - GNUNET_asprintf (&ret, - "%s%s%s%s%s%s%s.dir%s%s", - basename, - DIR_SEPARATOR_STR, - h->client_name, - DIR_SEPARATOR_STR, - ext, - DIR_SEPARATOR_STR, - uni, - DIR_SEPARATOR_STR, - ent); - GNUNET_free (basename); + GNUNET_asprintf(&ret, + "%s%s%s%s%s%s%s.dir%s%s", + basename, + DIR_SEPARATOR_STR, + h->client_name, + DIR_SEPARATOR_STR, + ext, + DIR_SEPARATOR_STR, + uni, + DIR_SEPARATOR_STR, + ent); + GNUNET_free(basename); return ret; } @@ -662,16 +667,16 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, * @return NULL on error */ static struct GNUNET_BIO_ReadHandle * -get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) +get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) { char *fn; struct GNUNET_BIO_ReadHandle *ret; - fn = get_serialization_file_name (h, ext, ent); + fn = get_serialization_file_name(h, ext, ent); if (NULL == fn) return NULL; - ret = GNUNET_BIO_read_open (fn); - GNUNET_free (fn); + ret = GNUNET_BIO_read_open(fn); + GNUNET_free(fn); return ret; } @@ -685,17 +690,17 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) * @return NULL on error */ static struct GNUNET_BIO_WriteHandle * -get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) +get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) { char *fn; struct GNUNET_BIO_WriteHandle *ret; - fn = get_serialization_file_name (h, ext, ent); + fn = get_serialization_file_name(h, ext, ent); if (NULL == fn) return NULL; - ret = GNUNET_BIO_write_open (fn); - GNUNET_break (NULL != ret); - GNUNET_free (fn); + ret = GNUNET_BIO_write_open(fn); + GNUNET_break(NULL != ret); + GNUNET_free(fn); return ret; } @@ -710,19 +715,19 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) * @return NULL on error */ static struct GNUNET_BIO_WriteHandle * -get_write_handle_in_dir (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni, - const char *ent) +get_write_handle_in_dir(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni, + const char *ent) { char *fn; struct GNUNET_BIO_WriteHandle *ret; - fn = get_serialization_file_name_in_dir (h, ext, uni, ent); + fn = get_serialization_file_name_in_dir(h, ext, uni, ent); if (NULL == fn) return NULL; - ret = GNUNET_BIO_write_open (fn); - GNUNET_free (fn); + ret = GNUNET_BIO_write_open(fn); + GNUNET_free(fn); return ret; } @@ -735,24 +740,24 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h, * @param ent entity identifier */ void -GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, - const char *ext, - const char *ent) +GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, + const char *ext, + const char *ent) { char *filename; - if ((NULL == ent) || (0 == strlen (ent))) - { - GNUNET_break (0); - return; - } - filename = get_serialization_file_name (h, ext, ent); + if ((NULL == ent) || (0 == strlen(ent))) + { + GNUNET_break(0); + return; + } + filename = get_serialization_file_name(h, ext, ent); if (NULL != filename) - { - if ((0 != unlink (filename)) && (ENOENT != errno)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); - GNUNET_free (filename); - } + { + if ((0 != unlink(filename)) && (ENOENT != errno)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); + GNUNET_free(filename); + } } @@ -765,24 +770,24 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, * @param ent entity identifier */ static void -remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni, - const char *ent) +remove_sync_file_in_dir(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni, + const char *ent) { char *filename; - if ((NULL == ent) || (0 == strlen (ent))) - { - GNUNET_break (0); - return; - } - filename = get_serialization_file_name_in_dir (h, ext, uni, ent); + if ((NULL == ent) || (0 == strlen(ent))) + { + GNUNET_break(0); + return; + } + filename = get_serialization_file_name_in_dir(h, ext, uni, ent); if (NULL == filename) return; - if (0 != unlink (filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); - GNUNET_free (filename); + if (0 != unlink(filename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); + GNUNET_free(filename); } @@ -794,21 +799,21 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, * @param uni unique name of parent */ void -GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni) +GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni) { char *dn; if (NULL == uni) return; - dn = get_serialization_file_name_in_dir (h, ext, uni, ""); + dn = get_serialization_file_name_in_dir(h, ext, uni, ""); if (NULL == dn) return; - if ((GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) && - (GNUNET_OK != GNUNET_DISK_directory_remove (dn))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); - GNUNET_free (dn); + if ((GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) && + (GNUNET_OK != GNUNET_DISK_directory_remove(dn))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); + GNUNET_free(dn); } @@ -827,13 +832,13 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, * @return #GNUNET_OK on success */ static int -write_start_time (struct GNUNET_BIO_WriteHandle *wh, - struct GNUNET_TIME_Absolute timestamp) +write_start_time(struct GNUNET_BIO_WriteHandle *wh, + struct GNUNET_TIME_Absolute timestamp) { struct GNUNET_TIME_Relative dur; - dur = GNUNET_TIME_absolute_get_duration (timestamp); - return GNUNET_BIO_write_int64 (wh, dur.rel_value_us); + dur = GNUNET_TIME_absolute_get_duration(timestamp); + return GNUNET_BIO_write_int64(wh, dur.rel_value_us); } @@ -852,14 +857,14 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh, * @return #GNUNET_OK on success */ static int -read_start_time (struct GNUNET_BIO_ReadHandle *rh, - struct GNUNET_TIME_Absolute *timestamp) +read_start_time(struct GNUNET_BIO_ReadHandle *rh, + struct GNUNET_TIME_Absolute *timestamp) { struct GNUNET_TIME_Relative dur; - if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us)) + if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dur.rel_value_us)) return GNUNET_SYSERR; - *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); + *timestamp = GNUNET_TIME_absolute_subtract(GNUNET_TIME_absolute_get(), dur); return GNUNET_OK; } @@ -874,7 +879,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, * @return NULL on error */ static struct GNUNET_FS_FileInformation * -deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); +deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename); /** @@ -888,9 +893,9 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); * @return NULL on error */ static struct GNUNET_FS_FileInformation * -deserialize_fi_node (struct GNUNET_FS_Handle *h, - const char *fn, - struct GNUNET_BIO_ReadHandle *rh) +deserialize_fi_node(struct GNUNET_FS_Handle *h, + const char *fn, + struct GNUNET_BIO_ReadHandle *rh) { struct GNUNET_FS_FileInformation *ret; struct GNUNET_FS_FileInformation *nxt; @@ -901,204 +906,209 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, char *filename; uint32_t dsize; - if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b))) - { - GNUNET_break (0); - return NULL; - } - ret = GNUNET_new (struct GNUNET_FS_FileInformation); + if (GNUNET_OK != GNUNET_BIO_read(rh, "status flag", &b, sizeof(b))) + { + GNUNET_break(0); + return NULL; + } + ret = GNUNET_new(struct GNUNET_FS_FileInformation); ret->h = h; ksks = NULL; chks = NULL; skss = NULL; filename = NULL; - if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || + if ((GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "metadata", &ret->meta)) || + (GNUNET_OK != GNUNET_BIO_read_string(rh, "ksk-uri", &ksks, 32 * 1024)) || ((NULL != ksks) && - ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || + ((NULL == (ret->keywords = GNUNET_FS_uri_parse(ksks, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_ksk(ret->keywords)))) || + (GNUNET_OK != GNUNET_BIO_read_string(rh, "chk-uri", &chks, 1024)) || ((NULL != chks) && - ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || + ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse(chks, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_chk(ret->chk_uri)))) || + (GNUNET_OK != GNUNET_BIO_read_string(rh, "sks-uri", &skss, 1024)) || ((NULL != skss) && - ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || - (GNUNET_OK != read_start_time (rh, &ret->start_time)) || + ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse(skss, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_sks(ret->sks_uri)))) || + (GNUNET_OK != read_start_time(rh, &ret->start_time)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || + GNUNET_BIO_read_string(rh, "emsg", &ret->emsg, 16 * 1024)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || + GNUNET_BIO_read_string(rh, "fn", &ret->filename, 16 * 1024)) || (GNUNET_OK != - GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) - { - GNUNET_break (0); - goto cleanup; - } - switch (b) - { - case 0: /* file-insert */ - if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) + GNUNET_BIO_read_int64(rh, &ret->bo.expiration_time.abs_value_us)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.anonymity_level)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.content_priority)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.replication_level))) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - ret->is_directory = GNUNET_NO; - ret->data.file.do_index = GNUNET_NO; - ret->data.file.have_hash = GNUNET_NO; - ret->data.file.index_start_confirmed = GNUNET_NO; - if (GNUNET_NO == ret->is_published) + switch (b) { + case 0: /* file-insert */ + if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) + { + GNUNET_break(0); + goto cleanup; + } + ret->is_directory = GNUNET_NO; + ret->data.file.do_index = GNUNET_NO; + ret->data.file.have_hash = GNUNET_NO; + ret->data.file.index_start_confirmed = GNUNET_NO; + if (GNUNET_NO == ret->is_published) + { + if (NULL == ret->filename) + { + ret->data.file.reader = &GNUNET_FS_data_reader_copy_; + ret->data.file.reader_cls = + GNUNET_malloc_large(ret->data.file.file_size); + if (ret->data.file.reader_cls == NULL) + goto cleanup; + if (GNUNET_OK != GNUNET_BIO_read(rh, + "file-data", + ret->data.file.reader_cls, + ret->data.file.file_size)) + { + GNUNET_break(0); + goto cleanup; + } + } + else + { + ret->data.file.reader = &GNUNET_FS_data_reader_file_; + ret->data.file.reader_cls = + GNUNET_FS_make_file_reader_context_(ret->filename); + } + } + break; + + case 1: /* file-index, no hash */ + if (NULL == ret->filename) + { + GNUNET_break(0); + goto cleanup; + } + if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) + { + GNUNET_break(0); + goto cleanup; + } + ret->is_directory = GNUNET_NO; + ret->data.file.do_index = GNUNET_YES; + ret->data.file.have_hash = GNUNET_NO; + ret->data.file.index_start_confirmed = GNUNET_NO; + ret->data.file.reader = &GNUNET_FS_data_reader_file_; + ret->data.file.reader_cls = + GNUNET_FS_make_file_reader_context_(ret->filename); + break; + + case 2: /* file-index-with-hash */ if (NULL == ret->filename) - { - ret->data.file.reader = &GNUNET_FS_data_reader_copy_; - ret->data.file.reader_cls = - GNUNET_malloc_large (ret->data.file.file_size); - if (ret->data.file.reader_cls == NULL) + { + GNUNET_break(0); goto cleanup; - if (GNUNET_OK != GNUNET_BIO_read (rh, - "file-data", - ret->data.file.reader_cls, - ret->data.file.file_size)) + } + if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || + (GNUNET_OK != GNUNET_BIO_read(rh, + "fileid", + &ret->data.file.file_id, + sizeof(struct GNUNET_HashCode)))) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - } - else - { - ret->data.file.reader = &GNUNET_FS_data_reader_file_; - ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); - } - } - break; - case 1: /* file-index, no hash */ - if (NULL == ret->filename) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) - { - GNUNET_break (0); - goto cleanup; - } - ret->is_directory = GNUNET_NO; - ret->data.file.do_index = GNUNET_YES; - ret->data.file.have_hash = GNUNET_NO; - ret->data.file.index_start_confirmed = GNUNET_NO; - ret->data.file.reader = &GNUNET_FS_data_reader_file_; - ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); - break; - case 2: /* file-index-with-hash */ - if (NULL == ret->filename) - { - GNUNET_break (0); - goto cleanup; - } - if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || - (GNUNET_OK != GNUNET_BIO_read (rh, - "fileid", - &ret->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) - { - GNUNET_break (0); - goto cleanup; - } - ret->is_directory = GNUNET_NO; - ret->data.file.do_index = GNUNET_YES; - ret->data.file.have_hash = GNUNET_YES; - ret->data.file.index_start_confirmed = GNUNET_NO; - ret->data.file.reader = &GNUNET_FS_data_reader_file_; - ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); - break; - case 3: /* file-index-with-hash-confirmed */ - if (NULL == ret->filename) - { - GNUNET_break (0); + ret->is_directory = GNUNET_NO; + ret->data.file.do_index = GNUNET_YES; + ret->data.file.have_hash = GNUNET_YES; + ret->data.file.index_start_confirmed = GNUNET_NO; + ret->data.file.reader = &GNUNET_FS_data_reader_file_; + ret->data.file.reader_cls = + GNUNET_FS_make_file_reader_context_(ret->filename); + break; + + case 3: /* file-index-with-hash-confirmed */ + if (NULL == ret->filename) + { + GNUNET_break(0); + goto cleanup; + } + if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || + (GNUNET_OK != GNUNET_BIO_read(rh, + "fileid", + &ret->data.file.file_id, + sizeof(struct GNUNET_HashCode)))) + { + GNUNET_break(0); + goto cleanup; + } + ret->is_directory = GNUNET_NO; + ret->data.file.do_index = GNUNET_YES; + ret->data.file.have_hash = GNUNET_YES; + ret->data.file.index_start_confirmed = GNUNET_YES; + ret->data.file.reader = &GNUNET_FS_data_reader_file_; + ret->data.file.reader_cls = + GNUNET_FS_make_file_reader_context_(ret->filename); + break; + + case 4: /* directory */ + ret->is_directory = GNUNET_YES; + if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dsize)) || + (GNUNET_OK != + GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_completed)) || + (GNUNET_OK != + GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_size)) || + (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large(dsize))) || + (GNUNET_OK != + GNUNET_BIO_read(rh, "dir-data", ret->data.dir.dir_data, dsize)) || + (GNUNET_OK != + GNUNET_BIO_read_string(rh, "ent-filename", &filename, 16 * 1024))) + { + GNUNET_break(0); + goto cleanup; + } + ret->data.dir.dir_size = (uint32_t)dsize; + if (NULL != filename) + { + ret->data.dir.entries = deserialize_file_information(h, filename); + GNUNET_free(filename); + filename = NULL; + nxt = ret->data.dir.entries; + while (NULL != nxt) + { + nxt->dir = ret; + nxt = nxt->next; + } + } + break; + + default: + GNUNET_break(0); goto cleanup; } - if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || - (GNUNET_OK != GNUNET_BIO_read (rh, - "fileid", - &ret->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) + ret->serialization = GNUNET_strdup(fn); + if (GNUNET_OK != + GNUNET_BIO_read_string(rh, "nxt-filename", &filename, 16 * 1024)) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - ret->is_directory = GNUNET_NO; - ret->data.file.do_index = GNUNET_YES; - ret->data.file.have_hash = GNUNET_YES; - ret->data.file.index_start_confirmed = GNUNET_YES; - ret->data.file.reader = &GNUNET_FS_data_reader_file_; - ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); - break; - case 4: /* directory */ - ret->is_directory = GNUNET_YES; - if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || - (GNUNET_OK != - GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || - (GNUNET_OK != - GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || - (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || - (GNUNET_OK != - GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || - (GNUNET_OK != - GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024))) - { - GNUNET_break (0); - goto cleanup; - } - ret->data.dir.dir_size = (uint32_t) dsize; - if (NULL != filename) + if (NULL != filename) { - ret->data.dir.entries = deserialize_file_information (h, filename); - GNUNET_free (filename); + ret->next = deserialize_file_information(h, filename); + GNUNET_free(filename); filename = NULL; - nxt = ret->data.dir.entries; - while (NULL != nxt) - { - nxt->dir = ret; - nxt = nxt->next; - } - } - break; - default: - GNUNET_break (0); - goto cleanup; - } - ret->serialization = GNUNET_strdup (fn); - if (GNUNET_OK != - GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024)) - { - GNUNET_break (0); - goto cleanup; - } - if (NULL != filename) - { - ret->next = deserialize_file_information (h, filename); - GNUNET_free (filename); - filename = NULL; - } - GNUNET_free_non_null (ksks); - GNUNET_free_non_null (skss); - GNUNET_free_non_null (chks); + } + GNUNET_free_non_null(ksks); + GNUNET_free_non_null(skss); + GNUNET_free_non_null(chks); return ret; cleanup: - GNUNET_free_non_null (ksks); - GNUNET_free_non_null (chks); - GNUNET_free_non_null (skss); - GNUNET_free_non_null (filename); - GNUNET_FS_file_information_destroy (ret, NULL, NULL); + GNUNET_free_non_null(ksks); + GNUNET_free_non_null(chks); + GNUNET_free_non_null(skss); + GNUNET_free_non_null(filename); + GNUNET_FS_file_information_destroy(ret, NULL, NULL); return NULL; } @@ -1113,36 +1123,36 @@ cleanup: * @return NULL on error */ static struct GNUNET_FS_FileInformation * -deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) +deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename) { struct GNUNET_FS_FileInformation *ret; struct GNUNET_BIO_ReadHandle *rh; char *emsg; char *fn; - rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); + rh = get_read_handle(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); if (NULL == rh) return NULL; - ret = deserialize_fi_node (h, filename, rh); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume publishing information `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + ret = deserialize_fi_node(h, filename, rh); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume publishing information `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } if (NULL == ret) - { - fn = - get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); - if (NULL != fn) { - if (0 != unlink (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); - GNUNET_free (fn); + fn = + get_serialization_file_name(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); + if (NULL != fn) + { + if (0 != unlink(fn)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + GNUNET_free(fn); + } } - } return ret; } @@ -1156,7 +1166,7 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) * @return copy of the basename, NULL on error */ static char * -get_serialization_short_name (const char *fullname) +get_serialization_short_name(const char *fullname) { const char *end; const char *nxt; @@ -1166,18 +1176,18 @@ get_serialization_short_name (const char *fullname) /* FIXME: we could do this faster since we know * the length of 'end'... */ while ('\0' != *nxt) - { - if (DIR_SEPARATOR == *nxt) - end = nxt + 1; - nxt++; - } - if ((NULL == end) || (0 == strlen (end))) - { - GNUNET_break (0); - return NULL; - } - GNUNET_break (6 == strlen (end)); - return GNUNET_strdup (end); + { + if (DIR_SEPARATOR == *nxt) + end = nxt + 1; + nxt++; + } + if ((NULL == end) || (0 == strlen(end))) + { + GNUNET_break(0); + return NULL; + } + GNUNET_break(6 == strlen(end)); + return GNUNET_strdup(end); } @@ -1190,7 +1200,7 @@ get_serialization_short_name (const char *fullname) * @return NULL on errror */ static char * -make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) +make_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext) { char *fn; char *dn; @@ -1198,20 +1208,20 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ - dn = get_serialization_file_name (h, ext, ""); + dn = get_serialization_file_name(h, ext, ""); if (NULL == dn) return NULL; - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) - { - GNUNET_free (dn); - return NULL; - } - fn = GNUNET_DISK_mktemp (dn); - GNUNET_free (dn); + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) + { + GNUNET_free(dn); + return NULL; + } + fn = GNUNET_DISK_mktemp(dn); + GNUNET_free(dn); if (NULL == fn) return NULL; /* epic fail */ - ret = get_serialization_short_name (fn); - GNUNET_free (fn); + ret = get_serialization_short_name(fn); + GNUNET_free(fn); return ret; } @@ -1226,9 +1236,9 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) * @return NULL on errror */ static char * -make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni) +make_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni) { char *fn; char *dn; @@ -1236,20 +1246,20 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ - dn = get_serialization_file_name_in_dir (h, ext, uni, ""); + dn = get_serialization_file_name_in_dir(h, ext, uni, ""); if (NULL == dn) return NULL; - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) - { - GNUNET_free (dn); - return NULL; - } - fn = GNUNET_DISK_mktemp (dn); - GNUNET_free (dn); + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) + { + GNUNET_free(dn); + return NULL; + } + fn = GNUNET_DISK_mktemp(dn); + GNUNET_free(dn); if (NULL == fn) return NULL; /* epic fail */ - ret = get_serialization_short_name (fn); - GNUNET_free (fn); + ret = get_serialization_short_name(fn); + GNUNET_free(fn); return ret; } @@ -1262,8 +1272,8 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, * @return #GNUNET_OK on success */ static int -copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, - struct GNUNET_FS_FileInformation *fi) +copy_from_reader(struct GNUNET_BIO_WriteHandle *wh, + struct GNUNET_FS_FileInformation *fi) { char buf[32 * 1024]; uint64_t off; @@ -1274,19 +1284,19 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, emsg = NULL; off = 0; while (off < fi->data.file.file_size) - { - left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); - ret = - fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); - if (0 == ret) - { - GNUNET_free (emsg); - return GNUNET_SYSERR; - } - if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) - return GNUNET_SYSERR; - off += ret; - } + { + left = GNUNET_MIN(sizeof(buf), fi->data.file.file_size - off); + ret = + fi->data.file.reader(fi->data.file.reader_cls, off, left, buf, &emsg); + if (0 == ret) + { + GNUNET_free(emsg); + return GNUNET_SYSERR; + } + if (GNUNET_OK != GNUNET_BIO_write(wh, buf, ret)) + return GNUNET_SYSERR; + off += ret; + } return GNUNET_OK; } @@ -1298,7 +1308,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, * @param fi file information to sync with disk */ void -GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) +GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *fi) { char *fn; struct GNUNET_BIO_WriteHandle *wh; @@ -1309,17 +1319,17 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) if (NULL == fi->serialization) fi->serialization = - make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); + make_serialization_file_name(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); if (NULL == fi->serialization) return; wh = - get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); + get_write_handle(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); if (NULL == wh) - { - GNUNET_free (fi->serialization); - fi->serialization = NULL; - return; - } + { + GNUNET_free(fi->serialization); + fi->serialization = NULL; + return; + } if (GNUNET_YES == fi->is_directory) b = 4; else if (GNUNET_YES == fi->data.file.index_start_confirmed) @@ -1331,143 +1341,147 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) else b = 0; if (NULL != fi->keywords) - ksks = GNUNET_FS_uri_to_string (fi->keywords); + ksks = GNUNET_FS_uri_to_string(fi->keywords); else ksks = NULL; if (NULL != fi->chk_uri) - chks = GNUNET_FS_uri_to_string (fi->chk_uri); + chks = GNUNET_FS_uri_to_string(fi->chk_uri); else chks = NULL; if (NULL != fi->sks_uri) - skss = GNUNET_FS_uri_to_string (fi->sks_uri); + skss = GNUNET_FS_uri_to_string(fi->sks_uri); else skss = NULL; - if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof (b))) || - (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) || - (GNUNET_OK != write_start_time (wh, fi->start_time)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) || + if ((GNUNET_OK != GNUNET_BIO_write(wh, &b, sizeof(b))) || + (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, fi->meta)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, ksks)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, chks)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, skss)) || + (GNUNET_OK != write_start_time(wh, fi->start_time)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->emsg)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->filename)) || (GNUNET_OK != - GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) - { - GNUNET_break (0); - goto cleanup; - } - GNUNET_free_non_null (chks); + GNUNET_BIO_write_int64(wh, fi->bo.expiration_time.abs_value_us)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.anonymity_level)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.content_priority)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.replication_level))) + { + GNUNET_break(0); + goto cleanup; + } + GNUNET_free_non_null(chks); chks = NULL; - GNUNET_free_non_null (ksks); + GNUNET_free_non_null(ksks); ksks = NULL; - GNUNET_free_non_null (skss); + GNUNET_free_non_null(skss); skss = NULL; switch (b) - { - case 0: /* file-insert */ - if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) - { - GNUNET_break (0); - goto cleanup; - } - if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) - if (GNUNET_OK != copy_from_reader (wh, fi)) - { - GNUNET_break (0); - goto cleanup; - } - break; - case 1: /* file-index, no hash */ - if (NULL == fi->filename) { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) - { - GNUNET_break (0); + case 0: /* file-insert */ + if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) + { + GNUNET_break(0); + goto cleanup; + } + if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) + if (GNUNET_OK != copy_from_reader(wh, fi)) + { + GNUNET_break(0); + goto cleanup; + } + break; + + case 1: /* file-index, no hash */ + if (NULL == fi->filename) + { + GNUNET_break(0); + goto cleanup; + } + if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) + { + GNUNET_break(0); + goto cleanup; + } + break; + + case 2: /* file-index-with-hash */ + case 3: /* file-index-with-hash-confirmed */ + if (NULL == fi->filename) + { + GNUNET_break(0); + goto cleanup; + } + if ((GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) || + (GNUNET_OK != GNUNET_BIO_write(wh, + &fi->data.file.file_id, + sizeof(struct GNUNET_HashCode)))) + { + GNUNET_break(0); + goto cleanup; + } + break; + + case 4: /* directory */ + if ((NULL != fi->data.dir.entries) && + (NULL == fi->data.dir.entries->serialization)) + GNUNET_FS_file_information_sync_(fi->data.dir.entries); + if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->data.dir.dir_size)) || + (GNUNET_OK != + GNUNET_BIO_write_int64(wh, fi->data.dir.contents_completed)) || + (GNUNET_OK != + GNUNET_BIO_write_int64(wh, fi->data.dir.contents_size)) || + (GNUNET_OK != GNUNET_BIO_write(wh, + fi->data.dir.dir_data, + (uint32_t)fi->data.dir.dir_size)) || + (GNUNET_OK != + GNUNET_BIO_write_string(wh, + (fi->data.dir.entries == NULL) + ? NULL + : fi->data.dir.entries->serialization))) + { + GNUNET_break(0); + goto cleanup; + } + break; + + default: + GNUNET_assert(0); goto cleanup; } - break; - case 2: /* file-index-with-hash */ - case 3: /* file-index-with-hash-confirmed */ - if (NULL == fi->filename) + if ((NULL != fi->next) && (NULL == fi->next->serialization)) + GNUNET_FS_file_information_sync_(fi->next); + if (GNUNET_OK != GNUNET_BIO_write_string(wh, + (fi->next != NULL) + ? fi->next->serialization + : NULL)) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || - (GNUNET_OK != GNUNET_BIO_write (wh, - &fi->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) { - GNUNET_break (0); + wh = NULL; + GNUNET_break(0); goto cleanup; } - break; - case 4: /* directory */ - if ((NULL != fi->data.dir.entries) && - (NULL == fi->data.dir.entries->serialization)) - GNUNET_FS_file_information_sync_ (fi->data.dir.entries); - if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || - (GNUNET_OK != - GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || - (GNUNET_OK != - GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || - (GNUNET_OK != GNUNET_BIO_write (wh, - fi->data.dir.dir_data, - (uint32_t) fi->data.dir.dir_size)) || - (GNUNET_OK != - GNUNET_BIO_write_string (wh, - (fi->data.dir.entries == NULL) - ? NULL - : fi->data.dir.entries->serialization))) - { - GNUNET_break (0); - goto cleanup; - } - break; - default: - GNUNET_assert (0); - goto cleanup; - } - if ((NULL != fi->next) && (NULL == fi->next->serialization)) - GNUNET_FS_file_information_sync_ (fi->next); - if (GNUNET_OK != GNUNET_BIO_write_string (wh, - (fi->next != NULL) - ? fi->next->serialization - : NULL)) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } return; /* done! */ cleanup: if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - GNUNET_free_non_null (chks); - GNUNET_free_non_null (ksks); - GNUNET_free_non_null (skss); - fn = get_serialization_file_name (fi->h, - GNUNET_FS_SYNC_PATH_FILE_INFO, - fi->serialization); + (void)GNUNET_BIO_write_close(wh); + GNUNET_free_non_null(chks); + GNUNET_free_non_null(ksks); + GNUNET_free_non_null(skss); + fn = get_serialization_file_name(fi->h, + GNUNET_FS_SYNC_PATH_FILE_INFO, + fi->serialization); if (NULL != fn) - { - if (0 != unlink (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); - GNUNET_free (fn); - } - GNUNET_free (fi->serialization); + { + if (0 != unlink(fn)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + GNUNET_free(fn); + } + GNUNET_free(fi->serialization); fi->serialization = NULL; } @@ -1481,19 +1495,19 @@ cleanup: * @return NULL if srch was not found in this subtree */ static struct GNUNET_FS_FileInformation * -find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) +find_file_position(struct GNUNET_FS_FileInformation *pos, const char *srch) { struct GNUNET_FS_FileInformation *r; while (NULL != pos) - { - if (0 == strcmp (srch, pos->serialization)) - return pos; - if ((GNUNET_YES == pos->is_directory) && - (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) - return r; - pos = pos->next; - } + { + if (0 == strcmp(srch, pos->serialization)) + return pos; + if ((GNUNET_YES == pos->is_directory) && + (NULL != (r = find_file_position(pos->data.dir.entries, srch)))) + return r; + pos = pos->next; + } return NULL; } @@ -1513,33 +1527,33 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) * @return #GNUNET_OK to continue (always) */ static int -fip_signal_resume (void *cls, - struct GNUNET_FS_FileInformation *fi, - uint64_t length, - struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, - int *do_index, - void **client_info) +fip_signal_resume(void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, + void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; if (GNUNET_YES == pc->skip_next_fi_callback) - { - pc->skip_next_fi_callback = GNUNET_NO; - return GNUNET_OK; - } + { + pc->skip_next_fi_callback = GNUNET_NO; + return GNUNET_OK; + } pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME; pi.value.publish.specifics.resume.message = fi->emsg; pi.value.publish.specifics.resume.chk_uri = fi->chk_uri; - *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); - if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) - { - /* process entries in directory */ - pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (fi, &fip_signal_resume, pc); - } + *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); + if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) + { + /* process entries in directory */ + pc->skip_next_fi_callback = GNUNET_YES; + GNUNET_FS_file_information_inspect(fi, &fip_signal_resume, pc); + } return GNUNET_OK; } @@ -1553,7 +1567,7 @@ fip_signal_resume (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_publish_file (void *cls, const char *filename) +deserialize_publish_file(void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_BIO_ReadHandle *rh; @@ -1566,115 +1580,115 @@ deserialize_publish_file (void *cls, const char *filename) char *fi_pos; char *emsg; - pc = GNUNET_new (struct GNUNET_FS_PublishContext); + pc = GNUNET_new(struct GNUNET_FS_PublishContext); pc->h = h; - pc->serialization = get_serialization_short_name (filename); + pc->serialization = get_serialization_short_name(filename); fi_root = NULL; fi_pos = NULL; - rh = GNUNET_BIO_read_open (filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - GNUNET_break (0); - goto cleanup; - } + { + GNUNET_break(0); + goto cleanup; + } if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || + GNUNET_BIO_read_string(rh, "publish-nid", &pc->nid, 1024)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || + GNUNET_BIO_read_string(rh, "publish-nuid", &pc->nuid, 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &all_done)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &have_ns)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || + GNUNET_BIO_read_string(rh, "publish-firoot", &fi_root, 128)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || + GNUNET_BIO_read_string(rh, "publish-fipos", &fi_pos, 128)) || ((GNUNET_YES == have_ns) && - (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) - { - GNUNET_break (0); - goto cleanup; - } + (GNUNET_OK != GNUNET_BIO_read(rh, "publish-ns", &ns, sizeof(ns))))) + { + GNUNET_break(0); + goto cleanup; + } pc->options = options; pc->all_done = all_done; if (NULL == fi_root) - { - GNUNET_break (0); - goto cleanup; - } - pc->fi = deserialize_file_information (h, fi_root); + { + GNUNET_break(0); + goto cleanup; + } + pc->fi = deserialize_file_information(h, fi_root); if (NULL == pc->fi) - { - GNUNET_break (0); - goto cleanup; - } + { + GNUNET_break(0); + goto cleanup; + } if (GNUNET_YES == have_ns) - { - pc->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); - *pc->ns = ns; - } + { + pc->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); + *pc->ns = ns; + } if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && (GNUNET_YES != pc->all_done)) - { - pc->dsh = GNUNET_DATASTORE_connect (h->cfg); - if (NULL == pc->dsh) - goto cleanup; - } + { + pc->dsh = GNUNET_DATASTORE_connect(h->cfg); + if (NULL == pc->dsh) + goto cleanup; + } if (NULL != fi_pos) - { - pc->fi_pos = find_file_position (pc->fi, fi_pos); - GNUNET_free (fi_pos); - fi_pos = NULL; - if (NULL == pc->fi_pos) - { - /* failed to find position for resuming, outch! Will start from root! */ - GNUNET_break (0); - if (GNUNET_YES != pc->all_done) - pc->fi_pos = pc->fi; - } - } - GNUNET_free (fi_root); + { + pc->fi_pos = find_file_position(pc->fi, fi_pos); + GNUNET_free(fi_pos); + fi_pos = NULL; + if (NULL == pc->fi_pos) + { + /* failed to find position for resuming, outch! Will start from root! */ + GNUNET_break(0); + if (GNUNET_YES != pc->all_done) + pc->fi_pos = pc->fi; + } + } + GNUNET_free(fi_root); fi_root = NULL; /* generate RESUME event(s) */ - GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc); + GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_resume, pc); /* re-start publishing (if needed)... */ if (GNUNET_YES != pc->all_done) - { - GNUNET_assert (NULL == pc->upload_task); - pc->upload_task = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, - pc); - } - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming publishing operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } - pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); + { + GNUNET_assert(NULL == pc->upload_task); + pc->upload_task = + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, + pc); + } + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming publishing operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } + pc->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, pc); return GNUNET_OK; cleanup: - GNUNET_free_non_null (pc->nid); - GNUNET_free_non_null (pc->nuid); - GNUNET_free_non_null (fi_root); - GNUNET_free_non_null (fi_pos); - if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume publishing operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + GNUNET_free_non_null(pc->nid); + GNUNET_free_non_null(pc->nuid); + GNUNET_free_non_null(fi_root); + GNUNET_free_non_null(fi_pos); + if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume publishing operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } if (NULL != pc->fi) - GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); - if (0 != unlink (filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); - GNUNET_free (pc->serialization); - GNUNET_free (pc); + GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); + if (0 != unlink(filename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); + GNUNET_free(pc->serialization); + GNUNET_free(pc); return GNUNET_OK; } @@ -1688,65 +1702,65 @@ cleanup: * @param pc the struct to sync */ void -GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) +GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc) { struct GNUNET_BIO_WriteHandle *wh; int32_t have_ns; if (NULL == pc->serialization) pc->serialization = - make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); + make_serialization_file_name(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); if (NULL == pc->serialization) return; if (NULL == pc->fi) return; if (NULL == pc->fi->serialization) - { - GNUNET_break (0); - return; - } - wh = get_write_handle (pc->h, - GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, - pc->serialization); + { + GNUNET_break(0); + return; + } + wh = get_write_handle(pc->h, + GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + pc->serialization); if (NULL == wh) - { - GNUNET_break (0); - goto cleanup; - } + { + GNUNET_break(0); + goto cleanup; + } have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, - (NULL == pc->fi_pos) - ? NULL - : pc->fi_pos->serialization)) || + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nid)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nuid)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->options)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->all_done)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, have_ns)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->fi->serialization)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, + (NULL == pc->fi_pos) + ? NULL + : pc->fi_pos->serialization)) || ((NULL != pc->ns) && (GNUNET_OK != - GNUNET_BIO_write (wh, - pc->ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } + GNUNET_BIO_write(wh, + pc->ns, + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) + { + GNUNET_break(0); + goto cleanup; + } + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + wh = NULL; + GNUNET_break(0); + goto cleanup; + } return; cleanup: if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - GNUNET_FS_remove_sync_file_ (pc->h, - GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, - pc->serialization); - GNUNET_free (pc->serialization); + (void)GNUNET_BIO_write_close(wh); + GNUNET_FS_remove_sync_file_(pc->h, + GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + pc->serialization); + GNUNET_free(pc->serialization); pc->serialization = NULL; } @@ -1760,60 +1774,60 @@ cleanup: * @param uc the struct to sync */ void -GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) +GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_BIO_WriteHandle *wh; char *uris; if (NULL == uc->serialization) uc->serialization = - make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); + make_serialization_file_name(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); if (NULL == uc->serialization) return; - wh = get_write_handle (uc->h, - GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - uc->serialization); + wh = get_write_handle(uc->h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + uc->serialization); if (NULL == wh) - { - GNUNET_break (0); - goto cleanup; - } + { + GNUNET_break(0); + goto cleanup; + } if (NULL != uc->ksk_uri) - uris = GNUNET_FS_uri_to_string (uc->ksk_uri); + uris = GNUNET_FS_uri_to_string(uc->ksk_uri); else uris = NULL; - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) || - (GNUNET_OK != write_start_time (wh, uc->start_time)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uc->filename)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, uc->file_size)) || + (GNUNET_OK != write_start_time(wh, uc->start_time)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->state)) || (GNUNET_OK != - GNUNET_BIO_write (wh, &uc->chk, sizeof (struct ContentHashKey))) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || + GNUNET_BIO_write(wh, &uc->chk, sizeof(struct ContentHashKey))) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->ksk_offset)) || ((uc->state == UNINDEX_STATE_FS_NOTIFY) && - (GNUNET_OK != GNUNET_BIO_write (wh, - &uc->file_id, - sizeof (struct GNUNET_HashCode)))) || + (GNUNET_OK != GNUNET_BIO_write(wh, + &uc->file_id, + sizeof(struct GNUNET_HashCode)))) || ((uc->state == UNINDEX_STATE_ERROR) && - (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } + (GNUNET_OK != GNUNET_BIO_write_string(wh, uc->emsg)))) + { + GNUNET_break(0); + goto cleanup; + } + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + wh = NULL; + GNUNET_break(0); + goto cleanup; + } return; cleanup: if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - GNUNET_FS_remove_sync_file_ (uc->h, - GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - uc->serialization); - GNUNET_free (uc->serialization); + (void)GNUNET_BIO_write_close(wh); + GNUNET_FS_remove_sync_file_(uc->h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + uc->serialization); + GNUNET_free(uc->serialization); uc->serialization = NULL; } @@ -1826,22 +1840,22 @@ cleanup: * @return #GNUNET_YES on success, #GNUNET_NO on error */ static int -write_download_request (struct GNUNET_BIO_WriteHandle *wh, - struct DownloadRequest *dr) +write_download_request(struct GNUNET_BIO_WriteHandle *wh, + struct DownloadRequest *dr) { unsigned int i; - if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) + if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->state)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, dr->offset)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->num_children)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->depth))) return GNUNET_NO; if ((BRS_CHK_SET == dr->state) && (GNUNET_OK != - GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey)))) + GNUNET_BIO_write(wh, &dr->chk, sizeof(struct ContentHashKey)))) return GNUNET_NO; for (i = 0; i < dr->num_children; i++) - if (GNUNET_NO == write_download_request (wh, dr->children[i])) + if (GNUNET_NO == write_download_request(wh, dr->children[i])) return GNUNET_NO; return GNUNET_YES; } @@ -1854,56 +1868,59 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh, * @return value the download request read from disk, NULL on error */ static struct DownloadRequest * -read_download_request (struct GNUNET_BIO_ReadHandle *rh) +read_download_request(struct GNUNET_BIO_ReadHandle *rh) { struct DownloadRequest *dr; unsigned int i; - dr = GNUNET_new (struct DownloadRequest); - if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || + dr = GNUNET_new(struct DownloadRequest); + if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->state)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dr->offset)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->num_children)) || (dr->num_children > CHK_PER_INODE) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->depth)) || ((0 == dr->depth) && (dr->num_children > 0)) || ((dr->depth > 0) && (0 == dr->num_children))) - { - GNUNET_break (0); - dr->num_children = 0; - goto cleanup; - } + { + GNUNET_break(0); + dr->num_children = 0; + goto cleanup; + } if (dr->num_children > 0) dr->children = - GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); + GNUNET_malloc(dr->num_children * sizeof(struct DownloadRequest *)); switch (dr->state) - { - case BRS_INIT: - case BRS_RECONSTRUCT_DOWN: - case BRS_RECONSTRUCT_META_UP: - case BRS_RECONSTRUCT_UP: - break; - case BRS_CHK_SET: - if (GNUNET_OK != - GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) + { + case BRS_INIT: + case BRS_RECONSTRUCT_DOWN: + case BRS_RECONSTRUCT_META_UP: + case BRS_RECONSTRUCT_UP: + break; + + case BRS_CHK_SET: + if (GNUNET_OK != + GNUNET_BIO_read(rh, "chk", &dr->chk, sizeof(struct ContentHashKey))) + goto cleanup; + break; + + case BRS_DOWNLOAD_DOWN: + case BRS_DOWNLOAD_UP: + case BRS_ERROR: + break; + + default: + GNUNET_break(0); goto cleanup; - break; - case BRS_DOWNLOAD_DOWN: - case BRS_DOWNLOAD_UP: - case BRS_ERROR: - break; - default: - GNUNET_break (0); - goto cleanup; - } + } for (i = 0; i < dr->num_children; i++) - { - if (NULL == (dr->children[i] = read_download_request (rh))) - goto cleanup; - dr->children[i]->parent = dr; - } + { + if (NULL == (dr->children[i] = read_download_request(rh))) + goto cleanup; + dr->children[i]->parent = dr; + } return dr; cleanup: - GNUNET_FS_free_download_request_ (dr); + GNUNET_FS_free_download_request_(dr); return NULL; } @@ -1918,26 +1935,26 @@ cleanup: * @return the expanded file name, NULL for none */ static char * -get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, - const char *uni, - const char *ext) +get_download_sync_filename(struct GNUNET_FS_DownloadContext *dc, + const char *uni, + const char *ext) { char *par; char *epar; if (dc->parent == NULL) - return get_serialization_file_name (dc->h, - (dc->search != NULL) - ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD - : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, - uni); + return get_serialization_file_name(dc->h, + (dc->search != NULL) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + uni); if (NULL == dc->parent->serialization) return NULL; - par = get_download_sync_filename (dc->parent, dc->parent->serialization, ""); + par = get_download_sync_filename(dc->parent, dc->parent->serialization, ""); if (NULL == par) return NULL; - GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); - GNUNET_free (par); + GNUNET_asprintf(&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); + GNUNET_free(par); return epar; } @@ -1951,7 +1968,7 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, * @param dc the struct to sync */ void -GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) +GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc) { struct GNUNET_BIO_WriteHandle *wh; char *uris; @@ -1961,87 +1978,87 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) return; /* we don't sync probes */ if (NULL == dc->serialization) - { - dir = get_download_sync_filename (dc, "", ""); - if (NULL == dir) - return; - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir)) { - GNUNET_free (dir); - return; + dir = get_download_sync_filename(dc, "", ""); + if (NULL == dir) + return; + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dir)) + { + GNUNET_free(dir); + return; + } + fn = GNUNET_DISK_mktemp(dir); + GNUNET_free(dir); + if (NULL == fn) + return; + dc->serialization = get_serialization_short_name(fn); } - fn = GNUNET_DISK_mktemp (dir); - GNUNET_free (dir); - if (NULL == fn) - return; - dc->serialization = get_serialization_short_name (fn); - } else - { - fn = get_download_sync_filename (dc, dc->serialization, ""); - if (NULL == fn) { - GNUNET_free (dc->serialization); + fn = get_download_sync_filename(dc, dc->serialization, ""); + if (NULL == fn) + { + GNUNET_free(dc->serialization); + dc->serialization = NULL; + GNUNET_free(fn); + return; + } + } + wh = GNUNET_BIO_write_open(fn); + if (NULL == wh) + { + GNUNET_free(dc->serialization); dc->serialization = NULL; - GNUNET_free (fn); + GNUNET_free(fn); return; } - } - wh = GNUNET_BIO_write_open (fn); - if (NULL == wh) - { - GNUNET_free (dc->serialization); - dc->serialization = NULL; - GNUNET_free (fn); - return; - } - GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || - (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); - uris = GNUNET_FS_uri_to_string (dc->uri); - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || - (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) || - (GNUNET_OK != write_start_time (wh, dc->start_time)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) - { - GNUNET_break (0); - goto cleanup; - } - if (NULL == dc->emsg) - { - GNUNET_assert (dc->top_request != NULL); - if (GNUNET_YES != write_download_request (wh, dc->top_request)) + GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_chk(dc->uri)) || + (GNUNET_YES == GNUNET_FS_uri_test_loc(dc->uri))); + uris = GNUNET_FS_uri_to_string(dc->uri); + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || + (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, dc->meta)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->emsg)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->filename)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->temp_filename)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->old_file_size)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->offset)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->length)) || + (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->completed)) || + (GNUNET_OK != write_start_time(wh, dc->start_time)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, dc->anonymity)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->options)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->has_finished))) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - } - GNUNET_free_non_null (uris); + if (NULL == dc->emsg) + { + GNUNET_assert(dc->top_request != NULL); + if (GNUNET_YES != write_download_request(wh, dc->top_request)) + { + GNUNET_break(0); + goto cleanup; + } + } + GNUNET_free_non_null(uris); uris = NULL; - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } - GNUNET_free (fn); + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + wh = NULL; + GNUNET_break(0); + goto cleanup; + } + GNUNET_free(fn); return; cleanup: if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - GNUNET_free_non_null (uris); - if (0 != unlink (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); - GNUNET_free (fn); - GNUNET_free (dc->serialization); + (void)GNUNET_BIO_write_close(wh); + GNUNET_free_non_null(uris); + if (0 != unlink(fn)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + GNUNET_free(fn); + GNUNET_free(dc->serialization); dc->serialization = NULL; } @@ -2055,7 +2072,7 @@ cleanup: * @param sr the struct to sync */ void -GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) +GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr) { struct GNUNET_BIO_WriteHandle *wh; char *uris; @@ -2065,74 +2082,74 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) uris = NULL; if (NULL == sr->serialization) sr->serialization = - make_serialization_file_name_in_dir (sr->h, - (sr->sc->psearch_result == NULL) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization); + make_serialization_file_name_in_dir(sr->h, + (sr->sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization); if (NULL == sr->serialization) return; - wh = get_write_handle_in_dir (sr->h, - (sr->sc->psearch_result == NULL) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization, - sr->serialization); + wh = get_write_handle_in_dir(sr->h, + (sr->sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization, + sr->serialization); if (NULL == wh) - { - GNUNET_break (0); - goto cleanup; - } - uris = GNUNET_FS_uri_to_string (sr->uri); - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, - sr->download != NULL - ? sr->download->serialization - : NULL)) || + { + GNUNET_break(0); + goto cleanup; + } + uris = GNUNET_FS_uri_to_string(sr->uri); + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, + sr->download != NULL + ? sr->download->serialization + : NULL)) || (GNUNET_OK != - GNUNET_BIO_write_string (wh, - sr->update_search != NULL - ? sr->update_search->serialization - : NULL)) || - (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || + GNUNET_BIO_write_string(wh, + sr->update_search != NULL + ? sr->update_search->serialization + : NULL)) || + (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, sr->meta)) || (GNUNET_OK != - GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) - { - GNUNET_break (0); - goto cleanup; - } + GNUNET_BIO_write(wh, &sr->key, sizeof(struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->mandatory_missing)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->optional_support)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_success)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_trials))) + { + GNUNET_break(0); + goto cleanup; + } if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && (GNUNET_OK != - GNUNET_BIO_write (wh, - sr->keyword_bitmap, - (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } - GNUNET_free_non_null (uris); + GNUNET_BIO_write(wh, + sr->keyword_bitmap, + (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) + { + GNUNET_break(0); + goto cleanup; + } + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + wh = NULL; + GNUNET_break(0); + goto cleanup; + } + GNUNET_free_non_null(uris); return; cleanup: - GNUNET_free_non_null (uris); + GNUNET_free_non_null(uris); if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - remove_sync_file_in_dir (sr->h, - (NULL == sr->sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization, - sr->serialization); - GNUNET_free (sr->serialization); + (void)GNUNET_BIO_write_close(wh); + remove_sync_file_in_dir(sr->h, + (NULL == sr->sc->psearch_result) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization, + sr->serialization); + GNUNET_free(sr->serialization); sr->serialization = NULL; } @@ -2146,7 +2163,7 @@ cleanup: * @param sc the struct to sync */ void -GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc) { struct GNUNET_BIO_WriteHandle *wh; char *uris; @@ -2154,47 +2171,47 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) const char *category; category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; if (NULL == sc->serialization) - sc->serialization = make_serialization_file_name (sc->h, category); + sc->serialization = make_serialization_file_name(sc->h, category); if (NULL == sc->serialization) return; uris = NULL; - wh = get_write_handle (sc->h, category, sc->serialization); + wh = get_write_handle(sc->h, category, sc->serialization); if (NULL == wh) - { - GNUNET_break (0); - goto cleanup; - } - GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) || - (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); - uris = GNUNET_FS_uri_to_string (sc->uri); + { + GNUNET_break(0); + goto cleanup; + } + GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_ksk(sc->uri)) || + (GNUNET_YES == GNUNET_FS_uri_test_sks(sc->uri))); + uris = GNUNET_FS_uri_to_string(sc->uri); in_pause = (sc->task != NULL) ? 'r' : '\0'; - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || - (GNUNET_OK != write_start_time (wh, sc->start_time)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || - (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) - { - GNUNET_break (0); - goto cleanup; - } - GNUNET_free (uris); + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || + (GNUNET_OK != write_start_time(wh, sc->start_time)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, sc->emsg)) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)sc->options)) || + (GNUNET_OK != GNUNET_BIO_write(wh, &in_pause, sizeof(in_pause))) || + (GNUNET_OK != GNUNET_BIO_write_int32(wh, sc->anonymity))) + { + GNUNET_break(0); + goto cleanup; + } + GNUNET_free(uris); uris = NULL; - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - wh = NULL; - GNUNET_break (0); - goto cleanup; - } + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + wh = NULL; + GNUNET_break(0); + goto cleanup; + } return; cleanup: if (NULL != wh) - (void) GNUNET_BIO_write_close (wh); - GNUNET_free_non_null (uris); - GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); - GNUNET_free (sc->serialization); + (void)GNUNET_BIO_write_close(wh); + GNUNET_free_non_null(uris); + GNUNET_FS_remove_sync_file_(sc->h, category, sc->serialization); + GNUNET_free(sc->serialization); sc->serialization = NULL; } @@ -2208,7 +2225,7 @@ cleanup: * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_unindex_file (void *cls, const char *filename) +deserialize_unindex_file(void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_BIO_ReadHandle *rh; @@ -2218,144 +2235,155 @@ deserialize_unindex_file (void *cls, const char *filename) char *uris; uint32_t state; - uc = GNUNET_new (struct GNUNET_FS_UnindexContext); + uc = GNUNET_new(struct GNUNET_FS_UnindexContext); uc->h = h; - uc->serialization = get_serialization_short_name (filename); - rh = GNUNET_BIO_read_open (filename); + uc->serialization = get_serialization_short_name(filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - GNUNET_break (0); - goto cleanup; - } + { + GNUNET_break(0); + goto cleanup; + } uris = NULL; if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || - (GNUNET_OK != read_start_time (rh, &uc->start_time)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || + GNUNET_BIO_read_string(rh, "unindex-fn", &uc->filename, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &uc->file_size)) || + (GNUNET_OK != read_start_time(rh, &uc->start_time)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &state)) || (GNUNET_OK != - GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || + GNUNET_BIO_read(rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) - { - GNUNET_free_non_null (uris); - GNUNET_break (0); - goto cleanup; - } - if (NULL != uris) - { - uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg); - GNUNET_free (uris); - if (NULL == uc->ksk_uri) + GNUNET_BIO_read_string(rh, "unindex-kskuri", &uris, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &uc->ksk_offset))) { - GNUNET_break (0); - GNUNET_free_non_null (emsg); + GNUNET_free_non_null(uris); + GNUNET_break(0); goto cleanup; } - } + if (NULL != uris) + { + uc->ksk_uri = GNUNET_FS_uri_parse(uris, &emsg); + GNUNET_free(uris); + if (NULL == uc->ksk_uri) + { + GNUNET_break(0); + GNUNET_free_non_null(emsg); + goto cleanup; + } + } if ((uc->ksk_offset > 0) && ((NULL == uc->ksk_uri) || (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) - { - GNUNET_break (0); - goto cleanup; - } - uc->state = (enum UnindexState) state; - switch (state) - { - case UNINDEX_STATE_HASHING: - break; - case UNINDEX_STATE_FS_NOTIFY: - if (GNUNET_OK != GNUNET_BIO_read (rh, - "unindex-hash", - &uc->file_id, - sizeof (struct GNUNET_HashCode))) { - GNUNET_break (0); + GNUNET_break(0); goto cleanup; } - break; - case UNINDEX_STATE_DS_REMOVE: - case UNINDEX_STATE_EXTRACT_KEYWORDS: - case UNINDEX_STATE_DS_REMOVE_KBLOCKS: - break; - case UNINDEX_STATE_COMPLETE: - break; - case UNINDEX_STATE_ERROR: - if (GNUNET_OK != - GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024)) - { - GNUNET_break (0); + uc->state = (enum UnindexState)state; + switch (state) + { + case UNINDEX_STATE_HASHING: + break; + + case UNINDEX_STATE_FS_NOTIFY: + if (GNUNET_OK != GNUNET_BIO_read(rh, + "unindex-hash", + &uc->file_id, + sizeof(struct GNUNET_HashCode))) + { + GNUNET_break(0); + goto cleanup; + } + break; + + case UNINDEX_STATE_DS_REMOVE: + case UNINDEX_STATE_EXTRACT_KEYWORDS: + case UNINDEX_STATE_DS_REMOVE_KBLOCKS: + break; + + case UNINDEX_STATE_COMPLETE: + break; + + case UNINDEX_STATE_ERROR: + if (GNUNET_OK != + GNUNET_BIO_read_string(rh, "unindex-emsg", &uc->emsg, 10 * 1024)) + { + GNUNET_break(0); + goto cleanup; + } + break; + + default: + GNUNET_break(0); goto cleanup; } - break; - default: - GNUNET_break (0); - goto cleanup; - } - uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); + uc->top = GNUNET_FS_make_top(h, &GNUNET_FS_unindex_signal_suspend_, uc); pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; pi.value.unindex.specifics.resume.message = uc->emsg; - GNUNET_FS_unindex_make_status_ (&pi, - uc, - (uc->state == UNINDEX_STATE_COMPLETE) - ? uc->file_size - : 0); + GNUNET_FS_unindex_make_status_(&pi, + uc, + (uc->state == UNINDEX_STATE_COMPLETE) + ? uc->file_size + : 0); switch (uc->state) - { - case UNINDEX_STATE_HASHING: - uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, - uc->filename, - HASHING_BLOCKSIZE, - &GNUNET_FS_unindex_process_hash_, - uc); - break; - case UNINDEX_STATE_FS_NOTIFY: - uc->state = UNINDEX_STATE_HASHING; - GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id); - break; - case UNINDEX_STATE_DS_REMOVE: - GNUNET_FS_unindex_do_remove_ (uc); - break; - case UNINDEX_STATE_EXTRACT_KEYWORDS: - GNUNET_FS_unindex_do_extract_keywords_ (uc); - break; - case UNINDEX_STATE_DS_REMOVE_KBLOCKS: - GNUNET_FS_unindex_do_remove_kblocks_ (uc); - break; - case UNINDEX_STATE_COMPLETE: - case UNINDEX_STATE_ERROR: - /* no need to resume any operation, we were done */ - break; - default: - break; - } - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming unindexing operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + { + case UNINDEX_STATE_HASHING: + uc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, + uc->filename, + HASHING_BLOCKSIZE, + &GNUNET_FS_unindex_process_hash_, + uc); + break; + + case UNINDEX_STATE_FS_NOTIFY: + uc->state = UNINDEX_STATE_HASHING; + GNUNET_FS_unindex_process_hash_(uc, &uc->file_id); + break; + + case UNINDEX_STATE_DS_REMOVE: + GNUNET_FS_unindex_do_remove_(uc); + break; + + case UNINDEX_STATE_EXTRACT_KEYWORDS: + GNUNET_FS_unindex_do_extract_keywords_(uc); + break; + + case UNINDEX_STATE_DS_REMOVE_KBLOCKS: + GNUNET_FS_unindex_do_remove_kblocks_(uc); + break; + + case UNINDEX_STATE_COMPLETE: + case UNINDEX_STATE_ERROR: + /* no need to resume any operation, we were done */ + break; + + default: + break; + } + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming unindexing operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } return GNUNET_OK; cleanup: - GNUNET_free_non_null (uc->filename); - if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume unindexing operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + GNUNET_free_non_null(uc->filename); + if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume unindexing operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } if (NULL != uc->serialization) - GNUNET_FS_remove_sync_file_ (h, - GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - uc->serialization); - GNUNET_free_non_null (uc->serialization); - GNUNET_free (uc); + GNUNET_FS_remove_sync_file_(h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + uc->serialization); + GNUNET_free_non_null(uc->serialization); + GNUNET_free(uc); return GNUNET_OK; } @@ -2370,11 +2398,11 @@ cleanup: * @param serialization name under which the search was serialized */ static void -deserialize_download (struct GNUNET_FS_Handle *h, - struct GNUNET_BIO_ReadHandle *rh, - struct GNUNET_FS_DownloadContext *parent, - struct GNUNET_FS_SearchResult *search, - const char *serialization); +deserialize_download(struct GNUNET_FS_Handle *h, + struct GNUNET_BIO_ReadHandle *rh, + struct GNUNET_FS_DownloadContext *parent, + struct GNUNET_FS_SearchResult *search, + const char *serialization); /** @@ -2386,10 +2414,10 @@ deserialize_download (struct GNUNET_FS_Handle *h, * @param serialization name under which the search was serialized */ static struct GNUNET_FS_SearchContext * -deserialize_search (struct GNUNET_FS_Handle *h, - struct GNUNET_BIO_ReadHandle *rh, - struct GNUNET_FS_SearchResult *psearch_result, - const char *serialization); +deserialize_search(struct GNUNET_FS_Handle *h, + struct GNUNET_BIO_ReadHandle *rh, + struct GNUNET_FS_SearchResult *psearch_result, + const char *serialization); /** @@ -2401,7 +2429,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_search_result (void *cls, const char *filename) +deserialize_search_result(void *cls, const char *filename) { struct GNUNET_FS_SearchContext *sc = cls; char *ser; @@ -2413,133 +2441,133 @@ deserialize_search_result (void *cls, const char *filename) struct GNUNET_BIO_ReadHandle *drh; struct GNUNET_FS_SearchResult *sr; - ser = get_serialization_short_name (filename); - rh = GNUNET_BIO_read_open (filename); + ser = get_serialization_short_name(filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - if (NULL != ser) { - remove_sync_file_in_dir (sc->h, - (NULL == sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization, - ser); - GNUNET_free (ser); + if (NULL != ser) + { + remove_sync_file_in_dir(sc->h, + (NULL == sc->psearch_result) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sc->serialization, + ser); + GNUNET_free(ser); + } + return GNUNET_OK; } - return GNUNET_OK; - } emsg = NULL; uris = NULL; download = NULL; update_srch = NULL; - sr = GNUNET_new (struct GNUNET_FS_SearchResult); + sr = GNUNET_new(struct GNUNET_FS_SearchResult); sr->h = sc->h; sr->sc = sc; sr->serialization = ser; if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || - (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || + GNUNET_BIO_read_string(rh, "result-uri", &uris, 10 * 1024)) || + (NULL == (sr->uri = GNUNET_FS_uri_parse(uris, &emsg))) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || + GNUNET_BIO_read_string(rh, "download-lnk", &download, 16)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || - (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || - (GNUNET_OK != GNUNET_BIO_read (rh, - "result-key", - &sr->key, - sizeof (struct GNUNET_HashCode))) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_FS_URI_KSK == sr->sc->uri->type) - { - sr->keyword_bitmap = GNUNET_malloc ( - (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ - if (GNUNET_OK != - GNUNET_BIO_read (rh, - "keyword-bitmap", - sr->keyword_bitmap, - (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) - { - GNUNET_break (0); + GNUNET_BIO_read_string(rh, "search-lnk", &update_srch, 16)) || + (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "result-meta", &sr->meta)) || + (GNUNET_OK != GNUNET_BIO_read(rh, + "result-key", + &sr->key, + sizeof(struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->mandatory_missing)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->optional_support)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_success)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_trials))) + { + GNUNET_break(0); goto cleanup; } - } - GNUNET_free (uris); + if (GNUNET_FS_URI_KSK == sr->sc->uri->type) + { + sr->keyword_bitmap = GNUNET_malloc( + (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ + if (GNUNET_OK != + GNUNET_BIO_read(rh, + "keyword-bitmap", + sr->keyword_bitmap, + (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) + { + GNUNET_break(0); + goto cleanup; + } + } + GNUNET_free(uris); if (NULL != download) - { - drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); - if (NULL != drh) - { - deserialize_download (sc->h, drh, NULL, sr, download); - if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume sub-download `%s': %s\n"), - download, - emsg); - GNUNET_free (emsg); - } - } - GNUNET_free (download); - } + { + drh = get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); + if (NULL != drh) + { + deserialize_download(sc->h, drh, NULL, sr, download); + if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume sub-download `%s': %s\n"), + download, + emsg); + GNUNET_free(emsg); + } + } + GNUNET_free(download); + } if (NULL != update_srch) - { - drh = - get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); - if (NULL != drh) - { - deserialize_search (sc->h, drh, sr, update_srch); - if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume sub-search `%s': %s\n"), - update_srch, - emsg); - GNUNET_free (emsg); - } - } - GNUNET_free (update_srch); - } - GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( - sc->master_result_map, - &sr->key, - sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming search operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + { + drh = + get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); + if (NULL != drh) + { + deserialize_search(sc->h, drh, sr, update_srch); + if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume sub-search `%s': %s\n"), + update_srch, + emsg); + GNUNET_free(emsg); + } + } + GNUNET_free(update_srch); + } + GNUNET_break(GNUNET_YES == GNUNET_CONTAINER_multihashmap_put( + sc->master_result_map, + &sr->key, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } return GNUNET_OK; cleanup: - GNUNET_free_non_null (download); - GNUNET_free_non_null (emsg); - GNUNET_free_non_null (uris); - GNUNET_free_non_null (update_srch); + GNUNET_free_non_null(download); + GNUNET_free_non_null(emsg); + GNUNET_free_non_null(uris); + GNUNET_free_non_null(update_srch); if (NULL != sr->uri) - GNUNET_FS_uri_destroy (sr->uri); + GNUNET_FS_uri_destroy(sr->uri); if (NULL != sr->meta) - GNUNET_CONTAINER_meta_data_destroy (sr->meta); - GNUNET_free (sr->serialization); - GNUNET_free (sr); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming search operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + GNUNET_CONTAINER_meta_data_destroy(sr->meta); + GNUNET_free(sr->serialization); + GNUNET_free(sr); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } return GNUNET_OK; } @@ -2553,7 +2581,7 @@ cleanup: * @param dc download to resume */ static void -signal_download_resume (struct GNUNET_FS_DownloadContext *dc) +signal_download_resume(struct GNUNET_FS_DownloadContext *dc) { struct GNUNET_FS_DownloadContext *dcc; struct GNUNET_FS_ProgressInfo pi; @@ -2561,13 +2589,13 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; pi.value.download.specifics.resume.meta = dc->meta; pi.value.download.specifics.resume.message = dc->emsg; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); dcc = dc->child_head; while (NULL != dcc) - { - signal_download_resume (dcc); - dcc = dcc->next; - } + { + signal_download_resume(dcc); + dcc = dcc->next; + } } @@ -2578,7 +2606,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) * @param sc search being resumed */ static void -signal_search_resume (struct GNUNET_FS_SearchContext *sc); +signal_search_resume(struct GNUNET_FS_SearchContext *sc); /** @@ -2591,36 +2619,36 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); * @return #GNUNET_YES (we should continue to iterate) */ static int -signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) +signal_result_resume(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_ProgressInfo pi; struct GNUNET_FS_SearchResult *sr = value; if (0 == sr->mandatory_missing) - { - pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; - pi.value.search.specifics.resume_result.meta = sr->meta; - pi.value.search.specifics.resume_result.uri = sr->uri; - pi.value.search.specifics.resume_result.result = sr; - pi.value.search.specifics.resume_result.availability_rank = - 2 * sr->availability_success - sr->availability_trials; - pi.value.search.specifics.resume_result.availability_certainty = - sr->availability_trials; - pi.value.search.specifics.resume_result.applicability_rank = - sr->optional_support; - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); - } + { + pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; + pi.value.search.specifics.resume_result.meta = sr->meta; + pi.value.search.specifics.resume_result.uri = sr->uri; + pi.value.search.specifics.resume_result.result = sr; + pi.value.search.specifics.resume_result.availability_rank = + 2 * sr->availability_success - sr->availability_trials; + pi.value.search.specifics.resume_result.availability_certainty = + sr->availability_trials; + pi.value.search.specifics.resume_result.applicability_rank = + sr->optional_support; + sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); + } if (NULL != sr->download) - { - signal_download_resume (sr->download); - } + { + signal_download_resume(sr->download); + } else - { - GNUNET_FS_search_start_probe_ (sr); - } + { + GNUNET_FS_search_start_probe_(sr); + } if (NULL != sr->update_search) - signal_search_resume (sr->update_search); + signal_search_resume(sr->update_search); return GNUNET_YES; } @@ -2631,7 +2659,7 @@ signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) * @param sc search context to free */ static void -free_search_context (struct GNUNET_FS_SearchContext *sc); +free_search_context(struct GNUNET_FS_SearchContext *sc); /** @@ -2643,18 +2671,18 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); * @return #GNUNET_YES (we should continue to iterate) */ static int -free_result (void *cls, const struct GNUNET_HashCode *key, void *value) +free_result(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_FS_SearchResult *sr = value; if (NULL != sr->update_search) - { - free_search_context (sr->update_search); - GNUNET_assert (NULL == sr->update_search); - } - GNUNET_CONTAINER_meta_data_destroy (sr->meta); - GNUNET_FS_uri_destroy (sr->uri); - GNUNET_free (sr); + { + free_search_context(sr->update_search); + GNUNET_assert(NULL == sr->update_search); + } + GNUNET_CONTAINER_meta_data_destroy(sr->meta); + GNUNET_FS_uri_destroy(sr->uri); + GNUNET_free(sr); return GNUNET_YES; } @@ -2665,33 +2693,33 @@ free_result (void *cls, const struct GNUNET_HashCode *key, void *value) * @param sc search context to free */ static void -free_search_context (struct GNUNET_FS_SearchContext *sc) +free_search_context(struct GNUNET_FS_SearchContext *sc) { if (NULL != sc->serialization) - { - GNUNET_FS_remove_sync_file_ (sc->h, - (sc->psearch_result == NULL) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization); - GNUNET_FS_remove_sync_dir_ (sc->h, - (sc->psearch_result == NULL) + { + GNUNET_FS_remove_sync_file_(sc->h, + (sc->psearch_result == NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization); - } - GNUNET_free_non_null (sc->serialization); - GNUNET_free_non_null (sc->emsg); + sc->serialization); + GNUNET_FS_remove_sync_dir_(sc->h, + (sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sc->serialization); + } + GNUNET_free_non_null(sc->serialization); + GNUNET_free_non_null(sc->emsg); if (NULL != sc->uri) - GNUNET_FS_uri_destroy (sc->uri); + GNUNET_FS_uri_destroy(sc->uri); if (NULL != sc->master_result_map) - { - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &free_result, - sc); - GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); - } - GNUNET_free (sc); + { + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &free_result, + sc); + GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); + } + GNUNET_free(sc); } @@ -2704,35 +2732,35 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_subdownload (void *cls, const char *filename) +deserialize_subdownload(void *cls, const char *filename) { struct GNUNET_FS_DownloadContext *parent = cls; char *ser; char *emsg; struct GNUNET_BIO_ReadHandle *rh; - ser = get_serialization_short_name (filename); - rh = GNUNET_BIO_read_open (filename); + ser = get_serialization_short_name(filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ( - "Failed to resume sub-download `%s': could not open file `%s'\n"), - ser, - filename); - GNUNET_free (ser); - return GNUNET_OK; - } - deserialize_download (parent->h, rh, parent, NULL, ser); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to resume sub-download `%s': %s\n"), - ser, - emsg); - GNUNET_free (emsg); - } - GNUNET_free (ser); + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _( + "Failed to resume sub-download `%s': could not open file `%s'\n"), + ser, + filename); + GNUNET_free(ser); + return GNUNET_OK; + } + deserialize_download(parent->h, rh, parent, NULL, ser); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume sub-download `%s': %s\n"), + ser, + emsg); + GNUNET_free(emsg); + } + GNUNET_free(ser); return GNUNET_OK; } @@ -2745,27 +2773,27 @@ deserialize_subdownload (void *cls, const char *filename) * @param dc context to free */ static void -free_download_context (struct GNUNET_FS_DownloadContext *dc) +free_download_context(struct GNUNET_FS_DownloadContext *dc) { struct GNUNET_FS_DownloadContext *dcc; if (NULL != dc->meta) - GNUNET_CONTAINER_meta_data_destroy (dc->meta); + GNUNET_CONTAINER_meta_data_destroy(dc->meta); if (NULL != dc->uri) - GNUNET_FS_uri_destroy (dc->uri); - GNUNET_free_non_null (dc->temp_filename); - GNUNET_free_non_null (dc->emsg); - GNUNET_free_non_null (dc->filename); - GNUNET_free_non_null (dc->serialization); + GNUNET_FS_uri_destroy(dc->uri); + GNUNET_free_non_null(dc->temp_filename); + GNUNET_free_non_null(dc->emsg); + GNUNET_free_non_null(dc->filename); + GNUNET_free_non_null(dc->serialization); while (NULL != (dcc = dc->child_head)) - { - GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); - free_download_context (dcc); - } - GNUNET_FS_free_download_request_ (dc->top_request); + { + GNUNET_CONTAINER_DLL_remove(dc->child_head, dc->child_tail, dcc); + free_download_context(dcc); + } + GNUNET_FS_free_download_request_(dc->top_request); if (NULL != dc->active) - GNUNET_CONTAINER_multihashmap_destroy (dc->active); - GNUNET_free (dc); + GNUNET_CONTAINER_multihashmap_destroy(dc->active); + GNUNET_free(dc); } @@ -2779,11 +2807,11 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) * @param serialization name under which the search was serialized */ static void -deserialize_download (struct GNUNET_FS_Handle *h, - struct GNUNET_BIO_ReadHandle *rh, - struct GNUNET_FS_DownloadContext *parent, - struct GNUNET_FS_SearchResult *search, - const char *serialization) +deserialize_download(struct GNUNET_FS_Handle *h, + struct GNUNET_BIO_ReadHandle *rh, + struct GNUNET_FS_DownloadContext *parent, + struct GNUNET_FS_SearchResult *search, + const char *serialization) { struct GNUNET_FS_DownloadContext *dc; char *emsg; @@ -2794,86 +2822,86 @@ deserialize_download (struct GNUNET_FS_Handle *h, uris = NULL; emsg = NULL; - dc = GNUNET_new (struct GNUNET_FS_DownloadContext); + dc = GNUNET_new(struct GNUNET_FS_DownloadContext); dc->parent = parent; dc->h = h; - dc->serialization = GNUNET_strdup (serialization); + dc->serialization = GNUNET_strdup(serialization); if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || - (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || - ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && - (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || + GNUNET_BIO_read_string(rh, "download-uri", &uris, 10 * 1024)) || + (NULL == (dc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || + ((GNUNET_YES != GNUNET_FS_uri_test_chk(dc->uri)) && + (GNUNET_YES != GNUNET_FS_uri_test_loc(dc->uri))) || (GNUNET_OK != - GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || + GNUNET_BIO_read_meta_data(rh, "download-meta", &dc->meta)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || + GNUNET_BIO_read_string(rh, "download-emsg", &dc->emsg, 10 * 1024)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, - "download-tfn", - &dc->temp_filename, - 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) || - (GNUNET_OK != read_start_time (rh, &dc->start_time)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status))) - { - GNUNET_break (0); - goto cleanup; - } - dc->options = (enum GNUNET_FS_DownloadOptions) options; + GNUNET_BIO_read_string(rh, "download-fn", &dc->filename, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_string(rh, + "download-tfn", + &dc->temp_filename, + 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->old_file_size)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->offset)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->length)) || + (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->completed)) || + (GNUNET_OK != read_start_time(rh, &dc->start_time)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dc->anonymity)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &status))) + { + GNUNET_break(0); + goto cleanup; + } + dc->options = (enum GNUNET_FS_DownloadOptions)options; dc->active = - GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), - GNUNET_NO); - dc->has_finished = (int) status; + GNUNET_CONTAINER_multihashmap_create(1 + 2 * (dc->length / DBLOCK_SIZE), + GNUNET_NO); + dc->has_finished = (int)status; dc->treedepth = - GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); - if (GNUNET_FS_uri_test_loc (dc->uri)) - GNUNET_assert (GNUNET_OK == - GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); + GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); + if (GNUNET_FS_uri_test_loc(dc->uri)) + GNUNET_assert(GNUNET_OK == + GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); if (NULL == dc->emsg) - { - dc->top_request = read_download_request (rh); - if (NULL == dc->top_request) { - GNUNET_break (0); - goto cleanup; + dc->top_request = read_download_request(rh); + if (NULL == dc->top_request) + { + GNUNET_break(0); + goto cleanup; + } } - } - dn = get_download_sync_filename (dc, dc->serialization, ".dir"); + dn = get_download_sync_filename(dc, dc->serialization, ".dir"); if (NULL != dn) - { - if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) - GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); - GNUNET_free (dn); - } + { + if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) + GNUNET_DISK_directory_scan(dn, &deserialize_subdownload, dc); + GNUNET_free(dn); + } if (NULL != parent) - { - GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); - } + { + GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); + } if (NULL != search) - { - dc->search = search; - search->download = dc; - } + { + dc->search = search; + search->download = dc; + } if ((NULL == parent) && (NULL == search)) - { - dc->top = - GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); - signal_download_resume (dc); - } - GNUNET_free (uris); - GNUNET_assert (NULL == dc->job_queue); - dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); + { + dc->top = + GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); + signal_download_resume(dc); + } + GNUNET_free(uris); + GNUNET_assert(NULL == dc->job_queue); + dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); return; cleanup: - GNUNET_free_non_null (uris); - GNUNET_free_non_null (emsg); - free_download_context (dc); + GNUNET_free_non_null(uris); + GNUNET_free_non_null(emsg); + free_download_context(dc); } @@ -2884,7 +2912,7 @@ cleanup: * @param sc search being resumed */ static void -signal_search_resume (struct GNUNET_FS_SearchContext *sc) +signal_search_resume(struct GNUNET_FS_SearchContext *sc) { struct GNUNET_FS_ProgressInfo pi; @@ -2892,10 +2920,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) pi.value.search.specifics.resume.message = sc->emsg; pi.value.search.specifics.resume.is_paused = (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &signal_result_resume, - sc); + sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &signal_result_resume, + sc); } @@ -2908,10 +2936,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) * @param serialization name under which the search was serialized */ static struct GNUNET_FS_SearchContext * -deserialize_search (struct GNUNET_FS_Handle *h, - struct GNUNET_BIO_ReadHandle *rh, - struct GNUNET_FS_SearchResult *psearch_result, - const char *serialization) +deserialize_search(struct GNUNET_FS_Handle *h, + struct GNUNET_BIO_ReadHandle *rh, + struct GNUNET_FS_SearchResult *psearch_result, + const char *serialization) { struct GNUNET_FS_SearchContext *sc; char *emsg; @@ -2921,64 +2949,64 @@ deserialize_search (struct GNUNET_FS_Handle *h, char in_pause; if ((NULL != psearch_result) && (NULL != psearch_result->update_search)) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } uris = NULL; emsg = NULL; - sc = GNUNET_new (struct GNUNET_FS_SearchContext); + sc = GNUNET_new(struct GNUNET_FS_SearchContext); if (NULL != psearch_result) - { - sc->psearch_result = psearch_result; - psearch_result->update_search = sc; - } + { + sc->psearch_result = psearch_result; + psearch_result->update_search = sc; + } sc->h = h; - sc->serialization = GNUNET_strdup (serialization); + sc->serialization = GNUNET_strdup(serialization); if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) || - (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || - ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && - (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) || - (GNUNET_OK != read_start_time (rh, &sc->start_time)) || + GNUNET_BIO_read_string(rh, "search-uri", &uris, 10 * 1024)) || + (NULL == (sc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || + ((GNUNET_YES != GNUNET_FS_uri_test_ksk(sc->uri)) && + (GNUNET_YES != GNUNET_FS_uri_test_sks(sc->uri))) || + (GNUNET_OK != read_start_time(rh, &sc->start_time)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || + GNUNET_BIO_read_string(rh, "search-emsg", &sc->emsg, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || (GNUNET_OK != - GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) - { - GNUNET_break (0); - goto cleanup; - } - sc->options = (enum GNUNET_FS_SearchOptions) options; - sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); - dn = get_serialization_file_name_in_dir (h, - (NULL == sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization, - ""); + GNUNET_BIO_read(rh, "search-pause", &in_pause, sizeof(in_pause))) || + (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sc->anonymity))) + { + GNUNET_break(0); + goto cleanup; + } + sc->options = (enum GNUNET_FS_SearchOptions)options; + sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); + dn = get_serialization_file_name_in_dir(h, + (NULL == sc->psearch_result) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sc->serialization, + ""); if (NULL != dn) - { - if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) - GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); - GNUNET_free (dn); - } + { + if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) + GNUNET_DISK_directory_scan(dn, &deserialize_search_result, sc); + GNUNET_free(dn); + } if (('\0' == in_pause) && - (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_WARNING, - _ ("Could not resume running search, will resume as paused search\n")); - } - signal_search_resume (sc); - GNUNET_free (uris); + (GNUNET_OK != GNUNET_FS_search_start_searching_(sc))) + { + GNUNET_log( + GNUNET_ERROR_TYPE_WARNING, + _("Could not resume running search, will resume as paused search\n")); + } + signal_search_resume(sc); + GNUNET_free(uris); return sc; cleanup: - GNUNET_free_non_null (emsg); - free_search_context (sc); - GNUNET_free_non_null (uris); + GNUNET_free_non_null(emsg); + free_search_context(sc); + GNUNET_free_non_null(uris); return NULL; } @@ -2992,7 +3020,7 @@ cleanup: * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_search_file (void *cls, const char *filename) +deserialize_search_file(void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; char *ser; @@ -3001,36 +3029,36 @@ deserialize_search_file (void *cls, const char *filename) struct GNUNET_FS_SearchContext *sc; struct stat buf; - if (0 != stat (filename, &buf)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); - return GNUNET_OK; - } - if (S_ISDIR (buf.st_mode)) + if (0 != stat(filename, &buf)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); + return GNUNET_OK; + } + if (S_ISDIR(buf.st_mode)) return GNUNET_OK; /* skip directories */ - ser = get_serialization_short_name (filename); - rh = GNUNET_BIO_read_open (filename); + ser = get_serialization_short_name(filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - if (NULL != ser) { - GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); - GNUNET_free (ser); + if (NULL != ser) + { + GNUNET_FS_remove_sync_file_(h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); + GNUNET_free(ser); + } + return GNUNET_OK; } - return GNUNET_OK; - } - sc = deserialize_search (h, rh, NULL, ser); + sc = deserialize_search(h, rh, NULL, ser); if (NULL != sc) - sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); - GNUNET_free (ser); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming search operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + sc->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, sc); + GNUNET_free(ser); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } return GNUNET_OK; } @@ -3044,32 +3072,32 @@ deserialize_search_file (void *cls, const char *filename) * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_download_file (void *cls, const char *filename) +deserialize_download_file(void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; char *ser; char *emsg; struct GNUNET_BIO_ReadHandle *rh; - ser = get_serialization_short_name (filename); - rh = GNUNET_BIO_read_open (filename); + ser = get_serialization_short_name(filename); + rh = GNUNET_BIO_read_open(filename); if (NULL == rh) - { - if (0 != unlink (filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); - GNUNET_free (ser); - return GNUNET_OK; - } - deserialize_download (h, rh, NULL, NULL, ser); - GNUNET_free (ser); - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failure while resuming download operation `%s': %s\n"), - filename, - emsg); - GNUNET_free (emsg); - } + { + if (0 != unlink(filename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); + GNUNET_free(ser); + return GNUNET_OK; + } + deserialize_download(h, rh, NULL, NULL, ser); + GNUNET_free(ser); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failure while resuming download operation `%s': %s\n"), + filename, + emsg); + GNUNET_free(emsg); + } return GNUNET_OK; } @@ -3082,18 +3110,18 @@ deserialize_download_file (void *cls, const char *filename) * @param h the `struct GNUNET_FS_Handle *` */ static void -deserialization_master (const char *master_path, - GNUNET_FileNameCallback proc, - struct GNUNET_FS_Handle *h) +deserialization_master(const char *master_path, + GNUNET_FileNameCallback proc, + struct GNUNET_FS_Handle *h) { char *dn; - dn = get_serialization_file_name (h, master_path, ""); + dn = get_serialization_file_name(h, master_path, ""); if (NULL == dn) return; - if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) - GNUNET_DISK_directory_scan (dn, proc, h); - GNUNET_free (dn); + if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) + GNUNET_DISK_directory_scan(dn, proc, h); + GNUNET_free(dn); } @@ -3109,20 +3137,20 @@ deserialization_master (const char *master_path, * @return NULL on error */ struct GNUNET_FS_Handle * -GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *client_name, - GNUNET_FS_ProgressCallback upcb, - void *upcb_cls, - enum GNUNET_FS_Flags flags, - ...) +GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *client_name, + GNUNET_FS_ProgressCallback upcb, + void *upcb_cls, + enum GNUNET_FS_Flags flags, + ...) { struct GNUNET_FS_Handle *ret; enum GNUNET_FS_OPTIONS opt; va_list ap; - ret = GNUNET_new (struct GNUNET_FS_Handle); + ret = GNUNET_new(struct GNUNET_FS_Handle); ret->cfg = cfg; - ret->client_name = GNUNET_strdup (client_name); + ret->client_name = GNUNET_strdup(client_name); ret->upcb = upcb; ret->upcb_cls = upcb_cls; ret->flags = flags; @@ -3130,44 +3158,46 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ - va_start (ap, flags); + va_start(ap, flags); while (GNUNET_FS_OPTIONS_END != - (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) - { - switch (opt) + (opt = GNUNET_VA_ARG_ENUM(ap, GNUNET_FS_OPTIONS))) { - case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: - ret->max_parallel_downloads = va_arg (ap, unsigned int); + switch (opt) + { + case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: + ret->max_parallel_downloads = va_arg(ap, unsigned int); - break; - case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: - ret->max_parallel_requests = va_arg (ap, unsigned int); + break; - break; - default: - GNUNET_break (0); - GNUNET_free (ret->client_name); - GNUNET_free (ret); - va_end (ap); - return NULL; + case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: + ret->max_parallel_requests = va_arg(ap, unsigned int); + + break; + + default: + GNUNET_break(0); + GNUNET_free(ret->client_name); + GNUNET_free(ret); + va_end(ap); + return NULL; + } } - } - va_end (ap); + va_end(ap); if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) - { - deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, - &deserialize_publish_file, - ret); - deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, - &deserialize_search_file, - ret); - deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, - &deserialize_download_file, - ret); - deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - &deserialize_unindex_file, - ret); - } + { + deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + &deserialize_publish_file, + ret); + deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_SEARCH, + &deserialize_search_file, + ret); + deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + &deserialize_download_file, + ret); + deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + &deserialize_unindex_file, + ret); + } return ret; } @@ -3182,14 +3212,14 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param h handle that was returned from #GNUNET_FS_start() */ void -GNUNET_FS_stop (struct GNUNET_FS_Handle *h) +GNUNET_FS_stop(struct GNUNET_FS_Handle *h) { while (NULL != h->top_head) - h->top_head->ssf (h->top_head->ssf_cls); + h->top_head->ssf(h->top_head->ssf_cls); if (NULL != h->queue_job) - GNUNET_SCHEDULER_cancel (h->queue_job); - GNUNET_free (h->client_name); - GNUNET_free (h); + GNUNET_SCHEDULER_cancel(h->queue_job); + GNUNET_free(h->client_name); + GNUNET_free(h); } diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h index ad054ef06..dcc487eb1 100644 --- a/src/fs/fs_api.h +++ b/src/fs/fs_api.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_api.h @@ -90,9 +90,7 @@ * @brief complete information needed * to download a file. */ -struct FileIdentifier -{ - +struct FileIdentifier { /** * Total size of the file in bytes. (network byte order (!)) */ @@ -102,7 +100,6 @@ struct FileIdentifier * Query and key of the top GNUNET_EC_IBlock. */ struct ContentHashKey chk; - }; @@ -110,8 +107,7 @@ struct FileIdentifier * Information about a file and its location * (peer claiming to share the file). */ -struct Location -{ +struct Location { /** * Information about the shared file. */ @@ -132,14 +128,12 @@ struct Location * peer identity and expiration time. */ struct GNUNET_CRYPTO_EddsaSignature contentSignature; - }; /** * Types of URIs. */ -enum GNUNET_FS_UriType -{ +enum GNUNET_FS_UriType { /** * Content-hash-key (simple file). */ @@ -165,17 +159,14 @@ enum GNUNET_FS_UriType /** * A Universal Resource Identifier (URI), opaque. */ -struct GNUNET_FS_Uri -{ +struct GNUNET_FS_Uri { /** * Type of the URI. */ enum GNUNET_FS_UriType type; - union - { - struct - { + union { + struct { /** * Keywords start with a '+' if they are mandatory (in which * case the '+' is NOT part of the keyword) and with a simple @@ -193,8 +184,7 @@ struct GNUNET_FS_Uri unsigned int keywordCount; } ksk; - struct - { + struct { /** * Identifier of the namespace. */ @@ -205,7 +195,6 @@ struct GNUNET_FS_Uri * namespace. */ char *identifier; - } sks; /** @@ -220,7 +209,6 @@ struct GNUNET_FS_Uri */ struct Location loc; } data; - }; @@ -228,9 +216,7 @@ struct GNUNET_FS_Uri * Information for a file or directory that is * about to be published. */ -struct GNUNET_FS_FileInformation -{ - +struct GNUNET_FS_FileInformation { /** * Files in a directory are kept as a linked list. */ @@ -309,15 +295,11 @@ struct GNUNET_FS_FileInformation /** * Data describing either the file or the directory. */ - union - { - + union { /** * Data for a file. */ - struct - { - + struct { /** * Function that can be used to read the data for the file. */ @@ -356,15 +338,12 @@ struct GNUNET_FS_FileInformation * #GNUNET_YES if this step has been completed. */ int index_start_confirmed; - } file; /** * Data for a directory. */ - struct - { - + struct { /** * Linked list of entries in the directory. */ @@ -391,9 +370,7 @@ struct GNUNET_FS_FileInformation * Sum of all of the sizes of all of the files in the directory. */ uint64_t contents_size; - } dir; - } data; /** @@ -405,15 +382,13 @@ struct GNUNET_FS_FileInformation * Are we done publishing this file? */ int is_published; - }; /** * Priorities for the queue. */ -enum GNUNET_FS_QueuePriority -{ +enum GNUNET_FS_QueuePriority { /** * This is a probe (low priority). */ @@ -429,8 +404,7 @@ enum GNUNET_FS_QueuePriority /** * Entry in the job queue. */ -struct GNUNET_FS_QueueEntry -{ +struct GNUNET_FS_QueueEntry { /** * This is a linked list. */ @@ -501,16 +475,13 @@ struct GNUNET_FS_QueueEntry * #GNUNET_YES if the job is active now. */ int active; - }; /** * Information we store for each search result. */ -struct GNUNET_FS_SearchResult -{ - +struct GNUNET_FS_SearchResult { /** * File-sharing context this result belongs to. */ @@ -625,7 +596,6 @@ struct GNUNET_FS_SearchResult * search result. */ uint32_t availability_trials; - }; @@ -641,12 +611,12 @@ struct GNUNET_FS_SearchResult * @return queue handle */ struct GNUNET_FS_QueueEntry * -GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, - GNUNET_SCHEDULER_TaskCallback start, - GNUNET_SCHEDULER_TaskCallback stop, - void *cls, - unsigned int blocks, - enum GNUNET_FS_QueuePriority priority); +GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, + GNUNET_SCHEDULER_TaskCallback start, + GNUNET_SCHEDULER_TaskCallback stop, + void *cls, + unsigned int blocks, + enum GNUNET_FS_QueuePriority priority); /** @@ -655,7 +625,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, * @param qe handle for the job */ void -GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); +GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe); /** @@ -675,11 +645,11 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); * @return number of bytes written, usually "max", 0 on error */ size_t -GNUNET_FS_data_reader_file_ (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg); +GNUNET_FS_data_reader_file_(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg); /** @@ -689,7 +659,7 @@ GNUNET_FS_data_reader_file_ (void *cls, * @return closure to use */ void * -GNUNET_FS_make_file_reader_context_ (const char *filename); +GNUNET_FS_make_file_reader_context_(const char *filename); @@ -710,11 +680,11 @@ GNUNET_FS_make_file_reader_context_ (const char *filename); * @return number of bytes written, usually @a max, 0 on error */ size_t -GNUNET_FS_data_reader_copy_ (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg); +GNUNET_FS_data_reader_copy_(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg); /** @@ -733,8 +703,8 @@ GNUNET_FS_data_reader_copy_ (void *cls, * field in the `struct GNUNET_FS_ProgressInfo`. */ void * -GNUNET_FS_search_probe_progress_ (void *cls, - const struct GNUNET_FS_ProgressInfo *info); +GNUNET_FS_search_probe_progress_(void *cls, + const struct GNUNET_FS_ProgressInfo *info); /** @@ -743,7 +713,7 @@ GNUNET_FS_search_probe_progress_ (void *cls, * @param cls `struct GNUNET_FS_PublishContext` identifies the upload */ void -GNUNET_FS_publish_main_ (void *cls); +GNUNET_FS_publish_main_(void *cls); /** @@ -754,8 +724,8 @@ GNUNET_FS_publish_main_ (void *cls); * @param file_id computed hash, NULL on error */ void -GNUNET_FS_unindex_process_hash_ (void *cls, - const struct GNUNET_HashCode *file_id); +GNUNET_FS_unindex_process_hash_(void *cls, + const struct GNUNET_HashCode *file_id); /** @@ -764,7 +734,7 @@ GNUNET_FS_unindex_process_hash_ (void *cls, * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc); +GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc); /** @@ -773,7 +743,7 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc); * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc); +GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc); /** @@ -787,10 +757,10 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc); * @return value returned from callback */ void * -GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_PublishContext *pc, - const struct GNUNET_FS_FileInformation *p, - uint64_t offset); +GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_PublishContext *pc, + const struct GNUNET_FS_FileInformation *p, + uint64_t offset); /** @@ -801,8 +771,8 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @param dc overall download context */ void -GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_DownloadContext *dc); +GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_DownloadContext *dc); /** @@ -812,7 +782,7 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @param cls the 'struct GNUNET_FS_DownloadContext' */ void -GNUNET_FS_download_start_task_ (void *cls); +GNUNET_FS_download_start_task_(void *cls); @@ -825,9 +795,9 @@ GNUNET_FS_download_start_task_ (void *cls); * @param offset where we are in the file (for progress) */ void -GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_UnindexContext *uc, - uint64_t offset); +GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_UnindexContext *uc, + uint64_t offset); /** * Fill in all of the generic fields for a search event and @@ -839,9 +809,9 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @return value returned by the callback */ void * -GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_Handle *h, - struct GNUNET_FS_SearchContext *sc); +GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_Handle *h, + struct GNUNET_FS_SearchContext *sc); /** @@ -850,7 +820,7 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc); +GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc); /** * Build the request and actually initiate the search using the @@ -860,7 +830,7 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc); * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc); +GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc); /** * Start the downloading process (by entering the queue). @@ -868,7 +838,7 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc); * @param dc our download context */ void -GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc); +GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc); /** @@ -877,7 +847,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc); * @param sr the search result */ void -GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr); +GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr); /** @@ -888,9 +858,9 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr); * @param ent entity identifier */ void -GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, - const char *ext, - const char *ent); +GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, + const char *ext, + const char *ent); /** @@ -901,9 +871,9 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, * @param uni unique name of parent */ void -GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, - const char *ext, - const char *uni); +GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni); /** @@ -915,7 +885,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, * @param fi the struct to sync */ void -GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f); +GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *f); /** @@ -927,7 +897,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f); * @param pc the struct to sync */ void -GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); +GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc); /** @@ -939,7 +909,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); * @param uc the struct to sync */ void -GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc); +GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc); /** @@ -951,7 +921,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc); * @param sc the struct to sync */ void -GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc); +GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc); /** @@ -963,7 +933,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc); * @param sr the struct to sync */ void -GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr); +GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr); /** @@ -975,7 +945,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr); * @param dc the struct to sync */ void -GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc); +GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc); /** @@ -985,7 +955,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc); * @param cls the `struct GNUNET_FS_PublishContext` to signal for */ void -GNUNET_FS_publish_signal_suspend_ (void *cls); +GNUNET_FS_publish_signal_suspend_(void *cls); /** @@ -995,7 +965,7 @@ GNUNET_FS_publish_signal_suspend_ (void *cls); * @param cls the 'struct GNUNET_FS_SearchContext' to signal for */ void -GNUNET_FS_search_signal_suspend_ (void *cls); +GNUNET_FS_search_signal_suspend_(void *cls); /** @@ -1005,7 +975,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls); * @param cls the `struct GNUNET_FS_DownloadContext` to signal for */ void -GNUNET_FS_download_signal_suspend_ (void *cls); +GNUNET_FS_download_signal_suspend_(void *cls); /** @@ -1015,7 +985,7 @@ GNUNET_FS_download_signal_suspend_ (void *cls); * @param cls the `struct GNUNET_FS_UnindexContext` to signal for */ void -GNUNET_FS_unindex_signal_suspend_ (void *cls); +GNUNET_FS_unindex_signal_suspend_(void *cls); /** @@ -1031,8 +1001,7 @@ typedef void (*SuspendSignalFunction) (void *cls); * We track all of the top-level activities of FS * so that we can signal 'suspend' on shutdown. */ -struct TopLevelActivity -{ +struct TopLevelActivity { /** * This is a doubly-linked list. */ @@ -1064,9 +1033,9 @@ struct TopLevelActivity * @return fresh top-level activity handle */ struct TopLevelActivity * -GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, - SuspendSignalFunction ssf, - void *ssf_cls); +GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, + SuspendSignalFunction ssf, + void *ssf_cls); /** @@ -1076,16 +1045,15 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, * @param top top level activity entry */ void -GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, - struct TopLevelActivity *top); +GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, + struct TopLevelActivity *top); /** * Master context for most FS operations. */ -struct GNUNET_FS_Handle -{ +struct GNUNET_FS_Handle { /** * Configuration to use. */ @@ -1188,15 +1156,13 @@ struct GNUNET_FS_Handle * Maximum number of parallel requests. */ unsigned int max_parallel_requests; - }; /** * Handle for controlling a publication process. */ -struct GNUNET_FS_PublishContext -{ +struct GNUNET_FS_PublishContext { /** * Handle to the global fs context. */ @@ -1322,8 +1288,7 @@ struct GNUNET_FS_PublishContext /** * Phases of unindex processing (state machine). */ -enum UnindexState -{ +enum UnindexState { /** * We're currently hashing the file. */ @@ -1366,9 +1331,7 @@ enum UnindexState /** * Handle for controlling an unindexing operation. */ -struct GNUNET_FS_UnindexContext -{ - +struct GNUNET_FS_UnindexContext { /** * The content hash key of the last block we processed, will in the * end be set to the CHK from the URI. Used to remove the KBlocks. @@ -1482,16 +1445,13 @@ struct GNUNET_FS_UnindexContext * Current operatinonal phase. */ enum UnindexState state; - }; /** * Information we keep for each keyword in a keyword search. */ -struct SearchRequestEntry -{ - +struct SearchRequestEntry { /** * Hash of the public key, also known as the query. */ @@ -1523,15 +1483,13 @@ struct SearchRequestEntry * (started with '+')? */ int mandatory; - }; /** * Handle for controlling a search. */ -struct GNUNET_FS_SearchContext -{ +struct GNUNET_FS_SearchContext { /** * Handle to the global FS context. */ @@ -1627,8 +1585,7 @@ struct GNUNET_FS_SearchContext * order of progression is linear through the states, alternatives * are documented in the comments. */ -enum BlockRequestState -{ +enum BlockRequestState { /** * Initial state, block has only been allocated (since it is * relevant to the overall download request). @@ -1695,9 +1652,7 @@ enum BlockRequestState /** * Information about an active download request. */ -struct DownloadRequest -{ - +struct DownloadRequest { /** * Parent in the CHK-tree. */ @@ -1740,7 +1695,6 @@ struct DownloadRequest * State in the FSM. */ enum BlockRequestState state; - }; @@ -1750,7 +1704,7 @@ struct DownloadRequest * @param dr request to free */ void -GNUNET_FS_free_download_request_ (struct DownloadRequest *dr); +GNUNET_FS_free_download_request_(struct DownloadRequest *dr); /** @@ -1759,15 +1713,13 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr); * @param sr result to start pinging for. */ void -GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr); +GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr); /** * Context for controlling a download. */ -struct GNUNET_FS_DownloadContext -{ - +struct GNUNET_FS_DownloadContext { /** * Global FS context. */ @@ -1959,7 +1911,6 @@ struct GNUNET_FS_DownloadContext * Are we ready to issue requests (reconstructions are finished)? */ int issue_requests; - }; diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index 2dadc4835..ae7727cf0 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_directory.c @@ -51,18 +51,18 @@ * we have no mime-type information (treat as #GNUNET_NO) */ int -GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md) +GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_CONTAINER_MetaData *md) { char *mime; int ret; if (NULL == md) return GNUNET_SYSERR; - mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); + mime = GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); if (NULL == mime) return GNUNET_SYSERR; - ret = (0 == strcasecmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; - GNUNET_free (mime); + ret = (0 == strcasecmp(mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; + GNUNET_free(mime); return ret; } @@ -74,32 +74,30 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData * * @param md metadata to add mimetype to */ void -GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md) +GNUNET_FS_meta_data_make_directory(struct GNUNET_CONTAINER_MetaData *md) { char *mime; mime = - GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); + GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); if (mime != NULL) - { - GNUNET_break (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)); - GNUNET_free (mime); - return; - } - GNUNET_CONTAINER_meta_data_insert (md, "", - EXTRACTOR_METATYPE_MIMETYPE, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - GNUNET_FS_DIRECTORY_MIME, - strlen (GNUNET_FS_DIRECTORY_MIME) + 1); + { + GNUNET_break(0 == strcmp(mime, GNUNET_FS_DIRECTORY_MIME)); + GNUNET_free(mime); + return; + } + GNUNET_CONTAINER_meta_data_insert(md, "", + EXTRACTOR_METATYPE_MIMETYPE, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + GNUNET_FS_DIRECTORY_MIME, + strlen(GNUNET_FS_DIRECTORY_MIME) + 1); } /** * Closure for 'find_full_data'. */ -struct GetFullDataClosure -{ - +struct GetFullDataClosure { /** * Extracted binary meta data. */ @@ -130,22 +128,22 @@ struct GetFullDataClosure * @return 0 to continue extracting, 1 to abort */ static int -find_full_data (void *cls, const char *plugin_name, - enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, const char *data, size_t data_len) +find_full_data(void *cls, const char *plugin_name, + enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, const char *data, size_t data_len) { struct GetFullDataClosure *gfdc = cls; if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) - { - gfdc->size = data_len; - if (data_len > 0) { - gfdc->data = GNUNET_malloc (data_len); - GNUNET_memcpy (gfdc->data, data, data_len); + gfdc->size = data_len; + if (data_len > 0) + { + gfdc->data = GNUNET_malloc(data_len); + GNUNET_memcpy(gfdc->data, data, data_len); + } + return 1; } - return 1; - } return 0; } @@ -176,11 +174,11 @@ find_full_data (void *cls, const char *plugin_name, * #GNUNET_SYSERR if @a data does not represent a directory */ int -GNUNET_FS_directory_list_contents (size_t size, - const void *data, - uint64_t offset, - GNUNET_FS_DirectoryEntryProcessor dep, - void *dep_cls) +GNUNET_FS_directory_list_contents(size_t size, + const void *data, + uint64_t offset, + GNUNET_FS_DirectoryEntryProcessor dep, + void *dep_cls) { struct GetFullDataClosure full_data; const char *cdata = data; @@ -194,132 +192,131 @@ GNUNET_FS_directory_list_contents (size_t size, char *filename; if ((offset == 0) && - ((size < 8 + sizeof (uint32_t)) || - (0 != memcmp (cdata, - GNUNET_FS_DIRECTORY_MAGIC, - 8)))) + ((size < 8 + sizeof(uint32_t)) || + (0 != memcmp(cdata, + GNUNET_FS_DIRECTORY_MAGIC, + 8)))) return GNUNET_SYSERR; pos = offset; if (offset == 0) - { - GNUNET_memcpy (&mdSize, - &cdata[8], - sizeof (uint32_t)); - mdSize = ntohl (mdSize); - if (mdSize > size - 8 - sizeof (uint32_t)) { - /* invalid size */ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("MAGIC mismatch. This is not a GNUnet directory.\n")); - return GNUNET_SYSERR; - } - md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + sizeof (uint32_t)], - mdSize); - if (md == NULL) - { - GNUNET_break (0); - return GNUNET_SYSERR; /* malformed ! */ + GNUNET_memcpy(&mdSize, + &cdata[8], + sizeof(uint32_t)); + mdSize = ntohl(mdSize); + if (mdSize > size - 8 - sizeof(uint32_t)) + { + /* invalid size */ + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("MAGIC mismatch. This is not a GNUnet directory.\n")); + return GNUNET_SYSERR; + } + md = GNUNET_CONTAINER_meta_data_deserialize(&cdata[8 + sizeof(uint32_t)], + mdSize); + if (md == NULL) + { + GNUNET_break(0); + return GNUNET_SYSERR; /* malformed ! */ + } + dep(dep_cls, + NULL, + NULL, + md, + 0, + NULL); + GNUNET_CONTAINER_meta_data_destroy(md); + pos = 8 + sizeof(uint32_t) + mdSize; } - dep (dep_cls, - NULL, - NULL, - md, - 0, - NULL); - GNUNET_CONTAINER_meta_data_destroy (md); - pos = 8 + sizeof (uint32_t) + mdSize; - } while (pos < size) - { - /* find end of URI */ - if (cdata[pos] == '\0') - { - /* URI is never empty, must be end of block, - * skip to next alignment */ - align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; - if (align == pos) - { - /* if we were already aligned, still skip a block! */ - align += DBLOCK_SIZE; - } - pos = align; - if (pos >= size) - { - /* malformed - or partial download... */ - break; - } - } - epos = pos; - while ((epos < size) && (cdata[epos] != '\0')) - epos++; - if (epos >= size) - return GNUNET_NO; /* malformed - or partial download */ - - uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); - pos = epos + 1; - if (NULL == uri) - { - GNUNET_free (emsg); - pos--; /* go back to '\0' to force going to next alignment */ - continue; - } - if (GNUNET_FS_uri_test_ksk (uri)) { - GNUNET_FS_uri_destroy (uri); - GNUNET_break (0); - return GNUNET_NO; /* illegal in directory! */ - } + /* find end of URI */ + if (cdata[pos] == '\0') + { + /* URI is never empty, must be end of block, + * skip to next alignment */ + align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; + if (align == pos) + { + /* if we were already aligned, still skip a block! */ + align += DBLOCK_SIZE; + } + pos = align; + if (pos >= size) + { + /* malformed - or partial download... */ + break; + } + } + epos = pos; + while ((epos < size) && (cdata[epos] != '\0')) + epos++; + if (epos >= size) + return GNUNET_NO; /* malformed - or partial download */ + + uri = GNUNET_FS_uri_parse(&cdata[pos], &emsg); + pos = epos + 1; + if (NULL == uri) + { + GNUNET_free(emsg); + pos--; /* go back to '\0' to force going to next alignment */ + continue; + } + if (GNUNET_FS_uri_test_ksk(uri)) + { + GNUNET_FS_uri_destroy(uri); + GNUNET_break(0); + return GNUNET_NO; /* illegal in directory! */ + } - GNUNET_memcpy (&mdSize, - &cdata[pos], - sizeof (uint32_t)); - mdSize = ntohl (mdSize); - pos += sizeof (uint32_t); - if (pos + mdSize > size) - { - GNUNET_FS_uri_destroy (uri); - return GNUNET_NO; /* malformed - or partial download */ - } + GNUNET_memcpy(&mdSize, + &cdata[pos], + sizeof(uint32_t)); + mdSize = ntohl(mdSize); + pos += sizeof(uint32_t); + if (pos + mdSize > size) + { + GNUNET_FS_uri_destroy(uri); + return GNUNET_NO; /* malformed - or partial download */ + } - md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], - mdSize); - if (NULL == md) - { - GNUNET_FS_uri_destroy (uri); - GNUNET_break (0); - return GNUNET_NO; /* malformed ! */ - } - pos += mdSize; - filename = - GNUNET_CONTAINER_meta_data_get_by_type (md, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); - full_data.size = 0; - full_data.data = NULL; - GNUNET_CONTAINER_meta_data_iterate (md, - &find_full_data, - &full_data); - if (NULL != dep) - { - dep (dep_cls, - filename, - uri, - md, - full_data.size, - full_data.data); + md = GNUNET_CONTAINER_meta_data_deserialize(&cdata[pos], + mdSize); + if (NULL == md) + { + GNUNET_FS_uri_destroy(uri); + GNUNET_break(0); + return GNUNET_NO; /* malformed ! */ + } + pos += mdSize; + filename = + GNUNET_CONTAINER_meta_data_get_by_type(md, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + full_data.size = 0; + full_data.data = NULL; + GNUNET_CONTAINER_meta_data_iterate(md, + &find_full_data, + &full_data); + if (NULL != dep) + { + dep(dep_cls, + filename, + uri, + md, + full_data.size, + full_data.data); + } + GNUNET_free_non_null(full_data.data); + GNUNET_free_non_null(filename); + GNUNET_CONTAINER_meta_data_destroy(md); + GNUNET_FS_uri_destroy(uri); } - GNUNET_free_non_null (full_data.data); - GNUNET_free_non_null (filename); - GNUNET_CONTAINER_meta_data_destroy (md); - GNUNET_FS_uri_destroy (uri); - } return GNUNET_OK; } /** * Entries in the directory (builder). */ -struct BuilderEntry -{ +struct BuilderEntry { /** * This is a linked list. */ @@ -334,8 +331,7 @@ struct BuilderEntry /** * Internal state of a directory builder. */ -struct GNUNET_FS_DirectoryBuilder -{ +struct GNUNET_FS_DirectoryBuilder { /** * Meta-data for the directory itself. */ @@ -359,17 +355,17 @@ struct GNUNET_FS_DirectoryBuilder * @param mdir metadata for the directory */ struct GNUNET_FS_DirectoryBuilder * -GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData - *mdir) +GNUNET_FS_directory_builder_create(const struct GNUNET_CONTAINER_MetaData + *mdir) { struct GNUNET_FS_DirectoryBuilder *ret; - ret = GNUNET_new (struct GNUNET_FS_DirectoryBuilder); + ret = GNUNET_new(struct GNUNET_FS_DirectoryBuilder); if (mdir != NULL) - ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); + ret->meta = GNUNET_CONTAINER_meta_data_duplicate(mdir); else - ret->meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_FS_meta_data_make_directory (ret->meta); + ret->meta = GNUNET_CONTAINER_meta_data_create(); + GNUNET_FS_meta_data_make_directory(ret->meta); return ret; } @@ -385,10 +381,10 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData * by the uri which must be of type LOC or CHK */ void -GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *md, - const void *data) +GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *md, + const void *data) { struct GNUNET_FS_Uri *curi; struct BuilderEntry *e; @@ -404,71 +400,71 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, struct GNUNET_CONTAINER_MetaData *meta; const struct GNUNET_CONTAINER_MetaData *meta_use; - GNUNET_assert (!GNUNET_FS_uri_test_ksk (uri)); + GNUNET_assert(!GNUNET_FS_uri_test_ksk(uri)); if (NULL != data) - { - GNUNET_assert (!GNUNET_FS_uri_test_sks (uri)); - if (GNUNET_FS_uri_test_chk (uri)) { - fsize = GNUNET_FS_uri_chk_get_file_size (uri); + GNUNET_assert(!GNUNET_FS_uri_test_sks(uri)); + if (GNUNET_FS_uri_test_chk(uri)) + { + fsize = GNUNET_FS_uri_chk_get_file_size(uri); + } + else + { + curi = GNUNET_FS_uri_loc_get_uri(uri); + GNUNET_assert(NULL != curi); + fsize = GNUNET_FS_uri_chk_get_file_size(curi); + GNUNET_FS_uri_destroy(curi); + } } - else + else { - curi = GNUNET_FS_uri_loc_get_uri (uri); - GNUNET_assert (NULL != curi); - fsize = GNUNET_FS_uri_chk_get_file_size (curi); - GNUNET_FS_uri_destroy (curi); + fsize = 0; /* not given */ } - } - else - { - fsize = 0; /* not given */ - } if (fsize > MAX_INLINE_SIZE) fsize = 0; /* too large */ - uris = GNUNET_FS_uri_to_string (uri); - slen = strlen (uris) + 1; - mds = GNUNET_CONTAINER_meta_data_get_serialized_size (md); + uris = GNUNET_FS_uri_to_string(uri); + slen = strlen(uris) + 1; + mds = GNUNET_CONTAINER_meta_data_get_serialized_size(md); meta_use = md; meta = NULL; if (fsize > 0) - { - meta = GNUNET_CONTAINER_meta_data_duplicate (md); - GNUNET_CONTAINER_meta_data_insert (meta, "", - EXTRACTOR_METATYPE_GNUNET_FULL_DATA, - EXTRACTOR_METAFORMAT_BINARY, NULL, data, - fsize); - mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); - if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE == - (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE) { - /* adding full data would not cause us to cross - * additional blocks, so add it! */ - meta_use = meta; - mds = mdxs; + meta = GNUNET_CONTAINER_meta_data_duplicate(md); + GNUNET_CONTAINER_meta_data_insert(meta, "", + EXTRACTOR_METATYPE_GNUNET_FULL_DATA, + EXTRACTOR_METAFORMAT_BINARY, NULL, data, + fsize); + mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); + if ((slen + sizeof(uint32_t) + mdxs - 1) / DBLOCK_SIZE == + (slen + sizeof(uint32_t) + mds - 1) / DBLOCK_SIZE) + { + /* adding full data would not cause us to cross + * additional blocks, so add it! */ + meta_use = meta; + mds = mdxs; + } } - } if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) mds = GNUNET_MAX_MALLOC_CHECKED / 2; - e = GNUNET_malloc (sizeof (struct BuilderEntry) + slen + mds + - sizeof (uint32_t)); - ser = (char *) &e[1]; - GNUNET_memcpy (ser, uris, slen); - GNUNET_free (uris); - sptr = &ser[slen + sizeof (uint32_t)]; + e = GNUNET_malloc(sizeof(struct BuilderEntry) + slen + mds + + sizeof(uint32_t)); + ser = (char *)&e[1]; + GNUNET_memcpy(ser, uris, slen); + GNUNET_free(uris); + sptr = &ser[slen + sizeof(uint32_t)]; ret = - GNUNET_CONTAINER_meta_data_serialize (meta_use, &sptr, mds, - GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); + GNUNET_CONTAINER_meta_data_serialize(meta_use, &sptr, mds, + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); if (NULL != meta) - GNUNET_CONTAINER_meta_data_destroy (meta); + GNUNET_CONTAINER_meta_data_destroy(meta); if (ret == -1) mds = 0; else mds = ret; - big = htonl (mds); - GNUNET_memcpy (&ser[slen], &big, sizeof (uint32_t)); - e->len = slen + sizeof (uint32_t) + mds; + big = htonl(mds); + GNUNET_memcpy(&ser[slen], &big, sizeof(uint32_t)); + e->len = slen + sizeof(uint32_t) + mds; e->next = bld->head; bld->head = e; bld->count++; @@ -481,7 +477,7 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, * after alignment to the DBLOCK_SIZE. */ static size_t -do_align (size_t start_position, size_t end_position) +do_align(size_t start_position, size_t end_position) { size_t align; @@ -502,8 +498,8 @@ do_align (size_t start_position, size_t end_position) * @param perm the permutation of the blocks (updated) */ static void -block_align (size_t start, unsigned int count, const size_t * sizes, - unsigned int *perm) +block_align(size_t start, unsigned int count, const size_t * sizes, + unsigned int *perm) { unsigned int i; unsigned int j; @@ -517,46 +513,46 @@ block_align (size_t start, unsigned int count, const size_t * sizes, cpos = start; for (i = 0; i < count; i++) - { - start = cpos; - badness = 0x7FFFFFFF; - best = -1; - for (j = i; j < count; j++) { - cval = perm[j]; - cend = cpos + sizes[cval]; - if (cpos % DBLOCK_SIZE == 0) - { - /* prefer placing the largest blocks first */ - cbad = -(cend % DBLOCK_SIZE); - } - else - { - if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE) - { - /* Data fits into the same block! Prefer small left-overs! */ - cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE; - } - else + start = cpos; + badness = 0x7FFFFFFF; + best = -1; + for (j = i; j < count; j++) { - /* Would have to waste space to re-align, add big factor, this - * case is a real loss (proportional to space wasted)! */ - cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE); + cval = perm[j]; + cend = cpos + sizes[cval]; + if (cpos % DBLOCK_SIZE == 0) + { + /* prefer placing the largest blocks first */ + cbad = -(cend % DBLOCK_SIZE); + } + else + { + if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE) + { + /* Data fits into the same block! Prefer small left-overs! */ + cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE; + } + else + { + /* Would have to waste space to re-align, add big factor, this + * case is a real loss (proportional to space wasted)! */ + cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE); + } + } + if (cbad < badness) + { + best = j; + badness = cbad; + } } - } - if (cbad < badness) - { - best = j; - badness = cbad; - } + GNUNET_assert(best != -1); + tmp = perm[i]; + perm[i] = perm[best]; + perm[best] = tmp; + cpos += sizes[perm[i]]; + cpos = do_align(start, cpos); } - GNUNET_assert (best != -1); - tmp = perm[i]; - perm[i] = perm[best]; - perm[best] = tmp; - cpos += sizes[perm[i]]; - cpos = do_align (start, cpos); - } } @@ -571,9 +567,9 @@ block_align (size_t start, unsigned int count, const size_t * sizes, * @return #GNUNET_OK on success */ int -GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, - size_t * rsize, - void **rdata) +GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, + size_t * rsize, + void **rdata) { char *data; char *sptr; @@ -589,82 +585,82 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, ssize_t ret; uint32_t big; - size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof (uint32_t); - size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta); + size = strlen(GNUNET_DIRECTORY_MAGIC) + sizeof(uint32_t); + size += GNUNET_CONTAINER_meta_data_get_serialized_size(bld->meta); sizes = NULL; perm = NULL; bes = NULL; if (0 < bld->count) - { - sizes = GNUNET_new_array (bld->count, - size_t); - perm = GNUNET_new_array (bld->count, - unsigned int); - bes = GNUNET_new_array (bld->count, - struct BuilderEntry *); - pos = bld->head; - for (i = 0; i < bld->count; i++) - { - perm[i] = i; - bes[i] = pos; - sizes[i] = pos->len; - pos = pos->next; - } - block_align (size, bld->count, sizes, perm); - /* compute final size with alignment */ - for (i = 0; i < bld->count; i++) { - psize = size; - size += sizes[perm[i]]; - size = do_align (psize, size); + sizes = GNUNET_new_array(bld->count, + size_t); + perm = GNUNET_new_array(bld->count, + unsigned int); + bes = GNUNET_new_array(bld->count, + struct BuilderEntry *); + pos = bld->head; + for (i = 0; i < bld->count; i++) + { + perm[i] = i; + bes[i] = pos; + sizes[i] = pos->len; + pos = pos->next; + } + block_align(size, bld->count, sizes, perm); + /* compute final size with alignment */ + for (i = 0; i < bld->count; i++) + { + psize = size; + size += sizes[perm[i]]; + size = do_align(psize, size); + } } - } *rsize = size; - data = GNUNET_malloc_large (size); + data = GNUNET_malloc_large(size); if (data == NULL) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, - "malloc"); - *rsize = 0; - *rdata = NULL; - GNUNET_free_non_null (sizes); - GNUNET_free_non_null (perm); - GNUNET_free_non_null (bes); - return GNUNET_SYSERR; - } + { + GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, + "malloc"); + *rsize = 0; + *rdata = NULL; + GNUNET_free_non_null(sizes); + GNUNET_free_non_null(perm); + GNUNET_free_non_null(bes); + return GNUNET_SYSERR; + } *rdata = data; - GNUNET_memcpy (data, - GNUNET_DIRECTORY_MAGIC, - strlen (GNUNET_DIRECTORY_MAGIC)); - off = strlen (GNUNET_DIRECTORY_MAGIC); + GNUNET_memcpy(data, + GNUNET_DIRECTORY_MAGIC, + strlen(GNUNET_DIRECTORY_MAGIC)); + off = strlen(GNUNET_DIRECTORY_MAGIC); - sptr = &data[off + sizeof (uint32_t)]; + sptr = &data[off + sizeof(uint32_t)]; ret = - GNUNET_CONTAINER_meta_data_serialize (bld->meta, - &sptr, - size - off - sizeof (uint32_t), - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); - GNUNET_assert (ret != -1); - big = htonl (ret); - GNUNET_memcpy (&data[off], - &big, - sizeof (uint32_t)); - off += sizeof (uint32_t) + ret; + GNUNET_CONTAINER_meta_data_serialize(bld->meta, + &sptr, + size - off - sizeof(uint32_t), + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); + GNUNET_assert(ret != -1); + big = htonl(ret); + GNUNET_memcpy(&data[off], + &big, + sizeof(uint32_t)); + off += sizeof(uint32_t) + ret; for (j = 0; j < bld->count; j++) - { - i = perm[j]; - psize = off; - off += sizes[i]; - off = do_align (psize, off); - GNUNET_memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]); - GNUNET_free (bes[i]); - } - GNUNET_free_non_null (sizes); - GNUNET_free_non_null (perm); - GNUNET_free_non_null (bes); - GNUNET_assert (off == size); - GNUNET_CONTAINER_meta_data_destroy (bld->meta); - GNUNET_free (bld); + { + i = perm[j]; + psize = off; + off += sizes[i]; + off = do_align(psize, off); + GNUNET_memcpy(&data[off - sizes[i]], &(bes[i])[1], sizes[i]); + GNUNET_free(bes[i]); + } + GNUNET_free_non_null(sizes); + GNUNET_free_non_null(perm); + GNUNET_free_non_null(bes); + GNUNET_assert(off == size); + GNUNET_CONTAINER_meta_data_destroy(bld->meta); + GNUNET_free(bld); return GNUNET_OK; } diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index dd207e2c9..9202de5ab 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_dirmetascan.c @@ -35,9 +35,7 @@ * An opaque structure a pointer to which is returned to the * caller to be used to control the scanner. */ -struct GNUNET_FS_DirScanner -{ - +struct GNUNET_FS_DirScanner { /** * Helper process. */ @@ -96,20 +94,20 @@ struct GNUNET_FS_DirScanner * @param ds directory scanner structure */ void -GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) +GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) { /* terminate helper */ if (NULL != ds->helper) - GNUNET_HELPER_stop (ds->helper, GNUNET_NO); + GNUNET_HELPER_stop(ds->helper, GNUNET_NO); /* free resources */ if (NULL != ds->toplevel) - GNUNET_FS_share_tree_free (ds->toplevel); + GNUNET_FS_share_tree_free(ds->toplevel); if (NULL != ds->stop_task) - GNUNET_SCHEDULER_cancel (ds->stop_task); - GNUNET_free_non_null (ds->ex_arg); - GNUNET_free (ds->filename_expanded); - GNUNET_free (ds); + GNUNET_SCHEDULER_cancel(ds->stop_task); + GNUNET_free_non_null(ds->ex_arg); + GNUNET_free(ds->filename_expanded); + GNUNET_free(ds); } @@ -122,16 +120,16 @@ GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) * @return the results of the scan (a directory tree) */ struct GNUNET_FS_ShareTreeItem * -GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) +GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) { struct GNUNET_FS_ShareTreeItem *result; /* check that we're actually done */ - GNUNET_assert (NULL == ds->helper); + GNUNET_assert(NULL == ds->helper); /* preserve result */ result = ds->toplevel; ds->toplevel = NULL; - GNUNET_FS_directory_scan_abort (ds); + GNUNET_FS_directory_scan_abort(ds); return result; } @@ -144,35 +142,35 @@ GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) * @return next file, NULL for none */ static struct GNUNET_FS_ShareTreeItem * -advance (struct GNUNET_FS_ShareTreeItem *pos) +advance(struct GNUNET_FS_ShareTreeItem *pos) { int moved; - GNUNET_assert (NULL != pos); + GNUNET_assert(NULL != pos); moved = 0; /* must not terminate, even on file, otherwise "normal" */ while ((pos->is_directory == GNUNET_YES) || (0 == moved)) - { - if ((moved != -1) && (NULL != pos->children_head)) - { - pos = pos->children_head; - moved = 1; /* can terminate if file */ - continue; - } - if (NULL != pos->next) - { - pos = pos->next; - moved = 1; /* can terminate if file */ - continue; - } - if (NULL != pos->parent) { - pos = pos->parent; - moved = -1; /* force move to 'next' or 'parent' */ - continue; + if ((moved != -1) && (NULL != pos->children_head)) + { + pos = pos->children_head; + moved = 1; /* can terminate if file */ + continue; + } + if (NULL != pos->next) + { + pos = pos->next; + moved = 1; /* can terminate if file */ + continue; + } + if (NULL != pos->parent) + { + pos = pos->parent; + moved = -1; /* force move to 'next' or 'parent' */ + continue; + } + /* no more options, end of traversal */ + return NULL; } - /* no more options, end of traversal */ - return NULL; - } return pos; } @@ -186,30 +184,30 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) * @return new entry that was just created */ static struct GNUNET_FS_ShareTreeItem * -expand_tree (struct GNUNET_FS_ShareTreeItem *parent, - const char *filename, - int is_directory) +expand_tree(struct GNUNET_FS_ShareTreeItem *parent, + const char *filename, + int is_directory) { struct GNUNET_FS_ShareTreeItem *chld; size_t slen; - chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); + chld = GNUNET_new(struct GNUNET_FS_ShareTreeItem); chld->parent = parent; - chld->filename = GNUNET_strdup (filename); - GNUNET_asprintf (&chld->short_filename, - "%s%s", - GNUNET_STRINGS_get_short_name (filename), - is_directory == GNUNET_YES ? "/" : ""); + chld->filename = GNUNET_strdup(filename); + GNUNET_asprintf(&chld->short_filename, + "%s%s", + GNUNET_STRINGS_get_short_name(filename), + is_directory == GNUNET_YES ? "/" : ""); /* make sure we do not end with '//' */ - slen = strlen (chld->short_filename); + slen = strlen(chld->short_filename); if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && (chld->short_filename[slen - 2] == '/')) chld->short_filename[slen - 1] = '\0'; chld->is_directory = is_directory; if (NULL != parent) - GNUNET_CONTAINER_DLL_insert (parent->children_head, - parent->children_tail, - chld); + GNUNET_CONTAINER_DLL_insert(parent->children_head, + parent->children_tail, + chld); return chld; } @@ -220,20 +218,20 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, * @param cls the 'struct GNUNET_FS_DirScanner' */ static void -finish_scan (void *cls) +finish_scan(void *cls) { struct GNUNET_FS_DirScanner *ds = cls; ds->stop_task = NULL; if (NULL != ds->helper) - { - GNUNET_HELPER_stop (ds->helper, GNUNET_NO); - ds->helper = NULL; - } - ds->progress_callback (ds->progress_callback_cls, - NULL, - GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_FINISHED); + { + GNUNET_HELPER_stop(ds->helper, GNUNET_NO); + ds->helper = NULL; + } + ds->progress_callback(ds->progress_callback_cls, + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_FINISHED); } @@ -248,168 +246,175 @@ finish_scan (void *cls) * #GNUNET_SYSERR to stop further processing with error */ static int -process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) +process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_DirScanner *ds = cls; const char *filename; size_t left; #if 0 - fprintf (stderr, - "DMS parses %u-byte message of type %u\n", - (unsigned int) ntohs (msg->size), - (unsigned int) ntohs (msg->type)); + fprintf(stderr, + "DMS parses %u-byte message of type %u\n", + (unsigned int)ntohs(msg->size), + (unsigned int)ntohs(msg->type)); #endif - left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); - filename = (const char *) &msg[1]; - switch (ntohs (msg->type)) - { - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: - if (filename[left - 1] != '\0') - { - GNUNET_break (0); - break; - } - ds->progress_callback (ds->progress_callback_cls, - filename, - GNUNET_NO, - GNUNET_FS_DIRSCANNER_FILE_START); - if (NULL == ds->toplevel) - { - ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); - } - else + left = ntohs(msg->size) - sizeof(struct GNUNET_MessageHeader); + filename = (const char *)&msg[1]; + switch (ntohs(msg->type)) { - GNUNET_assert (NULL != ds->pos); - (void) expand_tree (ds->pos, filename, GNUNET_NO); - } - return GNUNET_OK; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: - if (filename[left - 1] != '\0') - { - GNUNET_break (0); + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: + if (filename[left - 1] != '\0') + { + GNUNET_break(0); + break; + } + ds->progress_callback(ds->progress_callback_cls, + filename, + GNUNET_NO, + GNUNET_FS_DIRSCANNER_FILE_START); + if (NULL == ds->toplevel) + { + ds->toplevel = expand_tree(ds->pos, filename, GNUNET_NO); + } + else + { + GNUNET_assert(NULL != ds->pos); + (void)expand_tree(ds->pos, filename, GNUNET_NO); + } + return GNUNET_OK; + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: + if (filename[left - 1] != '\0') + { + GNUNET_break(0); + break; + } + if (0 == strcmp("..", filename)) + { + if (NULL == ds->pos) + { + GNUNET_break(0); + break; + } + ds->pos = ds->pos->parent; + return GNUNET_OK; + } + ds->progress_callback(ds->progress_callback_cls, + filename, + GNUNET_YES, + GNUNET_FS_DIRSCANNER_FILE_START); + ds->pos = expand_tree(ds->pos, filename, GNUNET_YES); + if (NULL == ds->toplevel) + ds->toplevel = ds->pos; + return GNUNET_OK; + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: break; - } - if (0 == strcmp ("..", filename)) - { - if (NULL == ds->pos) - { - GNUNET_break (0); + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: + if ('\0' != filename[left - 1]) break; - } - ds->pos = ds->pos->parent; + ds->progress_callback(ds->progress_callback_cls, + filename, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_FILE_IGNORED); return GNUNET_OK; - } - ds->progress_callback (ds->progress_callback_cls, - filename, - GNUNET_YES, - GNUNET_FS_DIRSCANNER_FILE_START); - ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); - if (NULL == ds->toplevel) - ds->toplevel = ds->pos; - return GNUNET_OK; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: - break; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: - if ('\0' != filename[left - 1]) - break; - ds->progress_callback (ds->progress_callback_cls, - filename, - GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_FILE_IGNORED); - return GNUNET_OK; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: - if (0 != left) - { - GNUNET_break (0); - break; - } - if (NULL == ds->toplevel) - break; - ds->progress_callback (ds->progress_callback_cls, - NULL, - GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_ALL_COUNTED); - ds->pos = ds->toplevel; - if (GNUNET_YES == ds->pos->is_directory) - ds->pos = advance (ds->pos); - return GNUNET_OK; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { - size_t nlen; - const char *end; - - if (NULL == ds->pos) - { - GNUNET_break (0); - break; - } - end = memchr (filename, 0, left); - if (NULL == end) - { - GNUNET_break (0); - break; - } - end++; - nlen = end - filename; - left -= nlen; - if (0 != strcmp (filename, ds->pos->filename)) - { - GNUNET_break (0); - break; - } - ds->progress_callback (ds->progress_callback_cls, - filename, - GNUNET_YES, - GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); - if (0 < left) - { - ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); - if (NULL == ds->pos->meta) - { - GNUNET_break (0); + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: + if (0 != left) + { + GNUNET_break(0); + break; + } + if (NULL == ds->toplevel) break; - } - /* having full filenames is too dangerous; always make sure we clean them up */ - GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, - EXTRACTOR_METATYPE_FILENAME, - NULL, - 0); - /* instead, put in our 'safer' original filename */ - GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, - "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - ds->pos->short_filename, - strlen (ds->pos->short_filename) + 1); - } - ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); - ds->pos = advance (ds->pos); - return GNUNET_OK; - } - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: - if (NULL != ds->pos) - { - GNUNET_break (0); - break; + ds->progress_callback(ds->progress_callback_cls, + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_ALL_COUNTED); + ds->pos = ds->toplevel; + if (GNUNET_YES == ds->pos->is_directory) + ds->pos = advance(ds->pos); + return GNUNET_OK; + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { + size_t nlen; + const char *end; + + if (NULL == ds->pos) + { + GNUNET_break(0); + break; + } + end = memchr(filename, 0, left); + if (NULL == end) + { + GNUNET_break(0); + break; + } + end++; + nlen = end - filename; + left -= nlen; + if (0 != strcmp(filename, ds->pos->filename)) + { + GNUNET_break(0); + break; + } + ds->progress_callback(ds->progress_callback_cls, + filename, + GNUNET_YES, + GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); + if (0 < left) + { + ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize(end, left); + if (NULL == ds->pos->meta) + { + GNUNET_break(0); + break; + } + /* having full filenames is too dangerous; always make sure we clean them up */ + GNUNET_CONTAINER_meta_data_delete(ds->pos->meta, + EXTRACTOR_METATYPE_FILENAME, + NULL, + 0); + /* instead, put in our 'safer' original filename */ + GNUNET_CONTAINER_meta_data_insert(ds->pos->meta, + "", + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + ds->pos->short_filename, + strlen(ds->pos->short_filename) + 1); + } + ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data(ds->pos->meta); + ds->pos = advance(ds->pos); + return GNUNET_OK; } - if (0 != left) - { - GNUNET_break (0); + + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: + if (NULL != ds->pos) + { + GNUNET_break(0); + break; + } + if (0 != left) + { + GNUNET_break(0); + break; + } + if (NULL == ds->toplevel) + break; + ds->stop_task = GNUNET_SCHEDULER_add_now(&finish_scan, ds); + return GNUNET_OK; + + default: + GNUNET_break(0); break; } - if (NULL == ds->toplevel) - break; - ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); - return GNUNET_OK; - default: - GNUNET_break (0); - break; - } - ds->progress_callback (ds->progress_callback_cls, - NULL, - GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); + ds->progress_callback(ds->progress_callback_cls, + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); return GNUNET_OK; } @@ -420,17 +425,17 @@ process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) * @param cls the 'struct GNUNET_FS_DirScanner' callback. */ static void -helper_died_cb (void *cls) +helper_died_cb(void *cls) { struct GNUNET_FS_DirScanner *ds = cls; ds->helper = NULL; if (NULL != ds->stop_task) return; /* normal death, was finished */ - ds->progress_callback (ds->progress_callback_cls, - NULL, - GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); + ds->progress_callback(ds->progress_callback_cls, + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); } @@ -446,48 +451,48 @@ helper_died_cb (void *cls) * @return directory scanner object to be used for controlling the scanner */ struct GNUNET_FS_DirScanner * -GNUNET_FS_directory_scan_start (const char *filename, - int disable_extractor, - const char *ex, - GNUNET_FS_DirScannerProgressCallback cb, - void *cb_cls) +GNUNET_FS_directory_scan_start(const char *filename, + int disable_extractor, + const char *ex, + GNUNET_FS_DirScannerProgressCallback cb, + void *cb_cls) { struct stat sbuf; char *filename_expanded; struct GNUNET_FS_DirScanner *ds; - if (0 != stat (filename, &sbuf)) + if (0 != stat(filename, &sbuf)) return NULL; - filename_expanded = GNUNET_STRINGS_filename_expand (filename); + filename_expanded = GNUNET_STRINGS_filename_expand(filename); if (NULL == filename_expanded) return NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting to scan directory `%s'\n", - filename_expanded); - ds = GNUNET_new (struct GNUNET_FS_DirScanner); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting to scan directory `%s'\n", + filename_expanded); + ds = GNUNET_new(struct GNUNET_FS_DirScanner); ds->progress_callback = cb; ds->progress_callback_cls = cb_cls; ds->filename_expanded = filename_expanded; if (disable_extractor) - ds->ex_arg = GNUNET_strdup ("-"); + ds->ex_arg = GNUNET_strdup("-"); else - ds->ex_arg = (NULL != ex) ? GNUNET_strdup (ex) : NULL; + ds->ex_arg = (NULL != ex) ? GNUNET_strdup(ex) : NULL; ds->args[0] = "gnunet-helper-fs-publish"; ds->args[1] = ds->filename_expanded; ds->args[2] = ds->ex_arg; ds->args[3] = NULL; - ds->helper = GNUNET_HELPER_start (GNUNET_NO, - "gnunet-helper-fs-publish", - ds->args, - &process_helper_msgs, - &helper_died_cb, - ds); + ds->helper = GNUNET_HELPER_start(GNUNET_NO, + "gnunet-helper-fs-publish", + ds->args, + &process_helper_msgs, + &helper_died_cb, + ds); if (NULL == ds->helper) - { - GNUNET_free (filename_expanded); - GNUNET_free (ds); - return NULL; - } + { + GNUNET_free(filename_expanded); + GNUNET_free(ds); + return NULL; + } return ds; } diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 59821f8a5..de70c53a8 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_download.c * @brief download methods @@ -34,16 +34,16 @@ * use to try to do a recursive download. */ static int -is_recursive_download (struct GNUNET_FS_DownloadContext *dc) +is_recursive_download(struct GNUNET_FS_DownloadContext *dc) { return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && - ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || + ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(dc->meta)) || ((NULL == dc->meta) && ((NULL == dc->filename) || - ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != strstr (dc->filename + strlen (dc->filename) - - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT)))))); + ((strlen(dc->filename) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && + (NULL != strstr(dc->filename + strlen(dc->filename) - + strlen(GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT)))))); } @@ -64,7 +64,7 @@ is_recursive_download (struct GNUNET_FS_DownloadContext *dc) * with the range for any other block */ static uint64_t -compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) +compute_disk_offset(uint64_t fsize, uint64_t off, unsigned int depth) { unsigned int i; uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ @@ -77,18 +77,18 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) * to full DBLOCK_SIZE */ loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; lsize = - ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); - GNUNET_assert (0 == (off % DBLOCK_SIZE)); + ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof(struct ContentHashKey); + GNUNET_assert(0 == (off % DBLOCK_SIZE)); ioff = (off / DBLOCK_SIZE); for (i = 1; i < depth; i++) - { - loff += lsize; - lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE; - GNUNET_assert (lsize > 0); - GNUNET_assert (0 == (ioff % CHK_PER_INODE)); - ioff /= CHK_PER_INODE; - } - return loff + ioff * sizeof (struct ContentHashKey); + { + loff += lsize; + lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE; + GNUNET_assert(lsize > 0); + GNUNET_assert(0 == (ioff % CHK_PER_INODE)); + ioff /= CHK_PER_INODE; + } + return loff + ioff * sizeof(struct ContentHashKey); } @@ -100,8 +100,8 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) * @param dc overall download context */ void -GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_DownloadContext *dc) +GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_DownloadContext *dc) { pi->value.download.dc = dc; pi->value.download.cctx = dc->client_info; @@ -114,26 +114,24 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, pi->value.download.size = dc->length; /* FIXME: Fix duration calculation to account for pauses */ pi->value.download.duration = - GNUNET_TIME_absolute_get_duration (dc->start_time); + GNUNET_TIME_absolute_get_duration(dc->start_time); pi->value.download.completed = dc->completed; pi->value.download.anonymity = dc->anonymity; pi->value.download.eta = - GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); + GNUNET_TIME_calculate_eta(dc->start_time, dc->completed, dc->length); pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; pi->fsh = dc->h; if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) - dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi); + dc->client_info = dc->h->upcb(dc->h->upcb_cls, pi); else - dc->client_info = GNUNET_FS_search_probe_progress_ (NULL, pi); + dc->client_info = GNUNET_FS_search_probe_progress_(NULL, pi); } /** * Closure for iterator processing results. */ -struct ProcessResultClosure -{ - +struct ProcessResultClosure { /** * Hash of data. */ @@ -191,9 +189,9 @@ struct ProcessResultClosure * @return #GNUNET_YES (we should continue to iterate); unless serious error */ static int -process_result_with_request (void *cls, - const struct GNUNET_HashCode *key, - void *value); +process_result_with_request(void *cls, + const struct GNUNET_HashCode *key, + void *value); /** @@ -210,12 +208,12 @@ process_result_with_request (void *cls, * @return GNUNET_OK on success */ static int -encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, - const struct ContentHashKey *chk, - struct DownloadRequest *dr, - const char *block, - size_t len, - int do_store) +encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, + const struct ContentHashKey *chk, + struct DownloadRequest *dr, + const char *block, + size_t len, + int do_store) { struct ProcessResultClosure prc; char enc[len]; @@ -223,34 +221,34 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, struct GNUNET_CRYPTO_SymmetricInitializationVector iv; struct GNUNET_HashCode query; - GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv); - if (-1 == GNUNET_CRYPTO_symmetric_encrypt (block, len, &sk, &iv, enc)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_CRYPTO_hash (enc, len, &query); - if (0 != memcmp (&query, &chk->query, sizeof (struct GNUNET_HashCode))) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - GNUNET_log ( + GNUNET_CRYPTO_hash_to_aes_key(&chk->key, &sk, &iv); + if (-1 == GNUNET_CRYPTO_symmetric_encrypt(block, len, &sk, &iv, enc)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_CRYPTO_hash(enc, len, &query); + if (0 != memcmp(&query, &chk->query, sizeof(struct GNUNET_HashCode))) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", - (unsigned int) len, + (unsigned int)len, dc->filename, - (unsigned long long) dr->offset); + (unsigned long long)dr->offset); /* already got it! */ prc.dc = dc; prc.data = enc; prc.size = len; prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK - : GNUNET_BLOCK_TYPE_FS_IBLOCK; + : GNUNET_BLOCK_TYPE_FS_IBLOCK; prc.query = chk->query; prc.do_store = do_store; prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; - process_result_with_request (&prc, &chk->key, dr); + process_result_with_request(&prc, &chk->key, dr); return GNUNET_OK; } @@ -263,7 +261,7 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, * @param dc download context that is having trouble */ static void -try_reconnect (struct GNUNET_FS_DownloadContext *dc); +try_reconnect(struct GNUNET_FS_DownloadContext *dc); /** @@ -278,12 +276,12 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc); * @param data contents of the file (or NULL if they were not inlined) */ static void -trigger_recursive_download (void *cls, - const char *filename, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - size_t length, - const void *data); +trigger_recursive_download(void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + size_t length, + const void *data); /** @@ -293,7 +291,7 @@ trigger_recursive_download (void *cls, * @param dc context of download that just completed */ static void -full_recursive_download (struct GNUNET_FS_DownloadContext *dc) +full_recursive_download(struct GNUNET_FS_DownloadContext *dc) { size_t size; uint64_t size64; @@ -301,64 +299,64 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) struct GNUNET_DISK_FileHandle *h; struct GNUNET_DISK_MapHandle *m; - size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri); - size = (size_t) size64; - if (size64 != (uint64_t) size) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_ERROR, - _ ( - "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); - return; - } + size64 = GNUNET_FS_uri_chk_get_file_size(dc->uri); + size = (size_t)size64; + if (size64 != (uint64_t)size) + { + GNUNET_log( + GNUNET_ERROR_TYPE_ERROR, + _( + "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); + return; + } if (NULL != dc->filename) - { - h = GNUNET_DISK_file_open (dc->filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - } + { + h = GNUNET_DISK_file_open(dc->filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); + } else - { - GNUNET_assert (NULL != dc->temp_filename); - h = GNUNET_DISK_file_open (dc->temp_filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - } + { + GNUNET_assert(NULL != dc->temp_filename); + h = GNUNET_DISK_file_open(dc->temp_filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); + } if (NULL == h) return; /* oops */ - data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); + data = GNUNET_DISK_file_map(h, &m, GNUNET_DISK_MAP_TYPE_READ, size); if (NULL == data) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Directory too large for system address space\n")); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Directory too large for system address space\n")); + } else - { - if (GNUNET_OK != - GNUNET_FS_directory_list_contents (size, - data, - 0, - &trigger_recursive_download, - dc)) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_WARNING, - _ ( - "Failed to access full directroy contents of `%s' for recursive download\n"), - dc->filename); - } - GNUNET_DISK_file_unmap (m); - } - GNUNET_DISK_file_close (h); + { + if (GNUNET_OK != + GNUNET_FS_directory_list_contents(size, + data, + 0, + &trigger_recursive_download, + dc)) + { + GNUNET_log( + GNUNET_ERROR_TYPE_WARNING, + _( + "Failed to access full directroy contents of `%s' for recursive download\n"), + dc->filename); + } + GNUNET_DISK_file_unmap(m); + } + GNUNET_DISK_file_close(h); if (NULL == dc->filename) - { - if (0 != unlink (dc->temp_filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - dc->temp_filename); - GNUNET_free (dc->temp_filename); - dc->temp_filename = NULL; - } + { + if (0 != unlink(dc->temp_filename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "unlink", + dc->temp_filename); + GNUNET_free(dc->temp_filename); + dc->temp_filename = NULL; + } } @@ -373,48 +371,48 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) * @param dc download to check for completion of children */ static void -check_completed (struct GNUNET_FS_DownloadContext *dc) +check_completed(struct GNUNET_FS_DownloadContext *dc) { struct GNUNET_FS_ProgressInfo pi; struct GNUNET_FS_DownloadContext *pos; /* first, check if we need to download children */ - if (is_recursive_download (dc)) - full_recursive_download (dc); + if (is_recursive_download(dc)) + full_recursive_download(dc); /* then, check if children are done already */ for (pos = dc->child_head; NULL != pos; pos = pos->next) - { - if ((NULL == pos->emsg) && (pos->completed < pos->length)) - return; /* not done yet */ - if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) - return; /* not transitively done yet */ - } + { + if ((NULL == pos->emsg) && (pos->completed < pos->length)) + return; /* not done yet */ + if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) + return; /* not transitively done yet */ + } /* All of our children are done, so mark this download done */ dc->has_finished = GNUNET_YES; if (NULL != dc->job_queue) - { - GNUNET_FS_dequeue_ (dc->job_queue); - dc->job_queue = NULL; - } + { + GNUNET_FS_dequeue_(dc->job_queue); + dc->job_queue = NULL; + } if (NULL != dc->task) - { - GNUNET_SCHEDULER_cancel (dc->task); - dc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(dc->task); + dc->task = NULL; + } if (NULL != dc->rfh) - { - GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); - dc->rfh = NULL; - } - GNUNET_FS_download_sync_ (dc); + { + GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); + dc->rfh = NULL; + } + GNUNET_FS_download_sync_(dc); /* signal completion */ pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); /* let parent know */ if (NULL != dc->parent) - check_completed (dc->parent); + check_completed(dc->parent); } @@ -429,10 +427,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) * @param data_len number of bytes in data */ static void -try_match_block (struct GNUNET_FS_DownloadContext *dc, - struct DownloadRequest *dr, - const char *data, - size_t data_len) +try_match_block(struct GNUNET_FS_DownloadContext *dc, + struct DownloadRequest *dr, + const char *data, + size_t data_len) { struct GNUNET_FS_ProgressInfo pi; unsigned int i; @@ -454,128 +452,130 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, if (BRS_DOWNLOAD_UP == dr->state) return; if (dr->depth > 0) - { - if ((dc->offset > 0) || - (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length))) - { - /* NOTE: this test is not tight, but should suffice; the issue - here is that 'dr->num_children' may inherently only specify a - smaller range than what is in the original file; - thus, reconstruction of (some) inner blocks will fail. - FIXME: we might eventually want to write a tighter test to - maximize the circumstances under which we do succeed with - IBlock reconstruction. (need good tests though). */ - return; - } - complete = GNUNET_YES; - for (i = 0; i < dr->num_children; i++) { - drc = dr->children[i]; - try_match_block (dc, drc, data, data_len); - if (drc->state != BRS_RECONSTRUCT_META_UP) - complete = GNUNET_NO; - else - chks[i] = drc->chk; + if ((dc->offset > 0) || + (dc->length < GNUNET_ntohll(dc->uri->data.chk.file_length))) + { + /* NOTE: this test is not tight, but should suffice; the issue + here is that 'dr->num_children' may inherently only specify a + smaller range than what is in the original file; + thus, reconstruction of (some) inner blocks will fail. + FIXME: we might eventually want to write a tighter test to + maximize the circumstances under which we do succeed with + IBlock reconstruction. (need good tests though). */ + return; + } + complete = GNUNET_YES; + for (i = 0; i < dr->num_children; i++) + { + drc = dr->children[i]; + try_match_block(dc, drc, data, data_len); + if (drc->state != BRS_RECONSTRUCT_META_UP) + complete = GNUNET_NO; + else + chks[i] = drc->chk; + } + if (GNUNET_YES != complete) + return; + data = (const char *)chks; + dlen = dr->num_children * sizeof(struct ContentHashKey); } - if (GNUNET_YES != complete) - return; - data = (const char *) chks; - dlen = dr->num_children * sizeof (struct ContentHashKey); - } else - { - if (dr->offset > data_len) - return; /* oops */ - dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); - } - GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); - GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); + { + if (dr->offset > data_len) + return; /* oops */ + dlen = GNUNET_MIN(data_len - dr->offset, DBLOCK_SIZE); + } + GNUNET_CRYPTO_hash(&data[dr->offset], dlen, &in_chk.key); + GNUNET_CRYPTO_hash_to_aes_key(&in_chk.key, &sk, &iv); if (-1 == - GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) - { - GNUNET_break (0); - return; - } - GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query); + GNUNET_CRYPTO_symmetric_encrypt(&data[dr->offset], dlen, &sk, &iv, enc)) + { + GNUNET_break(0); + return; + } + GNUNET_CRYPTO_hash(enc, dlen, &in_chk.query); switch (dr->state) - { - case BRS_INIT: - dr->chk = in_chk; - dr->state = BRS_RECONSTRUCT_META_UP; - break; - case BRS_CHK_SET: - if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey))) - { - /* other peer provided bogus meta data */ - GNUNET_break_op (0); + { + case BRS_INIT: + dr->chk = in_chk; + dr->state = BRS_RECONSTRUCT_META_UP; + break; + + case BRS_CHK_SET: + if (0 != memcmp(&in_chk, &dr->chk, sizeof(struct ContentHashKey))) + { + /* other peer provided bogus meta data */ + GNUNET_break_op(0); + break; + } + /* write block to disk */ + fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename; + if (NULL != fn) + { + fh = GNUNET_DISK_file_open(fn, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_TRUNCATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); + if (NULL == fh) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); + GNUNET_asprintf(&dc->emsg, + _("Failed to open file `%s' for writing"), + fn); + GNUNET_DISK_file_close(fh); + dr->state = BRS_ERROR; + pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; + pi.value.download.specifics.error.message = dc->emsg; + GNUNET_FS_download_make_status_(&pi, dc); + return; + } + if (data_len != GNUNET_DISK_file_write(fh, odata, odata_len)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", fn); + GNUNET_asprintf(&dc->emsg, + _("Failed to open file `%s' for writing"), + fn); + GNUNET_DISK_file_close(fh); + dr->state = BRS_ERROR; + pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; + pi.value.download.specifics.error.message = dc->emsg; + GNUNET_FS_download_make_status_(&pi, dc); + return; + } + GNUNET_DISK_file_close(fh); + } + /* signal success */ + dr->state = BRS_DOWNLOAD_UP; + dc->completed = dc->length; + GNUNET_FS_download_sync_(dc); + pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; + pi.value.download.specifics.progress.data = data; + pi.value.download.specifics.progress.offset = 0; + pi.value.download.specifics.progress.data_len = dlen; + pi.value.download.specifics.progress.depth = 0; + pi.value.download.specifics.progress.respect_offered = 0; + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_UNIT_ZERO; + GNUNET_FS_download_make_status_(&pi, dc); + if ((NULL != dc->filename) && + (0 != truncate(dc->filename, + GNUNET_ntohll(dc->uri->data.chk.file_length)))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "truncate", + dc->filename); + check_completed(dc); + break; + + default: + /* how did we get here? */ + GNUNET_break(0); break; } - /* write block to disk */ - fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename; - if (NULL != fn) - { - fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_TRUNCATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); - if (NULL == fh) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); - GNUNET_asprintf (&dc->emsg, - _ ("Failed to open file `%s' for writing"), - fn); - GNUNET_DISK_file_close (fh); - dr->state = BRS_ERROR; - pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; - pi.value.download.specifics.error.message = dc->emsg; - GNUNET_FS_download_make_status_ (&pi, dc); - return; - } - if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); - GNUNET_asprintf (&dc->emsg, - _ ("Failed to open file `%s' for writing"), - fn); - GNUNET_DISK_file_close (fh); - dr->state = BRS_ERROR; - pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; - pi.value.download.specifics.error.message = dc->emsg; - GNUNET_FS_download_make_status_ (&pi, dc); - return; - } - GNUNET_DISK_file_close (fh); - } - /* signal success */ - dr->state = BRS_DOWNLOAD_UP; - dc->completed = dc->length; - GNUNET_FS_download_sync_ (dc); - pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; - pi.value.download.specifics.progress.data = data; - pi.value.download.specifics.progress.offset = 0; - pi.value.download.specifics.progress.data_len = dlen; - pi.value.download.specifics.progress.depth = 0; - pi.value.download.specifics.progress.respect_offered = 0; - pi.value.download.specifics.progress.block_download_duration = - GNUNET_TIME_UNIT_ZERO; - GNUNET_FS_download_make_status_ (&pi, dc); - if ((NULL != dc->filename) && - (0 != truncate (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length)))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "truncate", - dc->filename); - check_completed (dc); - break; - default: - /* how did we get here? */ - GNUNET_break (0); - break; - } } @@ -598,27 +598,27 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, * @return 0 to continue extracting, 1 to abort */ static int -match_full_data (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_len) +match_full_data(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) { struct GNUNET_FS_DownloadContext *dc = cls; if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) return 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found %u bytes of FD!\n", - (unsigned int) data_len); - if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) - { - GNUNET_break_op (0); - return 1; /* bogus meta data */ - } - try_match_block (dc, dc->top_request, data, data_len); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Found %u bytes of FD!\n", + (unsigned int)data_len); + if (GNUNET_FS_uri_chk_get_file_size(dc->uri) != data_len) + { + GNUNET_break_op(0); + return 1; /* bogus meta data */ + } + try_match_block(dc, dc->top_request, data, data_len); return 1; } @@ -630,20 +630,21 @@ match_full_data (void *cls, * @param dr download request that is done */ static void -propagate_up (struct DownloadRequest *dr) +propagate_up(struct DownloadRequest *dr) { unsigned int i; do - { - dr->state = BRS_DOWNLOAD_UP; - dr = dr->parent; - if (NULL == dr) - break; - for (i = 0; i < dr->num_children; i++) - if (dr->children[i]->state != BRS_DOWNLOAD_UP) + { + dr->state = BRS_DOWNLOAD_UP; + dr = dr->parent; + if (NULL == dr) break; - } while (i == dr->num_children); + for (i = 0; i < dr->num_children; i++) + if (dr->children[i]->state != BRS_DOWNLOAD_UP) + break; + } + while (i == dr->num_children); } @@ -658,8 +659,8 @@ propagate_up (struct DownloadRequest *dr) * @param dr block to reconstruct */ static void -try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, - struct DownloadRequest *dr) +try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, + struct DownloadRequest *dr) { uint64_t off; char block[DBLOCK_SIZE]; @@ -672,64 +673,64 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, const struct ContentHashKey *chks; int up_done; - GNUNET_assert (NULL != dc->rfh); - GNUNET_assert (BRS_CHK_SET == dr->state); - total = GNUNET_FS_uri_chk_get_file_size (dc->uri); - GNUNET_assert (dr->depth < dc->treedepth); - len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth); - GNUNET_assert (len <= DBLOCK_SIZE); - off = compute_disk_offset (total, dr->offset, dr->depth); + GNUNET_assert(NULL != dc->rfh); + GNUNET_assert(BRS_CHK_SET == dr->state); + total = GNUNET_FS_uri_chk_get_file_size(dc->uri); + GNUNET_assert(dr->depth < dc->treedepth); + len = GNUNET_FS_tree_calculate_block_size(total, dr->offset, dr->depth); + GNUNET_assert(len <= DBLOCK_SIZE); + off = compute_disk_offset(total, dr->offset, dr->depth); if (dc->old_file_size < off + len) return; /* failure */ - if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); - return; /* failure */ - } - if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); - return; /* failure */ - } - GNUNET_CRYPTO_hash (block, len, &key); - if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) + if (off != GNUNET_DISK_file_seek(dc->rfh, off, GNUNET_DISK_SEEK_SET)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); + return; /* failure */ + } + if (len != GNUNET_DISK_file_read(dc->rfh, block, len)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); + return; /* failure */ + } + GNUNET_CRYPTO_hash(block, len, &key); + if (0 != memcmp(&key, &dr->chk.key, sizeof(struct GNUNET_HashCode))) return; /* mismatch */ if (GNUNET_OK != - encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) - { - /* hash matches but encrypted block does not, really bad */ - dr->state = BRS_ERROR; - /* propagate up */ - while (NULL != dr->parent) + encrypt_existing_match(dc, &dr->chk, dr, block, len, GNUNET_NO)) { - dr = dr->parent; + /* hash matches but encrypted block does not, really bad */ dr->state = BRS_ERROR; + /* propagate up */ + while (NULL != dr->parent) + { + dr = dr->parent; + dr->state = BRS_ERROR; + } + return; } - return; - } /* block matches */ dr->state = BRS_DOWNLOAD_DOWN; /* set CHKs for children */ up_done = GNUNET_YES; - chks = (const struct ContentHashKey *) block; + chks = (const struct ContentHashKey *)block; for (i = 0; i < dr->num_children; i++) - { - drc = dr->children[i]; - GNUNET_assert (drc->offset >= dr->offset); - child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); - GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); - if (BRS_INIT == drc->state) - { - drc->state = BRS_CHK_SET; - drc->chk = chks[drc->chk_idx]; - try_top_down_reconstruction (dc, drc); - } - if (BRS_DOWNLOAD_UP != drc->state) - up_done = GNUNET_NO; /* children not all done */ - } + { + drc = dr->children[i]; + GNUNET_assert(drc->offset >= dr->offset); + child_block_size = GNUNET_FS_tree_compute_tree_size(drc->depth); + GNUNET_assert(0 == (drc->offset - dr->offset) % child_block_size); + if (BRS_INIT == drc->state) + { + drc->state = BRS_CHK_SET; + drc->chk = chks[drc->chk_idx]; + try_top_down_reconstruction(dc, drc); + } + if (BRS_DOWNLOAD_UP != drc->state) + up_done = GNUNET_NO; /* children not all done */ + } if (GNUNET_YES == up_done) - propagate_up (dr); /* children all done (or no children...) */ + propagate_up(dr); /* children all done (or no children...) */ } @@ -742,26 +743,26 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, * @return #GNUNET_OK */ static int -retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) +retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry) { struct GNUNET_FS_DownloadContext *dc = cls; struct DownloadRequest *dr = entry; struct SearchMessage *sm; struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); + env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) - sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); + sm->options = htonl(GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); else - sm->options = htonl (GNUNET_FS_SEARCH_OPTION_NONE); + sm->options = htonl(GNUNET_FS_SEARCH_OPTION_NONE); if (0 == dr->depth) - sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); + sm->type = htonl(GNUNET_BLOCK_TYPE_FS_DBLOCK); else - sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); - sm->anonymity_level = htonl (dc->anonymity); + sm->type = htonl(GNUNET_BLOCK_TYPE_FS_IBLOCK); + sm->anonymity_level = htonl(dc->anonymity); sm->target = dc->target; sm->query = dr->chk.query; - GNUNET_MQ_send (dc->mq, env); + GNUNET_MQ_send(dc->mq, env); return GNUNET_OK; } @@ -773,55 +774,62 @@ retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) * @param dr request to schedule */ static void -schedule_block_download (struct GNUNET_FS_DownloadContext *dc, - struct DownloadRequest *dr) +schedule_block_download(struct GNUNET_FS_DownloadContext *dc, + struct DownloadRequest *dr) { unsigned int i; switch (dr->state) - { - case BRS_INIT: - GNUNET_assert (0); - break; - case BRS_RECONSTRUCT_DOWN: - GNUNET_assert (0); - break; - case BRS_RECONSTRUCT_META_UP: - GNUNET_assert (0); - break; - case BRS_RECONSTRUCT_UP: - GNUNET_assert (0); - break; - case BRS_CHK_SET: - /* normal case, start download */ - break; - case BRS_DOWNLOAD_DOWN: - for (i = 0; i < dr->num_children; i++) - schedule_block_download (dc, dr->children[i]); - return; - case BRS_DOWNLOAD_UP: - /* We're done! */ - return; - case BRS_ERROR: - GNUNET_break (0); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling download at offset %llu and depth %u for `%s'\n", - (unsigned long long) dr->offset, - dr->depth, - GNUNET_h2s (&dr->chk.query)); - if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active, - &dr->chk.query, - dr)) + { + case BRS_INIT: + GNUNET_assert(0); + break; + + case BRS_RECONSTRUCT_DOWN: + GNUNET_assert(0); + break; + + case BRS_RECONSTRUCT_META_UP: + GNUNET_assert(0); + break; + + case BRS_RECONSTRUCT_UP: + GNUNET_assert(0); + break; + + case BRS_CHK_SET: + /* normal case, start download */ + break; + + case BRS_DOWNLOAD_DOWN: + for (i = 0; i < dr->num_children; i++) + schedule_block_download(dc, dr->children[i]); + return; + + case BRS_DOWNLOAD_UP: + /* We're done! */ + return; + + case BRS_ERROR: + GNUNET_break(0); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Scheduling download at offset %llu and depth %u for `%s'\n", + (unsigned long long)dr->offset, + dr->depth, + GNUNET_h2s(&dr->chk.query)); + if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value(dc->active, + &dr->chk.query, + dr)) return; /* already active */ - GNUNET_CONTAINER_multihashmap_put (dc->active, - &dr->chk.query, - dr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multihashmap_put(dc->active, + &dr->chk.query, + dr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); if (NULL == dc->mq) return; /* download not active */ - retry_entry (dc, &dr->chk.query, dr); + retry_entry(dc, &dr->chk.query, dr); } @@ -839,12 +847,12 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, * @param data contents of the file (or NULL if they were not inlined) */ static void -trigger_recursive_download (void *cls, - const char *filename, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - size_t length, - const void *data) +trigger_recursive_download(void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + size_t length, + const void *data) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_DownloadContext *cpos; @@ -861,121 +869,121 @@ trigger_recursive_download (void *cls, return; /* entry for the directory itself */ cpos = dc->child_head; while (NULL != cpos) - { - if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) || - ((NULL != filename) && (0 == strcmp (cpos->filename, filename)))) - break; - cpos = cpos->next; - } + { + if ((GNUNET_FS_uri_test_equal(uri, cpos->uri)) || + ((NULL != filename) && (0 == strcmp(cpos->filename, filename)))) + break; + cpos = cpos->next; + } if (NULL != cpos) return; /* already exists */ fn = NULL; if (NULL == filename) - { - fn = GNUNET_FS_meta_data_suggest_filename (meta); - if (NULL == fn) - { - us = GNUNET_FS_uri_to_string (uri); - fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]); - GNUNET_free (us); - } - else if ('.' == fn[0]) - { - ext = fn; - us = GNUNET_FS_uri_to_string (uri); - GNUNET_asprintf (&fn, - "%s%s", - &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], - ext); - GNUNET_free (ext); - GNUNET_free (us); - } - /* change '\' to '/' (this should have happened - * during insertion, but malicious peers may - * not have done this) */ - while (NULL != (pos = strstr (fn, "\\"))) - *pos = '/'; - /* remove '../' everywhere (again, well-behaved - * peers don't do this, but don't trust that - * we did not get something nasty) */ - while (NULL != (pos = strstr (fn, "../"))) - { - pos[0] = '_'; - pos[1] = '_'; - pos[2] = '_'; - } - filename = fn; - } + { + fn = GNUNET_FS_meta_data_suggest_filename(meta); + if (NULL == fn) + { + us = GNUNET_FS_uri_to_string(uri); + fn = GNUNET_strdup(&us[strlen(GNUNET_FS_URI_CHK_PREFIX)]); + GNUNET_free(us); + } + else if ('.' == fn[0]) + { + ext = fn; + us = GNUNET_FS_uri_to_string(uri); + GNUNET_asprintf(&fn, + "%s%s", + &us[strlen(GNUNET_FS_URI_CHK_PREFIX)], + ext); + GNUNET_free(ext); + GNUNET_free(us); + } + /* change '\' to '/' (this should have happened + * during insertion, but malicious peers may + * not have done this) */ + while (NULL != (pos = strstr(fn, "\\"))) + *pos = '/'; + /* remove '../' everywhere (again, well-behaved + * peers don't do this, but don't trust that + * we did not get something nasty) */ + while (NULL != (pos = strstr(fn, "../"))) + { + pos[0] = '_'; + pos[1] = '_'; + pos[2] = '_'; + } + filename = fn; + } if (NULL == dc->filename) - { - full_name = NULL; - } + { + full_name = NULL; + } else - { - dn = GNUNET_strdup (dc->filename); - GNUNET_break ( - (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT))); - sfn = GNUNET_strdup (filename); - while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) - sfn[strlen (sfn) - 1] = '\0'; - if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT))) - dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; - if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && - ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || - (NULL == strstr (filename + strlen (filename) - - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT)))) - { - GNUNET_asprintf (&full_name, - "%s%s%s%s", - dn, - DIR_SEPARATOR_STR, - sfn, - GNUNET_FS_DIRECTORY_EXT); - } - else - { - GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); - } - GNUNET_free (sfn); - GNUNET_free (dn); - } + { + dn = GNUNET_strdup(dc->filename); + GNUNET_break( + (strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && + (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT))); + sfn = GNUNET_strdup(filename); + while ((strlen(sfn) > 0) && ('/' == filename[strlen(sfn) - 1])) + sfn[strlen(sfn) - 1] = '\0'; + if ((strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && + (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT))) + dn[strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT)] = '\0'; + if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) && + ((strlen(filename) < strlen(GNUNET_FS_DIRECTORY_EXT)) || + (NULL == strstr(filename + strlen(filename) - + strlen(GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT)))) + { + GNUNET_asprintf(&full_name, + "%s%s%s%s", + dn, + DIR_SEPARATOR_STR, + sfn, + GNUNET_FS_DIRECTORY_EXT); + } + else + { + GNUNET_asprintf(&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); + } + GNUNET_free(sfn); + GNUNET_free(dn); + } if ((NULL != full_name) && - (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ( - "Failed to create directory for recursive download of `%s'\n"), - full_name); - GNUNET_free (full_name); - GNUNET_free_non_null (fn); - return; - } + (GNUNET_OK != GNUNET_DISK_directory_create_for_file(full_name))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _( + "Failed to create directory for recursive download of `%s'\n"), + full_name); + GNUNET_free(full_name); + GNUNET_free_non_null(fn); + return; + } temp_name = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Triggering recursive download of size %llu with %u bytes MD\n", - (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), - (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size ( - meta)); - GNUNET_FS_download_start (dc->h, - uri, - meta, - full_name, - temp_name, - 0, - GNUNET_FS_uri_chk_get_file_size (uri), - dc->anonymity, - dc->options, - NULL, - dc); - GNUNET_free_non_null (full_name); - GNUNET_free_non_null (temp_name); - GNUNET_free_non_null (fn); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Triggering recursive download of size %llu with %u bytes MD\n", + (unsigned long long)GNUNET_FS_uri_chk_get_file_size(uri), + (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size( + meta)); + GNUNET_FS_download_start(dc->h, + uri, + meta, + full_name, + temp_name, + 0, + GNUNET_FS_uri_chk_get_file_size(uri), + dc->anonymity, + dc->options, + NULL, + dc); + GNUNET_free_non_null(full_name); + GNUNET_free_non_null(temp_name); + GNUNET_free_non_null(fn); } @@ -985,14 +993,14 @@ trigger_recursive_download (void *cls, * @param dr request to free */ void -GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) +GNUNET_FS_free_download_request_(struct DownloadRequest *dr) { if (NULL == dr) return; for (unsigned int i = 0; i < dr->num_children; i++) - GNUNET_FS_free_download_request_ (dr->children[i]); - GNUNET_free_non_null (dr->children); - GNUNET_free (dr); + GNUNET_FS_free_download_request_(dr->children[i]); + GNUNET_free_non_null(dr->children); + GNUNET_free(dr); } @@ -1006,9 +1014,9 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) * @return #GNUNET_YES (we should continue to iterate); unless serious error */ static int -process_result_with_request (void *cls, - const struct GNUNET_HashCode *key, - void *value) +process_result_with_request(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct ProcessResultClosure *prc = cls; struct DownloadRequest *dr = value; @@ -1025,132 +1033,132 @@ process_result_with_request (void *cls, int i; struct ContentHashKey *chkarr; - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", - (unsigned int) prc->size, - GNUNET_h2s (key), + (unsigned int)prc->size, + GNUNET_h2s(key), dr->depth, - (unsigned long long) dr->offset, - (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); - bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll ( - dc->uri->data.chk.file_length), - dr->offset, - dr->depth); + (unsigned long long)dr->offset, + (unsigned long long)GNUNET_ntohll(dc->uri->data.chk.file_length)); + bs = GNUNET_FS_tree_calculate_block_size(GNUNET_ntohll( + dc->uri->data.chk.file_length), + dr->offset, + dr->depth); if (prc->size != bs) - { - GNUNET_asprintf ( - &dc->emsg, - _ ( - "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), - bs, - dr->depth, - (unsigned long long) dr->offset, - (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length), - prc->size); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); - while (NULL != dr->parent) { + GNUNET_asprintf( + &dc->emsg, + _( + "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), + bs, + dr->depth, + (unsigned long long)dr->offset, + (unsigned long long)GNUNET_ntohll(dc->uri->data.chk.file_length), + prc->size); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); + while (NULL != dr->parent) + { + dr->state = BRS_ERROR; + dr = dr->parent; + } dr->state = BRS_ERROR; - dr = dr->parent; + goto signal_error; } - dr->state = BRS_ERROR; - goto signal_error; - } - (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr); - GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); + (void)GNUNET_CONTAINER_multihashmap_remove(dc->active, &prc->query, dr); + GNUNET_CRYPTO_hash_to_aes_key(&dr->chk.key, &skey, &iv); if (-1 == - GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt)) - { - GNUNET_break (0); - dc->emsg = GNUNET_strdup (_ ("internal error decrypting content")); - goto signal_error; - } - off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), - dr->offset, - dr->depth); + GNUNET_CRYPTO_symmetric_decrypt(prc->data, prc->size, &skey, &iv, pt)) + { + GNUNET_break(0); + dc->emsg = GNUNET_strdup(_("internal error decrypting content")); + goto signal_error; + } + off = compute_disk_offset(GNUNET_ntohll(dc->uri->data.chk.file_length), + dr->offset, + dr->depth); /* save to disk */ if ((GNUNET_YES == prc->do_store) && - ((NULL != dc->filename) || (is_recursive_download (dc))) && + ((NULL != dc->filename) || (is_recursive_download(dc))) && ((dr->depth == dc->treedepth) || (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) - { - fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename - : dc->temp_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); - if (NULL == fh) - { - GNUNET_asprintf (&dc->emsg, - _ ("Download failed: could not open file `%s': %s"), - dc->filename, - strerror (errno)); - goto signal_error; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Saving decrypted block to disk at offset %llu\n", - (unsigned long long) off); - if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) - { - GNUNET_asprintf (&dc->emsg, - _ ("Failed to seek to offset %llu in file `%s': %s"), - (unsigned long long) off, - dc->filename, - strerror (errno)); - goto signal_error; - } - if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) { - GNUNET_asprintf ( - &dc->emsg, - _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), - (unsigned int) prc->size, - (unsigned long long) off, - dc->filename, - strerror (errno)); - goto signal_error; + fh = GNUNET_DISK_file_open(NULL != dc->filename ? dc->filename + : dc->temp_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); + if (NULL == fh) + { + GNUNET_asprintf(&dc->emsg, + _("Download failed: could not open file `%s': %s"), + dc->filename, + strerror(errno)); + goto signal_error; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Saving decrypted block to disk at offset %llu\n", + (unsigned long long)off); + if ((off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET))) + { + GNUNET_asprintf(&dc->emsg, + _("Failed to seek to offset %llu in file `%s': %s"), + (unsigned long long)off, + dc->filename, + strerror(errno)); + goto signal_error; + } + if (prc->size != GNUNET_DISK_file_write(fh, pt, prc->size)) + { + GNUNET_asprintf( + &dc->emsg, + _("Failed to write block of %u bytes at offset %llu in file `%s': %s"), + (unsigned int)prc->size, + (unsigned long long)off, + dc->filename, + strerror(errno)); + goto signal_error; + } + GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(fh)); + fh = NULL; } - GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); - fh = NULL; - } if (0 == dr->depth) - { - /* DBLOCK, update progress and try recursion if applicable */ - app = prc->size; - if (dr->offset < dc->offset) - { - /* starting offset begins in the middle of pt, - * do not count first bytes as progress */ - GNUNET_assert (app > (dc->offset - dr->offset)); - app -= (dc->offset - dr->offset); - } - if (dr->offset + prc->size > dc->offset + dc->length) - { - /* end of block is after relevant range, - * do not count last bytes as progress */ - GNUNET_assert (app > - (dr->offset + prc->size) - (dc->offset + dc->length)); - app -= (dr->offset + prc->size) - (dc->offset + dc->length); - } - dc->completed += app; - - /* do recursive download if option is set and either meta data - * says it is a directory or if no meta data is given AND filename - * ends in '.gnd' (top-level case) */ - if (is_recursive_download (dc)) - GNUNET_FS_directory_list_contents (prc->size, - pt, - off, - &trigger_recursive_download, - dc); - } - GNUNET_assert (dc->completed <= dc->length); + { + /* DBLOCK, update progress and try recursion if applicable */ + app = prc->size; + if (dr->offset < dc->offset) + { + /* starting offset begins in the middle of pt, + * do not count first bytes as progress */ + GNUNET_assert(app > (dc->offset - dr->offset)); + app -= (dc->offset - dr->offset); + } + if (dr->offset + prc->size > dc->offset + dc->length) + { + /* end of block is after relevant range, + * do not count last bytes as progress */ + GNUNET_assert(app > + (dr->offset + prc->size) - (dc->offset + dc->length)); + app -= (dr->offset + prc->size) - (dc->offset + dc->length); + } + dc->completed += app; + + /* do recursive download if option is set and either meta data + * says it is a directory or if no meta data is given AND filename + * ends in '.gnd' (top-level case) */ + if (is_recursive_download(dc)) + GNUNET_FS_directory_list_contents(prc->size, + pt, + off, + &trigger_recursive_download, + dc); + } + GNUNET_assert(dc->completed <= dc->length); dr->state = BRS_DOWNLOAD_DOWN; pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; pi.value.download.specifics.progress.data = pt; @@ -1163,112 +1171,120 @@ process_result_with_request (void *cls, if (prc->last_transmission.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) pi.value.download.specifics.progress.block_download_duration = - GNUNET_TIME_absolute_get_duration (prc->last_transmission); + GNUNET_TIME_absolute_get_duration(prc->last_transmission); else pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; /* found locally */ - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); if (0 == dr->depth) - propagate_up (dr); + propagate_up(dr); if (dc->completed == dc->length) - { - /* download completed, signal */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download completed, truncating file to desired length %llu\n", - (unsigned long long) GNUNET_ntohll ( - dc->uri->data.chk.file_length)); - /* truncate file to size (since we store IBlocks at the end) */ - if (NULL != dc->filename) - { - if (0 != truncate (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "truncate", - dc->filename); - } - GNUNET_assert (0 == dr->depth); - check_completed (dc); - } + { + /* download completed, signal */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Download completed, truncating file to desired length %llu\n", + (unsigned long long)GNUNET_ntohll( + dc->uri->data.chk.file_length)); + /* truncate file to size (since we store IBlocks at the end) */ + if (NULL != dc->filename) + { + if (0 != truncate(dc->filename, + GNUNET_ntohll(dc->uri->data.chk.file_length))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "truncate", + dc->filename); + } + GNUNET_assert(0 == dr->depth); + check_completed(dc); + } if (0 == dr->depth) - { - /* bottom of the tree, no child downloads possible, just sync */ - GNUNET_FS_download_sync_ (dc); - return GNUNET_YES; - } + { + /* bottom of the tree, no child downloads possible, just sync */ + GNUNET_FS_download_sync_(dc); + return GNUNET_YES; + } - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Triggering downloads of children (this block was at depth %u and offset %llu)\n", dr->depth, - (unsigned long long) dr->offset); - GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); - chkarr = (struct ContentHashKey *) pt; + (unsigned long long)dr->offset); + GNUNET_assert(0 == (prc->size % sizeof(struct ContentHashKey))); + chkarr = (struct ContentHashKey *)pt; for (i = dr->num_children - 1; i >= 0; i--) - { - drc = dr->children[i]; - switch (drc->state) { - case BRS_INIT: - if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) - { - /* 'chkarr' does not have enough space for this chk_idx; - internal error! */ - GNUNET_break (0); - GNUNET_assert (0); - dc->emsg = GNUNET_strdup (_ ("internal error decoding tree")); - goto signal_error; - } - drc->chk = chkarr[drc->chk_idx]; - drc->state = BRS_CHK_SET; - if (GNUNET_YES == dc->issue_requests) - schedule_block_download (dc, drc); - break; - case BRS_RECONSTRUCT_DOWN: - GNUNET_assert (0); - break; - case BRS_RECONSTRUCT_META_UP: - GNUNET_assert (0); - break; - case BRS_RECONSTRUCT_UP: - GNUNET_assert (0); - break; - case BRS_CHK_SET: - GNUNET_assert (0); - break; - case BRS_DOWNLOAD_DOWN: - GNUNET_assert (0); - break; - case BRS_DOWNLOAD_UP: - GNUNET_assert (0); - break; - case BRS_ERROR: - GNUNET_assert (0); - break; - default: - GNUNET_assert (0); - break; + drc = dr->children[i]; + switch (drc->state) + { + case BRS_INIT: + if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size) + { + /* 'chkarr' does not have enough space for this chk_idx; + internal error! */ + GNUNET_break(0); + GNUNET_assert(0); + dc->emsg = GNUNET_strdup(_("internal error decoding tree")); + goto signal_error; + } + drc->chk = chkarr[drc->chk_idx]; + drc->state = BRS_CHK_SET; + if (GNUNET_YES == dc->issue_requests) + schedule_block_download(dc, drc); + break; + + case BRS_RECONSTRUCT_DOWN: + GNUNET_assert(0); + break; + + case BRS_RECONSTRUCT_META_UP: + GNUNET_assert(0); + break; + + case BRS_RECONSTRUCT_UP: + GNUNET_assert(0); + break; + + case BRS_CHK_SET: + GNUNET_assert(0); + break; + + case BRS_DOWNLOAD_DOWN: + GNUNET_assert(0); + break; + + case BRS_DOWNLOAD_UP: + GNUNET_assert(0); + break; + + case BRS_ERROR: + GNUNET_assert(0); + break; + + default: + GNUNET_assert(0); + break; + } } - } - GNUNET_FS_download_sync_ (dc); + GNUNET_FS_download_sync_(dc); return GNUNET_YES; signal_error: if (NULL != fh) - GNUNET_DISK_file_close (fh); + GNUNET_DISK_file_close(fh); pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; pi.value.download.specifics.error.message = dc->emsg; - GNUNET_FS_download_make_status_ (&pi, dc); - GNUNET_MQ_destroy (dc->mq); + GNUNET_FS_download_make_status_(&pi, dc); + GNUNET_MQ_destroy(dc->mq); dc->mq = NULL; - GNUNET_FS_free_download_request_ (dc->top_request); + GNUNET_FS_free_download_request_(dc->top_request); dc->top_request = NULL; if (NULL != dc->job_queue) - { - GNUNET_FS_dequeue_ (dc->job_queue); - dc->job_queue = NULL; - } - GNUNET_FS_download_sync_ (dc); + { + GNUNET_FS_dequeue_(dc->job_queue); + dc->job_queue = NULL; + } + GNUNET_FS_download_sync_(dc); return GNUNET_NO; } @@ -1281,7 +1297,7 @@ signal_error: * @param msg message received */ static int -check_put (void *cls, const struct ClientPutMessage *cm) +check_put(void *cls, const struct ClientPutMessage *cm) { /* any varsize length is OK */ return GNUNET_OK; @@ -1296,28 +1312,28 @@ check_put (void *cls, const struct ClientPutMessage *cm) * @param msg message received */ static void -handle_put (void *cls, const struct ClientPutMessage *cm) +handle_put(void *cls, const struct ClientPutMessage *cm) { struct GNUNET_FS_DownloadContext *dc = cls; - uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); + uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); struct ProcessResultClosure prc; prc.dc = dc; prc.data = &cm[1]; - prc.last_transmission = GNUNET_TIME_absolute_ntoh (cm->last_transmission); + prc.last_transmission = GNUNET_TIME_absolute_ntoh(cm->last_transmission); prc.size = msize; - prc.type = ntohl (cm->type); + prc.type = ntohl(cm->type); prc.do_store = GNUNET_YES; - prc.respect_offered = ntohl (cm->respect_offered); - prc.num_transmissions = ntohl (cm->num_transmissions); - GNUNET_CRYPTO_hash (prc.data, msize, &prc.query); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received result for query `%s' from FS service\n", - GNUNET_h2s (&prc.query)); - GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, - &prc.query, - &process_result_with_request, - &prc); + prc.respect_offered = ntohl(cm->respect_offered); + prc.num_transmissions = ntohl(cm->num_transmissions); + GNUNET_CRYPTO_hash(prc.data, msize, &prc.query); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received result for query `%s' from FS service\n", + GNUNET_h2s(&prc.query)); + GNUNET_CONTAINER_multihashmap_get_multiple(dc->active, + &prc.query, + &process_result_with_request, + &prc); } @@ -1330,18 +1346,18 @@ handle_put (void *cls, const struct ClientPutMessage *cm) * @param error error code */ static void -download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +download_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_FS_DownloadContext *dc = cls; if (NULL != dc->mq) - { - GNUNET_MQ_destroy (dc->mq); - dc->mq = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting download request failed, trying to reconnect\n"); - try_reconnect (dc); + { + GNUNET_MQ_destroy(dc->mq); + dc->mq = NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Transmitting download request failed, trying to reconnect\n"); + try_reconnect(dc); } @@ -1351,31 +1367,31 @@ download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @param cls our download context */ static void -do_reconnect (void *cls) +do_reconnect(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (put, - GNUNET_MESSAGE_TYPE_FS_PUT, - struct ClientPutMessage, - dc), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(put, + GNUNET_MESSAGE_TYPE_FS_PUT, + struct ClientPutMessage, + dc), + GNUNET_MQ_handler_end() }; dc->task = NULL; - dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, - "fs", - handlers, - &download_mq_error_handler, - dc); + dc->mq = GNUNET_CLIENT_connect(dc->h->cfg, + "fs", + handlers, + &download_mq_error_handler, + dc); if (NULL == dc->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Connecting to `%s'-service failed, will try again.\n", - "FS"); - try_reconnect (dc); - return; - } - GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Connecting to `%s'-service failed, will try again.\n", + "FS"); + try_reconnect(dc); + return; + } + GNUNET_CONTAINER_multihashmap_iterate(dc->active, &retry_entry, dc); } @@ -1387,27 +1403,27 @@ do_reconnect (void *cls) * @param dc download context that is having trouble */ static void -try_reconnect (struct GNUNET_FS_DownloadContext *dc) +try_reconnect(struct GNUNET_FS_DownloadContext *dc) { if (NULL != dc->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Moving all requests back to pending list\n"); - GNUNET_MQ_destroy (dc->mq); - dc->mq = NULL; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Moving all requests back to pending list\n"); + GNUNET_MQ_destroy(dc->mq); + dc->mq = NULL; + } if (0 == dc->reconnect_backoff.rel_value_us) dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; else - dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (dc->reconnect_backoff); + dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(dc->reconnect_backoff); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Will try to reconnect in %s\n", - GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, - GNUNET_YES)); - GNUNET_break (NULL != dc->job_queue); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Will try to reconnect in %s\n", + GNUNET_STRINGS_relative_time_to_string(dc->reconnect_backoff, + GNUNET_YES)); + GNUNET_break(NULL != dc->job_queue); dc->task = - GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc); + GNUNET_SCHEDULER_add_delayed(dc->reconnect_backoff, &do_reconnect, dc); } @@ -1418,18 +1434,18 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) * @param mq handle to use for communcation with FS (we must destroy it!) */ static void -activate_fs_download (void *cls) +activate_fs_download(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; - GNUNET_assert (NULL == dc->mq); - GNUNET_assert (NULL != dc->active); - do_reconnect (dc); + GNUNET_assert(NULL == dc->mq); + GNUNET_assert(NULL != dc->active); + do_reconnect(dc); if (NULL != dc->mq) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); } @@ -1439,19 +1455,19 @@ activate_fs_download (void *cls) * @param cls the `struct GNUNET_FS_DownloadContext` */ static void -deactivate_fs_download (void *cls) +deactivate_fs_download(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); if (NULL != dc->mq) - { - GNUNET_MQ_destroy (dc->mq); - dc->mq = NULL; - } + { + GNUNET_MQ_destroy(dc->mq); + dc->mq = NULL; + } pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); } @@ -1475,38 +1491,38 @@ deactivate_fs_download (void *cls) * the specified depth */ static struct DownloadRequest * -create_download_request (struct DownloadRequest *parent, - unsigned int chk_idx, - unsigned int depth, - uint64_t dr_offset, - uint64_t file_start_offset, - uint64_t desired_length) +create_download_request(struct DownloadRequest *parent, + unsigned int chk_idx, + unsigned int depth, + uint64_t dr_offset, + uint64_t file_start_offset, + uint64_t desired_length) { struct DownloadRequest *dr; unsigned int i; unsigned int head_skip; uint64_t child_block_size; - dr = GNUNET_new (struct DownloadRequest); + dr = GNUNET_new(struct DownloadRequest); dr->parent = parent; dr->depth = depth; dr->offset = dr_offset; dr->chk_idx = chk_idx; if (0 == depth) return dr; - child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); + child_block_size = GNUNET_FS_tree_compute_tree_size(depth - 1); /* calculate how many blocks at this level are not interesting * from the start (rounded down), either because of the requested * file offset or because this IBlock is further along */ if (dr_offset < file_start_offset) - { - head_skip = (file_start_offset - dr_offset) / child_block_size; - } + { + head_skip = (file_start_offset - dr_offset) / child_block_size; + } else - { - head_skip = 0; - } + { + head_skip = 0; + } /* calculate index of last block at this level that is interesting (rounded up) */ dr->num_children = @@ -1514,32 +1530,32 @@ create_download_request (struct DownloadRequest *parent, if (dr->num_children * child_block_size < file_start_offset + desired_length - dr_offset) dr->num_children++; /* round up */ - GNUNET_assert (dr->num_children > head_skip); + GNUNET_assert(dr->num_children > head_skip); dr->num_children -= head_skip; if (dr->num_children > CHK_PER_INODE) dr->num_children = CHK_PER_INODE; /* cap at max */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block at offset %llu and depth %u has %u children\n", - (unsigned long long) dr_offset, - depth, - dr->num_children); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Block at offset %llu and depth %u has %u children\n", + (unsigned long long)dr_offset, + depth, + dr->num_children); /* now we can get the total number of *interesting* children for this block */ /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ - GNUNET_assert (dr->num_children > 0); + GNUNET_assert(dr->num_children > 0); - dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *); + dr->children = GNUNET_new_array(dr->num_children, struct DownloadRequest *); for (i = 0; i < dr->num_children; i++) - { - dr->children[i] = - create_download_request (dr, - i + head_skip, - depth - 1, - dr_offset + (i + head_skip) * child_block_size, - file_start_offset, - desired_length); - } + { + dr->children[i] = + create_download_request(dr, + i + head_skip, + depth - 1, + dr_offset + (i + head_skip) * child_block_size, + file_start_offset, + desired_length); + } return dr; } @@ -1551,25 +1567,25 @@ create_download_request (struct DownloadRequest *parent, * @param cls the 'struct ReconstructContext' */ static void -reconstruct_cont (void *cls) +reconstruct_cont(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; /* clean up state from tree encoder */ if (NULL != dc->task) - { - GNUNET_SCHEDULER_cancel (dc->task); - dc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(dc->task); + dc->task = NULL; + } if (NULL != dc->rfh) - { - GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); - dc->rfh = NULL; - } + { + GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); + dc->rfh = NULL; + } /* start "normal" download */ dc->issue_requests = GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); - schedule_block_download (dc, dc->top_request); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); + schedule_block_download(dc, dc->top_request); } @@ -1579,12 +1595,12 @@ reconstruct_cont (void *cls) * @param cls the 'struct GNUJNET_FS_DownloadContext' we're processing */ static void -get_next_block (void *cls) +get_next_block(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; dc->task = NULL; - GNUNET_FS_tree_encoder_next (dc->te); + GNUNET_FS_tree_encoder_next(dc->te); } @@ -1606,13 +1622,13 @@ get_next_block (void *cls) * @param block_size size of block (in bytes) */ static void -reconstruct_cb (void *cls, - const struct ContentHashKey *chk, - uint64_t offset, - unsigned int depth, - enum GNUNET_BLOCK_Type type, - const void *block, - uint16_t block_size) +reconstruct_cb(void *cls, + const struct ContentHashKey *chk, + uint64_t offset, + unsigned int depth, + enum GNUNET_BLOCK_Type type, + const void *block, + uint16_t block_size) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -1623,117 +1639,125 @@ reconstruct_cb (void *cls, /* find corresponding request entry */ dr = dc->top_request; while (dr->depth > depth) - { - GNUNET_assert (dr->num_children > 0); - blen = GNUNET_FS_tree_compute_tree_size (dr->depth - 1); - chld = (offset - dr->offset) / blen; - if (chld < dr->children[0]->chk_idx) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block %u < %u irrelevant for our range\n", - chld, - dr->children[0]->chk_idx); - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); - return; /* irrelevant block */ - } - if (chld > dr->children[dr->num_children - 1]->chk_idx) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block %u > %u irrelevant for our range\n", - chld, - dr->children[dr->num_children - 1]->chk_idx); - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); - return; /* irrelevant block */ - } - dr = dr->children[chld - dr->children[0]->chk_idx]; - } - GNUNET_log ( + { + GNUNET_assert(dr->num_children > 0); + blen = GNUNET_FS_tree_compute_tree_size(dr->depth - 1); + chld = (offset - dr->offset) / blen; + if (chld < dr->children[0]->chk_idx) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Block %u < %u irrelevant for our range\n", + chld, + dr->children[0]->chk_idx); + dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); + return; /* irrelevant block */ + } + if (chld > dr->children[dr->num_children - 1]->chk_idx) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Block %u > %u irrelevant for our range\n", + chld, + dr->children[dr->num_children - 1]->chk_idx); + dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); + return; /* irrelevant block */ + } + dr = dr->children[chld - dr->children[0]->chk_idx]; + } + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Matched TE block with request at offset %llu and depth %u in state %d\n", - (unsigned long long) dr->offset, + (unsigned long long)dr->offset, dr->depth, dr->state); /* FIXME: this code needs more testing and might need to handle more states... */ switch (dr->state) - { - case BRS_INIT: - break; - case BRS_RECONSTRUCT_DOWN: - break; - case BRS_RECONSTRUCT_META_UP: - break; - case BRS_RECONSTRUCT_UP: - break; - case BRS_CHK_SET: - if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Reconstruction succeeded, can use block at offset %llu, depth %u\n", - (unsigned long long) offset, - depth); - /* block matches, hence tree below matches; - * this request is done! */ - dr->state = BRS_DOWNLOAD_UP; - (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, - &dr->chk.query, - dr); - /* calculate how many bytes of payload this block - * corresponds to */ - blen = GNUNET_FS_tree_compute_tree_size (dr->depth); - /* how many of those bytes are in the requested range? */ - blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset); - /* signal progress */ - dc->completed += blen; - pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; - pi.value.download.specifics.progress.data = NULL; - pi.value.download.specifics.progress.offset = offset; - pi.value.download.specifics.progress.data_len = 0; - pi.value.download.specifics.progress.depth = 0; - pi.value.download.specifics.progress.respect_offered = 0; - pi.value.download.specifics.progress.block_download_duration = - GNUNET_TIME_UNIT_ZERO; - GNUNET_FS_download_make_status_ (&pi, dc); - /* FIXME: duplicated code from 'process_result_with_request - refactor */ - if (dc->completed == dc->length) - { - /* download completed, signal */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download completed, truncating file to desired length %llu\n", - (unsigned long long) GNUNET_ntohll ( - dc->uri->data.chk.file_length)); - /* truncate file to size (since we store IBlocks at the end) */ - if (NULL != dc->filename) + { + case BRS_INIT: + break; + + case BRS_RECONSTRUCT_DOWN: + break; + + case BRS_RECONSTRUCT_META_UP: + break; + + case BRS_RECONSTRUCT_UP: + break; + + case BRS_CHK_SET: + if (0 == memcmp(chk, &dr->chk, sizeof(struct ContentHashKey))) { - if (0 != truncate (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "truncate", - dc->filename); + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Reconstruction succeeded, can use block at offset %llu, depth %u\n", + (unsigned long long)offset, + depth); + /* block matches, hence tree below matches; + * this request is done! */ + dr->state = BRS_DOWNLOAD_UP; + (void)GNUNET_CONTAINER_multihashmap_remove(dc->active, + &dr->chk.query, + dr); + /* calculate how many bytes of payload this block + * corresponds to */ + blen = GNUNET_FS_tree_compute_tree_size(dr->depth); + /* how many of those bytes are in the requested range? */ + blen = GNUNET_MIN(blen, dc->length + dc->offset - dr->offset); + /* signal progress */ + dc->completed += blen; + pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; + pi.value.download.specifics.progress.data = NULL; + pi.value.download.specifics.progress.offset = offset; + pi.value.download.specifics.progress.data_len = 0; + pi.value.download.specifics.progress.depth = 0; + pi.value.download.specifics.progress.respect_offered = 0; + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_UNIT_ZERO; + GNUNET_FS_download_make_status_(&pi, dc); + /* FIXME: duplicated code from 'process_result_with_request - refactor */ + if (dc->completed == dc->length) + { + /* download completed, signal */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Download completed, truncating file to desired length %llu\n", + (unsigned long long)GNUNET_ntohll( + dc->uri->data.chk.file_length)); + /* truncate file to size (since we store IBlocks at the end) */ + if (NULL != dc->filename) + { + if (0 != truncate(dc->filename, + GNUNET_ntohll(dc->uri->data.chk.file_length))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "truncate", + dc->filename); + } + } } - } + else + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Reconstruction failed, need to download block at offset %llu, depth %u\n", + (unsigned long long)offset, + depth); + break; + + case BRS_DOWNLOAD_DOWN: + break; + + case BRS_DOWNLOAD_UP: + break; + + case BRS_ERROR: + break; + + default: + GNUNET_assert(0); + break; } - else - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Reconstruction failed, need to download block at offset %llu, depth %u\n", - (unsigned long long) offset, - depth); - break; - case BRS_DOWNLOAD_DOWN: - break; - case BRS_DOWNLOAD_UP: - break; - case BRS_ERROR: - break; - default: - GNUNET_assert (0); - break; - } - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); + dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) - check_completed (dc); + check_completed(dc); } @@ -1750,7 +1774,7 @@ reconstruct_cb (void *cls, * @return number of bytes copied to buf, 0 on error */ static size_t -fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) +fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_DISK_FileHandle *fh = dc->rfh; @@ -1758,19 +1782,19 @@ fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) if (NULL != emsg) *emsg = NULL; - if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET)) - { - if (NULL != emsg) - *emsg = GNUNET_strdup (strerror (errno)); - return 0; - } - ret = GNUNET_DISK_file_read (fh, buf, max); + if (offset != GNUNET_DISK_file_seek(fh, offset, GNUNET_DISK_SEEK_SET)) + { + if (NULL != emsg) + *emsg = GNUNET_strdup(strerror(errno)); + return 0; + } + ret = GNUNET_DISK_file_read(fh, buf, max); if (ret < 0) - { - if (NULL != emsg) - *emsg = GNUNET_strdup (strerror (errno)); - return 0; - } + { + if (NULL != emsg) + *emsg = GNUNET_strdup(strerror(errno)); + return 0; + } return ret; } @@ -1782,151 +1806,155 @@ fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) * @param cls the 'struct GNUNET_FS_DownloadContext' */ void -GNUNET_FS_download_start_task_ (void *cls) +GNUNET_FS_download_start_task_(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; struct GNUNET_DISK_FileHandle *fh; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); dc->task = NULL; if (0 == dc->length) - { - /* no bytes required! */ - if (NULL != dc->filename) - { - fh = GNUNET_DISK_file_open (dc->filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE | - ((0 == - GNUNET_FS_uri_chk_get_file_size (dc->uri)) - ? GNUNET_DISK_OPEN_TRUNCATE - : 0), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); - GNUNET_DISK_file_close (fh); - } - GNUNET_FS_download_sync_ (dc); - pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; - pi.value.download.specifics.start.meta = dc->meta; - GNUNET_FS_download_make_status_ (&pi, dc); - check_completed (dc); - return; - } + { + /* no bytes required! */ + if (NULL != dc->filename) + { + fh = GNUNET_DISK_file_open(dc->filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE | + ((0 == + GNUNET_FS_uri_chk_get_file_size(dc->uri)) + ? GNUNET_DISK_OPEN_TRUNCATE + : 0), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); + GNUNET_DISK_file_close(fh); + } + GNUNET_FS_download_sync_(dc); + pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; + pi.value.download.specifics.start.meta = dc->meta; + GNUNET_FS_download_make_status_(&pi, dc); + check_completed(dc); + return; + } if (NULL != dc->emsg) return; if (NULL == dc->top_request) - { - dc->top_request = create_download_request (NULL, - 0, - dc->treedepth - 1, - 0, - dc->offset, - dc->length); - dc->top_request->state = BRS_CHK_SET; - dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) + { + dc->top_request = create_download_request(NULL, + 0, + dc->treedepth - 1, + 0, + dc->offset, + dc->length); + dc->top_request->state = BRS_CHK_SET; + dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk; - /* signal start */ - GNUNET_FS_download_sync_ (dc); - if (NULL != dc->search) - GNUNET_FS_search_result_sync_ (dc->search); - pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; - pi.value.download.specifics.start.meta = dc->meta; - GNUNET_FS_download_make_status_ (&pi, dc); - } - GNUNET_FS_download_start_downloading_ (dc); + /* signal start */ + GNUNET_FS_download_sync_(dc); + if (NULL != dc->search) + GNUNET_FS_search_result_sync_(dc->search); + pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; + pi.value.download.specifics.start.meta = dc->meta; + GNUNET_FS_download_make_status_(&pi, dc); + } + GNUNET_FS_download_start_downloading_(dc); /* attempt reconstruction from disk */ - if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) - dc->rfh = GNUNET_DISK_file_open (dc->filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + if (GNUNET_YES == GNUNET_DISK_file_test(dc->filename)) + dc->rfh = GNUNET_DISK_file_open(dc->filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (dc->top_request->state == BRS_CHK_SET) - { - if (NULL != dc->rfh) - { - /* first, try top-down */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying top-down reconstruction for `%s'\n", - dc->filename); - try_top_down_reconstruction (dc, dc->top_request); - switch (dc->top_request->state) - { - case BRS_CHK_SET: - break; /* normal */ - case BRS_DOWNLOAD_DOWN: - break; /* normal, some blocks already down */ - case BRS_DOWNLOAD_UP: - /* already done entirely, party! */ - if (NULL != dc->rfh) + { + if (NULL != dc->rfh) { - /* avoid hanging on to file handle longer than - * necessary */ - GNUNET_DISK_file_close (dc->rfh); - dc->rfh = NULL; + /* first, try top-down */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Trying top-down reconstruction for `%s'\n", + dc->filename); + try_top_down_reconstruction(dc, dc->top_request); + switch (dc->top_request->state) + { + case BRS_CHK_SET: + break; /* normal */ + + case BRS_DOWNLOAD_DOWN: + break; /* normal, some blocks already down */ + + case BRS_DOWNLOAD_UP: + /* already done entirely, party! */ + if (NULL != dc->rfh) + { + /* avoid hanging on to file handle longer than + * necessary */ + GNUNET_DISK_file_close(dc->rfh); + dc->rfh = NULL; + } + return; + + case BRS_ERROR: + GNUNET_asprintf(&dc->emsg, _("Invalid URI")); + GNUNET_FS_download_sync_(dc); + pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; + pi.value.download.specifics.error.message = dc->emsg; + GNUNET_FS_download_make_status_(&pi, dc); + return; + + default: + GNUNET_assert(0); + break; + } } - return; - case BRS_ERROR: - GNUNET_asprintf (&dc->emsg, _ ("Invalid URI")); - GNUNET_FS_download_sync_ (dc); - pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; - pi.value.download.specifics.error.message = dc->emsg; - GNUNET_FS_download_make_status_ (&pi, dc); - return; - default: - GNUNET_assert (0); - break; - } } - } /* attempt reconstruction from meta data */ - if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && + if ((GNUNET_FS_uri_chk_get_file_size(dc->uri) <= MAX_INLINE_SIZE) && (NULL != dc->meta)) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", - (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), - (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); - GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); - if (BRS_DOWNLOAD_UP == dc->top_request->state) { - if (NULL != dc->rfh) - { - /* avoid hanging on to file handle longer than - * necessary */ - GNUNET_DISK_file_close (dc->rfh); - dc->rfh = NULL; - } - return; /* finished, status update was already done for us */ - } - } + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", + (unsigned long long)GNUNET_FS_uri_chk_get_file_size(dc->uri), + (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size(dc->meta)); + GNUNET_CONTAINER_meta_data_iterate(dc->meta, &match_full_data, dc); + if (BRS_DOWNLOAD_UP == dc->top_request->state) + { + if (NULL != dc->rfh) + { + /* avoid hanging on to file handle longer than + * necessary */ + GNUNET_DISK_file_close(dc->rfh); + dc->rfh = NULL; + } + return; /* finished, status update was already done for us */ + } + } if (NULL != dc->rfh) - { - /* finally, actually run bottom-up */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying bottom-up reconstruction of file `%s'\n", - dc->filename); - dc->te = - GNUNET_FS_tree_encoder_create (dc->h, - GNUNET_FS_uri_chk_get_file_size (dc->uri), - dc, - &fh_reader, - &reconstruct_cb, - NULL, - &reconstruct_cont); - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); - } + { + /* finally, actually run bottom-up */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Trying bottom-up reconstruction of file `%s'\n", + dc->filename); + dc->te = + GNUNET_FS_tree_encoder_create(dc->h, + GNUNET_FS_uri_chk_get_file_size(dc->uri), + dc, + &fh_reader, + &reconstruct_cb, + NULL, + &reconstruct_cont); + dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); + } else - { - /* simple, top-level download */ - dc->issue_requests = GNUNET_YES; - schedule_block_download (dc, dc->top_request); - } + { + /* simple, top-level download */ + dc->issue_requests = GNUNET_YES; + schedule_block_download(dc, dc->top_request); + } if (BRS_DOWNLOAD_UP == dc->top_request->state) - check_completed (dc); + check_completed(dc); } @@ -1937,59 +1965,59 @@ GNUNET_FS_download_start_task_ (void *cls) * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for */ void -GNUNET_FS_download_signal_suspend_ (void *cls) +GNUNET_FS_download_signal_suspend_(void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; if (NULL != dc->top) - GNUNET_FS_end_top (dc->h, dc->top); + GNUNET_FS_end_top(dc->h, dc->top); while (NULL != dc->child_head) - GNUNET_FS_download_signal_suspend_ (dc->child_head); + GNUNET_FS_download_signal_suspend_(dc->child_head); if (NULL != dc->search) - { - dc->search->download = NULL; - dc->search = NULL; - } + { + dc->search->download = NULL; + dc->search = NULL; + } if (NULL != dc->job_queue) - { - GNUNET_FS_dequeue_ (dc->job_queue); - dc->job_queue = NULL; - } + { + GNUNET_FS_dequeue_(dc->job_queue); + dc->job_queue = NULL; + } if (NULL != dc->parent) - GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, - dc->parent->child_tail, - dc); + GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, + dc->parent->child_tail, + dc); if (NULL != dc->task) - { - GNUNET_SCHEDULER_cancel (dc->task); - dc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(dc->task); + dc->task = NULL; + } pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); if (NULL != dc->te) - { - GNUNET_FS_tree_encoder_finish (dc->te, NULL); - dc->te = NULL; - } + { + GNUNET_FS_tree_encoder_finish(dc->te, NULL); + dc->te = NULL; + } if (NULL != dc->rfh) - { - GNUNET_DISK_file_close (dc->rfh); - dc->rfh = NULL; - } - GNUNET_FS_free_download_request_ (dc->top_request); + { + GNUNET_DISK_file_close(dc->rfh); + dc->rfh = NULL; + } + GNUNET_FS_free_download_request_(dc->top_request); if (NULL != dc->active) - { - GNUNET_CONTAINER_multihashmap_destroy (dc->active); - dc->active = NULL; - } - GNUNET_free_non_null (dc->filename); - GNUNET_CONTAINER_meta_data_destroy (dc->meta); - GNUNET_FS_uri_destroy (dc->uri); - GNUNET_free_non_null (dc->temp_filename); - GNUNET_free_non_null (dc->serialization); - GNUNET_assert (NULL == dc->job_queue); - GNUNET_free (dc); + { + GNUNET_CONTAINER_multihashmap_destroy(dc->active); + dc->active = NULL; + } + GNUNET_free_non_null(dc->filename); + GNUNET_CONTAINER_meta_data_destroy(dc->meta); + GNUNET_FS_uri_destroy(dc->uri); + GNUNET_free_non_null(dc->temp_filename); + GNUNET_free_non_null(dc->serialization); + GNUNET_assert(NULL == dc->job_queue); + GNUNET_free(dc); } @@ -2013,72 +2041,72 @@ GNUNET_FS_download_signal_suspend_ (void *cls) * @return context that can be used to control this download */ struct GNUNET_FS_DownloadContext * -create_download_context (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - const char *filename, - const char *tempname, - uint64_t offset, - uint64_t length, - uint32_t anonymity, - enum GNUNET_FS_DownloadOptions options, - void *cctx) +create_download_context(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const char *filename, + const char *tempname, + uint64_t offset, + uint64_t length, + uint32_t anonymity, + enum GNUNET_FS_DownloadOptions options, + void *cctx) { struct GNUNET_FS_DownloadContext *dc; - GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)); + GNUNET_assert(GNUNET_FS_uri_test_chk(uri) || GNUNET_FS_uri_test_loc(uri)); if ((offset + length < offset) || - (offset + length > GNUNET_FS_uri_chk_get_file_size (uri))) - { - GNUNET_break (0); - return NULL; - } - dc = GNUNET_new (struct GNUNET_FS_DownloadContext); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting download %p, %u bytes at offset %llu\n", - dc, - (unsigned int) length, - (unsigned long long) offset); + (offset + length > GNUNET_FS_uri_chk_get_file_size(uri))) + { + GNUNET_break(0); + return NULL; + } + dc = GNUNET_new(struct GNUNET_FS_DownloadContext); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting download %p, %u bytes at offset %llu\n", + dc, + (unsigned int)length, + (unsigned long long)offset); dc->h = h; - dc->uri = GNUNET_FS_uri_dup (uri); - dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); + dc->uri = GNUNET_FS_uri_dup(uri); + dc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); dc->client_info = cctx; - dc->start_time = GNUNET_TIME_absolute_get (); + dc->start_time = GNUNET_TIME_absolute_get(); if (NULL != filename) - { - dc->filename = GNUNET_strdup (filename); - if (GNUNET_YES == GNUNET_DISK_file_test (filename)) - GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, + { + dc->filename = GNUNET_strdup(filename); + if (GNUNET_YES == GNUNET_DISK_file_test(filename)) + GNUNET_break(GNUNET_OK == GNUNET_DISK_file_size(filename, &dc->old_file_size, GNUNET_YES, GNUNET_YES)); - } - if (GNUNET_FS_uri_test_loc (dc->uri)) - GNUNET_assert (GNUNET_OK == - GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); + } + if (GNUNET_FS_uri_test_loc(dc->uri)) + GNUNET_assert(GNUNET_OK == + GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); dc->offset = offset; dc->length = length; dc->anonymity = anonymity; dc->options = options; dc->active = - GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), - GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create(1 + 2 * (length / DBLOCK_SIZE), + GNUNET_NO); dc->treedepth = - GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); - if ((NULL == filename) && (is_recursive_download (dc))) - { - if (NULL != tempname) - dc->temp_filename = GNUNET_strdup (tempname); - else - dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting download `%s' of %llu bytes with tree depth %u\n", - filename, - (unsigned long long) length, - dc->treedepth); - GNUNET_assert (NULL == dc->job_queue); - dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); + GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); + if ((NULL == filename) && (is_recursive_download(dc))) + { + if (NULL != tempname) + dc->temp_filename = GNUNET_strdup(tempname); + else + dc->temp_filename = GNUNET_DISK_mktemp("gnunet-directory-download-tmp"); + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting download `%s' of %llu bytes with tree depth %u\n", + filename, + (unsigned long long)length, + dc->treedepth); + GNUNET_assert(NULL == dc->job_queue); + dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); return dc; } @@ -2114,38 +2142,38 @@ create_download_context (struct GNUNET_FS_Handle *h, * @return context that can be used to control this download */ struct GNUNET_FS_DownloadContext * -GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - const char *filename, - const char *tempname, - uint64_t offset, - uint64_t length, - uint32_t anonymity, - enum GNUNET_FS_DownloadOptions options, - void *cctx, - struct GNUNET_FS_DownloadContext *parent) +GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const char *filename, + const char *tempname, + uint64_t offset, + uint64_t length, + uint32_t anonymity, + enum GNUNET_FS_DownloadOptions options, + void *cctx, + struct GNUNET_FS_DownloadContext *parent) { struct GNUNET_FS_DownloadContext *dc; - dc = create_download_context (h, - uri, - meta, - filename, - tempname, - offset, - length, - anonymity, - options, - cctx); + dc = create_download_context(h, + uri, + meta, + filename, + tempname, + offset, + length, + anonymity, + options, + cctx); if (NULL == dc) return NULL; dc->parent = parent; if (NULL != parent) - GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); + GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) dc->top = - GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); + GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); return dc; } @@ -2185,43 +2213,43 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, * @return context that can be used to control this download */ struct GNUNET_FS_DownloadContext * -GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, - struct GNUNET_FS_SearchResult *sr, - const char *filename, - const char *tempname, - uint64_t offset, - uint64_t length, - uint32_t anonymity, - enum GNUNET_FS_DownloadOptions options, - void *cctx) +GNUNET_FS_download_start_from_search(struct GNUNET_FS_Handle *h, + struct GNUNET_FS_SearchResult *sr, + const char *filename, + const char *tempname, + uint64_t offset, + uint64_t length, + uint32_t anonymity, + enum GNUNET_FS_DownloadOptions options, + void *cctx) { struct GNUNET_FS_DownloadContext *dc; if ((NULL == sr) || (NULL != sr->download)) - { - GNUNET_break (0); - return NULL; - } - dc = create_download_context (h, - sr->uri, - sr->meta, - filename, - tempname, - offset, - length, - anonymity, - options, - cctx); + { + GNUNET_break(0); + return NULL; + } + dc = create_download_context(h, + sr->uri, + sr->meta, + filename, + tempname, + offset, + length, + anonymity, + options, + cctx); if (NULL == dc) return NULL; dc->search = sr; sr->download = dc; if (NULL != sr->probe_ctx) - { - GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); - sr->probe_ctx = NULL; - GNUNET_FS_stop_probe_ping_task_ (sr); - } + { + GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); + sr->probe_ctx = NULL; + GNUNET_FS_stop_probe_ping_task_(sr); + } return dc; } @@ -2232,28 +2260,28 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, * @param dc our download context */ void -GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) +GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc) { if (dc->completed == dc->length) return; if (NULL != dc->mq) return; /* already running */ - GNUNET_assert (NULL == dc->job_queue); - GNUNET_assert (NULL == dc->task); - GNUNET_assert (NULL != dc->active); + GNUNET_assert(NULL == dc->job_queue); + GNUNET_assert(NULL == dc->task); + GNUNET_assert(NULL != dc->active); dc->job_queue = - GNUNET_FS_queue_ (dc->h, - &activate_fs_download, - &deactivate_fs_download, - dc, - (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, - (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) - ? GNUNET_FS_QUEUE_PRIORITY_NORMAL - : GNUNET_FS_QUEUE_PRIORITY_PROBE); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download %p put into queue as job %p\n", - dc, - dc->job_queue); + GNUNET_FS_queue_(dc->h, + &activate_fs_download, + &deactivate_fs_download, + dc, + (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, + (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) + ? GNUNET_FS_QUEUE_PRIORITY_NORMAL + : GNUNET_FS_QUEUE_PRIORITY_PROBE); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Download %p put into queue as job %p\n", + dc, + dc->job_queue); } /** @@ -2262,9 +2290,9 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) * @param dc handle for the download */ void -GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) +GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc) { - deactivate_fs_download (dc); + deactivate_fs_download(dc); } @@ -2274,23 +2302,23 @@ GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) * @param dc handle for the download */ void -GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) +GNUNET_FS_download_resume(struct GNUNET_FS_DownloadContext *dc) { struct GNUNET_FS_ProgressInfo pi; pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; - GNUNET_FS_download_make_status_ (&pi, dc); + GNUNET_FS_download_make_status_(&pi, dc); - GNUNET_assert (NULL == dc->task); + GNUNET_assert(NULL == dc->task); dc->job_queue = - GNUNET_FS_queue_ (dc->h, - &activate_fs_download, - &deactivate_fs_download, - dc, - (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, - (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) - ? GNUNET_FS_QUEUE_PRIORITY_NORMAL - : GNUNET_FS_QUEUE_PRIORITY_PROBE); + GNUNET_FS_queue_(dc->h, + &activate_fs_download, + &deactivate_fs_download, + dc, + (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, + (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) + ? GNUNET_FS_QUEUE_PRIORITY_NORMAL + : GNUNET_FS_QUEUE_PRIORITY_PROBE); } @@ -2301,88 +2329,88 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) * @param do_delete delete files of incomplete downloads */ void -GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) +GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete) { struct GNUNET_FS_ProgressInfo pi; int have_children; int search_was_null; if (NULL != dc->top) - GNUNET_FS_end_top (dc->h, dc->top); + GNUNET_FS_end_top(dc->h, dc->top); if (NULL != dc->task) - { - GNUNET_SCHEDULER_cancel (dc->task); - dc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(dc->task); + dc->task = NULL; + } search_was_null = (NULL == dc->search); if (NULL != dc->search) - { - dc->search->download = NULL; - GNUNET_FS_search_result_sync_ (dc->search); - dc->search = NULL; - } + { + dc->search->download = NULL; + GNUNET_FS_search_result_sync_(dc->search); + dc->search = NULL; + } if (NULL != dc->job_queue) - { - GNUNET_FS_dequeue_ (dc->job_queue); - dc->job_queue = NULL; - } + { + GNUNET_FS_dequeue_(dc->job_queue); + dc->job_queue = NULL; + } if (NULL != dc->te) - { - GNUNET_FS_tree_encoder_finish (dc->te, NULL); - dc->te = NULL; - } + { + GNUNET_FS_tree_encoder_finish(dc->te, NULL); + dc->te = NULL; + } have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; while (NULL != dc->child_head) - GNUNET_FS_download_stop (dc->child_head, do_delete); + GNUNET_FS_download_stop(dc->child_head, do_delete); if (NULL != dc->parent) - GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, - dc->parent->child_tail, - dc); + GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, + dc->parent->child_tail, + dc); if (NULL != dc->serialization) - GNUNET_FS_remove_sync_file_ (dc->h, - ((NULL != dc->parent) || (! search_was_null)) - ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD - : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, - dc->serialization); - if ((GNUNET_YES == have_children) && (NULL == dc->parent)) - GNUNET_FS_remove_sync_dir_ (dc->h, - (! search_was_null) - ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD - : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + GNUNET_FS_remove_sync_file_(dc->h, + ((NULL != dc->parent) || (!search_was_null)) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, dc->serialization); + if ((GNUNET_YES == have_children) && (NULL == dc->parent)) + GNUNET_FS_remove_sync_dir_(dc->h, + (!search_was_null) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + dc->serialization); pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; - GNUNET_FS_download_make_status_ (&pi, dc); - GNUNET_FS_free_download_request_ (dc->top_request); + GNUNET_FS_download_make_status_(&pi, dc); + GNUNET_FS_free_download_request_(dc->top_request); dc->top_request = NULL; if (NULL != dc->active) - { - GNUNET_CONTAINER_multihashmap_destroy (dc->active); - dc->active = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy(dc->active); + dc->active = NULL; + } if (NULL != dc->filename) - { - if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) - { - if ((0 != unlink (dc->filename)) && (ENOENT != errno)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - dc->filename); - } - GNUNET_free (dc->filename); - } - GNUNET_CONTAINER_meta_data_destroy (dc->meta); - GNUNET_FS_uri_destroy (dc->uri); + { + if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) + { + if ((0 != unlink(dc->filename)) && (ENOENT != errno)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "unlink", + dc->filename); + } + GNUNET_free(dc->filename); + } + GNUNET_CONTAINER_meta_data_destroy(dc->meta); + GNUNET_FS_uri_destroy(dc->uri); if (NULL != dc->temp_filename) - { - if (0 != unlink (dc->temp_filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "unlink", - dc->temp_filename); - GNUNET_free (dc->temp_filename); - } - GNUNET_free_non_null (dc->serialization); - GNUNET_assert (NULL == dc->job_queue); - GNUNET_free (dc); + { + if (0 != unlink(dc->temp_filename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, + "unlink", + dc->temp_filename); + GNUNET_free(dc->temp_filename); + } + GNUNET_free_non_null(dc->serialization); + GNUNET_assert(NULL == dc->job_queue); + GNUNET_free(dc); } /* end of fs_download.c */ diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index fbf3181ef..ccba1a8b4 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_file_information.c @@ -42,7 +42,7 @@ * can be used to read this fi-struct from disk. */ const char * -GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) +GNUNET_FS_file_information_get_id(struct GNUNET_FS_FileInformation *s) { if (NULL != s->dir) return NULL; @@ -56,7 +56,7 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) * @return "filename" field of the structure (can be NULL) */ const char * -GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s) +GNUNET_FS_file_information_get_filename(struct GNUNET_FS_FileInformation *s) { return s->filename; } @@ -71,12 +71,12 @@ GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s) * @param filename filename to set */ void -GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, - const char *filename) +GNUNET_FS_file_information_set_filename(struct GNUNET_FS_FileInformation *s, + const char *filename) { - GNUNET_free_non_null (s->filename); + GNUNET_free_non_null(s->filename); if (filename) - s->filename = GNUNET_strdup (filename); + s->filename = GNUNET_strdup(filename); else s->filename = NULL; } @@ -97,7 +97,7 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_file ( +GNUNET_FS_file_information_create_from_file( struct GNUNET_FS_Handle *h, void *client_info, const char *filename, @@ -118,58 +118,58 @@ GNUNET_FS_file_information_create_from_file ( /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ if (GNUNET_OK != - GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); - return NULL; - } - fi = GNUNET_FS_make_file_reader_context_ (filename); + GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); + return NULL; + } + fi = GNUNET_FS_make_file_reader_context_(filename); if (NULL == fi) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } ret = - GNUNET_FS_file_information_create_from_reader (h, - client_info, - fsize, - &GNUNET_FS_data_reader_file_, - fi, - keywords, - meta, - do_index, - bo); + GNUNET_FS_file_information_create_from_reader(h, + client_info, + fsize, + &GNUNET_FS_data_reader_file_, + fi, + keywords, + meta, + do_index, + bo); if (ret == NULL) return NULL; ret->h = h; - ret->filename = GNUNET_strdup (filename); -#if ! WINDOWS + ret->filename = GNUNET_strdup(filename); +#if !WINDOWS fn = filename; #else - plibc_conv_to_win_path (filename, fn_conv); + plibc_conv_to_win_path(filename, fn_conv); fn = fn_conv; #endif - while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) + while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) fn = ss + 1; /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then * this should be changed to EXTRACTOR_METAFORMAT_UTF8 */ -#if ! WINDOWS - GNUNET_CONTAINER_meta_data_insert (ret->meta, - "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_C_STRING, - "text/plain", - fn, - strlen (fn) + 1); +#if !WINDOWS + GNUNET_CONTAINER_meta_data_insert(ret->meta, + "", + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + EXTRACTOR_METAFORMAT_C_STRING, + "text/plain", + fn, + strlen(fn) + 1); #else - GNUNET_CONTAINER_meta_data_insert (ret->meta, - "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - fn, - strlen (fn) + 1); + GNUNET_CONTAINER_meta_data_insert(ret->meta, + "", + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + fn, + strlen(fn) + 1); #endif return ret; } @@ -192,7 +192,7 @@ GNUNET_FS_file_information_create_from_file ( * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_data ( +GNUNET_FS_file_information_create_from_data( struct GNUNET_FS_Handle *h, void *client_info, uint64_t length, @@ -203,19 +203,19 @@ GNUNET_FS_file_information_create_from_data ( const struct GNUNET_FS_BlockOptions *bo) { if (GNUNET_YES == do_index) - { - GNUNET_break (0); - return NULL; - } - return GNUNET_FS_file_information_create_from_reader (h, - client_info, - length, - &GNUNET_FS_data_reader_copy_, - data, - keywords, - meta, - do_index, - bo); + { + GNUNET_break(0); + return NULL; + } + return GNUNET_FS_file_information_create_from_reader(h, + client_info, + length, + &GNUNET_FS_data_reader_copy_, + data, + keywords, + meta, + do_index, + bo); } @@ -236,7 +236,7 @@ GNUNET_FS_file_information_create_from_data ( * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_reader ( +GNUNET_FS_file_information_create_from_reader( struct GNUNET_FS_Handle *h, void *client_info, uint64_t length, @@ -250,17 +250,17 @@ GNUNET_FS_file_information_create_from_reader ( struct GNUNET_FS_FileInformation *ret; if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) - { - GNUNET_break (0); - return NULL; - } - ret = GNUNET_new (struct GNUNET_FS_FileInformation); + { + GNUNET_break(0); + return NULL; + } + ret = GNUNET_new(struct GNUNET_FS_FileInformation); ret->h = h; ret->client_info = client_info; - ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); + ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); if (ret->meta == NULL) - ret->meta = GNUNET_CONTAINER_meta_data_create (); - ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); + ret->meta = GNUNET_CONTAINER_meta_data_create(); + ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup(keywords); ret->data.file.reader = reader; ret->data.file.reader_cls = reader_cls; ret->data.file.do_index = do_index; @@ -277,7 +277,7 @@ GNUNET_FS_file_information_create_from_reader ( * @return #GNUNET_YES if so, #GNUNET_NO if not */ int -GNUNET_FS_file_information_is_directory ( +GNUNET_FS_file_information_is_directory( const struct GNUNET_FS_FileInformation *ent) { return ent->is_directory; @@ -297,7 +297,7 @@ GNUNET_FS_file_information_is_directory ( * @return publish structure entry for the directory , NULL on error */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_empty_directory ( +GNUNET_FS_file_information_create_empty_directory( struct GNUNET_FS_Handle *h, void *client_info, const struct GNUNET_FS_Uri *keywords, @@ -307,15 +307,15 @@ GNUNET_FS_file_information_create_empty_directory ( { struct GNUNET_FS_FileInformation *ret; - ret = GNUNET_new (struct GNUNET_FS_FileInformation); + ret = GNUNET_new(struct GNUNET_FS_FileInformation); ret->h = h; ret->client_info = client_info; - ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); - ret->keywords = GNUNET_FS_uri_dup (keywords); + ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); + ret->keywords = GNUNET_FS_uri_dup(keywords); ret->bo = *bo; ret->is_directory = GNUNET_YES; if (filename != NULL) - ret->filename = GNUNET_strdup (filename); + ret->filename = GNUNET_strdup(filename); return ret; } @@ -332,15 +332,15 @@ GNUNET_FS_file_information_create_empty_directory ( * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, - struct GNUNET_FS_FileInformation *ent) +GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir, + struct GNUNET_FS_FileInformation *ent) { if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } ent->dir = dir; ent->next = dir->data.dir.entries; dir->data.dir.entries = ent; @@ -364,45 +364,45 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, * @param proc_cls closure for @a proc */ void -GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, - GNUNET_FS_FileInformationProcessor proc, - void *proc_cls) +GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, + GNUNET_FS_FileInformationProcessor proc, + void *proc_cls) { struct GNUNET_FS_FileInformation *pos; int no; no = GNUNET_NO; if (GNUNET_OK != - proc (proc_cls, - dir, - (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size - : dir->data.file.file_size, - dir->meta, - &dir->keywords, - &dir->bo, - (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, - &dir->client_info)) + proc(proc_cls, + dir, + (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size + : dir->data.file.file_size, + dir->meta, + &dir->keywords, + &dir->bo, + (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, + &dir->client_info)) return; if (dir->is_directory != GNUNET_YES) return; pos = dir->data.dir.entries; while (pos != NULL) - { - no = GNUNET_NO; - if (GNUNET_OK != - proc (proc_cls, - pos, - (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size - : pos->data.file.file_size, - pos->meta, - &pos->keywords, - &pos->bo, - (pos->is_directory == GNUNET_YES) ? &no - : &pos->data.file.do_index, - &pos->client_info)) - break; - pos = pos->next; - } + { + no = GNUNET_NO; + if (GNUNET_OK != + proc(proc_cls, + pos, + (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size + : pos->data.file.file_size, + pos->meta, + &pos->keywords, + &pos->bo, + (pos->is_directory == GNUNET_YES) ? &no + : &pos->data.file.do_index, + &pos->client_info)) + break; + pos = pos->next; + } } @@ -417,75 +417,75 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, * @param cleaner_cls closure for @a cleaner */ void -GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, - GNUNET_FS_FileInformationProcessor cleaner, - void *cleaner_cls) +GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, + GNUNET_FS_FileInformationProcessor cleaner, + void *cleaner_cls) { struct GNUNET_FS_FileInformation *pos; int no; no = GNUNET_NO; if (GNUNET_YES == fi->is_directory) - { - /* clean up directory */ - while (NULL != (pos = fi->data.dir.entries)) { - fi->data.dir.entries = pos->next; - GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); + /* clean up directory */ + while (NULL != (pos = fi->data.dir.entries)) + { + fi->data.dir.entries = pos->next; + GNUNET_FS_file_information_destroy(pos, cleaner, cleaner_cls); + } + /* clean up client-info */ + if (NULL != cleaner) + cleaner(cleaner_cls, + fi, + fi->data.dir.dir_size, + fi->meta, + &fi->keywords, + &fi->bo, + &no, + &fi->client_info); + GNUNET_free_non_null(fi->data.dir.dir_data); } - /* clean up client-info */ - if (NULL != cleaner) - cleaner (cleaner_cls, - fi, - fi->data.dir.dir_size, - fi->meta, - &fi->keywords, - &fi->bo, - &no, - &fi->client_info); - GNUNET_free_non_null (fi->data.dir.dir_data); - } else - { - /* call clean-up function of the reader */ - if (NULL != fi->data.file.reader) { - (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); - fi->data.file.reader = NULL; + /* call clean-up function of the reader */ + if (NULL != fi->data.file.reader) + { + (void)fi->data.file.reader(fi->data.file.reader_cls, 0, 0, NULL, NULL); + fi->data.file.reader = NULL; + } + /* clean up client-info */ + if (NULL != cleaner) + cleaner(cleaner_cls, + fi, + fi->data.file.file_size, + fi->meta, + &fi->keywords, + &fi->bo, + &fi->data.file.do_index, + &fi->client_info); } - /* clean up client-info */ - if (NULL != cleaner) - cleaner (cleaner_cls, - fi, - fi->data.file.file_size, - fi->meta, - &fi->keywords, - &fi->bo, - &fi->data.file.do_index, - &fi->client_info); - } - GNUNET_free_non_null (fi->filename); - GNUNET_free_non_null (fi->emsg); + GNUNET_free_non_null(fi->filename); + GNUNET_free_non_null(fi->emsg); if (NULL != fi->sks_uri) - GNUNET_FS_uri_destroy (fi->sks_uri); + GNUNET_FS_uri_destroy(fi->sks_uri); if (NULL != fi->chk_uri) - GNUNET_FS_uri_destroy (fi->chk_uri); + GNUNET_FS_uri_destroy(fi->chk_uri); /* clean up serialization */ - if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - fi->serialization); + if ((NULL != fi->serialization) && (0 != unlink(fi->serialization))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "unlink", + fi->serialization); if (NULL != fi->keywords) - GNUNET_FS_uri_destroy (fi->keywords); + GNUNET_FS_uri_destroy(fi->keywords); if (NULL != fi->meta) - GNUNET_CONTAINER_meta_data_destroy (fi->meta); - GNUNET_free_non_null (fi->serialization); + GNUNET_CONTAINER_meta_data_destroy(fi->meta); + GNUNET_free_non_null(fi->serialization); if (NULL != fi->te) - { - GNUNET_FS_tree_encoder_finish (fi->te, NULL); - fi->te = NULL; - } - GNUNET_free (fi); + { + GNUNET_FS_tree_encoder_finish(fi->te, NULL); + fi->te = NULL; + } + GNUNET_free(fi); } diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c index 0d5907a40..4f53f64a5 100644 --- a/src/fs/fs_getopt.c +++ b/src/fs/fs_getopt.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_getopt.c @@ -43,10 +43,10 @@ * @return #GNUNET_OK on success */ static int -getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, - void *scls, - const char *option, - const char *value) +getopt_set_keywords(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, + const char *option, + const char *value) { struct GNUNET_FS_Uri **uri = scls; struct GNUNET_FS_Uri *u = *uri; @@ -54,64 +54,64 @@ getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, size_t slen; if (NULL == u) - { - u = GNUNET_new (struct GNUNET_FS_Uri); - *uri = u; - u->type = GNUNET_FS_URI_KSK; - u->data.ksk.keywordCount = 0; - u->data.ksk.keywords = NULL; - } + { + u = GNUNET_new(struct GNUNET_FS_Uri); + *uri = u; + u->type = GNUNET_FS_URI_KSK; + u->data.ksk.keywordCount = 0; + u->data.ksk.keywords = NULL; + } else - { - GNUNET_assert (GNUNET_FS_URI_KSK == u->type); - } - slen = strlen (value); + { + GNUNET_assert(GNUNET_FS_URI_KSK == u->type); + } + slen = strlen(value); if (0 == slen) return GNUNET_SYSERR; /* cannot be empty */ if (value[0] == '+') - { - /* simply preserve the "mandatory" flag */ - if (slen < 2) - return GNUNET_SYSERR; /* empty keywords not allowed */ - if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) - { - /* remove the quotes, keep the '+' */ - val = GNUNET_malloc (slen - 1); - val[0] = '+'; - GNUNET_memcpy (&val[1], - &value[2], - slen - 3); - val[slen - 2] = '\0'; - } - else { - /* no quotes, just keep the '+' */ - val = GNUNET_strdup (value); + /* simply preserve the "mandatory" flag */ + if (slen < 2) + return GNUNET_SYSERR; /* empty keywords not allowed */ + if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) + { + /* remove the quotes, keep the '+' */ + val = GNUNET_malloc(slen - 1); + val[0] = '+'; + GNUNET_memcpy(&val[1], + &value[2], + slen - 3); + val[slen - 2] = '\0'; + } + else + { + /* no quotes, just keep the '+' */ + val = GNUNET_strdup(value); + } } - } else - { - if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) { - /* remove the quotes, add a space */ - val = GNUNET_malloc (slen); - val[0] = ' '; - GNUNET_memcpy (&val[1], - &value[1], - slen - 2); - val[slen - 1] = '\0'; + if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) + { + /* remove the quotes, add a space */ + val = GNUNET_malloc(slen); + val[0] = ' '; + GNUNET_memcpy(&val[1], + &value[1], + slen - 2); + val[slen - 1] = '\0'; + } + else + { + /* add a space to indicate "not mandatory" */ + val = GNUNET_malloc(slen + 2); + strcpy(val, " "); + strcat(val, value); + } } - else - { - /* add a space to indicate "not mandatory" */ - val = GNUNET_malloc (slen + 2); - strcpy (val, " "); - strcat (val, value); - } - } - GNUNET_array_append (u->data.ksk.keywords, - u->data.ksk.keywordCount, - val); + GNUNET_array_append(u->data.ksk.keywords, + u->data.ksk.keywordCount, + val); return GNUNET_OK; } @@ -126,11 +126,11 @@ getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, * @param[out] topKeywords set to the desired value */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_FS_GETOPT_KEYWORDS (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_FS_Uri **topKeywords) +GNUNET_FS_GETOPT_KEYWORDS(char shortName, + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_FS_Uri **topKeywords) { struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, @@ -139,7 +139,7 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName, .description = description, .require_argument = 1, .processor = &getopt_set_keywords, - .scls = (void *) topKeywords + .scls = (void *)topKeywords }; return clo; @@ -159,12 +159,13 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName, * @return #GNUNET_OK on success */ static int -getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, - void *scls, - const char *option, - const char *value) +getopt_set_metadata(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, + const char *option, + const char *value) { struct GNUNET_CONTAINER_MetaData **mm = scls; + #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR enum EXTRACTOR_MetaType type; const char *typename; @@ -175,66 +176,66 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, meta = *mm; if (meta == NULL) - { - meta = GNUNET_CONTAINER_meta_data_create (); - *mm = meta; - } + { + meta = GNUNET_CONTAINER_meta_data_create(); + *mm = meta; + } /* Use GNUNET_STRINGS_get_utf8_args() in main() to acquire utf-8-encoded * commandline arguments, so that the following line is not needed. */ /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/ - tmp = GNUNET_strdup (value); + tmp = GNUNET_strdup(value); #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR - type = EXTRACTOR_metatype_get_max (); + type = EXTRACTOR_metatype_get_max(); while (type > 0) - { - type--; - typename = EXTRACTOR_metatype_to_string (type); - typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); - if ((strlen (tmp) >= strlen (typename) + 1) && - (tmp[strlen (typename)] == ':') && - (0 == strncmp (typename, tmp, strlen (typename)))) { - GNUNET_CONTAINER_meta_data_insert (meta, "", type, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - &tmp[strlen (typename) + 1], - strlen (&tmp[strlen (typename) + 1]) + - 1); - GNUNET_free (tmp); - tmp = NULL; - break; + type--; + typename = EXTRACTOR_metatype_to_string(type); + typename_i18n = dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, typename); + if ((strlen(tmp) >= strlen(typename) + 1) && + (tmp[strlen(typename)] == ':') && + (0 == strncmp(typename, tmp, strlen(typename)))) + { + GNUNET_CONTAINER_meta_data_insert(meta, "", type, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + &tmp[strlen(typename) + 1], + strlen(&tmp[strlen(typename) + 1]) + + 1); + GNUNET_free(tmp); + tmp = NULL; + break; + } + if ((strlen(tmp) >= strlen(typename_i18n) + 1) && + (tmp[strlen(typename_i18n)] == ':') && + (0 == strncmp(typename_i18n, tmp, strlen(typename_i18n)))) + { + GNUNET_CONTAINER_meta_data_insert(meta, "", type, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + &tmp[strlen(typename_i18n) + 1], + strlen(&tmp + [strlen(typename_i18n) + 1]) + + 1); + GNUNET_free(tmp); + tmp = NULL; + break; + } } - if ((strlen (tmp) >= strlen (typename_i18n) + 1) && - (tmp[strlen (typename_i18n)] == ':') && - (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) - { - GNUNET_CONTAINER_meta_data_insert (meta, "", type, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - &tmp[strlen (typename_i18n) + 1], - strlen (&tmp - [strlen (typename_i18n) + 1]) + - 1); - GNUNET_free (tmp); - tmp = NULL; - break; - } - } #endif if (NULL != tmp) - { - GNUNET_CONTAINER_meta_data_insert (meta, "", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - tmp, strlen (tmp) + 1); - GNUNET_free (tmp); - printf (_ - ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), - value); - } + { + GNUNET_CONTAINER_meta_data_insert(meta, "", + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + tmp, strlen(tmp) + 1); + GNUNET_free(tmp); + printf(_ + ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), + value); + } return GNUNET_OK; } @@ -248,11 +249,11 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, * @param[out] metadata set to the desired value */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_FS_GETOPT_METADATA (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_CONTAINER_MetaData **meta) +GNUNET_FS_GETOPT_METADATA(char shortName, + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_CONTAINER_MetaData **meta) { struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, @@ -261,7 +262,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName, .description = description, .require_argument = 1, .processor = &getopt_set_metadata, - .scls = (void *) meta + .scls = (void *)meta }; return clo; diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c index 08a7be48e..c023d0ac6 100644 --- a/src/fs/fs_list_indexed.c +++ b/src/fs/fs_list_indexed.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_list_indexed.c @@ -34,9 +34,7 @@ /** * Context for #GNUNET_FS_get_indexed_files(). */ -struct GNUNET_FS_GetIndexedContext -{ - +struct GNUNET_FS_GetIndexedContext { /** * Connection to the FS service. */ @@ -72,15 +70,15 @@ struct GNUNET_FS_GetIndexedContext * @param msg message with indexing information */ static void -handle_index_info_end (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_index_info_end(void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_GetIndexedContext *gic = cls; - (void) gic->iterator (gic->iterator_cls, - NULL, - NULL); - GNUNET_FS_get_indexed_files_cancel (gic); + (void)gic->iterator(gic->iterator_cls, + NULL, + NULL); + GNUNET_FS_get_indexed_files_cancel(gic); } @@ -92,18 +90,18 @@ handle_index_info_end (void *cls, * @param iim message with indexing information */ static int -check_index_info (void *cls, - const struct IndexInfoMessage *iim) +check_index_info(void *cls, + const struct IndexInfoMessage *iim) { - uint16_t msize = ntohs (iim->header.size) - sizeof (*iim); + uint16_t msize = ntohs(iim->header.size) - sizeof(*iim); const char *filename; - filename = (const char *) &iim[1]; + filename = (const char *)&iim[1]; if (filename[msize - 1] != '\0') - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -116,21 +114,21 @@ check_index_info (void *cls, * @param iim message with indexing information */ static void -handle_index_info (void *cls, - const struct IndexInfoMessage *iim) +handle_index_info(void *cls, + const struct IndexInfoMessage *iim) { struct GNUNET_FS_GetIndexedContext *gic = cls; const char *filename; - filename = (const char *) &iim[1]; + filename = (const char *)&iim[1]; if (GNUNET_OK != - gic->iterator (gic->iterator_cls, - filename, - &iim->file_id)) - { - GNUNET_FS_get_indexed_files_cancel (gic); - return; - } + gic->iterator(gic->iterator_cls, + filename, + &iim->file_id)) + { + GNUNET_FS_get_indexed_files_cancel(gic); + return; + } } @@ -143,16 +141,16 @@ handle_index_info (void *cls, * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_FS_GetIndexedContext *gic = cls; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to receive response from `%s' service.\n"), - "fs"); - (void) gic->iterator (gic->iterator_cls, NULL, NULL); - GNUNET_FS_get_indexed_files_cancel (gic); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to receive response from `%s' service.\n"), + "fs"); + (void)gic->iterator(gic->iterator_cls, NULL, NULL); + GNUNET_FS_get_indexed_files_cancel(gic); } @@ -165,45 +163,45 @@ mq_error_handler (void *cls, * @return NULL on error ('iter' is not called) */ struct GNUNET_FS_GetIndexedContext * -GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, - GNUNET_FS_IndexedFileProcessor iterator, - void *iterator_cls) +GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, + GNUNET_FS_IndexedFileProcessor iterator, + void *iterator_cls) { struct GNUNET_FS_GetIndexedContext *gic - = GNUNET_new (struct GNUNET_FS_GetIndexedContext); + = GNUNET_new(struct GNUNET_FS_GetIndexedContext); struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (index_info_end, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, - struct GNUNET_MessageHeader, - gic), - GNUNET_MQ_hd_var_size (index_info, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, - struct IndexInfoMessage, - gic), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(index_info_end, + GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, + struct GNUNET_MessageHeader, + gic), + GNUNET_MQ_hd_var_size(index_info, + GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, + struct IndexInfoMessage, + gic), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; - gic->mq = GNUNET_CLIENT_connect (h->cfg, - "fs", - handlers, - &mq_error_handler, - h); + gic->mq = GNUNET_CLIENT_connect(h->cfg, + "fs", + handlers, + &mq_error_handler, + h); if (NULL == gic->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to not connect to `%s' service.\n"), - "fs"); - GNUNET_free (gic); - return NULL; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to not connect to `%s' service.\n"), + "fs"); + GNUNET_free(gic); + return NULL; + } gic->iterator = iterator; gic->iterator_cls = iterator_cls; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); - GNUNET_MQ_send (gic->mq, - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); + GNUNET_MQ_send(gic->mq, + env); return gic; } @@ -214,10 +212,10 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, * @param gic operation to cancel */ void -GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic) +GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic) { - GNUNET_MQ_destroy (gic->mq); - GNUNET_free (gic); + GNUNET_MQ_destroy(gic->mq); + GNUNET_free(gic); } diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index 918c637a0..79f082626 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_misc.c * @brief misc. functions related to file-sharing in general @@ -35,74 +35,74 @@ * @return NULL if meta data is useless for suggesting a filename */ char * -GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData - *md) +GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_CONTAINER_MetaData + *md) { static const char *mimeMap[][2] = { - {"application/bz2", ".bz2"}, - {"application/gnunet-directory", ".gnd"}, - {"application/java", ".class"}, - {"application/msword", ".doc"}, - {"application/nar", ".nar"}, - {"application/narinfo", ".narinfo"}, - {"application/ogg", ".ogg"}, - {"application/pdf", ".pdf"}, - {"application/pgp-keys", ".key"}, - {"application/pgp-signature", ".pgp"}, - {"application/postscript", ".ps"}, - {"application/rar", ".rar"}, - {"application/rtf", ".rtf"}, - {"application/xml", ".xml"}, - {"application/x-debian-package", ".deb"}, - {"application/x-dvi", ".dvi"}, - {"application/x-flac", ".flac"}, - {"application/x-gzip", ".gz"}, - {"application/x-java-archive", ".jar"}, - {"application/x-java-vm", ".class"}, - {"application/x-python-code", ".pyc"}, - {"application/x-redhat-package-manager", ".rpm"}, - {"application/x-rpm", ".rpm"}, - {"application/x-tar", ".tar"}, - {"application/x-tex-pk", ".pk"}, - {"application/x-texinfo", ".texinfo"}, - {"application/x-xcf", ".xcf"}, - {"application/x-xfig", ".xfig"}, - {"application/zip", ".zip"}, + { "application/bz2", ".bz2" }, + { "application/gnunet-directory", ".gnd" }, + { "application/java", ".class" }, + { "application/msword", ".doc" }, + { "application/nar", ".nar" }, + { "application/narinfo", ".narinfo" }, + { "application/ogg", ".ogg" }, + { "application/pdf", ".pdf" }, + { "application/pgp-keys", ".key" }, + { "application/pgp-signature", ".pgp" }, + { "application/postscript", ".ps" }, + { "application/rar", ".rar" }, + { "application/rtf", ".rtf" }, + { "application/xml", ".xml" }, + { "application/x-debian-package", ".deb" }, + { "application/x-dvi", ".dvi" }, + { "application/x-flac", ".flac" }, + { "application/x-gzip", ".gz" }, + { "application/x-java-archive", ".jar" }, + { "application/x-java-vm", ".class" }, + { "application/x-python-code", ".pyc" }, + { "application/x-redhat-package-manager", ".rpm" }, + { "application/x-rpm", ".rpm" }, + { "application/x-tar", ".tar" }, + { "application/x-tex-pk", ".pk" }, + { "application/x-texinfo", ".texinfo" }, + { "application/x-xcf", ".xcf" }, + { "application/x-xfig", ".xfig" }, + { "application/zip", ".zip" }, - {"audio/midi", ".midi"}, - {"audio/mpeg", ".mp3"}, - {"audio/real", ".rm"}, - {"audio/x-wav", ".wav"}, + { "audio/midi", ".midi" }, + { "audio/mpeg", ".mp3" }, + { "audio/real", ".rm" }, + { "audio/x-wav", ".wav" }, - {"image/gif", ".gif"}, - {"image/jpeg", ".jpg"}, - {"image/pcx", ".pcx"}, - {"image/png", ".png"}, - {"image/tiff", ".tiff"}, - {"image/x-ms-bmp", ".bmp"}, - {"image/x-xpixmap", ".xpm"}, + { "image/gif", ".gif" }, + { "image/jpeg", ".jpg" }, + { "image/pcx", ".pcx" }, + { "image/png", ".png" }, + { "image/tiff", ".tiff" }, + { "image/x-ms-bmp", ".bmp" }, + { "image/x-xpixmap", ".xpm" }, - {"text/css", ".css"}, - {"text/html", ".html"}, - {"text/plain", ".txt"}, - {"text/rtf", ".rtf"}, - {"text/x-c++hdr", ".h++"}, - {"text/x-c++src", ".c++"}, - {"text/x-chdr", ".h"}, - {"text/x-csrc", ".c"}, - {"text/x-java", ".java"}, - {"text/x-moc", ".moc"}, - {"text/x-pascal", ".pas"}, - {"text/x-perl", ".pl"}, - {"text/x-python", ".py"}, - {"text/x-tex", ".tex"}, + { "text/css", ".css" }, + { "text/html", ".html" }, + { "text/plain", ".txt" }, + { "text/rtf", ".rtf" }, + { "text/x-c++hdr", ".h++" }, + { "text/x-c++src", ".c++" }, + { "text/x-chdr", ".h" }, + { "text/x-csrc", ".c" }, + { "text/x-java", ".java" }, + { "text/x-moc", ".moc" }, + { "text/x-pascal", ".pas" }, + { "text/x-perl", ".pl" }, + { "text/x-python", ".py" }, + { "text/x-tex", ".tex" }, - {"video/avi", ".avi"}, - {"video/mpeg", ".mpeg"}, - {"video/quicktime", ".qt"}, - {"video/real", ".rm"}, - {"video/x-msvideo", ".avi"}, - {NULL, NULL}, + { "video/avi", ".avi" }, + { "video/mpeg", ".mpeg" }, + { "video/quicktime", ".qt" }, + { "video/real", ".rm" }, + { "video/x-msvideo", ".avi" }, + { NULL, NULL }, }; char *ret; unsigned int i; @@ -111,52 +111,52 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData const char *ext; ret = - GNUNET_CONTAINER_meta_data_get_by_type (md, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + GNUNET_CONTAINER_meta_data_get_by_type(md, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); if (ret != NULL) return ret; ext = NULL; mime = - GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); + GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); if (mime != NULL) - { - i = 0; - while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0]))) - i++; - if (mimeMap[i][1] == NULL) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - _("Did not find mime type `%s' in extension list.\n"), mime); - else - ext = mimeMap[i][1]; - GNUNET_free (mime); - } + { + i = 0; + while ((mimeMap[i][0] != NULL) && (0 != strcmp(mime, mimeMap[i][0]))) + i++; + if (mimeMap[i][1] == NULL) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + _("Did not find mime type `%s' in extension list.\n"), mime); + else + ext = mimeMap[i][1]; + GNUNET_free(mime); + } base = - GNUNET_CONTAINER_meta_data_get_first_by_types (md, - EXTRACTOR_METATYPE_TITLE, - EXTRACTOR_METATYPE_BOOK_TITLE, - EXTRACTOR_METATYPE_ORIGINAL_TITLE, - EXTRACTOR_METATYPE_PACKAGE_NAME, - EXTRACTOR_METATYPE_URL, - EXTRACTOR_METATYPE_URI, - EXTRACTOR_METATYPE_DESCRIPTION, - EXTRACTOR_METATYPE_ISRC, - EXTRACTOR_METATYPE_JOURNAL_NAME, - EXTRACTOR_METATYPE_AUTHOR_NAME, - EXTRACTOR_METATYPE_SUBJECT, - EXTRACTOR_METATYPE_ALBUM, - EXTRACTOR_METATYPE_ARTIST, - EXTRACTOR_METATYPE_KEYWORDS, - EXTRACTOR_METATYPE_COMMENT, - EXTRACTOR_METATYPE_UNKNOWN, - -1); + GNUNET_CONTAINER_meta_data_get_first_by_types(md, + EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METATYPE_BOOK_TITLE, + EXTRACTOR_METATYPE_ORIGINAL_TITLE, + EXTRACTOR_METATYPE_PACKAGE_NAME, + EXTRACTOR_METATYPE_URL, + EXTRACTOR_METATYPE_URI, + EXTRACTOR_METATYPE_DESCRIPTION, + EXTRACTOR_METATYPE_ISRC, + EXTRACTOR_METATYPE_JOURNAL_NAME, + EXTRACTOR_METATYPE_AUTHOR_NAME, + EXTRACTOR_METATYPE_SUBJECT, + EXTRACTOR_METATYPE_ALBUM, + EXTRACTOR_METATYPE_ARTIST, + EXTRACTOR_METATYPE_KEYWORDS, + EXTRACTOR_METATYPE_COMMENT, + EXTRACTOR_METATYPE_UNKNOWN, + -1); if ((base == NULL) && (ext == NULL)) return NULL; if (base == NULL) - return GNUNET_strdup (ext); + return GNUNET_strdup(ext); if (ext == NULL) return base; - GNUNET_asprintf (&ret, "%s%s", base, ext); - GNUNET_free (base); + GNUNET_asprintf(&ret, "%s%s", base, ext); + GNUNET_free(base); return ret; } diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 11a137a09..b740eb2ba 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_namespace.c @@ -37,8 +37,7 @@ * Information about an (updateable) node in the * namespace. */ -struct NamespaceUpdateNode -{ +struct NamespaceUpdateNode { /** * Identifier for this node. */ @@ -75,9 +74,7 @@ struct NamespaceUpdateNode /** * Handle to update information for a namespace. */ -struct GNUNET_FS_UpdateInformationGraph -{ - +struct GNUNET_FS_UpdateInformationGraph { /** * Handle to the FS service context. */ @@ -125,7 +122,7 @@ struct GNUNET_FS_UpdateInformationGraph * @return NULL on error, otherwise the name of the directory */ static char * -get_update_information_directory ( +get_update_information_directory( struct GNUNET_FS_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) { @@ -136,20 +133,20 @@ get_update_information_directory ( struct GNUNET_CRYPTO_HashAsciiEncoded enc; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); - return NULL; - } - GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, &enc); - GNUNET_asprintf (&ret, - "%s%s%s", - dn, - DIR_SEPARATOR_STR, - (const char *) enc.encoding); - GNUNET_free (dn); + GNUNET_CONFIGURATION_get_value_filename(h->cfg, "FS", "UPDATE_DIR", &dn)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); + return NULL; + } + GNUNET_CRYPTO_ecdsa_key_get_public(ns, &pub); + GNUNET_CRYPTO_hash(&pub, sizeof(pub), &hc); + GNUNET_CRYPTO_hash_to_enc(&hc, &enc); + GNUNET_asprintf(&ret, + "%s%s%s", + dn, + DIR_SEPARATOR_STR, + (const char *)enc.encoding); + GNUNET_free(dn); return ret; } @@ -160,24 +157,24 @@ get_update_information_directory ( * @param uig data structure to free */ static void -free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) +free_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) { unsigned int i; struct NamespaceUpdateNode *nsn; for (i = 0; i < uig->update_node_count; i++) - { - nsn = uig->update_nodes[i]; - GNUNET_CONTAINER_meta_data_destroy (nsn->md); - GNUNET_FS_uri_destroy (nsn->uri); - GNUNET_free (nsn->id); - GNUNET_free (nsn->update); - GNUNET_free (nsn); - } - GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); + { + nsn = uig->update_nodes[i]; + GNUNET_CONTAINER_meta_data_destroy(nsn->md); + GNUNET_FS_uri_destroy(nsn->uri); + GNUNET_free(nsn->id); + GNUNET_free(nsn->update); + GNUNET_free(nsn); + } + GNUNET_array_grow(uig->update_nodes, uig->update_node_count, 0); if (NULL != uig->update_map) - GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); - GNUNET_free (uig); + GNUNET_CONTAINER_multihashmap_destroy(uig->update_map); + GNUNET_free(uig); } @@ -187,7 +184,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) * @param uig update information graph to dump */ static void -write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) +write_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) { char *fn; struct GNUNET_BIO_WriteHandle *wh; @@ -195,40 +192,40 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) struct NamespaceUpdateNode *n; char *uris; - fn = get_update_information_directory (uig->h, &uig->ns); - wh = GNUNET_BIO_write_open (fn); + fn = get_update_information_directory(uig->h, &uig->ns); + wh = GNUNET_BIO_write_open(fn); if (NULL == wh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to open `%s' for writing: %s\n"), - fn, - strerror (errno)); - GNUNET_free (fn); - return; - } - if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to open `%s' for writing: %s\n"), + fn, + strerror(errno)); + GNUNET_free(fn); + return; + } + if (GNUNET_OK != GNUNET_BIO_write_int32(wh, uig->update_node_count)) goto END; for (i = 0; i < uig->update_node_count; i++) - { - n = uig->update_nodes[i]; - uris = GNUNET_FS_uri_to_string (n->uri); - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) || - (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) { - GNUNET_free (uris); - break; + n = uig->update_nodes[i]; + uris = GNUNET_FS_uri_to_string(n->uri); + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, n->id)) || + (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, n->md)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, n->update)) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, uris))) + { + GNUNET_free(uris); + break; + } + GNUNET_free(uris); } - GNUNET_free (uris); - } END: - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to write `%s': %s\n"), - fn, - strerror (errno)); - GNUNET_free (fn); + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to write `%s': %s\n"), + fn, + strerror(errno)); + GNUNET_free(fn); } @@ -240,8 +237,8 @@ END: * @return update graph, never NULL */ static struct GNUNET_FS_UpdateInformationGraph * -read_update_information_graph (struct GNUNET_FS_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) +read_update_information_graph(struct GNUNET_FS_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) { struct GNUNET_FS_UpdateInformationGraph *uig; char *fn; @@ -252,79 +249,79 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, uint32_t count; char *emsg; - uig = GNUNET_new (struct GNUNET_FS_UpdateInformationGraph); + uig = GNUNET_new(struct GNUNET_FS_UpdateInformationGraph); uig->h = h; uig->ns = *ns; - fn = get_update_information_directory (h, ns); - if (GNUNET_YES != GNUNET_DISK_file_test (fn)) - { - GNUNET_free (fn); - return uig; - } - rh = GNUNET_BIO_read_open (fn); + fn = get_update_information_directory(h, ns); + if (GNUNET_YES != GNUNET_DISK_file_test(fn)) + { + GNUNET_free(fn); + return uig; + } + rh = GNUNET_BIO_read_open(fn); if (NULL == rh) - { - GNUNET_free (fn); - return uig; - } - if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count)) - { - GNUNET_break (0); - goto END; - } + { + GNUNET_free(fn); + return uig; + } + if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &count)) + { + GNUNET_break(0); + goto END; + } if (count > 1024 * 1024) - { - GNUNET_break (0); - goto END; - } + { + GNUNET_break(0); + goto END; + } if (0 == count) goto END; uig->update_nodes = - GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *)); + GNUNET_malloc(count * sizeof(struct NamespaceUpdateNode *)); for (i = 0; i < count; i++) - { - n = GNUNET_new (struct NamespaceUpdateNode); - if ((GNUNET_OK != - GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || - (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || - (GNUNET_OK != - GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) { - GNUNET_break (0); - GNUNET_free_non_null (n->id); - GNUNET_free_non_null (n->update); - if (n->md != NULL) - GNUNET_CONTAINER_meta_data_destroy (n->md); - GNUNET_free (n); - break; - } - n->uri = GNUNET_FS_uri_parse (uris, &emsg); - GNUNET_free (uris); - if (n->uri == NULL) - { - GNUNET_break (0); - GNUNET_free (emsg); - GNUNET_free (n->id); - GNUNET_free_non_null (n->update); - GNUNET_CONTAINER_meta_data_destroy (n->md); - GNUNET_free (n); - break; + n = GNUNET_new(struct NamespaceUpdateNode); + if ((GNUNET_OK != + GNUNET_BIO_read_string(rh, "identifier", &n->id, 1024)) || + (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "meta", &n->md)) || + (GNUNET_OK != + GNUNET_BIO_read_string(rh, "update-id", &n->update, 1024)) || + (GNUNET_OK != GNUNET_BIO_read_string(rh, "uri", &uris, 1024 * 2))) + { + GNUNET_break(0); + GNUNET_free_non_null(n->id); + GNUNET_free_non_null(n->update); + if (n->md != NULL) + GNUNET_CONTAINER_meta_data_destroy(n->md); + GNUNET_free(n); + break; + } + n->uri = GNUNET_FS_uri_parse(uris, &emsg); + GNUNET_free(uris); + if (n->uri == NULL) + { + GNUNET_break(0); + GNUNET_free(emsg); + GNUNET_free(n->id); + GNUNET_free_non_null(n->update); + GNUNET_CONTAINER_meta_data_destroy(n->md); + GNUNET_free(n); + break; + } + uig->update_nodes[i] = n; } - uig->update_nodes[i] = n; - } uig->update_node_count = i; END: - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to read `%s': %s\n"), - fn, - emsg); - GNUNET_free (emsg); - } - GNUNET_free (fn); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to read `%s': %s\n"), + fn, + emsg); + GNUNET_free(emsg); + } + GNUNET_free(fn); return uig; } @@ -332,9 +329,7 @@ END: /** * Context for the SKS publication. */ -struct GNUNET_FS_PublishSksContext -{ - +struct GNUNET_FS_PublishSksContext { /** * URI of the new entry in the namespace. */ @@ -386,33 +381,33 @@ struct GNUNET_FS_PublishSksContext * @param msg error message (or NULL) */ static void -sks_publish_cont (void *cls, const char *msg) +sks_publish_cont(void *cls, const char *msg) { struct GNUNET_FS_PublishSksContext *psc = cls; struct GNUNET_FS_UpdateInformationGraph *uig; psc->uc = NULL; if (NULL != msg) - { - if (NULL != psc->cont) - psc->cont (psc->cont_cls, NULL, msg); - GNUNET_FS_publish_sks_cancel (psc); - return; - } + { + if (NULL != psc->cont) + psc->cont(psc->cont_cls, NULL, msg); + GNUNET_FS_publish_sks_cancel(psc); + return; + } if (NULL != psc->nsn) - { - /* FIXME: this can be done much more - * efficiently by simply appending to the - * file and overwriting the 4-byte header */ - uig = read_update_information_graph (psc->h, &psc->ns); - GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); - psc->nsn = NULL; - write_update_information_graph (uig); - free_update_information_graph (uig); - } + { + /* FIXME: this can be done much more + * efficiently by simply appending to the + * file and overwriting the 4-byte header */ + uig = read_update_information_graph(psc->h, &psc->ns); + GNUNET_array_append(uig->update_nodes, uig->update_node_count, psc->nsn); + psc->nsn = NULL; + write_update_information_graph(uig); + free_update_information_graph(uig); + } if (NULL != psc->cont) - psc->cont (psc->cont_cls, psc->uri, NULL); - GNUNET_FS_publish_sks_cancel (psc); + psc->cont(psc->cont_cls, psc->uri, NULL); + GNUNET_FS_publish_sks_cancel(psc); } @@ -432,59 +427,59 @@ sks_publish_cont (void *cls, const char *msg) * @return NULL on error ('cont' will still be called) */ struct GNUNET_FS_PublishSksContext * -GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const char *identifier, - const char *update, - const struct GNUNET_CONTAINER_MetaData *meta, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_FS_BlockOptions *bo, - enum GNUNET_FS_PublishOptions options, - GNUNET_FS_PublishContinuation cont, - void *cont_cls) +GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, + const char *identifier, + const char *update, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_PublishContinuation cont, + void *cont_cls) { struct GNUNET_FS_PublishSksContext *psc; struct GNUNET_FS_Uri *sks_uri; - sks_uri = GNUNET_new (struct GNUNET_FS_Uri); + sks_uri = GNUNET_new(struct GNUNET_FS_Uri); sks_uri->type = GNUNET_FS_URI_SKS; - sks_uri->data.sks.identifier = GNUNET_strdup (identifier); - GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); + sks_uri->data.sks.identifier = GNUNET_strdup(identifier); + GNUNET_CRYPTO_ecdsa_key_get_public(ns, &sks_uri->data.sks.ns); - psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); + psc = GNUNET_new(struct GNUNET_FS_PublishSksContext); psc->h = h; psc->uri = sks_uri; psc->cont = cont; psc->cont_cls = cont_cls; psc->ns = *ns; if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) - { - psc->dsh = GNUNET_DATASTORE_connect (h->cfg); - if (NULL == psc->dsh) { - sks_publish_cont (psc, _ ("Failed to connect to datastore.")); - return NULL; + psc->dsh = GNUNET_DATASTORE_connect(h->cfg); + if (NULL == psc->dsh) + { + sks_publish_cont(psc, _("Failed to connect to datastore.")); + return NULL; + } } - } if (NULL != update) - { - psc->nsn = GNUNET_new (struct NamespaceUpdateNode); - psc->nsn->id = GNUNET_strdup (identifier); - psc->nsn->update = GNUNET_strdup (update); - psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); - psc->nsn->uri = GNUNET_FS_uri_dup (uri); - } - psc->uc = GNUNET_FS_publish_ublock_ (h, - psc->dsh, - identifier, - update, - ns, - meta, - uri, - bo, - options, - &sks_publish_cont, - psc); + { + psc->nsn = GNUNET_new(struct NamespaceUpdateNode); + psc->nsn->id = GNUNET_strdup(identifier); + psc->nsn->update = GNUNET_strdup(update); + psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate(meta); + psc->nsn->uri = GNUNET_FS_uri_dup(uri); + } + psc->uc = GNUNET_FS_publish_ublock_(h, + psc->dsh, + identifier, + update, + ns, + meta, + uri, + bo, + options, + &sks_publish_cont, + psc); return psc; } @@ -495,36 +490,35 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, * @param psc context of the operation to abort. */ void -GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc) +GNUNET_FS_publish_sks_cancel(struct GNUNET_FS_PublishSksContext *psc) { if (NULL != psc->uc) - { - GNUNET_FS_publish_ublock_cancel_ (psc->uc); - psc->uc = NULL; - } + { + GNUNET_FS_publish_ublock_cancel_(psc->uc); + psc->uc = NULL; + } if (NULL != psc->dsh) - { - GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); - psc->dsh = NULL; - } - GNUNET_FS_uri_destroy (psc->uri); + { + GNUNET_DATASTORE_disconnect(psc->dsh, GNUNET_NO); + psc->dsh = NULL; + } + GNUNET_FS_uri_destroy(psc->uri); if (NULL != psc->nsn) - { - GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); - GNUNET_FS_uri_destroy (psc->nsn->uri); - GNUNET_free (psc->nsn->id); - GNUNET_free (psc->nsn->update); - GNUNET_free (psc->nsn); - } - GNUNET_free (psc); + { + GNUNET_CONTAINER_meta_data_destroy(psc->nsn->md); + GNUNET_FS_uri_destroy(psc->nsn->uri); + GNUNET_free(psc->nsn->id); + GNUNET_free(psc->nsn->update); + GNUNET_free(psc->nsn); + } + GNUNET_free(psc); } /** * Closure for 'process_update_node'. */ -struct ProcessUpdateClosure -{ +struct ProcessUpdateClosure { /** * Function to call for each node. */ @@ -548,12 +542,12 @@ struct ProcessUpdateClosure * GNUNET_NO if not. */ static int -process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) +process_update_node(void *cls, const struct GNUNET_HashCode *key, void *value) { struct ProcessUpdateClosure *pc = cls; struct NamespaceUpdateNode *nsn = value; - pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); + pc->ip(pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); return GNUNET_YES; } @@ -561,8 +555,7 @@ process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) /** * Closure for 'find_trees'. */ -struct FindTreeClosure -{ +struct FindTreeClosure { /** * UIG we are operating on. */ @@ -611,38 +604,38 @@ struct FindTreeClosure * GNUNET_NO if not. */ static int -find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) +find_trees(void *cls, const struct GNUNET_HashCode *key, void *value) { struct FindTreeClosure *fc = cls; struct NamespaceUpdateNode *nsn = value; struct GNUNET_HashCode hc; if (nsn->nug == fc->nug) - { - if (UINT_MAX == nsn->tree_id) - return GNUNET_YES; /* circular */ - GNUNET_assert (nsn->tree_id < fc->tree_array_size); - if (fc->tree_array[nsn->tree_id] != nsn) - return GNUNET_YES; /* part of "another" (directed) TREE, - * and not root of it, end trace */ - if (nsn->tree_id == fc->id) - return GNUNET_YES; /* that's our own root (can this be?) */ - /* merge existing TREE, we have a root for both */ - fc->tree_array[nsn->tree_id] = NULL; - if (UINT_MAX == fc->id) - fc->id = nsn->tree_id; /* take over ID */ - } + { + if (UINT_MAX == nsn->tree_id) + return GNUNET_YES; /* circular */ + GNUNET_assert(nsn->tree_id < fc->tree_array_size); + if (fc->tree_array[nsn->tree_id] != nsn) + return GNUNET_YES; /* part of "another" (directed) TREE, + * and not root of it, end trace */ + if (nsn->tree_id == fc->id) + return GNUNET_YES; /* that's our own root (can this be?) */ + /* merge existing TREE, we have a root for both */ + fc->tree_array[nsn->tree_id] = NULL; + if (UINT_MAX == fc->id) + fc->id = nsn->tree_id; /* take over ID */ + } else - { - nsn->nug = fc->nug; - nsn->tree_id = UINT_MAX; /* mark as undef */ - /* trace */ - GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); - GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, - &hc, - &find_trees, - fc); - } + { + nsn->nug = fc->nug; + nsn->tree_id = UINT_MAX; /* mark as undef */ + /* trace */ + GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); + GNUNET_CONTAINER_multihashmap_get_multiple(fc->uig->update_map, + &hc, + &find_trees, + fc); + } return GNUNET_YES; } @@ -671,7 +664,7 @@ find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) * @param ip_cls closure for ip */ void -GNUNET_FS_namespace_list_updateable ( +GNUNET_FS_namespace_list_updateable( struct GNUNET_FS_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, const char *next_id, @@ -686,125 +679,125 @@ GNUNET_FS_namespace_list_updateable ( struct FindTreeClosure fc; struct GNUNET_FS_UpdateInformationGraph *uig; - uig = read_update_information_graph (h, ns); + uig = read_update_information_graph(h, ns); if (NULL == uig->update_nodes) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No updateable nodes found for ID `%s'\n", - next_id); - free_update_information_graph (uig); - return; /* no nodes */ - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No updateable nodes found for ID `%s'\n", + next_id); + free_update_information_graph(uig); + return; /* no nodes */ + } uig->update_map = - GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, - GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create(2 + 3 * uig->update_node_count / 4, + GNUNET_NO); for (i = 0; i < uig->update_node_count; i++) - { - nsn = uig->update_nodes[i]; - GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); - GNUNET_CONTAINER_multihashmap_put ( - uig->update_map, - &hc, - nsn, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - } + { + nsn = uig->update_nodes[i]; + GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); + GNUNET_CONTAINER_multihashmap_put( + uig->update_map, + &hc, + nsn, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + } if (NULL != next_id) - { - GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); - pc.ip = ip; - pc.ip_cls = ip_cls; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, - &hc, - &process_update_node, - &pc); - free_update_information_graph (uig); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Calculating TREEs to find roots of update trees\n"); + { + GNUNET_CRYPTO_hash(next_id, strlen(next_id), &hc); + pc.ip = ip; + pc.ip_cls = ip_cls; + GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, + &hc, + &process_update_node, + &pc); + free_update_information_graph(uig); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Calculating TREEs to find roots of update trees\n"); /* Find heads of TREEs in update graph */ nug = ++uig->nug_gen; fc.tree_array = NULL; fc.tree_array_size = 0; for (i = 0; i < uig->update_node_count; i++) - { - nsn = uig->update_nodes[i]; - if (nsn->nug == nug) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TREE of node `%s' is %u\n", - nsn->id, - nsn->nug); - continue; /* already placed in TREE */ - } - GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); - nsn->nug = nug; - nsn->tree_id = UINT_MAX; - fc.id = UINT_MAX; - fc.nug = nug; - fc.uig = uig; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, - &hc, - &find_trees, - &fc); - if (UINT_MAX == fc.id) { - /* start new TREE */ - for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) - { - if (NULL == fc.tree_array[fc.id]) + nsn = uig->update_nodes[i]; + if (nsn->nug == nug) { - fc.tree_array[fc.id] = nsn; - nsn->tree_id = fc.id; - break; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "TREE of node `%s' is %u\n", + nsn->id, + nsn->nug); + continue; /* already placed in TREE */ } - } - if (fc.id == fc.tree_array_size) - { - GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn); - nsn->tree_id = fc.id; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting new TREE %u with node `%s'\n", - nsn->tree_id, - nsn->id); - /* put all nodes with same identifier into this TREE */ - GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); - fc.id = nsn->tree_id; + GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); + nsn->nug = nug; + nsn->tree_id = UINT_MAX; + fc.id = UINT_MAX; fc.nug = nug; fc.uig = uig; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, - &hc, - &find_trees, - &fc); - } - else - { - /* make head of TREE "id" */ - fc.tree_array[fc.id] = nsn; - nsn->tree_id = fc.id; + GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, + &hc, + &find_trees, + &fc); + if (UINT_MAX == fc.id) + { + /* start new TREE */ + for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) + { + if (NULL == fc.tree_array[fc.id]) + { + fc.tree_array[fc.id] = nsn; + nsn->tree_id = fc.id; + break; + } + } + if (fc.id == fc.tree_array_size) + { + GNUNET_array_append(fc.tree_array, fc.tree_array_size, nsn); + nsn->tree_id = fc.id; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting new TREE %u with node `%s'\n", + nsn->tree_id, + nsn->id); + /* put all nodes with same identifier into this TREE */ + GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); + fc.id = nsn->tree_id; + fc.nug = nug; + fc.uig = uig; + GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, + &hc, + &find_trees, + &fc); + } + else + { + /* make head of TREE "id" */ + fc.tree_array[fc.id] = nsn; + nsn->tree_id = fc.id; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "TREE of node `%s' is %u\n", + nsn->id, + fc.id); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TREE of node `%s' is %u\n", - nsn->id, - fc.id); - } for (i = 0; i < fc.tree_array_size; i++) - { - nsn = fc.tree_array[i]; - if (NULL != nsn) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Root of TREE %u is node `%s'\n", - i, - nsn->id); - ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); + nsn = fc.tree_array[i]; + if (NULL != nsn) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Root of TREE %u is node `%s'\n", + i, + nsn->id); + ip(ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); + } } - } - GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); - free_update_information_graph (uig); + GNUNET_array_grow(fc.tree_array, fc.tree_array_size, 0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); + free_update_information_graph(uig); } diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 71ab1122c..b599bb06e 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_publish.c * @brief publish a file or directory in GNUnet @@ -44,10 +44,10 @@ * @return value returned from callback */ void * -GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_PublishContext *pc, - const struct GNUNET_FS_FileInformation *p, - uint64_t offset) +GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_PublishContext *pc, + const struct GNUNET_FS_FileInformation *p, + uint64_t offset) { pi->value.publish.pc = pc; pi->value.publish.fi = p; @@ -55,16 +55,16 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; pi->value.publish.filename = p->filename; pi->value.publish.size = - (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; + (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; pi->value.publish.eta = - GNUNET_TIME_calculate_eta (p->start_time, offset, - pi->value.publish.size); + GNUNET_TIME_calculate_eta(p->start_time, offset, + pi->value.publish.size); pi->value.publish.completed = offset; pi->value.publish.duration = - GNUNET_TIME_absolute_get_duration (p->start_time); + GNUNET_TIME_absolute_get_duration(p->start_time); pi->value.publish.anonymity = p->bo.anonymity_level; pi->fsh = pc->h; - return pc->h->upcb (pc->h->upcb_cls, pi); + return pc->h->upcb(pc->h->upcb_cls, pi); } @@ -74,31 +74,31 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @param pc struct to clean up */ static void -publish_cleanup (struct GNUNET_FS_PublishContext *pc) +publish_cleanup(struct GNUNET_FS_PublishContext *pc) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up publish context (done!)\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up publish context (done!)\n"); if (NULL != pc->fhc) - { - GNUNET_CRYPTO_hash_file_cancel (pc->fhc); - pc->fhc = NULL; - } - GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); - GNUNET_free_non_null (pc->nid); - GNUNET_free_non_null (pc->nuid); - GNUNET_free_non_null (pc->serialization); + { + GNUNET_CRYPTO_hash_file_cancel(pc->fhc); + pc->fhc = NULL; + } + GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); + GNUNET_free_non_null(pc->nid); + GNUNET_free_non_null(pc->nuid); + GNUNET_free_non_null(pc->serialization); if (NULL != pc->dsh) - { - GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); - pc->dsh = NULL; - } + { + GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); + pc->dsh = NULL; + } if (NULL != pc->mq) - { - GNUNET_MQ_destroy (pc->mq); - pc->mq = NULL; - } - GNUNET_assert (NULL == pc->upload_task); - GNUNET_free (pc); + { + GNUNET_MQ_destroy(pc->mq); + pc->mq = NULL; + } + GNUNET_assert(NULL == pc->upload_task); + GNUNET_free(pc); } @@ -112,42 +112,42 @@ publish_cleanup (struct GNUNET_FS_PublishContext *pc) * @param msg error message (or NULL) */ static void -ds_put_cont (void *cls, - int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +ds_put_cont(void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; pc->qre = NULL; if (GNUNET_SYSERR == success) - { - GNUNET_asprintf (&pc->fi_pos->emsg, - _("Publishing failed: %s"), - msg); - pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; - pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; - pi.value.publish.specifics.error.message = pc->fi_pos->emsg; - pc->fi_pos->client_info = - GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0); - if ((GNUNET_YES != pc->fi_pos->is_directory) && - (NULL != pc->fi_pos->filename) && - (GNUNET_YES == pc->any_done) && - (GNUNET_YES == pc->fi_pos->data.file.do_index)) { - /* run unindex to clean up */ - GNUNET_FS_unindex_start (pc->h, - pc->fi_pos->filename, - NULL); + GNUNET_asprintf(&pc->fi_pos->emsg, + _("Publishing failed: %s"), + msg); + pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; + pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; + pi.value.publish.specifics.error.message = pc->fi_pos->emsg; + pc->fi_pos->client_info = + GNUNET_FS_publish_make_status_(&pi, pc, pc->fi_pos, 0); + if ((GNUNET_YES != pc->fi_pos->is_directory) && + (NULL != pc->fi_pos->filename) && + (GNUNET_YES == pc->any_done) && + (GNUNET_YES == pc->fi_pos->data.file.do_index)) + { + /* run unindex to clean up */ + GNUNET_FS_unindex_start(pc->h, + pc->fi_pos->filename, + NULL); + } + return; } - return; - } pc->any_done = GNUNET_YES; - GNUNET_assert (NULL == pc->upload_task); + GNUNET_assert(NULL == pc->upload_task); pc->upload_task = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, pc); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, pc); } @@ -160,8 +160,8 @@ ds_put_cont (void *cls, * @param pc context of the publication */ static void -signal_publish_completion (struct GNUNET_FS_FileInformation *p, - struct GNUNET_FS_PublishContext *pc) +signal_publish_completion(struct GNUNET_FS_FileInformation *p, + struct GNUNET_FS_PublishContext *pc) { struct GNUNET_FS_ProgressInfo pi; @@ -170,8 +170,8 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, pi.value.publish.specifics.completed.chk_uri = p->chk_uri; pi.value.publish.specifics.completed.sks_uri = p->sks_uri; p->client_info = - GNUNET_FS_publish_make_status_ (&pi, pc, p, - p->data.file.file_size); + GNUNET_FS_publish_make_status_(&pi, pc, p, + p->data.file.file_size); } @@ -185,28 +185,27 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, * @param emsg error message */ static void -signal_publish_error (struct GNUNET_FS_FileInformation *p, - struct GNUNET_FS_PublishContext *pc, - const char *emsg) +signal_publish_error(struct GNUNET_FS_FileInformation *p, + struct GNUNET_FS_PublishContext *pc, + const char *emsg) { struct GNUNET_FS_ProgressInfo pi; - p->emsg = GNUNET_strdup (emsg); + p->emsg = GNUNET_strdup(emsg); pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; pi.value.publish.specifics.error.message = emsg; - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); if ((p->is_directory != GNUNET_YES) && (NULL != p->filename) && (GNUNET_YES == pc->any_done) && (p->data.file.do_index == GNUNET_YES)) - { - /* run unindex to clean up */ - GNUNET_FS_unindex_start (pc->h, - p->filename, - NULL); - } - + { + /* run unindex to clean up */ + GNUNET_FS_unindex_start(pc->h, + p->filename, + NULL); + } } @@ -219,18 +218,18 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p, * @param msg error message (typically NULL, not used) */ static void -finish_release_reserve (void *cls, int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +finish_release_reserve(void *cls, int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_PublishContext *pc = cls; pc->qre = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Releasing reserve done!\n"); - signal_publish_completion (pc->fi, pc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Releasing reserve done!\n"); + signal_publish_completion(pc->fi, pc); pc->all_done = GNUNET_YES; - GNUNET_FS_publish_sync_ (pc); + GNUNET_FS_publish_sync_(pc); } @@ -243,35 +242,35 @@ finish_release_reserve (void *cls, int success, * @param emsg NULL on success, otherwise error message */ static void -publish_sblocks_cont (void *cls, - const struct GNUNET_FS_Uri *uri, - const char *emsg) +publish_sblocks_cont(void *cls, + const struct GNUNET_FS_Uri *uri, + const char *emsg) { struct GNUNET_FS_PublishContext *pc = cls; pc->sks_pc = NULL; if (NULL != emsg) - { - signal_publish_error (pc->fi, pc, emsg); - GNUNET_FS_publish_sync_ (pc); - return; - } + { + signal_publish_error(pc->fi, pc, emsg); + GNUNET_FS_publish_sync_(pc); + return; + } if (NULL != uri) - { - /* sks publication, remember namespace URI */ - pc->fi->sks_uri = GNUNET_FS_uri_dup (uri); - } - GNUNET_assert (pc->qre == NULL); + { + /* sks publication, remember namespace URI */ + pc->fi->sks_uri = GNUNET_FS_uri_dup(uri); + } + GNUNET_assert(pc->qre == NULL); if ((pc->dsh != NULL) && (pc->rid != 0)) - { - pc->qre = - GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX, - &finish_release_reserve, pc); - } + { + pc->qre = + GNUNET_DATASTORE_release_reserve(pc->dsh, pc->rid, UINT_MAX, UINT_MAX, + &finish_release_reserve, pc); + } else - { - finish_release_reserve (pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); - } + { + finish_release_reserve(pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); + } } @@ -282,20 +281,20 @@ publish_sblocks_cont (void *cls, * @param pc overall upload data */ static void -publish_sblock (struct GNUNET_FS_PublishContext *pc) +publish_sblock(struct GNUNET_FS_PublishContext *pc) { if (NULL != pc->ns) - pc->sks_pc = GNUNET_FS_publish_sks (pc->h, - pc->ns, - pc->nid, - pc->nuid, - pc->fi->meta, - pc->fi->chk_uri, - &pc->fi->bo, - pc->options, - &publish_sblocks_cont, pc); + pc->sks_pc = GNUNET_FS_publish_sks(pc->h, + pc->ns, + pc->nid, + pc->nuid, + pc->fi->meta, + pc->fi->chk_uri, + &pc->fi->bo, + pc->options, + &publish_sblocks_cont, pc); else - publish_sblocks_cont (pc, NULL, NULL); + publish_sblocks_cont(pc, NULL, NULL); } @@ -309,44 +308,44 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc) * @param emsg NULL on success, otherwise error message */ static void -publish_kblocks_cont (void *cls, - const struct GNUNET_FS_Uri *uri, - const char *emsg) +publish_kblocks_cont(void *cls, + const struct GNUNET_FS_Uri *uri, + const char *emsg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p = pc->fi_pos; pc->ksk_pc = NULL; if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Error uploading KSK blocks: %s\n", - emsg); - signal_publish_error (p, pc, emsg); - GNUNET_FS_file_information_sync_ (p); - GNUNET_FS_publish_sync_ (pc); - GNUNET_assert (NULL == pc->upload_task); - pc->upload_task = - GNUNET_SCHEDULER_add_with_priority - (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, - pc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "KSK blocks published, moving on to next file\n"); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Error uploading KSK blocks: %s\n", + emsg); + signal_publish_error(p, pc, emsg); + GNUNET_FS_file_information_sync_(p); + GNUNET_FS_publish_sync_(pc); + GNUNET_assert(NULL == pc->upload_task); + pc->upload_task = + GNUNET_SCHEDULER_add_with_priority + (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, + pc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "KSK blocks published, moving on to next file\n"); if (NULL != p->dir) - signal_publish_completion (p, pc); + signal_publish_completion(p, pc); /* move on to next file */ if (NULL != p->next) pc->fi_pos = p->next; else pc->fi_pos = p->dir; - GNUNET_FS_publish_sync_ (pc); - GNUNET_assert (NULL == pc->upload_task); + GNUNET_FS_publish_sync_(pc); + GNUNET_assert(NULL == pc->upload_task); pc->upload_task = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, pc); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, pc); } @@ -364,11 +363,11 @@ publish_kblocks_cont (void *cls, * @return number of bytes copied to buf, 0 on error */ static size_t -block_reader (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg) +block_reader(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -377,31 +376,31 @@ block_reader (void *cls, p = pc->fi_pos; if (GNUNET_YES == p->is_directory) - { - pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset); - dd = p->data.dir.dir_data; - GNUNET_memcpy (buf, &dd[offset], pt_size); - } + { + pt_size = GNUNET_MIN(max, p->data.dir.dir_size - offset); + dd = p->data.dir.dir_data; + GNUNET_memcpy(buf, &dd[offset], pt_size); + } else - { - if (UINT64_MAX == offset) - { - if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) - { - /* force closing the file to avoid keeping too many files open */ - p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); - } - return 0; - } - pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); - if (0 == pt_size) - return 0; /* calling reader with pt_size==0 + { + if (UINT64_MAX == offset) + { + if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) + { + /* force closing the file to avoid keeping too many files open */ + p->data.file.reader(p->data.file.reader_cls, offset, 0, NULL, NULL); + } + return 0; + } + pt_size = GNUNET_MIN(max, p->data.file.file_size - offset); + if (0 == pt_size) + return 0; /* calling reader with pt_size==0 * might free buf, so don't! */ - if (pt_size != - p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf, - emsg)) - return 0; - } + if (pt_size != + p->data.file.reader(p->data.file.reader_cls, offset, pt_size, buf, + emsg)) + return 0; + } return pt_size; } @@ -414,7 +413,7 @@ block_reader (void *cls, * @param cls our publishing context */ static void -encode_cont (void *cls) +encode_cont(void *cls) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -422,44 +421,44 @@ encode_cont (void *cls) char *emsg; uint64_t flen; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished with tree encoder\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished with tree encoder\n"); p = pc->fi_pos; - p->chk_uri = GNUNET_FS_tree_encoder_get_uri (p->te); - GNUNET_FS_file_information_sync_ (p); - GNUNET_FS_tree_encoder_finish (p->te, &emsg); + p->chk_uri = GNUNET_FS_tree_encoder_get_uri(p->te); + GNUNET_FS_file_information_sync_(p); + GNUNET_FS_tree_encoder_finish(p->te, &emsg); p->te = NULL; if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Error during tree walk: %s\n", - emsg); - GNUNET_asprintf (&p->emsg, - _("Publishing failed: %s"), - emsg); - GNUNET_free (emsg); - pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; - pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; - pi.value.publish.specifics.error.message = p->emsg; - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Error during tree walk: %s\n", + emsg); + GNUNET_asprintf(&p->emsg, + _("Publishing failed: %s"), + emsg); + GNUNET_free(emsg); + pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; + pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; + pi.value.publish.specifics.error.message = p->emsg; + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); + } else - { - /* final progress event */ - GNUNET_assert (NULL != p->chk_uri); - flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); - pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; - pi.value.publish.specifics.progress.data = NULL; - pi.value.publish.specifics.progress.offset = flen; - pi.value.publish.specifics.progress.data_len = 0; - pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen); - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen); - } + { + /* final progress event */ + GNUNET_assert(NULL != p->chk_uri); + flen = GNUNET_FS_uri_chk_get_file_size(p->chk_uri); + pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; + pi.value.publish.specifics.progress.data = NULL; + pi.value.publish.specifics.progress.offset = flen; + pi.value.publish.specifics.progress.data_len = 0; + pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth(flen); + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, flen); + } /* continue with main */ /* continue with main */ - GNUNET_assert (NULL == pc->upload_task); + GNUNET_assert(NULL == pc->upload_task); pc->upload_task = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, pc); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, pc); } @@ -478,13 +477,13 @@ encode_cont (void *cls) * @param block_size size of @a block (in bytes) */ static void -block_proc (void *cls, - const struct ContentHashKey *chk, - uint64_t offset, - unsigned int depth, - enum GNUNET_BLOCK_Type type, - const void *block, - uint16_t block_size) +block_proc(void *cls, + const struct ContentHashKey *chk, + uint64_t offset, + unsigned int depth, + enum GNUNET_BLOCK_Type type, + const void *block, + uint16_t block_size) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -492,62 +491,62 @@ block_proc (void *cls, p = pc->fi_pos; if (NULL == pc->dsh) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Waiting for datastore connection\n"); - GNUNET_assert (NULL == pc->upload_task); - pc->upload_task = + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Waiting for datastore connection\n"); + GNUNET_assert(NULL == pc->upload_task); + pc->upload_task = GNUNET_SCHEDULER_add_with_priority - (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); - return; - } - - if ( (GNUNET_YES != p->is_directory) && - (GNUNET_YES == p->data.file.do_index) && - (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Indexing block `%s' for offset %llu with index size %u\n", - GNUNET_h2s (&chk->query), - (unsigned long long) offset, - (unsigned int) sizeof (struct OnDemandBlock)); - odb.offset = GNUNET_htonll (offset); - odb.file_id = p->data.file.file_id; - GNUNET_assert (pc->qre == NULL); - pc->qre = - GNUNET_DATASTORE_put (pc->dsh, - (p->is_directory == GNUNET_YES) ? 0 : pc->rid, - &chk->query, - sizeof (struct OnDemandBlock), - &odb, - GNUNET_BLOCK_TYPE_FS_ONDEMAND, - p->bo.content_priority, - p->bo.anonymity_level, - p->bo.replication_level, - p->bo.expiration_time, - -2, 1, - &ds_put_cont, pc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publishing block `%s' for offset %llu with size %u\n", - GNUNET_h2s (&chk->query), - (unsigned long long) offset, - (unsigned int) block_size); - GNUNET_assert (pc->qre == NULL); + (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); + return; + } + + if ((GNUNET_YES != p->is_directory) && + (GNUNET_YES == p->data.file.do_index) && + (GNUNET_BLOCK_TYPE_FS_DBLOCK == type)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Indexing block `%s' for offset %llu with index size %u\n", + GNUNET_h2s(&chk->query), + (unsigned long long)offset, + (unsigned int)sizeof(struct OnDemandBlock)); + odb.offset = GNUNET_htonll(offset); + odb.file_id = p->data.file.file_id; + GNUNET_assert(pc->qre == NULL); + pc->qre = + GNUNET_DATASTORE_put(pc->dsh, + (p->is_directory == GNUNET_YES) ? 0 : pc->rid, + &chk->query, + sizeof(struct OnDemandBlock), + &odb, + GNUNET_BLOCK_TYPE_FS_ONDEMAND, + p->bo.content_priority, + p->bo.anonymity_level, + p->bo.replication_level, + p->bo.expiration_time, + -2, 1, + &ds_put_cont, pc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publishing block `%s' for offset %llu with size %u\n", + GNUNET_h2s(&chk->query), + (unsigned long long)offset, + (unsigned int)block_size); + GNUNET_assert(pc->qre == NULL); pc->qre = - GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, - &chk->query, - block_size, - block, - type, - p->bo.content_priority, - p->bo.anonymity_level, - p->bo.replication_level, - p->bo.expiration_time, - -2, 1, - &ds_put_cont, - pc); + GNUNET_DATASTORE_put(pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, + &chk->query, + block_size, + block, + type, + p->bo.content_priority, + p->bo.anonymity_level, + p->bo.replication_level, + p->bo.expiration_time, + -2, 1, + &ds_put_cont, + pc); } @@ -562,10 +561,10 @@ block_proc (void *cls, * @param depth depth of the block in the tree, 0 for DBLOCK */ static void -progress_proc (void *cls, uint64_t offset, - const void *pt_block, - size_t pt_size, - unsigned int depth) +progress_proc(void *cls, uint64_t offset, + const void *pt_block, + size_t pt_size, + unsigned int depth) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -578,24 +577,23 @@ progress_proc (void *cls, uint64_t offset, pi.value.publish.specifics.progress.offset = offset; pi.value.publish.specifics.progress.data_len = pt_size; pi.value.publish.specifics.progress.depth = depth; - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset); - if ( (0 != depth) || - (GNUNET_YES == p->is_directory) ) + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, offset); + if ((0 != depth) || + (GNUNET_YES == p->is_directory)) return; while (NULL != (par = p->dir)) - { - p = par; - GNUNET_assert (GNUNET_YES == par->is_directory); - p->data.dir.contents_completed += pt_size; - pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; - pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; - pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; - pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta (p->start_time, - p->data.dir.contents_completed, - p->data.dir.contents_size); - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); - - } + { + p = par; + GNUNET_assert(GNUNET_YES == par->is_directory); + p->data.dir.contents_completed += pt_size; + pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; + pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; + pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; + pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta(p->start_time, + p->data.dir.contents_completed, + p->data.dir.contents_size); + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); + } } @@ -607,7 +605,7 @@ progress_proc (void *cls, uint64_t offset, * @param pc overall upload data */ static void -publish_content (struct GNUNET_FS_PublishContext *pc) +publish_content(struct GNUNET_FS_PublishContext *pc) { struct GNUNET_FS_FileInformation *p; char *emsg; @@ -617,65 +615,64 @@ publish_content (struct GNUNET_FS_PublishContext *pc) uint64_t size; p = pc->fi_pos; - GNUNET_assert (NULL != p); + GNUNET_assert(NULL != p); if (NULL == p->te) - { - if (GNUNET_YES == p->is_directory) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); - db = GNUNET_FS_directory_builder_create (p->meta); - dirpos = p->data.dir.entries; - while (NULL != dirpos) - { - if (GNUNET_YES == dirpos->is_directory) - { - raw_data = dirpos->data.dir.dir_data; - dirpos->data.dir.dir_data = NULL; - } - else + { + if (GNUNET_YES == p->is_directory) { - raw_data = NULL; - if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && - (dirpos->data.file.file_size > 0)) - { - raw_data = GNUNET_malloc (dirpos->data.file.file_size); - emsg = NULL; - if (dirpos->data.file.file_size != - dirpos->data.file.reader (dirpos->data.file.reader_cls, 0, - dirpos->data.file.file_size, raw_data, - &emsg)) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); + db = GNUNET_FS_directory_builder_create(p->meta); + dirpos = p->data.dir.entries; + while (NULL != dirpos) { - GNUNET_free_non_null (emsg); - GNUNET_free (raw_data); - raw_data = NULL; + if (GNUNET_YES == dirpos->is_directory) + { + raw_data = dirpos->data.dir.dir_data; + dirpos->data.dir.dir_data = NULL; + } + else + { + raw_data = NULL; + if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && + (dirpos->data.file.file_size > 0)) + { + raw_data = GNUNET_malloc(dirpos->data.file.file_size); + emsg = NULL; + if (dirpos->data.file.file_size != + dirpos->data.file.reader(dirpos->data.file.reader_cls, 0, + dirpos->data.file.file_size, raw_data, + &emsg)) + { + GNUNET_free_non_null(emsg); + GNUNET_free(raw_data); + raw_data = NULL; + } + dirpos->data.file.reader(dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); + } + } + GNUNET_FS_directory_builder_add(db, dirpos->chk_uri, dirpos->meta, + raw_data); + GNUNET_free_non_null(raw_data); + dirpos = dirpos->next; } - dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); - } + GNUNET_free_non_null(p->data.dir.dir_data); + p->data.dir.dir_data = NULL; + p->data.dir.dir_size = 0; + GNUNET_FS_directory_builder_finish(db, &p->data.dir.dir_size, + &p->data.dir.dir_data); + GNUNET_FS_file_information_sync_(p); } - GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta, - raw_data); - GNUNET_free_non_null (raw_data); - dirpos = dirpos->next; - } - GNUNET_free_non_null (p->data.dir.dir_data); - p->data.dir.dir_data = NULL; - p->data.dir.dir_size = 0; - GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size, - &p->data.dir.dir_data); - GNUNET_FS_file_information_sync_ (p); - } - size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating tree encoder\n"); - p->te = - GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader, - &block_proc, &progress_proc, - &encode_cont); - - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Processing next block from tree\n"); - GNUNET_FS_tree_encoder_next (p->te); + size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating tree encoder\n"); + p->te = + GNUNET_FS_tree_encoder_create(pc->h, size, pc, &block_reader, + &block_proc, &progress_proc, + &encode_cont); + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Processing next block from tree\n"); + GNUNET_FS_tree_encoder_next(p->te); } @@ -687,17 +684,17 @@ publish_content (struct GNUNET_FS_PublishContext *pc) * @param msg the response we got */ static int -check_index_start_failed (void *cls, - const struct GNUNET_MessageHeader *msg) +check_index_start_failed(void *cls, + const struct GNUNET_MessageHeader *msg) { - size_t msize = ntohs (msg->size) - sizeof (*msg); - const char *emsg = (const char *) &msg[1]; - - if (emsg[msize - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + size_t msize = ntohs(msg->size) - sizeof(*msg); + const char *emsg = (const char *)&msg[1]; + + if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -710,27 +707,27 @@ check_index_start_failed (void *cls, * @param msg the response we got */ static void -handle_index_start_failed (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_index_start_failed(void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; - const char *emsg = (const char *) &msg[1]; + const char *emsg = (const char *)&msg[1]; char *msgtxt; - GNUNET_MQ_destroy (pc->mq); + GNUNET_MQ_destroy(pc->mq); pc->mq = NULL; p = pc->fi_pos; - GNUNET_asprintf (&msgtxt, - _("Can not index file `%s': %s.\n"), - p->filename, - gettext (emsg)); - signal_publish_error (p, - pc, - msgtxt); - GNUNET_free (msgtxt); - GNUNET_FS_file_information_sync_ (p); - GNUNET_FS_publish_sync_ (pc); + GNUNET_asprintf(&msgtxt, + _("Can not index file `%s': %s.\n"), + p->filename, + gettext(emsg)); + signal_publish_error(p, + pc, + msgtxt); + GNUNET_free(msgtxt); + GNUNET_FS_file_information_sync_(p); + GNUNET_FS_publish_sync_(pc); } @@ -742,18 +739,18 @@ handle_index_start_failed (void *cls, * @param msg the response we got */ static void -handle_index_start_ok (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_index_start_ok(void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; - GNUNET_MQ_destroy (pc->mq); + GNUNET_MQ_destroy(pc->mq); pc->mq = NULL; p = pc->fi_pos; p->data.file.index_start_confirmed = GNUNET_YES; - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); + GNUNET_FS_file_information_sync_(p); + publish_content(pc); } @@ -766,25 +763,25 @@ handle_index_start_ok (void *cls, * @param error error code */ static void -index_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +index_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; if (NULL != pc->mq) - { - GNUNET_MQ_destroy (pc->mq); - pc->mq = NULL; - } + { + GNUNET_MQ_destroy(pc->mq); + pc->mq = NULL; + } p = pc->fi_pos; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not index file `%s': %s. Will try to insert instead.\n"), - p->filename, - _("error on index-start request to `fs' service")); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not index file `%s': %s. Will try to insert instead.\n"), + p->filename, + _("error on index-start request to `fs' service")); p->data.file.do_index = GNUNET_NO; - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); + GNUNET_FS_file_information_sync_(p); + publish_content(pc); } @@ -796,20 +793,20 @@ index_mq_error_handler (void *cls, * @param res resulting hash, NULL on error */ static void -hash_for_index_cb (void *cls, - const struct GNUNET_HashCode *res) +hash_for_index_cb(void *cls, + const struct GNUNET_HashCode *res) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (index_start_ok, - GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, - struct GNUNET_MessageHeader, - pc), - GNUNET_MQ_hd_var_size (index_start_failed, - GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, - struct GNUNET_MessageHeader, - pc), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(index_start_ok, + GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, + struct GNUNET_MessageHeader, + pc), + GNUNET_MQ_hd_var_size(index_start_failed, + GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, + struct GNUNET_MessageHeader, + pc), + GNUNET_MQ_handler_end() }; struct GNUNET_FS_FileInformation *p; struct GNUNET_MQ_Envelope *env; @@ -822,97 +819,97 @@ hash_for_index_cb (void *cls, pc->fhc = NULL; p = pc->fi_pos; if (NULL == res) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not index file `%s': %s. Will try to insert instead.\n"), - p->filename, - _("failed to compute hash")); - p->data.file.do_index = GNUNET_NO; - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not index file `%s': %s. Will try to insert instead.\n"), + p->filename, + _("failed to compute hash")); + p->data.file.do_index = GNUNET_NO; + GNUNET_FS_file_information_sync_(p); + publish_content(pc); + return; + } if (GNUNET_YES == p->data.file.index_start_confirmed) - { - publish_content (pc); - return; - } - fn = GNUNET_STRINGS_filename_expand (p->filename); - GNUNET_assert (fn != NULL); - slen = strlen (fn) + 1; + { + publish_content(pc); + return; + } + fn = GNUNET_STRINGS_filename_expand(p->filename); + GNUNET_assert(fn != NULL); + slen = strlen(fn) + 1; if (slen >= - GNUNET_MAX_MESSAGE_SIZE - sizeof (struct IndexStartMessage)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ - ("Can not index file `%s': %s. Will try to insert instead.\n"), - fn, _("filename too long")); - GNUNET_free (fn); - p->data.file.do_index = GNUNET_NO; - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hash of indexed file `%s' is `%s'\n", - p->filename, - GNUNET_h2s (res)); + GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _ + ("Can not index file `%s': %s. Will try to insert instead.\n"), + fn, _("filename too long")); + GNUNET_free(fn); + p->data.file.do_index = GNUNET_NO; + GNUNET_FS_file_information_sync_(p); + publish_content(pc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Hash of indexed file `%s' is `%s'\n", + p->filename, + GNUNET_h2s(res)); if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) - { - p->data.file.file_id = *res; - p->data.file.have_hash = GNUNET_YES; - p->data.file.index_start_confirmed = GNUNET_YES; - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); - GNUNET_free (fn); - return; - } - pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, - "fs", - handlers, - &index_mq_error_handler, - pc); + { + p->data.file.file_id = *res; + p->data.file.have_hash = GNUNET_YES; + p->data.file.index_start_confirmed = GNUNET_YES; + GNUNET_FS_file_information_sync_(p); + publish_content(pc); + GNUNET_free(fn); + return; + } + pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, + "fs", + handlers, + &index_mq_error_handler, + pc); if (NULL == pc->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not index file `%s': %s. Will try to insert instead.\n"), - p->filename, - _("could not connect to `fs' service")); - p->data.file.do_index = GNUNET_NO; - publish_content (pc); - GNUNET_free (fn); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not index file `%s': %s. Will try to insert instead.\n"), + p->filename, + _("could not connect to `fs' service")); + p->data.file.do_index = GNUNET_NO; + publish_content(pc); + GNUNET_free(fn); + return; + } if (p->data.file.have_hash != GNUNET_YES) - { - p->data.file.file_id = *res; - p->data.file.have_hash = GNUNET_YES; - GNUNET_FS_file_information_sync_ (p); - } - env = GNUNET_MQ_msg_extra (ism, - slen, - GNUNET_MESSAGE_TYPE_FS_INDEX_START); + { + p->data.file.file_id = *res; + p->data.file.have_hash = GNUNET_YES; + GNUNET_FS_file_information_sync_(p); + } + env = GNUNET_MQ_msg_extra(ism, + slen, + GNUNET_MESSAGE_TYPE_FS_INDEX_START); if (GNUNET_OK == - GNUNET_DISK_file_get_identifiers (p->filename, - &dev, - &ino)) - { - ism->device = GNUNET_htonll (dev); - ism->inode = GNUNET_htonll (ino); - } + GNUNET_DISK_file_get_identifiers(p->filename, + &dev, + &ino)) + { + ism->device = GNUNET_htonll(dev); + ism->inode = GNUNET_htonll(ino); + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Failed to get file identifiers for `%s'\n"), - p->filename); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + _("Failed to get file identifiers for `%s'\n"), + p->filename); + } ism->file_id = *res; - GNUNET_memcpy (&ism[1], - fn, - slen); - GNUNET_free (fn); - GNUNET_MQ_send (pc->mq, - env); + GNUNET_memcpy(&ism[1], + fn, + slen); + GNUNET_free(fn); + GNUNET_MQ_send(pc->mq, + env); } @@ -922,27 +919,27 @@ hash_for_index_cb (void *cls, * @param pc publishing context to do this for */ static void -publish_kblocks (struct GNUNET_FS_PublishContext *pc) +publish_kblocks(struct GNUNET_FS_PublishContext *pc) { struct GNUNET_FS_FileInformation *p; p = pc->fi_pos; /* upload of "p" complete, publish KBlocks! */ if (NULL != p->keywords) - { - pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h, - p->keywords, - p->meta, - p->chk_uri, - &p->bo, - pc->options, - &publish_kblocks_cont, - pc); - } + { + pc->ksk_pc = GNUNET_FS_publish_ksk(pc->h, + p->keywords, + p->meta, + p->chk_uri, + &p->bo, + pc->options, + &publish_kblocks_cont, + pc); + } else - { - publish_kblocks_cont (pc, p->chk_uri, NULL); - } + { + publish_kblocks_cont(pc, p->chk_uri, NULL); + } } @@ -953,8 +950,8 @@ publish_kblocks (struct GNUNET_FS_PublishContext *pc) * @param sig the response we got */ static void -handle_signature_response (void *cls, - const struct ResponseLocSignatureMessage *sig) +handle_signature_response(void *cls, + const struct ResponseLocSignatureMessage *sig) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -964,11 +961,11 @@ handle_signature_response (void *cls, /* p->data.loc.fi kept from CHK before */ p->chk_uri->data.loc.peer = sig->peer; p->chk_uri->data.loc.expirationTime - = GNUNET_TIME_absolute_ntoh (sig->expiration_time); + = GNUNET_TIME_absolute_ntoh(sig->expiration_time); p->chk_uri->data.loc.contentSignature = sig->signature; - GNUNET_FS_file_information_sync_ (p); - GNUNET_FS_publish_sync_ (pc); - publish_kblocks (pc); + GNUNET_FS_file_information_sync_(p); + GNUNET_FS_publish_sync_(pc); + publish_kblocks(pc); } @@ -981,19 +978,19 @@ handle_signature_response (void *cls, * @param error error code */ static void -loc_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +loc_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_FS_PublishContext *pc = cls; if (NULL != pc->mq) - { - GNUNET_MQ_destroy (pc->mq); - pc->mq = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not create LOC URI. Will continue with CHK instead.\n")); - publish_kblocks (pc); + { + GNUNET_MQ_destroy(pc->mq); + pc->mq = NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not create LOC URI. Will continue with CHK instead.\n")); + publish_kblocks(pc); } @@ -1005,42 +1002,42 @@ loc_mq_error_handler (void *cls, * @param pc the publishing context do to this for */ static void -create_loc_uri (struct GNUNET_FS_PublishContext *pc) +create_loc_uri(struct GNUNET_FS_PublishContext *pc) { struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (signature_response, - GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, - struct ResponseLocSignatureMessage, - pc), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(signature_response, + GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, + struct ResponseLocSignatureMessage, + pc), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *env; struct RequestLocSignatureMessage *req; struct GNUNET_FS_FileInformation *p; if (NULL != pc->mq) - GNUNET_MQ_destroy (pc->mq); - pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, - "fs", - handlers, - &loc_mq_error_handler, - pc); + GNUNET_MQ_destroy(pc->mq); + pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, + "fs", + handlers, + &loc_mq_error_handler, + pc); if (NULL == pc->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not create LOC URI. Will continue with CHK instead.\n")); - publish_kblocks (pc); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not create LOC URI. Will continue with CHK instead.\n")); + publish_kblocks(pc); + return; + } p = pc->fi_pos; - env = GNUNET_MQ_msg (req, - GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); - req->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); - req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time); + env = GNUNET_MQ_msg(req, + GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); + req->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); + req->expiration_time = GNUNET_TIME_absolute_hton(p->bo.expiration_time); req->chk = p->chk_uri->data.chk.chk; - req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length); - GNUNET_MQ_send (pc->mq, - env); + req->file_length = GNUNET_htonll(p->chk_uri->data.chk.file_length); + GNUNET_MQ_send(pc->mq, + env); } @@ -1050,7 +1047,7 @@ create_loc_uri (struct GNUNET_FS_PublishContext *pc) * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload */ void -GNUNET_FS_publish_main_ (void *cls) +GNUNET_FS_publish_main_(void *cls) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -1060,108 +1057,108 @@ GNUNET_FS_publish_main_ (void *cls) pc->upload_task = NULL; p = pc->fi_pos; if (NULL == p) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publishing complete, now publishing SKS and KSK blocks.\n"); - /* upload of entire hierarchy complete, - * publish namespace entries */ - GNUNET_FS_publish_sync_ (pc); - publish_sblock (pc); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publishing complete, now publishing SKS and KSK blocks.\n"); + /* upload of entire hierarchy complete, + * publish namespace entries */ + GNUNET_FS_publish_sync_(pc); + publish_sblock(pc); + return; + } /* find starting position */ - while ( (GNUNET_YES == p->is_directory) && - (NULL != p->data.dir.entries) && - (NULL == p->emsg) && - (NULL == p->data.dir.entries->chk_uri) ) - { - p = p->data.dir.entries; - pc->fi_pos = p; - GNUNET_FS_publish_sync_ (pc); - } + while ((GNUNET_YES == p->is_directory) && + (NULL != p->data.dir.entries) && + (NULL == p->emsg) && + (NULL == p->data.dir.entries->chk_uri)) + { + p = p->data.dir.entries; + pc->fi_pos = p; + GNUNET_FS_publish_sync_(pc); + } /* abort on error */ if (NULL != p->emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Error uploading: %s\n", - p->emsg); - /* error with current file, abort all - * related files as well! */ - while (NULL != p->dir) - { - fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); - p = p->dir; - if (fn != NULL) - { - GNUNET_asprintf (&p->emsg, - _("Recursive upload failed at `%s': %s"), - fn, - p->emsg); - GNUNET_free (fn); - } - else - { - GNUNET_asprintf (&p->emsg, - _("Recursive upload failed: %s"), - p->emsg); - } - pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; - pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; - pi.value.publish.specifics.error.message = p->emsg; - p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Error uploading: %s\n", + p->emsg); + /* error with current file, abort all + * related files as well! */ + while (NULL != p->dir) + { + fn = GNUNET_CONTAINER_meta_data_get_by_type(p->meta, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + p = p->dir; + if (fn != NULL) + { + GNUNET_asprintf(&p->emsg, + _("Recursive upload failed at `%s': %s"), + fn, + p->emsg); + GNUNET_free(fn); + } + else + { + GNUNET_asprintf(&p->emsg, + _("Recursive upload failed: %s"), + p->emsg); + } + pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; + pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; + pi.value.publish.specifics.error.message = p->emsg; + p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); + } + pc->all_done = GNUNET_YES; + GNUNET_FS_publish_sync_(pc); + return; } - pc->all_done = GNUNET_YES; - GNUNET_FS_publish_sync_ (pc); - return; - } /* handle completion */ if (NULL != p->chk_uri) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "File upload complete, now publishing KSK blocks.\n"); - GNUNET_FS_publish_sync_ (pc); - - if ( (0 == p->bo.anonymity_level) && - (GNUNET_YES != - GNUNET_FS_uri_test_loc (p->chk_uri)) ) - { - /* zero anonymity, box CHK URI in LOC URI */ - create_loc_uri (pc); - } - else { - publish_kblocks (pc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "File upload complete, now publishing KSK blocks.\n"); + GNUNET_FS_publish_sync_(pc); + + if ((0 == p->bo.anonymity_level) && + (GNUNET_YES != + GNUNET_FS_uri_test_loc(p->chk_uri))) + { + /* zero anonymity, box CHK URI in LOC URI */ + create_loc_uri(pc); + } + else + { + publish_kblocks(pc); + } + return; } - return; - } if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) - { - if (NULL == p->filename) { - p->data.file.do_index = GNUNET_NO; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Can not index file `%s': %s. Will try to insert instead.\n"), - "", - _("needs to be an actual file")); - GNUNET_FS_file_information_sync_ (p); - publish_content (pc); + if (NULL == p->filename) + { + p->data.file.do_index = GNUNET_NO; + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Can not index file `%s': %s. Will try to insert instead.\n"), + "", + _("needs to be an actual file")); + GNUNET_FS_file_information_sync_(p); + publish_content(pc); + return; + } + if (p->data.file.have_hash) + { + hash_for_index_cb(pc, &p->data.file.file_id); + } + else + { + p->start_time = GNUNET_TIME_absolute_get(); + pc->fhc = + GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename, + HASHING_BLOCKSIZE, &hash_for_index_cb, pc); + } return; } - if (p->data.file.have_hash) - { - hash_for_index_cb (pc, &p->data.file.file_id); - } - else - { - p->start_time = GNUNET_TIME_absolute_get (); - pc->fhc = - GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename, - HASHING_BLOCKSIZE, &hash_for_index_cb, pc); - } - return; - } - publish_content (pc); + publish_content(pc); } @@ -1180,14 +1177,14 @@ GNUNET_FS_publish_main_ (void *cls) * @return #GNUNET_OK to continue (always) */ static int -fip_signal_start (void *cls, - struct GNUNET_FS_FileInformation *fi, - uint64_t length, - struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, - int *do_index, - void **client_info) +fip_signal_start(void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, + void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -1195,52 +1192,52 @@ fip_signal_start (void *cls, uint64_t left; if (GNUNET_YES == pc->skip_next_fi_callback) - { - pc->skip_next_fi_callback = GNUNET_NO; - return GNUNET_OK; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting publish operation\n"); + { + pc->skip_next_fi_callback = GNUNET_NO; + return GNUNET_OK; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting publish operation\n"); if (*do_index) - { - /* space for on-demand blocks */ - pc->reserve_space += + { + /* space for on-demand blocks */ + pc->reserve_space += ((length + DBLOCK_SIZE - - 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock); - } + 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock); + } else - { - /* space for DBlocks */ - pc->reserve_space += length; - } + { + /* space for DBlocks */ + pc->reserve_space += length; + } /* entries for IBlocks and DBlocks, space for IBlocks */ left = length; while (1) - { - left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; - pc->reserve_entries += left; - if (left <= 1) - break; - left = left * sizeof (struct ContentHashKey); - pc->reserve_space += left; - } + { + left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; + pc->reserve_entries += left; + if (left <= 1) + break; + left = left * sizeof(struct ContentHashKey); + pc->reserve_space += left; + } pc->reserve_entries++; /* entries and space for keywords */ if (NULL != *uri) - { - kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri); - pc->reserve_entries += kc; - pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; - } + { + kc = GNUNET_FS_uri_ksk_get_keyword_count(*uri); + pc->reserve_entries += kc; + pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; + } pi.status = GNUNET_FS_STATUS_PUBLISH_START; - *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); - GNUNET_FS_file_information_sync_ (fi); + *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); + GNUNET_FS_file_information_sync_(fi); if ((fi->is_directory) && (fi->dir != NULL)) - { - /* We are a directory, and we are not top-level; process entries in directory */ - pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (fi, &fip_signal_start, pc); - } + { + /* We are a directory, and we are not top-level; process entries in directory */ + pc->skip_next_fi_callback = GNUNET_YES; + GNUNET_FS_file_information_inspect(fi, &fip_signal_start, pc); + } return GNUNET_OK; } @@ -1253,39 +1250,39 @@ fip_signal_start (void *cls, * @param pc the publish context of which a file is being suspended */ static void -suspend_operation (struct GNUNET_FS_FileInformation *fi, - struct GNUNET_FS_PublishContext *pc) +suspend_operation(struct GNUNET_FS_FileInformation *fi, + struct GNUNET_FS_PublishContext *pc) { struct GNUNET_FS_ProgressInfo pi; uint64_t off; if (NULL != pc->ksk_pc) - { - GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); - pc->ksk_pc = NULL; - } + { + GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); + pc->ksk_pc = NULL; + } if (NULL != pc->sks_pc) - { - GNUNET_FS_publish_sks_cancel (pc->sks_pc); - pc->sks_pc = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Suspending publish operation\n"); - GNUNET_free_non_null (fi->serialization); + { + GNUNET_FS_publish_sks_cancel(pc->sks_pc); + pc->sks_pc = NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Suspending publish operation\n"); + GNUNET_free_non_null(fi->serialization); fi->serialization = NULL; off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? fi->data.dir.dir_size : fi->data.file.file_size; pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; - GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); + GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); if (NULL != pc->qre) - { - GNUNET_DATASTORE_cancel (pc->qre); - pc->qre = NULL; - } + { + GNUNET_DATASTORE_cancel(pc->qre); + pc->qre = NULL; + } if (NULL != pc->dsh) - { - GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); - pc->dsh = NULL; - } + { + GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); + pc->dsh = NULL; + } pc->rid = 0; } @@ -1305,29 +1302,29 @@ suspend_operation (struct GNUNET_FS_FileInformation *fi, * @return #GNUNET_OK to continue (always) */ static int -fip_signal_suspend (void *cls, - struct GNUNET_FS_FileInformation *fi, - uint64_t length, - struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, - int *do_index, - void **client_info) +fip_signal_suspend(void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, + void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; if (GNUNET_YES == pc->skip_next_fi_callback) - { - pc->skip_next_fi_callback = GNUNET_NO; - return GNUNET_OK; - } - if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) - { - /* process entries in directory */ - pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (fi, &fip_signal_suspend, pc); - } - suspend_operation (fi, pc); + { + pc->skip_next_fi_callback = GNUNET_NO; + return GNUNET_OK; + } + if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) + { + /* process entries in directory */ + pc->skip_next_fi_callback = GNUNET_YES; + GNUNET_FS_file_information_inspect(fi, &fip_signal_suspend, pc); + } + suspend_operation(fi, pc); *client_info = NULL; return GNUNET_OK; } @@ -1340,21 +1337,21 @@ fip_signal_suspend (void *cls, * @param cls the `struct GNUNET_FS_PublishContext` to signal for */ void -GNUNET_FS_publish_signal_suspend_ (void *cls) +GNUNET_FS_publish_signal_suspend_(void *cls) { struct GNUNET_FS_PublishContext *pc = cls; if (NULL != pc->upload_task) - { - GNUNET_SCHEDULER_cancel (pc->upload_task); - pc->upload_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(pc->upload_task); + pc->upload_task = NULL; + } pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc); - suspend_operation (pc->fi, pc); - GNUNET_FS_end_top (pc->h, pc->top); + GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_suspend, pc); + suspend_operation(pc->fi, pc); + GNUNET_FS_end_top(pc->h, pc->top); pc->top = NULL; - publish_cleanup (pc); + publish_cleanup(pc); } @@ -1368,30 +1365,30 @@ GNUNET_FS_publish_signal_suspend_ (void *cls) * @param msg error message on error, otherwise NULL */ static void -finish_reserve (void *cls, - int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +finish_reserve(void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_PublishContext *pc = cls; pc->qre = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reservation complete (%d)!\n", - success); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Reservation complete (%d)!\n", + success); if ((msg != NULL) || (success <= 0)) - { - GNUNET_asprintf (&pc->fi->emsg, - _("Datastore failure: %s"), - msg); - signal_publish_error (pc->fi, pc, pc->fi->emsg); - return; - } + { + GNUNET_asprintf(&pc->fi->emsg, + _("Datastore failure: %s"), + msg); + signal_publish_error(pc->fi, pc, pc->fi->emsg); + return; + } pc->rid = success; - GNUNET_assert (NULL == pc->upload_task); + GNUNET_assert(NULL == pc->upload_task); pc->upload_task = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, pc); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, pc); } @@ -1401,7 +1398,7 @@ finish_reserve (void *cls, * @param fi file structure to traverse */ static uint64_t -compute_contents_size (struct GNUNET_FS_FileInformation *fi) +compute_contents_size(struct GNUNET_FS_FileInformation *fi) { struct GNUNET_FS_FileInformation *ent; @@ -1409,7 +1406,7 @@ compute_contents_size (struct GNUNET_FS_FileInformation *fi) return fi->data.file.file_size; fi->data.dir.contents_size = 0; for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) - fi->data.dir.contents_size += compute_contents_size (ent); + fi->data.dir.contents_size += compute_contents_size(ent); return fi->data.dir.contents_size; } @@ -1428,67 +1425,67 @@ compute_contents_size (struct GNUNET_FS_FileInformation *fi) * @return context that can be used to control the publish operation */ struct GNUNET_FS_PublishContext * -GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, - struct GNUNET_FS_FileInformation *fi, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const char *nid, - const char *nuid, - enum GNUNET_FS_PublishOptions options) +GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h, + struct GNUNET_FS_FileInformation *fi, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, + const char *nid, + const char *nuid, + enum GNUNET_FS_PublishOptions options) { struct GNUNET_FS_PublishContext *ret; struct GNUNET_DATASTORE_Handle *dsh; - GNUNET_assert (NULL != h); - compute_contents_size (fi); + GNUNET_assert(NULL != h); + compute_contents_size(fi); if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) - { - dsh = GNUNET_DATASTORE_connect (h->cfg); - if (NULL == dsh) - return NULL; - } + { + dsh = GNUNET_DATASTORE_connect(h->cfg); + if (NULL == dsh) + return NULL; + } else - { - dsh = NULL; - } - ret = GNUNET_new (struct GNUNET_FS_PublishContext); + { + dsh = NULL; + } + ret = GNUNET_new(struct GNUNET_FS_PublishContext); ret->dsh = dsh; ret->h = h; ret->fi = fi; if (NULL != ns) - { - ret->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); - *ret->ns = *ns; - GNUNET_assert (NULL != nid); - ret->nid = GNUNET_strdup (nid); - if (NULL != nuid) - ret->nuid = GNUNET_strdup (nuid); - } + { + ret->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); + *ret->ns = *ns; + GNUNET_assert(NULL != nid); + ret->nid = GNUNET_strdup(nid); + if (NULL != nuid) + ret->nuid = GNUNET_strdup(nuid); + } ret->options = options; /* signal start */ - GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret); + GNUNET_FS_file_information_inspect(ret->fi, &fip_signal_start, ret); ret->fi_pos = ret->fi; - ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret); - GNUNET_FS_publish_sync_ (ret); + ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, ret); + GNUNET_FS_publish_sync_(ret); if (NULL != ret->dsh) - { - GNUNET_assert (NULL == ret->qre); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Reserving space for %u entries and %llu bytes for publication\n"), - (unsigned int) ret->reserve_entries, - (unsigned long long) ret->reserve_space); - ret->qre = - GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space, - ret->reserve_entries, - &finish_reserve, - ret); - } + { + GNUNET_assert(NULL == ret->qre); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Reserving space for %u entries and %llu bytes for publication\n"), + (unsigned int)ret->reserve_entries, + (unsigned long long)ret->reserve_space); + ret->qre = + GNUNET_DATASTORE_reserve(ret->dsh, ret->reserve_space, + ret->reserve_entries, + &finish_reserve, + ret); + } else - { - GNUNET_assert (NULL == ret->upload_task); - ret->upload_task = + { + GNUNET_assert(NULL == ret->upload_task); + ret->upload_task = GNUNET_SCHEDULER_add_with_priority - (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); - } + (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); + } return ret; } @@ -1508,39 +1505,39 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, * @return #GNUNET_OK to continue (always) */ static int -fip_signal_stop (void *cls, - struct GNUNET_FS_FileInformation *fi, - uint64_t length, - struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, - int *do_index, void **client_info) +fip_signal_stop(void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; uint64_t off; if (GNUNET_YES == pc->skip_next_fi_callback) - { - pc->skip_next_fi_callback = GNUNET_NO; - return GNUNET_OK; - } - if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) - { - /* process entries in directory first */ - pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (fi, &fip_signal_stop, pc); - } + { + pc->skip_next_fi_callback = GNUNET_NO; + return GNUNET_OK; + } + if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) + { + /* process entries in directory first */ + pc->skip_next_fi_callback = GNUNET_YES; + GNUNET_FS_file_information_inspect(fi, &fip_signal_stop, pc); + } if (NULL != fi->serialization) - { - GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, - fi->serialization); - GNUNET_free (fi->serialization); - fi->serialization = NULL; - } + { + GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, + fi->serialization); + GNUNET_free(fi->serialization); + fi->serialization = NULL; + } off = (fi->chk_uri == NULL) ? 0 : length; pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; - GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); + GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); *client_info = NULL; return GNUNET_OK; } @@ -1555,56 +1552,56 @@ fip_signal_stop (void *cls, * @param pc context for the upload to stop */ void -GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) +GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc) { struct GNUNET_FS_ProgressInfo pi; uint64_t off; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish stop called\n"); - GNUNET_FS_end_top (pc->h, pc->top); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish stop called\n"); + GNUNET_FS_end_top(pc->h, pc->top); if (NULL != pc->ksk_pc) - { - GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); - pc->ksk_pc = NULL; - } + { + GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); + pc->ksk_pc = NULL; + } if (NULL != pc->sks_pc) - { - GNUNET_FS_publish_sks_cancel (pc->sks_pc); - pc->sks_pc = NULL; - } + { + GNUNET_FS_publish_sks_cancel(pc->sks_pc); + pc->sks_pc = NULL; + } if (NULL != pc->upload_task) - { - GNUNET_SCHEDULER_cancel (pc->upload_task); - pc->upload_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(pc->upload_task); + pc->upload_task = NULL; + } pc->skip_next_fi_callback = GNUNET_YES; - GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc); + GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_stop, pc); if (NULL != pc->fi->serialization) - { - GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, - pc->fi->serialization); - GNUNET_free (pc->fi->serialization); - pc->fi->serialization = NULL; - } - off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll (pc->fi->chk_uri->data.chk.file_length); + { + GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, + pc->fi->serialization); + GNUNET_free(pc->fi->serialization); + pc->fi->serialization = NULL; + } + off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll(pc->fi->chk_uri->data.chk.file_length); if (NULL != pc->serialization) - { - GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, - pc->serialization); - GNUNET_free (pc->serialization); - pc->serialization = NULL; - } + { + GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + pc->serialization); + GNUNET_free(pc->serialization); + pc->serialization = NULL; + } if (NULL != pc->qre) - { - GNUNET_DATASTORE_cancel (pc->qre); - pc->qre = NULL; - } + { + GNUNET_DATASTORE_cancel(pc->qre); + pc->qre = NULL; + } pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; - GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi, off)); - publish_cleanup (pc); + GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, pc->fi, off)); + publish_cleanup(pc); } diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c index e7f6408fd..151b8256c 100644 --- a/src/fs/fs_publish_ksk.c +++ b/src/fs/fs_publish_ksk.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_publish_ksk.c @@ -38,9 +38,7 @@ /** * Context for the KSK publication. */ -struct GNUNET_FS_PublishKskContext -{ - +struct GNUNET_FS_PublishKskContext { /** * Keywords to use. */ @@ -100,7 +98,6 @@ struct GNUNET_FS_PublishKskContext * Keyword that we are currently processing. */ unsigned int i; - }; @@ -112,7 +109,7 @@ struct GNUNET_FS_PublishKskContext * @param cls closure of type `struct PublishKskContext *` */ static void -publish_ksk_cont (void *cls); +publish_ksk_cont(void *cls); /** @@ -123,21 +120,21 @@ publish_ksk_cont (void *cls); * @param msg error message (or NULL) */ static void -kb_put_cont (void *cls, - const char *msg) +kb_put_cont(void *cls, + const char *msg) { struct GNUNET_FS_PublishKskContext *pkc = cls; pkc->uc = NULL; if (NULL != msg) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "KBlock PUT operation failed: %s\n", msg); - pkc->cont (pkc->cont_cls, NULL, msg); - GNUNET_FS_publish_ksk_cancel (pkc); - return; - } - pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "KBlock PUT operation failed: %s\n", msg); + pkc->cont(pkc->cont_cls, NULL, msg); + GNUNET_FS_publish_ksk_cancel(pkc); + return; + } + pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); } @@ -148,33 +145,33 @@ kb_put_cont (void *cls, * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` */ static void -publish_ksk_cont (void *cls) +publish_ksk_cont(void *cls) { struct GNUNET_FS_PublishKskContext *pkc = cls; const char *keyword; pkc->ksk_task = NULL; - if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || - (NULL == pkc->dsh) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "KSK PUT operation complete\n"); - pkc->cont (pkc->cont_cls, pkc->ksk_uri, - NULL); - GNUNET_FS_publish_ksk_cancel (pkc); - return; - } + if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || + (NULL == pkc->dsh)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "KSK PUT operation complete\n"); + pkc->cont(pkc->cont_cls, pkc->ksk_uri, + NULL); + GNUNET_FS_publish_ksk_cancel(pkc); + return; + } keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; - pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h, - pkc->dsh, - keyword + 1 /* skip '+' */, - NULL, - GNUNET_CRYPTO_ecdsa_key_get_anonymous (), - pkc->meta, - pkc->uri, - &pkc->bo, - pkc->options, - &kb_put_cont, pkc); + pkc->uc = GNUNET_FS_publish_ublock_(pkc->h, + pkc->dsh, + keyword + 1 /* skip '+' */, + NULL, + GNUNET_CRYPTO_ecdsa_key_get_anonymous(), + pkc->meta, + pkc->uri, + &pkc->bo, + pkc->options, + &kb_put_cont, pkc); } @@ -192,39 +189,39 @@ publish_ksk_cont (void *cls) * @return NULL on error ('cont' will still be called) */ struct GNUNET_FS_PublishKskContext * -GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *ksk_uri, - const struct GNUNET_CONTAINER_MetaData *meta, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_FS_BlockOptions *bo, - enum GNUNET_FS_PublishOptions options, - GNUNET_FS_PublishContinuation cont, void *cont_cls) +GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *ksk_uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_PublishContinuation cont, void *cont_cls) { struct GNUNET_FS_PublishKskContext *pkc; - GNUNET_assert (NULL != uri); - pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext); + GNUNET_assert(NULL != uri); + pkc = GNUNET_new(struct GNUNET_FS_PublishKskContext); pkc->h = h; pkc->bo = *bo; pkc->options = options; pkc->cont = cont; pkc->cont_cls = cont_cls; - pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); + pkc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) - { - pkc->dsh = GNUNET_DATASTORE_connect (h->cfg); - if (NULL == pkc->dsh) { - cont (cont_cls, - NULL, - _("Could not connect to datastore.")); - GNUNET_free (pkc); - return NULL; + pkc->dsh = GNUNET_DATASTORE_connect(h->cfg); + if (NULL == pkc->dsh) + { + cont(cont_cls, + NULL, + _("Could not connect to datastore.")); + GNUNET_free(pkc); + return NULL; + } } - } - pkc->uri = GNUNET_FS_uri_dup (uri); - pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); - pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); + pkc->uri = GNUNET_FS_uri_dup(uri); + pkc->ksk_uri = GNUNET_FS_uri_dup(ksk_uri); + pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); return pkc; } @@ -235,27 +232,27 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, * @param pkc context of the operation to abort. */ void -GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc) +GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc) { if (NULL != pkc->ksk_task) - { - GNUNET_SCHEDULER_cancel (pkc->ksk_task); - pkc->ksk_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(pkc->ksk_task); + pkc->ksk_task = NULL; + } if (NULL != pkc->uc) - { - GNUNET_FS_publish_ublock_cancel_ (pkc->uc); - pkc->uc = NULL; - } + { + GNUNET_FS_publish_ublock_cancel_(pkc->uc); + pkc->uc = NULL; + } if (NULL != pkc->dsh) - { - GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); - pkc->dsh = NULL; - } - GNUNET_CONTAINER_meta_data_destroy (pkc->meta); - GNUNET_FS_uri_destroy (pkc->ksk_uri); - GNUNET_FS_uri_destroy (pkc->uri); - GNUNET_free (pkc); + { + GNUNET_DATASTORE_disconnect(pkc->dsh, GNUNET_NO); + pkc->dsh = NULL; + } + GNUNET_CONTAINER_meta_data_destroy(pkc->meta); + GNUNET_FS_uri_destroy(pkc->ksk_uri); + GNUNET_FS_uri_destroy(pkc->uri); + GNUNET_free(pkc); } diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index 368a4aff4..4dfb4a585 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_publish_ublock.c @@ -43,21 +43,21 @@ * @param pub public key to use for key derivation */ static void -derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, - struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, - const char *label, - const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) +derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, + struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, + const char *label, + const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) { struct GNUNET_HashCode key; /* derive key from 'label' and public key of the namespace */ - GNUNET_assert (GNUNET_YES == - GNUNET_CRYPTO_kdf (&key, sizeof (key), - "UBLOCK-ENC", strlen ("UBLOCK-ENC"), - label, strlen (label), - pub, sizeof (*pub), - NULL, 0)); - GNUNET_CRYPTO_hash_to_aes_key (&key, skey, iv); + GNUNET_assert(GNUNET_YES == + GNUNET_CRYPTO_kdf(&key, sizeof(key), + "UBLOCK-ENC", strlen("UBLOCK-ENC"), + label, strlen(label), + pub, sizeof(*pub), + NULL, 0)); + GNUNET_CRYPTO_hash_to_aes_key(&key, skey, iv); } @@ -71,29 +71,27 @@ derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, * @param output where to write the result, has input_len bytes */ void -GNUNET_FS_ublock_decrypt_ (const void *input, - size_t input_len, - const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, - const char *label, - void *output) +GNUNET_FS_ublock_decrypt_(const void *input, + size_t input_len, + const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, + const char *label, + void *output) { struct GNUNET_CRYPTO_SymmetricInitializationVector iv; struct GNUNET_CRYPTO_SymmetricSessionKey skey; - derive_ublock_encryption_key (&skey, &iv, - label, ns); - GNUNET_CRYPTO_symmetric_decrypt (input, input_len, - &skey, &iv, - output); + derive_ublock_encryption_key(&skey, &iv, + label, ns); + GNUNET_CRYPTO_symmetric_decrypt(input, input_len, + &skey, &iv, + output); } /** * Context for 'ublock_put_cont'. */ -struct GNUNET_FS_PublishUblockContext -{ - +struct GNUNET_FS_PublishUblockContext { /** * Function to call when done. */ @@ -113,7 +111,6 @@ struct GNUNET_FS_PublishUblockContext * Task to run continuation asynchronously. */ struct GNUNET_SCHEDULER_Task * task; - }; @@ -130,16 +127,16 @@ struct GNUNET_FS_PublishUblockContext * @param msg NULL on success, otherwise an error message */ static void -ublock_put_cont (void *cls, - int32_t success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +ublock_put_cont(void *cls, + int32_t success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_PublishUblockContext *uc = cls; uc->qre = NULL; - uc->cont (uc->cont_cls, msg); - GNUNET_free (uc); + uc->cont(uc->cont_cls, msg); + GNUNET_free(uc); } @@ -149,13 +146,13 @@ ublock_put_cont (void *cls, * @param cls the `struct GNUNET_FS_PublishUblockContext *` */ static void -run_cont (void *cls) +run_cont(void *cls) { struct GNUNET_FS_PublishUblockContext *uc = cls; uc->task = NULL; - uc->cont (uc->cont_cls, NULL); - GNUNET_free (uc); + uc->cont(uc->cont_cls, NULL); + GNUNET_free(uc); } @@ -176,16 +173,16 @@ run_cont (void *cls) * @return NULL on error (@a cont will still be called) */ struct GNUNET_FS_PublishUblockContext * -GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, - struct GNUNET_DATASTORE_Handle *dsh, - const char *label, - const char *ulabel, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const struct GNUNET_CONTAINER_MetaData *meta, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_FS_BlockOptions *bo, - enum GNUNET_FS_PublishOptions options, - GNUNET_FS_UBlockContinuation cont, void *cont_cls) +GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, + struct GNUNET_DATASTORE_Handle *dsh, + const char *label, + const char *ulabel, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_UBlockContinuation cont, void *cont_cls) { struct GNUNET_FS_PublishUblockContext *uc; struct GNUNET_HashCode query; @@ -207,101 +204,101 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, if (NULL == meta) mdsize = 0; else - mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); - GNUNET_assert (mdsize >= 0); - uris = GNUNET_FS_uri_to_string (uri); - slen = strlen (uris) + 1; + mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); + GNUNET_assert(mdsize >= 0); + uris = GNUNET_FS_uri_to_string(uri); + slen = strlen(uris) + 1; if (NULL == ulabel) ulen = 1; else - ulen = strlen (ulabel) + 1; - size = mdsize + sizeof (struct UBlock) + slen + ulen; + ulen = strlen(ulabel) + 1; + size = mdsize + sizeof(struct UBlock) + slen + ulen; if (size > MAX_UBLOCK_SIZE) - { - size = MAX_UBLOCK_SIZE; - mdsize = size - sizeof (struct UBlock) - (slen + ulen); - } - ub_plain = GNUNET_malloc (size); - kbe = (char *) &ub_plain[1]; + { + size = MAX_UBLOCK_SIZE; + mdsize = size - sizeof(struct UBlock) - (slen + ulen); + } + ub_plain = GNUNET_malloc(size); + kbe = (char *)&ub_plain[1]; if (NULL != ulabel) - GNUNET_memcpy (kbe, ulabel, ulen); + GNUNET_memcpy(kbe, ulabel, ulen); kbe += ulen; - GNUNET_memcpy (kbe, uris, slen); + GNUNET_memcpy(kbe, uris, slen); kbe += slen; - GNUNET_free (uris); + GNUNET_free(uris); sptr = kbe; if (NULL != meta) mdsize = - GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, mdsize, - GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); + GNUNET_CONTAINER_meta_data_serialize(meta, &sptr, mdsize, + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); if (-1 == mdsize) - { - GNUNET_break (0); - GNUNET_free (ub_plain); - cont (cont_cls, _("Internal error.")); - return NULL; - } - size = sizeof (struct UBlock) + slen + mdsize + ulen; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publishing under identifier `%s'\n", - label); + { + GNUNET_break(0); + GNUNET_free(ub_plain); + cont(cont_cls, _("Internal error.")); + return NULL; + } + size = sizeof(struct UBlock) + slen + mdsize + ulen; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publishing under identifier `%s'\n", + label); /* get public key of the namespace */ - GNUNET_CRYPTO_ecdsa_key_get_public (ns, - &pub); - derive_ublock_encryption_key (&skey, &iv, - label, &pub); + GNUNET_CRYPTO_ecdsa_key_get_public(ns, + &pub); + derive_ublock_encryption_key(&skey, &iv, + label, &pub); /* encrypt ublock */ - ub_enc = GNUNET_malloc (size); - GNUNET_CRYPTO_symmetric_encrypt (&ub_plain[1], - ulen + slen + mdsize, - &skey, &iv, - &ub_enc[1]); - GNUNET_free (ub_plain); - ub_enc->purpose.size = htonl (ulen + slen + mdsize + - sizeof (struct UBlock) - - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); - ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); + ub_enc = GNUNET_malloc(size); + GNUNET_CRYPTO_symmetric_encrypt(&ub_plain[1], + ulen + slen + mdsize, + &skey, &iv, + &ub_enc[1]); + GNUNET_free(ub_plain); + ub_enc->purpose.size = htonl(ulen + slen + mdsize + + sizeof(struct UBlock) + - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); + ub_enc->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); /* derive signing-key from 'label' and public key of the namespace */ - nsd = GNUNET_CRYPTO_ecdsa_private_key_derive (ns, label, "fs-ublock"); - GNUNET_CRYPTO_ecdsa_key_get_public (nsd, - &ub_enc->verification_key); - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_ecdsa_sign (nsd, - &ub_enc->purpose, - &ub_enc->signature)); - GNUNET_CRYPTO_hash (&ub_enc->verification_key, - sizeof (ub_enc->verification_key), - &query); - GNUNET_free (nsd); - - uc = GNUNET_new (struct GNUNET_FS_PublishUblockContext); + nsd = GNUNET_CRYPTO_ecdsa_private_key_derive(ns, label, "fs-ublock"); + GNUNET_CRYPTO_ecdsa_key_get_public(nsd, + &ub_enc->verification_key); + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_ecdsa_sign(nsd, + &ub_enc->purpose, + &ub_enc->signature)); + GNUNET_CRYPTO_hash(&ub_enc->verification_key, + sizeof(ub_enc->verification_key), + &query); + GNUNET_free(nsd); + + uc = GNUNET_new(struct GNUNET_FS_PublishUblockContext); uc->cont = cont; uc->cont_cls = cont_cls; if (NULL != dsh) - { - uc->qre = - GNUNET_DATASTORE_put (dsh, - 0, - &query, - ulen + slen + mdsize + sizeof (struct UBlock), - ub_enc, - GNUNET_BLOCK_TYPE_FS_UBLOCK, - bo->content_priority, - bo->anonymity_level, - bo->replication_level, - bo->expiration_time, - -2, 1, - &ublock_put_cont, uc); - } + { + uc->qre = + GNUNET_DATASTORE_put(dsh, + 0, + &query, + ulen + slen + mdsize + sizeof(struct UBlock), + ub_enc, + GNUNET_BLOCK_TYPE_FS_UBLOCK, + bo->content_priority, + bo->anonymity_level, + bo->replication_level, + bo->expiration_time, + -2, 1, + &ublock_put_cont, uc); + } else - { - uc->task = GNUNET_SCHEDULER_add_now (&run_cont, - uc); - } - GNUNET_free (ub_enc); + { + uc->task = GNUNET_SCHEDULER_add_now(&run_cont, + uc); + } + GNUNET_free(ub_enc); return uc; } @@ -312,13 +309,13 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, * @param uc operation to abort. */ void -GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc) +GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc) { if (NULL != uc->qre) - GNUNET_DATASTORE_cancel (uc->qre); + GNUNET_DATASTORE_cancel(uc->qre); if (NULL != uc->task) - GNUNET_SCHEDULER_cancel (uc->task); - GNUNET_free (uc); + GNUNET_SCHEDULER_cancel(uc->task); + GNUNET_free(uc); } /* end of fs_publish_ublock.c */ diff --git a/src/fs/fs_publish_ublock.h b/src/fs/fs_publish_ublock.h index ad07e5f6f..9d0a518c6 100644 --- a/src/fs/fs_publish_ublock.h +++ b/src/fs/fs_publish_ublock.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_publish_ublock.h @@ -44,11 +44,11 @@ * @param output where to write the result, has input_len bytes */ void -GNUNET_FS_ublock_decrypt_ (const void *input, - size_t input_len, - const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, - const char *label, - void *output); +GNUNET_FS_ublock_decrypt_(const void *input, + size_t input_len, + const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, + const char *label, + void *output); /** @@ -65,7 +65,7 @@ struct GNUNET_FS_PublishUblockContext; * @param emsg error message, NULL on success */ typedef void (*GNUNET_FS_UBlockContinuation) (void *cls, - const char *emsg); + const char *emsg); /** @@ -85,16 +85,16 @@ typedef void (*GNUNET_FS_UBlockContinuation) (void *cls, * @return NULL on error ('cont' will still be called) */ struct GNUNET_FS_PublishUblockContext * -GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, - struct GNUNET_DATASTORE_Handle *dsh, - const char *label, - const char *ulabel, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const struct GNUNET_CONTAINER_MetaData *meta, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_FS_BlockOptions *bo, - enum GNUNET_FS_PublishOptions options, - GNUNET_FS_UBlockContinuation cont, void *cont_cls); +GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, + struct GNUNET_DATASTORE_Handle *dsh, + const char *label, + const char *ulabel, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_UBlockContinuation cont, void *cont_cls); /** @@ -103,6 +103,6 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, * @param uc operation to abort. */ void -GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc); +GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc); #endif diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index e808d3eaa..662bc1619 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_search.c * @brief Helper functions for searching. @@ -45,9 +45,9 @@ * @return value returned by the callback */ void * -GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_Handle *h, - struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_Handle *h, + struct GNUNET_FS_SearchContext *sc) { void *ret; @@ -59,11 +59,11 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, : sc->psearch_result->client_info; pi->value.search.query = (NULL != sc) ? sc->uri : NULL; pi->value.search.duration = (NULL != sc) - ? GNUNET_TIME_absolute_get_duration (sc->start_time) - : GNUNET_TIME_UNIT_ZERO; + ? GNUNET_TIME_absolute_get_duration(sc->start_time) + : GNUNET_TIME_UNIT_ZERO; pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0; pi->fsh = h; - ret = h->upcb (h->upcb_cls, pi); + ret = h->upcb(h->upcb_cls, pi); return ret; } @@ -79,14 +79,14 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * #GNUNET_OK otherwise */ static int -test_result_present (void *cls, - const struct GNUNET_HashCode * key, - void *value) +test_result_present(void *cls, + const struct GNUNET_HashCode * key, + void *value) { const struct GNUNET_FS_Uri *uri = cls; struct GNUNET_FS_SearchResult *sr = value; - if (GNUNET_FS_uri_test_equal (uri, sr->uri)) + if (GNUNET_FS_uri_test_equal(uri, sr->uri)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -100,8 +100,8 @@ test_result_present (void *cls, * @param sr the specific result */ static void -notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, - struct GNUNET_FS_SearchResult *sr) +notify_client_chk_result(struct GNUNET_FS_SearchContext *sc, + struct GNUNET_FS_SearchResult *sr) { struct GNUNET_FS_ProgressInfo pi; @@ -110,7 +110,7 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, pi.value.search.specifics.result.uri = sr->uri; pi.value.search.specifics.result.result = sr; pi.value.search.specifics.result.applicability_rank = sr->optional_support; - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); + sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); } @@ -122,8 +122,8 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, * @param sr the specific result */ static void -notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, - struct GNUNET_FS_SearchResult *sr) +notify_client_chk_update(struct GNUNET_FS_SearchContext *sc, + struct GNUNET_FS_SearchResult *sr) { struct GNUNET_FS_ProgressInfo pi; @@ -132,21 +132,20 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, pi.value.search.specifics.update.meta = sr->meta; pi.value.search.specifics.update.uri = sr->uri; pi.value.search.specifics.update.availability_rank = - 2 * sr->availability_success - sr->availability_trials; + 2 * sr->availability_success - sr->availability_trials; pi.value.search.specifics.update.availability_certainty = - sr->availability_trials; + sr->availability_trials; pi.value.search.specifics.update.applicability_rank = sr->optional_support; pi.value.search.specifics.update.current_probe_time - = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); + = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); + sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); } /** * Context for "get_result_present". */ -struct GetResultContext -{ +struct GetResultContext { /** * The URI we're looking for. */ @@ -171,14 +170,14 @@ struct GetResultContext * @return #GNUNET_OK */ static int -get_result_present (void *cls, - const struct GNUNET_HashCode *key, - void *value) +get_result_present(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GetResultContext *grc = cls; struct GNUNET_FS_SearchResult *sr = value; - if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri)) + if (GNUNET_FS_uri_test_equal(grc->uri, sr->uri)) grc->sr = sr; return GNUNET_OK; } @@ -191,7 +190,7 @@ get_result_present (void *cls, * @param sr search result to signal for */ static void -signal_probe_result (struct GNUNET_FS_SearchResult *sr) +signal_probe_result(struct GNUNET_FS_SearchResult *sr) { struct GNUNET_FS_ProgressInfo pi; @@ -205,9 +204,9 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) = sr->availability_trials; pi.value.search.specifics.update.applicability_rank = sr->optional_support; pi.value.search.specifics.update.current_probe_time - = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sr->sc); - GNUNET_FS_search_start_probe_ (sr); + = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); + sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sr->sc); + GNUNET_FS_search_start_probe_(sr); } @@ -217,21 +216,21 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) * @param cls our `struct GNUNET_FS_SearchResult *` */ static void -probe_failure_handler (void *cls) +probe_failure_handler(void *cls) { struct GNUNET_FS_SearchResult *sr = cls; sr->probe_cancel_task = NULL; sr->availability_trials++; - GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); + GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); sr->probe_ctx = NULL; - GNUNET_FS_stop_probe_ping_task_ (sr); - GNUNET_FS_search_result_sync_ (sr); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Probe #%u for search result %p failed\n", - sr->availability_trials, - sr); - signal_probe_result (sr); + GNUNET_FS_stop_probe_ping_task_(sr); + GNUNET_FS_search_result_sync_(sr); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Probe #%u for search result %p failed\n", + sr->availability_trials, + sr); + signal_probe_result(sr); } @@ -241,22 +240,22 @@ probe_failure_handler (void *cls) * @param cls our `struct GNUNET_FS_SearchResult *` */ static void -probe_success_handler (void *cls) +probe_success_handler(void *cls) { struct GNUNET_FS_SearchResult *sr = cls; sr->probe_cancel_task = NULL; sr->availability_trials++; sr->availability_success++; - GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); + GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); sr->probe_ctx = NULL; - GNUNET_FS_stop_probe_ping_task_ (sr); - GNUNET_FS_search_result_sync_ (sr); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Probe #%u for search result %p succeeded\n", - sr->availability_trials, - sr); - signal_probe_result (sr); + GNUNET_FS_stop_probe_ping_task_(sr); + GNUNET_FS_search_result_sync_(sr); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Probe #%u for search result %p succeeded\n", + sr->availability_trials, + sr); + signal_probe_result(sr); } @@ -276,82 +275,91 @@ probe_success_handler (void *cls) * field in the `struct GNUNET_FS_ProgressInfo`. */ void * -GNUNET_FS_search_probe_progress_ (void *cls, - const struct GNUNET_FS_ProgressInfo *info) +GNUNET_FS_search_probe_progress_(void *cls, + const struct GNUNET_FS_ProgressInfo *info) { struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; struct GNUNET_TIME_Relative dur; switch (info->status) - { - case GNUNET_FS_STATUS_DOWNLOAD_START: - /* ignore */ - break; - case GNUNET_FS_STATUS_DOWNLOAD_RESUME: - /* probes should never be resumed */ - GNUNET_assert (0); - break; - case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: - /* probes should never be suspended */ - GNUNET_break (0); - break; - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - /* ignore */ - break; - case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } - sr->probe_cancel_task = - GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, - &probe_failure_handler, sr); - break; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } - sr->probe_cancel_task = - GNUNET_SCHEDULER_add_now (&probe_success_handler, sr); - break; - case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: - if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } - sr = NULL; - break; - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - if (NULL == sr->probe_cancel_task) { - sr->probe_active_time = GNUNET_TIME_absolute_get (); + case GNUNET_FS_STATUS_DOWNLOAD_START: + /* ignore */ + break; + + case GNUNET_FS_STATUS_DOWNLOAD_RESUME: + /* probes should never be resumed */ + GNUNET_assert(0); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: + /* probes should never be suspended */ + GNUNET_break(0); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + /* ignore */ + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + if (NULL != sr->probe_cancel_task) + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } sr->probe_cancel_task = - GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, - &probe_failure_handler, sr); - } - break; - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } - dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); - sr->remaining_probe_time = - GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur); - if (0 == sr->remaining_probe_time.rel_value_us) + GNUNET_SCHEDULER_add_delayed(sr->remaining_probe_time, + &probe_failure_handler, sr); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + if (NULL != sr->probe_cancel_task) + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } sr->probe_cancel_task = - GNUNET_SCHEDULER_add_now (&probe_failure_handler, sr); - GNUNET_FS_search_result_sync_ (sr); - break; - default: - GNUNET_break (0); - return NULL; - } + GNUNET_SCHEDULER_add_now(&probe_success_handler, sr); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + if (NULL != sr->probe_cancel_task) + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } + sr = NULL; + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + if (NULL == sr->probe_cancel_task) + { + sr->probe_active_time = GNUNET_TIME_absolute_get(); + sr->probe_cancel_task = + GNUNET_SCHEDULER_add_delayed(sr->remaining_probe_time, + &probe_failure_handler, sr); + } + break; + + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + if (NULL != sr->probe_cancel_task) + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } + dur = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); + sr->remaining_probe_time = + GNUNET_TIME_relative_subtract(sr->remaining_probe_time, dur); + if (0 == sr->remaining_probe_time.rel_value_us) + sr->probe_cancel_task = + GNUNET_SCHEDULER_add_now(&probe_failure_handler, sr); + GNUNET_FS_search_result_sync_(sr); + break; + + default: + GNUNET_break(0); + return NULL; + } return sr; } @@ -362,18 +370,18 @@ GNUNET_FS_search_probe_progress_ (void *cls, * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for */ static void -probe_ping_task_cb (void *cls) +probe_ping_task_cb(void *cls) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_FS_SearchResult *sr; for (sr = h->probes_head; NULL != sr; sr = sr->next) if (NULL != sr->probe_ctx->mq) - signal_probe_result (sr); + signal_probe_result(sr); h->probe_ping_task - = GNUNET_SCHEDULER_add_delayed (GNUNET_FS_PROBE_UPDATE_FREQUENCY, - &probe_ping_task_cb, - h); + = GNUNET_SCHEDULER_add_delayed(GNUNET_FS_PROBE_UPDATE_FREQUENCY, + &probe_ping_task_cb, + h); } @@ -383,17 +391,17 @@ probe_ping_task_cb (void *cls) * @param sr result to start pinging for. */ static void -start_probe_ping_task (struct GNUNET_FS_SearchResult *sr) +start_probe_ping_task(struct GNUNET_FS_SearchResult *sr) { struct GNUNET_FS_Handle *h = sr->h; - GNUNET_CONTAINER_DLL_insert (h->probes_head, - h->probes_tail, - sr); + GNUNET_CONTAINER_DLL_insert(h->probes_head, + h->probes_tail, + sr); if (NULL == h->probe_ping_task) h->probe_ping_task - = GNUNET_SCHEDULER_add_now (&probe_ping_task_cb, - h); + = GNUNET_SCHEDULER_add_now(&probe_ping_task_cb, + h); } @@ -403,18 +411,18 @@ start_probe_ping_task (struct GNUNET_FS_SearchResult *sr) * @param sr result to start pinging for. */ void -GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr) +GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr) { struct GNUNET_FS_Handle *h = sr->h; - GNUNET_CONTAINER_DLL_remove (h->probes_head, - h->probes_tail, - sr); + GNUNET_CONTAINER_DLL_remove(h->probes_head, + h->probes_tail, + sr); if (NULL == h->probes_head) - { - GNUNET_SCHEDULER_cancel (h->probe_ping_task); - h->probe_ping_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(h->probe_ping_task); + h->probe_ping_task = NULL; + } } @@ -424,7 +432,7 @@ GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr) * @param sr the search result */ void -GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) +GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr) { uint64_t off; uint64_t len; @@ -437,35 +445,35 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) return; if (sr->availability_trials > AVAILABILITY_TRIALS_MAX) return; - if ( (GNUNET_FS_URI_CHK != sr->uri->type) && (GNUNET_FS_URI_LOC != sr->uri->type)) + if ((GNUNET_FS_URI_CHK != sr->uri->type) && (GNUNET_FS_URI_LOC != sr->uri->type)) return; - len = GNUNET_FS_uri_chk_get_file_size (sr->uri); + len = GNUNET_FS_uri_chk_get_file_size(sr->uri); if (0 == len) return; if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) return; off = len / DBLOCK_SIZE; if (off > 0) - off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, off); + off = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, off); off *= DBLOCK_SIZE; if (len - off < DBLOCK_SIZE) len = len - off; else len = DBLOCK_SIZE; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting probe #%u (at offset %llu) for search result %p\n", - sr->availability_trials + 1, - (unsigned long long) off, - sr); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting probe #%u (at offset %llu) for search result %p\n", + sr->availability_trials + 1, + (unsigned long long)off, + sr); sr->remaining_probe_time = - GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency, - 2 * (1 + sr->availability_trials)); + GNUNET_TIME_relative_saturating_multiply(sr->h->avg_block_latency, + 2 * (1 + sr->availability_trials)); sr->probe_ctx = - GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, - len, sr->anonymity, - GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | - GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); - start_probe_ping_task (sr); + GNUNET_FS_download_start(sr->h, sr->uri, sr->meta, NULL, NULL, off, + len, sr->anonymity, + GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | + GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); + start_probe_ping_task(sr); } @@ -480,23 +488,23 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) * @return the search result handle to access the probe activity */ struct GNUNET_FS_SearchResult * -GNUNET_FS_probe (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - void *client_info, - uint32_t anonymity) +GNUNET_FS_probe(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + void *client_info, + uint32_t anonymity) { struct GNUNET_FS_SearchResult *sr; - GNUNET_assert (NULL != h); - GNUNET_assert (NULL != uri); - sr = GNUNET_new (struct GNUNET_FS_SearchResult); + GNUNET_assert(NULL != h); + GNUNET_assert(NULL != uri); + sr = GNUNET_new(struct GNUNET_FS_SearchResult); sr->h = h; - sr->uri = GNUNET_FS_uri_dup (uri); - sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); + sr->uri = GNUNET_FS_uri_dup(uri); + sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); sr->client_info = client_info; sr->anonymity = anonymity; - GNUNET_FS_search_start_probe_ (sr); + GNUNET_FS_search_start_probe_(sr); return sr; } @@ -507,19 +515,19 @@ GNUNET_FS_probe (struct GNUNET_FS_Handle *h, * @param sr search result */ static void -GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr) +GNUNET_FS_search_stop_probe_(struct GNUNET_FS_SearchResult *sr) { if (NULL != sr->probe_ctx) - { - GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); - sr->probe_ctx = NULL; - GNUNET_FS_stop_probe_ping_task_ (sr); - } + { + GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); + sr->probe_ctx = NULL; + GNUNET_FS_stop_probe_ping_task_(sr); + } if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } } @@ -531,16 +539,16 @@ GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr) * @return the value of the 'client_info' pointer */ void * -GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr) +GNUNET_FS_probe_stop(struct GNUNET_FS_SearchResult *sr) { void *client_info; - GNUNET_assert (NULL == sr->sc); - GNUNET_FS_search_stop_probe_ (sr); - GNUNET_FS_uri_destroy (sr->uri); - GNUNET_CONTAINER_meta_data_destroy (sr->meta); + GNUNET_assert(NULL == sr->sc); + GNUNET_FS_search_stop_probe_(sr); + GNUNET_FS_uri_destroy(sr->uri); + GNUNET_CONTAINER_meta_data_destroy(sr->meta); client_info = sr->client_info; - GNUNET_free (sr); + GNUNET_free(sr); return client_info; } @@ -556,10 +564,10 @@ GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr) * under the @a ent keyword */ static void -process_ksk_result (struct GNUNET_FS_SearchContext *sc, - struct SearchRequestEntry *ent, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta) +process_ksk_result(struct GNUNET_FS_SearchContext *sc, + struct SearchRequestEntry *ent, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta) { struct GNUNET_HashCode key; struct GNUNET_FS_SearchResult *sr; @@ -568,80 +576,80 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, unsigned int koff; /* check if new */ - GNUNET_assert (NULL != sc); + GNUNET_assert(NULL != sc); if (GNUNET_OK != - GNUNET_FS_uri_to_key (uri, - &key)) - { - GNUNET_break_op (0); - return; - } + GNUNET_FS_uri_to_key(uri, + &key)) + { + GNUNET_break_op(0); + return; + } if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, - &key, - &test_result_present, - (void *) uri)) + GNUNET_CONTAINER_multihashmap_get_multiple(ent->results, + &key, + &test_result_present, + (void *)uri)) return; /* duplicate result */ /* try to find search result in master map */ grc.sr = NULL; grc.uri = uri; - GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, - &key, - &get_result_present, &grc); + GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, + &key, + &get_result_present, &grc); sr = grc.sr; is_new = (NULL == sr) || (sr->mandatory_missing > 0); if (NULL == sr) - { - sr = GNUNET_new (struct GNUNET_FS_SearchResult); - sr->h = sc->h; - sr->sc = sc; - sr->anonymity = sc->anonymity; - sr->uri = GNUNET_FS_uri_dup (uri); - sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); - sr->mandatory_missing = sc->mandatory_count; - sr->key = key; - sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ - GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - } + { + sr = GNUNET_new(struct GNUNET_FS_SearchResult); + sr->h = sc->h; + sr->sc = sc; + sr->anonymity = sc->anonymity; + sr->uri = GNUNET_FS_uri_dup(uri); + sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); + sr->mandatory_missing = sc->mandatory_count; + sr->key = key; + sr->keyword_bitmap = GNUNET_malloc((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ + GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + } else - { - GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); - } - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (ent->results, - &sr->key, - sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + { + GNUNET_CONTAINER_meta_data_merge(sr->meta, meta); + } + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(ent->results, + &sr->key, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); koff = ent - sc->requests; - GNUNET_assert ( (ent >= sc->requests) && - (koff < sc->uri->data.ksk.keywordCount)); + GNUNET_assert((ent >= sc->requests) && + (koff < sc->uri->data.ksk.keywordCount)); sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8)); /* check if mandatory satisfied */ - if (1 <= GNUNET_CONTAINER_multihashmap_size (ent->results)) - { - if (ent->mandatory) + if (1 <= GNUNET_CONTAINER_multihashmap_size(ent->results)) { - GNUNET_break (sr->mandatory_missing > 0); - sr->mandatory_missing--; + if (ent->mandatory) + { + GNUNET_break(sr->mandatory_missing > 0); + sr->mandatory_missing--; + } + else + { + sr->optional_support++; + } } - else + if (0 != sr->mandatory_missing) { - sr->optional_support++; + GNUNET_break(NULL == sr->client_info); + return; } - } - if (0 != sr->mandatory_missing) - { - GNUNET_break (NULL == sr->client_info); - return; - } if (is_new) - notify_client_chk_result (sc, sr); + notify_client_chk_result(sc, sr); else - notify_client_chk_update (sc, sr); - GNUNET_FS_search_result_sync_ (sr); - GNUNET_FS_search_start_probe_ (sr); + notify_client_chk_update(sc, sr); + GNUNET_FS_search_result_sync_(sr); + GNUNET_FS_search_start_probe_(sr); } @@ -658,12 +666,12 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, * @return context that can be used to control the search */ static struct GNUNET_FS_SearchContext * -search_start (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - uint32_t anonymity, - enum GNUNET_FS_SearchOptions options, - void *cctx, - struct GNUNET_FS_SearchResult *psearch); +search_start(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + uint32_t anonymity, + enum GNUNET_FS_SearchOptions options, + void *cctx, + struct GNUNET_FS_SearchResult *psearch); /** @@ -674,58 +682,58 @@ search_start (struct GNUNET_FS_Handle *h, * @param id_update identifier for updates, NULL for none * @param uri the URI that was found * @param meta metadata associated with the URI - */ + */ static void -process_sks_result (struct GNUNET_FS_SearchContext *sc, - const char *id_update, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta) +process_sks_result(struct GNUNET_FS_SearchContext *sc, + const char *id_update, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta) { struct GNUNET_FS_Uri uu; struct GNUNET_HashCode key; struct GNUNET_FS_SearchResult *sr; /* check if new */ - GNUNET_assert (NULL != sc); + GNUNET_assert(NULL != sc); if (GNUNET_OK != - GNUNET_FS_uri_to_key (uri, - &key)) - { - GNUNET_break (0); - return; - } - GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, - &uri->data.chk.chk.query, - &key); + GNUNET_FS_uri_to_key(uri, + &key)) + { + GNUNET_break(0); + return; + } + GNUNET_CRYPTO_hash_xor(&uri->data.chk.chk.key, + &uri->data.chk.chk.query, + &key); if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, - &test_result_present, - (void *) uri)) + GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, &key, + &test_result_present, + (void *)uri)) return; /* duplicate result */ - sr = GNUNET_new (struct GNUNET_FS_SearchResult); + sr = GNUNET_new(struct GNUNET_FS_SearchResult); sr->h = sc->h; sr->sc = sc; sr->anonymity = sc->anonymity; - sr->uri = GNUNET_FS_uri_dup (uri); - sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); + sr->uri = GNUNET_FS_uri_dup(uri); + sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); sr->key = key; - GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_FS_search_result_sync_ (sr); - GNUNET_FS_search_start_probe_ (sr); + GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_FS_search_result_sync_(sr); + GNUNET_FS_search_start_probe_(sr); /* notify client */ if (0 == sr->mandatory_missing) - notify_client_chk_result (sc, sr); + notify_client_chk_result(sc, sr); else - GNUNET_break (NULL == sr->client_info); + GNUNET_break(NULL == sr->client_info); /* search for updates */ - if (0 == strlen (id_update)) + if (0 == strlen(id_update)) return; /* no updates */ uu.type = GNUNET_FS_URI_SKS; uu.data.sks.ns = sc->uri->data.sks.ns; - uu.data.sks.identifier = GNUNET_strdup (id_update); - (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr); - GNUNET_free (uu.data.sks.identifier); + uu.data.sks.identifier = GNUNET_strdup(id_update); + (void)search_start(sc->h, &uu, sc->anonymity, sc->options, NULL, sr); + GNUNET_free(uu.data.sks.identifier); } @@ -744,11 +752,11 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, * keyword, internal error) */ static int -decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, - const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, - const void *edata, - size_t edata_size, - char *data) +decrypt_block_with_keyword(const struct GNUNET_FS_SearchContext *sc, + const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, + const void *edata, + size_t edata_size, + char *data) { const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; @@ -756,23 +764,23 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, /* find key */ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) - if (0 == memcmp (dpub, - &sc->requests[i].dpub, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) + if (0 == memcmp(dpub, + &sc->requests[i].dpub, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) break; if (i == sc->uri->data.ksk.keywordCount) - { - /* oops, does not match any of our keywords!? */ - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + /* oops, does not match any of our keywords!? */ + GNUNET_break(0); + return GNUNET_SYSERR; + } /* decrypt */ - anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); - GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); - GNUNET_FS_ublock_decrypt_ (edata, edata_size, - &anon_pub, - sc->requests[i].keyword, - data); + anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); + GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); + GNUNET_FS_ublock_decrypt_(edata, edata_size, + &anon_pub, + sc->requests[i].keyword, + data); return i; } @@ -787,65 +795,65 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, * @param size size of @a ub */ static void -process_kblock (struct GNUNET_FS_SearchContext *sc, - const struct UBlock *ub, - size_t size) +process_kblock(struct GNUNET_FS_SearchContext *sc, + const struct UBlock *ub, + size_t size) { size_t j; - char pt[size - sizeof (struct UBlock)]; + char pt[size - sizeof(struct UBlock)]; const char *eos; struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Uri *uri; char *emsg; int i; - if (-1 == (i = decrypt_block_with_keyword (sc, - &ub->verification_key, - &ub[1], - size - sizeof (struct UBlock), - pt))) + if (-1 == (i = decrypt_block_with_keyword(sc, + &ub->verification_key, + &ub[1], + size - sizeof(struct UBlock), + pt))) return; /* parse; pt[0] is just '\0', so we skip over that */ - eos = memchr (&pt[1], '\0', sizeof (pt) - 1); + eos = memchr(&pt[1], '\0', sizeof(pt) - 1); if (NULL == eos) - { - GNUNET_break_op (0); - return; - } - if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg))) - { - if (GNUNET_FS_VERSION > 0x00090400) { - /* we broke this in 0x00090300, so don't bitch - too loudly just one version up... */ - GNUNET_break_op (0); /* ublock malformed */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to parse URI `%s': %s\n"), - &pt[1], - emsg); + GNUNET_break_op(0); + return; + } + if (NULL == (uri = GNUNET_FS_uri_parse(&pt[1], &emsg))) + { + if (GNUNET_FS_VERSION > 0x00090400) + { + /* we broke this in 0x00090300, so don't bitch + too loudly just one version up... */ + GNUNET_break_op(0); /* ublock malformed */ + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to parse URI `%s': %s\n"), + &pt[1], + emsg); + } + GNUNET_free_non_null(emsg); + return; } - GNUNET_free_non_null (emsg); - return; - } j = eos - pt + 1; - if (sizeof (pt) == j) - meta = GNUNET_CONTAINER_meta_data_create (); + if (sizeof(pt) == j) + meta = GNUNET_CONTAINER_meta_data_create(); else - meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j); + meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[j], sizeof(pt) - j); if (NULL == meta) - { - GNUNET_break_op (0); /* ublock malformed */ - GNUNET_FS_uri_destroy (uri); - return; - } - process_ksk_result (sc, - &sc->requests[i], - uri, - meta); + { + GNUNET_break_op(0); /* ublock malformed */ + GNUNET_FS_uri_destroy(uri); + return; + } + process_ksk_result(sc, + &sc->requests[i], + uri, + meta); /* clean up */ - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_FS_uri_destroy (uri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_FS_uri_destroy(uri); } @@ -859,11 +867,11 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, * @param size size of @a ub */ static void -process_sblock (struct GNUNET_FS_SearchContext *sc, - const struct UBlock *ub, - size_t size) +process_sblock(struct GNUNET_FS_SearchContext *sc, + const struct UBlock *ub, + size_t size) { - size_t len = size - sizeof (struct UBlock); + size_t len = size - sizeof(struct UBlock); char pt[len]; struct GNUNET_FS_Uri *uri; struct GNUNET_CONTAINER_MetaData *meta; @@ -872,36 +880,36 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, size_t off; char *emsg; - GNUNET_FS_ublock_decrypt_ (&ub[1], len, - &sc->uri->data.sks.ns, - sc->uri->data.sks.identifier, - pt); + GNUNET_FS_ublock_decrypt_(&ub[1], len, + &sc->uri->data.sks.ns, + sc->uri->data.sks.identifier, + pt); /* parse */ - if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris))) - { - GNUNET_break_op (0); /* ublock malformed */ - return; - } - if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off))) - { - GNUNET_break_op (0); /* ublock malformed */ - return; - } - if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to parse URI `%s': %s\n"), - uris, emsg); - GNUNET_break_op (0); /* ublock malformed */ - GNUNET_free_non_null (emsg); - GNUNET_CONTAINER_meta_data_destroy (meta); - return; - } + if (0 == (off = GNUNET_STRINGS_buffer_tokenize(pt, len, 2, &id, &uris))) + { + GNUNET_break_op(0); /* ublock malformed */ + return; + } + if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[off], len - off))) + { + GNUNET_break_op(0); /* ublock malformed */ + return; + } + if (NULL == (uri = GNUNET_FS_uri_parse(uris, &emsg))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to parse URI `%s': %s\n"), + uris, emsg); + GNUNET_break_op(0); /* ublock malformed */ + GNUNET_free_non_null(emsg); + GNUNET_CONTAINER_meta_data_destroy(meta); + return; + } /* process */ - process_sks_result (sc, id, uri, meta); + process_sks_result(sc, id, uri, meta); /* clean up */ - GNUNET_FS_uri_destroy (uri); - GNUNET_CONTAINER_meta_data_destroy (meta); + GNUNET_FS_uri_destroy(uri); + GNUNET_CONTAINER_meta_data_destroy(meta); } @@ -913,7 +921,7 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, * @param sc the search to reconnec */ static void -try_reconnect (struct GNUNET_FS_SearchContext *sc); +try_reconnect(struct GNUNET_FS_SearchContext *sc); /** @@ -923,8 +931,8 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc); * @param msg result message received */ static int -check_result (void *cls, - const struct ClientPutMessage *cm) +check_result(void *cls, + const struct ClientPutMessage *cm) { /* payload of any variable size is OK */ return GNUNET_OK; @@ -938,49 +946,54 @@ check_result (void *cls, * @param msg result message received */ static void -handle_result (void *cls, - const struct ClientPutMessage *cm) +handle_result(void *cls, + const struct ClientPutMessage *cm) { struct GNUNET_FS_SearchContext *sc = cls; - uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); - enum GNUNET_BLOCK_Type type = ntohl (cm->type); - - if (GNUNET_TIME_absolute_get_duration (GNUNET_TIME_absolute_ntoh (cm->expiration)).rel_value_us > 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Result received has already expired.\n"); - return; /* result expired */ - } + uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); + enum GNUNET_BLOCK_Type type = ntohl(cm->type); + + if (GNUNET_TIME_absolute_get_duration(GNUNET_TIME_absolute_ntoh(cm->expiration)).rel_value_us > 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Result received has already expired.\n"); + return; /* result expired */ + } switch (type) - { - case GNUNET_BLOCK_TYPE_FS_UBLOCK: - if (GNUNET_FS_URI_SKS == sc->uri->type) - process_sblock (sc, - (const struct UBlock *) &cm[1], - msize); - else - process_kblock (sc, - (const struct UBlock *) &cm[1], - msize); - break; - case GNUNET_BLOCK_TYPE_ANY: - GNUNET_break (0); - break; - case GNUNET_BLOCK_TYPE_FS_DBLOCK: - GNUNET_break (0); - break; - case GNUNET_BLOCK_TYPE_FS_ONDEMAND: - GNUNET_break (0); - break; - case GNUNET_BLOCK_TYPE_FS_IBLOCK: - GNUNET_break (0); - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Got result with unknown block type `%d', ignoring"), - type); - break; - } + { + case GNUNET_BLOCK_TYPE_FS_UBLOCK: + if (GNUNET_FS_URI_SKS == sc->uri->type) + process_sblock(sc, + (const struct UBlock *)&cm[1], + msize); + else + process_kblock(sc, + (const struct UBlock *)&cm[1], + msize); + break; + + case GNUNET_BLOCK_TYPE_ANY: + GNUNET_break(0); + break; + + case GNUNET_BLOCK_TYPE_FS_DBLOCK: + GNUNET_break(0); + break; + + case GNUNET_BLOCK_TYPE_FS_ONDEMAND: + GNUNET_break(0); + break; + + case GNUNET_BLOCK_TYPE_FS_IBLOCK: + GNUNET_break(0); + break; + + default: + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Got result with unknown block type `%d', ignoring"), + type); + break; + } } @@ -991,14 +1004,13 @@ handle_result (void *cls, * @param sc context for the search */ static void -schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc); +schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc); /** * Closure for #build_result_set(). */ -struct MessageBuilderContext -{ +struct MessageBuilderContext { /** * How many entries can we store to xoff. */ @@ -1036,21 +1048,21 @@ struct MessageBuilderContext * @return #GNUNET_OK to continue iterating */ static int -build_result_set (void *cls, - const struct GNUNET_HashCode *key, - void *value) +build_result_set(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct MessageBuilderContext *mbc = cls; struct GNUNET_FS_SearchResult *sr = value; - if ( (NULL != sr->keyword_bitmap) && - (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) ) + if ((NULL != sr->keyword_bitmap) && + (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) return GNUNET_OK; /* have no match for this keyword yet */ if (mbc->skip_cnt > 0) - { - mbc->skip_cnt--; - return GNUNET_OK; - } + { + mbc->skip_cnt--; + return GNUNET_OK; + } if (0 == mbc->put_cnt) return GNUNET_SYSERR; mbc->xoff[--mbc->put_cnt] = *key; @@ -1069,15 +1081,15 @@ build_result_set (void *cls, * @return #GNUNET_OK to continue iterating */ static int -find_result_set (void *cls, - const struct GNUNET_HashCode *key, - void *value) +find_result_set(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct MessageBuilderContext *mbc = cls; struct GNUNET_FS_SearchResult *sr = value; - if ( (NULL != sr->keyword_bitmap) && - (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) ) + if ((NULL != sr->keyword_bitmap) && + (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) return GNUNET_OK; /* have no match for this keyword yet */ mbc->put_cnt++; return GNUNET_OK; @@ -1091,7 +1103,7 @@ find_result_set (void *cls, * @param sc context for the search */ static void -schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) +schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc) { struct MessageBuilderContext mbc; struct GNUNET_MQ_Envelope *env; @@ -1106,115 +1118,115 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) unsigned int keyword_offset; int first_call; - memset (&mbc, 0, sizeof (mbc)); + memset(&mbc, 0, sizeof(mbc)); mbc.sc = sc; - if (GNUNET_FS_uri_test_ksk (sc->uri)) - { - /* This will calculate the result set size ONLY for - "keyword_offset == 0", so we will have to recalculate - it for the other keywords later! */ - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &find_result_set, - &mbc); - total_seen_results = mbc.put_cnt; - } + if (GNUNET_FS_uri_test_ksk(sc->uri)) + { + /* This will calculate the result set size ONLY for + "keyword_offset == 0", so we will have to recalculate + it for the other keywords later! */ + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &find_result_set, + &mbc); + total_seen_results = mbc.put_cnt; + } else - { - total_seen_results - = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); - } + { + total_seen_results + = GNUNET_CONTAINER_multihashmap_size(sc->master_result_map); + } search_request_map_offset = 0; keyword_offset = 0; first_call = GNUNET_YES; - while ( (0 != (left = - (total_seen_results - search_request_map_offset))) || - (GNUNET_YES == first_call) ) - { - first_call = GNUNET_NO; - options = SEARCH_MESSAGE_OPTION_NONE; - if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) - options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; - - fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*sm)) / sizeof (struct GNUNET_HashCode); - todo = GNUNET_MIN (fit, - left); - env = GNUNET_MQ_msg_extra (sm, - sizeof (struct GNUNET_HashCode) * todo, - GNUNET_MESSAGE_TYPE_FS_START_SEARCH); - mbc.skip_cnt = search_request_map_offset; - mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; - sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); - sm->anonymity_level = htonl (sc->anonymity); - memset (&sm->target, - 0, - sizeof (struct GNUNET_PeerIdentity)); - - if (GNUNET_FS_uri_test_ksk (sc->uri)) + while ((0 != (left = + (total_seen_results - search_request_map_offset))) || + (GNUNET_YES == first_call)) { - mbc.keyword_offset = keyword_offset; - /* calculate how many results we can send in this message */ - mbc.put_cnt = todo; - /* now build message */ - sm->query = sc->requests[keyword_offset].uquery; - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &build_result_set, - &mbc); - search_request_map_offset += todo; - GNUNET_assert (0 == mbc.put_cnt); - GNUNET_assert (total_seen_results >= search_request_map_offset); - if (total_seen_results != search_request_map_offset) - { - /* more requesting to be done... */ - sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); - } - else - { - sm->options = htonl (options); - keyword_offset++; - if (sc->uri->data.ksk.keywordCount != keyword_offset) + first_call = GNUNET_NO; + options = SEARCH_MESSAGE_OPTION_NONE; + if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) + options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; + + fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*sm)) / sizeof(struct GNUNET_HashCode); + todo = GNUNET_MIN(fit, + left); + env = GNUNET_MQ_msg_extra(sm, + sizeof(struct GNUNET_HashCode) * todo, + GNUNET_MESSAGE_TYPE_FS_START_SEARCH); + mbc.skip_cnt = search_request_map_offset; + mbc.xoff = (struct GNUNET_HashCode *)&sm[1]; + sm->type = htonl(GNUNET_BLOCK_TYPE_FS_UBLOCK); + sm->anonymity_level = htonl(sc->anonymity); + memset(&sm->target, + 0, + sizeof(struct GNUNET_PeerIdentity)); + + if (GNUNET_FS_uri_test_ksk(sc->uri)) { - /* more keywords => more requesting to be done... */ - first_call = GNUNET_YES; - search_request_map_offset = 0; - mbc.put_cnt = 0; mbc.keyword_offset = keyword_offset; - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &find_result_set, - &mbc); - total_seen_results = mbc.put_cnt; + /* calculate how many results we can send in this message */ + mbc.put_cnt = todo; + /* now build message */ + sm->query = sc->requests[keyword_offset].uquery; + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &build_result_set, + &mbc); + search_request_map_offset += todo; + GNUNET_assert(0 == mbc.put_cnt); + GNUNET_assert(total_seen_results >= search_request_map_offset); + if (total_seen_results != search_request_map_offset) + { + /* more requesting to be done... */ + sm->options = htonl(options | SEARCH_MESSAGE_OPTION_CONTINUED); + } + else + { + sm->options = htonl(options); + keyword_offset++; + if (sc->uri->data.ksk.keywordCount != keyword_offset) + { + /* more keywords => more requesting to be done... */ + first_call = GNUNET_YES; + search_request_map_offset = 0; + mbc.put_cnt = 0; + mbc.keyword_offset = keyword_offset; + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &find_result_set, + &mbc); + total_seen_results = mbc.put_cnt; + } + } } - } - } - else - { - GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); - - GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, - sc->uri->data.sks.identifier, - "fs-ublock", - &dpub); - GNUNET_CRYPTO_hash (&dpub, - sizeof (dpub), - &sm->query); - mbc.put_cnt = todo; - mbc.keyword_offset = 0; - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &build_result_set, - &mbc); - GNUNET_assert (total_seen_results >= search_request_map_offset); - if (total_seen_results != search_request_map_offset) - { - /* more requesting to be done... */ - sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); - } else - { - sm->options = htonl (options); - } + { + GNUNET_assert(GNUNET_FS_uri_test_sks(sc->uri)); + + GNUNET_CRYPTO_ecdsa_public_key_derive(&sc->uri->data.sks.ns, + sc->uri->data.sks.identifier, + "fs-ublock", + &dpub); + GNUNET_CRYPTO_hash(&dpub, + sizeof(dpub), + &sm->query); + mbc.put_cnt = todo; + mbc.keyword_offset = 0; + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &build_result_set, + &mbc); + GNUNET_assert(total_seen_results >= search_request_map_offset); + if (total_seen_results != search_request_map_offset) + { + /* more requesting to be done... */ + sm->options = htonl(options | SEARCH_MESSAGE_OPTION_CONTINUED); + } + else + { + sm->options = htonl(options); + } + } + GNUNET_MQ_send(sc->mq, + env); } - GNUNET_MQ_send (sc->mq, - env); - } } @@ -1227,17 +1239,17 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) * @param error error code */ static void -search_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +search_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_FS_SearchContext *sc = cls; if (NULL != sc->mq) - { - GNUNET_MQ_destroy (sc->mq); - sc->mq = NULL; - } - try_reconnect (sc); + { + GNUNET_MQ_destroy(sc->mq); + sc->mq = NULL; + } + try_reconnect(sc); } @@ -1248,29 +1260,29 @@ search_mq_error_handler (void *cls, * @param cls our search context */ static void -do_reconnect (void *cls) +do_reconnect(void *cls) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (result, - GNUNET_MESSAGE_TYPE_FS_PUT, - struct ClientPutMessage, - sc), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(result, + GNUNET_MESSAGE_TYPE_FS_PUT, + struct ClientPutMessage, + sc), + GNUNET_MQ_handler_end() }; sc->task = NULL; - sc->mq = GNUNET_CLIENT_connect (sc->h->cfg, - "fs", - handlers, - &search_mq_error_handler, - sc); + sc->mq = GNUNET_CLIENT_connect(sc->h->cfg, + "fs", + handlers, + &search_mq_error_handler, + sc); if (NULL == sc->mq) - { - try_reconnect (sc); - return; - } - schedule_transmit_search_request (sc); + { + try_reconnect(sc); + return; + } + schedule_transmit_search_request(sc); } @@ -1282,18 +1294,18 @@ do_reconnect (void *cls) * @param sc the search to reconnec */ static void -try_reconnect (struct GNUNET_FS_SearchContext *sc) +try_reconnect(struct GNUNET_FS_SearchContext *sc) { if (NULL != sc->mq) - { - GNUNET_MQ_destroy (sc->mq); - sc->mq = NULL; - } - sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff); + { + GNUNET_MQ_destroy(sc->mq); + sc->mq = NULL; + } + sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(sc->reconnect_backoff); sc->task = - GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff, - &do_reconnect, - sc); + GNUNET_SCHEDULER_add_delayed(sc->reconnect_backoff, + &do_reconnect, + sc); } @@ -1310,39 +1322,39 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc) * @return context that can be used to control the search */ static struct GNUNET_FS_SearchContext * -search_start (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - uint32_t anonymity, - enum GNUNET_FS_SearchOptions options, - void *cctx, - struct GNUNET_FS_SearchResult *psearch) +search_start(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + uint32_t anonymity, + enum GNUNET_FS_SearchOptions options, + void *cctx, + struct GNUNET_FS_SearchResult *psearch) { struct GNUNET_FS_SearchContext *sc; struct GNUNET_FS_ProgressInfo pi; - sc = GNUNET_new (struct GNUNET_FS_SearchContext); + sc = GNUNET_new(struct GNUNET_FS_SearchContext); sc->h = h; sc->options = options; - sc->uri = GNUNET_FS_uri_dup (uri); + sc->uri = GNUNET_FS_uri_dup(uri); sc->anonymity = anonymity; - sc->start_time = GNUNET_TIME_absolute_get (); + sc->start_time = GNUNET_TIME_absolute_get(); if (NULL != psearch) - { - sc->psearch_result = psearch; - psearch->update_search = sc; - } - sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); + { + sc->psearch_result = psearch; + psearch->update_search = sc; + } + sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); sc->client_info = cctx; - if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)) - { - GNUNET_FS_uri_destroy (sc->uri); - GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); - GNUNET_free (sc); - return NULL; - } - GNUNET_FS_search_sync_ (sc); + if (GNUNET_OK != GNUNET_FS_search_start_searching_(sc)) + { + GNUNET_FS_uri_destroy(sc->uri); + GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); + GNUNET_free(sc); + return NULL; + } + GNUNET_FS_search_sync_(sc); pi.status = GNUNET_FS_STATUS_SEARCH_START; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); + sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); return sc; } @@ -1357,9 +1369,9 @@ search_start (struct GNUNET_FS_Handle *h, * @return #GNUNET_YES (we should continue to iterate) */ static int -update_sre_result_maps (void *cls, - const struct GNUNET_HashCode *key, - void *value) +update_sre_result_maps(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_SearchResult *sr = value; @@ -1367,11 +1379,11 @@ update_sre_result_maps (void *cls, for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8)))) - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (sc->requests[i].results, - &sr->key, - sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(sc->requests[i].results, + &sr->key, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return GNUNET_YES; } @@ -1385,7 +1397,7 @@ update_sre_result_maps (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc) { unsigned int i; const char *keyword; @@ -1393,45 +1405,45 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; struct SearchRequestEntry *sre; - GNUNET_assert (NULL == sc->mq); - if (GNUNET_FS_uri_test_ksk (sc->uri)) - { - GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); - anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); - GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); - sc->requests - = GNUNET_new_array (sc->uri->data.ksk.keywordCount, - struct SearchRequestEntry); - - for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) + GNUNET_assert(NULL == sc->mq); + if (GNUNET_FS_uri_test_ksk(sc->uri)) { - keyword = &sc->uri->data.ksk.keywords[i][1]; - sre = &sc->requests[i]; - sre->keyword = GNUNET_strdup (keyword); - GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, - keyword, - "fs-ublock", - &sre->dpub); - GNUNET_CRYPTO_hash (&sre->dpub, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - &sre->uquery); - sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); - if (sre->mandatory) - sc->mandatory_count++; - sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); + GNUNET_assert(0 != sc->uri->data.ksk.keywordCount); + anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); + GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); + sc->requests + = GNUNET_new_array(sc->uri->data.ksk.keywordCount, + struct SearchRequestEntry); + + for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) + { + keyword = &sc->uri->data.ksk.keywords[i][1]; + sre = &sc->requests[i]; + sre->keyword = GNUNET_strdup(keyword); + GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, + keyword, + "fs-ublock", + &sre->dpub); + GNUNET_CRYPTO_hash(&sre->dpub, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + &sre->uquery); + sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); + if (sre->mandatory) + sc->mandatory_count++; + sre->results = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); + } + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &update_sre_result_maps, + sc); } - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &update_sre_result_maps, - sc); - } - GNUNET_assert (NULL == sc->task); - do_reconnect (sc); + GNUNET_assert(NULL == sc->task); + do_reconnect(sc); if (NULL == sc->mq) - { - GNUNET_SCHEDULER_cancel (sc->task); - sc->task = NULL; - return GNUNET_SYSERR; - } + { + GNUNET_SCHEDULER_cancel(sc->task); + sc->task = NULL; + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1445,25 +1457,25 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) * @return #GNUNET_OK */ static int -search_result_freeze_probes (void *cls, - const struct GNUNET_HashCode *key, - void *value) +search_result_freeze_probes(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_FS_SearchResult *sr = value; if (NULL != sr->probe_ctx) - { - GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); - sr->probe_ctx = NULL; - GNUNET_FS_stop_probe_ping_task_ (sr); - } + { + GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); + sr->probe_ctx = NULL; + GNUNET_FS_stop_probe_ping_task_(sr); + } if (NULL != sr->probe_cancel_task) - { - GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); - sr->probe_cancel_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); + sr->probe_cancel_task = NULL; + } if (NULL != sr->update_search) - GNUNET_FS_search_pause (sr->update_search); + GNUNET_FS_search_pause(sr->update_search); return GNUNET_OK; } @@ -1477,15 +1489,15 @@ search_result_freeze_probes (void *cls, * @return #GNUNET_OK */ static int -search_result_resume_probes (void *cls, - const struct GNUNET_HashCode * key, - void *value) +search_result_resume_probes(void *cls, + const struct GNUNET_HashCode * key, + void *value) { struct GNUNET_FS_SearchResult *sr = value; - GNUNET_FS_search_start_probe_ (sr); + GNUNET_FS_search_start_probe_(sr); if (NULL != sr->update_search) - GNUNET_FS_search_continue (sr->update_search); + GNUNET_FS_search_continue(sr->update_search); return GNUNET_OK; } @@ -1499,40 +1511,40 @@ search_result_resume_probes (void *cls, * @return #GNUNET_OK */ static int -search_result_suspend (void *cls, - const struct GNUNET_HashCode *key, - void *value) +search_result_suspend(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_SearchResult *sr = value; struct GNUNET_FS_ProgressInfo pi; if (NULL != sr->download) - { - GNUNET_FS_download_signal_suspend_ (sr->download); - sr->download = NULL; - } + { + GNUNET_FS_download_signal_suspend_(sr->download); + sr->download = NULL; + } if (NULL != sr->update_search) - { - GNUNET_FS_search_signal_suspend_ (sr->update_search); - sr->update_search = NULL; - } - GNUNET_FS_search_stop_probe_ (sr); + { + GNUNET_FS_search_signal_suspend_(sr->update_search); + sr->update_search = NULL; + } + GNUNET_FS_search_stop_probe_(sr); if (0 == sr->mandatory_missing) - { - /* client is aware of search result, notify about suspension event */ - pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; - pi.value.search.specifics.result_suspend.cctx = sr->client_info; - pi.value.search.specifics.result_suspend.meta = sr->meta; - pi.value.search.specifics.result_suspend.uri = sr->uri; - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); - } - GNUNET_break (NULL == sr->client_info); - GNUNET_free_non_null (sr->serialization); - GNUNET_FS_uri_destroy (sr->uri); - GNUNET_CONTAINER_meta_data_destroy (sr->meta); - GNUNET_free_non_null (sr->keyword_bitmap); - GNUNET_free (sr); + { + /* client is aware of search result, notify about suspension event */ + pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; + pi.value.search.specifics.result_suspend.cctx = sr->client_info; + pi.value.search.specifics.result_suspend.meta = sr->meta; + pi.value.search.specifics.result_suspend.uri = sr->uri; + sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); + } + GNUNET_break(NULL == sr->client_info); + GNUNET_free_non_null(sr->serialization); + GNUNET_FS_uri_destroy(sr->uri); + GNUNET_CONTAINER_meta_data_destroy(sr->meta); + GNUNET_free_non_null(sr->keyword_bitmap); + GNUNET_free(sr); return GNUNET_OK; } @@ -1544,43 +1556,43 @@ search_result_suspend (void *cls, * @param cls the `struct GNUNET_FS_SearchContext` to signal for */ void -GNUNET_FS_search_signal_suspend_ (void *cls) +GNUNET_FS_search_signal_suspend_(void *cls) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_ProgressInfo pi; unsigned int i; - GNUNET_FS_end_top (sc->h, sc->top); - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_suspend, sc); + GNUNET_FS_end_top(sc->h, sc->top); + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &search_result_suspend, sc); pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); - GNUNET_break (NULL == sc->client_info); + sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); + GNUNET_break(NULL == sc->client_info); if (sc->task != NULL) - { - GNUNET_SCHEDULER_cancel (sc->task); - sc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(sc->task); + sc->task = NULL; + } if (NULL != sc->mq) - { - GNUNET_MQ_destroy (sc->mq); - sc->mq = NULL; - } - GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); + { + GNUNET_MQ_destroy(sc->mq); + sc->mq = NULL; + } + GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); if (NULL != sc->requests) - { - GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); - for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) { - GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); - GNUNET_free (sc->requests[i].keyword); + GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); + for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) + { + GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); + GNUNET_free(sc->requests[i].keyword); + } } - } - GNUNET_free_non_null (sc->requests); - GNUNET_free_non_null (sc->emsg); - GNUNET_FS_uri_destroy (sc->uri); - GNUNET_free_non_null (sc->serialization); - GNUNET_free (sc); + GNUNET_free_non_null(sc->requests); + GNUNET_free_non_null(sc->emsg); + GNUNET_FS_uri_destroy(sc->uri); + GNUNET_free_non_null(sc->serialization); + GNUNET_free(sc); } @@ -1596,16 +1608,16 @@ GNUNET_FS_search_signal_suspend_ (void *cls) * @return context that can be used to control the search */ struct GNUNET_FS_SearchContext * -GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, uint32_t anonymity, - enum GNUNET_FS_SearchOptions options, void *cctx) +GNUNET_FS_search_start(struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, uint32_t anonymity, + enum GNUNET_FS_SearchOptions options, void *cctx) { struct GNUNET_FS_SearchContext *ret; - ret = search_start (h, uri, anonymity, options, cctx, NULL); + ret = search_start(h, uri, anonymity, options, cctx, NULL); if (NULL == ret) return NULL; - ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret); + ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, ret); return ret; } @@ -1616,28 +1628,28 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, * @param sc context for the search that should be paused */ void -GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_pause(struct GNUNET_FS_SearchContext *sc) { struct GNUNET_FS_ProgressInfo pi; if (NULL != sc->task) - { - GNUNET_SCHEDULER_cancel (sc->task); - sc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(sc->task); + sc->task = NULL; + } if (NULL != sc->mq) - { - GNUNET_MQ_destroy (sc->mq); - sc->mq = NULL; - } - GNUNET_FS_search_sync_ (sc); - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_freeze_probes, - sc); + { + GNUNET_MQ_destroy(sc->mq); + sc->mq = NULL; + } + GNUNET_FS_search_sync_(sc); + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &search_result_freeze_probes, + sc); pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, - sc->h, - sc); + sc->client_info = GNUNET_FS_search_make_status_(&pi, + sc->h, + sc); } @@ -1647,18 +1659,18 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) * @param sc context for the search that should be resumed */ void -GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_continue(struct GNUNET_FS_SearchContext *sc) { struct GNUNET_FS_ProgressInfo pi; - GNUNET_assert (NULL == sc->mq); - GNUNET_assert (NULL == sc->task); - do_reconnect (sc); - GNUNET_FS_search_sync_ (sc); + GNUNET_assert(NULL == sc->mq); + GNUNET_assert(NULL == sc->task); + do_reconnect(sc); + GNUNET_FS_search_sync_(sc); pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_resume_probes, sc); + sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &search_result_resume_probes, sc); } @@ -1671,48 +1683,48 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) * @return #GNUNET_OK */ static int -search_result_stop (void *cls, - const struct GNUNET_HashCode *key, - void *value) +search_result_stop(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_SearchResult *sr = value; struct GNUNET_FS_ProgressInfo pi; - GNUNET_FS_search_stop_probe_ (sr); + GNUNET_FS_search_stop_probe_(sr); if (NULL != sr->download) - { - sr->download->search = NULL; - sr->download->top - = GNUNET_FS_make_top (sr->download->h, - &GNUNET_FS_download_signal_suspend_, - sr->download); - if (NULL != sr->download->serialization) { - GNUNET_FS_remove_sync_file_ (sc->h, - GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, - sr->download->serialization); - GNUNET_free (sr->download->serialization); - sr->download->serialization = NULL; + sr->download->search = NULL; + sr->download->top + = GNUNET_FS_make_top(sr->download->h, + &GNUNET_FS_download_signal_suspend_, + sr->download); + if (NULL != sr->download->serialization) + { + GNUNET_FS_remove_sync_file_(sc->h, + GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, + sr->download->serialization); + GNUNET_free(sr->download->serialization); + sr->download->serialization = NULL; + } + pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; + GNUNET_FS_download_make_status_(&pi, + sr->download); + GNUNET_FS_download_sync_(sr->download); + sr->download = NULL; } - pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; - GNUNET_FS_download_make_status_ (&pi, - sr->download); - GNUNET_FS_download_sync_ (sr->download); - sr->download = NULL; - } if (0 != sr->mandatory_missing) - { - /* client is unaware of search result as - it does not match required keywords */ - GNUNET_break (NULL == sr->client_info); - return GNUNET_OK; - } + { + /* client is unaware of search result as + it does not match required keywords */ + GNUNET_break(NULL == sr->client_info); + return GNUNET_OK; + } pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; pi.value.search.specifics.result_stopped.cctx = sr->client_info; pi.value.search.specifics.result_stopped.meta = sr->meta; pi.value.search.specifics.result_stopped.uri = sr->uri; - sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sc); + sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sc); return GNUNET_OK; } @@ -1726,25 +1738,25 @@ search_result_stop (void *cls, * @return #GNUNET_OK */ static int -search_result_free (void *cls, - const struct GNUNET_HashCode *key, - void *value) +search_result_free(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_FS_SearchResult *sr = value; if (NULL != sr->update_search) - { - GNUNET_FS_search_stop (sr->update_search); - GNUNET_assert (NULL == sr->update_search); - } - GNUNET_break (NULL == sr->probe_ctx); - GNUNET_break (NULL == sr->probe_cancel_task); - GNUNET_break (NULL == sr->client_info); - GNUNET_free_non_null (sr->serialization); - GNUNET_FS_uri_destroy (sr->uri); - GNUNET_CONTAINER_meta_data_destroy (sr->meta); - GNUNET_free_non_null (sr->keyword_bitmap); - GNUNET_free (sr); + { + GNUNET_FS_search_stop(sr->update_search); + GNUNET_assert(NULL == sr->update_search); + } + GNUNET_break(NULL == sr->probe_ctx); + GNUNET_break(NULL == sr->probe_cancel_task); + GNUNET_break(NULL == sr->client_info); + GNUNET_free_non_null(sr->serialization); + GNUNET_FS_uri_destroy(sr->uri); + GNUNET_CONTAINER_meta_data_destroy(sr->meta); + GNUNET_free_non_null(sr->keyword_bitmap); + GNUNET_free(sr); return GNUNET_OK; } @@ -1755,60 +1767,60 @@ search_result_free (void *cls, * @param sc context for the search that should be stopped */ void -GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) +GNUNET_FS_search_stop(struct GNUNET_FS_SearchContext *sc) { struct GNUNET_FS_ProgressInfo pi; unsigned int i; if (NULL != sc->top) - GNUNET_FS_end_top (sc->h, sc->top); - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_stop, - sc); + GNUNET_FS_end_top(sc->h, sc->top); + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &search_result_stop, + sc); if (NULL != sc->psearch_result) sc->psearch_result->update_search = NULL; if (NULL != sc->serialization) - { - GNUNET_FS_remove_sync_file_ (sc->h, + { + GNUNET_FS_remove_sync_file_(sc->h, + (NULL != sc->psearch_result) + ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH + : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, + sc->serialization); + GNUNET_FS_remove_sync_dir_(sc->h, (NULL != sc->psearch_result) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, sc->serialization); - GNUNET_FS_remove_sync_dir_ (sc->h, - (NULL != sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH - : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, - sc->serialization); - GNUNET_free (sc->serialization); - } + GNUNET_free(sc->serialization); + } pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; - sc->client_info = GNUNET_FS_search_make_status_ (&pi, - sc->h, - sc); - GNUNET_break (NULL == sc->client_info); + sc->client_info = GNUNET_FS_search_make_status_(&pi, + sc->h, + sc); + GNUNET_break(NULL == sc->client_info); if (NULL != sc->task) - { - GNUNET_SCHEDULER_cancel (sc->task); - sc->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(sc->task); + sc->task = NULL; + } if (NULL != sc->mq) - { - GNUNET_MQ_destroy (sc->mq); - sc->mq = NULL; - } - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_free, sc); - GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); + { + GNUNET_MQ_destroy(sc->mq); + sc->mq = NULL; + } + GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, + &search_result_free, sc); + GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); if (NULL != sc->requests) - { - GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); - for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) - GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); - } - GNUNET_free_non_null (sc->requests); - GNUNET_free_non_null (sc->emsg); - GNUNET_FS_uri_destroy (sc->uri); - GNUNET_free (sc); + { + GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); + for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) + GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); + } + GNUNET_free_non_null(sc->requests); + GNUNET_free_non_null(sc->emsg); + GNUNET_FS_uri_destroy(sc->uri); + GNUNET_free(sc); } /* end of fs_search.c */ diff --git a/src/fs/fs_sharetree.c b/src/fs/fs_sharetree.c index 282d7796a..a2cc37170 100644 --- a/src/fs/fs_sharetree.c +++ b/src/fs/fs_sharetree.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_sharetree.c @@ -34,9 +34,7 @@ * Entry for each unique keyword to track how often * it occured. Contains the keyword and the counter. */ -struct KeywordCounter -{ - +struct KeywordCounter { /** * This is a doubly-linked list */ @@ -56,16 +54,13 @@ struct KeywordCounter * How many files have this keyword? */ unsigned int count; - }; /** * Aggregate information we keep for meta data in each directory. */ -struct MetaCounter -{ - +struct MetaCounter { /** * This is a doubly-linked list */ @@ -111,7 +106,6 @@ struct MetaCounter * (type and format do not have to match). */ unsigned int count; - }; @@ -119,9 +113,7 @@ struct MetaCounter * A structure that forms a singly-linked list that serves as a stack * for metadata-processing function. */ -struct TrimContext -{ - +struct TrimContext { /** * Map from the hash over the keyword to an 'struct KeywordCounter *' * counter that says how often this keyword was @@ -145,7 +137,6 @@ struct TrimContext * Number of times an item has to be found to be moved to the parent. */ unsigned int move_threshold; - }; @@ -158,26 +149,26 @@ struct TrimContext * @return always GNUNET_OK */ static int -add_to_keyword_counter (void *cls, const char *keyword, int is_mandatory) +add_to_keyword_counter(void *cls, const char *keyword, int is_mandatory) { struct GNUNET_CONTAINER_MultiHashMap *mcm = cls; struct KeywordCounter *cnt; struct GNUNET_HashCode hc; size_t klen; - klen = strlen (keyword) + 1; - GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); - cnt = GNUNET_CONTAINER_multihashmap_get (mcm, &hc); + klen = strlen(keyword) + 1; + GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); + cnt = GNUNET_CONTAINER_multihashmap_get(mcm, &hc); if (cnt == NULL) - { - cnt = GNUNET_malloc (sizeof (struct KeywordCounter) + klen); - cnt->value = (const char *) &cnt[1]; - GNUNET_memcpy (&cnt[1], keyword, klen); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (mcm, - &hc, cnt, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + cnt = GNUNET_malloc(sizeof(struct KeywordCounter) + klen); + cnt->value = (const char *)&cnt[1]; + GNUNET_memcpy(&cnt[1], keyword, klen); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(mcm, + &hc, cnt, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } cnt->count++; return GNUNET_OK; } @@ -201,30 +192,30 @@ add_to_keyword_counter (void *cls, const char *keyword, int is_mandatory) * @return 0 to continue extracting / iterating */ static int -add_to_meta_counter (void *cls, const char *plugin_name, - enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, const char *data, size_t data_len) +add_to_meta_counter(void *cls, const char *plugin_name, + enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, const char *data, size_t data_len) { struct GNUNET_CONTAINER_MultiHashMap *map = cls; struct GNUNET_HashCode key; struct MetaCounter *cnt; - GNUNET_CRYPTO_hash (data, data_len, &key); - cnt = GNUNET_CONTAINER_multihashmap_get (map, &key); + GNUNET_CRYPTO_hash(data, data_len, &key); + cnt = GNUNET_CONTAINER_multihashmap_get(map, &key); if (NULL == cnt) - { - cnt = GNUNET_new (struct MetaCounter); - cnt->data = data; - cnt->data_size = data_len; - cnt->plugin_name = plugin_name; - cnt->type = type; - cnt->format = format; - cnt->data_mime_type = data_mime_type; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (map, - &key, cnt, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + cnt = GNUNET_new(struct MetaCounter); + cnt->data = data; + cnt->data_size = data_len; + cnt->plugin_name = plugin_name; + cnt->type = type; + cnt->format = format; + cnt->data_mime_type = data_mime_type; + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(map, + &key, cnt, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } cnt->count++; return 0; } @@ -239,21 +230,21 @@ add_to_meta_counter (void *cls, const char *plugin_name, * @return always GNUNET_OK */ static int -remove_high_frequency_keywords (void *cls, const char *keyword, int is_mandatory) +remove_high_frequency_keywords(void *cls, const char *keyword, int is_mandatory) { struct TrimContext *tc = cls; struct KeywordCounter *counter; struct GNUNET_HashCode hc; size_t klen; - klen = strlen (keyword) + 1; - GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); - counter = GNUNET_CONTAINER_multihashmap_get (tc->keywordcounter, &hc); - GNUNET_assert (NULL != counter); + klen = strlen(keyword) + 1; + GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); + counter = GNUNET_CONTAINER_multihashmap_get(tc->keywordcounter, &hc); + GNUNET_assert(NULL != counter); if (counter->count < tc->move_threshold) return GNUNET_OK; - GNUNET_FS_uri_ksk_remove_keyword (tc->pos->ksk_uri, - counter->value); + GNUNET_FS_uri_ksk_remove_keyword(tc->pos->ksk_uri, + counter->value); return GNUNET_OK; } @@ -268,23 +259,23 @@ remove_high_frequency_keywords (void *cls, const char *keyword, int is_mandatory * @return GNUNET_YES (always) */ static int -migrate_and_drop_keywords (void *cls, const struct GNUNET_HashCode * key, void *value) +migrate_and_drop_keywords(void *cls, const struct GNUNET_HashCode * key, void *value) { struct TrimContext *tc = cls; struct KeywordCounter *counter = value; if (counter->count >= tc->move_threshold) - { - if (NULL == tc->pos->ksk_uri) - tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &counter->value); - else - GNUNET_FS_uri_ksk_add_keyword (tc->pos->ksk_uri, counter->value, GNUNET_NO); - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (tc->keywordcounter, - key, - counter)); - GNUNET_free (counter); + { + if (NULL == tc->pos->ksk_uri) + tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args(1, &counter->value); + else + GNUNET_FS_uri_ksk_add_keyword(tc->pos->ksk_uri, counter->value, GNUNET_NO); + } + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(tc->keywordcounter, + key, + counter)); + GNUNET_free(counter); return GNUNET_YES; } @@ -299,27 +290,27 @@ migrate_and_drop_keywords (void *cls, const struct GNUNET_HashCode * key, void * * @return GNUNET_YES (always) */ static int -migrate_and_drop_metadata (void *cls, const struct GNUNET_HashCode * key, void *value) +migrate_and_drop_metadata(void *cls, const struct GNUNET_HashCode * key, void *value) { struct TrimContext *tc = cls; struct MetaCounter *counter = value; if (counter->count >= tc->move_threshold) - { - if (NULL == tc->pos->meta) - tc->pos->meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_CONTAINER_meta_data_insert (tc->pos->meta, - counter->plugin_name, - counter->type, - counter->format, - counter->data_mime_type, counter->data, - counter->data_size); - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (tc->metacounter, - key, - counter)); - GNUNET_free (counter); + { + if (NULL == tc->pos->meta) + tc->pos->meta = GNUNET_CONTAINER_meta_data_create(); + GNUNET_CONTAINER_meta_data_insert(tc->pos->meta, + counter->plugin_name, + counter->type, + counter->format, + counter->data_mime_type, counter->data, + counter->data_size); + } + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(tc->metacounter, + key, + counter)); + GNUNET_free(counter); return GNUNET_YES; } @@ -332,8 +323,8 @@ migrate_and_drop_metadata (void *cls, const struct GNUNET_HashCode * key, void * * @param tree tree to trim */ static void -share_tree_trim (struct TrimContext *tc, - struct GNUNET_FS_ShareTreeItem *tree) +share_tree_trim(struct TrimContext *tc, + struct GNUNET_FS_ShareTreeItem *tree) { struct GNUNET_FS_ShareTreeItem *pos; unsigned int num_children; @@ -341,64 +332,64 @@ share_tree_trim (struct TrimContext *tc, /* first, trim all children */ num_children = 0; for (pos = tree->children_head; NULL != pos; pos = pos->next) - { - share_tree_trim (tc, pos); - num_children++; - } + { + share_tree_trim(tc, pos); + num_children++; + } /* consider adding filename to directory meta data */ if (tree->is_directory == GNUNET_YES) - { - const char *user = getenv ("USER"); - if ( (user == NULL) || - (0 != strncasecmp (user, tree->short_filename, strlen(user)))) { - /* only use filename if it doesn't match $USER */ - if (NULL == tree->meta) - tree->meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_CONTAINER_meta_data_insert (tree->meta, "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", tree->short_filename, - strlen (tree->short_filename) + 1); + const char *user = getenv("USER"); + if ((user == NULL) || + (0 != strncasecmp(user, tree->short_filename, strlen(user)))) + { + /* only use filename if it doesn't match $USER */ + if (NULL == tree->meta) + tree->meta = GNUNET_CONTAINER_meta_data_create(); + GNUNET_CONTAINER_meta_data_insert(tree->meta, "", + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", tree->short_filename, + strlen(tree->short_filename) + 1); + } } - } if (1 >= num_children) return; /* nothing to trim */ /* now, count keywords and meta data in children */ for (pos = tree->children_head; NULL != pos; pos = pos->next) - { - if (NULL != pos->meta) - GNUNET_CONTAINER_meta_data_iterate (pos->meta, &add_to_meta_counter, tc->metacounter); - if (NULL != pos->ksk_uri) - GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter); - } + { + if (NULL != pos->meta) + GNUNET_CONTAINER_meta_data_iterate(pos->meta, &add_to_meta_counter, tc->metacounter); + if (NULL != pos->ksk_uri) + GNUNET_FS_uri_ksk_get_keywords(pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter); + } /* calculate threshold for moving keywords / meta data */ tc->move_threshold = 1 + (num_children / 2); /* remove high-frequency keywords from children */ for (pos = tree->children_head; NULL != pos; pos = pos->next) - { - tc->pos = pos; - if (NULL != pos->ksk_uri) { - struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup (pos->ksk_uri); - GNUNET_FS_uri_ksk_get_keywords (ksk_uri_copy, &remove_high_frequency_keywords, tc); - GNUNET_FS_uri_destroy (ksk_uri_copy); + tc->pos = pos; + if (NULL != pos->ksk_uri) + { + struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup(pos->ksk_uri); + GNUNET_FS_uri_ksk_get_keywords(ksk_uri_copy, &remove_high_frequency_keywords, tc); + GNUNET_FS_uri_destroy(ksk_uri_copy); + } } - } /* add high-frequency meta data and keywords to parent */ tc->pos = tree; - GNUNET_CONTAINER_multihashmap_iterate (tc->keywordcounter, - &migrate_and_drop_keywords, - tc); - GNUNET_CONTAINER_multihashmap_iterate (tc->metacounter, - &migrate_and_drop_metadata, - tc); + GNUNET_CONTAINER_multihashmap_iterate(tc->keywordcounter, + &migrate_and_drop_keywords, + tc); + GNUNET_CONTAINER_multihashmap_iterate(tc->metacounter, + &migrate_and_drop_metadata, + tc); } @@ -409,17 +400,17 @@ share_tree_trim (struct TrimContext *tc, * @param toplevel toplevel directory in the tree, returned by the scanner */ void -GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel) +GNUNET_FS_share_tree_trim(struct GNUNET_FS_ShareTreeItem *toplevel) { struct TrimContext tc; if (toplevel == NULL) return; - tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); - tc.metacounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); - share_tree_trim (&tc, toplevel); - GNUNET_CONTAINER_multihashmap_destroy (tc.keywordcounter); - GNUNET_CONTAINER_multihashmap_destroy (tc.metacounter); + tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); + tc.metacounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); + share_tree_trim(&tc, toplevel); + GNUNET_CONTAINER_multihashmap_destroy(tc.keywordcounter); + GNUNET_CONTAINER_multihashmap_destroy(tc.metacounter); } @@ -429,23 +420,23 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel) * @param toplevel toplevel of the tree to be freed */ void -GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel) +GNUNET_FS_share_tree_free(struct GNUNET_FS_ShareTreeItem *toplevel) { struct GNUNET_FS_ShareTreeItem *pos; while (NULL != (pos = toplevel->children_head)) - GNUNET_FS_share_tree_free (pos); + GNUNET_FS_share_tree_free(pos); if (NULL != toplevel->parent) - GNUNET_CONTAINER_DLL_remove (toplevel->parent->children_head, - toplevel->parent->children_tail, - toplevel); + GNUNET_CONTAINER_DLL_remove(toplevel->parent->children_head, + toplevel->parent->children_tail, + toplevel); if (NULL != toplevel->meta) - GNUNET_CONTAINER_meta_data_destroy (toplevel->meta); + GNUNET_CONTAINER_meta_data_destroy(toplevel->meta); if (NULL != toplevel->ksk_uri) - GNUNET_FS_uri_destroy (toplevel->ksk_uri); - GNUNET_free_non_null (toplevel->filename); - GNUNET_free_non_null (toplevel->short_filename); - GNUNET_free (toplevel); + GNUNET_FS_uri_destroy(toplevel->ksk_uri); + GNUNET_free_non_null(toplevel->filename); + GNUNET_free_non_null(toplevel->short_filename); + GNUNET_free(toplevel); } /* end fs_sharetree.c */ diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index abbda1ece..e3ab0ec88 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_test_lib.c @@ -37,9 +37,7 @@ /** * Handle for a publishing operation started for testing FS. */ -struct TestPublishOperation -{ - +struct TestPublishOperation { /** * Handle for the operation to connect to the peer's 'fs' service. */ @@ -110,9 +108,7 @@ struct TestPublishOperation /** * Handle for a download operation started for testing FS. */ -struct TestDownloadOperation -{ - +struct TestDownloadOperation { /** * Handle for the operation to connect to the peer's 'fs' service. */ @@ -172,7 +168,6 @@ struct TestDownloadOperation * Verbosity level of the current operation. */ unsigned int verbose; - }; @@ -183,23 +178,23 @@ struct TestDownloadOperation * @param tc scheduler context (unused) */ static void -report_uri (void *cls) +report_uri(void *cls) { struct TestPublishOperation *po = cls; - GNUNET_FS_publish_stop (po->publish_context); - GNUNET_TESTBED_operation_done (po->fs_op); - po->publish_cont (po->publish_cont_cls, - po->publish_uri, - (GNUNET_YES == po->do_index) - ? po->publish_tmp_file - : NULL); - GNUNET_FS_uri_destroy (po->publish_uri); - if ( (GNUNET_YES != po->do_index) && - (NULL != po->publish_tmp_file) ) - (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); - GNUNET_free_non_null (po->publish_tmp_file); - GNUNET_free (po); + GNUNET_FS_publish_stop(po->publish_context); + GNUNET_TESTBED_operation_done(po->fs_op); + po->publish_cont(po->publish_cont_cls, + po->publish_uri, + (GNUNET_YES == po->do_index) + ? po->publish_tmp_file + : NULL); + GNUNET_FS_uri_destroy(po->publish_uri); + if ((GNUNET_YES != po->do_index) && + (NULL != po->publish_tmp_file)) + (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); + GNUNET_free_non_null(po->publish_tmp_file); + GNUNET_free(po); } @@ -209,19 +204,19 @@ report_uri (void *cls) * @param cls the publish operation context */ static void -publish_timeout (void *cls) +publish_timeout(void *cls) { struct TestPublishOperation *po = cls; po->publish_timeout_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout while trying to publish data\n"); - GNUNET_TESTBED_operation_done (po->fs_op); - GNUNET_FS_publish_stop (po->publish_context); - po->publish_cont (po->publish_cont_cls, NULL, NULL); - (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); - GNUNET_free_non_null (po->publish_tmp_file); - GNUNET_free (po); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout while trying to publish data\n"); + GNUNET_TESTBED_operation_done(po->fs_op); + GNUNET_FS_publish_stop(po->publish_context); + po->publish_cont(po->publish_cont_cls, NULL, NULL); + (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); + GNUNET_free_non_null(po->publish_tmp_file); + GNUNET_free(po); } @@ -232,37 +227,41 @@ publish_timeout (void *cls) * @param info information about the event */ static void * -publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) +publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) { struct TestPublishOperation *po = cls; switch (info->status) - { - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - GNUNET_SCHEDULER_cancel (po->publish_timeout_task); - po->publish_timeout_task = NULL; - po->publish_uri = - GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); - GNUNET_SCHEDULER_add_now (&report_uri, - po); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - if (po->verbose) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", - (unsigned long long) info->value.publish.completed, - (unsigned long long) info->value.publish.size); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - if (po->verbose) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", - (unsigned long long) info->value.download.completed, - (unsigned long long) info->value.download.size); - break; - default: - break; - } + { + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + GNUNET_SCHEDULER_cancel(po->publish_timeout_task); + po->publish_timeout_task = NULL; + po->publish_uri = + GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); + GNUNET_SCHEDULER_add_now(&report_uri, + po); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + if (po->verbose) + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", + (unsigned long long)info->value.publish.completed, + (unsigned long long)info->value.publish.size); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + if (po->verbose) + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", + (unsigned long long)info->value.download.completed, + (unsigned long long)info->value.download.size); + break; + + default: + break; + } return NULL; } @@ -278,11 +277,11 @@ publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) * @return number of bytes written to buf */ static size_t -file_generator (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg) +file_generator(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg) { uint32_t *publish_seed = cls; uint64_t pos; @@ -294,14 +293,14 @@ file_generator (void *cls, if (buf == NULL) return 0; for (pos = 0; pos < 8; pos++) - cbuf[pos] = (uint8_t) (offset >> pos * 8); + cbuf[pos] = (uint8_t)(offset >> pos * 8); for (pos = 8; pos < max; pos++) - { - mod = (255 - (offset / 1024 / 32)); - if (mod == 0) - mod = 1; - cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); - } + { + mod = (255 - (offset / 1024 / 32)); + if (mod == 0) + mod = 1; + cbuf[pos] = (uint8_t)((offset * (*publish_seed)) % mod); + } return max; } @@ -316,16 +315,16 @@ file_generator (void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -publish_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +publish_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestPublishOperation *po = cls; - return GNUNET_FS_start (cfg, - "fs-test-publish", - &publish_progress_cb, po, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); + return GNUNET_FS_start(cfg, + "fs-test-publish", + &publish_progress_cb, po, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); } @@ -336,12 +335,12 @@ publish_connect_adapter (void *cls, * @param op_result unused (different for publish/download!) */ static void -fs_disconnect_adapter (void *cls, - void *op_result) +fs_disconnect_adapter(void *cls, + void *op_result) { struct GNUNET_FS_Handle *fs = op_result; - GNUNET_FS_stop (fs); + GNUNET_FS_stop(fs); } @@ -355,10 +354,10 @@ fs_disconnect_adapter (void *cls, * operation has executed successfully. */ static void -publish_fs_connect_complete_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +publish_fs_connect_complete_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct TestPublishOperation *po = cls; struct GNUNET_FS_FileInformation *fi; @@ -371,58 +370,58 @@ publish_fs_connect_complete_cb (void *cls, if (NULL == ca_result) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); - po->publish_cont (po->publish_cont_cls, - NULL, NULL); - GNUNET_TESTBED_operation_done (po->fs_op); - GNUNET_free (po); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); + po->publish_cont(po->publish_cont_cls, + NULL, NULL); + GNUNET_TESTBED_operation_done(po->fs_op); + GNUNET_free(po); return; } po->fs = ca_result; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(CONTENT_LIFETIME); bo.anonymity_level = po->anonymity; bo.content_priority = 42; bo.replication_level = 1; if (GNUNET_YES == po->do_index) - { - po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); - GNUNET_assert (po->publish_tmp_file != NULL); - fh = GNUNET_DISK_file_open (po->publish_tmp_file, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - GNUNET_assert (NULL != fh); - off = 0; - while (off < po->size) { - bsize = GNUNET_MIN (sizeof (buf), po->size - off); - emsg = NULL; - GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em)); - GNUNET_assert (em == NULL); - GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); - off += bsize; + po->publish_tmp_file = GNUNET_DISK_mktemp("fs-test-publish-index"); + GNUNET_assert(po->publish_tmp_file != NULL); + fh = GNUNET_DISK_file_open(po->publish_tmp_file, + GNUNET_DISK_OPEN_WRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + GNUNET_assert(NULL != fh); + off = 0; + while (off < po->size) + { + bsize = GNUNET_MIN(sizeof(buf), po->size - off); + emsg = NULL; + GNUNET_assert(bsize == file_generator(&po->publish_seed, off, bsize, buf, &em)); + GNUNET_assert(em == NULL); + GNUNET_assert(bsize == GNUNET_DISK_file_write(fh, buf, bsize)); + off += bsize; + } + GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); + fi = GNUNET_FS_file_information_create_from_file(po->fs, po, + po->publish_tmp_file, + NULL, NULL, po->do_index, + &bo); + GNUNET_assert(NULL != fi); } - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); - fi = GNUNET_FS_file_information_create_from_file (po->fs, po, - po->publish_tmp_file, - NULL, NULL, po->do_index, - &bo); - GNUNET_assert (NULL != fi); - } else - { - fi = GNUNET_FS_file_information_create_from_reader (po->fs, po, - po->size, - &file_generator, &po->publish_seed, - NULL, NULL, - po->do_index, &bo); - GNUNET_assert (NULL != fi); - } + { + fi = GNUNET_FS_file_information_create_from_reader(po->fs, po, + po->size, + &file_generator, &po->publish_seed, + NULL, NULL, + po->do_index, &bo); + GNUNET_assert(NULL != fi); + } po->publish_context = - GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_FS_publish_start(po->fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); } @@ -442,15 +441,15 @@ publish_fs_connect_complete_cb (void *cls, * @param cont_cls closure for cont */ void -GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, - struct GNUNET_TIME_Relative timeout, uint32_t anonymity, - int do_index, uint64_t size, uint32_t seed, - unsigned int verbose, - GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) +GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, + struct GNUNET_TIME_Relative timeout, uint32_t anonymity, + int do_index, uint64_t size, uint32_t seed, + unsigned int verbose, + GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) { struct TestPublishOperation *po; - po = GNUNET_new (struct TestPublishOperation); + po = GNUNET_new(struct TestPublishOperation); po->publish_cont = cont; po->publish_cont_cls = cont_cls; po->publish_seed = seed; @@ -458,16 +457,16 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, po->size = size; po->verbose = verbose; po->do_index = do_index; - po->fs_op = GNUNET_TESTBED_service_connect (po, - peer, - "fs", - &publish_fs_connect_complete_cb, - po, - &publish_connect_adapter, - &fs_disconnect_adapter, - po); + po->fs_op = GNUNET_TESTBED_service_connect(po, + peer, + "fs", + &publish_fs_connect_complete_cb, + po, + &publish_connect_adapter, + &fs_disconnect_adapter, + po); po->publish_timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po); + GNUNET_SCHEDULER_add_delayed(timeout, &publish_timeout, po); } @@ -480,20 +479,20 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, * @param cls the download operation context */ static void -download_timeout (void *cls) +download_timeout(void *cls) { struct TestDownloadOperation *dop = cls; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout while trying to download file\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout while trying to download file\n"); dop->download_timeout_task = NULL; - GNUNET_FS_download_stop (dop->download_context, - GNUNET_YES); - GNUNET_SCHEDULER_add_now (dop->download_cont, - dop->download_cont_cls); - GNUNET_TESTBED_operation_done (dop->fs_op); - GNUNET_FS_uri_destroy (dop->uri); - GNUNET_free (dop); + GNUNET_FS_download_stop(dop->download_context, + GNUNET_YES); + GNUNET_SCHEDULER_add_now(dop->download_cont, + dop->download_cont_cls); + GNUNET_TESTBED_operation_done(dop->fs_op); + GNUNET_FS_uri_destroy(dop->uri); + GNUNET_free(dop); } @@ -503,17 +502,17 @@ download_timeout (void *cls) * @param cls the download operation context */ static void -report_success (void *cls) +report_success(void *cls) { struct TestDownloadOperation *dop = cls; - GNUNET_FS_download_stop (dop->download_context, - GNUNET_YES); - GNUNET_SCHEDULER_add_now (dop->download_cont, - dop->download_cont_cls); - GNUNET_TESTBED_operation_done (dop->fs_op); - GNUNET_FS_uri_destroy (dop->uri); - GNUNET_free (dop); + GNUNET_FS_download_stop(dop->download_context, + GNUNET_YES); + GNUNET_SCHEDULER_add_now(dop->download_cont, + dop->download_cont_cls); + GNUNET_TESTBED_operation_done(dop->fs_op); + GNUNET_FS_uri_destroy(dop->uri); + GNUNET_free(dop); } @@ -524,34 +523,37 @@ report_success (void *cls) * @param info information about the event */ static void * -download_progress_cb (void *cls, - const struct GNUNET_FS_ProgressInfo *info) +download_progress_cb(void *cls, + const struct GNUNET_FS_ProgressInfo *info) { struct TestDownloadOperation *dop = cls; switch (info->status) - { - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - if (dop->verbose) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Download at %llu/%llu bytes\n", - (unsigned long long) info->value.download.completed, - (unsigned long long) info->value.download.size); - break; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - GNUNET_SCHEDULER_cancel (dop->download_timeout_task); - dop->download_timeout_task = NULL; - GNUNET_SCHEDULER_add_now (&report_success, dop); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - break; + { + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + if (dop->verbose) + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Download at %llu/%llu bytes\n", + (unsigned long long)info->value.download.completed, + (unsigned long long)info->value.download.size); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + GNUNET_SCHEDULER_cancel(dop->download_timeout_task); + dop->download_timeout_task = NULL; + GNUNET_SCHEDULER_add_now(&report_success, dop); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + break; + /* FIXME: monitor data correctness during download progress */ /* FIXME: do performance reports given sufficient verbosity */ /* FIXME: advance timeout task to "immediate" on error */ - default: - break; - } + default: + break; + } return NULL; } @@ -566,16 +568,16 @@ download_progress_cb (void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -download_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +download_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestPublishOperation *po = cls; - return GNUNET_FS_start (cfg, - "fs-test-download", - &download_progress_cb, po, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); + return GNUNET_FS_start(cfg, + "fs-test-download", + &download_progress_cb, po, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); } @@ -589,19 +591,19 @@ download_connect_adapter (void *cls, * operation has executed successfully. */ static void -download_fs_connect_complete_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +download_fs_connect_complete_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct TestDownloadOperation *dop = cls; dop->fs = ca_result; - GNUNET_assert (NULL != dop->fs); + GNUNET_assert(NULL != dop->fs); dop->download_context = - GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, - dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, - NULL, NULL); + GNUNET_FS_download_start(dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, + dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, + NULL, NULL); } @@ -619,33 +621,33 @@ download_fs_connect_complete_cb (void *cls, * @param cont_cls closure for cont */ void -GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, - struct GNUNET_TIME_Relative timeout, - uint32_t anonymity, uint32_t seed, - const struct GNUNET_FS_Uri *uri, unsigned int verbose, - GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) +GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, + struct GNUNET_TIME_Relative timeout, + uint32_t anonymity, uint32_t seed, + const struct GNUNET_FS_Uri *uri, unsigned int verbose, + GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) { struct TestDownloadOperation *dop; - dop = GNUNET_new (struct TestDownloadOperation); - dop->uri = GNUNET_FS_uri_dup (uri); - dop->size = GNUNET_FS_uri_chk_get_file_size (uri); + dop = GNUNET_new(struct TestDownloadOperation); + dop->uri = GNUNET_FS_uri_dup(uri); + dop->size = GNUNET_FS_uri_chk_get_file_size(uri); dop->verbose = verbose; dop->anonymity = anonymity; dop->download_cont = cont; dop->download_cont_cls = cont_cls; dop->download_seed = seed; - dop->fs_op = GNUNET_TESTBED_service_connect (dop, - peer, - "fs", - &download_fs_connect_complete_cb, - dop, - &download_connect_adapter, - &fs_disconnect_adapter, - dop); + dop->fs_op = GNUNET_TESTBED_service_connect(dop, + peer, + "fs", + &download_fs_connect_complete_cb, + dop, + &download_connect_adapter, + &fs_disconnect_adapter, + dop); dop->download_timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop); + GNUNET_SCHEDULER_add_delayed(timeout, &download_timeout, dop); } diff --git a/src/fs/fs_test_lib.h b/src/fs/fs_test_lib.h index 4bf0c7caa..e1c43bea7 100644 --- a/src/fs/fs_test_lib.h +++ b/src/fs/fs_test_lib.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_test_lib.h @@ -64,15 +64,15 @@ typedef void * @param cont_cls closure for @a cont */ void -GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, - struct GNUNET_TIME_Relative timeout, - uint32_t anonymity, - int do_index, - uint64_t size, - uint32_t seed, - unsigned int verbose, - GNUNET_FS_TEST_UriContinuation cont, - void *cont_cls); +GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, + struct GNUNET_TIME_Relative timeout, + uint32_t anonymity, + int do_index, + uint64_t size, + uint32_t seed, + unsigned int verbose, + GNUNET_FS_TEST_UriContinuation cont, + void *cont_cls); /** @@ -89,14 +89,14 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, * @param cont_cls closure for @a cont */ void -GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, - struct GNUNET_TIME_Relative timeout, - uint32_t anonymity, - uint32_t seed, - const struct GNUNET_FS_Uri *uri, - unsigned int verbose, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls); +GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, + struct GNUNET_TIME_Relative timeout, + uint32_t anonymity, + uint32_t seed, + const struct GNUNET_FS_Uri *uri, + unsigned int verbose, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls); diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index 203de3c7e..5d486a8c9 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_tree.c * @brief Merkle-tree-ish-CHK file encoding for GNUnet @@ -32,9 +32,7 @@ * Context for an ECRS-based file encoder that computes * the Merkle-ish-CHK tree. */ -struct GNUNET_FS_TreeEncoder -{ - +struct GNUNET_FS_TreeEncoder { /** * Global FS context. */ @@ -123,7 +121,7 @@ struct GNUNET_FS_TreeEncoder * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. */ unsigned int -GNUNET_FS_compute_depth (uint64_t flen) +GNUNET_FS_compute_depth(uint64_t flen) { unsigned int treeDepth; uint64_t fl; @@ -131,15 +129,15 @@ GNUNET_FS_compute_depth (uint64_t flen) treeDepth = 1; fl = DBLOCK_SIZE; while (fl < flen) - { - treeDepth++; - if (fl * CHK_PER_INODE < fl) { - /* integer overflow, this is a HUGE file... */ - return treeDepth; + treeDepth++; + if (fl * CHK_PER_INODE < fl) + { + /* integer overflow, this is a HUGE file... */ + return treeDepth; + } + fl = fl * CHK_PER_INODE; } - fl = fl * CHK_PER_INODE; - } return treeDepth; } @@ -154,7 +152,7 @@ GNUNET_FS_compute_depth (uint64_t flen) * @return number of bytes of payload a subtree of this depth may correspond to */ uint64_t -GNUNET_FS_tree_compute_tree_size (unsigned int depth) +GNUNET_FS_tree_compute_tree_size(unsigned int depth) { uint64_t rsize; unsigned int i; @@ -181,30 +179,30 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth) * @return size of the corresponding IBlock */ static uint16_t -GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) +GNUNET_FS_tree_compute_iblock_size(unsigned int depth, uint64_t end_offset) { unsigned int ret; uint64_t mod; uint64_t bds; - GNUNET_assert (depth > 0); - GNUNET_assert (end_offset > 0); - bds = GNUNET_FS_tree_compute_tree_size (depth); + GNUNET_assert(depth > 0); + GNUNET_assert(end_offset > 0); + bds = GNUNET_FS_tree_compute_tree_size(depth); mod = end_offset % bds; if (0 == mod) - { - /* we were triggered at the end of a full block */ - ret = CHK_PER_INODE; - } + { + /* we were triggered at the end of a full block */ + ret = CHK_PER_INODE; + } else - { - /* we were triggered at the end of the file */ - bds /= CHK_PER_INODE; - ret = mod / bds; - if (0 != mod % bds) - ret++; - } - return (uint16_t) (ret * sizeof (struct ContentHashKey)); + { + /* we were triggered at the end of the file */ + bds /= CHK_PER_INODE; + ret = mod / bds; + if (0 != mod % bds) + ret++; + } + return (uint16_t)(ret * sizeof(struct ContentHashKey)); } @@ -220,32 +218,32 @@ GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) * @return number of bytes stored in this node */ size_t -GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, - unsigned int depth) +GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, + unsigned int depth) { size_t ret; uint64_t rsize; uint64_t epos; unsigned int chks; - GNUNET_assert (fsize > 0); - GNUNET_assert (offset <= fsize); + GNUNET_assert(fsize > 0); + GNUNET_assert(offset <= fsize); if (depth == 0) - { - ret = DBLOCK_SIZE; - if ((offset + ret > fsize) || (offset + ret < offset)) - ret = (size_t) (fsize - offset); - return ret; - } - - rsize = GNUNET_FS_tree_compute_tree_size (depth - 1); + { + ret = DBLOCK_SIZE; + if ((offset + ret > fsize) || (offset + ret < offset)) + ret = (size_t)(fsize - offset); + return ret; + } + + rsize = GNUNET_FS_tree_compute_tree_size(depth - 1); epos = offset + rsize * CHK_PER_INODE; if ((epos < offset) || (epos > fsize)) epos = fsize; /* round up when computing #CHKs in our IBlock */ chks = (epos - offset + rsize - 1) / rsize; - GNUNET_assert (chks <= CHK_PER_INODE); - return chks * sizeof (struct ContentHashKey); + GNUNET_assert(chks <= CHK_PER_INODE); + return chks * sizeof(struct ContentHashKey); } @@ -267,16 +265,16 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, * @param cont function to call when done */ struct GNUNET_FS_TreeEncoder * -GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, - void *cls, - GNUNET_FS_DataReader reader, - GNUNET_FS_TreeBlockProcessor proc, - GNUNET_FS_TreeProgressCallback progress, - GNUNET_SCHEDULER_TaskCallback cont) +GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, + void *cls, + GNUNET_FS_DataReader reader, + GNUNET_FS_TreeBlockProcessor proc, + GNUNET_FS_TreeProgressCallback progress, + GNUNET_SCHEDULER_TaskCallback cont) { struct GNUNET_FS_TreeEncoder *te; - te = GNUNET_new (struct GNUNET_FS_TreeEncoder); + te = GNUNET_new(struct GNUNET_FS_TreeEncoder); te->h = h; te->size = size; te->cls = cls; @@ -284,14 +282,14 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, te->proc = proc; te->progress = progress; te->cont = cont; - te->chk_tree_depth = GNUNET_FS_compute_depth (size); + te->chk_tree_depth = GNUNET_FS_compute_depth(size); te->chk_tree - = GNUNET_new_array (te->chk_tree_depth * CHK_PER_INODE, - struct ContentHashKey); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created tree encoder for file with %llu bytes and depth %u\n", - (unsigned long long) size, - te->chk_tree_depth); + = GNUNET_new_array(te->chk_tree_depth * CHK_PER_INODE, + struct ContentHashKey); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Created tree encoder for file with %llu bytes and depth %u\n", + (unsigned long long)size, + te->chk_tree_depth); return te; } @@ -308,12 +306,12 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, * @return (array of CHKs') offset in the above IBlock */ static unsigned int -compute_chk_offset (unsigned int depth, uint64_t end_offset) +compute_chk_offset(unsigned int depth, uint64_t end_offset) { uint64_t bds; unsigned int ret; - bds = GNUNET_FS_tree_compute_tree_size (depth); + bds = GNUNET_FS_tree_compute_tree_size(depth); if (depth > 0) end_offset--; /* round down since for depth > 0 offset is at the END of the block */ ret = end_offset / bds; @@ -329,7 +327,7 @@ compute_chk_offset (unsigned int depth, uint64_t end_offset) * @param te tree encoder to use */ void -GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) +GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te) { struct ContentHashKey *mychk; const void *pt_block; @@ -340,77 +338,77 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) struct GNUNET_CRYPTO_SymmetricInitializationVector iv; unsigned int off; - GNUNET_assert (GNUNET_NO == te->in_next); + GNUNET_assert(GNUNET_NO == te->in_next); te->in_next = GNUNET_YES; if (te->chk_tree_depth == te->current_depth) - { - off = CHK_PER_INODE * (te->chk_tree_depth - 1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", - GNUNET_h2s (&te->chk_tree[off].query), off); - te->uri = GNUNET_new (struct GNUNET_FS_Uri); - te->uri->type = GNUNET_FS_URI_CHK; - te->uri->data.chk.chk = te->chk_tree[off]; - te->uri->data.chk.file_length = GNUNET_htonll (te->size); - te->in_next = GNUNET_NO; - te->cont (te->cls); - return; - } - if (0 == te->current_depth) - { - /* read DBLOCK */ - pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); - if (pt_size != - te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) { + off = CHK_PER_INODE * (te->chk_tree_depth - 1); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", + GNUNET_h2s(&te->chk_tree[off].query), off); + te->uri = GNUNET_new(struct GNUNET_FS_Uri); + te->uri->type = GNUNET_FS_URI_CHK; + te->uri->data.chk.chk = te->chk_tree[off]; + te->uri->data.chk.file_length = GNUNET_htonll(te->size); te->in_next = GNUNET_NO; - te->cont (te->cls); + te->cont(te->cls); return; } - pt_block = iob; - } + if (0 == te->current_depth) + { + /* read DBLOCK */ + pt_size = GNUNET_MIN(DBLOCK_SIZE, te->size - te->publish_offset); + if (pt_size != + te->reader(te->cls, te->publish_offset, pt_size, iob, &te->emsg)) + { + te->in_next = GNUNET_NO; + te->cont(te->cls); + return; + } + pt_block = iob; + } else - { - pt_size = - GNUNET_FS_tree_compute_iblock_size (te->current_depth, - te->publish_offset); - pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; - } - off = compute_chk_offset (te->current_depth, te->publish_offset); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", - (unsigned long long) te->publish_offset, te->current_depth, - (unsigned int) pt_size, (unsigned int) off); + { + pt_size = + GNUNET_FS_tree_compute_iblock_size(te->current_depth, + te->publish_offset); + pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; + } + off = compute_chk_offset(te->current_depth, te->publish_offset); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", + (unsigned long long)te->publish_offset, te->current_depth, + (unsigned int)pt_size, (unsigned int)off); mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; - GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); - GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); - GNUNET_CRYPTO_symmetric_encrypt (pt_block, pt_size, &sk, &iv, enc); - GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TE calculates query to be `%s', stored at %u\n", - GNUNET_h2s (&mychk->query), - te->current_depth * CHK_PER_INODE + off); + GNUNET_CRYPTO_hash(pt_block, pt_size, &mychk->key); + GNUNET_CRYPTO_hash_to_aes_key(&mychk->key, &sk, &iv); + GNUNET_CRYPTO_symmetric_encrypt(pt_block, pt_size, &sk, &iv, enc); + GNUNET_CRYPTO_hash(enc, pt_size, &mychk->query); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "TE calculates query to be `%s', stored at %u\n", + GNUNET_h2s(&mychk->query), + te->current_depth * CHK_PER_INODE + off); if (NULL != te->proc) - te->proc (te->cls, mychk, te->publish_offset, te->current_depth, - (0 == - te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : - GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); + te->proc(te->cls, mychk, te->publish_offset, te->current_depth, + (0 == + te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : + GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); if (NULL != te->progress) - te->progress (te->cls, te->publish_offset, pt_block, pt_size, - te->current_depth); + te->progress(te->cls, te->publish_offset, pt_block, pt_size, + te->current_depth); if (0 == te->current_depth) - { - te->publish_offset += pt_size; - if ((te->publish_offset == te->size) || - (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) - te->current_depth++; - } + { + te->publish_offset += pt_size; + if ((te->publish_offset == te->size) || + (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) + te->current_depth++; + } else - { - if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) - te->current_depth++; - else - te->current_depth = 0; - } + { + if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) + te->current_depth++; + else + te->current_depth = 0; + } te->in_next = GNUNET_NO; } @@ -422,10 +420,10 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) * @return uri set to the resulting URI (if encoding finished), NULL otherwise */ struct GNUNET_FS_Uri * -GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) +GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te) { if (NULL != te->uri) - return GNUNET_FS_uri_dup (te->uri); + return GNUNET_FS_uri_dup(te->uri); return NULL; } @@ -441,23 +439,23 @@ GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) * both "*emsg" will be set to NULL). */ void -GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, - char **emsg) +GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, + char **emsg) { if (NULL != te->reader) - { - (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); - te->reader = NULL; - } - GNUNET_assert (GNUNET_NO == te->in_next); + { + (void)te->reader(te->cls, UINT64_MAX, 0, 0, NULL); + te->reader = NULL; + } + GNUNET_assert(GNUNET_NO == te->in_next); if (NULL != te->uri) - GNUNET_FS_uri_destroy (te->uri); + GNUNET_FS_uri_destroy(te->uri); if (emsg != NULL) *emsg = te->emsg; else - GNUNET_free_non_null (te->emsg); - GNUNET_free (te->chk_tree); - GNUNET_free (te); + GNUNET_free_non_null(te->emsg); + GNUNET_free(te->chk_tree); + GNUNET_free(te); } /* end of fs_tree.c */ diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h index 13a8603c5..7ce7e461b 100644 --- a/src/fs/fs_tree.h +++ b/src/fs/fs_tree.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_tree.h @@ -41,7 +41,7 @@ * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. */ unsigned int -GNUNET_FS_compute_depth (uint64_t flen); +GNUNET_FS_compute_depth(uint64_t flen); /** @@ -54,7 +54,7 @@ GNUNET_FS_compute_depth (uint64_t flen); * @return number of bytes of payload a subtree of this depth may correspond to */ uint64_t -GNUNET_FS_tree_compute_tree_size (unsigned int depth); +GNUNET_FS_tree_compute_tree_size(unsigned int depth); /** @@ -69,8 +69,8 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth); * @return number of bytes stored in this node */ size_t -GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, - unsigned int depth); +GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, + unsigned int depth); /** @@ -138,11 +138,11 @@ typedef void (*GNUNET_FS_TreeProgressCallback) (void *cls, uint64_t offset, * @return tree encoder context */ struct GNUNET_FS_TreeEncoder * -GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, - void *cls, GNUNET_FS_DataReader reader, - GNUNET_FS_TreeBlockProcessor proc, - GNUNET_FS_TreeProgressCallback progress, - GNUNET_SCHEDULER_TaskCallback cont); +GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, + void *cls, GNUNET_FS_DataReader reader, + GNUNET_FS_TreeBlockProcessor proc, + GNUNET_FS_TreeProgressCallback progress, + GNUNET_SCHEDULER_TaskCallback cont); /** @@ -154,7 +154,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, * @param te tree encoder to use */ void -GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te); +GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te); /** @@ -164,7 +164,7 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te); * @return uri set to the resulting URI (if encoding finished), NULL otherwise */ struct GNUNET_FS_Uri * -GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te); +GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te); /** @@ -178,8 +178,8 @@ GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te); * both "*emsg" will be set to NULL). */ void -GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, - char **emsg); +GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, + char **emsg); #if 0 @@ -194,8 +194,8 @@ GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, * @param size set to the size of the resume data */ void -GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder *te, - void **data, size_t * size); +GNUNET_FS_tree_encoder_resume_get_data(const struct GNUNET_FS_TreeEncoder *te, + void **data, size_t * size); /** @@ -207,8 +207,8 @@ GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder *te, * @param size the size of the resume data */ void -GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te, - const void *data, size_t size); +GNUNET_FS_tree_encoder_resume(struct GNUNET_FS_TreeEncoder *te, + const void *data, size_t size); #endif diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index b013902c9..be2dbbddd 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_unindex.c @@ -48,26 +48,26 @@ * @return number of bytes copied to buf, 0 on error */ static size_t -unindex_reader (void *cls, - uint64_t offset, - size_t max, - void *buf, - char **emsg) +unindex_reader(void *cls, + uint64_t offset, + size_t max, + void *buf, + char **emsg) { struct GNUNET_FS_UnindexContext *uc = cls; size_t pt_size; - pt_size = GNUNET_MIN (max, uc->file_size - offset); - if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) - { - *emsg = GNUNET_strdup (_("Failed to find given position in file")); - return 0; - } - if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) - { - *emsg = GNUNET_strdup (_("Failed to read file")); - return 0; - } + pt_size = GNUNET_MIN(max, uc->file_size - offset); + if (offset != GNUNET_DISK_file_seek(uc->fh, offset, GNUNET_DISK_SEEK_SET)) + { + *emsg = GNUNET_strdup(_("Failed to find given position in file")); + return 0; + } + if (pt_size != GNUNET_DISK_file_read(uc->fh, buf, pt_size)) + { + *emsg = GNUNET_strdup(_("Failed to read file")); + return 0; + } return pt_size; } @@ -81,21 +81,21 @@ unindex_reader (void *cls, * @param offset where we are in the file (for progress) */ void -GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, - struct GNUNET_FS_UnindexContext *uc, - uint64_t offset) +GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, + struct GNUNET_FS_UnindexContext *uc, + uint64_t offset) { pi->value.unindex.uc = uc; pi->value.unindex.cctx = uc->client_info; pi->value.unindex.filename = uc->filename; pi->value.unindex.size = uc->file_size; pi->value.unindex.eta = - GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size); + GNUNET_TIME_calculate_eta(uc->start_time, offset, uc->file_size); pi->value.unindex.duration = - GNUNET_TIME_absolute_get_duration (uc->start_time); + GNUNET_TIME_absolute_get_duration(uc->start_time); pi->value.unindex.completed = offset; pi->fsh = uc->h; - uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi); + uc->client_info = uc->h->upcb(uc->h->upcb_cls, pi); } @@ -110,11 +110,11 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, * @param depth depth of the block in the tree, 0 for DBLOCK */ static void -unindex_progress (void *cls, - uint64_t offset, - const void *pt_block, - size_t pt_size, - unsigned int depth) +unindex_progress(void *cls, + uint64_t offset, + const void *pt_block, + size_t pt_size, + unsigned int depth) { struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -124,7 +124,7 @@ unindex_progress (void *cls, pi.value.unindex.specifics.progress.offset = offset; pi.value.unindex.specifics.progress.data_len = pt_size; pi.value.unindex.specifics.progress.depth = depth; - GNUNET_FS_unindex_make_status_ (&pi, uc, offset); + GNUNET_FS_unindex_make_status_(&pi, uc, offset); } @@ -135,14 +135,14 @@ unindex_progress (void *cls, * @param uc context for the failed unindexing operation */ static void -signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) +signal_unindex_error(struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_FS_ProgressInfo pi; pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; pi.value.unindex.specifics.error.message = uc->emsg; - GNUNET_FS_unindex_make_status_ (&pi, uc, 0); + GNUNET_FS_unindex_make_status_(&pi, uc, 0); } @@ -156,22 +156,22 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) * @param msg NULL on success, otherwise an error message */ static void -process_cont (void *cls, - int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +process_cont(void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_UnindexContext *uc = cls; if (success == GNUNET_SYSERR) - { - uc->emsg = GNUNET_strdup (msg); - signal_unindex_error (uc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Datastore REMOVE operation succeeded\n"); - GNUNET_FS_tree_encoder_next (uc->tc); + { + uc->emsg = GNUNET_strdup(msg); + signal_unindex_error(uc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Datastore REMOVE operation succeeded\n"); + GNUNET_FS_tree_encoder_next(uc->tc); } @@ -190,13 +190,13 @@ process_cont (void *cls, * @param block_size size of block (in bytes) */ static void -unindex_process (void *cls, - const struct ContentHashKey *chk, - uint64_t offset, - unsigned int depth, - enum GNUNET_BLOCK_Type type, - const void *block, - uint16_t block_size) +unindex_process(void *cls, + const struct ContentHashKey *chk, + uint64_t offset, + unsigned int depth, + enum GNUNET_BLOCK_Type type, + const void *block, + uint16_t block_size) { struct GNUNET_FS_UnindexContext *uc = cls; uint32_t size; @@ -204,21 +204,21 @@ unindex_process (void *cls, struct OnDemandBlock odb; if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) - { - size = block_size; - data = block; - } + { + size = block_size; + data = block; + } else /* on-demand encoded DBLOCK */ - { - size = sizeof (struct OnDemandBlock); - odb.offset = GNUNET_htonll (offset); - odb.file_id = uc->file_id; - data = &odb; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending REMOVE request to DATASTORE service\n"); - GNUNET_DATASTORE_remove (uc->dsh, &chk->query, size, data, -2, 1, - &process_cont, uc); + { + size = sizeof(struct OnDemandBlock); + odb.offset = GNUNET_htonll(offset); + odb.file_id = uc->file_id; + data = &odb; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending REMOVE request to DATASTORE service\n"); + GNUNET_DATASTORE_remove(uc->dsh, &chk->query, size, data, -2, 1, + &process_cont, uc); uc->chk = *chk; } @@ -231,24 +231,24 @@ unindex_process (void *cls, * @param msg the response */ static void -handle_unindex_response (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_unindex_response(void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; if (NULL != uc->mq) - { - GNUNET_MQ_destroy (uc->mq); - uc->mq = NULL; - } + { + GNUNET_MQ_destroy(uc->mq); + uc->mq = NULL; + } uc->state = UNINDEX_STATE_COMPLETE; pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; - GNUNET_FS_unindex_sync_ (uc); - GNUNET_FS_unindex_make_status_ (&pi, - uc, - uc->file_size); + GNUNET_FS_unindex_sync_(uc); + GNUNET_FS_unindex_make_status_(&pi, + uc, + uc->file_size); } @@ -261,20 +261,20 @@ handle_unindex_response (void *cls, * @param error error code */ static void -unindex_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +unindex_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_FS_UnindexContext *uc = cls; if (NULL != uc->mq) - { - GNUNET_MQ_destroy (uc->mq); - uc->mq = NULL; - } + { + GNUNET_MQ_destroy(uc->mq); + uc->mq = NULL; + } uc->state = UNINDEX_STATE_ERROR; - uc->emsg = GNUNET_strdup (_("Error communicating with `fs' service.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); + uc->emsg = GNUNET_strdup(_("Error communicating with `fs' service.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); } @@ -286,56 +286,56 @@ unindex_mq_error_handler (void *cls, * @param uc our unindexing context */ static void -unindex_finish (struct GNUNET_FS_UnindexContext *uc) +unindex_finish(struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (unindex_response, - GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, - struct GNUNET_MessageHeader, - uc), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(unindex_response, + GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, + struct GNUNET_MessageHeader, + uc), + GNUNET_MQ_handler_end() }; char *emsg; struct GNUNET_MQ_Envelope *env; struct UnindexMessage *req; /* generate final progress message */ - unindex_progress (uc, - uc->file_size, - NULL, - 0, - 0); - GNUNET_FS_tree_encoder_finish (uc->tc, - &emsg); + unindex_progress(uc, + uc->file_size, + NULL, + 0, + 0); + GNUNET_FS_tree_encoder_finish(uc->tc, + &emsg); uc->tc = NULL; - GNUNET_DISK_file_close (uc->fh); + GNUNET_DISK_file_close(uc->fh); uc->fh = NULL; - GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); + GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); uc->dsh = NULL; uc->state = UNINDEX_STATE_FS_NOTIFY; - GNUNET_FS_unindex_sync_ (uc); - uc->mq = GNUNET_CLIENT_connect (uc->h->cfg, - "fs", - handlers, - &unindex_mq_error_handler, - uc); + GNUNET_FS_unindex_sync_(uc); + uc->mq = GNUNET_CLIENT_connect(uc->h->cfg, + "fs", + handlers, + &unindex_mq_error_handler, + uc); if (NULL == uc->mq) - { - uc->state = UNINDEX_STATE_ERROR; - uc->emsg = - GNUNET_strdup (_("Failed to connect to FS service for unindexing.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending UNINDEX message to FS service\n"); - env = GNUNET_MQ_msg (req, - GNUNET_MESSAGE_TYPE_FS_UNINDEX); + { + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = + GNUNET_strdup(_("Failed to connect to FS service for unindexing.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending UNINDEX message to FS service\n"); + env = GNUNET_MQ_msg(req, + GNUNET_MESSAGE_TYPE_FS_UNINDEX); req->reserved = 0; req->file_id = uc->file_id; - GNUNET_MQ_send (uc->mq, - env); + GNUNET_MQ_send(uc->mq, + env); } @@ -351,47 +351,49 @@ unindex_finish (struct GNUNET_FS_UnindexContext *uc) * @param reason kind of progress we are making */ static void -unindex_directory_scan_cb (void *cls, - const char *filename, - int is_directory, - enum GNUNET_FS_DirScannerProgressUpdateReason reason) +unindex_directory_scan_cb(void *cls, + const char *filename, + int is_directory, + enum GNUNET_FS_DirScannerProgressUpdateReason reason) { struct GNUNET_FS_UnindexContext *uc = cls; static struct GNUNET_FS_ShareTreeItem * directory_scan_result; switch (reason) - { - case GNUNET_FS_DIRSCANNER_FINISHED: - directory_scan_result = GNUNET_FS_directory_scan_get_result (uc->dscan); - uc->dscan = NULL; - if (NULL != directory_scan_result->ksk_uri) - { - uc->ksk_uri = GNUNET_FS_uri_dup (directory_scan_result->ksk_uri); - uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; - GNUNET_FS_unindex_sync_ (uc); - GNUNET_FS_unindex_do_remove_kblocks_ (uc); - } - else - { - uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan.")); - GNUNET_FS_unindex_sync_ (uc); - unindex_finish (uc); - } - GNUNET_FS_share_tree_free (directory_scan_result); - break; - case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Internal error scanning `%s'.\n"), - uc->filename); - GNUNET_FS_directory_scan_abort (uc->dscan); - uc->dscan = NULL; - uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan.")); - GNUNET_FS_unindex_sync_ (uc); - unindex_finish (uc); - break; - default: - break; - } + { + case GNUNET_FS_DIRSCANNER_FINISHED: + directory_scan_result = GNUNET_FS_directory_scan_get_result(uc->dscan); + uc->dscan = NULL; + if (NULL != directory_scan_result->ksk_uri) + { + uc->ksk_uri = GNUNET_FS_uri_dup(directory_scan_result->ksk_uri); + uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; + GNUNET_FS_unindex_sync_(uc); + GNUNET_FS_unindex_do_remove_kblocks_(uc); + } + else + { + uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); + GNUNET_FS_unindex_sync_(uc); + unindex_finish(uc); + } + GNUNET_FS_share_tree_free(directory_scan_result); + break; + + case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Internal error scanning `%s'.\n"), + uc->filename); + GNUNET_FS_directory_scan_abort(uc->dscan); + uc->dscan = NULL; + uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); + GNUNET_FS_unindex_sync_(uc); + unindex_finish(uc); + break; + + default: + break; + } } @@ -401,18 +403,18 @@ unindex_directory_scan_cb (void *cls, * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) +GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc) { char *ex; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (uc->h->cfg, "FS", "EXTRACTORS", &ex)) + GNUNET_CONFIGURATION_get_value_string(uc->h->cfg, "FS", "EXTRACTORS", &ex)) ex = NULL; - uc->dscan = GNUNET_FS_directory_scan_start (uc->filename, - GNUNET_NO, ex, - &unindex_directory_scan_cb, - uc); - GNUNET_free_non_null (ex); + uc->dscan = GNUNET_FS_directory_scan_start(uc->filename, + GNUNET_NO, ex, + &unindex_directory_scan_cb, + uc); + GNUNET_free_non_null(ex); } @@ -430,20 +432,20 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) * @param msg NULL on success, otherwise an error message */ static void -continue_after_remove (void *cls, - int32_t success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +continue_after_remove(void *cls, + int32_t success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct GNUNET_FS_UnindexContext *uc = cls; uc->dqe = NULL; if (success != GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to remove UBlock: %s\n"), - msg); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to remove UBlock: %s\n"), + msg); uc->ksk_offset++; - GNUNET_FS_unindex_do_remove_kblocks_ (uc); + GNUNET_FS_unindex_do_remove_kblocks_(uc); } @@ -470,16 +472,16 @@ continue_after_remove (void *cls, * maybe 0 if no unique identifier is available */ static void -process_kblock_for_unindex (void *cls, - const struct GNUNET_HashCode *key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid) +process_kblock_for_unindex(void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid) { struct GNUNET_FS_UnindexContext *uc = cls; const struct UBlock *ub; @@ -488,82 +490,82 @@ process_kblock_for_unindex (void *cls, uc->dqe = NULL; if (NULL == data) - { - /* no result */ - uc->ksk_offset++; - GNUNET_FS_unindex_do_remove_kblocks_ (uc); - return; - } - GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); - if (size < sizeof (struct UBlock)) - { - GNUNET_break (0); - goto get_next; - } + { + /* no result */ + uc->ksk_offset++; + GNUNET_FS_unindex_do_remove_kblocks_(uc); + return; + } + GNUNET_assert(GNUNET_BLOCK_TYPE_FS_UBLOCK == type); + if (size < sizeof(struct UBlock)) + { + GNUNET_break(0); + goto get_next; + } ub = data; - GNUNET_CRYPTO_hash (&ub->verification_key, - sizeof (ub->verification_key), - &query); - if (0 != memcmp (&query, - key, - sizeof (struct GNUNET_HashCode))) - { - /* result does not match our keyword, skip */ - goto get_next; - } + GNUNET_CRYPTO_hash(&ub->verification_key, + sizeof(ub->verification_key), + &query); + if (0 != memcmp(&query, + key, + sizeof(struct GNUNET_HashCode))) + { + /* result does not match our keyword, skip */ + goto get_next; + } { - char pt[size - sizeof (struct UBlock)]; + char pt[size - sizeof(struct UBlock)]; struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; const char *keyword; - GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), - &anon_pub); + GNUNET_CRYPTO_ecdsa_key_get_public(GNUNET_CRYPTO_ecdsa_key_get_anonymous(), + &anon_pub); keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; - GNUNET_FS_ublock_decrypt_ (&ub[1], size - sizeof (struct UBlock), - &anon_pub, - keyword, - pt); - if (NULL == memchr (&pt[1], 0, sizeof (pt) - 1)) - { - GNUNET_break_op (0); /* malformed UBlock */ - goto get_next; - } - chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL); + GNUNET_FS_ublock_decrypt_(&ub[1], size - sizeof(struct UBlock), + &anon_pub, + keyword, + pt); + if (NULL == memchr(&pt[1], 0, sizeof(pt) - 1)) + { + GNUNET_break_op(0); /* malformed UBlock */ + goto get_next; + } + chk_uri = GNUNET_FS_uri_parse(&pt[1], NULL); if (NULL == chk_uri) + { + GNUNET_break_op(0); /* malformed UBlock */ + goto get_next; + } + } + if (0 != memcmp(&uc->chk, + &chk_uri->data.chk.chk, + sizeof(struct ContentHashKey))) { - GNUNET_break_op (0); /* malformed UBlock */ + /* different CHK, ignore */ + GNUNET_FS_uri_destroy(chk_uri); goto get_next; } - } - if (0 != memcmp (&uc->chk, - &chk_uri->data.chk.chk, - sizeof (struct ContentHashKey))) - { - /* different CHK, ignore */ - GNUNET_FS_uri_destroy (chk_uri); - goto get_next; - } - GNUNET_FS_uri_destroy (chk_uri); + GNUNET_FS_uri_destroy(chk_uri); /* matches! */ - uc->dqe = GNUNET_DATASTORE_remove (uc->dsh, - key, - size, - data, + uc->dqe = GNUNET_DATASTORE_remove(uc->dsh, + key, + size, + data, + 0 /* priority */, + 1 /* queue size */, + &continue_after_remove, + uc); + return; +get_next: + uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, + uid + 1 /* next_uid */, + false /* random */, + &uc->uquery, + GNUNET_BLOCK_TYPE_FS_UBLOCK, 0 /* priority */, 1 /* queue size */, - &continue_after_remove, + &process_kblock_for_unindex, uc); - return; - get_next: - uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, - uid + 1 /* next_uid */, - false /* random */, - &uc->uquery, - GNUNET_BLOCK_TYPE_FS_UBLOCK, - 0 /* priority */, - 1 /* queue size */, - &process_kblock_for_unindex, - uc); } @@ -573,7 +575,7 @@ process_kblock_for_unindex (void *cls, * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) +GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) { const char *keyword; const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; @@ -581,41 +583,41 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) struct GNUNET_CRYPTO_EcdsaPublicKey dpub; if (NULL == uc->dsh) - uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); + uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); if (NULL == uc->dsh) - { - uc->state = UNINDEX_STATE_ERROR; - uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); - return; - } - if ( (NULL == uc->ksk_uri) || - (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount) ) - { - unindex_finish (uc); - return; - } - anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); - GNUNET_CRYPTO_ecdsa_key_get_public (anon, - &anon_pub); + { + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); + return; + } + if ((NULL == uc->ksk_uri) || + (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount)) + { + unindex_finish(uc); + return; + } + anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); + GNUNET_CRYPTO_ecdsa_key_get_public(anon, + &anon_pub); keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; - GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, - keyword, - "fs-ublock", - &dpub); - GNUNET_CRYPTO_hash (&dpub, - sizeof (dpub), - &uc->uquery); - uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, - 0 /* next_uid */, - false /* random */, - &uc->uquery, - GNUNET_BLOCK_TYPE_FS_UBLOCK, - 0 /* priority */, - 1 /* queue size */, - &process_kblock_for_unindex, - uc); + GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, + keyword, + "fs-ublock", + &dpub); + GNUNET_CRYPTO_hash(&dpub, + sizeof(dpub), + &uc->uquery); + uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, + 0 /* next_uid */, + false /* random */, + &uc->uquery, + GNUNET_BLOCK_TYPE_FS_UBLOCK, + 0 /* priority */, + 1 /* queue size */, + &process_kblock_for_unindex, + uc); } @@ -626,13 +628,13 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) * @param cls our unindexing context */ static void -unindex_extract_keywords (void *cls) +unindex_extract_keywords(void *cls) { struct GNUNET_FS_UnindexContext *uc = cls; uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; - GNUNET_FS_unindex_sync_ (uc); - GNUNET_FS_unindex_do_extract_keywords_ (uc); + GNUNET_FS_unindex_sync_(uc); + GNUNET_FS_unindex_do_extract_keywords_(uc); } @@ -642,40 +644,40 @@ unindex_extract_keywords (void *cls) * @param uc context for the unindex operation. */ void -GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) +GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc) { if (NULL == uc->dsh) - uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); + uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); if (NULL == uc->dsh) - { - uc->state = UNINDEX_STATE_ERROR; - uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); - return; - } + { + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); + return; + } uc->fh = - GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_file_open(uc->filename, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == uc->fh) - { - GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); - uc->dsh = NULL; - uc->state = UNINDEX_STATE_ERROR; - uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); - return; - } + { + GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); + uc->dsh = NULL; + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup(_("Failed to open file for unindexing.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); + return; + } uc->tc = - GNUNET_FS_tree_encoder_create (uc->h, - uc->file_size, - uc, - &unindex_reader, - &unindex_process, - &unindex_progress, - &unindex_extract_keywords); - GNUNET_FS_tree_encoder_next (uc->tc); + GNUNET_FS_tree_encoder_create(uc->h, + uc->file_size, + uc, + &unindex_reader, + &unindex_process, + &unindex_progress, + &unindex_extract_keywords); + GNUNET_FS_tree_encoder_next(uc->tc); } @@ -687,29 +689,29 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) * @param file_id computed hash, NULL on error */ void -GNUNET_FS_unindex_process_hash_ (void *cls, - const struct GNUNET_HashCode *file_id) +GNUNET_FS_unindex_process_hash_(void *cls, + const struct GNUNET_HashCode *file_id) { struct GNUNET_FS_UnindexContext *uc = cls; uc->fhc = NULL; if (uc->state != UNINDEX_STATE_HASHING) - { - GNUNET_FS_unindex_stop (uc); - return; - } + { + GNUNET_FS_unindex_stop(uc); + return; + } if (file_id == NULL) - { - uc->state = UNINDEX_STATE_ERROR; - uc->emsg = GNUNET_strdup (_("Failed to compute hash of file.")); - GNUNET_FS_unindex_sync_ (uc); - signal_unindex_error (uc); - return; - } + { + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup(_("Failed to compute hash of file.")); + GNUNET_FS_unindex_sync_(uc); + signal_unindex_error(uc); + return; + } uc->file_id = *file_id; uc->state = UNINDEX_STATE_DS_REMOVE; - GNUNET_FS_unindex_sync_ (uc); - GNUNET_FS_unindex_do_remove_ (uc); + GNUNET_FS_unindex_sync_(uc); + GNUNET_FS_unindex_do_remove_(uc); } @@ -720,62 +722,62 @@ GNUNET_FS_unindex_process_hash_ (void *cls, * @param cls the `struct GNUNET_FS_UnindexContext` to signal for */ void -GNUNET_FS_unindex_signal_suspend_ (void *cls) +GNUNET_FS_unindex_signal_suspend_(void *cls) { struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; /* FIXME: lots of duplication with unindex_stop here! */ if (uc->dscan != NULL) - { - GNUNET_FS_directory_scan_abort (uc->dscan); - uc->dscan = NULL; - } + { + GNUNET_FS_directory_scan_abort(uc->dscan); + uc->dscan = NULL; + } if (NULL != uc->dqe) - { - GNUNET_DATASTORE_cancel (uc->dqe); - uc->dqe = NULL; - } + { + GNUNET_DATASTORE_cancel(uc->dqe); + uc->dqe = NULL; + } if (uc->fhc != NULL) - { - GNUNET_CRYPTO_hash_file_cancel (uc->fhc); - uc->fhc = NULL; - } + { + GNUNET_CRYPTO_hash_file_cancel(uc->fhc); + uc->fhc = NULL; + } if (NULL != uc->ksk_uri) - { - GNUNET_FS_uri_destroy (uc->ksk_uri); - uc->ksk_uri = NULL; - } + { + GNUNET_FS_uri_destroy(uc->ksk_uri); + uc->ksk_uri = NULL; + } if (NULL != uc->mq) - { - GNUNET_MQ_destroy (uc->mq); - uc->mq = NULL; - } + { + GNUNET_MQ_destroy(uc->mq); + uc->mq = NULL; + } if (NULL != uc->dsh) - { - GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); - uc->dsh = NULL; - } + { + GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); + uc->dsh = NULL; + } if (NULL != uc->tc) - { - GNUNET_FS_tree_encoder_finish (uc->tc, NULL); - uc->tc = NULL; - } + { + GNUNET_FS_tree_encoder_finish(uc->tc, NULL); + uc->tc = NULL; + } if (uc->fh != NULL) - { - GNUNET_DISK_file_close (uc->fh); - uc->fh = NULL; - } - GNUNET_FS_end_top (uc->h, uc->top); + { + GNUNET_DISK_file_close(uc->fh); + uc->fh = NULL; + } + GNUNET_FS_end_top(uc->h, uc->top); pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; - GNUNET_FS_unindex_make_status_ (&pi, uc, - (uc->state == - UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); - GNUNET_break (NULL == uc->client_info); - GNUNET_free (uc->filename); - GNUNET_free_non_null (uc->serialization); - GNUNET_free_non_null (uc->emsg); - GNUNET_free (uc); + GNUNET_FS_unindex_make_status_(&pi, uc, + (uc->state == + UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); + GNUNET_break(NULL == uc->client_info); + GNUNET_free(uc->filename); + GNUNET_free_non_null(uc->serialization); + GNUNET_free_non_null(uc->emsg); + GNUNET_free(uc); } @@ -788,38 +790,38 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) * @return NULL on error, otherwise handle */ struct GNUNET_FS_UnindexContext * -GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, - const char *filename, - void *cctx) +GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, + const char *filename, + void *cctx) { struct GNUNET_FS_UnindexContext *uc; struct GNUNET_FS_ProgressInfo pi; uint64_t size; if (GNUNET_OK != - GNUNET_DISK_file_size (filename, - &size, - GNUNET_YES, - GNUNET_YES)) + GNUNET_DISK_file_size(filename, + &size, + GNUNET_YES, + GNUNET_YES)) return NULL; - uc = GNUNET_new (struct GNUNET_FS_UnindexContext); + uc = GNUNET_new(struct GNUNET_FS_UnindexContext); uc->h = h; - uc->filename = GNUNET_strdup (filename); - uc->start_time = GNUNET_TIME_absolute_get (); + uc->filename = GNUNET_strdup(filename); + uc->start_time = GNUNET_TIME_absolute_get(); uc->file_size = size; uc->client_info = cctx; - GNUNET_FS_unindex_sync_ (uc); + GNUNET_FS_unindex_sync_(uc); pi.status = GNUNET_FS_STATUS_UNINDEX_START; pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; - GNUNET_FS_unindex_make_status_ (&pi, uc, 0); + GNUNET_FS_unindex_make_status_(&pi, uc, 0); uc->fhc = - GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, - filename, - HASHING_BLOCKSIZE, - &GNUNET_FS_unindex_process_hash_, uc); - uc->top = GNUNET_FS_make_top (h, - &GNUNET_FS_unindex_signal_suspend_, - uc); + GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, + filename, + HASHING_BLOCKSIZE, + &GNUNET_FS_unindex_process_hash_, uc); + uc->top = GNUNET_FS_make_top(h, + &GNUNET_FS_unindex_signal_suspend_, + uc); return uc; } @@ -830,67 +832,67 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, * @param uc handle */ void -GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) +GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_FS_ProgressInfo pi; if (NULL != uc->dscan) - { - GNUNET_FS_directory_scan_abort (uc->dscan); - uc->dscan = NULL; - } + { + GNUNET_FS_directory_scan_abort(uc->dscan); + uc->dscan = NULL; + } if (NULL != uc->dqe) - { - GNUNET_DATASTORE_cancel (uc->dqe); - uc->dqe = NULL; - } + { + GNUNET_DATASTORE_cancel(uc->dqe); + uc->dqe = NULL; + } if (NULL != uc->fhc) - { - GNUNET_CRYPTO_hash_file_cancel (uc->fhc); - uc->fhc = NULL; - } + { + GNUNET_CRYPTO_hash_file_cancel(uc->fhc); + uc->fhc = NULL; + } if (NULL != uc->mq) - { - GNUNET_MQ_destroy (uc->mq); - uc->mq = NULL; - } + { + GNUNET_MQ_destroy(uc->mq); + uc->mq = NULL; + } if (NULL != uc->dsh) - { - GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); - uc->dsh = NULL; - } + { + GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); + uc->dsh = NULL; + } if (NULL != uc->ksk_uri) - { - GNUNET_FS_uri_destroy (uc->ksk_uri); - uc->ksk_uri = NULL; - } + { + GNUNET_FS_uri_destroy(uc->ksk_uri); + uc->ksk_uri = NULL; + } if (NULL != uc->tc) - { - GNUNET_FS_tree_encoder_finish (uc->tc, NULL); - uc->tc = NULL; - } + { + GNUNET_FS_tree_encoder_finish(uc->tc, NULL); + uc->tc = NULL; + } if (uc->fh != NULL) - { - GNUNET_DISK_file_close (uc->fh); - uc->fh = NULL; - } - GNUNET_FS_end_top (uc->h, uc->top); + { + GNUNET_DISK_file_close(uc->fh); + uc->fh = NULL; + } + GNUNET_FS_end_top(uc->h, uc->top); if (uc->serialization != NULL) - { - GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - uc->serialization); - GNUNET_free (uc->serialization); - uc->serialization = NULL; - } + { + GNUNET_FS_remove_sync_file_(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + uc->serialization); + GNUNET_free(uc->serialization); + uc->serialization = NULL; + } pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; - GNUNET_FS_unindex_make_status_ (&pi, uc, - (uc->state == - UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); - GNUNET_break (NULL == uc->client_info); - GNUNET_free_non_null (uc->emsg); - GNUNET_free (uc->filename); - GNUNET_free (uc); + GNUNET_FS_unindex_make_status_(&pi, uc, + (uc->state == + UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); + GNUNET_break(NULL == uc->client_info); + GNUNET_free_non_null(uc->emsg); + GNUNET_free(uc->filename); + GNUNET_free(uc); } /* end of fs_unindex.c */ diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 5a67afbc0..c9ce19114 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/fs_uri.c @@ -100,43 +100,47 @@ * @return #GNUNET_OK on success */ int -GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, - struct GNUNET_HashCode *key) +GNUNET_FS_uri_to_key(const struct GNUNET_FS_Uri *uri, + struct GNUNET_HashCode *key) { switch (uri->type) - { - case GNUNET_FS_URI_CHK: - *key = uri->data.chk.chk.query; - return GNUNET_OK; - case GNUNET_FS_URI_SKS: - GNUNET_CRYPTO_hash (uri->data.sks.identifier, - strlen (uri->data.sks.identifier), - key); - return GNUNET_OK; - case GNUNET_FS_URI_KSK: - if (uri->data.ksk.keywordCount > 0) { - GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], - strlen (uri->data.ksk.keywords[0]), - key); + case GNUNET_FS_URI_CHK: + *key = uri->data.chk.chk.query; return GNUNET_OK; - } - else - { - memset (key, 0, sizeof (struct GNUNET_HashCode)); + + case GNUNET_FS_URI_SKS: + GNUNET_CRYPTO_hash(uri->data.sks.identifier, + strlen(uri->data.sks.identifier), + key); + return GNUNET_OK; + + case GNUNET_FS_URI_KSK: + if (uri->data.ksk.keywordCount > 0) + { + GNUNET_CRYPTO_hash(uri->data.ksk.keywords[0], + strlen(uri->data.ksk.keywords[0]), + key); + return GNUNET_OK; + } + else + { + memset(key, 0, sizeof(struct GNUNET_HashCode)); + return GNUNET_SYSERR; + } + break; + + case GNUNET_FS_URI_LOC: + GNUNET_CRYPTO_hash(&uri->data.loc.fi, + sizeof(struct FileIdentifier) + + sizeof(struct GNUNET_PeerIdentity), + key); + return GNUNET_OK; + + default: + memset(key, 0, sizeof(struct GNUNET_HashCode)); return GNUNET_SYSERR; } - break; - case GNUNET_FS_URI_LOC: - GNUNET_CRYPTO_hash (&uri->data.loc.fi, - sizeof (struct FileIdentifier) + - sizeof (struct GNUNET_PeerIdentity), - key); - return GNUNET_OK; - default: - memset (key, 0, sizeof (struct GNUNET_HashCode)); - return GNUNET_SYSERR; - } } @@ -148,7 +152,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, * @return string with the keywords */ char * -GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri) { size_t n; char *ret; @@ -158,45 +162,45 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) unsigned int keywordCount; if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } keywords = uri->data.ksk.keywords; keywordCount = uri->data.ksk.keywordCount; n = keywordCount + 1; for (i = 0; i < keywordCount; i++) - { - keyword = keywords[i]; - n += strlen (keyword) - 1; - if (NULL != strstr (&keyword[1], " ")) - n += 2; - if (keyword[0] == '+') - n++; - } - ret = GNUNET_malloc (n); - strcpy (ret, ""); - for (i = 0; i < keywordCount; i++) - { - keyword = keywords[i]; - if (NULL != strstr (&keyword[1], " ")) { - strcat (ret, "\""); + keyword = keywords[i]; + n += strlen(keyword) - 1; + if (NULL != strstr(&keyword[1], " ")) + n += 2; if (keyword[0] == '+') - strcat (ret, keyword); - else - strcat (ret, &keyword[1]); - strcat (ret, "\""); + n++; } - else + ret = GNUNET_malloc(n); + strcpy(ret, ""); + for (i = 0; i < keywordCount; i++) { - if (keyword[0] == '+') - strcat (ret, keyword); + keyword = keywords[i]; + if (NULL != strstr(&keyword[1], " ")) + { + strcat(ret, "\""); + if (keyword[0] == '+') + strcat(ret, keyword); + else + strcat(ret, &keyword[1]); + strcat(ret, "\""); + } else - strcat (ret, &keyword[1]); + { + if (keyword[0] == '+') + strcat(ret, keyword); + else + strcat(ret, &keyword[1]); + } + strcat(ret, " "); } - strcat (ret, " "); - } return ret; } @@ -212,7 +216,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) * @return decodded string with leading space (or preserved plus) */ static char * -percent_decode_keyword (const char *in, char **emsg) +percent_decode_keyword(const char *in, char **emsg) { char *out; char *ret; @@ -220,44 +224,44 @@ percent_decode_keyword (const char *in, char **emsg) unsigned int wpos; unsigned int hx; - out = GNUNET_strdup (in); + out = GNUNET_strdup(in); rpos = 0; wpos = 0; while (out[rpos] != '\0') - { - if (out[rpos] == '%') - { - if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) - { - GNUNET_free (out); - *emsg = GNUNET_strdup ( - _ (/* xgettext:no-c-format */ - "Malformed KSK URI (`%' must be followed by HEX number)")); - return NULL; - } - rpos += 3; - if (hx == '"') - continue; /* skip double quote */ - out[wpos++] = (char) hx; - } - else { - out[wpos++] = out[rpos++]; + if (out[rpos] == '%') + { + if (1 != sscanf(&out[rpos + 1], "%2X", &hx)) + { + GNUNET_free(out); + *emsg = GNUNET_strdup( + _(/* xgettext:no-c-format */ + "Malformed KSK URI (`%' must be followed by HEX number)")); + return NULL; + } + rpos += 3; + if (hx == '"') + continue; /* skip double quote */ + out[wpos++] = (char)hx; + } + else + { + out[wpos++] = out[rpos++]; + } } - } out[wpos] = '\0'; if (out[0] == '+') - { - ret = GNUNET_strdup (out); - } + { + ret = GNUNET_strdup(out); + } else - { - /* need to prefix with space */ - ret = GNUNET_malloc (strlen (out) + 2); - strcpy (ret, " "); - strcat (ret, out); - } - GNUNET_free (out); + { + /* need to prefix with space */ + ret = GNUNET_malloc(strlen(out) + 2); + strcpy(ret, " "); + strcat(ret, out); + } + GNUNET_free(out); return ret; } @@ -271,7 +275,7 @@ percent_decode_keyword (const char *in, char **emsg) * @return NULL on error, otherwise the KSK URI */ static struct GNUNET_FS_Uri * -uri_ksk_parse (const char *s, char **emsg) +uri_ksk_parse(const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; char **keywords; @@ -283,74 +287,74 @@ uri_ksk_parse (const char *s, char **emsg) char *dup; int saw_quote; - slen = strlen (s); - pos = strlen (GNUNET_FS_URI_KSK_PREFIX); - if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) + slen = strlen(s); + pos = strlen(GNUNET_FS_URI_KSK_PREFIX); + if ((slen <= pos) || (0 != strncmp(s, GNUNET_FS_URI_KSK_PREFIX, pos))) return NULL; /* not KSK URI */ if ((s[slen - 1] == '+') || (s[pos] == '+')) - { - *emsg = - GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); - return NULL; - } + { + *emsg = + GNUNET_strdup(_("Malformed KSK URI (must not begin or end with `+')")); + return NULL; + } max = 1; saw_quote = 0; for (i = pos; i < slen; i++) - { - if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) - { - saw_quote = (saw_quote + 1) % 2; - i += 3; - continue; - } - if ((s[i] == '+') && (saw_quote == 0)) { - max++; - if (s[i - 1] == '+') - { - *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); - return NULL; - } + if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) + { + saw_quote = (saw_quote + 1) % 2; + i += 3; + continue; + } + if ((s[i] == '+') && (saw_quote == 0)) + { + max++; + if (s[i - 1] == '+') + { + *emsg = GNUNET_strdup(_("Malformed KSK URI (`++' not allowed)")); + return NULL; + } + } } - } if (saw_quote == 1) - { - *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); - return NULL; - } - iret = max; - dup = GNUNET_strdup (s); - keywords = GNUNET_new_array (max, char *); - for (i = slen - 1; i >= (int) pos; i--) - { - if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) { - saw_quote = (saw_quote + 1) % 2; - continue; + *emsg = GNUNET_strdup(_("Malformed KSK URI (quotes not balanced)")); + return NULL; } - if ((dup[i] == '+') && (saw_quote == 0)) + iret = max; + dup = GNUNET_strdup(s); + keywords = GNUNET_new_array(max, char *); + for (i = slen - 1; i >= (int)pos; i--) { - keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); - if (NULL == keywords[max]) - goto CLEANUP; - dup[i] = '\0'; + if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) + { + saw_quote = (saw_quote + 1) % 2; + continue; + } + if ((dup[i] == '+') && (saw_quote == 0)) + { + keywords[--max] = percent_decode_keyword(&dup[i + 1], emsg); + if (NULL == keywords[max]) + goto CLEANUP; + dup[i] = '\0'; + } } - } - keywords[--max] = percent_decode_keyword (&dup[pos], emsg); + keywords[--max] = percent_decode_keyword(&dup[pos], emsg); if (NULL == keywords[max]) goto CLEANUP; - GNUNET_assert (0 == max); - GNUNET_free (dup); - ret = GNUNET_new (struct GNUNET_FS_Uri); + GNUNET_assert(0 == max); + GNUNET_free(dup); + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_KSK; ret->data.ksk.keywordCount = iret; ret->data.ksk.keywords = keywords; return ret; CLEANUP: for (i = 0; i < max; i++) - GNUNET_free_non_null (keywords[i]); - GNUNET_free (keywords); - GNUNET_free (dup); + GNUNET_free_non_null(keywords[i]); + GNUNET_free(keywords); + GNUNET_free(dup); return NULL; } @@ -365,31 +369,31 @@ CLEANUP: * @return NULL on error, SKS URI otherwise */ static struct GNUNET_FS_Uri * -uri_sks_parse (const char *s, char **emsg) +uri_sks_parse(const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; struct GNUNET_CRYPTO_EcdsaPublicKey ns; size_t pos; char *end; - pos = strlen (GNUNET_FS_URI_SKS_PREFIX); - if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) + pos = strlen(GNUNET_FS_URI_SKS_PREFIX); + if ((strlen(s) <= pos) || (0 != strncmp(s, GNUNET_FS_URI_SKS_PREFIX, pos))) return NULL; /* not an SKS URI */ - end = strchr (&s[pos], '/'); + end = strchr(&s[pos], '/'); if ((NULL == end) || - (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], - end - &s[pos], - &ns, - sizeof (ns)))) - { - *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); - return NULL; /* malformed */ - } + (GNUNET_OK != GNUNET_STRINGS_string_to_data(&s[pos], + end - &s[pos], + &ns, + sizeof(ns)))) + { + *emsg = GNUNET_strdup(_("Malformed SKS URI (wrong syntax)")); + return NULL; /* malformed */ + } end++; /* skip over '/' */ - ret = GNUNET_new (struct GNUNET_FS_Uri); + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_SKS; ret->data.sks.ns = ns; - ret->data.sks.identifier = GNUNET_strdup (end); + ret->data.sks.identifier = GNUNET_strdup(end); return ret; } @@ -404,46 +408,46 @@ uri_sks_parse (const char *s, char **emsg) * @return NULL on error, CHK URI otherwise */ static struct GNUNET_FS_Uri * -uri_chk_parse (const char *s, char **emsg) +uri_chk_parse(const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; struct FileIdentifier fi; unsigned int pos; unsigned long long flen; size_t slen; - char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; - char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; + char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; + char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; - slen = strlen (s); - pos = strlen (GNUNET_FS_URI_CHK_PREFIX); - if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || - (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) + slen = strlen(s); + pos = strlen(GNUNET_FS_URI_CHK_PREFIX); + if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || + (0 != strncmp(s, GNUNET_FS_URI_CHK_PREFIX, pos))) return NULL; /* not a CHK URI */ - if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || - (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) - { - *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); - return NULL; - } - GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); - h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - GNUNET_memcpy (h2, - &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); - h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - - if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || - (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || + if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || + (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) + { + *emsg = GNUNET_strdup(_("Malformed CHK URI (wrong syntax)")); + return NULL; + } + GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); + h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; + GNUNET_memcpy(h2, + &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); + h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; + + if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &fi.chk.key)) || + (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &fi.chk.query)) || (1 != - sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], - "%llu", - &flen))) - { - *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); - return NULL; - } - fi.file_length = GNUNET_htonll (flen); - ret = GNUNET_new (struct GNUNET_FS_Uri); + sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], + "%llu", + &flen))) + { + *emsg = GNUNET_strdup(_("Malformed CHK URI (failed to decode CHK)")); + return NULL; + } + fi.file_length = GNUNET_htonll(flen); + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_CHK; ret->data.chk = fi; return ret; @@ -456,8 +460,7 @@ GNUNET_NETWORK_STRUCT_BEGIN * assembled in memory to create or verify the signature of a location * URI. */ -struct LocUriAssembly -{ +struct LocUriAssembly { /** * What is being signed (rest of this struct). */ @@ -494,11 +497,11 @@ GNUNET_NETWORK_STRUCT_END * @return NULL on error, valid LOC URI otherwise */ static struct GNUNET_FS_Uri * -uri_loc_parse (const char *s, char **emsg) +uri_loc_parse(const char *s, char **emsg) { struct GNUNET_FS_Uri *uri; - char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; - char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; + char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; + char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; unsigned int pos; unsigned int npos; unsigned long long exptime; @@ -508,113 +511,113 @@ uri_loc_parse (const char *s, char **emsg) struct LocUriAssembly ass; size_t slen; - slen = strlen (s); - pos = strlen (GNUNET_FS_URI_LOC_PREFIX); - if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || - (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) + slen = strlen(s); + pos = strlen(GNUNET_FS_URI_LOC_PREFIX); + if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || + (0 != strncmp(s, GNUNET_FS_URI_LOC_PREFIX, pos))) return NULL; /* not a LOC URI */ - if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || - (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) - { - *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); - return NULL; - } - GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); - h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - GNUNET_memcpy (h2, - &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); - h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - - if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || - (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || + if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || + (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) + { + *emsg = GNUNET_strdup(_("LOC URI malformed (wrong syntax)")); + return NULL; + } + GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); + h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; + GNUNET_memcpy(h2, + &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); + h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; + + if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &ass.fi.chk.key)) || + (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &ass.fi.chk.query)) || (1 != - sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], - "%llu", - &flen))) - { - *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); - return NULL; - } - ass.fi.file_length = GNUNET_htonll (flen); + sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], + "%llu", + &flen))) + { + *emsg = GNUNET_strdup(_("LOC URI malformed (no CHK)")); + return NULL; + } + ass.fi.file_length = GNUNET_htonll(flen); - npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; + npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; while ((s[npos] != '\0') && (s[npos] != '.')) npos++; if (s[npos] == '\0') - { - *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); - goto ERR; - } + { + *emsg = GNUNET_strdup(_("LOC URI malformed (missing LOC)")); + goto ERR; + } npos++; - if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || + if ((strlen(&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); - } + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (wrong syntax for public key)")); + } if ( GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], - GNUNET_CRYPTO_PKEY_ASCII_LENGTH, - &ass.peer.public_key)) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); - goto ERR; - } + GNUNET_CRYPTO_eddsa_public_key_from_string(&s[npos], + GNUNET_CRYPTO_PKEY_ASCII_LENGTH, + &ass.peer.public_key)) + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (could not decode public key)")); + goto ERR; + } npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; if (s[npos++] != '.') - { - *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); - goto ERR; - } - if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || + { + *emsg = GNUNET_strdup(_("LOC URI malformed (could not find signature)")); + goto ERR; + } + if ((strlen(&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); - goto ERR; - } + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (wrong syntax for signature)")); + goto ERR; + } if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (&s[npos], - SIGNATURE_ASCII_LENGTH, - &sig, - sizeof ( - struct GNUNET_CRYPTO_EddsaSignature))) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); - goto ERR; - } + GNUNET_STRINGS_string_to_data(&s[npos], + SIGNATURE_ASCII_LENGTH, + &sig, + sizeof( + struct GNUNET_CRYPTO_EddsaSignature))) + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (could not decode signature)")); + goto ERR; + } npos += SIGNATURE_ASCII_LENGTH; if (s[npos++] != '.') - { - *emsg = GNUNET_strdup ( - _ ("LOC URI malformed (wrong syntax for expiration time)")); - goto ERR; - } - if (1 != sscanf (&s[npos], "%llu", &exptime)) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); - goto ERR; - } - ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); - ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); + { + *emsg = GNUNET_strdup( + _("LOC URI malformed (wrong syntax for expiration time)")); + goto ERR; + } + if (1 != sscanf(&s[npos], "%llu", &exptime)) + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (could not parse expiration time)")); + goto ERR; + } + ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); + ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); et.abs_value_us = exptime * 1000LL * 1000LL; - ass.exptime = GNUNET_TIME_absolute_hton (et); + ass.exptime = GNUNET_TIME_absolute_hton(et); if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, - &ass.purpose, - &sig, - &ass.peer.public_key)) - { - *emsg = - GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); - goto ERR; - } - uri = GNUNET_new (struct GNUNET_FS_Uri); + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, + &ass.purpose, + &sig, + &ass.peer.public_key)) + { + *emsg = + GNUNET_strdup(_("LOC URI malformed (signature failed validation)")); + goto ERR; + } + uri = GNUNET_new(struct GNUNET_FS_Uri); uri->type = GNUNET_FS_URI_LOC; uri->data.loc.fi = ass.fi; uri->data.loc.peer = ass.peer; @@ -635,30 +638,30 @@ ERR: * @return NULL on error */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_parse (const char *uri, char **emsg) +GNUNET_FS_uri_parse(const char *uri, char **emsg) { struct GNUNET_FS_Uri *ret; char *msg; if (NULL == uri) - { - GNUNET_break (0); - if (NULL != emsg) - *emsg = GNUNET_strdup (_ ("invalid argument")); - return NULL; - } + { + GNUNET_break(0); + if (NULL != emsg) + *emsg = GNUNET_strdup(_("invalid argument")); + return NULL; + } if (NULL == emsg) emsg = &msg; *emsg = NULL; - if ((NULL != (ret = uri_chk_parse (uri, emsg))) || - (NULL != (ret = uri_ksk_parse (uri, emsg))) || - (NULL != (ret = uri_sks_parse (uri, emsg))) || - (NULL != (ret = uri_loc_parse (uri, emsg)))) + if ((NULL != (ret = uri_chk_parse(uri, emsg))) || + (NULL != (ret = uri_ksk_parse(uri, emsg))) || + (NULL != (ret = uri_sks_parse(uri, emsg))) || + (NULL != (ret = uri_loc_parse(uri, emsg)))) return ret; if (NULL == *emsg) - *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); + *emsg = GNUNET_strdup(_("Unrecognized URI type")); if (emsg == &msg) - GNUNET_free (msg); + GNUNET_free(msg); return NULL; } @@ -669,27 +672,30 @@ GNUNET_FS_uri_parse (const char *uri, char **emsg) * @param uri uri to free */ void -GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri) { unsigned int i; switch (uri->type) - { - case GNUNET_FS_URI_KSK: - for (i = 0; i < uri->data.ksk.keywordCount; i++) - GNUNET_free (uri->data.ksk.keywords[i]); - GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); - break; - case GNUNET_FS_URI_SKS: - GNUNET_free (uri->data.sks.identifier); - break; - case GNUNET_FS_URI_LOC: - break; - default: - /* do nothing */ - break; - } - GNUNET_free (uri); + { + case GNUNET_FS_URI_KSK: + for (i = 0; i < uri->data.ksk.keywordCount; i++) + GNUNET_free(uri->data.ksk.keywords[i]); + GNUNET_array_grow(uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); + break; + + case GNUNET_FS_URI_SKS: + GNUNET_free(uri->data.sks.identifier); + break; + + case GNUNET_FS_URI_LOC: + break; + + default: + /* do nothing */ + break; + } + GNUNET_free(uri); } @@ -700,7 +706,7 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) * @return 0 if this is not a keyword URI */ unsigned int -GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri) { if (uri->type != GNUNET_FS_URI_KSK) return 0; @@ -718,9 +724,9 @@ GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) * keywords iterated over until iterator aborted */ int -GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, - GNUNET_FS_KeywordIterator iterator, - void *iterator_cls) +GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, + GNUNET_FS_KeywordIterator iterator, + void *iterator_cls) { unsigned int i; char *keyword; @@ -730,13 +736,13 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, if (NULL == iterator) return uri->data.ksk.keywordCount; for (i = 0; i < uri->data.ksk.keywordCount; i++) - { - keyword = uri->data.ksk.keywords[i]; - /* first character of keyword indicates - * if it is mandatory or not */ - if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+')) - return i; - } + { + keyword = uri->data.ksk.keywords[i]; + /* first character of keyword indicates + * if it is mandatory or not */ + if (GNUNET_OK != iterator(iterator_cls, &keyword[1], keyword[0] == '+')) + return i; + } return i; } @@ -750,23 +756,23 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, * @param is_mandatory is this keyword mandatory? */ void -GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, - const char *keyword, - int is_mandatory) +GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri, + const char *keyword, + int is_mandatory) { unsigned int i; const char *old; char *n; - GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); + GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); for (i = 0; i < uri->data.ksk.keywordCount; i++) - { - old = uri->data.ksk.keywords[i]; - if (0 == strcmp (&old[1], keyword)) - return; - } - GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword); - GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); + { + old = uri->data.ksk.keywords[i]; + if (0 == strcmp(&old[1], keyword)) + return; + } + GNUNET_asprintf(&n, is_mandatory ? "+%s" : " %s", keyword); + GNUNET_array_append(uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); } @@ -778,27 +784,27 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, * @param keyword keyword to add */ void -GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, - const char *keyword) +GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri, + const char *keyword) { unsigned int i; char *old; - GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); + GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); for (i = 0; i < uri->data.ksk.keywordCount; i++) - { - old = uri->data.ksk.keywords[i]; - if (0 == strcmp (&old[1], keyword)) { - uri->data.ksk.keywords[i] = - uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; - GNUNET_array_grow (uri->data.ksk.keywords, - uri->data.ksk.keywordCount, - uri->data.ksk.keywordCount - 1); - GNUNET_free (old); - return; + old = uri->data.ksk.keywords[i]; + if (0 == strcmp(&old[1], keyword)) + { + uri->data.ksk.keywords[i] = + uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; + GNUNET_array_grow(uri->data.ksk.keywords, + uri->data.ksk.keywordCount, + uri->data.ksk.keywordCount - 1); + GNUNET_free(old); + return; + } } - } } @@ -810,8 +816,8 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK */ int -GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, - struct GNUNET_PeerIdentity *peer) +GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, + struct GNUNET_PeerIdentity *peer) { if (uri->type != GNUNET_FS_URI_LOC) return GNUNET_SYSERR; @@ -827,9 +833,9 @@ GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, * @return expiration time of the URI */ struct GNUNET_TIME_Absolute -GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri) { - GNUNET_assert (uri->type == GNUNET_FS_URI_LOC); + GNUNET_assert(uri->type == GNUNET_FS_URI_LOC); return uri->data.loc.expirationTime; } @@ -841,13 +847,13 @@ GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) * @return NULL if argument is not a location URI */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri) { struct GNUNET_FS_Uri *ret; if (uri->type != GNUNET_FS_URI_LOC) return NULL; - ret = GNUNET_new (struct GNUNET_FS_Uri); + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_CHK; ret->data.chk = uri->data.loc.fi; return ret; @@ -867,9 +873,9 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) * @return the location URI, NULL on error */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, - const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, - struct GNUNET_TIME_Absolute expiration_time) +GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, + const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, + struct GNUNET_TIME_Absolute expiration_time) { struct GNUNET_FS_Uri *uri; struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; @@ -880,21 +886,21 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, return NULL; /* we round expiration time to full seconds for SKS URIs */ et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; - GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); - ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); - ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); - ass.exptime = GNUNET_TIME_absolute_hton (et); + GNUNET_CRYPTO_eddsa_key_get_public(sign_key, &my_public_key); + ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); + ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); + ass.exptime = GNUNET_TIME_absolute_hton(et); ass.fi = base_uri->data.chk; ass.peer.public_key = my_public_key; - uri = GNUNET_new (struct GNUNET_FS_Uri); + uri = GNUNET_new(struct GNUNET_FS_Uri); uri->type = GNUNET_FS_URI_LOC; uri->data.loc.fi = base_uri->data.chk; uri->data.loc.expirationTime = et; uri->data.loc.peer.public_key = my_public_key; - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (sign_key, - &ass.purpose, - &uri->data.loc.contentSignature)); + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign(sign_key, + &ass.purpose, + &uri->data.loc.contentSignature)); return uri; } @@ -907,15 +913,15 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, * @return an FS URI for the given namespace and identifier */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, - const char *id) +GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, + const char *id) { struct GNUNET_FS_Uri *ns_uri; - ns_uri = GNUNET_new (struct GNUNET_FS_Uri); + ns_uri = GNUNET_new(struct GNUNET_FS_Uri); ns_uri->type = GNUNET_FS_URI_SKS; ns_uri->data.sks.ns = *ns; - ns_uri->data.sks.identifier = GNUNET_strdup (id); + ns_uri->data.sks.identifier = GNUNET_strdup(id); return ns_uri; } @@ -930,8 +936,8 @@ GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, * @return merged URI, NULL on error */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, - const struct GNUNET_FS_Uri *u2) +GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, + const struct GNUNET_FS_Uri *u2) { struct GNUNET_FS_Uri *ret; unsigned int kc; @@ -944,34 +950,34 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, if ((u1 == NULL) && (u2 == NULL)) return NULL; if (u1 == NULL) - return GNUNET_FS_uri_dup (u2); + return GNUNET_FS_uri_dup(u2); if (u2 == NULL) - return GNUNET_FS_uri_dup (u1); + return GNUNET_FS_uri_dup(u1); if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } kc = u1->data.ksk.keywordCount; - kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); + kl = GNUNET_new_array(kc + u2->data.ksk.keywordCount, char *); for (i = 0; i < u1->data.ksk.keywordCount; i++) - kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); + kl[i] = GNUNET_strdup(u1->data.ksk.keywords[i]); for (i = 0; i < u2->data.ksk.keywordCount; i++) - { - kp = u2->data.ksk.keywords[i]; - found = 0; - for (j = 0; j < u1->data.ksk.keywordCount; j++) - if (0 == strcmp (kp + 1, kl[j] + 1)) - { - found = 1; - if (kp[0] == '+') - kl[j][0] = '+'; - break; - } - if (0 == found) - kl[kc++] = GNUNET_strdup (kp); - } - ret = GNUNET_new (struct GNUNET_FS_Uri); + { + kp = u2->data.ksk.keywords[i]; + found = 0; + for (j = 0; j < u1->data.ksk.keywordCount; j++) + if (0 == strcmp(kp + 1, kl[j] + 1)) + { + found = 1; + if (kp[0] == '+') + kl[j][0] = '+'; + break; + } + if (0 == found) + kl[kc++] = GNUNET_strdup(kp); + } + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_KSK; ret->data.ksk.keywordCount = kc; ret->data.ksk.keywords = kl; @@ -986,43 +992,46 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, * @return copy of the URI */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri) { struct GNUNET_FS_Uri *ret; unsigned int i; if (uri == NULL) return NULL; - ret = GNUNET_new (struct GNUNET_FS_Uri); - GNUNET_memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); + ret = GNUNET_new(struct GNUNET_FS_Uri); + GNUNET_memcpy(ret, uri, sizeof(struct GNUNET_FS_Uri)); switch (ret->type) - { - case GNUNET_FS_URI_KSK: - if (ret->data.ksk.keywordCount >= - GNUNET_MAX_MALLOC_CHECKED / sizeof (char *)) { - GNUNET_break (0); - GNUNET_free (ret); - return NULL; - } - if (ret->data.ksk.keywordCount > 0) - { - ret->data.ksk.keywords = - GNUNET_new_array (ret->data.ksk.keywordCount, char *); - for (i = 0; i < ret->data.ksk.keywordCount; i++) - ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); + case GNUNET_FS_URI_KSK: + if (ret->data.ksk.keywordCount >= + GNUNET_MAX_MALLOC_CHECKED / sizeof(char *)) + { + GNUNET_break(0); + GNUNET_free(ret); + return NULL; + } + if (ret->data.ksk.keywordCount > 0) + { + ret->data.ksk.keywords = + GNUNET_new_array(ret->data.ksk.keywordCount, char *); + for (i = 0; i < ret->data.ksk.keywordCount; i++) + ret->data.ksk.keywords[i] = GNUNET_strdup(uri->data.ksk.keywords[i]); + } + else + ret->data.ksk.keywords = NULL; /* just to be sure */ + break; + + case GNUNET_FS_URI_SKS: + ret->data.sks.identifier = GNUNET_strdup(uri->data.sks.identifier); + break; + + case GNUNET_FS_URI_LOC: + break; + + default: + break; } - else - ret->data.ksk.keywords = NULL; /* just to be sure */ - break; - case GNUNET_FS_URI_SKS: - ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); - break; - case GNUNET_FS_URI_LOC: - break; - default: - break; - } return ret; } @@ -1045,7 +1054,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) * if keywords is not legal (i.e. empty). */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) +GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) { char **keywordarr; unsigned int num_Words; @@ -1056,68 +1065,68 @@ GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) int saw_quote; if (keywords == NULL) - { - *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); - GNUNET_break (0); - return NULL; - } - searchString = GNUNET_strdup (keywords); + { + *emsg = GNUNET_strdup(_("No keywords specified!\n")); + GNUNET_break(0); + return NULL; + } + searchString = GNUNET_strdup(keywords); num_Words = 0; inWord = 0; saw_quote = 0; pos = searchString; while ('\0' != *pos) - { - if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) { - inWord = 0; + if ((saw_quote == 0) && (isspace((unsigned char)*pos))) + { + inWord = 0; + } + else if (0 == inWord) + { + inWord = 1; + ++num_Words; + } + if ('"' == *pos) + saw_quote = (saw_quote + 1) % 2; + pos++; } - else if (0 == inWord) + if (num_Words == 0) { - inWord = 1; - ++num_Words; + GNUNET_free(searchString); + *emsg = GNUNET_strdup(_("No keywords specified!\n")); + return NULL; } - if ('"' == *pos) - saw_quote = (saw_quote + 1) % 2; - pos++; - } - if (num_Words == 0) - { - GNUNET_free (searchString); - *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); - return NULL; - } if (saw_quote != 0) - { - GNUNET_free (searchString); - *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); - return NULL; - } - keywordarr = GNUNET_new_array (num_Words, char *); + { + GNUNET_free(searchString); + *emsg = GNUNET_strdup(_("Number of double-quotes not balanced!\n")); + return NULL; + } + keywordarr = GNUNET_new_array(num_Words, char *); num_Words = 0; inWord = 0; pos = searchString; while ('\0' != *pos) - { - if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) - { - inWord = 0; - *pos = '\0'; - } - else if (0 == inWord) { - keywordarr[num_Words] = pos; - inWord = 1; - ++num_Words; + if ((saw_quote == 0) && (isspace((unsigned char)*pos))) + { + inWord = 0; + *pos = '\0'; + } + else if (0 == inWord) + { + keywordarr[num_Words] = pos; + inWord = 1; + ++num_Words; + } + if ('"' == *pos) + saw_quote = (saw_quote + 1) % 2; + pos++; } - if ('"' == *pos) - saw_quote = (saw_quote + 1) % 2; - pos++; - } uri = - GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); - GNUNET_free (keywordarr); - GNUNET_free (searchString); + GNUNET_FS_uri_ksk_create_from_args(num_Words, (const char **)keywordarr); + GNUNET_free(keywordarr); + GNUNET_free(searchString); return uri; } @@ -1140,7 +1149,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) * if keywords is not legal (i.e. empty). */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) +GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) { unsigned int i; struct GNUNET_FS_Uri *uri; @@ -1155,36 +1164,36 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) /* allow URI to be given as one and only keyword and * handle accordingly */ emsg = NULL; - if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && - (0 == strncmp (argv[0], - GNUNET_FS_URI_PREFIX, - strlen (GNUNET_FS_URI_PREFIX))) && - (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) + if ((argc == 1) && (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && + (0 == strncmp(argv[0], + GNUNET_FS_URI_PREFIX, + strlen(GNUNET_FS_URI_PREFIX))) && + (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)))) return uri; - GNUNET_free_non_null (emsg); - uri = GNUNET_new (struct GNUNET_FS_Uri); + GNUNET_free_non_null(emsg); + uri = GNUNET_new(struct GNUNET_FS_Uri); uri->type = GNUNET_FS_URI_KSK; uri->data.ksk.keywordCount = argc; - uri->data.ksk.keywords = GNUNET_new_array (argc, char *); + uri->data.ksk.keywords = GNUNET_new_array(argc, char *); for (i = 0; i < argc; i++) - { - keyword = argv[i]; - if (keyword[0] == '+') - val = GNUNET_strdup (keyword); - else - GNUNET_asprintf (&val, " %s", keyword); - r = val; - w = val; - while ('\0' != *r) { - if ('"' == *r) - r++; + keyword = argv[i]; + if (keyword[0] == '+') + val = GNUNET_strdup(keyword); else - *(w++) = *(r++); + GNUNET_asprintf(&val, " %s", keyword); + r = val; + w = val; + while ('\0' != *r) + { + if ('"' == *r) + r++; + else + *(w++) = *(r++); + } + *w = '\0'; + uri->data.ksk.keywords[i] = val; } - *w = '\0'; - uri->data.ksk.keywords[i] = val; - } return uri; } @@ -1197,62 +1206,66 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) * @return #GNUNET_YES if the URIs are equal */ int -GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, - const struct GNUNET_FS_Uri *u2) +GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, + const struct GNUNET_FS_Uri *u2) { int ret; unsigned int i; unsigned int j; - GNUNET_assert (u1 != NULL); - GNUNET_assert (u2 != NULL); + GNUNET_assert(u1 != NULL); + GNUNET_assert(u2 != NULL); if (u1->type != u2->type) return GNUNET_NO; switch (u1->type) - { - case GNUNET_FS_URI_CHK: - if (0 == - memcmp (&u1->data.chk, &u2->data.chk, sizeof (struct FileIdentifier))) - return GNUNET_YES; - return GNUNET_NO; - case GNUNET_FS_URI_SKS: - if ((0 == memcmp (&u1->data.sks.ns, - &u2->data.sks.ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && - (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) + { + case GNUNET_FS_URI_CHK: + if (0 == + memcmp(&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier))) + return GNUNET_YES; + return GNUNET_NO; - return GNUNET_YES; - return GNUNET_NO; - case GNUNET_FS_URI_KSK: - if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) + case GNUNET_FS_URI_SKS: + if ((0 == memcmp(&u1->data.sks.ns, + &u2->data.sks.ns, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) && + (0 == strcmp(u1->data.sks.identifier, u2->data.sks.identifier))) + + return GNUNET_YES; return GNUNET_NO; - for (i = 0; i < u1->data.ksk.keywordCount; i++) - { - ret = GNUNET_NO; - for (j = 0; j < u2->data.ksk.keywordCount; j++) - { - if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) + + case GNUNET_FS_URI_KSK: + if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) + return GNUNET_NO; + for (i = 0; i < u1->data.ksk.keywordCount; i++) { - ret = GNUNET_YES; - break; + ret = GNUNET_NO; + for (j = 0; j < u2->data.ksk.keywordCount; j++) + { + if (0 == strcmp(u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) + { + ret = GNUNET_YES; + break; + } + } + if (ret == GNUNET_NO) + return GNUNET_NO; } - } - if (ret == GNUNET_NO) + return GNUNET_YES; + + case GNUNET_FS_URI_LOC: + if (memcmp(&u1->data.loc, + &u2->data.loc, + sizeof(struct FileIdentifier) + + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + + sizeof(struct GNUNET_TIME_Absolute) + + sizeof(unsigned short) + sizeof(unsigned short)) != 0) return GNUNET_NO; - } - return GNUNET_YES; - case GNUNET_FS_URI_LOC: - if (memcmp (&u1->data.loc, - &u2->data.loc, - sizeof (struct FileIdentifier) + - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + - sizeof (struct GNUNET_TIME_Absolute) + - sizeof (unsigned short) + sizeof (unsigned short)) != 0) + return GNUNET_YES; + + default: return GNUNET_NO; - return GNUNET_YES; - default: - return GNUNET_NO; - } + } } @@ -1263,7 +1276,7 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, * @return #GNUNET_YES if this is an SKS uri */ int -GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri) { return uri->type == GNUNET_FS_URI_SKS; } @@ -1278,14 +1291,14 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) * @return #GNUNET_OK on success */ int -GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, - struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) +GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri, + struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) { - if (! GNUNET_FS_uri_test_sks (uri)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + if (!GNUNET_FS_uri_test_sks(uri)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } *pseudonym = uri->data.sks.ns; return GNUNET_OK; } @@ -1298,14 +1311,14 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, * @return NULL on error (not a valid SKS URI) */ char * -GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri) { - if (! GNUNET_FS_uri_test_sks (uri)) - { - GNUNET_break (0); - return NULL; - } - return GNUNET_strdup (uri->data.sks.identifier); + if (!GNUNET_FS_uri_test_sks(uri)) + { + GNUNET_break(0); + return NULL; + } + return GNUNET_strdup(uri->data.sks.identifier); } @@ -1316,16 +1329,16 @@ GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) * @return #GNUNET_YES if this is a KSK uri */ int -GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri) { #if EXTRA_CHECKS unsigned int i; if (uri->type == GNUNET_FS_URI_KSK) - { - for (i = 0; i < uri->data.ksk.keywordCount; i++) - GNUNET_assert (uri->data.ksk.keywords[i] != NULL); - } + { + for (i = 0; i < uri->data.ksk.keywordCount; i++) + GNUNET_assert(uri->data.ksk.keywords[i] != NULL); + } #endif return uri->type == GNUNET_FS_URI_KSK; } @@ -1338,7 +1351,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) * @return #GNUNET_YES if this is a CHK uri */ int -GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri) { return uri->type == GNUNET_FS_URI_CHK; } @@ -1352,17 +1365,19 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) * @return size of the file as specified in the CHK URI */ uint64_t -GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri) { switch (uri->type) - { - case GNUNET_FS_URI_CHK: - return GNUNET_ntohll (uri->data.chk.file_length); - case GNUNET_FS_URI_LOC: - return GNUNET_ntohll (uri->data.loc.fi.file_length); - default: - GNUNET_assert (0); - } + { + case GNUNET_FS_URI_CHK: + return GNUNET_ntohll(uri->data.chk.file_length); + + case GNUNET_FS_URI_LOC: + return GNUNET_ntohll(uri->data.loc.fi.file_length); + + default: + GNUNET_assert(0); + } return 0; /* unreachable */ } @@ -1374,7 +1389,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) * @return #GNUNET_YES if this is a LOC uri */ int -GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri) { return uri->type == GNUNET_FS_URI_LOC; } @@ -1390,13 +1405,13 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) * @param index offset where to add the keyword */ static void -insert_non_mandatory_keyword (const char *s, char **array, int index) +insert_non_mandatory_keyword(const char *s, char **array, int index) { char *nkword; - GNUNET_asprintf (&nkword, - " %s", /* space to mark as 'non mandatory' */ - s); + GNUNET_asprintf(&nkword, + " %s", /* space to mark as 'non mandatory' */ + s); array[index] = nkword; } @@ -1411,12 +1426,12 @@ insert_non_mandatory_keyword (const char *s, char **array, int index) * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not */ static int -find_duplicate (const char *s, const char **array, int array_length) +find_duplicate(const char *s, const char **array, int array_length) { int j; for (j = array_length - 1; j >= 0; j--) - if (0 == strcmp (&array[j][1], s)) + if (0 == strcmp(&array[j][1], s)) return GNUNET_YES; return GNUNET_NO; } @@ -1426,53 +1441,54 @@ find_duplicate (const char *s, const char **array, int array_length) * FIXME: comment */ static char * -normalize_metadata (enum EXTRACTOR_MetaFormat format, - const char *data, - size_t data_len) +normalize_metadata(enum EXTRACTOR_MetaFormat format, + const char *data, + size_t data_len) { uint8_t *free_str = NULL; - uint8_t *str_to_normalize = (uint8_t *) data; + uint8_t *str_to_normalize = (uint8_t *)data; uint8_t *normalized; size_t r_len; + if (str_to_normalize == NULL) return NULL; /* Don't trust libextractor */ if (format == EXTRACTOR_METAFORMAT_UTF8) - { - free_str = (uint8_t *) u8_check ((const uint8_t *) data, data_len); - if (free_str == NULL) - free_str = NULL; - else - format = EXTRACTOR_METAFORMAT_C_STRING; - } + { + free_str = (uint8_t *)u8_check((const uint8_t *)data, data_len); + if (free_str == NULL) + free_str = NULL; + else + format = EXTRACTOR_METAFORMAT_C_STRING; + } if (format == EXTRACTOR_METAFORMAT_C_STRING) - { - free_str = u8_strconv_from_encoding (data, - locale_charset (), - iconveh_escape_sequence); - if (free_str == NULL) - return NULL; - } - - normalized = u8_tolower (str_to_normalize, - strlen ((char *) str_to_normalize), - NULL, - UNINORM_NFD, - NULL, - &r_len); + { + free_str = u8_strconv_from_encoding(data, + locale_charset(), + iconveh_escape_sequence); + if (free_str == NULL) + return NULL; + } + + normalized = u8_tolower(str_to_normalize, + strlen((char *)str_to_normalize), + NULL, + UNINORM_NFD, + NULL, + &r_len); /* free_str is allocated by libunistring internally, use free() */ if (free_str != NULL) - free (free_str); + free(free_str); if (normalized != NULL) - { - /* u8_tolower allocates a non-NULL-terminated string! */ - free_str = GNUNET_malloc (r_len + 1); - GNUNET_memcpy (free_str, normalized, r_len); - free_str[r_len] = '\0'; - free (normalized); - normalized = free_str; - } - return (char *) normalized; + { + /* u8_tolower allocates a non-NULL-terminated string! */ + free_str = GNUNET_malloc(r_len + 1); + GNUNET_memcpy(free_str, normalized, r_len); + free_str[r_len] = '\0'; + free(normalized); + normalized = free_str; + } + return (char *)normalized; } @@ -1481,15 +1497,16 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, * returns that count. */ static size_t -u8_strcount (const uint8_t *s) +u8_strcount(const uint8_t *s) { size_t count; ucs4_t c; - GNUNET_assert (s != NULL); + + GNUNET_assert(s != NULL); if (s[0] == 0) return 0; for (count = 0; s != NULL; count++) - s = u8_next (&c, s); + s = u8_next(&c, s); return count - 1; } @@ -1511,7 +1528,7 @@ u8_strcount (const uint8_t *s) * were duplicates (when extracting). */ static int -get_keywords_from_parens (const char *s, char **array, int index) +get_keywords_from_parens(const char *s, char **array, int index) { int count = 0; char *open_paren; @@ -1521,77 +1538,80 @@ get_keywords_from_parens (const char *s, char **array, int index) if (NULL == s) return 0; - ss = GNUNET_strdup (s); + ss = GNUNET_strdup(s); open_paren = ss - 1; - while (NULL != (open_paren = strpbrk (open_paren + 1, "[{("))) - { - int match = 0; - - close_paren = strpbrk (open_paren + 1, "]})"); - if (NULL == close_paren) - continue; - switch (open_paren[0]) - { - case '[': - if (']' == close_paren[0]) - match = 1; - break; - case '{': - if ('}' == close_paren[0]) - match = 1; - break; - case '(': - if (')' == close_paren[0]) - match = 1; - break; - default: - break; - } - if (match && (close_paren - open_paren > 1)) + while (NULL != (open_paren = strpbrk(open_paren + 1, "[{("))) { - tmp = close_paren[0]; - close_paren[0] = '\0'; - /* Keywords must be at least 3 characters long */ - if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2) - { - close_paren[0] = tmp; + int match = 0; + + close_paren = strpbrk(open_paren + 1, "]})"); + if (NULL == close_paren) continue; - } - if (NULL != array) - { - char *normalized; - if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], - (const char **) array, - index + count)) + switch (open_paren[0]) { - insert_non_mandatory_keyword ((const char *) &open_paren[1], - array, - index + count); - count++; + case '[': + if (']' == close_paren[0]) + match = 1; + break; + + case '{': + if ('}' == close_paren[0]) + match = 1; + break; + + case '(': + if (')' == close_paren[0]) + match = 1; + break; + + default: + break; } - normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, - &open_paren[1], - close_paren - &open_paren[1]); - if (normalized != NULL) + if (match && (close_paren - open_paren > 1)) { - if (GNUNET_NO == find_duplicate ((const char *) normalized, - (const char **) array, - index + count)) - { - insert_non_mandatory_keyword ((const char *) normalized, - array, - index + count); + tmp = close_paren[0]; + close_paren[0] = '\0'; + /* Keywords must be at least 3 characters long */ + if (u8_strcount((const uint8_t *)&open_paren[1]) <= 2) + { + close_paren[0] = tmp; + continue; + } + if (NULL != array) + { + char *normalized; + if (GNUNET_NO == find_duplicate((const char *)&open_paren[1], + (const char **)array, + index + count)) + { + insert_non_mandatory_keyword((const char *)&open_paren[1], + array, + index + count); + count++; + } + normalized = normalize_metadata(EXTRACTOR_METAFORMAT_UTF8, + &open_paren[1], + close_paren - &open_paren[1]); + if (normalized != NULL) + { + if (GNUNET_NO == find_duplicate((const char *)normalized, + (const char **)array, + index + count)) + { + insert_non_mandatory_keyword((const char *)normalized, + array, + index + count); + count++; + } + GNUNET_free(normalized); + } + } + else count++; - } - GNUNET_free (normalized); + close_paren[0] = tmp; } - } - else - count++; - close_paren[0] = tmp; } - } - GNUNET_free (ss); + GNUNET_free(ss); return count; } @@ -1616,46 +1636,46 @@ get_keywords_from_parens (const char *s, char **array, int index) * duplicates (when extracting). */ static int -get_keywords_from_tokens (const char *s, char **array, int index) +get_keywords_from_tokens(const char *s, char **array, int index) { char *p; char *ss; int seps = 0; - ss = GNUNET_strdup (s); - for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS)) - { - /* Keywords must be at least 3 characters long */ - if (u8_strcount ((const uint8_t *) p) <= 2) - continue; - if (NULL != array) + ss = GNUNET_strdup(s); + for (p = strtok(ss, TOKENS); p != NULL; p = strtok(NULL, TOKENS)) { - char *normalized; - if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) - { - insert_non_mandatory_keyword (p, array, index + seps); - seps++; - } - normalized = - normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); - if (normalized != NULL) - { - if (GNUNET_NO == find_duplicate ((const char *) normalized, - (const char **) array, - index + seps)) + /* Keywords must be at least 3 characters long */ + if (u8_strcount((const uint8_t *)p) <= 2) + continue; + if (NULL != array) { - insert_non_mandatory_keyword ((const char *) normalized, - array, - index + seps); - seps++; + char *normalized; + if (GNUNET_NO == find_duplicate(p, (const char **)array, index + seps)) + { + insert_non_mandatory_keyword(p, array, index + seps); + seps++; + } + normalized = + normalize_metadata(EXTRACTOR_METAFORMAT_UTF8, p, strlen(p)); + if (normalized != NULL) + { + if (GNUNET_NO == find_duplicate((const char *)normalized, + (const char **)array, + index + seps)) + { + insert_non_mandatory_keyword((const char *)normalized, + array, + index + seps); + seps++; + } + GNUNET_free(normalized); + } } - GNUNET_free (normalized); - } + else + seps++; } - else - seps++; - } - GNUNET_free (ss); + GNUNET_free(ss); return seps; } #undef TOKENS @@ -1679,13 +1699,13 @@ get_keywords_from_tokens (const char *s, char **array, int index) * @return 0 (always) */ static int -gather_uri_data (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_len) +gather_uri_data(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) { struct GNUNET_FS_Uri *uri = cls; char *normalized_data; @@ -1699,49 +1719,49 @@ gather_uri_data (void *cls, * and will return the length of its valid part, skipping the keyword. * If it does - fix the extractor, not this check! */ - if (u8_strcount ((const uint8_t *) data) <= 2) + if (u8_strcount((const uint8_t *)data) <= 2) return 0; if ((EXTRACTOR_METATYPE_MIMETYPE == type) && - (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) - { - char *xtra; + (NULL != (sep = memchr(data, '/', data_len))) && (sep != data)) + { + char *xtra; - GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); - if (! find_duplicate (xtra, - (const char **) uri->data.ksk.keywords, + GNUNET_asprintf(&xtra, "mimetype:%.*s", (int)(sep - data), data); + if (!find_duplicate(xtra, + (const char **)uri->data.ksk.keywords, uri->data.ksk.keywordCount)) + { + insert_non_mandatory_keyword(xtra, + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); + uri->data.ksk.keywordCount++; + } + GNUNET_free(xtra); + } + + normalized_data = normalize_metadata(format, data, data_len); + if (!find_duplicate(data, + (const char **)uri->data.ksk.keywords, + uri->data.ksk.keywordCount)) { - insert_non_mandatory_keyword (xtra, - uri->data.ksk.keywords, - uri->data.ksk.keywordCount); + insert_non_mandatory_keyword(data, + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); uri->data.ksk.keywordCount++; } - GNUNET_free (xtra); - } - - normalized_data = normalize_metadata (format, data, data_len); - if (! find_duplicate (data, - (const char **) uri->data.ksk.keywords, - uri->data.ksk.keywordCount)) - { - insert_non_mandatory_keyword (data, - uri->data.ksk.keywords, - uri->data.ksk.keywordCount); - uri->data.ksk.keywordCount++; - } if (NULL != normalized_data) - { - if (! find_duplicate (normalized_data, - (const char **) uri->data.ksk.keywords, - uri->data.ksk.keywordCount)) { - insert_non_mandatory_keyword (normalized_data, - uri->data.ksk.keywords, - uri->data.ksk.keywordCount); - uri->data.ksk.keywordCount++; + if (!find_duplicate(normalized_data, + (const char **)uri->data.ksk.keywords, + uri->data.ksk.keywordCount)) + { + insert_non_mandatory_keyword(normalized_data, + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); + uri->data.ksk.keywordCount++; + } + GNUNET_free(normalized_data); } - GNUNET_free (normalized_data); - } return 0; } @@ -1755,7 +1775,7 @@ gather_uri_data (void *cls, * @return NULL on error, otherwise a KSK URI */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create_from_meta_data ( +GNUNET_FS_uri_ksk_create_from_meta_data( const struct GNUNET_CONTAINER_MetaData *md) { struct GNUNET_FS_Uri *ret; @@ -1768,41 +1788,41 @@ GNUNET_FS_uri_ksk_create_from_meta_data ( if (NULL == md) return NULL; - ret = GNUNET_new (struct GNUNET_FS_Uri); + ret = GNUNET_new(struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_KSK; - ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); + ent = GNUNET_CONTAINER_meta_data_iterate(md, NULL, NULL); if (ent > 0) - { - full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( - md, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - -1); - if (NULL != full_name) { - filename = full_name; - while (NULL != (ss = strstr (filename, DIR_SEPARATOR_STR))) - filename = ss + 1; - tok_keywords = get_keywords_from_tokens (filename, NULL, 0); - paren_keywords = get_keywords_from_parens (filename, NULL, 0); + full_name = GNUNET_CONTAINER_meta_data_get_first_by_types( + md, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + -1); + if (NULL != full_name) + { + filename = full_name; + while (NULL != (ss = strstr(filename, DIR_SEPARATOR_STR))) + filename = ss + 1; + tok_keywords = get_keywords_from_tokens(filename, NULL, 0); + paren_keywords = get_keywords_from_parens(filename, NULL, 0); + } + /* x3 because there might be a normalized variant of every keyword, + plus theoretically one more for mime... */ + ret->data.ksk.keywords = + GNUNET_new_array((ent + tok_keywords + paren_keywords) * 3, char *); + GNUNET_CONTAINER_meta_data_iterate(md, &gather_uri_data, ret); } - /* x3 because there might be a normalized variant of every keyword, - plus theoretically one more for mime... */ - ret->data.ksk.keywords = - GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); - GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); - } if (tok_keywords > 0) ret->data.ksk.keywordCount += - get_keywords_from_tokens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + get_keywords_from_tokens(filename, + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (paren_keywords > 0) ret->data.ksk.keywordCount += - get_keywords_from_parens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + get_keywords_from_parens(filename, + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (ent > 0) - GNUNET_free_non_null (full_name); + GNUNET_free_non_null(full_name); return ret; } @@ -1812,10 +1832,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data ( * need to be encoded using %-encoding? */ static int -needs_percent (char c) +needs_percent(char c) { - return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || - (c == '.') || (c == '~'))); + return(!((isalnum((unsigned char)c)) || (c == '-') || (c == '_') || + (c == '.') || (c == '~'))); } @@ -1826,7 +1846,7 @@ needs_percent (char c) * @return NULL on error (i.e. keywordCount == 0) */ static char * -uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) +uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) { char **keywords; unsigned int keywordCount; @@ -1842,49 +1862,49 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) return NULL; keywords = uri->data.ksk.keywords; keywordCount = uri->data.ksk.keywordCount; - n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) + - strlen (GNUNET_FS_URI_KSK_INFIX) + 1; + n = keywordCount + strlen(GNUNET_FS_URI_PREFIX) + + strlen(GNUNET_FS_URI_KSK_INFIX) + 1; for (i = 0; i < keywordCount; i++) - { - keyword = keywords[i]; - slen = strlen (keyword); - n += slen; - for (j = 0; j < slen; j++) { - if ((j == 0) && (keyword[j] == ' ')) - { - n--; - continue; /* skip leading space */ - } - if (needs_percent (keyword[j])) - n += 2; /* will use %-encoding */ + keyword = keywords[i]; + slen = strlen(keyword); + n += slen; + for (j = 0; j < slen; j++) + { + if ((j == 0) && (keyword[j] == ' ')) + { + n--; + continue; /* skip leading space */ + } + if (needs_percent(keyword[j])) + n += 2; /* will use %-encoding */ + } } - } - ret = GNUNET_malloc (n); - strcpy (ret, GNUNET_FS_URI_PREFIX); - strcat (ret, GNUNET_FS_URI_KSK_INFIX); - wpos = strlen (ret); + ret = GNUNET_malloc(n); + strcpy(ret, GNUNET_FS_URI_PREFIX); + strcat(ret, GNUNET_FS_URI_KSK_INFIX); + wpos = strlen(ret); for (i = 0; i < keywordCount; i++) - { - keyword = keywords[i]; - slen = strlen (keyword); - for (j = 0; j < slen; j++) { - if ((j == 0) && (keyword[j] == ' ')) - continue; /* skip leading space */ - if (needs_percent (keyword[j])) - { - sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); - wpos += 3; - } - else - { - ret[wpos++] = keyword[j]; - } + keyword = keywords[i]; + slen = strlen(keyword); + for (j = 0; j < slen; j++) + { + if ((j == 0) && (keyword[j] == ' ')) + continue; /* skip leading space */ + if (needs_percent(keyword[j])) + { + sprintf(&ret[wpos], "%%%02X", (unsigned char)keyword[j]); + wpos += 3; + } + else + { + ret[wpos++] = keyword[j]; + } + } + if (i != keywordCount - 1) + ret[wpos++] = '+'; } - if (i != keywordCount - 1) - ret[wpos++] = '+'; - } return ret; } @@ -1896,7 +1916,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) * @return NULL on error */ static char * -uri_sks_to_string (const struct GNUNET_FS_Uri *uri) +uri_sks_to_string(const struct GNUNET_FS_Uri *uri) { char *ret; char buf[1024]; @@ -1904,18 +1924,18 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) if (GNUNET_FS_URI_SKS != uri->type) return NULL; ret = - GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - buf, - sizeof (buf)); - GNUNET_assert (NULL != ret); + GNUNET_STRINGS_data_to_string(&uri->data.sks.ns, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + buf, + sizeof(buf)); + GNUNET_assert(NULL != ret); ret[0] = '\0'; - GNUNET_asprintf (&ret, - "%s%s%s/%s", - GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_SKS_INFIX, - buf, - uri->data.sks.identifier); + GNUNET_asprintf(&ret, + "%s%s%s/%s", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_SKS_INFIX, + buf, + uri->data.sks.identifier); return ret; } @@ -1927,7 +1947,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) * @return NULL on error */ static char * -uri_chk_to_string (const struct GNUNET_FS_Uri *uri) +uri_chk_to_string(const struct GNUNET_FS_Uri *uri) { const struct FileIdentifier *fi; char *ret; @@ -1937,16 +1957,16 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) if (uri->type != GNUNET_FS_URI_CHK) return NULL; fi = &uri->data.chk; - GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); - GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); - - GNUNET_asprintf (&ret, - "%s%s%s.%s.%llu", - GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_CHK_INFIX, - (const char *) &keyhash, - (const char *) &queryhash, - GNUNET_ntohll (fi->file_length)); + GNUNET_CRYPTO_hash_to_enc(&fi->chk.key, &keyhash); + GNUNET_CRYPTO_hash_to_enc(&fi->chk.query, &queryhash); + + GNUNET_asprintf(&ret, + "%s%s%s.%s.%llu", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_CHK_INFIX, + (const char *)&keyhash, + (const char *)&queryhash, + GNUNET_ntohll(fi->file_length)); return ret; } @@ -1958,7 +1978,7 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) * @return NULL on error */ static char * -uri_loc_to_string (const struct GNUNET_FS_Uri *uri) +uri_loc_to_string(const struct GNUNET_FS_Uri *uri) { char *ret; struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; @@ -1966,30 +1986,30 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) char *peer_id; char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; - GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); - GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); + GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.key, &keyhash); + GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.query, &queryhash); peer_id = - GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); - GNUNET_assert ( + GNUNET_CRYPTO_eddsa_public_key_to_string(&uri->data.loc.peer.public_key); + GNUNET_assert( NULL != - GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, - sizeof (struct GNUNET_CRYPTO_EddsaSignature), - peer_sig, - sizeof (peer_sig))); - GNUNET_asprintf (&ret, - "%s%s%s.%s.%llu.%s.%s.%llu", - GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_LOC_INFIX, - (const char *) &keyhash, - (const char *) &queryhash, - (unsigned long long) GNUNET_ntohll ( - uri->data.loc.fi.file_length), - peer_id, - peer_sig, - (unsigned long long) - uri->data.loc.expirationTime.abs_value_us / - 1000000LL); - GNUNET_free (peer_id); + GNUNET_STRINGS_data_to_string(&uri->data.loc.contentSignature, + sizeof(struct GNUNET_CRYPTO_EddsaSignature), + peer_sig, + sizeof(peer_sig))); + GNUNET_asprintf(&ret, + "%s%s%s.%s.%llu.%s.%s.%llu", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_LOC_INFIX, + (const char *)&keyhash, + (const char *)&queryhash, + (unsigned long long)GNUNET_ntohll( + uri->data.loc.fi.file_length), + peer_id, + peer_sig, + (unsigned long long) + uri->data.loc.expirationTime.abs_value_us / + 1000000LL); + GNUNET_free(peer_id); return ret; } @@ -2001,27 +2021,31 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) * @return the UTF-8 string */ char * -GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) +GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri) { if (uri == NULL) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break(0); + return NULL; + } switch (uri->type) - { - case GNUNET_FS_URI_KSK: - return uri_ksk_to_string (uri); - case GNUNET_FS_URI_SKS: - return uri_sks_to_string (uri); - case GNUNET_FS_URI_CHK: - return uri_chk_to_string (uri); - case GNUNET_FS_URI_LOC: - return uri_loc_to_string (uri); - default: - GNUNET_break (0); - return NULL; - } + { + case GNUNET_FS_URI_KSK: + return uri_ksk_to_string(uri); + + case GNUNET_FS_URI_SKS: + return uri_sks_to_string(uri); + + case GNUNET_FS_URI_CHK: + return uri_chk_to_string(uri); + + case GNUNET_FS_URI_LOC: + return uri_loc_to_string(uri); + + default: + GNUNET_break(0); + return NULL; + } } /* end of fs_uri.c */ diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 8b04e474d..6fc71ebe5 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-auto-share.c * @brief automatically publish files on GNUnet @@ -29,7 +29,7 @@ #include "platform.h" #include "gnunet_util_lib.h" -#define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) +#define MAX_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) #define MIN_DELAY GNUNET_TIME_UNIT_MINUTES @@ -38,9 +38,7 @@ * Item in our work queue (or in the set of files/directories * we have successfully published). */ -struct WorkItem -{ - +struct WorkItem { /** * PENDING Work is kept in a linked list. */ @@ -162,16 +160,16 @@ static struct GNUNET_OS_Process *publish_proc; * Compute the name of the state database file we will use. */ static char * -get_state_file () +get_state_file() { char *ret; - GNUNET_asprintf (&ret, - "%s%s.auto-share", - dir_name, - (DIR_SEPARATOR == dir_name[strlen (dir_name) - 1]) - ? "" - : DIR_SEPARATOR_STR); + GNUNET_asprintf(&ret, + "%s%s.auto-share", + dir_name, + (DIR_SEPARATOR == dir_name[strlen(dir_name) - 1]) + ? "" + : DIR_SEPARATOR_STR); return ret; } @@ -180,7 +178,7 @@ get_state_file () * Load the set of #work_finished items from disk. */ static void -load_state () +load_state() { char *fn; struct GNUNET_BIO_ReadHandle *rh; @@ -190,47 +188,47 @@ load_state () char *emsg; emsg = NULL; - fn = get_state_file (); - rh = GNUNET_BIO_read_open (fn); - GNUNET_free (fn); + fn = get_state_file(); + rh = GNUNET_BIO_read_open(fn); + GNUNET_free(fn); if (NULL == rh) return; fn = NULL; - if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) + if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &n)) goto error; while (n-- > 0) - { - if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || - (GNUNET_OK != - GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode)))) - goto error; - wi = GNUNET_new (struct WorkItem); - wi->id = id; - wi->filename = fn; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Loaded serialization ID for `%s' is `%s'\n", - wi->filename, - GNUNET_h2s (&id)); - fn = NULL; - GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &id); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - work_finished, - &id, - wi, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } - if (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)) + { + if ((GNUNET_OK != GNUNET_BIO_read_string(rh, "filename", &fn, 1024)) || + (GNUNET_OK != + GNUNET_BIO_read(rh, "id", &id, sizeof(struct GNUNET_HashCode)))) + goto error; + wi = GNUNET_new(struct WorkItem); + wi->id = id; + wi->filename = fn; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Loaded serialization ID for `%s' is `%s'\n", + wi->filename, + GNUNET_h2s(&id)); + fn = NULL; + GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &id); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + work_finished, + &id, + wi, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } + if (GNUNET_OK == GNUNET_BIO_read_close(rh, &emsg)) return; rh = NULL; error: - GNUNET_free_non_null (fn); + GNUNET_free_non_null(fn); if (NULL != rh) - (void) GNUNET_BIO_read_close (rh, &emsg); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to load state: %s\n"), - emsg); - GNUNET_free_non_null (emsg); + (void)GNUNET_BIO_read_close(rh, &emsg); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to load state: %s\n"), + emsg); + GNUNET_free_non_null(emsg); } @@ -243,18 +241,18 @@ error: * @return #GNUNET_OK to continue to iterate (if write worked) */ static int -write_item (void *cls, const struct GNUNET_HashCode *key, void *value) +write_item(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_BIO_WriteHandle *wh = cls; struct WorkItem *wi = value; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Saving serialization ID of file `%s' with value `%s'\n", - wi->filename, - GNUNET_h2s (&wi->id)); - if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) || + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Saving serialization ID of file `%s' with value `%s'\n", + wi->filename, + GNUNET_h2s(&wi->id)); + if ((GNUNET_OK != GNUNET_BIO_write_string(wh, wi->filename)) || (GNUNET_OK != - GNUNET_BIO_write (wh, &wi->id, sizeof (struct GNUNET_HashCode)))) + GNUNET_BIO_write(wh, &wi->id, sizeof(struct GNUNET_HashCode)))) return GNUNET_SYSERR; /* write error, abort iteration */ return GNUNET_OK; } @@ -264,38 +262,38 @@ write_item (void *cls, const struct GNUNET_HashCode *key, void *value) * Save the set of #work_finished items on disk. */ static void -save_state () +save_state() { uint32_t n; struct GNUNET_BIO_WriteHandle *wh; char *fn; - n = GNUNET_CONTAINER_multihashmap_size (work_finished); - fn = get_state_file (); - wh = GNUNET_BIO_write_open (fn); + n = GNUNET_CONTAINER_multihashmap_size(work_finished); + fn = get_state_file(); + wh = GNUNET_BIO_write_open(fn); if (NULL == wh) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to save state to file %s\n"), - fn); - GNUNET_free (fn); - return; - } - if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n)) - { - (void) GNUNET_BIO_write_close (wh); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to save state to file %s\n"), - fn); - GNUNET_free (fn); - return; - } - (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to save state to file %s\n"), - fn); - GNUNET_free (fn); + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to save state to file %s\n"), + fn); + GNUNET_free(fn); + return; + } + if (GNUNET_OK != GNUNET_BIO_write_int32(wh, n)) + { + (void)GNUNET_BIO_write_close(wh); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to save state to file %s\n"), + fn); + GNUNET_free(fn); + return; + } + (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, &write_item, wh); + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to save state to file %s\n"), + fn); + GNUNET_free(fn); } @@ -305,19 +303,19 @@ save_state () * @param cls closure, unused */ static void -do_stop_task (void *cls) +do_stop_task(void *cls) { do_shutdown = GNUNET_YES; if (NULL != publish_proc) - { - GNUNET_OS_process_kill (publish_proc, SIGKILL); - return; - } + { + GNUNET_OS_process_kill(publish_proc, SIGKILL); + return; + } if (NULL != run_task) - { - GNUNET_SCHEDULER_cancel (run_task); - run_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(run_task); + run_task = NULL; + } } @@ -325,7 +323,7 @@ do_stop_task (void *cls) * Decide what the next task is (working or scanning) and schedule it. */ static void -schedule_next_task (void); +schedule_next_task(void); /** @@ -335,7 +333,7 @@ schedule_next_task (void); * @param cls the `struct WorkItem` we were working on */ static void -maint_child_death (void *cls) +maint_child_death(void *cls) { struct WorkItem *wi = cls; struct GNUNET_HashCode key; @@ -347,65 +345,65 @@ maint_child_death (void *cls) const struct GNUNET_SCHEDULER_TaskContext *tc; run_task = NULL; - pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); - tc = GNUNET_SCHEDULER_get_task_context (); + pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); + tc = GNUNET_SCHEDULER_get_task_context(); if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) - { - /* shutdown scheduled us, someone else will kill child, - we should just try again */ - run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, - &maint_child_death, - wi); - return; - } + { + /* shutdown scheduled us, someone else will kill child, + we should just try again */ + run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + pr, + &maint_child_death, + wi); + return; + } /* consume the signal */ - GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); + GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); - ret = GNUNET_OS_process_status (publish_proc, &type, &code); - GNUNET_assert (GNUNET_SYSERR != ret); + ret = GNUNET_OS_process_status(publish_proc, &type, &code); + GNUNET_assert(GNUNET_SYSERR != ret); if (GNUNET_NO == ret) - { - /* process still running? Then where did the SIGCHLD come from? - Well, let's declare it spurious (kernel bug?) and keep rolling. - */ - GNUNET_break (0); - run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, - &maint_child_death, - wi); - return; - } - GNUNET_assert (GNUNET_OK == ret); - - GNUNET_OS_process_destroy (publish_proc); + { + /* process still running? Then where did the SIGCHLD come from? + Well, let's declare it spurious (kernel bug?) and keep rolling. + */ + GNUNET_break(0); + run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + pr, + &maint_child_death, + wi); + return; + } + GNUNET_assert(GNUNET_OK == ret); + + GNUNET_OS_process_destroy(publish_proc); publish_proc = NULL; if (GNUNET_YES == do_shutdown) - { - GNUNET_free (wi->filename); - GNUNET_free (wi); - return; - } + { + GNUNET_free(wi->filename); + GNUNET_free(wi); + return; + } if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ ("Publication of `%s' done\n"), - wi->filename); - GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &key); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - work_finished, - &key, - wi, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Publication of `%s' done\n"), + wi->filename); + GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &key); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + work_finished, + &key, + wi, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } else - { - GNUNET_CONTAINER_DLL_insert_tail (work_head, work_tail, wi); - } - save_state (); - schedule_next_task (); + { + GNUNET_CONTAINER_DLL_insert_tail(work_head, work_tail, wi); + } + save_state(); + schedule_next_task(); } @@ -414,17 +412,17 @@ maint_child_death (void *cls) * respective handler by writing to the trigger pipe. */ static void -sighandler_child_death () +sighandler_child_death() { static char c; int old_errno = errno; /* back-up errno */ - GNUNET_break ( + GNUNET_break( 1 == - GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, - GNUNET_DISK_PIPE_END_WRITE), - &c, - sizeof (c))); + GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, + GNUNET_DISK_PIPE_END_WRITE), + &c, + sizeof(c))); errno = old_errno; /* restore errno */ } @@ -435,7 +433,7 @@ sighandler_child_death () * @param cls closure, NULL */ static void -work (void *cls) +work(void *cls) { static char *argv[14]; static char anon_level[20]; @@ -447,7 +445,7 @@ work (void *cls) run_task = NULL; wi = work_head; - GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); + GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); argc = 0; argv[argc++] = "gnunet-publish"; if (verbose) @@ -458,41 +456,41 @@ work (void *cls) argv[argc++] = "-d"; argv[argc++] = "-c"; argv[argc++] = cfg_filename; - GNUNET_snprintf (anon_level, sizeof (anon_level), "%u", anonymity_level); + GNUNET_snprintf(anon_level, sizeof(anon_level), "%u", anonymity_level); argv[argc++] = "-a"; argv[argc++] = anon_level; - GNUNET_snprintf (content_prio, sizeof (content_prio), "%u", content_priority); + GNUNET_snprintf(content_prio, sizeof(content_prio), "%u", content_priority); argv[argc++] = "-p"; argv[argc++] = content_prio; - GNUNET_snprintf (repl_level, sizeof (repl_level), "%u", replication_level); + GNUNET_snprintf(repl_level, sizeof(repl_level), "%u", replication_level); argv[argc++] = "-r"; argv[argc++] = repl_level; argv[argc++] = wi->filename; argv[argc] = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Publishing `%s'\n"), wi->filename); - GNUNET_assert (NULL == publish_proc); - publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, - 0, - NULL, - NULL, - NULL, - "gnunet-publish", - argv); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Publishing `%s'\n"), wi->filename); + GNUNET_assert(NULL == publish_proc); + publish_proc = GNUNET_OS_start_process_vap(GNUNET_YES, + 0, + NULL, + NULL, + NULL, + "gnunet-publish", + argv); if (NULL == publish_proc) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to run `%s'\n"), - "gnunet-publish"); - GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); - run_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &work, NULL); - return; - } - pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); - run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - pr, - &maint_child_death, - wi); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to run `%s'\n"), + "gnunet-publish"); + GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); + run_task = + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &work, NULL); + return; + } + pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); + run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + pr, + &maint_child_death, + wi); } @@ -505,39 +503,39 @@ work (void *cls) * @return #GNUNET_OK (always) */ static int -determine_id (void *cls, const char *filename) +determine_id(void *cls, const char *filename) { struct GNUNET_HashCode *id = cls; struct stat sbuf; struct GNUNET_HashCode fx[2]; struct GNUNET_HashCode ft; - if (0 != stat (filename, &sbuf)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); - return GNUNET_OK; - } - GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]); - if (! S_ISDIR (sbuf.st_mode)) - { - uint64_t fattr[2]; - - fattr[0] = GNUNET_htonll (sbuf.st_size); - fattr[0] = GNUNET_htonll (sbuf.st_mtime); - - GNUNET_CRYPTO_hash (fattr, sizeof (fattr), &fx[1]); - } + if (0 != stat(filename, &sbuf)) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); + return GNUNET_OK; + } + GNUNET_CRYPTO_hash(filename, strlen(filename), &fx[0]); + if (!S_ISDIR(sbuf.st_mode)) + { + uint64_t fattr[2]; + + fattr[0] = GNUNET_htonll(sbuf.st_size); + fattr[0] = GNUNET_htonll(sbuf.st_mtime); + + GNUNET_CRYPTO_hash(fattr, sizeof(fattr), &fx[1]); + } else - { - memset (&fx[1], 1, sizeof (struct GNUNET_HashCode)); - GNUNET_DISK_directory_scan (filename, &determine_id, &fx[1]); - } + { + memset(&fx[1], 1, sizeof(struct GNUNET_HashCode)); + GNUNET_DISK_directory_scan(filename, &determine_id, &fx[1]); + } /* use hash here to make hierarchical structure distinct from all files on the same level */ - GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft); + GNUNET_CRYPTO_hash(fx, sizeof(fx), &ft); /* use XOR here so that order of the files in the directory does not matter! */ - GNUNET_CRYPTO_hash_xor (&ft, id, id); + GNUNET_CRYPTO_hash_xor(&ft, id, id); return GNUNET_OK; } @@ -552,7 +550,7 @@ determine_id (void *cls, const char *filename) * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown */ static int -add_file (void *cls, const char *filename) +add_file(void *cls, const char *filename) { struct WorkItem *wi; struct GNUNET_HashCode key; @@ -560,29 +558,29 @@ add_file (void *cls, const char *filename) if (GNUNET_YES == do_shutdown) return GNUNET_SYSERR; - if ((NULL != strstr (filename, "/.auto-share")) || - (NULL != strstr (filename, "\\.auto-share"))) + if ((NULL != strstr(filename, "/.auto-share")) || + (NULL != strstr(filename, "\\.auto-share"))) return GNUNET_OK; /* skip internal file */ - GNUNET_CRYPTO_hash (filename, strlen (filename), &key); - wi = GNUNET_CONTAINER_multihashmap_get (work_finished, &key); - memset (&id, 0, sizeof (struct GNUNET_HashCode)); - determine_id (&id, filename); + GNUNET_CRYPTO_hash(filename, strlen(filename), &key); + wi = GNUNET_CONTAINER_multihashmap_get(work_finished, &key); + memset(&id, 0, sizeof(struct GNUNET_HashCode)); + determine_id(&id, filename); if (NULL != wi) - { - if (0 == memcmp (&id, &wi->id, sizeof (struct GNUNET_HashCode))) - return GNUNET_OK; /* skip: we did this one already */ - /* contents changed, need to re-do the directory... */ - GNUNET_assert ( - GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (work_finished, &key, wi)); - } + { + if (0 == memcmp(&id, &wi->id, sizeof(struct GNUNET_HashCode))) + return GNUNET_OK; /* skip: we did this one already */ + /* contents changed, need to re-do the directory... */ + GNUNET_assert( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(work_finished, &key, wi)); + } else - { - wi = GNUNET_new (struct WorkItem); - wi->filename = GNUNET_strdup (filename); - } + { + wi = GNUNET_new(struct WorkItem); + wi->filename = GNUNET_strdup(filename); + } wi->id = id; - GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); + GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); if (GNUNET_YES == do_shutdown) return GNUNET_SYSERR; return GNUNET_OK; @@ -595,12 +593,12 @@ add_file (void *cls, const char *filename) * @param cls NULL */ static void -scan (void *cls) +scan(void *cls) { run_task = NULL; - start_time = GNUNET_TIME_absolute_get (); - (void) GNUNET_DISK_directory_scan (dir_name, &add_file, NULL); - schedule_next_task (); + start_time = GNUNET_TIME_absolute_get(); + (void)GNUNET_DISK_directory_scan(dir_name, &add_file, NULL); + schedule_next_task(); } @@ -608,27 +606,27 @@ scan (void *cls) * Decide what the next task is (working or scanning) and schedule it. */ static void -schedule_next_task () +schedule_next_task() { struct GNUNET_TIME_Relative delay; if (GNUNET_YES == do_shutdown) return; - GNUNET_assert (NULL == run_task); + GNUNET_assert(NULL == run_task); if (NULL == work_head) - { - /* delay by at most 4h, at least 1s, and otherwise in between depending - on how long it took to scan */ - delay = GNUNET_TIME_absolute_get_duration (start_time); - delay = GNUNET_TIME_relative_saturating_multiply (delay, 100); - delay = GNUNET_TIME_relative_min (delay, MAX_DELAY); - delay = GNUNET_TIME_relative_max (delay, MIN_DELAY); - run_task = GNUNET_SCHEDULER_add_delayed (delay, &scan, NULL); - } + { + /* delay by at most 4h, at least 1s, and otherwise in between depending + on how long it took to scan */ + delay = GNUNET_TIME_absolute_get_duration(start_time); + delay = GNUNET_TIME_relative_saturating_multiply(delay, 100); + delay = GNUNET_TIME_relative_min(delay, MAX_DELAY); + delay = GNUNET_TIME_relative_max(delay, MIN_DELAY); + run_task = GNUNET_SCHEDULER_add_delayed(delay, &scan, NULL); + } else - { - run_task = GNUNET_SCHEDULER_add_now (&work, NULL); - } + { + run_task = GNUNET_SCHEDULER_add_now(&work, NULL); + } } @@ -641,29 +639,29 @@ schedule_next_task () * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { /* check arguments */ if ((NULL == args[0]) || (NULL != args[1]) || - (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))) - { - printf (_ ( - "You must specify one and only one directory name for automatic publication.\n")); - ret = -1; - return; - } - cfg_filename = GNUNET_strdup (cfgfile); + (GNUNET_YES != GNUNET_DISK_directory_test(args[0], GNUNET_YES))) + { + printf(_( + "You must specify one and only one directory name for automatic publication.\n")); + ret = -1; + return; + } + cfg_filename = GNUNET_strdup(cfgfile); cfg = c; dir_name = args[0]; - work_finished = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); - load_state (); - run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, - &scan, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); + work_finished = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); + load_state(); + run_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, + &scan, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); } @@ -676,12 +674,12 @@ run (void *cls, * @return #GNUNET_OK to continue to iterate */ static int -free_item (void *cls, const struct GNUNET_HashCode *key, void *value) +free_item(void *cls, const struct GNUNET_HashCode *key, void *value) { struct WorkItem *wi = value; - GNUNET_free (wi->filename); - GNUNET_free (wi); + GNUNET_free(wi->filename); + GNUNET_free(wi); return GNUNET_OK; } @@ -694,89 +692,89 @@ free_item (void *cls, const struct GNUNET_HashCode *key, void *value) * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - - GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ( - "set the desired LEVEL of sender-anonymity"), - &anonymity_level), - - GNUNET_GETOPT_option_flag ( + GNUNET_GETOPT_option_uint('a', + "anonymity", + "LEVEL", + gettext_noop( + "set the desired LEVEL of sender-anonymity"), + &anonymity_level), + + GNUNET_GETOPT_option_flag( 'd', "disable-creation-time", - gettext_noop ( + gettext_noop( "disable adding the creation time to the metadata of the uploaded file"), &do_disable_creation_time), - GNUNET_GETOPT_option_flag ( + GNUNET_GETOPT_option_flag( 'D', "disable-extractor", - gettext_noop ("do not use libextractor to add keywords or metadata"), + gettext_noop("do not use libextractor to add keywords or metadata"), &disable_extractor), - GNUNET_GETOPT_option_uint ('p', - "priority", - "PRIORITY", - gettext_noop ( - "specify the priority of the content"), - &content_priority), + GNUNET_GETOPT_option_uint('p', + "priority", + "PRIORITY", + gettext_noop( + "specify the priority of the content"), + &content_priority), - GNUNET_GETOPT_option_uint ('r', - "replication", - "LEVEL", - gettext_noop ( - "set the desired replication LEVEL"), - &replication_level), + GNUNET_GETOPT_option_uint('r', + "replication", + "LEVEL", + gettext_noop( + "set the desired replication LEVEL"), + &replication_level), - GNUNET_GETOPT_option_verbose (&verbose), + GNUNET_GETOPT_option_verbose(&verbose), - GNUNET_GETOPT_OPTION_END}; + GNUNET_GETOPT_OPTION_END + }; struct WorkItem *wi; int ok; struct GNUNET_SIGNAL_Context *shc_chld; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; - sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); - GNUNET_assert (NULL != sigpipe); + sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); + GNUNET_assert(NULL != sigpipe); shc_chld = - GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); + GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); ok = (GNUNET_OK == - GNUNET_PROGRAM_run ( + GNUNET_PROGRAM_run( argc, argv, "gnunet-auto-share [OPTIONS] FILENAME", - gettext_noop ("Automatically publish files from a directory on GNUnet"), + gettext_noop("Automatically publish files from a directory on GNUnet"), options, &run, NULL)) - ? ret - : 1; + ? ret + : 1; if (NULL != work_finished) - { - (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, + { + (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, &free_item, NULL); - GNUNET_CONTAINER_multihashmap_destroy (work_finished); - } + GNUNET_CONTAINER_multihashmap_destroy(work_finished); + } while (NULL != (wi = work_head)) - { - GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); - GNUNET_free (wi->filename); - GNUNET_free (wi); - } - GNUNET_SIGNAL_handler_uninstall (shc_chld); + { + GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); + GNUNET_free(wi->filename); + GNUNET_free(wi); + } + GNUNET_SIGNAL_handler_uninstall(shc_chld); shc_chld = NULL; - GNUNET_DISK_pipe_close (sigpipe); + GNUNET_DISK_pipe_close(sigpipe); sigpipe = NULL; - GNUNET_free_non_null (cfg_filename); + GNUNET_free_non_null(cfg_filename); cfg_filename = NULL; - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); return ok; } diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c index 0202dde9c..524475c40 100644 --- a/src/fs/gnunet-daemon-fsprofiler.c +++ b/src/fs/gnunet-daemon-fsprofiler.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-daemon-fsprofiler.c @@ -34,8 +34,7 @@ * We use 'patterns' of the form (x,y,t) to specify desired download/publish * activities of a peer. They are stored in a DLL. */ -struct Pattern -{ +struct Pattern { /** * Kept in a DLL. */ @@ -173,29 +172,29 @@ static struct Pattern *download_tail; * @return GNUNET_OK on success */ static int -parse_pattern (struct Pattern **head, - struct Pattern **tail, - const char *pattern) +parse_pattern(struct Pattern **head, + struct Pattern **tail, + const char *pattern) { struct Pattern *p; unsigned long long x; unsigned long long y; unsigned long long t; - while (3 == sscanf (pattern, - "(%llu,%llu,%llu)", - &x, &y, &t)) - { - p = GNUNET_new (struct Pattern); - p->x = x; - p->y = y; - p->delay.rel_value_us = (uint64_t) t; - GNUNET_CONTAINER_DLL_insert (*head, *tail, p); - pattern = strstr (pattern, ")"); - GNUNET_assert (NULL != pattern); - pattern++; - } - return (0 == strlen (pattern)) ? GNUNET_OK : GNUNET_SYSERR; + while (3 == sscanf(pattern, + "(%llu,%llu,%llu)", + &x, &y, &t)) + { + p = GNUNET_new(struct Pattern); + p->x = x; + p->y = y; + p->delay.rel_value_us = (uint64_t)t; + GNUNET_CONTAINER_DLL_insert(*head, *tail, p); + pattern = strstr(pattern, ")"); + GNUNET_assert(NULL != pattern); + pattern++; + } + return (0 == strlen(pattern)) ? GNUNET_OK : GNUNET_SYSERR; } @@ -206,13 +205,13 @@ parse_pattern (struct Pattern **head, * @return corresponding KSK URI */ static struct GNUNET_FS_Uri * -make_keywords (uint64_t kval) +make_keywords(uint64_t kval) { char kw[128]; - GNUNET_snprintf (kw, sizeof (kw), - "%llu", (unsigned long long) kval); - return GNUNET_FS_uri_ksk_create (kw, NULL); + GNUNET_snprintf(kw, sizeof(kw), + "%llu", (unsigned long long)kval); + return GNUNET_FS_uri_ksk_create(kw, NULL); } @@ -226,9 +225,9 @@ make_keywords (uint64_t kval) * @return file information handle for the file */ static struct GNUNET_FS_FileInformation * -make_file (uint64_t length, - uint64_t kval, - void *ctx) +make_file(uint64_t length, + uint64_t kval, + void *ctx) { struct GNUNET_FS_FileInformation *fi; struct GNUNET_FS_BlockOptions bo; @@ -238,27 +237,27 @@ make_file (uint64_t length, uint64_t xor; data = NULL; /* to make compilers happy */ - if ( (0 != length) && - (NULL == (data = GNUNET_malloc_large ((size_t) length))) ) - return NULL; + if ((0 != length) && + (NULL == (data = GNUNET_malloc_large((size_t)length)))) + return NULL; /* initialize data with 'unique' data only depending on 'kval' and 'size', making sure that blocks do not repeat */ - for (i=0;itask) - GNUNET_SCHEDULER_cancel (p->task); - if (NULL != p->ctx) - GNUNET_FS_publish_stop (p->ctx); - GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); - GNUNET_free (p); - } + { + if (NULL != p->task) + GNUNET_SCHEDULER_cancel(p->task); + if (NULL != p->ctx) + GNUNET_FS_publish_stop(p->ctx); + GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); + GNUNET_free(p); + } while (NULL != (p = download_head)) - { - if (NULL != p->task) - GNUNET_SCHEDULER_cancel (p->task); - if (NULL != p->stask) - GNUNET_SCHEDULER_cancel (p->stask); - if (NULL != p->ctx) - GNUNET_FS_download_stop (p->ctx, GNUNET_YES); - if (NULL != p->sctx) - GNUNET_FS_search_stop (p->sctx); - GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); - GNUNET_free (p); - } + { + if (NULL != p->task) + GNUNET_SCHEDULER_cancel(p->task); + if (NULL != p->stask) + GNUNET_SCHEDULER_cancel(p->stask); + if (NULL != p->ctx) + GNUNET_FS_download_stop(p->ctx, GNUNET_YES); + if (NULL != p->sctx) + GNUNET_FS_search_stop(p->sctx); + GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); + GNUNET_free(p); + } if (NULL != fs_handle) - { - GNUNET_FS_stop (fs_handle); - fs_handle = NULL; - } + { + GNUNET_FS_stop(fs_handle); + fs_handle = NULL; + } if (NULL != stats_handle) - { - GNUNET_STATISTICS_destroy (stats_handle, GNUNET_YES); - stats_handle = NULL; - } + { + GNUNET_STATISTICS_destroy(stats_handle, GNUNET_YES); + stats_handle = NULL; + } } @@ -314,12 +313,12 @@ shutdown_task (void *cls) * @param cls the 'struct Pattern' of the publish operation to stop */ static void -publish_stop_task (void *cls) +publish_stop_task(void *cls) { struct Pattern *p = cls; p->task = NULL; - GNUNET_FS_publish_stop (p->ctx); + GNUNET_FS_publish_stop(p->ctx); } @@ -329,12 +328,12 @@ publish_stop_task (void *cls) * @param cls the 'struct Pattern' of the download operation to stop */ static void -download_stop_task (void *cls) +download_stop_task(void *cls) { struct Pattern *p = cls; p->task = NULL; - GNUNET_FS_download_stop (p->ctx, GNUNET_YES); + GNUNET_FS_download_stop(p->ctx, GNUNET_YES); } @@ -344,12 +343,12 @@ download_stop_task (void *cls) * @param cls the 'struct Pattern' of the download operation to stop */ static void -search_stop_task (void *cls) +search_stop_task(void *cls) { struct Pattern *p = cls; p->stask = NULL; - GNUNET_FS_search_stop (p->sctx); + GNUNET_FS_search_stop(p->sctx); } @@ -369,124 +368,138 @@ search_stop_task (void *cls) * field in the GNUNET_FS_ProgressInfo struct. */ static void * -progress_cb (void *cls, - const struct GNUNET_FS_ProgressInfo *info) +progress_cb(void *cls, + const struct GNUNET_FS_ProgressInfo *info) { struct Pattern *p; const struct GNUNET_FS_Uri *uri; switch (info->status) - { - case GNUNET_FS_STATUS_PUBLISH_START: - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - p = info->value.publish.cctx; - return p; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - p = info->value.publish.cctx; - return p; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Publishing failed\n"); - GNUNET_STATISTICS_update (stats_handle, - "# failed publish operations", 1, GNUNET_NO); - p = info->value.publish.cctx; - p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); - return p; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - p = info->value.publish.cctx; - GNUNET_STATISTICS_update (stats_handle, - "# publishing time (ms)", - (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, - GNUNET_NO); - p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); - return p; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - p = info->value.publish.cctx; - p->ctx = NULL; - GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); - GNUNET_free (p); - return NULL; - case GNUNET_FS_STATUS_DOWNLOAD_START: - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - p = info->value.download.cctx; - return p; - case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Download failed\n"); - GNUNET_STATISTICS_update (stats_handle, - "# failed downloads", 1, GNUNET_NO); - p = info->value.download.cctx; - p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); - return p; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - p = info->value.download.cctx; - GNUNET_STATISTICS_update (stats_handle, - "# download time (ms)", - (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, - GNUNET_NO); - p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); - return p; - case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: - p = info->value.download.cctx; - p->ctx = NULL; - if (NULL == p->sctx) - { - GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); - GNUNET_free (p); - } - return NULL; - case GNUNET_FS_STATUS_SEARCH_START: - case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: - p = info->value.search.cctx; - return p; - case GNUNET_FS_STATUS_SEARCH_RESULT: - p = info->value.search.cctx; - uri = info->value.search.specifics.result.uri; - if (GNUNET_YES != GNUNET_FS_uri_test_chk (uri)) - return NULL; /* not what we want */ - if (p->y != GNUNET_FS_uri_chk_get_file_size (uri)) - return NULL; /* not what we want */ - GNUNET_STATISTICS_update (stats_handle, - "# search time (ms)", - (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, - GNUNET_NO); - p->start_time = GNUNET_TIME_absolute_get (); - p->ctx = GNUNET_FS_download_start (fs_handle, uri, - NULL, NULL, NULL, - 0, GNUNET_FS_uri_chk_get_file_size (uri), - anonymity_level, - GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, - p, - NULL); - p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); - return NULL; - case GNUNET_FS_STATUS_SEARCH_UPDATE: - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - return NULL; /* don't care */ - case GNUNET_FS_STATUS_SEARCH_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Search failed\n"); - GNUNET_STATISTICS_update (stats_handle, - "# failed searches", 1, GNUNET_NO); - p = info->value.search.cctx; - p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); - return p; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - p = info->value.search.cctx; - p->sctx = NULL; - if (NULL == p->ctx) { - GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); - GNUNET_free (p); + case GNUNET_FS_STATUS_PUBLISH_START: + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + p = info->value.publish.cctx; + return p; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + p = info->value.publish.cctx; + return p; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Publishing failed\n"); + GNUNET_STATISTICS_update(stats_handle, + "# failed publish operations", 1, GNUNET_NO); + p = info->value.publish.cctx; + p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); + return p; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + p = info->value.publish.cctx; + GNUNET_STATISTICS_update(stats_handle, + "# publishing time (ms)", + (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, + GNUNET_NO); + p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); + return p; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + p = info->value.publish.cctx; + p->ctx = NULL; + GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); + GNUNET_free(p); + return NULL; + + case GNUNET_FS_STATUS_DOWNLOAD_START: + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + p = info->value.download.cctx; + return p; + + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Download failed\n"); + GNUNET_STATISTICS_update(stats_handle, + "# failed downloads", 1, GNUNET_NO); + p = info->value.download.cctx; + p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); + return p; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + p = info->value.download.cctx; + GNUNET_STATISTICS_update(stats_handle, + "# download time (ms)", + (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, + GNUNET_NO); + p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); + return p; + + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + p = info->value.download.cctx; + p->ctx = NULL; + if (NULL == p->sctx) + { + GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); + GNUNET_free(p); + } + return NULL; + + case GNUNET_FS_STATUS_SEARCH_START: + case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: + p = info->value.search.cctx; + return p; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + p = info->value.search.cctx; + uri = info->value.search.specifics.result.uri; + if (GNUNET_YES != GNUNET_FS_uri_test_chk(uri)) + return NULL; /* not what we want */ + if (p->y != GNUNET_FS_uri_chk_get_file_size(uri)) + return NULL; /* not what we want */ + GNUNET_STATISTICS_update(stats_handle, + "# search time (ms)", + (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, + GNUNET_NO); + p->start_time = GNUNET_TIME_absolute_get(); + p->ctx = GNUNET_FS_download_start(fs_handle, uri, + NULL, NULL, NULL, + 0, GNUNET_FS_uri_chk_get_file_size(uri), + anonymity_level, + GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, + p, + NULL); + p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); + return NULL; + + case GNUNET_FS_STATUS_SEARCH_UPDATE: + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + return NULL; /* don't care */ + + case GNUNET_FS_STATUS_SEARCH_ERROR: + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Search failed\n"); + GNUNET_STATISTICS_update(stats_handle, + "# failed searches", 1, GNUNET_NO); + p = info->value.search.cctx; + p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); + return p; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + p = info->value.search.cctx; + p->sctx = NULL; + if (NULL == p->ctx) + { + GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); + GNUNET_free(p); + } + return NULL; + + default: + /* unexpected event during profiling */ + GNUNET_break(0); + return NULL; } - return NULL; - default: - /* unexpected event during profiling */ - GNUNET_break (0); - return NULL; - } } @@ -496,18 +509,18 @@ progress_cb (void *cls, * @param cls the 'struct Pattern' specifying the operation to perform */ static void -start_publish (void *cls) +start_publish(void *cls) { struct Pattern *p = cls; struct GNUNET_FS_FileInformation *fi; p->task = NULL; - fi = make_file (p->x, p->y, p); - p->start_time = GNUNET_TIME_absolute_get (); - p->ctx = GNUNET_FS_publish_start (fs_handle, - fi, - NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); + fi = make_file(p->x, p->y, p); + p->start_time = GNUNET_TIME_absolute_get(); + p->ctx = GNUNET_FS_publish_start(fs_handle, + fi, + NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); } @@ -517,18 +530,18 @@ start_publish (void *cls) * @param cls the 'struct Pattern' specifying the operation to perform */ static void -start_download (void *cls) +start_download(void *cls) { struct Pattern *p = cls; struct GNUNET_FS_Uri *keywords; p->task = NULL; - keywords = make_keywords (p->x); - p->start_time = GNUNET_TIME_absolute_get (); - p->sctx = GNUNET_FS_search_start (fs_handle, keywords, - anonymity_level, - GNUNET_FS_SEARCH_OPTION_NONE, - p); + keywords = make_keywords(p->x); + p->start_time = GNUNET_TIME_absolute_get(); + p->sctx = GNUNET_FS_search_start(fs_handle, keywords, + anonymity_level, + GNUNET_FS_SEARCH_OPTION_NONE, + p); } @@ -541,88 +554,88 @@ start_download (void *cls) * @param cfg_ configuration */ static void -run (void *cls, char *const *args GNUNET_UNUSED, - const char *cfgfile GNUNET_UNUSED, - const struct GNUNET_CONFIGURATION_Handle *cfg_) +run(void *cls, char *const *args GNUNET_UNUSED, + const char *cfgfile GNUNET_UNUSED, + const struct GNUNET_CONFIGURATION_Handle *cfg_) { char myoptname[128]; struct Pattern *p; cfg = cfg_; /* Scheduled the task to clean up when shutdown is called */ - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, + NULL); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "TESTBED", "PEERID", - &my_peerid)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "TESTBED", "PEERID"); - global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_number(cfg, + "TESTBED", "PEERID", + &my_peerid)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, + "TESTBED", "PEERID"); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown(); + return; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "FSPROFILER", "ANONYMITY_LEVEL", - &anonymity_level)) + GNUNET_CONFIGURATION_get_value_number(cfg, + "FSPROFILER", "ANONYMITY_LEVEL", + &anonymity_level)) anonymity_level = 1; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "FSPROFILER", "REPLICATION_LEVEL", - &replication_level)) + GNUNET_CONFIGURATION_get_value_number(cfg, + "FSPROFILER", "REPLICATION_LEVEL", + &replication_level)) replication_level = 1; - GNUNET_snprintf (myoptname, sizeof (myoptname), - "DOWNLOAD-PATTERN-%u", my_peerid); + GNUNET_snprintf(myoptname, sizeof(myoptname), + "DOWNLOAD-PATTERN-%u", my_peerid); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "FSPROFILER", myoptname, - &download_pattern)) - download_pattern = GNUNET_strdup (""); - GNUNET_snprintf (myoptname, sizeof (myoptname), - "PUBLISH-PATTERN-%u", my_peerid); + GNUNET_CONFIGURATION_get_value_string(cfg, + "FSPROFILER", myoptname, + &download_pattern)) + download_pattern = GNUNET_strdup(""); + GNUNET_snprintf(myoptname, sizeof(myoptname), + "PUBLISH-PATTERN-%u", my_peerid); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "FSPROFILER", myoptname, - &publish_pattern)) - publish_pattern = GNUNET_strdup (""); - if ( (GNUNET_OK != - parse_pattern (&download_head, - &download_tail, - download_pattern)) || - (GNUNET_OK != - parse_pattern (&publish_head, - &publish_tail, - publish_pattern)) ) - { - GNUNET_SCHEDULER_shutdown (); - return; - } - - stats_handle = GNUNET_STATISTICS_create ("fsprofiler", cfg); + GNUNET_CONFIGURATION_get_value_string(cfg, + "FSPROFILER", myoptname, + &publish_pattern)) + publish_pattern = GNUNET_strdup(""); + if ((GNUNET_OK != + parse_pattern(&download_head, + &download_tail, + download_pattern)) || + (GNUNET_OK != + parse_pattern(&publish_head, + &publish_tail, + publish_pattern))) + { + GNUNET_SCHEDULER_shutdown(); + return; + } + + stats_handle = GNUNET_STATISTICS_create("fsprofiler", cfg); fs_handle = - GNUNET_FS_start (cfg, - "fsprofiler", - &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, - GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, - GNUNET_FS_OPTIONS_END); + GNUNET_FS_start(cfg, + "fsprofiler", + &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, + GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, + GNUNET_FS_OPTIONS_END); if (NULL == fs_handle) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); - global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown(); + return; + } for (p = publish_head; NULL != p; p = p->next) - p->task = GNUNET_SCHEDULER_add_delayed (p->delay, - &start_publish, p); + p->task = GNUNET_SCHEDULER_add_delayed(p->delay, + &start_publish, p); for (p = download_head; NULL != p; p = p->next) - p->task = GNUNET_SCHEDULER_add_delayed (p->delay, - &start_download, p); + p->task = GNUNET_SCHEDULER_add_delayed(p->delay, + &start_download, p); } @@ -634,19 +647,19 @@ run (void *cls, char *const *args GNUNET_UNUSED, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; return (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-fsprofiler", - gettext_noop - ("Daemon to use file-sharing to measure its performance."), - options, &run, NULL)) ? global_ret : 1; + GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-fsprofiler", + gettext_noop + ("Daemon to use file-sharing to measure its performance."), + options, &run, NULL)) ? global_ret : 1; } /* end of gnunet-daemon-fsprofiler.c */ diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c index 4cce69d72..f33db109f 100644 --- a/src/fs/gnunet-directory.c +++ b/src/fs/gnunet-directory.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-directory.c * @brief display content of GNUnet directories @@ -40,32 +40,32 @@ static int ret; * @return always 0 (to continue iterating) */ static int -item_printer (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_size) +item_printer(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_size) { if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) - { - printf (_ ("\t\n"), - (unsigned int) data_size); - return 0; - } + { + printf(_("\t\n"), + (unsigned int)data_size); + return 0; + } if ((format != EXTRACTOR_METAFORMAT_UTF8) && (format != EXTRACTOR_METAFORMAT_C_STRING)) return 0; if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) return 0; #if HAVE_LIBEXTRACTOR - printf ("\t%20s: %s\n", - dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, - EXTRACTOR_metatype_to_string (type)), - data); + printf("\t%20s: %s\n", + dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, + EXTRACTOR_metatype_to_string(type)), + data); #else - printf ("\t%20d: %s\n", type, data); + printf("\t%20d: %s\n", type, data); #endif return 0; } @@ -87,34 +87,34 @@ item_printer (void *cls, * @param data data available for the file (length bytes) */ static void -print_entry (void *cls, - const char *filename, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - size_t length, - const void *data) +print_entry(void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + size_t length, + const void *data) { char *string; char *name; - name = GNUNET_CONTAINER_meta_data_get_by_type ( + name = GNUNET_CONTAINER_meta_data_get_by_type( meta, EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); if (uri == NULL) - { - printf (_ ("Directory `%s' meta data:\n"), name ? name : ""); - GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); - printf ("\n"); - printf (_ ("Directory `%s' contents:\n"), name ? name : ""); - GNUNET_free_non_null (name); - return; - } - string = GNUNET_FS_uri_to_string (uri); - printf ("%s (%s):\n", name ? name : "", string); - GNUNET_free (string); - GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); - printf ("\n"); - GNUNET_free_non_null (name); + { + printf(_("Directory `%s' meta data:\n"), name ? name : ""); + GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL); + printf("\n"); + printf(_("Directory `%s' contents:\n"), name ? name : ""); + GNUNET_free_non_null(name); + return; + } + string = GNUNET_FS_uri_to_string(uri); + printf("%s (%s):\n", name ? name : "", string); + GNUNET_free(string); + GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL); + printf("\n"); + GNUNET_free_non_null(name); } @@ -127,10 +127,10 @@ print_entry (void *cls, * @param cfg configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DISK_MapHandle *map; struct GNUNET_DISK_FileHandle *h; @@ -141,37 +141,37 @@ run (void *cls, int i; if (NULL == args[0]) - { - fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n")); - ret = 1; - return; - } + { + fprintf(stderr, "%s", _("You must specify a filename to inspect.\n")); + ret = 1; + return; + } i = 0; while (NULL != (filename = args[i++])) - { - if ((GNUNET_OK != - GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || - (NULL == (h = GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE)))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to read directory `%s'\n"), - filename); - ret = 1; - continue; + if ((GNUNET_OK != + GNUNET_DISK_file_size(filename, &size, GNUNET_YES, GNUNET_YES)) || + (NULL == (h = GNUNET_DISK_file_open(filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE)))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to read directory `%s'\n"), + filename); + ret = 1; + continue; + } + len = (size_t)size; + data = GNUNET_DISK_file_map(h, &map, GNUNET_DISK_MAP_TYPE_READ, len); + GNUNET_assert(NULL != data); + if (GNUNET_OK != + GNUNET_FS_directory_list_contents(len, data, 0, &print_entry, NULL)) + fprintf(stdout, _("`%s' is not a GNUnet directory\n"), filename); + else + printf("\n"); + GNUNET_DISK_file_unmap(map); + GNUNET_DISK_file_close(h); } - len = (size_t) size; - data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); - GNUNET_assert (NULL != data); - if (GNUNET_OK != - GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) - fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename); - else - printf ("\n"); - GNUNET_DISK_file_unmap (map); - GNUNET_DISK_file_close (h); - } } /** @@ -182,26 +182,27 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END}; + GNUNET_GETOPT_OPTION_END + }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-directory [OPTIONS] FILENAME", - gettext_noop ( - "Display contents of a GNUnet directory"), - options, - &run, - NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run(argc, + argv, + "gnunet-directory [OPTIONS] FILENAME", + gettext_noop( + "Display contents of a GNUnet directory"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 00e8336a2..eda6765ab 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-download.c * @brief downloading for files on GNUnet @@ -54,21 +54,21 @@ static int local_only; static void -cleanup_task (void *cls) +cleanup_task(void *cls) { - GNUNET_FS_stop (ctx); + GNUNET_FS_stop(ctx); ctx = NULL; } static void -shutdown_task (void *cls) +shutdown_task(void *cls) { if (NULL != dc) - { - GNUNET_FS_download_stop (dc, delete_incomplete); - dc = NULL; - } + { + GNUNET_FS_download_stop(dc, delete_incomplete); + dc = NULL; + } } @@ -80,30 +80,30 @@ shutdown_task (void *cls) * @param w desired number of steps in the progress bar */ static void -display_bar (unsigned long long x, unsigned long long n, unsigned int w) +display_bar(unsigned long long x, unsigned long long n, unsigned int w) { char buf[w + 20]; unsigned int p; unsigned int endeq; float ratio_complete; -#if ! WINDOWS - if (0 == isatty (1)) +#if !WINDOWS + if (0 == isatty(1)) return; #else - if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) + if (FILE_TYPE_CHAR != GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) return; #endif - ratio_complete = x / (float) n; + ratio_complete = x / (float)n; endeq = ratio_complete * w; - GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int) (ratio_complete * 100)); + GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100)); for (p = 0; p < endeq; p++) - strcat (buf, "="); + strcat(buf, "="); for (p = endeq; p < w; p++) - strcat (buf, " "); - strcat (buf, "]\r"); - printf ("%s", buf); - fflush (stdout); + strcat(buf, " "); + strcat(buf, "]\r"); + printf("%s", buf); + fflush(stdout); } @@ -121,100 +121,106 @@ display_bar (unsigned long long x, unsigned long long n, unsigned int w) * field in the `struct GNUNET_FS_ProgressInfo` */ static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) { char *s; const char *s2; char *t; switch (info->status) - { - case GNUNET_FS_STATUS_DOWNLOAD_START: - if (verbose > 1) - fprintf (stderr, - _ ("Starting download `%s'.\n"), - info->value.download.filename); - break; - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - if (verbose) { - s = GNUNET_strdup ( - GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, - GNUNET_YES)); - if (info->value.download.specifics.progress.block_download_duration - .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) - s2 = _ (""); + case GNUNET_FS_STATUS_DOWNLOAD_START: + if (verbose > 1) + fprintf(stderr, + _("Starting download `%s'.\n"), + info->value.download.filename); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + if (verbose) + { + s = GNUNET_strdup( + GNUNET_STRINGS_relative_time_to_string(info->value.download.eta, + GNUNET_YES)); + if (info->value.download.specifics.progress.block_download_duration + .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) + s2 = _(""); + else + s2 = GNUNET_STRINGS_relative_time_to_string(info->value.download + .specifics.progress + .block_download_duration, + GNUNET_YES); + t = GNUNET_STRINGS_byte_size_fancy( + info->value.download.completed * 1000LL / + (info->value.download.duration.rel_value_us + 1)); + fprintf( + stdout, + _( + "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), + info->value.download.filename, + (unsigned long long)info->value.download.completed, + (unsigned long long)info->value.download.size, + s, + t, + s2); + GNUNET_free(s); + GNUNET_free(t); + } else - s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download - .specifics.progress - .block_download_duration, - GNUNET_YES); - t = GNUNET_STRINGS_byte_size_fancy ( - info->value.download.completed * 1000LL / - (info->value.download.duration.rel_value_us + 1)); - fprintf ( - stdout, - _ ( - "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), - info->value.download.filename, - (unsigned long long) info->value.download.completed, - (unsigned long long) info->value.download.size, - s, - t, - s2); - GNUNET_free (s); - GNUNET_free (t); - } - else - { - display_bar (info->value.download.completed, - info->value.download.size, - 60); - } - break; - case GNUNET_FS_STATUS_DOWNLOAD_ERROR: -#if ! WINDOWS - if (0 != isatty (1)) - fprintf (stdout, "\n"); + { + display_bar(info->value.download.completed, + info->value.download.size, + 60); + } + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: +#if !WINDOWS + if (0 != isatty(1)) + fprintf(stdout, "\n"); #else - if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) - fprintf (stdout, "\n"); + if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) + fprintf(stdout, "\n"); #endif - fprintf (stderr, - _ ("Error downloading: %s.\n"), - info->value.download.specifics.error.message); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - s = GNUNET_STRINGS_byte_size_fancy ( - info->value.download.completed * 1000 / - (info->value.download.duration.rel_value_us + 1)); -#if ! WINDOWS - if (0 != isatty (1)) - fprintf (stdout, "\n"); + fprintf(stderr, + _("Error downloading: %s.\n"), + info->value.download.specifics.error.message); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + s = GNUNET_STRINGS_byte_size_fancy( + info->value.download.completed * 1000 / + (info->value.download.duration.rel_value_us + 1)); +#if !WINDOWS + if (0 != isatty(1)) + fprintf(stdout, "\n"); #else - if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) - fprintf (stdout, "\n"); + if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) + fprintf(stdout, "\n"); #endif - fprintf (stdout, - _ ("Downloading `%s' done (%s/s).\n"), - info->value.download.filename, - s); - GNUNET_free (s); - if (info->value.download.dc == dc) - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: - if (info->value.download.dc == dc) - GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - break; - default: - fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); - break; - } + fprintf(stdout, + _("Downloading `%s' done (%s/s).\n"), + info->value.download.filename, + s); + GNUNET_free(s); + if (info->value.download.dc == dc) + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + if (info->value.download.dc == dc) + GNUNET_SCHEDULER_add_now(&cleanup_task, NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + break; + + default: + fprintf(stderr, _("Unexpected status: %d\n"), info->status); + break; + } return NULL; } @@ -228,84 +234,84 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_FS_Uri *uri; char *emsg; enum GNUNET_FS_DownloadOptions options; if (NULL == args[0]) - { - fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n")); - return; - } - uri = GNUNET_FS_uri_parse (args[0], &emsg); + { + fprintf(stderr, "%s", _("You need to specify a URI argument.\n")); + return; + } + uri = GNUNET_FS_uri_parse(args[0], &emsg); if (NULL == uri) - { - fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); - GNUNET_free (emsg); - ret = 1; - return; - } - if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri))) - { - fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n")); - ret = 1; - GNUNET_FS_uri_destroy (uri); - return; - } + { + fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); + GNUNET_free(emsg); + ret = 1; + return; + } + if ((!GNUNET_FS_uri_test_chk(uri)) && (!GNUNET_FS_uri_test_loc(uri))) + { + fprintf(stderr, "%s", _("Only CHK or LOC URIs supported.\n")); + ret = 1; + GNUNET_FS_uri_destroy(uri); + return; + } if (NULL == filename) - { - fprintf (stderr, "%s", _ ("Target filename must be specified.\n")); - ret = 1; - GNUNET_FS_uri_destroy (uri); - return; - } + { + fprintf(stderr, "%s", _("Target filename must be specified.\n")); + ret = 1; + GNUNET_FS_uri_destroy(uri); + return; + } cfg = c; - ctx = GNUNET_FS_start (cfg, - "gnunet-download", - &progress_cb, - NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, - parallelism, - GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, - request_parallelism, - GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start(cfg, + "gnunet-download", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, + parallelism, + GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, + request_parallelism, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) - { - fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); - GNUNET_FS_uri_destroy (uri); - ret = 1; - return; - } + { + fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + GNUNET_FS_uri_destroy(uri); + ret = 1; + return; + } options = GNUNET_FS_DOWNLOAD_OPTION_NONE; if (do_recursive) options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; if (local_only) options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; - dc = GNUNET_FS_download_start (ctx, - uri, - NULL, - filename, - NULL, - 0, - GNUNET_FS_uri_chk_get_file_size (uri), - anonymity, - options, - NULL, - NULL); - GNUNET_FS_uri_destroy (uri); + dc = GNUNET_FS_download_start(ctx, + uri, + NULL, + filename, + NULL, + 0, + GNUNET_FS_uri_chk_get_file_size(uri), + anonymity, + options, + NULL, + NULL); + GNUNET_FS_uri_destroy(uri); if (dc == NULL) - { - GNUNET_FS_stop (ctx); - ctx = NULL; - return; - } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + { + GNUNET_FS_stop(ctx); + ctx = NULL; + return; + } + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); } @@ -317,75 +323,75 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - {GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ( - "set the desired LEVEL of receiver-anonymity"), - &anonymity), - - GNUNET_GETOPT_option_flag ( - 'D', - "delete-incomplete", - gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), - &delete_incomplete), - - GNUNET_GETOPT_option_flag ( - 'n', - "no-network", - gettext_noop ("only search the local peer (no P2P network search)"), - &local_only), - GNUNET_GETOPT_option_string ('o', - "output", - "FILENAME", - gettext_noop ("write the file to FILENAME"), - &filename), - GNUNET_GETOPT_option_uint ( - 'p', - "parallelism", - "DOWNLOADS", - gettext_noop ( - "set the maximum number of parallel downloads that is allowed"), - ¶llelism), - GNUNET_GETOPT_option_uint ( - 'r', - "request-parallelism", - "REQUESTS", - gettext_noop ( - "set the maximum number of parallel requests for blocks that is allowed"), - &request_parallelism), - GNUNET_GETOPT_option_flag ('R', - "recursive", - gettext_noop ( - "download a GNUnet directory recursively"), - &do_recursive), - GNUNET_GETOPT_option_increment_uint ( - 'V', - "verbose", - gettext_noop ("be verbose (print progress information)"), - &verbose), - GNUNET_GETOPT_OPTION_END}; - - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + { GNUNET_GETOPT_option_uint('a', + "anonymity", + "LEVEL", + gettext_noop( + "set the desired LEVEL of receiver-anonymity"), + &anonymity), + + GNUNET_GETOPT_option_flag( + 'D', + "delete-incomplete", + gettext_noop("delete incomplete downloads (when aborted with CTRL-C)"), + &delete_incomplete), + + GNUNET_GETOPT_option_flag( + 'n', + "no-network", + gettext_noop("only search the local peer (no P2P network search)"), + &local_only), + GNUNET_GETOPT_option_string('o', + "output", + "FILENAME", + gettext_noop("write the file to FILENAME"), + &filename), + GNUNET_GETOPT_option_uint( + 'p', + "parallelism", + "DOWNLOADS", + gettext_noop( + "set the maximum number of parallel downloads that is allowed"), + ¶llelism), + GNUNET_GETOPT_option_uint( + 'r', + "request-parallelism", + "REQUESTS", + gettext_noop( + "set the maximum number of parallel requests for blocks that is allowed"), + &request_parallelism), + GNUNET_GETOPT_option_flag('R', + "recursive", + gettext_noop( + "download a GNUnet directory recursively"), + &do_recursive), + GNUNET_GETOPT_option_increment_uint( + 'V', + "verbose", + gettext_noop("be verbose (print progress information)"), + &verbose), + GNUNET_GETOPT_OPTION_END }; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run ( + GNUNET_PROGRAM_run( argc, argv, "gnunet-download [OPTIONS] URI", - gettext_noop ( + gettext_noop( "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), options, &run, NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c index 8a71c5a59..d47ca8b29 100644 --- a/src/fs/gnunet-fs-profiler.c +++ b/src/fs/gnunet-fs-profiler.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-fs-profiler.c @@ -62,15 +62,15 @@ static struct GNUNET_SCHEDULER_Task * terminate_taskid; * operation has executed successfully. */ static void -shutdown_task (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +shutdown_task(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { if (NULL != emsg) - fprintf (stderr, - "Error collecting statistics: %s\n", - emsg); - GNUNET_SCHEDULER_shutdown (); + fprintf(stderr, + "Error collecting statistics: %s\n", + emsg); + GNUNET_SCHEDULER_shutdown(); } @@ -87,19 +87,19 @@ shutdown_task (void *cls, * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -process_stats (void *cls, - const struct GNUNET_TESTBED_Peer *peer, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +process_stats(void *cls, + const struct GNUNET_TESTBED_Peer *peer, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { - fprintf (stdout, - "%p-%s: %s = %llu\n", - peer, - subsystem, - name, - (unsigned long long) value); + fprintf(stdout, + "%p-%s: %s = %llu\n", + peer, + subsystem, + name, + (unsigned long long)value); return GNUNET_OK; } @@ -111,18 +111,18 @@ process_stats (void *cls, * @param cls NULL */ static void -terminate_task (void *cls) +terminate_task(void *cls) { if (NULL != terminate_taskid) - { - GNUNET_SCHEDULER_cancel (terminate_taskid); - terminate_taskid = NULL; - } - GNUNET_TESTBED_get_statistics (0, NULL, - NULL, NULL, - &process_stats, - &shutdown_task, - NULL); + { + GNUNET_SCHEDULER_cancel(terminate_taskid); + terminate_taskid = NULL; + } + GNUNET_TESTBED_get_statistics(0, NULL, + NULL, NULL, + &process_stats, + &shutdown_task, + NULL); } @@ -133,10 +133,10 @@ terminate_task (void *cls) * @param cls NULL */ static void -timeout_task (void *cls) +timeout_task(void *cls) { terminate_taskid = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -153,23 +153,23 @@ timeout_task (void *cls) * failed */ static void -test_master (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +test_master(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { // const struct GNUNET_CONFIGURATION_Handle *cfg = cls; // FIXME: enable clients to signal 'completion' before timeout; // in that case, run the 'terminate_task' "immediately" if (0 != timeout.rel_value_us) - terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout, - &timeout_task, - NULL); - GNUNET_SCHEDULER_add_shutdown (&terminate_task, - NULL); + terminate_taskid = GNUNET_SCHEDULER_add_delayed(timeout, + &timeout_task, + NULL); + GNUNET_SCHEDULER_add_shutdown(&terminate_task, + NULL); } @@ -182,14 +182,14 @@ test_master (void *cls, * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - GNUNET_TESTBED_run (host_filename, - cfg, - num_peers, - 0, NULL, NULL, - &test_master, (void *) cfg); + GNUNET_TESTBED_run(host_filename, + cfg, + num_peers, + 0, NULL, NULL, + &test_master, (void *)cfg); } @@ -201,38 +201,38 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - - GNUNET_GETOPT_option_uint ('n', - "num-peers", - "COUNT", - gettext_noop ("run the experiment with COUNT peers"), - &num_peers), - - GNUNET_GETOPT_option_string ('H', - "hosts", - "HOSTFILE", - gettext_noop ("specifies name of a file with the HOSTS the testbed should use"), - &host_filename), - - GNUNET_GETOPT_option_relative_time ('t', - "timeout", - "DELAY", - gettext_noop ("automatically terminate experiment after DELAY"), - &timeout), + GNUNET_GETOPT_option_uint('n', + "num-peers", + "COUNT", + gettext_noop("run the experiment with COUNT peers"), + &num_peers), + + GNUNET_GETOPT_option_string('H', + "hosts", + "HOSTFILE", + gettext_noop("specifies name of a file with the HOSTS the testbed should use"), + &host_filename), + + GNUNET_GETOPT_option_relative_time('t', + "timeout", + "DELAY", + gettext_noop("automatically terminate experiment after DELAY"), + &timeout), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-fs-profiler", - gettext_noop ("run a testbed to measure file-sharing performance"), options, &run, - NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run(argc, argv, "gnunet-fs-profiler", + gettext_noop("run a testbed to measure file-sharing performance"), options, &run, + NULL)) ? ret : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index ad2a8d6c5..3fa65d6cb 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-fs.c * @brief special file-sharing functions @@ -55,20 +55,20 @@ static unsigned int verbose; * @return GNUNET_OK to continue iteration */ static int -print_indexed (void *cls, - const char *filename, - const struct GNUNET_HashCode *file_id) +print_indexed(void *cls, + const char *filename, + const struct GNUNET_HashCode *file_id) { if (NULL == filename) - { - GNUNET_FS_stop (fs); - fs = NULL; - return GNUNET_OK; - } + { + GNUNET_FS_stop(fs); + fs = NULL; + return GNUNET_OK; + } if (verbose) - fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); + fprintf(stdout, "%s: %s\n", GNUNET_h2s(file_id), filename); else - fprintf (stdout, "%s\n", filename); + fprintf(stdout, "%s\n", filename); return GNUNET_OK; } @@ -82,32 +82,32 @@ print_indexed (void *cls, * @param cfg configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { if (list_indexed_files) - { - fs = GNUNET_FS_start (cfg, - "gnunet-fs", - NULL, - NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); - if (NULL == fs) { - ret = 1; - return; + fs = GNUNET_FS_start(cfg, + "gnunet-fs", + NULL, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); + if (NULL == fs) + { + ret = 1; + return; + } + if (NULL == GNUNET_FS_get_indexed_files(fs, &print_indexed, NULL)) + { + ret = 2; + GNUNET_FS_stop(fs); + fs = NULL; + return; + } } - if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL)) - { - ret = 2; - GNUNET_FS_stop (fs); - fs = NULL; - return; - } - } } /** @@ -118,32 +118,32 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_flag('i', + "list-indexed", + gettext_noop( + "print a list of all indexed files"), + &list_indexed_files), - GNUNET_GETOPT_option_flag ('i', - "list-indexed", - gettext_noop ( - "print a list of all indexed files"), - &list_indexed_files), - - GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END}; + GNUNET_GETOPT_option_verbose(&verbose), + GNUNET_GETOPT_OPTION_END + }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-fs [OPTIONS]", - gettext_noop ("Special file-sharing operations"), - options, - &run, - NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run(argc, + argv, + "gnunet-fs [OPTIONS]", + gettext_noop("Special file-sharing operations"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index dcb4b47cd..db74e65aa 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file src/fs/gnunet-helper-fs-publish.c @@ -33,9 +33,7 @@ /** * A node of a directory tree. */ -struct ScanTreeNode -{ - +struct ScanTreeNode { /** * This is a doubly-linked list */ @@ -113,41 +111,41 @@ static int output_stream; * @return always 0 to continue extracting */ static int -add_to_md (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_len) +add_to_md(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) { struct GNUNET_CONTAINER_MetaData *md = cls; if (((EXTRACTOR_METAFORMAT_UTF8 == format) || (EXTRACTOR_METAFORMAT_C_STRING == format)) && ('\0' != data[data_len - 1])) - { - char zdata[data_len + 1]; - GNUNET_memcpy (zdata, data, data_len); - zdata[data_len] = '\0'; - (void) GNUNET_CONTAINER_meta_data_insert (md, + { + char zdata[data_len + 1]; + GNUNET_memcpy(zdata, data, data_len); + zdata[data_len] = '\0'; + (void)GNUNET_CONTAINER_meta_data_insert(md, plugin_name, type, format, data_mime_type, zdata, data_len + 1); - } + } else - { - (void) GNUNET_CONTAINER_meta_data_insert (md, + { + (void)GNUNET_CONTAINER_meta_data_insert(md, plugin_name, type, format, data_mime_type, data, data_len); - } + } return 0; } #endif @@ -159,18 +157,18 @@ add_to_md (void *cls, * @param tree tree to free */ static void -free_tree (struct ScanTreeNode *tree) +free_tree(struct ScanTreeNode *tree) { struct ScanTreeNode *pos; while (NULL != (pos = tree->children_head)) - free_tree (pos); + free_tree(pos); if (NULL != tree->parent) - GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, - tree->parent->children_tail, - tree); - GNUNET_free (tree->filename); - GNUNET_free (tree); + GNUNET_CONTAINER_DLL_remove(tree->parent->children_head, + tree->parent->children_tail, + tree); + GNUNET_free(tree->filename); + GNUNET_free(tree); } @@ -182,7 +180,7 @@ free_tree (struct ScanTreeNode *tree) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -write_all (const void *buf, size_t size) +write_all(const void *buf, size_t size) { const char *cbuf = buf; size_t total; @@ -190,15 +188,16 @@ write_all (const void *buf, size_t size) total = 0; do - { - wr = write (output_stream, &cbuf[total], size - total); - if (wr > 0) - total += wr; - } while ((wr > 0) && (total < size)); + { + wr = write(output_stream, &cbuf[total], size - total); + if (wr > 0) + total += wr; + } + while ((wr > 0) && (total < size)); if (wr <= 0) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to write to stdout: %s\n", - strerror (errno)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Failed to write to stdout: %s\n", + strerror(errno)); return (total == size) ? GNUNET_OK : GNUNET_SYSERR; } @@ -212,20 +211,20 @@ write_all (const void *buf, size_t size) * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) */ static int -write_message (uint16_t message_type, const char *data, size_t data_length) +write_message(uint16_t message_type, const char *data, size_t data_length) { struct GNUNET_MessageHeader hdr; #if 0 - fprintf (stderr, - "Helper sends %u-byte message of type %u\n", - (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length), - (unsigned int) message_type); + fprintf(stderr, + "Helper sends %u-byte message of type %u\n", + (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), + (unsigned int)message_type); #endif - hdr.type = htons (message_type); - hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); - if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) || - (GNUNET_OK != write_all (data, data_length))) + hdr.type = htons(message_type); + hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); + if ((GNUNET_OK != write_all(&hdr, sizeof(hdr))) || + (GNUNET_OK != write_all(data, data_length))) return GNUNET_SYSERR; return GNUNET_OK; } @@ -242,14 +241,13 @@ write_message (uint16_t message_type, const char *data, size_t data_length) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -preprocess_file (const char *filename, struct ScanTreeNode **dst); +preprocess_file(const char *filename, struct ScanTreeNode **dst); /** * Closure for the 'scan_callback' */ -struct RecursionContext -{ +struct RecursionContext { /** * Parent to add the files to. */ @@ -272,22 +270,22 @@ struct RecursionContext * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -scan_callback (void *cls, const char *filename) +scan_callback(void *cls, const char *filename) { struct RecursionContext *rc = cls; struct ScanTreeNode *chld; - if (GNUNET_OK != preprocess_file (filename, &chld)) - { - rc->stop = GNUNET_YES; - return GNUNET_SYSERR; - } + if (GNUNET_OK != preprocess_file(filename, &chld)) + { + rc->stop = GNUNET_YES; + return GNUNET_SYSERR; + } if (NULL == chld) return GNUNET_OK; chld->parent = rc->parent; - GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, - rc->parent->children_tail, - chld); + GNUNET_CONTAINER_DLL_insert(rc->parent->children_head, + rc->parent->children_tail, + chld); return GNUNET_OK; } @@ -303,60 +301,60 @@ scan_callback (void *cls, const char *filename) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -preprocess_file (const char *filename, struct ScanTreeNode **dst) +preprocess_file(const char *filename, struct ScanTreeNode **dst) { struct ScanTreeNode *item; struct stat sbuf; uint64_t fsize = 0; - if ((0 != stat (filename, &sbuf)) || - ((! S_ISDIR (sbuf.st_mode)) && + if ((0 != stat(filename, &sbuf)) || + ((!S_ISDIR(sbuf.st_mode)) && (GNUNET_OK != - GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) - { - /* If the file doesn't exist (or is not stat-able for any other reason) - skip it (but report it), but do continue. */ - if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, - filename, - strlen (filename) + 1)) - return GNUNET_SYSERR; - /* recoverable error, store 'NULL' in *dst */ - *dst = NULL; - return GNUNET_OK; - } + GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)))) + { + /* If the file doesn't exist (or is not stat-able for any other reason) + skip it (but report it), but do continue. */ + if (GNUNET_OK != + write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, + filename, + strlen(filename) + 1)) + return GNUNET_SYSERR; + /* recoverable error, store 'NULL' in *dst */ + *dst = NULL; + return GNUNET_OK; + } /* Report the progress */ if ( GNUNET_OK != - write_message (S_ISDIR (sbuf.st_mode) - ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY - : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, - filename, - strlen (filename) + 1)) + write_message(S_ISDIR(sbuf.st_mode) + ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY + : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, + filename, + strlen(filename) + 1)) return GNUNET_SYSERR; - item = GNUNET_new (struct ScanTreeNode); - item->filename = GNUNET_strdup (filename); - item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; + item = GNUNET_new(struct ScanTreeNode); + item->filename = GNUNET_strdup(filename); + item->is_directory = (S_ISDIR(sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; item->file_size = fsize; if (GNUNET_YES == item->is_directory) - { - struct RecursionContext rc; - - rc.parent = item; - rc.stop = GNUNET_NO; - GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); - if ( - (GNUNET_YES == rc.stop) || - (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, - "..", - 3))) { - free_tree (item); - return GNUNET_SYSERR; + struct RecursionContext rc; + + rc.parent = item; + rc.stop = GNUNET_NO; + GNUNET_DISK_directory_scan(filename, &scan_callback, &rc); + if ( + (GNUNET_YES == rc.stop) || + (GNUNET_OK != + write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, + "..", + 3))) + { + free_tree(item); + return GNUNET_SYSERR; + } } - } *dst = item; return GNUNET_OK; } @@ -369,67 +367,67 @@ preprocess_file (const char *filename, struct ScanTreeNode **dst) * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors */ static int -extract_files (struct ScanTreeNode *item) +extract_files(struct ScanTreeNode *item) { struct GNUNET_CONTAINER_MetaData *meta; ssize_t size; size_t slen; if (GNUNET_YES == item->is_directory) - { - /* for directories, we simply only descent, no extraction, no - progress reporting */ - struct ScanTreeNode *pos; - - for (pos = item->children_head; NULL != pos; pos = pos->next) - if (GNUNET_OK != extract_files (pos)) - return GNUNET_SYSERR; - return GNUNET_OK; - } + { + /* for directories, we simply only descent, no extraction, no + progress reporting */ + struct ScanTreeNode *pos; + + for (pos = item->children_head; NULL != pos; pos = pos->next) + if (GNUNET_OK != extract_files(pos)) + return GNUNET_SYSERR; + return GNUNET_OK; + } /* this is the expensive operation, *afterwards* we'll check for aborts */ - meta = GNUNET_CONTAINER_meta_data_create (); + meta = GNUNET_CONTAINER_meta_data_create(); #if HAVE_LIBEXTRACTOR - EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); + EXTRACTOR_extract(plugins, item->filename, NULL, 0, &add_to_md, meta); #endif - slen = strlen (item->filename) + 1; - size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); + slen = strlen(item->filename) + 1; + size = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); if (-1 == size) - { - /* no meta data */ - GNUNET_CONTAINER_meta_data_destroy (meta); - if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, - item->filename, - slen)) - return GNUNET_SYSERR; - return GNUNET_OK; - } - else if (size > (UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen)) - { - /* We can't transfer more than 64k bytes in one message. */ - size = UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen; - } + { + /* no meta data */ + GNUNET_CONTAINER_meta_data_destroy(meta); + if (GNUNET_OK != + write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, + item->filename, + slen)) + return GNUNET_SYSERR; + return GNUNET_OK; + } + else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) + { + /* We can't transfer more than 64k bytes in one message. */ + size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; + } { char buf[size + slen]; char *dst = &buf[slen]; - GNUNET_memcpy (buf, item->filename, slen); - size = GNUNET_CONTAINER_meta_data_serialize ( + GNUNET_memcpy(buf, item->filename, slen); + size = GNUNET_CONTAINER_meta_data_serialize( meta, &dst, size, GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); if (size < 0) - { - GNUNET_break (0); - size = 0; - } - GNUNET_CONTAINER_meta_data_destroy (meta); + { + GNUNET_break(0); + size = 0; + } + GNUNET_CONTAINER_meta_data_destroy(meta); if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, - buf, - slen + size)) + write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, + buf, + slen + size)) return GNUNET_SYSERR; } return GNUNET_OK; @@ -441,23 +439,23 @@ extract_files (struct ScanTreeNode *item) * Install a signal handler to ignore SIGPIPE. */ static void -ignore_sigpipe () +ignore_sigpipe() { struct sigaction oldsig; struct sigaction sig; - memset (&sig, 0, sizeof (struct sigaction)); + memset(&sig, 0, sizeof(struct sigaction)); sig.sa_handler = SIG_IGN; - sigemptyset (&sig.sa_mask); + sigemptyset(&sig.sa_mask); #ifdef SA_INTERRUPT sig.sa_flags = SA_INTERRUPT; /* SunOS */ #else sig.sa_flags = SA_RESTART; #endif - if (0 != sigaction (SIGPIPE, &sig, &oldsig)) - fprintf (stderr, - "Failed to install SIGPIPE handler: %s\n", - strerror (errno)); + if (0 != sigaction(SIGPIPE, &sig, &oldsig)) + fprintf(stderr, + "Failed to install SIGPIPE handler: %s\n", + strerror(errno)); } @@ -468,17 +466,17 @@ ignore_sigpipe () * @param flags flags to use (O_RDONLY or O_WRONLY) */ static void -make_dev_zero (int fd, int flags) +make_dev_zero(int fd, int flags) { int z; - GNUNET_assert (0 == close (fd)); - z = open ("/dev/null", flags); - GNUNET_assert (-1 != z); + GNUNET_assert(0 == close(fd)); + z = open("/dev/null", flags); + GNUNET_assert(-1 != z); if (z == fd) return; - GNUNET_break (fd == dup2 (z, fd)); - GNUNET_assert (0 == close (z)); + GNUNET_break(fd == dup2(z, fd)); + GNUNET_assert(0 == close(z)); } #endif @@ -495,7 +493,7 @@ make_dev_zero (int fd, int flags) * @return 0 on success */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { const char *filename_expanded; const char *ex; @@ -505,98 +503,98 @@ main (int argc, char *const *argv) /* We're using stdout to communicate binary data back to the parent; use * binary mode. */ - _setmode (1, _O_BINARY); + _setmode(1, _O_BINARY); /* Get utf-8-encoded arguments */ - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 5; output_stream = 1; /* stdout */ #else - ignore_sigpipe (); + ignore_sigpipe(); /* move stdout to some other FD for IPC, bind stdout/stderr to /dev/null */ - output_stream = dup (1); - make_dev_zero (1, O_WRONLY); - make_dev_zero (2, O_WRONLY); + output_stream = dup(1); + make_dev_zero(1, O_WRONLY); + make_dev_zero(2, O_WRONLY); #endif /* parse command line */ if ((3 != argc) && (2 != argc)) - { - fprintf (stderr, - "%s", - "gnunet-helper-fs-publish needs exactly one or two arguments\n"); + { + fprintf(stderr, + "%s", + "gnunet-helper-fs-publish needs exactly one or two arguments\n"); #if WINDOWS - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); #endif - return 1; - } + return 1; + } filename_expanded = argv[1]; ex = argv[2]; - if ((NULL == ex) || (0 != strcmp (ex, "-"))) - { + if ((NULL == ex) || (0 != strcmp(ex, "-"))) + { #if HAVE_LIBEXTRACTOR - plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); - if (NULL != ex) - plugins = EXTRACTOR_plugin_add_config (plugins, - ex, - EXTRACTOR_OPTION_DEFAULT_POLICY); + plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); + if (NULL != ex) + plugins = EXTRACTOR_plugin_add_config(plugins, + ex, + EXTRACTOR_OPTION_DEFAULT_POLICY); #endif - } + } /* scan tree to find out how much work there is to be done */ - if (GNUNET_OK != preprocess_file (filename_expanded, &root)) - { - (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); + if (GNUNET_OK != preprocess_file(filename_expanded, &root)) + { + (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); #if HAVE_LIBEXTRACTOR - EXTRACTOR_plugin_remove_all (plugins); + EXTRACTOR_plugin_remove_all(plugins); #endif #if WINDOWS - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); #endif - return 2; - } + return 2; + } /* signal that we're done counting files, so that a percentage of progress can now be calculated */ if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, - NULL, - 0)) - { + write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, + NULL, + 0)) + { #if HAVE_LIBEXTRACTOR - EXTRACTOR_plugin_remove_all (plugins); + EXTRACTOR_plugin_remove_all(plugins); #endif #if WINDOWS - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); #endif - return 3; - } + return 3; + } if (NULL != root) - { - if (GNUNET_OK != extract_files (root)) { - (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, - NULL, - 0); - free_tree (root); + if (GNUNET_OK != extract_files(root)) + { + (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, + NULL, + 0); + free_tree(root); #if HAVE_LIBEXTRACTOR - EXTRACTOR_plugin_remove_all (plugins); + EXTRACTOR_plugin_remove_all(plugins); #endif #if WINDOWS - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); #endif - return 4; + return 4; + } + free_tree(root); } - free_tree (root); - } /* enable "clean" shutdown by telling parent that we are done */ - (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, - NULL, - 0); + (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, + NULL, + 0); #if HAVE_LIBEXTRACTOR - EXTRACTOR_plugin_remove_all (plugins); + EXTRACTOR_plugin_remove_all(plugins); #endif #if WINDOWS - GNUNET_free ((void *) argv); + GNUNET_free((void *)argv); #endif return 0; } diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 84cbf0aac..24baa4d38 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-publish.c * @brief publishing files on GNUnet @@ -67,7 +67,7 @@ static struct GNUNET_FS_Uri *topKeywords; /** * Options we set for published blocks. */ -static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1}; +static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; /** * Value of URI provided on command-line (when not publishing @@ -148,41 +148,41 @@ static struct GNUNET_IDENTITY_Handle *identity; * @param cls NULL */ static void -do_stop_task (void *cls) +do_stop_task(void *cls) { struct GNUNET_FS_PublishContext *p; if (NULL != ds) - { - GNUNET_FS_directory_scan_abort (ds); - ds = NULL; - } + { + GNUNET_FS_directory_scan_abort(ds); + ds = NULL; + } if (NULL != identity) - { - GNUNET_IDENTITY_disconnect (identity); - identity = NULL; - } + { + GNUNET_IDENTITY_disconnect(identity); + identity = NULL; + } if (NULL != pc) - { - p = pc; - pc = NULL; - GNUNET_FS_publish_stop (p); - } + { + p = pc; + pc = NULL; + GNUNET_FS_publish_stop(p); + } if (NULL != ctx) - { - GNUNET_FS_stop (ctx); - ctx = NULL; - } + { + GNUNET_FS_stop(ctx); + ctx = NULL; + } if (NULL != meta) - { - GNUNET_CONTAINER_meta_data_destroy (meta); - meta = NULL; - } + { + GNUNET_CONTAINER_meta_data_destroy(meta); + meta = NULL; + } if (NULL != uri) - { - GNUNET_FS_uri_destroy (uri); - uri = NULL; - } + { + GNUNET_FS_uri_destroy(uri); + uri = NULL; + } } @@ -200,94 +200,105 @@ do_stop_task (void *cls) * field in the GNUNET_FS_ProgressInfo struct. */ static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) { const char *s; char *suri; switch (info->status) - { - case GNUNET_FS_STATUS_PUBLISH_START: - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - if (verbose) { - s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, - GNUNET_YES); - fprintf (stdout, - _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), - info->value.publish.filename, - (unsigned long long) info->value.publish.completed, - (unsigned long long) info->value.publish.size, - s); - } - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - if (verbose) - { - s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics - .progress_directory.eta, - GNUNET_YES); - fprintf (stdout, - _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), - info->value.publish.filename, - (unsigned long long) - info->value.publish.specifics.progress_directory.completed, - (unsigned long long) - info->value.publish.specifics.progress_directory.total, - s); - } - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, - _ ("Error publishing: %s.\n"), - info->value.publish.specifics.error.message); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - fprintf (stdout, - _ ("Publishing `%s' done.\n"), - info->value.publish.filename); - suri = - GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); - fprintf (stdout, _ ("URI is `%s'.\n"), suri); - GNUNET_free (suri); - if (NULL != info->value.publish.specifics.completed.sks_uri) - { - suri = GNUNET_FS_uri_to_string ( - info->value.publish.specifics.completed.sks_uri); - fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri); - GNUNET_free (suri); - } - if (NULL == info->value.publish.pctx) - { - ret = 0; - GNUNET_SCHEDULER_shutdown (); + case GNUNET_FS_STATUS_PUBLISH_START: + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + if (verbose) + { + s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta, + GNUNET_YES); + fprintf(stdout, + _("Publishing `%s' at %llu/%llu (%s remaining)\n"), + info->value.publish.filename, + (unsigned long long)info->value.publish.completed, + (unsigned long long)info->value.publish.size, + s); + } + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + if (verbose) + { + s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.specifics + .progress_directory.eta, + GNUNET_YES); + fprintf(stdout, + _("Publishing `%s' at %llu/%llu (%s remaining)\n"), + info->value.publish.filename, + (unsigned long long) + info->value.publish.specifics.progress_directory.completed, + (unsigned long long) + info->value.publish.specifics.progress_directory.total, + s); + } + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, + _("Error publishing: %s.\n"), + info->value.publish.specifics.error.message); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + fprintf(stdout, + _("Publishing `%s' done.\n"), + info->value.publish.filename); + suri = + GNUNET_FS_uri_to_string(info->value.publish.specifics.completed.chk_uri); + fprintf(stdout, _("URI is `%s'.\n"), suri); + GNUNET_free(suri); + if (NULL != info->value.publish.specifics.completed.sks_uri) + { + suri = GNUNET_FS_uri_to_string( + info->value.publish.specifics.completed.sks_uri); + fprintf(stdout, _("Namespace URI is `%s'.\n"), suri); + GNUNET_free(suri); + } + if (NULL == info->value.publish.pctx) + { + ret = 0; + GNUNET_SCHEDULER_shutdown(); + } + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_break(NULL == pc); + return NULL; + + case GNUNET_FS_STATUS_UNINDEX_START: + fprintf(stderr, "%s", _("Starting cleanup after abort\n")); + return NULL; + + case GNUNET_FS_STATUS_UNINDEX_PROGRESS: + return NULL; + + case GNUNET_FS_STATUS_UNINDEX_COMPLETED: + fprintf(stderr, "%s", _("Cleanup after abort completed.\n")); + GNUNET_FS_unindex_stop(info->value.unindex.uc); + return NULL; + + case GNUNET_FS_STATUS_UNINDEX_ERROR: + fprintf(stderr, "%s", _("Cleanup after abort failed.\n")); + GNUNET_FS_unindex_stop(info->value.unindex.uc); + return NULL; + + case GNUNET_FS_STATUS_UNINDEX_STOPPED: + return NULL; + + default: + fprintf(stderr, _("Unexpected status: %d\n"), info->status); + return NULL; } - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_break (NULL == pc); - return NULL; - case GNUNET_FS_STATUS_UNINDEX_START: - fprintf (stderr, "%s", _ ("Starting cleanup after abort\n")); - return NULL; - case GNUNET_FS_STATUS_UNINDEX_PROGRESS: - return NULL; - case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n")); - GNUNET_FS_unindex_stop (info->value.unindex.uc); - return NULL; - case GNUNET_FS_STATUS_UNINDEX_ERROR: - fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n")); - GNUNET_FS_unindex_stop (info->value.unindex.uc); - return NULL; - case GNUNET_FS_STATUS_UNINDEX_STOPPED: - return NULL; - default: - fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); - return NULL; - } return ""; /* non-null */ } @@ -306,13 +317,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) * @return always 0 */ static int -meta_printer (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_size) +meta_printer(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_size) { if ((EXTRACTOR_METAFORMAT_UTF8 != format) && (EXTRACTOR_METAFORMAT_C_STRING != format)) @@ -320,9 +331,9 @@ meta_printer (void *cls, if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) return 0; #if HAVE_LIBEXTRACTOR - fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); + fprintf(stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string(type), data); #else - fprintf (stdout, "\t%d - %s\n", type, data); + fprintf(stdout, "\t%d - %s\n", type, data); #endif return 0; } @@ -337,9 +348,9 @@ meta_printer (void *cls, * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort */ static int -keyword_printer (void *cls, const char *keyword, int is_mandatory) +keyword_printer(void *cls, const char *keyword, int is_mandatory) { - fprintf (stdout, "\t%s\n", keyword); + fprintf(stdout, "\t%s\n", keyword); return GNUNET_OK; } @@ -362,14 +373,14 @@ keyword_printer (void *cls, const char *keyword, int is_mandatory) * to abort the iteration */ static int -publish_inspector (void *cls, - struct GNUNET_FS_FileInformation *fi, - uint64_t length, - struct GNUNET_CONTAINER_MetaData *m, - struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, - int *do_index, - void **client_info) +publish_inspector(void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *m, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, + void **client_info) { char *fn; char *fs; @@ -378,50 +389,50 @@ publish_inspector (void *cls, if (cls == fi) return GNUNET_OK; if ((disable_extractor) && (NULL != *uri)) - { - GNUNET_FS_uri_destroy (*uri); - *uri = NULL; - } - if (NULL != topKeywords) - { - if (NULL != *uri) { - new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri); - GNUNET_FS_uri_destroy (*uri); - *uri = new_uri; - GNUNET_FS_uri_destroy (topKeywords); + GNUNET_FS_uri_destroy(*uri); + *uri = NULL; } - else + if (NULL != topKeywords) { - *uri = topKeywords; + if (NULL != *uri) + { + new_uri = GNUNET_FS_uri_ksk_merge(topKeywords, *uri); + GNUNET_FS_uri_destroy(*uri); + *uri = new_uri; + GNUNET_FS_uri_destroy(topKeywords); + } + else + { + *uri = topKeywords; + } + topKeywords = NULL; } - topKeywords = NULL; - } if (NULL != meta) - { - GNUNET_CONTAINER_meta_data_merge (m, meta); - GNUNET_CONTAINER_meta_data_destroy (meta); - meta = NULL; - } + { + GNUNET_CONTAINER_meta_data_merge(m, meta); + GNUNET_CONTAINER_meta_data_destroy(meta); + meta = NULL; + } if (enable_creation_time) - GNUNET_CONTAINER_meta_data_add_publication_date (m); + GNUNET_CONTAINER_meta_data_add_publication_date(m); if (extract_only) - { - fn = GNUNET_CONTAINER_meta_data_get_by_type ( - m, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); - fs = GNUNET_STRINGS_byte_size_fancy (length); - fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs); - GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); - fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs); - GNUNET_free (fn); - GNUNET_free (fs); - if (NULL != *uri) - GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); - fprintf (stdout, "%s", "\n"); - } - if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) - GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); + { + fn = GNUNET_CONTAINER_meta_data_get_by_type( + m, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + fs = GNUNET_STRINGS_byte_size_fancy(length); + fprintf(stdout, _("Meta data for file `%s' (%s)\n"), fn, fs); + GNUNET_CONTAINER_meta_data_iterate(m, &meta_printer, NULL); + fprintf(stdout, _("Keywords for file `%s' (%s)\n"), fn, fs); + GNUNET_free(fn); + GNUNET_free(fs); + if (NULL != *uri) + GNUNET_FS_uri_ksk_get_keywords(*uri, &keyword_printer, NULL); + fprintf(stdout, "%s", "\n"); + } + if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(m)) + GNUNET_FS_file_information_inspect(fi, &publish_inspector, fi); return GNUNET_OK; } @@ -436,16 +447,16 @@ publish_inspector (void *cls, * @param emsg error message, NULL on success */ static void -uri_sks_continuation (void *cls, - const struct GNUNET_FS_Uri *sks_uri, - const char *emsg) +uri_sks_continuation(void *cls, + const struct GNUNET_FS_Uri *sks_uri, + const char *emsg) { if (NULL != emsg) - { - fprintf (stderr, "%s\n", emsg); - ret = 1; - } - GNUNET_SCHEDULER_shutdown (); + { + fprintf(stderr, "%s\n", emsg); + ret = 1; + } + GNUNET_SCHEDULER_shutdown(); } @@ -459,33 +470,33 @@ uri_sks_continuation (void *cls, * @param emsg error message, NULL on success */ static void -uri_ksk_continuation (void *cls, - const struct GNUNET_FS_Uri *ksk_uri, - const char *emsg) +uri_ksk_continuation(void *cls, + const struct GNUNET_FS_Uri *ksk_uri, + const char *emsg) { const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; if (NULL != emsg) - { - fprintf (stderr, "%s\n", emsg); - ret = 1; - } + { + fprintf(stderr, "%s\n", emsg); + ret = 1; + } if (NULL == namespace) - { - GNUNET_SCHEDULER_shutdown (); - return; - } - priv = GNUNET_IDENTITY_ego_get_private_key (namespace); - GNUNET_FS_publish_sks (ctx, - priv, - this_id, - next_id, - meta, - uri, - &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, - &uri_sks_continuation, - NULL); + { + GNUNET_SCHEDULER_shutdown(); + return; + } + priv = GNUNET_IDENTITY_ego_get_private_key(namespace); + GNUNET_FS_publish_sks(ctx, + priv, + this_id, + next_id, + meta, + uri, + &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, + &uri_sks_continuation, + NULL); } @@ -497,52 +508,52 @@ uri_ksk_continuation (void *cls, * @return handle with the information for the publishing operation */ static struct GNUNET_FS_FileInformation * -get_file_information (struct GNUNET_FS_ShareTreeItem *item) +get_file_information(struct GNUNET_FS_ShareTreeItem *item) { struct GNUNET_FS_FileInformation *fi; struct GNUNET_FS_FileInformation *fic; struct GNUNET_FS_ShareTreeItem *child; if (GNUNET_YES == item->is_directory) - { - if (NULL == item->meta) - item->meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_CONTAINER_meta_data_delete (item->meta, - EXTRACTOR_METATYPE_MIMETYPE, - NULL, - 0); - GNUNET_FS_meta_data_make_directory (item->meta); - if (NULL == item->ksk_uri) { - const char *mime = GNUNET_FS_DIRECTORY_MIME; - item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); + if (NULL == item->meta) + item->meta = GNUNET_CONTAINER_meta_data_create(); + GNUNET_CONTAINER_meta_data_delete(item->meta, + EXTRACTOR_METATYPE_MIMETYPE, + NULL, + 0); + GNUNET_FS_meta_data_make_directory(item->meta); + if (NULL == item->ksk_uri) + { + const char *mime = GNUNET_FS_DIRECTORY_MIME; + item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args(1, &mime); + } + else + GNUNET_FS_uri_ksk_add_keyword(item->ksk_uri, + GNUNET_FS_DIRECTORY_MIME, + GNUNET_NO); + fi = GNUNET_FS_file_information_create_empty_directory(ctx, + NULL, + item->ksk_uri, + item->meta, + &bo, + item->filename); + for (child = item->children_head; child; child = child->next) + { + fic = get_file_information(child); + GNUNET_break(GNUNET_OK == GNUNET_FS_file_information_add(fi, fic)); + } } - else - GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, - GNUNET_FS_DIRECTORY_MIME, - GNUNET_NO); - fi = GNUNET_FS_file_information_create_empty_directory (ctx, - NULL, - item->ksk_uri, - item->meta, - &bo, - item->filename); - for (child = item->children_head; child; child = child->next) + else { - fic = get_file_information (child); - GNUNET_break (GNUNET_OK == GNUNET_FS_file_information_add (fi, fic)); + fi = GNUNET_FS_file_information_create_from_file(ctx, + NULL, + item->filename, + item->ksk_uri, + item->meta, + !do_insert, + &bo); } - } - else - { - fi = GNUNET_FS_file_information_create_from_file (ctx, - NULL, - item->filename, - item->ksk_uri, - item->meta, - ! do_insert, - &bo); - } return fi; } @@ -554,46 +565,46 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) * @param directory_scan_result result from the directory scan, freed in this function */ static void -directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) +directory_trim_complete(struct GNUNET_FS_ShareTreeItem *directory_scan_result) { struct GNUNET_FS_FileInformation *fi; const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; - fi = get_file_information (directory_scan_result); - GNUNET_FS_share_tree_free (directory_scan_result); + fi = get_file_information(directory_scan_result); + GNUNET_FS_share_tree_free(directory_scan_result); if (NULL == fi) - { - fprintf (stderr, "%s", _ ("Could not publish\n")); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); + { + fprintf(stderr, "%s", _("Could not publish\n")); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_FS_file_information_inspect(fi, &publish_inspector, NULL); if (extract_only) - { - GNUNET_FS_file_information_destroy (fi, NULL, NULL); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_FS_file_information_destroy(fi, NULL, NULL); + GNUNET_SCHEDULER_shutdown(); + return; + } if (NULL == namespace) priv = NULL; else - priv = GNUNET_IDENTITY_ego_get_private_key (namespace); - pc = GNUNET_FS_publish_start (ctx, - fi, - priv, - this_id, - next_id, - (do_simulate) - ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY - : GNUNET_FS_PUBLISH_OPTION_NONE); + priv = GNUNET_IDENTITY_ego_get_private_key(namespace); + pc = GNUNET_FS_publish_start(ctx, + fi, + priv, + this_id, + next_id, + (do_simulate) + ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY + : GNUNET_FS_PUBLISH_OPTION_NONE); if (NULL == pc) - { - fprintf (stderr, "%s", _ ("Could not start publishing.\n")); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } + { + fprintf(stderr, "%s", _("Could not start publishing.\n")); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + return; + } } @@ -609,57 +620,63 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) * @param reason kind of progress we are making */ static void -directory_scan_cb (void *cls, - const char *filename, - int is_directory, - enum GNUNET_FS_DirScannerProgressUpdateReason reason) +directory_scan_cb(void *cls, + const char *filename, + int is_directory, + enum GNUNET_FS_DirScannerProgressUpdateReason reason) { struct GNUNET_FS_ShareTreeItem *directory_scan_result; switch (reason) - { - case GNUNET_FS_DIRSCANNER_FILE_START: - if (verbose > 1) { - if (is_directory == GNUNET_YES) - fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename); - else - fprintf (stdout, _ ("Scanning file `%s'.\n"), filename); + case GNUNET_FS_DIRSCANNER_FILE_START: + if (verbose > 1) + { + if (is_directory == GNUNET_YES) + fprintf(stdout, _("Scanning directory `%s'.\n"), filename); + else + fprintf(stdout, _("Scanning file `%s'.\n"), filename); + } + break; + + case GNUNET_FS_DIRSCANNER_FILE_IGNORED: + fprintf(stderr, + _("There was trouble processing file `%s', skipping it.\n"), + filename); + break; + + case GNUNET_FS_DIRSCANNER_ALL_COUNTED: + if (verbose) + fprintf(stdout, "%s", _("Preprocessing complete.\n")); + break; + + case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: + if (verbose > 2) + fprintf(stdout, + _("Extracting meta data from file `%s' complete.\n"), + filename); + break; + + case GNUNET_FS_DIRSCANNER_FINISHED: + if (verbose > 1) + fprintf(stdout, "%s", _("Meta data extraction has finished.\n")); + directory_scan_result = GNUNET_FS_directory_scan_get_result(ds); + ds = NULL; + GNUNET_FS_share_tree_trim(directory_scan_result); + directory_trim_complete(directory_scan_result); + break; + + case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: + fprintf(stdout, "%s", _("Error scanning directory.\n")); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + break; + + default: + GNUNET_assert(0); + break; } - break; - case GNUNET_FS_DIRSCANNER_FILE_IGNORED: - fprintf (stderr, - _ ("There was trouble processing file `%s', skipping it.\n"), - filename); - break; - case GNUNET_FS_DIRSCANNER_ALL_COUNTED: - if (verbose) - fprintf (stdout, "%s", _ ("Preprocessing complete.\n")); - break; - case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: - if (verbose > 2) - fprintf (stdout, - _ ("Extracting meta data from file `%s' complete.\n"), - filename); - break; - case GNUNET_FS_DIRSCANNER_FINISHED: - if (verbose > 1) - fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n")); - directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); - ds = NULL; - GNUNET_FS_share_tree_trim (directory_scan_result); - directory_trim_complete (directory_scan_result); - break; - case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: - fprintf (stdout, "%s", _ ("Error scanning directory.\n")); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - break; - default: - GNUNET_assert (0); - break; - } - fflush (stdout); + fflush(stdout); } @@ -670,67 +687,67 @@ directory_scan_cb (void *cls, * @param args0 filename to publish */ static void -identity_continuation (const char *args0) +identity_continuation(const char *args0) { char *ex; char *emsg; if ((NULL != pseudonym) && (NULL == namespace)) - { - fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - if (NULL != uri_string) - { - emsg = NULL; - if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) { - fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); - GNUNET_free (emsg); + fprintf(stderr, _("Selected pseudonym `%s' unknown\n"), pseudonym); ret = 1; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); + return; + } + if (NULL != uri_string) + { + emsg = NULL; + if (NULL == (uri = GNUNET_FS_uri_parse(uri_string, &emsg))) + { + fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); + GNUNET_free(emsg); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_FS_publish_ksk(ctx, + topKeywords, + meta, + uri, + &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, + &uri_ksk_continuation, + NULL); return; } - GNUNET_FS_publish_ksk (ctx, - topKeywords, - meta, - uri, - &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, - &uri_ksk_continuation, - NULL); - return; - } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) + GNUNET_CONFIGURATION_get_value_string(cfg, "FS", "EXTRACTORS", &ex)) ex = NULL; - if (0 != access (args0, R_OK)) - { - fprintf (stderr, - _ ("Failed to access `%s': %s\n"), - args0, - strerror (errno)); - GNUNET_free_non_null (ex); - return; - } - ds = GNUNET_FS_directory_scan_start (args0, - disable_extractor, - ex, - &directory_scan_cb, - NULL); + if (0 != access(args0, R_OK)) + { + fprintf(stderr, + _("Failed to access `%s': %s\n"), + args0, + strerror(errno)); + GNUNET_free_non_null(ex); + return; + } + ds = GNUNET_FS_directory_scan_start(args0, + disable_extractor, + ex, + &directory_scan_cb, + NULL); if (NULL == ds) - { - fprintf ( - stderr, - "%s", - _ ( - "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); - GNUNET_free_non_null (ex); - return; - } - GNUNET_free_non_null (ex); + { + fprintf( + stderr, + "%s", + _( + "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); + GNUNET_free_non_null(ex); + return; + } + GNUNET_free_non_null(ex); } @@ -746,22 +763,22 @@ identity_continuation (const char *args0) * must thus no longer be used */ static void -identity_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *name) +identity_cb(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *name) { const char *args0 = cls; if (NULL == ego) - { - identity_continuation (args0); - return; - } + { + identity_continuation(args0); + return; + } if (NULL == name) return; - if (0 == strcmp (name, pseudonym)) - namespace = ego; + if (0 == strcmp(name, pseudonym)) + namespace = ego; } @@ -774,82 +791,82 @@ identity_cb (void *cls, * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { /* check arguments */ if ((NULL != uri_string) && (extract_only)) - { - printf (_ ("Cannot extract metadata from a URI!\n")); - ret = -1; - return; - } - if (((NULL == uri_string) || (extract_only)) && - ((NULL == args[0]) || (NULL != args[1]))) - { - printf (_ ("You must specify one and only one filename for insertion.\n")); - ret = -1; - return; - } - if ((NULL != uri_string) && (NULL != args[0])) - { - printf (_ ("You must NOT specify an URI and a filename.\n")); - ret = -1; - return; - } - if (NULL != pseudonym) - { - if (NULL == this_id) { - fprintf (stderr, - _ ("Option `%s' is required when using option `%s'.\n"), - "-t", - "-P"); + printf(_("Cannot extract metadata from a URI!\n")); ret = -1; return; } - } - else - { /* ordinary insertion checks */ - if (NULL != next_id) + if (((NULL == uri_string) || (extract_only)) && + ((NULL == args[0]) || (NULL != args[1]))) { - fprintf (stderr, - _ ("Option `%s' makes no sense without option `%s'.\n"), - "-N", - "-P"); + printf(_("You must specify one and only one filename for insertion.\n")); ret = -1; return; } - if (NULL != this_id) + if ((NULL != uri_string) && (NULL != args[0])) { - fprintf (stderr, - _ ("Option `%s' makes no sense without option `%s'.\n"), - "-t", - "-P"); + printf(_("You must NOT specify an URI and a filename.\n")); ret = -1; return; } - } + if (NULL != pseudonym) + { + if (NULL == this_id) + { + fprintf(stderr, + _("Option `%s' is required when using option `%s'.\n"), + "-t", + "-P"); + ret = -1; + return; + } + } + else + { /* ordinary insertion checks */ + if (NULL != next_id) + { + fprintf(stderr, + _("Option `%s' makes no sense without option `%s'.\n"), + "-N", + "-P"); + ret = -1; + return; + } + if (NULL != this_id) + { + fprintf(stderr, + _("Option `%s' makes no sense without option `%s'.\n"), + "-t", + "-P"); + ret = -1; + return; + } + } cfg = c; - ctx = GNUNET_FS_start (cfg, - "gnunet-publish", - &progress_cb, - NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start(cfg, + "gnunet-publish", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) - { - fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); - ret = 1; - return; - } - GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); + { + fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + ret = 1; + return; + } + GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); if (NULL != pseudonym) - identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]); + identity = GNUNET_IDENTITY_connect(cfg, &identity_cb, args[0]); else - identity_continuation (args[0]); + identity_continuation(args[0]); } @@ -861,120 +878,121 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - {GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ( - "set the desired LEVEL of sender-anonymity"), - &bo.anonymity_level), - GNUNET_GETOPT_option_flag ( - 'D', - "disable-extractor", - gettext_noop ("do not use libextractor to add keywords or metadata"), - &disable_extractor), - GNUNET_GETOPT_option_flag ('E', - "enable-creation-time", - gettext_noop ( - "enable adding the creation time to the " - "metadata of the uploaded file"), - &enable_creation_time), - GNUNET_GETOPT_option_flag ('e', - "extract", - gettext_noop ( - "print list of extracted keywords that would " - "be used, but do not perform upload"), - &extract_only), - GNUNET_FS_GETOPT_KEYWORDS ( - 'k', - "key", - "KEYWORD", - gettext_noop ( - "add an additional keyword for the top-level " - "file or directory (this option can be specified multiple times)"), - &topKeywords), - GNUNET_FS_GETOPT_METADATA ( - 'm', - "meta", - "TYPE:VALUE", - gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), - &meta), - GNUNET_GETOPT_option_flag ( - 'n', - "noindex", - gettext_noop ("do not index, perform full insertion (stores " - "entire file in encrypted form in GNUnet database)"), - &do_insert), - GNUNET_GETOPT_option_string ( - 'N', - "next", - "ID", - gettext_noop ("specify ID of an updated version to be " - "published in the future (for namespace insertions only)"), - &next_id), - GNUNET_GETOPT_option_uint ('p', - "priority", - "PRIORITY", - gettext_noop ( - "specify the priority of the content"), - &bo.content_priority), - GNUNET_GETOPT_option_string ('P', - "pseudonym", - "NAME", - gettext_noop ( - "publish the files under the pseudonym " - "NAME (place file into namespace)"), - &pseudonym), - GNUNET_GETOPT_option_uint ('r', - "replication", - "LEVEL", - gettext_noop ( - "set the desired replication LEVEL"), - &bo.replication_level), - GNUNET_GETOPT_option_flag ('s', - "simulate-only", - gettext_noop ( - "only simulate the process but do not do " - "any actual publishing (useful to compute URIs)"), - &do_simulate), - GNUNET_GETOPT_option_string ('t', - "this", - "ID", - gettext_noop ( - "set the ID of this version of the publication " - "(for namespace insertions only)"), - &this_id), - GNUNET_GETOPT_option_string ( - 'u', - "uri", - "URI", - gettext_noop ( - "URI to be published (can be used instead of passing a " - "file to add keywords to the file with the respective URI)"), - &uri_string), - - GNUNET_GETOPT_option_verbose (&verbose), - - GNUNET_GETOPT_OPTION_END}; + { GNUNET_GETOPT_option_uint('a', + "anonymity", + "LEVEL", + gettext_noop( + "set the desired LEVEL of sender-anonymity"), + &bo.anonymity_level), + GNUNET_GETOPT_option_flag( + 'D', + "disable-extractor", + gettext_noop("do not use libextractor to add keywords or metadata"), + &disable_extractor), + GNUNET_GETOPT_option_flag('E', + "enable-creation-time", + gettext_noop( + "enable adding the creation time to the " + "metadata of the uploaded file"), + &enable_creation_time), + GNUNET_GETOPT_option_flag('e', + "extract", + gettext_noop( + "print list of extracted keywords that would " + "be used, but do not perform upload"), + &extract_only), + GNUNET_FS_GETOPT_KEYWORDS( + 'k', + "key", + "KEYWORD", + gettext_noop( + "add an additional keyword for the top-level " + "file or directory (this option can be specified multiple times)"), + &topKeywords), + GNUNET_FS_GETOPT_METADATA( + 'm', + "meta", + "TYPE:VALUE", + gettext_noop("set the meta-data for the given TYPE to the given VALUE"), + &meta), + GNUNET_GETOPT_option_flag( + 'n', + "noindex", + gettext_noop("do not index, perform full insertion (stores " + "entire file in encrypted form in GNUnet database)"), + &do_insert), + GNUNET_GETOPT_option_string( + 'N', + "next", + "ID", + gettext_noop("specify ID of an updated version to be " + "published in the future (for namespace insertions only)"), + &next_id), + GNUNET_GETOPT_option_uint('p', + "priority", + "PRIORITY", + gettext_noop( + "specify the priority of the content"), + &bo.content_priority), + GNUNET_GETOPT_option_string('P', + "pseudonym", + "NAME", + gettext_noop( + "publish the files under the pseudonym " + "NAME (place file into namespace)"), + &pseudonym), + GNUNET_GETOPT_option_uint('r', + "replication", + "LEVEL", + gettext_noop( + "set the desired replication LEVEL"), + &bo.replication_level), + GNUNET_GETOPT_option_flag('s', + "simulate-only", + gettext_noop( + "only simulate the process but do not do " + "any actual publishing (useful to compute URIs)"), + &do_simulate), + GNUNET_GETOPT_option_string('t', + "this", + "ID", + gettext_noop( + "set the ID of this version of the publication " + "(for namespace insertions only)"), + &this_id), + GNUNET_GETOPT_option_string( + 'u', + "uri", + "URI", + gettext_noop( + "URI to be published (can be used instead of passing a " + "file to add keywords to the file with the respective URI)"), + &uri_string), + + GNUNET_GETOPT_option_verbose(&verbose), + + GNUNET_GETOPT_OPTION_END }; + bo.expiration_time = - GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); + GNUNET_TIME_year_to_time(GNUNET_TIME_get_current_year() + 2); - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-publish [OPTIONS] FILENAME", - gettext_noop ("Publish a file or directory on GNUnet"), - options, - &run, - NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run(argc, + argv, + "gnunet-publish [OPTIONS] FILENAME", + gettext_noop("Publish a file or directory on GNUnet"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 7d6ff4c6b..ac31387e2 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-search.c * @brief searching for files on GNUnet @@ -76,13 +76,13 @@ static struct GNUNET_SCHEDULER_Task *tt; * @return 0 to continue extracting, 1 to abort */ static int -item_printer (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_size) +item_printer(void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_size) { if ((format != EXTRACTOR_METAFORMAT_UTF8) && (format != EXTRACTOR_METAFORMAT_C_STRING)) @@ -90,45 +90,45 @@ item_printer (void *cls, if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) return 0; #if HAVE_LIBEXTRACTOR - printf ("\t%20s: %s\n", - dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, - EXTRACTOR_metatype_to_string (type)), - data); + printf("\t%20s: %s\n", + dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, + EXTRACTOR_metatype_to_string(type)), + data); #else - printf ("\t%20d: %s\n", type, data); + printf("\t%20d: %s\n", type, data); #endif return 0; } static void -clean_task (void *cls) +clean_task(void *cls) { size_t dsize; void *ddata; - GNUNET_FS_stop (ctx); + GNUNET_FS_stop(ctx); ctx = NULL; if (output_filename == NULL) return; - if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) - { - GNUNET_break (0); - GNUNET_free (output_filename); - return; - } - if (dsize != GNUNET_DISK_fn_write (output_filename, - ddata, - dsize, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) - { - fprintf (stderr, - _ ("Failed to write directory with search results to `%s'\n"), - output_filename); - } - GNUNET_free_non_null (ddata); - GNUNET_free (output_filename); + if (GNUNET_OK != GNUNET_FS_directory_builder_finish(db, &dsize, &ddata)) + { + GNUNET_break(0); + GNUNET_free(output_filename); + return; + } + if (dsize != GNUNET_DISK_fn_write(output_filename, + ddata, + dsize, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) + { + fprintf(stderr, + _("Failed to write directory with search results to `%s'\n"), + output_filename); + } + GNUNET_free_non_null(ddata); + GNUNET_free(output_filename); } @@ -146,7 +146,7 @@ clean_task (void *cls) * field in the GNUNET_FS_ProgressInfo struct. */ static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) { static unsigned int cnt; int is_directory; @@ -154,92 +154,98 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) char *filename; switch (info->status) - { - case GNUNET_FS_STATUS_SEARCH_START: - break; - case GNUNET_FS_STATUS_SEARCH_RESULT: - if (db != NULL) - GNUNET_FS_directory_builder_add (db, - info->value.search.specifics.result.uri, - info->value.search.specifics.result.meta, - NULL); - uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); - printf ("#%u:\n", ++cnt); - filename = GNUNET_CONTAINER_meta_data_get_by_type ( - info->value.search.specifics.result.meta, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); - is_directory = GNUNET_FS_meta_data_test_for_directory ( - info->value.search.specifics.result.meta); - if (NULL != filename) { - while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1])) - filename[strlen (filename) - 1] = '\0'; - GNUNET_DISK_filename_canonicalize (filename); - if (GNUNET_YES == is_directory) - printf ("gnunet-download -o \"%s%s\" -R %s\n", - filename, - GNUNET_FS_DIRECTORY_EXT, - uri); + case GNUNET_FS_STATUS_SEARCH_START: + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + if (db != NULL) + GNUNET_FS_directory_builder_add(db, + info->value.search.specifics.result.uri, + info->value.search.specifics.result.meta, + NULL); + uri = GNUNET_FS_uri_to_string(info->value.search.specifics.result.uri); + printf("#%u:\n", ++cnt); + filename = GNUNET_CONTAINER_meta_data_get_by_type( + info->value.search.specifics.result.meta, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + is_directory = GNUNET_FS_meta_data_test_for_directory( + info->value.search.specifics.result.meta); + if (NULL != filename) + { + while ((filename[0] != '\0') && ('/' == filename[strlen(filename) - 1])) + filename[strlen(filename) - 1] = '\0'; + GNUNET_DISK_filename_canonicalize(filename); + if (GNUNET_YES == is_directory) + printf("gnunet-download -o \"%s%s\" -R %s\n", + filename, + GNUNET_FS_DIRECTORY_EXT, + uri); + else + printf("gnunet-download -o \"%s\" %s\n", filename, uri); + } + else if (GNUNET_YES == is_directory) + printf("gnunet-download -o \"collection%s\" -R %s\n", + GNUNET_FS_DIRECTORY_EXT, + uri); else - printf ("gnunet-download -o \"%s\" %s\n", filename, uri); + printf("gnunet-download %s\n", uri); + if (verbose) + GNUNET_CONTAINER_meta_data_iterate(info->value.search.specifics.result + .meta, + &item_printer, + NULL); + printf("\n"); + fflush(stdout); + GNUNET_free_non_null(filename); + GNUNET_free(uri); + results++; + if ((results_limit > 0) && (results >= results_limit)) + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_SEARCH_UPDATE: + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + /* ignore */ + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, + _("Error searching: %s.\n"), + info->value.search.specifics.error.message); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_SCHEDULER_add_now(&clean_task, NULL); + break; + + default: + fprintf(stderr, _("Unexpected status: %d\n"), info->status); + break; } - else if (GNUNET_YES == is_directory) - printf ("gnunet-download -o \"collection%s\" -R %s\n", - GNUNET_FS_DIRECTORY_EXT, - uri); - else - printf ("gnunet-download %s\n", uri); - if (verbose) - GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result - .meta, - &item_printer, - NULL); - printf ("\n"); - fflush (stdout); - GNUNET_free_non_null (filename); - GNUNET_free (uri); - results++; - if ((results_limit > 0) && (results >= results_limit)) - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_SEARCH_UPDATE: - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - /* ignore */ - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, - _ ("Error searching: %s.\n"), - info->value.search.specifics.error.message); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - GNUNET_SCHEDULER_add_now (&clean_task, NULL); - break; - default: - fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); - break; - } return NULL; } static void -shutdown_task (void *cls) +shutdown_task(void *cls) { if (sc != NULL) - { - GNUNET_FS_search_stop (sc); - sc = NULL; - } + { + GNUNET_FS_search_stop(sc); + sc = NULL; + } } static void -timeout_task (void *cls) +timeout_task(void *cls) { tt = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -252,10 +258,10 @@ timeout_task (void *cls) * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_FS_Uri *uri; unsigned int argc; @@ -264,46 +270,46 @@ run (void *cls, argc = 0; while (NULL != args[argc]) argc++; - uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); + uri = GNUNET_FS_uri_ksk_create_from_args(argc, (const char **)args); if (NULL == uri) - { - fprintf (stderr, - "%s", - _ ("Could not create keyword URI from arguments.\n")); - ret = 1; - return; - } + { + fprintf(stderr, + "%s", + _("Could not create keyword URI from arguments.\n")); + ret = 1; + return; + } cfg = c; - ctx = GNUNET_FS_start (cfg, - "gnunet-search", - &progress_cb, - NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start(cfg, + "gnunet-search", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) - { - fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); - GNUNET_FS_uri_destroy (uri); - ret = 1; - return; - } + { + fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + GNUNET_FS_uri_destroy(uri); + ret = 1; + return; + } if (output_filename != NULL) - db = GNUNET_FS_directory_builder_create (NULL); + db = GNUNET_FS_directory_builder_create(NULL); options = GNUNET_FS_SEARCH_OPTION_NONE; if (local_only) options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; - sc = GNUNET_FS_search_start (ctx, uri, anonymity, options, NULL); - GNUNET_FS_uri_destroy (uri); + sc = GNUNET_FS_search_start(ctx, uri, anonymity, options, NULL); + GNUNET_FS_uri_destroy(uri); if (NULL == sc) - { - fprintf (stderr, "%s", _ ("Could not start searching.\n")); - GNUNET_FS_stop (ctx); - ret = 1; - return; - } + { + fprintf(stderr, "%s", _("Could not start searching.\n")); + GNUNET_FS_stop(ctx); + ret = 1; + return; + } if (0 != timeout.rel_value_us) - tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + tt = GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, NULL); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); } @@ -315,57 +321,57 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - {GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ( - "set the desired LEVEL of receiver-anonymity"), - &anonymity), - GNUNET_GETOPT_option_flag ( - 'n', - "no-network", - gettext_noop ("only search the local peer (no P2P network search)"), - &local_only), - GNUNET_GETOPT_option_string ( - 'o', - "output", - "PREFIX", - gettext_noop ("write search results to file starting with PREFIX"), - &output_filename), - GNUNET_GETOPT_option_relative_time ( - 't', - "timeout", - "DELAY", - gettext_noop ("automatically terminate search after DELAY"), - &timeout), - GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_option_uint ('N', - "results", - "VALUE", - gettext_noop ("automatically terminate search " - "after VALUE results are found"), - &results_limit), - GNUNET_GETOPT_OPTION_END}; - - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + { GNUNET_GETOPT_option_uint('a', + "anonymity", + "LEVEL", + gettext_noop( + "set the desired LEVEL of receiver-anonymity"), + &anonymity), + GNUNET_GETOPT_option_flag( + 'n', + "no-network", + gettext_noop("only search the local peer (no P2P network search)"), + &local_only), + GNUNET_GETOPT_option_string( + 'o', + "output", + "PREFIX", + gettext_noop("write search results to file starting with PREFIX"), + &output_filename), + GNUNET_GETOPT_option_relative_time( + 't', + "timeout", + "DELAY", + gettext_noop("automatically terminate search after DELAY"), + &timeout), + GNUNET_GETOPT_option_verbose(&verbose), + GNUNET_GETOPT_option_uint('N', + "results", + "VALUE", + gettext_noop("automatically terminate search " + "after VALUE results are found"), + &results_limit), + GNUNET_GETOPT_OPTION_END }; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-search [OPTIONS] KEYWORD", - gettext_noop ( - "Search GNUnet for files that were published on GNUnet"), - options, - &run, - NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run(argc, + argv, + "gnunet-search [OPTIONS] KEYWORD", + gettext_noop( + "Search GNUnet for files that were published on GNUnet"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 691242ce3..70aff8a75 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs.c @@ -59,7 +59,7 @@ * time interval, remaining cover traffic counters are * decremented by 1/16th. */ -#define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /** * Collect an instane number of statistics? May cause excessive IPC. @@ -72,9 +72,7 @@ * Doubly-linked list of requests we are performing * on behalf of the same client. */ -struct ClientRequest -{ - +struct ClientRequest { /** * This is a doubly-linked list. */ @@ -99,7 +97,6 @@ struct ClientRequest * Task scheduled to destroy the request. */ struct GNUNET_SCHEDULER_Task * kill_task; - }; @@ -107,8 +104,7 @@ struct ClientRequest * Replies to be transmitted to the client. The actual * response message is allocated after this struct. */ -struct ClientResponse -{ +struct ClientResponse { /** * This is a doubly-linked list. */ @@ -135,9 +131,7 @@ struct ClientResponse * Information we track while handling an index * start request from a client. */ -struct IndexStartContext -{ - +struct IndexStartContext { /** * This is a doubly linked list. */ @@ -167,16 +161,13 @@ struct IndexStartContext * Hash of the contents of the file. */ struct GNUNET_HashCode file_id; - }; /** * A local client. */ -struct GSF_LocalClient -{ - +struct GSF_LocalClient { /** * ID of the client. */ @@ -218,7 +209,6 @@ struct GSF_LocalClient * Tail of linked list of responses. */ struct ClientResponse *res_tail; - }; @@ -343,13 +333,13 @@ static struct GNUNET_LOAD_Value *datastore_get_load; * @return handle to local client entry */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct GSF_LocalClient *pos; - pos = GNUNET_new (struct GSF_LocalClient); + pos = GNUNET_new(struct GSF_LocalClient); pos->client = client; pos->mq = mq; return pos; @@ -362,22 +352,22 @@ client_connect_cb (void *cls, * @param cls the client request to free */ static void -client_request_destroy (void *cls) +client_request_destroy(void *cls) { struct ClientRequest *cr = cls; struct GSF_LocalClient *lc = cr->lc; cr->kill_task = NULL; - GNUNET_CONTAINER_DLL_remove (lc->cr_head, - lc->cr_tail, - cr); - GSF_pending_request_cancel_ (cr->pr, - GNUNET_YES); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# client searches active"), - -1, - GNUNET_NO); - GNUNET_free (cr); + GNUNET_CONTAINER_DLL_remove(lc->cr_head, + lc->cr_tail, + cr); + GSF_pending_request_cancel_(cr->pr, + GNUNET_YES); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# client searches active"), + -1, + GNUNET_NO); + GNUNET_free(cr); } @@ -400,15 +390,15 @@ client_request_destroy (void *cls) * @param data_len number of bytes in @a data */ static void -client_response_handler (void *cls, - enum GNUNET_BLOCK_EvaluationResult eval, - struct GSF_PendingRequest *pr, - uint32_t reply_anonymity_level, - struct GNUNET_TIME_Absolute expiration, - struct GNUNET_TIME_Absolute last_transmission, - enum GNUNET_BLOCK_Type type, - const void *data, - size_t data_len) +client_response_handler(void *cls, + enum GNUNET_BLOCK_EvaluationResult eval, + struct GSF_PendingRequest *pr, + uint32_t reply_anonymity_level, + struct GNUNET_TIME_Absolute expiration, + struct GNUNET_TIME_Absolute last_transmission, + enum GNUNET_BLOCK_Type type, + const void *data, + size_t data_len) { struct ClientRequest *cr = cls; struct GSF_LocalClient *lc; @@ -417,52 +407,52 @@ client_response_handler (void *cls, const struct GSF_PendingRequestData *prd; if (NULL == data) - { - /* local-only request, with no result, clean up. */ - if (NULL == cr->kill_task) - cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, - cr); - return; - } - prd = GSF_pending_request_get_data_ (pr); - GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); + { + /* local-only request, with no result, clean up. */ + if (NULL == cr->kill_task) + cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, + cr); + return; + } + prd = GSF_pending_request_get_data_(pr); + GNUNET_break(type != GNUNET_BLOCK_TYPE_ANY); if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) - { - GNUNET_break (0); - return; - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# replies received for local clients"), 1, - GNUNET_NO); - GNUNET_assert (pr == cr->pr); + { + GNUNET_break(0); + return; + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# replies received for local clients"), 1, + GNUNET_NO); + GNUNET_assert(pr == cr->pr); lc = cr->lc; - env = GNUNET_MQ_msg_extra (pm, - data_len, - GNUNET_MESSAGE_TYPE_FS_PUT); - pm->type = htonl (type); - pm->expiration = GNUNET_TIME_absolute_hton (expiration); - pm->last_transmission = GNUNET_TIME_absolute_hton (last_transmission); - pm->num_transmissions = htonl (prd->num_transmissions); - pm->respect_offered = htonl (prd->respect_offered); - GNUNET_memcpy (&pm[1], - data, - data_len); - GNUNET_MQ_send (lc->mq, - env); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queued reply to query `%s' for local client\n", - GNUNET_h2s (&prd->query)); + env = GNUNET_MQ_msg_extra(pm, + data_len, + GNUNET_MESSAGE_TYPE_FS_PUT); + pm->type = htonl(type); + pm->expiration = GNUNET_TIME_absolute_hton(expiration); + pm->last_transmission = GNUNET_TIME_absolute_hton(last_transmission); + pm->num_transmissions = htonl(prd->num_transmissions); + pm->respect_offered = htonl(prd->respect_offered); + GNUNET_memcpy(&pm[1], + data, + data_len); + GNUNET_MQ_send(lc->mq, + env); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Queued reply to query `%s' for local client\n", + GNUNET_h2s(&prd->query)); if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Evaluation %d - keeping query alive\n", - (int) eval); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Evaluation %d - keeping query alive\n", + (int)eval); + return; + } if (NULL == cr->kill_task) - cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, - cr); + cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, + cr); } @@ -475,9 +465,9 @@ client_response_handler (void *cls, * @param app_ctx the `struct GSF_LocalClient` */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct GSF_LocalClient *lc = app_ctx; struct IndexStartContext *isc; @@ -485,27 +475,27 @@ client_disconnect_cb (void *cls, struct ClientResponse *res; while (NULL != (cr = lc->cr_head)) - { - if (NULL != cr->kill_task) - GNUNET_SCHEDULER_cancel (cr->kill_task); - client_request_destroy (cr); - } + { + if (NULL != cr->kill_task) + GNUNET_SCHEDULER_cancel(cr->kill_task); + client_request_destroy(cr); + } while (NULL != (res = lc->res_head)) - { - GNUNET_CONTAINER_DLL_remove (lc->res_head, - lc->res_tail, - res); - GNUNET_free (res); - } + { + GNUNET_CONTAINER_DLL_remove(lc->res_head, + lc->res_tail, + res); + GNUNET_free(res); + } while (NULL != (isc = lc->isc_head)) - { - GNUNET_CONTAINER_DLL_remove (lc->isc_head, - lc->isc_tail, - isc); - GNUNET_CRYPTO_hash_file_cancel (isc->fhc); - GNUNET_free (isc); - } - GNUNET_free (lc); + { + GNUNET_CONTAINER_DLL_remove(lc->isc_head, + lc->isc_tail, + isc); + GNUNET_CRYPTO_hash_file_cancel(isc->fhc); + GNUNET_free(isc); + } + GNUNET_free(lc); } @@ -518,14 +508,14 @@ client_disconnect_cb (void *cls, * @param cls unused closure */ static void -age_cover_counters (void *cls) +age_cover_counters(void *cls) { GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; cover_age_task = - GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, - &age_cover_counters, - NULL); + GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, + &age_cover_counters, + NULL); } @@ -536,12 +526,12 @@ age_cover_counters (void *cls) * @param start time when the datastore request was issued */ void -GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) +GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start) { struct GNUNET_TIME_Relative delay; - delay = GNUNET_TIME_absolute_get_duration (start); - GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us); + delay = GNUNET_TIME_absolute_get_duration(start); + GNUNET_LOAD_update(datastore_get_load, delay.rel_value_us); } @@ -556,11 +546,11 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) * #GNUNET_SYSERR to process for free (load low) */ int -GSF_test_get_load_too_high_ (uint32_t priority) +GSF_test_get_load_too_high_(uint32_t priority) { double ld; - ld = GNUNET_LOAD_get_load (datastore_get_load); + ld = GNUNET_LOAD_get_load(datastore_get_load); if (ld < 1) return GNUNET_SYSERR; if (ld <= priority) @@ -581,30 +571,30 @@ GSF_test_get_load_too_high_ (uint32_t priority) * @param prop performance data for the address (as far as known) */ static void -update_latencies (void *cls, - const struct GNUNET_HELLO_Address *address, - int active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Properties *prop) +update_latencies(void *cls, + const struct GNUNET_HELLO_Address *address, + int active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *prop) { if (NULL == address) - { - /* ATS service temporarily disconnected */ - return; - } + { + /* ATS service temporarily disconnected */ + return; + } if (GNUNET_YES != active) return; - GSF_update_peer_latency_ (&address->peer, - prop->delay); + GSF_update_peer_latency_(&address->peer, + prop->delay); GSF_avg_latency.rel_value_us = (GSF_avg_latency.rel_value_us * 31 + - GNUNET_MIN (5000, prop->delay.rel_value_us)) / 32; - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# running average P2P latency (ms)"), - GSF_avg_latency.rel_value_us / 1000LL, - GNUNET_NO); + GNUNET_MIN(5000, prop->delay.rel_value_us)) / 32; + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# running average P2P latency (ms)"), + GSF_avg_latency.rel_value_us / 1000LL, + GNUNET_NO); } @@ -617,17 +607,17 @@ update_latencies (void *cls, * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_p2p_put (void *cls, - const struct PutMessage *put) +check_p2p_put(void *cls, + const struct PutMessage *put) { enum GNUNET_BLOCK_Type type; - type = ntohl (put->type); + type = ntohl(put->type); if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -642,25 +632,25 @@ check_p2p_put (void *cls, * @param ppd peer performance data */ static void -consider_request_for_forwarding (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GSF_ConnectedPeer *cp, - const struct GSF_PeerPerformanceData *ppd) +consider_request_for_forwarding(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GSF_ConnectedPeer *cp, + const struct GSF_PeerPerformanceData *ppd) { struct GSF_PendingRequest *pr = cls; if (GNUNET_YES != - GSF_pending_request_test_target_ (pr, peer)) - { + GSF_pending_request_test_target_(pr, peer)) + { #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Loopback routes suppressed"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Loopback routes suppressed"), 1, + GNUNET_NO); #endif - return; - } - GSF_plan_add_ (cp, - pr); + return; + } + GSF_plan_add_(cp, + pr); } @@ -675,17 +665,17 @@ consider_request_for_forwarding (void *cls, * @param result final datastore lookup result */ void -GSF_consider_forwarding (void *cls, - struct GSF_PendingRequest *pr, - enum GNUNET_BLOCK_EvaluationResult result) +GSF_consider_forwarding(void *cls, + struct GSF_PendingRequest *pr, + enum GNUNET_BLOCK_EvaluationResult result) { if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) return; /* we're done... */ if (GNUNET_YES != - GSF_pending_request_test_active_ (pr)) + GSF_pending_request_test_active_(pr)) return; /* request is not actually active, skip! */ - GSF_iterate_connected_peers_ (&consider_request_for_forwarding, - pr); + GSF_iterate_connected_peers_(&consider_request_for_forwarding, + pr); } @@ -698,35 +688,35 @@ GSF_consider_forwarding (void *cls, * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_p2p_get (void *cls, - const struct GetMessage *gm) +check_p2p_get(void *cls, + const struct GetMessage *gm) { size_t msize; unsigned int bm; unsigned int bits; size_t bfsize; - msize = ntohs (gm->header.size); - bm = ntohl (gm->hash_bitmap); + msize = ntohs(gm->header.size); + bm = ntohl(gm->hash_bitmap); bits = 0; while (bm > 0) - { - if (1 == (bm & 1)) - bits++; - bm >>= 1; - } - if (msize < sizeof (struct GetMessage) + bits * sizeof (struct GNUNET_PeerIdentity)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity); + { + if (1 == (bm & 1)) + bits++; + bm >>= 1; + } + if (msize < sizeof(struct GetMessage) + bits * sizeof(struct GNUNET_PeerIdentity)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); /* bfsize must be power of 2, check! */ if (0 != ((bfsize - 1) & bfsize)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -742,46 +732,48 @@ check_p2p_get (void *cls, * @param result final datastore lookup result */ static void -start_p2p_processing (void *cls, - struct GSF_PendingRequest *pr, - enum GNUNET_BLOCK_EvaluationResult result) +start_p2p_processing(void *cls, + struct GSF_PendingRequest *pr, + enum GNUNET_BLOCK_EvaluationResult result) { struct GSF_LocalClient *lc = cls; struct GSF_PendingRequestData *prd; - GNUNET_SERVICE_client_continue (lc->client); + GNUNET_SERVICE_client_continue(lc->client); if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) return; /* we're done, 'pr' was already destroyed... */ - prd = GSF_pending_request_get_data_ (pr); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished database lookup for local request `%s' with result %d\n", - GNUNET_h2s (&prd->query), - result); + prd = GSF_pending_request_get_data_(pr); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished database lookup for local request `%s' with result %d\n", + GNUNET_h2s(&prd->query), + result); if (0 == prd->anonymity_level) - { - switch (prd->type) { - case GNUNET_BLOCK_TYPE_FS_DBLOCK: - case GNUNET_BLOCK_TYPE_FS_IBLOCK: - /* the above block types MAY be available via 'cadet' */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Considering cadet-based download for block\n"); - GSF_cadet_lookup_ (pr); - break; - case GNUNET_BLOCK_TYPE_FS_UBLOCK: - /* the above block types are in the DHT */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Considering DHT-based search for block\n"); - GSF_dht_lookup_ (pr); - break; - default: - GNUNET_break (0); - break; + switch (prd->type) + { + case GNUNET_BLOCK_TYPE_FS_DBLOCK: + case GNUNET_BLOCK_TYPE_FS_IBLOCK: + /* the above block types MAY be available via 'cadet' */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Considering cadet-based download for block\n"); + GSF_cadet_lookup_(pr); + break; + + case GNUNET_BLOCK_TYPE_FS_UBLOCK: + /* the above block types are in the DHT */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Considering DHT-based search for block\n"); + GSF_dht_lookup_(pr); + break; + + default: + GNUNET_break(0); + break; + } } - } - GSF_consider_forwarding (NULL, - pr, - result); + GSF_consider_forwarding(NULL, + pr, + result); } @@ -794,17 +786,17 @@ start_p2p_processing (void *cls, * @return #GNUNET_OK if @a sm is well-formed */ static int -check_client_start_search (void *cls, - const struct SearchMessage *sm) +check_client_start_search(void *cls, + const struct SearchMessage *sm) { uint16_t msize; - msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); - if (0 != msize % sizeof (struct GNUNET_HashCode)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); + if (0 != msize % sizeof(struct GNUNET_HashCode)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -820,8 +812,8 @@ check_client_start_search (void *cls, * @param sm the actual message */ static void -handle_client_start_search (void *cls, - const struct SearchMessage *sm) +handle_client_start_search(void *cls, + const struct SearchMessage *sm) { static struct GNUNET_PeerIdentity all_zeros; struct GSF_LocalClient *lc = cls; @@ -832,90 +824,90 @@ handle_client_start_search (void *cls, enum GNUNET_BLOCK_Type type; enum GSF_PendingRequestOptions options; - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# client searches received"), - 1, - GNUNET_NO); - msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); - sc = msize / sizeof (struct GNUNET_HashCode); - type = ntohl (sm->type); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received request for `%s' of type %u from local client\n", - GNUNET_h2s (&sm->query), - (unsigned int) type); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# client searches received"), + 1, + GNUNET_NO); + msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); + sc = msize / sizeof(struct GNUNET_HashCode); + type = ntohl(sm->type); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received request for `%s' of type %u from local client\n", + GNUNET_h2s(&sm->query), + (unsigned int)type); cr = NULL; /* detect duplicate UBLOCK requests */ if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || (type == GNUNET_BLOCK_TYPE_ANY)) - { - cr = lc->cr_head; - while (NULL != cr) { - prd = GSF_pending_request_get_data_ (cr->pr); - /* only unify with queries that hae not yet started local processing - (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a - matching query and type */ - if ((GNUNET_YES != prd->has_started) && - (0 != memcmp (&prd->query, - &sm->query, - sizeof (struct GNUNET_HashCode))) && - (prd->type == type)) - break; - cr = cr->next; + cr = lc->cr_head; + while (NULL != cr) + { + prd = GSF_pending_request_get_data_(cr->pr); + /* only unify with queries that hae not yet started local processing + (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a + matching query and type */ + if ((GNUNET_YES != prd->has_started) && + (0 != memcmp(&prd->query, + &sm->query, + sizeof(struct GNUNET_HashCode))) && + (prd->type == type)) + break; + cr = cr->next; + } } - } if (NULL != cr) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Have existing request, merging content-seen lists.\n"); - GSF_pending_request_update_ (cr->pr, - (const struct GNUNET_HashCode *) &sm[1], - sc); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# client searches updated (merged content seen list)"), - 1, - GNUNET_NO); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Have existing request, merging content-seen lists.\n"); + GSF_pending_request_update_(cr->pr, + (const struct GNUNET_HashCode *)&sm[1], + sc); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# client searches updated (merged content seen list)"), + 1, + GNUNET_NO); + } else - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# client searches active"), - 1, - GNUNET_NO); - cr = GNUNET_new (struct ClientRequest); - cr->lc = lc; - GNUNET_CONTAINER_DLL_insert (lc->cr_head, - lc->cr_tail, - cr); - options = GSF_PRO_LOCAL_REQUEST; - if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options))) - options |= GSF_PRO_LOCAL_ONLY; - cr->pr = GSF_pending_request_create_ (options, type, - &sm->query, - (0 != - memcmp (&sm->target, + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# client searches active"), + 1, + GNUNET_NO); + cr = GNUNET_new(struct ClientRequest); + cr->lc = lc; + GNUNET_CONTAINER_DLL_insert(lc->cr_head, + lc->cr_tail, + cr); + options = GSF_PRO_LOCAL_REQUEST; + if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl(sm->options))) + options |= GSF_PRO_LOCAL_ONLY; + cr->pr = GSF_pending_request_create_(options, type, + &sm->query, + (0 != + memcmp(&sm->target, &all_zeros, - sizeof (struct GNUNET_PeerIdentity))) - ? &sm->target : NULL, NULL, 0, - 0 /* bf */ , - ntohl (sm->anonymity_level), - 0 /* priority */ , - 0 /* ttl */ , - 0 /* sender PID */ , - 0 /* origin PID */ , - (const struct GNUNET_HashCode *) &sm[1], sc, - &client_response_handler, - cr); - } - if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl (sm->options))) - { - GNUNET_SERVICE_client_continue (lc->client); - return; - } - GSF_pending_request_get_data_ (cr->pr)->has_started = GNUNET_YES; - GSF_local_lookup_ (cr->pr, - &start_p2p_processing, - lc); + sizeof(struct GNUNET_PeerIdentity))) + ? &sm->target : NULL, NULL, 0, + 0 /* bf */, + ntohl(sm->anonymity_level), + 0 /* priority */, + 0 /* ttl */, + 0 /* sender PID */, + 0 /* origin PID */, + (const struct GNUNET_HashCode *)&sm[1], sc, + &client_response_handler, + cr); + } + if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl(sm->options))) + { + GNUNET_SERVICE_client_continue(lc->client); + return; + } + GSF_pending_request_get_data_(cr->pr)->has_started = GNUNET_YES; + GSF_local_lookup_(cr->pr, + &start_p2p_processing, + lc); } @@ -926,8 +918,8 @@ handle_client_start_search (void *cls, * @param msg the actual message */ static void -handle_client_loc_sign (void *cls, - const struct RequestLocSignatureMessage *msg) +handle_client_loc_sign(void *cls, + const struct RequestLocSignatureMessage *msg) { struct GSF_LocalClient *lc = cls; struct GNUNET_FS_Uri base; @@ -935,24 +927,24 @@ handle_client_loc_sign (void *cls, struct GNUNET_MQ_Envelope *env; struct ResponseLocSignatureMessage *resp; - GNUNET_break (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == - ntohl (msg->purpose)); + GNUNET_break(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == + ntohl(msg->purpose)); base.type = GNUNET_FS_URI_CHK; base.data.chk.chk = msg->chk; - base.data.chk.file_length = GNUNET_ntohll (msg->file_length); - loc = GNUNET_FS_uri_loc_create (&base, - pk, - GNUNET_TIME_absolute_ntoh (msg->expiration_time)); - env = GNUNET_MQ_msg (resp, - GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); - resp->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); - resp->expiration_time = GNUNET_TIME_absolute_hton (loc->data.loc.expirationTime); + base.data.chk.file_length = GNUNET_ntohll(msg->file_length); + loc = GNUNET_FS_uri_loc_create(&base, + pk, + GNUNET_TIME_absolute_ntoh(msg->expiration_time)); + env = GNUNET_MQ_msg(resp, + GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); + resp->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); + resp->expiration_time = GNUNET_TIME_absolute_hton(loc->data.loc.expirationTime); resp->signature = loc->data.loc.contentSignature; resp->peer = loc->data.loc.peer; - GNUNET_FS_uri_destroy (loc); - GNUNET_MQ_send (lc->mq, - env); - GNUNET_SERVICE_client_continue (lc->client); + GNUNET_FS_uri_destroy(loc); + GNUNET_MQ_send(lc->mq, + env); + GNUNET_SERVICE_client_continue(lc->client); } @@ -964,24 +956,24 @@ handle_client_loc_sign (void *cls, * @return #GNUNET_OK if @a ism is well-formed */ static int -check_client_index_start (void *cls, - const struct IndexStartMessage *ism) +check_client_index_start(void *cls, + const struct IndexStartMessage *ism) { char *fn; - GNUNET_MQ_check_zero_termination (ism); + GNUNET_MQ_check_zero_termination(ism); if (0 != ism->reserved) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); if (NULL == fn) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_free (fn); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_free(fn); return GNUNET_OK; } @@ -993,21 +985,21 @@ check_client_index_start (void *cls, * @param isc the data about the index info entry for the request */ static void -signal_index_ok (struct IndexStartContext *isc) +signal_index_ok(struct IndexStartContext *isc) { struct GSF_LocalClient *lc = isc->lc; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; - GNUNET_FS_add_to_index (isc->filename, - &isc->file_id); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); - GNUNET_MQ_send (lc->mq, - env); - GNUNET_free (isc->filename); - GNUNET_free (isc); - GNUNET_SERVICE_client_continue (lc->client); + GNUNET_FS_add_to_index(isc->filename, + &isc->file_id); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); + GNUNET_MQ_send(lc->mq, + env); + GNUNET_free(isc->filename); + GNUNET_free(isc); + GNUNET_SERVICE_client_continue(lc->client); } @@ -1019,36 +1011,36 @@ signal_index_ok (struct IndexStartContext *isc) * @param res resulting hash, NULL on error */ static void -hash_for_index_val (void *cls, - const struct GNUNET_HashCode *res) +hash_for_index_val(void *cls, + const struct GNUNET_HashCode *res) { struct IndexStartContext *isc = cls; struct GSF_LocalClient *lc = isc->lc; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; - GNUNET_CONTAINER_DLL_remove (lc->isc_head, - lc->isc_tail, - isc); + GNUNET_CONTAINER_DLL_remove(lc->isc_head, + lc->isc_tail, + isc); isc->fhc = NULL; - if ( (NULL == res) || - (0 != memcmp (res, - &isc->file_id, - sizeof (struct GNUNET_HashCode)))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), - isc->filename, - GNUNET_h2s (&isc->file_id)); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); - GNUNET_MQ_send (lc->mq, - env); - GNUNET_SERVICE_client_continue (lc->client); - GNUNET_free (isc); - return; - } - signal_index_ok (isc); + if ((NULL == res) || + (0 != memcmp(res, + &isc->file_id, + sizeof(struct GNUNET_HashCode)))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), + isc->filename, + GNUNET_h2s(&isc->file_id)); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); + GNUNET_MQ_send(lc->mq, + env); + GNUNET_SERVICE_client_continue(lc->client); + GNUNET_free(isc); + return; + } + signal_index_ok(isc); } @@ -1059,8 +1051,8 @@ hash_for_index_val (void *cls, * @param message the actual message */ static void -handle_client_index_start (void *cls, - const struct IndexStartMessage *ism) +handle_client_index_start(void *cls, + const struct IndexStartMessage *ism) { struct GSF_LocalClient *lc = cls; struct IndexStartContext *isc; @@ -1070,49 +1062,49 @@ handle_client_index_start (void *cls, uint64_t mydev; uint64_t myino; - fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); - GNUNET_assert (NULL != fn); - dev = GNUNET_ntohll (ism->device); - ino = GNUNET_ntohll (ism->inode); - isc = GNUNET_new (struct IndexStartContext); + fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); + GNUNET_assert(NULL != fn); + dev = GNUNET_ntohll(ism->device); + ino = GNUNET_ntohll(ism->inode); + isc = GNUNET_new(struct IndexStartContext); isc->filename = fn; isc->file_id = ism->file_id; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received START_INDEX message for file `%s'\n", - isc->filename); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received START_INDEX message for file `%s'\n", + isc->filename); isc->lc = lc; mydev = 0; myino = 0; - if ( ( (dev != 0) || - (ino != 0) ) && - (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, - &mydev, - &myino)) && - (dev == mydev) && - (ino == myino) ) - { - /* fast validation OK! */ - signal_index_ok (isc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", - (unsigned long long) ino, - (unsigned long long) myino, - (unsigned int) dev, - (unsigned int) mydev); + if (((dev != 0) || + (ino != 0)) && + (GNUNET_OK == GNUNET_DISK_file_get_identifiers(fn, + &mydev, + &myino)) && + (dev == mydev) && + (ino == myino)) + { + /* fast validation OK! */ + signal_index_ok(isc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", + (unsigned long long)ino, + (unsigned long long)myino, + (unsigned int)dev, + (unsigned int)mydev); /* slow validation, need to hash full file (again) */ - GNUNET_CONTAINER_DLL_insert (lc->isc_head, - lc->isc_tail, - isc); - isc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, - isc->filename, - HASHING_BLOCKSIZE, - &hash_for_index_val, - isc); + GNUNET_CONTAINER_DLL_insert(lc->isc_head, + lc->isc_tail, + isc); + isc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, + isc->filename, + HASHING_BLOCKSIZE, + &hash_for_index_val, + isc); if (NULL == isc->fhc) - hash_for_index_val (isc, - NULL); + hash_for_index_val(isc, + NULL); } @@ -1123,13 +1115,13 @@ handle_client_index_start (void *cls, * @param message the actual message */ static void -handle_client_index_list_get (void *cls, - const struct GNUNET_MessageHeader *message) +handle_client_index_list_get(void *cls, + const struct GNUNET_MessageHeader *message) { struct GSF_LocalClient *lc = cls; - GNUNET_FS_indexing_send_list (lc->mq); - GNUNET_SERVICE_client_continue (lc->client); + GNUNET_FS_indexing_send_list(lc->mq); + GNUNET_SERVICE_client_continue(lc->client); } @@ -1140,25 +1132,25 @@ handle_client_index_list_get (void *cls, * @param message the actual message */ static void -handle_client_unindex (void *cls, - const struct UnindexMessage *um) +handle_client_unindex(void *cls, + const struct UnindexMessage *um) { struct GSF_LocalClient *lc = cls; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; int found; - GNUNET_break (0 == um->reserved); - found = GNUNET_FS_indexing_do_unindex (&um->file_id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client requested unindexing of file `%s': %s\n", - GNUNET_h2s (&um->file_id), - found ? "found" : "not found"); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); - GNUNET_MQ_send (lc->mq, - env); - GNUNET_SERVICE_client_continue (lc->client); + GNUNET_break(0 == um->reserved); + found = GNUNET_FS_indexing_do_unindex(&um->file_id); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client requested unindexing of file `%s': %s\n", + GNUNET_h2s(&um->file_id), + found ? "found" : "not found"); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); + GNUNET_MQ_send(lc->mq, + env); + GNUNET_SERVICE_client_continue(lc->client); } @@ -1168,44 +1160,44 @@ handle_client_unindex (void *cls, * @param cls unused */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { - GSF_cadet_stop_server (); + GSF_cadet_stop_server(); if (NULL != GSF_core) - { - GNUNET_CORE_disconnect (GSF_core); - GSF_core = NULL; - } + { + GNUNET_CORE_disconnect(GSF_core); + GSF_core = NULL; + } if (NULL != GSF_ats) - { - GNUNET_ATS_performance_done (GSF_ats); - GSF_ats = NULL; - } - GSF_put_done_ (); - GSF_push_done_ (); - GSF_pending_request_done_ (); - GSF_plan_done (); - GSF_connected_peer_done_ (); - GNUNET_DATASTORE_disconnect (GSF_dsh, - GNUNET_NO); + { + GNUNET_ATS_performance_done(GSF_ats); + GSF_ats = NULL; + } + GSF_put_done_(); + GSF_push_done_(); + GSF_pending_request_done_(); + GSF_plan_done(); + GSF_connected_peer_done_(); + GNUNET_DATASTORE_disconnect(GSF_dsh, + GNUNET_NO); GSF_dsh = NULL; - GNUNET_DHT_disconnect (GSF_dht); + GNUNET_DHT_disconnect(GSF_dht); GSF_dht = NULL; - GNUNET_BLOCK_context_destroy (GSF_block_ctx); + GNUNET_BLOCK_context_destroy(GSF_block_ctx); GSF_block_ctx = NULL; - GNUNET_CONFIGURATION_destroy (block_cfg); + GNUNET_CONFIGURATION_destroy(block_cfg); block_cfg = NULL; - GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO); + GNUNET_STATISTICS_destroy(GSF_stats, GNUNET_NO); GSF_stats = NULL; if (NULL != cover_age_task) - { - GNUNET_SCHEDULER_cancel (cover_age_task); - cover_age_task = NULL; - } - GNUNET_FS_indexing_done (); - GNUNET_LOAD_value_free (datastore_get_load); + { + GNUNET_SCHEDULER_cancel(cover_age_task); + cover_age_task = NULL; + } + GNUNET_FS_indexing_done(); + GNUNET_LOAD_value_free(datastore_get_load); datastore_get_load = NULL; - GNUNET_LOAD_value_free (GSF_rt_entry_lifetime); + GNUNET_LOAD_value_free(GSF_rt_entry_lifetime); GSF_rt_entry_lifetime = NULL; } @@ -1221,16 +1213,16 @@ shutdown_task (void *cls) * @param my_identity ID of this peer, NULL if we failed */ static void -peer_init_handler (void *cls, - const struct GNUNET_PeerIdentity *my_identity) +peer_init_handler(void *cls, + const struct GNUNET_PeerIdentity *my_identity) { - if (0 != GNUNET_memcmp (&GSF_my_id, - my_identity)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Peer identity mismatch, refusing to start!\n"); - GNUNET_SCHEDULER_shutdown (); - } + if (0 != GNUNET_memcmp(&GSF_my_id, + my_identity)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Peer identity mismatch, refusing to start!\n"); + GNUNET_SCHEDULER_shutdown(); + } } @@ -1240,25 +1232,25 @@ peer_init_handler (void *cls, * @param c configuration to use */ static int -main_init (const struct GNUNET_CONFIGURATION_Handle *c) +main_init(const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { - GNUNET_MQ_handler_end () + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_MessageHandler p2p_handlers[] = { - GNUNET_MQ_hd_var_size (p2p_get, - GNUNET_MESSAGE_TYPE_FS_GET, - struct GetMessage, - NULL), - GNUNET_MQ_hd_var_size (p2p_put, - GNUNET_MESSAGE_TYPE_FS_PUT, - struct PutMessage, - NULL), - GNUNET_MQ_hd_fixed_size (p2p_migration_stop, - GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, - struct MigrationStopMessage, - NULL), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(p2p_get, + GNUNET_MESSAGE_TYPE_FS_GET, + struct GetMessage, + NULL), + GNUNET_MQ_hd_var_size(p2p_put, + GNUNET_MESSAGE_TYPE_FS_PUT, + struct PutMessage, + NULL), + GNUNET_MQ_hd_fixed_size(p2p_migration_stop, + GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, + struct MigrationStopMessage, + NULL), + GNUNET_MQ_handler_end() }; int anon_p2p_off; char *keyfile; @@ -1266,54 +1258,54 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) /* this option is really only for testcases that need to disable _anonymous_ file-sharing for some reason */ anon_p2p_off = (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, - "fs", - "DISABLE_ANON_TRANSFER")); + GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, + "fs", + "DISABLE_ANON_TRANSFER")); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, - "PEER", - "PRIVATE_KEY", - &keyfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); - GNUNET_SCHEDULER_shutdown (); - return GNUNET_SYSERR; - } - pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); - GNUNET_free (keyfile); - GNUNET_assert (NULL != pk); - GNUNET_CRYPTO_eddsa_key_get_public (pk, - &GSF_my_id.public_key); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "I am peer %s\n", - GNUNET_i2s (&GSF_my_id)); + GNUNET_CONFIGURATION_get_value_filename(GSF_cfg, + "PEER", + "PRIVATE_KEY", + &keyfile)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); + GNUNET_SCHEDULER_shutdown(); + return GNUNET_SYSERR; + } + pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); + GNUNET_free(keyfile); + GNUNET_assert(NULL != pk); + GNUNET_CRYPTO_eddsa_key_get_public(pk, + &GSF_my_id.public_key); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "I am peer %s\n", + GNUNET_i2s(&GSF_my_id)); GSF_core - = GNUNET_CORE_connect (GSF_cfg, - NULL, - &peer_init_handler, - &GSF_peer_connect_handler, - &GSF_peer_disconnect_handler, - (GNUNET_YES == anon_p2p_off) - ? no_p2p_handlers - : p2p_handlers); + = GNUNET_CORE_connect(GSF_cfg, + NULL, + &peer_init_handler, + &GSF_peer_connect_handler, + &GSF_peer_disconnect_handler, + (GNUNET_YES == anon_p2p_off) + ? no_p2p_handlers + : p2p_handlers); if (NULL == GSF_core) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect to `%s' service.\n"), - "core"); - return GNUNET_SYSERR; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to connect to `%s' service.\n"), + "core"); + return GNUNET_SYSERR; + } cover_age_task = - GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, - &age_cover_counters, - NULL); - datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); - GSF_cadet_start_server (); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, + &age_cover_counters, + NULL); + datastore_get_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); + GSF_cadet_start_server(); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, + NULL); return GNUNET_OK; } @@ -1326,55 +1318,55 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) * @param service the initialized service */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SERVICE_Handle *service) { unsigned long long dqs; GSF_cfg = cfg; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_size (GSF_cfg, - "fs", - "DATASTORE_QUEUE_SIZE", - &dqs)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, - "fs", - "DATASTORE_QUEUE_SIZE"); - dqs = 32; - } - GSF_datastore_queue_size = (unsigned int) dqs; + GNUNET_CONFIGURATION_get_value_size(GSF_cfg, + "fs", + "DATASTORE_QUEUE_SIZE", + &dqs)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, + "fs", + "DATASTORE_QUEUE_SIZE"); + dqs = 32; + } + GSF_datastore_queue_size = (unsigned int)dqs; GSF_enable_randomized_delays = - GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY"); - GSF_dsh = GNUNET_DATASTORE_connect (cfg); + GNUNET_CONFIGURATION_get_value_yesno(cfg, "fs", "DELAY"); + GSF_dsh = GNUNET_DATASTORE_connect(cfg); if (NULL == GSF_dsh) - { - GNUNET_SCHEDULER_shutdown (); - return; - } - GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL); - GSF_stats = GNUNET_STATISTICS_create ("fs", cfg); - block_cfg = GNUNET_CONFIGURATION_create (); - GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg); - GNUNET_assert (NULL != GSF_block_ctx); - GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE); - GSF_plan_init (); - GSF_pending_request_init_ (); - GSF_connected_peer_init_ (); - GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, - &update_latencies, - NULL); - GSF_push_init_ (); - GSF_put_init_ (); - if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, - GSF_dsh)) || - (GNUNET_OK != main_init (cfg)) ) - { - GNUNET_SCHEDULER_shutdown (); - shutdown_task (NULL); - return; - } + { + GNUNET_SCHEDULER_shutdown(); + return; + } + GSF_rt_entry_lifetime = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_FOREVER_REL); + GSF_stats = GNUNET_STATISTICS_create("fs", cfg); + block_cfg = GNUNET_CONFIGURATION_create(); + GSF_block_ctx = GNUNET_BLOCK_context_create(block_cfg); + GNUNET_assert(NULL != GSF_block_ctx); + GSF_dht = GNUNET_DHT_connect(cfg, FS_DHT_HT_SIZE); + GSF_plan_init(); + GSF_pending_request_init_(); + GSF_connected_peer_init_(); + GSF_ats = GNUNET_ATS_performance_init(GSF_cfg, + &update_latencies, + NULL); + GSF_push_init_(); + GSF_put_init_(); + if ((GNUNET_OK != GNUNET_FS_indexing_init(cfg, + GSF_dsh)) || + (GNUNET_OK != main_init(cfg))) + { + GNUNET_SCHEDULER_shutdown(); + shutdown_task(NULL); + return; + } } @@ -1382,33 +1374,33 @@ run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -("fs", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_var_size (client_index_start, + ("fs", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_var_size(client_index_start, GNUNET_MESSAGE_TYPE_FS_INDEX_START, struct IndexStartMessage, NULL), - GNUNET_MQ_hd_fixed_size (client_index_list_get, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (client_unindex, - GNUNET_MESSAGE_TYPE_FS_UNINDEX, - struct UnindexMessage, - NULL), - GNUNET_MQ_hd_var_size (client_start_search, + GNUNET_MQ_hd_fixed_size(client_index_list_get, + GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size(client_unindex, + GNUNET_MESSAGE_TYPE_FS_UNINDEX, + struct UnindexMessage, + NULL), + GNUNET_MQ_hd_var_size(client_start_search, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, struct SearchMessage, NULL), - GNUNET_MQ_hd_fixed_size (client_loc_sign, - GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, - struct RequestLocSignatureMessage, - NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_hd_fixed_size(client_loc_sign, + GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, + struct RequestLocSignatureMessage, + NULL), + GNUNET_MQ_handler_end()); /* end of gnunet-service-fs.c */ diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h index 661126f08..21a822c6d 100644 --- a/src/fs/gnunet-service-fs.h +++ b/src/fs/gnunet-service-fs.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs.h @@ -48,7 +48,7 @@ * automatically (since if we don't use it, clearly the * load must be going down). */ -#define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) +#define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) /** * Only the (mandatory) query is included. @@ -79,9 +79,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Message sent between peers asking for FS-content. */ -struct GetMessage -{ - +struct GetMessage { /** * Message type will be #GNUNET_MESSAGE_TYPE_FS_GET. */ @@ -136,8 +134,7 @@ struct GetMessage * Message send by a peer that wants to be excluded * from migration for a while. */ -struct MigrationStopMessage -{ +struct MigrationStopMessage { /** * Message type will be * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP. @@ -153,7 +150,6 @@ struct MigrationStopMessage * How long should the block last? */ struct GNUNET_TIME_RelativeNBO duration; - }; GNUNET_NETWORK_STRUCT_END @@ -279,9 +275,9 @@ extern unsigned int GSF_datastore_queue_size; * @param result final datastore lookup result */ void -GSF_consider_forwarding (void *cls, - struct GSF_PendingRequest *pr, - enum GNUNET_BLOCK_EvaluationResult result); +GSF_consider_forwarding(void *cls, + struct GSF_PendingRequest *pr, + enum GNUNET_BLOCK_EvaluationResult result); /** @@ -294,7 +290,7 @@ GSF_consider_forwarding (void *cls, * #GNUNET_SYSERR to process for free (load low) */ int -GSF_test_get_load_too_high_ (uint32_t priority); +GSF_test_get_load_too_high_(uint32_t priority); /** @@ -304,7 +300,7 @@ GSF_test_get_load_too_high_ (uint32_t priority); * @param start time when the datastore request was issued */ void -GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start); +GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start); #endif diff --git a/src/fs/gnunet-service-fs_cadet.h b/src/fs/gnunet-service-fs_cadet.h index 728faaf27..61bd8b314 100644 --- a/src/fs/gnunet-service-fs_cadet.h +++ b/src/fs/gnunet-service-fs_cadet.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_cadet.h @@ -60,11 +60,11 @@ typedef void * @return handle to cancel the operation */ struct GSF_CadetRequest * -GSF_cadet_query (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_HashCode *query, - enum GNUNET_BLOCK_Type type, - GSF_CadetReplyProcessor proc, - void *proc_cls); +GSF_cadet_query(const struct GNUNET_PeerIdentity *target, + const struct GNUNET_HashCode *query, + enum GNUNET_BLOCK_Type type, + GSF_CadetReplyProcessor proc, + void *proc_cls); /** * Function called on each active cadets to shut them down. @@ -75,9 +75,9 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target, * @return #GNUNET_YES (continue to iterate) */ int -GSF_cadet_release_clients (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value); +GSF_cadet_release_clients(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value); /** @@ -87,21 +87,21 @@ GSF_cadet_release_clients (void *cls, * @param sr request to cancel */ void -GSF_cadet_query_cancel (struct GSF_CadetRequest *sr); +GSF_cadet_query_cancel(struct GSF_CadetRequest *sr); /** * Initialize subsystem for non-anonymous file-sharing. */ void -GSF_cadet_start_server (void); +GSF_cadet_start_server(void); /** * Shutdown subsystem for non-anonymous file-sharing. */ void -GSF_cadet_stop_server (void); +GSF_cadet_stop_server(void); /** * Cadet channel for creating outbound channels. @@ -120,9 +120,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Query from one peer, asking the other for CHK-data. */ -struct CadetQueryMessage -{ - +struct CadetQueryMessage { /** * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY. */ @@ -137,16 +135,13 @@ struct CadetQueryMessage * Query hash from CHK (hash of encrypted block). */ struct GNUNET_HashCode query; - }; /** * Reply to a CadetQueryMessage. */ -struct CadetReplyMessage -{ - +struct CadetReplyMessage { /** * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY. */ @@ -163,7 +158,6 @@ struct CadetReplyMessage struct GNUNET_TIME_AbsoluteNBO expiration; /* followed by the encrypted block */ - }; GNUNET_NETWORK_STRUCT_END diff --git a/src/fs/gnunet-service-fs_cadet_client.c b/src/fs/gnunet-service-fs_cadet_client.c index 81afe0411..a494ba751 100644 --- a/src/fs/gnunet-service-fs_cadet_client.c +++ b/src/fs/gnunet-service-fs_cadet_client.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_cadet_client.c @@ -42,7 +42,7 @@ * After how long do we reset connections without replies? */ #define CLIENT_RETRY_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) /** @@ -54,9 +54,7 @@ struct CadetHandle; /** * Handle for a request that is going out via cadet API. */ -struct GSF_CadetRequest -{ - +struct GSF_CadetRequest { /** * DLL. */ @@ -103,8 +101,7 @@ struct GSF_CadetRequest /** * Handle for a cadet to another peer. */ -struct CadetHandle -{ +struct CadetHandle { /** * Head of DLL of pending requests on this cadet. */ @@ -168,7 +165,7 @@ struct GNUNET_CONTAINER_MultiPeerMap *cadet_map; * @param cls `struct CadetHandle` to process */ static void -transmit_pending (void *cls); +transmit_pending(void *cls); /** @@ -181,15 +178,15 @@ transmit_pending (void *cls); * @return #GNUNET_YES (continue to iterate) */ static int -move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) +move_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value) { struct CadetHandle *mh = cls; struct GSF_CadetRequest *sr = value; - GNUNET_assert ( + GNUNET_assert( GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, key, value)); - GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); + GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, key, value)); + GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); sr->was_transmitted = GNUNET_NO; return GNUNET_YES; } @@ -204,7 +201,7 @@ move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing */ static int -check_reply (void *cls, const struct CadetReplyMessage *srm) +check_reply(void *cls, const struct CadetReplyMessage *srm) { /* We check later... */ return GNUNET_OK; @@ -217,7 +214,7 @@ check_reply (void *cls, const struct CadetReplyMessage *srm) * @param cls the `struct CadetHandle` to tear down */ static void -reset_cadet_task (void *cls); +reset_cadet_task(void *cls); /** @@ -227,20 +224,18 @@ reset_cadet_task (void *cls); * @param mh cadet to reset */ static void -reset_cadet_async (struct CadetHandle *mh) +reset_cadet_async(struct CadetHandle *mh) { if (NULL != mh->reset_task) - GNUNET_SCHEDULER_cancel (mh->reset_task); - mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, mh); + GNUNET_SCHEDULER_cancel(mh->reset_task); + mh->reset_task = GNUNET_SCHEDULER_add_now(&reset_cadet_task, mh); } /** * Closure for handle_reply(). */ -struct HandleReplyClosure -{ - +struct HandleReplyClosure { /** * Reply payload. */ @@ -278,18 +273,18 @@ struct HandleReplyClosure * @return #GNUNET_YES (continue to iterate) */ static int -process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) +process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) { struct HandleReplyClosure *hrc = cls; struct GSF_CadetRequest *sr = value; - sr->proc (sr->proc_cls, - hrc->type, - hrc->expiration, - hrc->data_size, - hrc->data); + sr->proc(sr->proc_cls, + hrc->type, + hrc->expiration, + hrc->data_size, + hrc->data); sr->proc = NULL; - GSF_cadet_query_cancel (sr); + GSF_cadet_query_cancel(sr); hrc->found = GNUNET_YES; return GNUNET_YES; } @@ -306,11 +301,11 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) * @return #GNUNET_YES (continue to iterate) */ static int -free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) +free_waiting_entry(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GSF_CadetRequest *sr = value; - GSF_cadet_query_cancel (sr); + GSF_cadet_query_cancel(sr); return GNUNET_YES; } @@ -323,7 +318,7 @@ free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) * @param srm the actual message */ static void -handle_reply (void *cls, const struct CadetReplyMessage *srm) +handle_reply(void *cls, const struct CadetReplyMessage *srm) { struct CadetHandle *mh = cls; struct HandleReplyClosure hrc; @@ -331,47 +326,47 @@ handle_reply (void *cls, const struct CadetReplyMessage *srm) enum GNUNET_BLOCK_Type type; struct GNUNET_HashCode query; - msize = ntohs (srm->header.size) - sizeof (struct CadetReplyMessage); - type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); + msize = ntohs(srm->header.size) - sizeof(struct CadetReplyMessage); + type = (enum GNUNET_BLOCK_Type)ntohl(srm->type); if (GNUNET_YES != - GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query)) - { - GNUNET_break_op (0); - GNUNET_log ( - GNUNET_ERROR_TYPE_WARNING, - "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", - type, - msize, - GNUNET_i2s (&mh->target)); - reset_cadet_async (mh); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received reply `%s' via cadet from peer %s\n", - GNUNET_h2s (&query), - GNUNET_i2s (&mh->target)); - GNUNET_CADET_receive_done (mh->channel); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# replies received via cadet"), - 1, - GNUNET_NO); + GNUNET_BLOCK_get_key(GSF_block_ctx, type, &srm[1], msize, &query)) + { + GNUNET_break_op(0); + GNUNET_log( + GNUNET_ERROR_TYPE_WARNING, + "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", + type, + msize, + GNUNET_i2s(&mh->target)); + reset_cadet_async(mh); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received reply `%s' via cadet from peer %s\n", + GNUNET_h2s(&query), + GNUNET_i2s(&mh->target)); + GNUNET_CADET_receive_done(mh->channel); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# replies received via cadet"), + 1, + GNUNET_NO); hrc.data = &srm[1]; hrc.data_size = msize; - hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration); + hrc.expiration = GNUNET_TIME_absolute_ntoh(srm->expiration); hrc.type = type; hrc.found = GNUNET_NO; - GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map, - &query, - &process_reply, - &hrc); + GNUNET_CONTAINER_multihashmap_get_multiple(mh->waiting_map, + &query, + &process_reply, + &hrc); if (GNUNET_NO == hrc.found) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# replies received via cadet dropped"), - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# replies received via cadet dropped"), + 1, + GNUNET_NO); + } } @@ -383,34 +378,34 @@ handle_reply (void *cls, const struct CadetReplyMessage *srm) * @param channel channel of the disconnecting client */ static void -disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) +disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel) { struct CadetHandle *mh = cls; struct GSF_CadetRequest *sr; if (NULL == mh->channel) return; /* being destroyed elsewhere */ - GNUNET_assert (channel == mh->channel); + GNUNET_assert(channel == mh->channel); mh->channel = NULL; while (NULL != (sr = mh->pending_head)) - GSF_cadet_query_cancel (sr); + GSF_cadet_query_cancel(sr); /* first remove `mh` from the `cadet_map`, so that if the callback from `free_waiting_entry()` happens to re-issue the request, we don't immediately have it back in the `waiting_map`. */ - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (cadet_map, - &mh->target, - mh)); - GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, - &free_waiting_entry, - mh); + GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove(cadet_map, + &mh->target, + mh)); + GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, + &free_waiting_entry, + mh); if (NULL != mh->timeout_task) - GNUNET_SCHEDULER_cancel (mh->timeout_task); + GNUNET_SCHEDULER_cancel(mh->timeout_task); if (NULL != mh->reset_task) - GNUNET_SCHEDULER_cancel (mh->reset_task); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)); - GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map); - GNUNET_free (mh); + GNUNET_SCHEDULER_cancel(mh->reset_task); + GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)); + GNUNET_CONTAINER_multihashmap_destroy(mh->waiting_map); + GNUNET_free(mh); } @@ -429,16 +424,16 @@ disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) * this value will be negative.. */ static void -window_change_cb (void *cls, - const struct GNUNET_CADET_Channel *channel, - int window_size) +window_change_cb(void *cls, + const struct GNUNET_CADET_Channel *channel, + int window_size) { /* FIXME: for flow control, implement? */ #if 0 /* Something like this instead of the GNUNET_MQ_notify_sent() in transmit_pending() might be good (once the window change CB works...) */ if (0 < window_size) /* test needed? */ - transmit_pending (mh); + transmit_pending(mh); #endif } @@ -449,38 +444,38 @@ window_change_cb (void *cls, * @param mh cadet to reset */ static void -reset_cadet (struct CadetHandle *mh) +reset_cadet(struct CadetHandle *mh) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resetting cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Resetting cadet channel to %s\n", + GNUNET_i2s(&mh->target)); if (NULL != mh->channel) - { - GNUNET_CADET_channel_destroy (mh->channel); - mh->channel = NULL; - } - GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, &move_to_pending, mh); + { + GNUNET_CADET_channel_destroy(mh->channel); + mh->channel = NULL; + } + GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, &move_to_pending, mh); { struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (reply, - GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, - struct CadetReplyMessage, - mh), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(reply, + GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, + struct CadetReplyMessage, + mh), + GNUNET_MQ_handler_end() }; struct GNUNET_HashCode port; - GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, - strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), - &port); - mh->channel = GNUNET_CADET_channel_create (cadet_handle, - mh, - &mh->target, - &port, - &window_change_cb, - &disconnect_cb, - handlers); + GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, + strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), + &port); + mh->channel = GNUNET_CADET_channel_create(cadet_handle, + mh, + &mh->target, + &port, + &window_change_cb, + &disconnect_cb, + handlers); } - transmit_pending (mh); + transmit_pending(mh); } @@ -490,19 +485,19 @@ reset_cadet (struct CadetHandle *mh) * @param cls the `struct CadetHandle` to tear down */ static void -cadet_timeout (void *cls) +cadet_timeout(void *cls) { struct CadetHandle *mh = cls; struct GNUNET_CADET_Channel *tun; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout on cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout on cadet channel to %s\n", + GNUNET_i2s(&mh->target)); mh->timeout_task = NULL; tun = mh->channel; mh->channel = NULL; if (NULL != tun) - GNUNET_CADET_channel_destroy (tun); + GNUNET_CADET_channel_destroy(tun); } @@ -512,12 +507,12 @@ cadet_timeout (void *cls) * @param cls the `struct CadetHandle` to tear down */ static void -reset_cadet_task (void *cls) +reset_cadet_task(void *cls) { struct CadetHandle *mh = cls; mh->reset_task = NULL; - reset_cadet (mh); + reset_cadet(mh); } @@ -527,36 +522,36 @@ reset_cadet_task (void *cls) * @param cls `struct CadetHandle` to process */ static void -transmit_pending (void *cls) +transmit_pending(void *cls) { struct CadetHandle *mh = cls; - struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (mh->channel); + struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq(mh->channel); struct GSF_CadetRequest *sr; struct GNUNET_MQ_Envelope *env; struct CadetQueryMessage *sqm; - if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head))) + if ((0 != GNUNET_MQ_get_length(mq)) || (NULL == (sr = mh->pending_head))) return; - GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( - mh->waiting_map, - &sr->query, - sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); + GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( + mh->waiting_map, + &sr->query, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); sr->was_transmitted = GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending query for %s via cadet to %s\n", - GNUNET_h2s (&sr->query), - GNUNET_i2s (&mh->target)); - env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); - GNUNET_MQ_env_set_options (env, - GNUNET_MQ_PREF_GOODPUT | - GNUNET_MQ_PREF_CORK_ALLOWED | - GNUNET_MQ_PREF_OUT_OF_ORDER); - sqm->type = htonl (sr->type); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending query for %s via cadet to %s\n", + GNUNET_h2s(&sr->query), + GNUNET_i2s(&mh->target)); + env = GNUNET_MQ_msg(sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); + GNUNET_MQ_env_set_options(env, + GNUNET_MQ_PREF_GOODPUT | + GNUNET_MQ_PREF_CORK_ALLOWED | + GNUNET_MQ_PREF_OUT_OF_ORDER); + sqm->type = htonl(sr->type); sqm->query = sr->query; - GNUNET_MQ_notify_sent (env, &transmit_pending, mh); - GNUNET_MQ_send (mq, env); + GNUNET_MQ_notify_sent(env, &transmit_pending, mh); + GNUNET_MQ_send(mq, env); } @@ -566,53 +561,53 @@ transmit_pending (void *cls) * @param target peer we want to communicate with */ static struct CadetHandle * -get_cadet (const struct GNUNET_PeerIdentity *target) +get_cadet(const struct GNUNET_PeerIdentity *target) { struct CadetHandle *mh; - mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target); + mh = GNUNET_CONTAINER_multipeermap_get(cadet_map, target); if (NULL != mh) - { - if (NULL != mh->timeout_task) { - GNUNET_SCHEDULER_cancel (mh->timeout_task); - mh->timeout_task = NULL; + if (NULL != mh->timeout_task) + { + GNUNET_SCHEDULER_cancel(mh->timeout_task); + mh->timeout_task = NULL; + } + return mh; } - return mh; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating cadet channel to %s\n", - GNUNET_i2s (target)); - mh = GNUNET_new (struct CadetHandle); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating cadet channel to %s\n", + GNUNET_i2s(target)); + mh = GNUNET_new(struct CadetHandle); mh->reset_task = - GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); - mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); + GNUNET_SCHEDULER_add_delayed(CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); + mh->waiting_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); mh->target = *target; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put ( - cadet_map, - &mh->target, - mh, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put( + cadet_map, + &mh->target, + mh, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); { struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (reply, - GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, - struct CadetReplyMessage, - mh), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(reply, + GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, + struct CadetReplyMessage, + mh), + GNUNET_MQ_handler_end() }; struct GNUNET_HashCode port; - GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, - strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), - &port); - mh->channel = GNUNET_CADET_channel_create (cadet_handle, - mh, - &mh->target, - &port, - &window_change_cb, - &disconnect_cb, - handlers); + GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, + strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), + &port); + mh->channel = GNUNET_CADET_channel_create(cadet_handle, + mh, + &mh->target, + &port, + &window_change_cb, + &disconnect_cb, + handlers); } return mh; } @@ -629,28 +624,28 @@ get_cadet (const struct GNUNET_PeerIdentity *target) * @return handle to cancel the operation */ struct GSF_CadetRequest * -GSF_cadet_query (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_HashCode *query, - enum GNUNET_BLOCK_Type type, - GSF_CadetReplyProcessor proc, - void *proc_cls) +GSF_cadet_query(const struct GNUNET_PeerIdentity *target, + const struct GNUNET_HashCode *query, + enum GNUNET_BLOCK_Type type, + GSF_CadetReplyProcessor proc, + void *proc_cls) { struct CadetHandle *mh; struct GSF_CadetRequest *sr; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing to send query for %s via cadet to %s\n", - GNUNET_h2s (query), - GNUNET_i2s (target)); - mh = get_cadet (target); - sr = GNUNET_new (struct GSF_CadetRequest); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Preparing to send query for %s via cadet to %s\n", + GNUNET_h2s(query), + GNUNET_i2s(target)); + mh = get_cadet(target); + sr = GNUNET_new(struct GSF_CadetRequest); sr->mh = mh; sr->proc = proc; sr->proc_cls = proc_cls; sr->type = type; sr->query = *query; - GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); - transmit_pending (mh); + GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); + transmit_pending(mh); return sr; } @@ -662,7 +657,7 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target, * @param sr request to cancel */ void -GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) +GSF_cadet_query_cancel(struct GSF_CadetRequest *sr) { struct CadetHandle *mh = sr->mh; GSF_CadetReplyProcessor p; @@ -670,26 +665,26 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) p = sr->proc; sr->proc = NULL; if (NULL != p) - { - /* signal failure / cancellation to callback */ - p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cancelled query for %s via cadet to %s\n", - GNUNET_h2s (&sr->query), - GNUNET_i2s (&sr->mh->target)); + { + /* signal failure / cancellation to callback */ + p(sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Cancelled query for %s via cadet to %s\n", + GNUNET_h2s(&sr->query), + GNUNET_i2s(&sr->mh->target)); if (GNUNET_YES == sr->was_transmitted) - GNUNET_assert ( + GNUNET_assert( GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr)); + GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, &sr->query, sr)); else - GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); - GNUNET_free (sr); - if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && + GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); + GNUNET_free(sr); + if ((0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)) && (NULL == mh->pending_head)) - mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &cadet_timeout, - mh); + mh->timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &cadet_timeout, + mh); } @@ -702,27 +697,27 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) * @return #GNUNET_YES (continue to iterate) */ int -GSF_cadet_release_clients (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +GSF_cadet_release_clients(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct CadetHandle *mh = value; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout on cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout on cadet channel to %s\n", + GNUNET_i2s(&mh->target)); if (NULL != mh->channel) - { - struct GNUNET_CADET_Channel *channel = mh->channel; + { + struct GNUNET_CADET_Channel *channel = mh->channel; - mh->channel = NULL; - GNUNET_CADET_channel_destroy (channel); - } + mh->channel = NULL; + GNUNET_CADET_channel_destroy(channel); + } if (NULL != mh->reset_task) - { - GNUNET_SCHEDULER_cancel (mh->reset_task); - mh->reset_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(mh->reset_task); + mh->reset_task = NULL; + } return GNUNET_YES; } diff --git a/src/fs/gnunet-service-fs_cadet_server.c b/src/fs/gnunet-service-fs_cadet_server.c index bb320806a..68e87f092 100644 --- a/src/fs/gnunet-service-fs_cadet_server.c +++ b/src/fs/gnunet-service-fs_cadet_server.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_cadet_server.c @@ -40,14 +40,13 @@ /** * After how long do we termiante idle connections? */ -#define IDLE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) +#define IDLE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) /** * A message in the queue to be written to the cadet. */ -struct WriteQueueItem -{ +struct WriteQueueItem { /** * Kept in a DLL. */ @@ -68,8 +67,7 @@ struct WriteQueueItem /** * Information we keep around for each active cadeting client. */ -struct CadetClient -{ +struct CadetClient { /** * DLL */ @@ -114,7 +112,6 @@ struct CadetClient * Size of the last write that was initiated. */ size_t reply_size; - }; @@ -151,7 +148,7 @@ static unsigned long long sc_count_max; * @param cls the 'struct CadetClient' */ static void -timeout_cadet_task (void *cls) +timeout_cadet_task(void *cls) { struct CadetClient *sc = cls; struct GNUNET_CADET_Channel *tun; @@ -159,10 +156,10 @@ timeout_cadet_task (void *cls) sc->timeout_task = NULL; tun = sc->channel; sc->channel = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout for inactive cadet client %p\n", - sc); - GNUNET_CADET_channel_destroy (tun); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout for inactive cadet client %p\n", + sc); + GNUNET_CADET_channel_destroy(tun); } @@ -172,13 +169,13 @@ timeout_cadet_task (void *cls) * @param sc client handle to reset timeout for */ static void -refresh_timeout_task (struct CadetClient *sc) +refresh_timeout_task(struct CadetClient *sc) { if (NULL != sc->timeout_task) - GNUNET_SCHEDULER_cancel (sc->timeout_task); - sc->timeout_task = GNUNET_SCHEDULER_add_delayed (IDLE_TIMEOUT, - &timeout_cadet_task, - sc); + GNUNET_SCHEDULER_cancel(sc->timeout_task); + sc->timeout_task = GNUNET_SCHEDULER_add_delayed(IDLE_TIMEOUT, + &timeout_cadet_task, + sc); } @@ -189,23 +186,23 @@ refresh_timeout_task (struct CadetClient *sc) * @param cls where to process the write queue */ static void -continue_writing (void *cls) +continue_writing(void *cls) { struct CadetClient *sc = cls; struct GNUNET_MQ_Handle *mq; - mq = GNUNET_CADET_get_mq (sc->channel); - if (0 != GNUNET_MQ_get_length (mq)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Write pending, waiting for it to complete\n"); - return; - } - refresh_timeout_task (sc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished processing cadet request from client %p, ready to receive the next one\n", - sc); - GNUNET_CADET_receive_done (sc->channel); + mq = GNUNET_CADET_get_mq(sc->channel); + if (0 != GNUNET_MQ_get_length(mq)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Write pending, waiting for it to complete\n"); + return; + } + refresh_timeout_task(sc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished processing cadet request from client %p, ready to receive the next one\n", + sc); + GNUNET_CADET_receive_done(sc->channel); } @@ -225,103 +222,103 @@ continue_writing (void *cls) * maybe 0 if no unique identifier is available */ static void -handle_datastore_reply (void *cls, - const struct GNUNET_HashCode *key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid) +handle_datastore_reply(void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid) { struct CadetClient *sc = cls; - size_t msize = size + sizeof (struct CadetReplyMessage); + size_t msize = size + sizeof(struct CadetReplyMessage); struct GNUNET_MQ_Envelope *env; struct CadetReplyMessage *srm; sc->qe = NULL; if (NULL == data) - { - /* no result, this should not really happen, as for - non-anonymous routing only peers that HAVE the - answers should be queried; OTOH, this is not a - hard error as we might have had the answer in the - past and the user might have unindexed it. Hence - we log at level "INFO" for now. */ - if (NULL == key) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Have no answer and the query was NULL\n"); - } - else { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Have no answer for query `%s'\n", - GNUNET_h2s (key)); + /* no result, this should not really happen, as for + non-anonymous routing only peers that HAVE the + answers should be queried; OTOH, this is not a + hard error as we might have had the answer in the + past and the user might have unindexed it. Hence + we log at level "INFO" for now. */ + if (NULL == key) + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Have no answer and the query was NULL\n"); + } + else + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Have no answer for query `%s'\n", + GNUNET_h2s(key)); + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# queries received via CADET not answered"), + 1, + GNUNET_NO); + continue_writing(sc); + return; } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# queries received via CADET not answered"), - 1, - GNUNET_NO); - continue_writing (sc); - return; - } if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Performing on-demand encoding for query %s\n", - GNUNET_h2s (key)); - if (GNUNET_OK != - GNUNET_FS_handle_on_demand_block (key, - size, - data, - type, - priority, - anonymity, - replication, - expiration, - uid, - &handle_datastore_reply, - sc)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "On-demand encoding request failed\n"); - continue_writing (sc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Performing on-demand encoding for query %s\n", + GNUNET_h2s(key)); + if (GNUNET_OK != + GNUNET_FS_handle_on_demand_block(key, + size, + data, + type, + priority, + anonymity, + replication, + expiration, + uid, + &handle_datastore_reply, + sc)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "On-demand encoding request failed\n"); + continue_writing(sc); + } + return; } - return; - } if (msize > GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - continue_writing (sc); - return; - } - GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", - (unsigned int) size, - (unsigned int) type, - GNUNET_h2s (key), - sc); - env = GNUNET_MQ_msg_extra (srm, - size, - GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); - srm->type = htonl (type); - srm->expiration = GNUNET_TIME_absolute_hton (expiration); - GNUNET_memcpy (&srm[1], - data, - size); - GNUNET_MQ_notify_sent (env, - &continue_writing, - sc); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Blocks transferred via cadet"), - 1, - GNUNET_NO); - GNUNET_MQ_send (GNUNET_CADET_get_mq (sc->channel), - env); + { + GNUNET_break(0); + continue_writing(sc); + return; + } + GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", + (unsigned int)size, + (unsigned int)type, + GNUNET_h2s(key), + sc); + env = GNUNET_MQ_msg_extra(srm, + size, + GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); + srm->type = htonl(type); + srm->expiration = GNUNET_TIME_absolute_hton(expiration); + GNUNET_memcpy(&srm[1], + data, + size); + GNUNET_MQ_notify_sent(env, + &continue_writing, + sc); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Blocks transferred via cadet"), + 1, + GNUNET_NO); + GNUNET_MQ_send(GNUNET_CADET_get_mq(sc->channel), + env); } @@ -333,35 +330,35 @@ handle_datastore_reply (void *cls, * @param sqm the actual message */ static void -handle_request (void *cls, - const struct CadetQueryMessage *sqm) +handle_request(void *cls, + const struct CadetQueryMessage *sqm) { struct CadetClient *sc = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received query for `%s' via cadet from client %p\n", - GNUNET_h2s (&sqm->query), - sc); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# queries received via cadet"), - 1, - GNUNET_NO); - refresh_timeout_task (sc); - sc->qe = GNUNET_DATASTORE_get_key (GSF_dsh, - 0 /* next_uid */, - false /* random */, - &sqm->query, - ntohl (sqm->type), - 0 /* priority */, - GSF_datastore_queue_size, - &handle_datastore_reply, - sc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received query for `%s' via cadet from client %p\n", + GNUNET_h2s(&sqm->query), + sc); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# queries received via cadet"), + 1, + GNUNET_NO); + refresh_timeout_task(sc); + sc->qe = GNUNET_DATASTORE_get_key(GSF_dsh, + 0 /* next_uid */, + false /* random */, + &sqm->query, + ntohl(sqm->type), + 0 /* priority */, + GSF_datastore_queue_size, + &handle_datastore_reply, + sc); if (NULL == sc->qe) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing request with datastore failed (queue full?)\n"); - continue_writing (sc); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Queueing request with datastore failed (queue full?)\n"); + continue_writing(sc); + } } @@ -375,37 +372,37 @@ handle_request (void *cls, * @return initial channel context (our `struct CadetClient`) */ static void * -connect_cb (void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator) +connect_cb(void *cls, + struct GNUNET_CADET_Channel *channel, + const struct GNUNET_PeerIdentity *initiator) { struct CadetClient *sc; - GNUNET_assert (NULL != channel); + GNUNET_assert(NULL != channel); if (sc_count >= sc_count_max) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# cadet client connections rejected"), - 1, - GNUNET_NO); - GNUNET_CADET_channel_destroy (channel); - return NULL; - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# cadet connections active"), - 1, - GNUNET_NO); - sc = GNUNET_new (struct CadetClient); + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# cadet client connections rejected"), + 1, + GNUNET_NO); + GNUNET_CADET_channel_destroy(channel); + return NULL; + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# cadet connections active"), + 1, + GNUNET_NO); + sc = GNUNET_new(struct CadetClient); sc->channel = channel; - GNUNET_CONTAINER_DLL_insert (sc_head, - sc_tail, - sc); + GNUNET_CONTAINER_DLL_insert(sc_head, + sc_tail, + sc); sc_count++; - refresh_timeout_task (sc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Accepting inbound cadet connection from `%s' as client %p\n", - GNUNET_i2s (initiator), - sc); + refresh_timeout_task(sc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Accepting inbound cadet connection from `%s' as client %p\n", + GNUNET_i2s(initiator), + sc); return sc; } @@ -419,8 +416,8 @@ connect_cb (void *cls, * @param channel_ctx */ static void -disconnect_cb (void *cls, - const struct GNUNET_CADET_Channel *channel) +disconnect_cb(void *cls, + const struct GNUNET_CADET_Channel *channel) { struct CadetClient *sc = cls; struct WriteQueueItem *wqi; @@ -428,30 +425,30 @@ disconnect_cb (void *cls, if (NULL == sc) return; sc->channel = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Terminating cadet connection with client %p\n", - sc); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# cadet connections active"), -1, - GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Terminating cadet connection with client %p\n", + sc); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# cadet connections active"), -1, + GNUNET_NO); if (NULL != sc->terminate_task) - GNUNET_SCHEDULER_cancel (sc->terminate_task); + GNUNET_SCHEDULER_cancel(sc->terminate_task); if (NULL != sc->timeout_task) - GNUNET_SCHEDULER_cancel (sc->timeout_task); + GNUNET_SCHEDULER_cancel(sc->timeout_task); if (NULL != sc->qe) - GNUNET_DATASTORE_cancel (sc->qe); + GNUNET_DATASTORE_cancel(sc->qe); while (NULL != (wqi = sc->wqi_head)) - { - GNUNET_CONTAINER_DLL_remove (sc->wqi_head, - sc->wqi_tail, - wqi); - GNUNET_free (wqi); - } - GNUNET_CONTAINER_DLL_remove (sc_head, - sc_tail, - sc); + { + GNUNET_CONTAINER_DLL_remove(sc->wqi_head, + sc->wqi_tail, + wqi); + GNUNET_free(wqi); + } + GNUNET_CONTAINER_DLL_remove(sc_head, + sc_tail, + sc); sc_count--; - GNUNET_free (sc); + GNUNET_free(sc); } @@ -470,9 +467,9 @@ disconnect_cb (void *cls, * this value will be negative.. */ static void -window_change_cb (void *cls, - const struct GNUNET_CADET_Channel *channel, - int window_size) +window_change_cb(void *cls, + const struct GNUNET_CADET_Channel *channel, + int window_size) { /* FIXME: could do flow control here... */ } @@ -482,39 +479,39 @@ window_change_cb (void *cls, * Initialize subsystem for non-anonymous file-sharing. */ void -GSF_cadet_start_server () +GSF_cadet_start_server() { struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (request, - GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, - struct CadetQueryMessage, - NULL), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(request, + GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, + struct CadetQueryMessage, + NULL), + GNUNET_MQ_handler_end() }; struct GNUNET_HashCode port; if (GNUNET_YES != - GNUNET_CONFIGURATION_get_value_number (GSF_cfg, - "fs", - "MAX_CADET_CLIENTS", - &sc_count_max)) + GNUNET_CONFIGURATION_get_value_number(GSF_cfg, + "fs", + "MAX_CADET_CLIENTS", + &sc_count_max)) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Initializing cadet FS server with a limit of %llu connections\n", - sc_count_max); - cadet_map = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); - cadet_handle = GNUNET_CADET_connect (GSF_cfg); - GNUNET_assert (NULL != cadet_handle); - GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, - strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), - &port); - cadet_port = GNUNET_CADET_open_port (cadet_handle, - &port, - &connect_cb, - NULL, - &window_change_cb, - &disconnect_cb, - handlers); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Initializing cadet FS server with a limit of %llu connections\n", + sc_count_max); + cadet_map = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); + cadet_handle = GNUNET_CADET_connect(GSF_cfg); + GNUNET_assert(NULL != cadet_handle); + GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, + strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), + &port); + cadet_port = GNUNET_CADET_open_port(cadet_handle, + &port, + &connect_cb, + NULL, + &window_change_cb, + &disconnect_cb, + handlers); } @@ -522,25 +519,25 @@ GSF_cadet_start_server () * Shutdown subsystem for non-anonymous file-sharing. */ void -GSF_cadet_stop_server () +GSF_cadet_stop_server() { - GNUNET_CONTAINER_multipeermap_iterate (cadet_map, - &GSF_cadet_release_clients, - NULL); - GNUNET_CONTAINER_multipeermap_destroy (cadet_map); + GNUNET_CONTAINER_multipeermap_iterate(cadet_map, + &GSF_cadet_release_clients, + NULL); + GNUNET_CONTAINER_multipeermap_destroy(cadet_map); cadet_map = NULL; if (NULL != cadet_port) - { - GNUNET_CADET_close_port (cadet_port); - cadet_port = NULL; - } + { + GNUNET_CADET_close_port(cadet_port); + cadet_port = NULL; + } if (NULL != cadet_handle) - { - GNUNET_CADET_disconnect (cadet_handle); - cadet_handle = NULL; - } - GNUNET_assert (NULL == sc_head); - GNUNET_assert (0 == sc_count); + { + GNUNET_CADET_disconnect(cadet_handle); + cadet_handle = NULL; + } + GNUNET_assert(NULL == sc_head); + GNUNET_assert(0 == sc_count); } /* end of gnunet-service-fs_cadet.c */ diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index a3a521221..6dab37869 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_cp.c * @brief API to handle 'connected peers' @@ -43,12 +43,12 @@ /** * How often do we flush respect values to disk? */ -#define RESPECT_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) +#define RESPECT_FLUSH_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) /** * After how long do we discard a reply? */ -#define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) +#define REPLY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) /** * Collect an instane number of statistics? May cause excessive IPC. @@ -59,9 +59,7 @@ /** * Handle to cancel a transmission request. */ -struct GSF_PeerTransmitHandle -{ - +struct GSF_PeerTransmitHandle { /** * Kept in a doubly-linked list. */ @@ -101,16 +99,13 @@ struct GSF_PeerTransmitHandle * Priority of this request. */ uint32_t priority; - }; /** * Handle for an entry in our delay list. */ -struct GSF_DelayedHandle -{ - +struct GSF_DelayedHandle { /** * Kept in a doubly-linked list. */ @@ -140,16 +135,13 @@ struct GSF_DelayedHandle * Size of the message. */ size_t msize; - }; /** * Information per peer and request. */ -struct PeerRequest -{ - +struct PeerRequest { /** * Handle to generic request (generic: from peer or local client). */ @@ -164,16 +156,13 @@ struct PeerRequest * Task for asynchronous stopping of this request. */ struct GNUNET_SCHEDULER_Task *kill_task; - }; /** * A connected peer. */ -struct GSF_ConnectedPeer -{ - +struct GSF_ConnectedPeer { /** * Performance data for this peer. */ @@ -278,7 +267,6 @@ struct GSF_ConnectedPeer * Handle to the PEERSTORE iterate request for peer respect value */ struct GNUNET_PEERSTORE_IterateContext *respect_iterate_req; - }; @@ -305,16 +293,16 @@ static struct GNUNET_SCHEDULER_Task *fr_task; * @param latency current latency value */ void -GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, - struct GNUNET_TIME_Relative latency) +GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, + struct GNUNET_TIME_Relative latency) { struct GSF_ConnectedPeer *cp; - cp = GSF_peer_get_ (id); + cp = GSF_peer_get_(id); if (NULL == cp) return; /* we're not yet connected at the core level, ignore */ - GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, - latency); + GNUNET_LOAD_value_set_decline(cp->ppd.transmission_delay, + latency); } @@ -325,7 +313,7 @@ GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, * @return performance data record for the peer */ struct GSF_PeerPerformanceData * -GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) +GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp) { return &cp->ppd; } @@ -337,7 +325,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) * @param cp which peer to send a message to */ static void -peer_transmit (struct GSF_ConnectedPeer *cp); +peer_transmit(struct GSF_ConnectedPeer *cp); /** @@ -351,10 +339,10 @@ peer_transmit (struct GSF_ConnectedPeer *cp); * long should the client wait until re-trying? */ static void -ats_reserve_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, - struct GNUNET_TIME_Relative res_delay); +ats_reserve_callback(void *cls, + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + struct GNUNET_TIME_Relative res_delay); /** @@ -364,42 +352,42 @@ ats_reserve_callback (void *cls, * @param pth transmission handle to schedule */ static void -schedule_transmission (struct GSF_PeerTransmitHandle *pth) +schedule_transmission(struct GSF_PeerTransmitHandle *pth) { struct GSF_ConnectedPeer *cp; struct GNUNET_PeerIdentity target; cp = pth->cp; - GNUNET_assert (0 != cp->ppd.pid); - GNUNET_PEER_resolve (cp->ppd.pid, &target); + GNUNET_assert(0 != cp->ppd.pid); + GNUNET_PEER_resolve(cp->ppd.pid, &target); if (0 != cp->inc_preference) - { - GNUNET_ATS_performance_change_preference (GSF_ats, - &target, - GNUNET_ATS_PREFERENCE_BANDWIDTH, - (double) cp->inc_preference, - GNUNET_ATS_PREFERENCE_END); - cp->inc_preference = 0; - } - - if ( (GNUNET_YES == pth->is_query) && - (GNUNET_YES != pth->was_reserved) ) - { - /* query, need reservation */ - if (GNUNET_YES != cp->did_reserve) - return; /* not ready */ - cp->did_reserve = GNUNET_NO; - /* reservation already done! */ - pth->was_reserved = GNUNET_YES; - cp->rc = GNUNET_ATS_reserve_bandwidth (GSF_ats, - &target, - DBLOCK_SIZE, - &ats_reserve_callback, - cp); - return; - } - peer_transmit (cp); + { + GNUNET_ATS_performance_change_preference(GSF_ats, + &target, + GNUNET_ATS_PREFERENCE_BANDWIDTH, + (double)cp->inc_preference, + GNUNET_ATS_PREFERENCE_END); + cp->inc_preference = 0; + } + + if ((GNUNET_YES == pth->is_query) && + (GNUNET_YES != pth->was_reserved)) + { + /* query, need reservation */ + if (GNUNET_YES != cp->did_reserve) + return; /* not ready */ + cp->did_reserve = GNUNET_NO; + /* reservation already done! */ + pth->was_reserved = GNUNET_YES; + cp->rc = GNUNET_ATS_reserve_bandwidth(GSF_ats, + &target, + DBLOCK_SIZE, + &ats_reserve_callback, + cp); + return; + } + peer_transmit(cp); } @@ -409,38 +397,38 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) * @param cp which peer to send a message to */ static void -peer_transmit (struct GSF_ConnectedPeer *cp) +peer_transmit(struct GSF_ConnectedPeer *cp) { struct GSF_PeerTransmitHandle *pth = cp->pth_head; struct GSF_PeerTransmitHandle *pos; if (NULL == pth) return; - GNUNET_CONTAINER_DLL_remove (cp->pth_head, - cp->pth_tail, - pth); + GNUNET_CONTAINER_DLL_remove(cp->pth_head, + cp->pth_tail, + pth); if (GNUNET_YES == pth->is_query) - { - cp->ppd.last_request_times[(cp->last_request_times_off++) % - MAX_QUEUE_PER_PEER] = - GNUNET_TIME_absolute_get (); - GNUNET_assert (0 < cp->ppd.pending_queries--); - } + { + cp->ppd.last_request_times[(cp->last_request_times_off++) % + MAX_QUEUE_PER_PEER] = + GNUNET_TIME_absolute_get(); + GNUNET_assert(0 < cp->ppd.pending_queries--); + } else if (GNUNET_NO == pth->is_query) - { - GNUNET_assert (0 < cp->ppd.pending_replies--); - } - GNUNET_LOAD_update (cp->ppd.transmission_delay, - GNUNET_TIME_absolute_get_duration - (pth->transmission_request_start_time).rel_value_us); - GNUNET_MQ_send (cp->mq, - pth->env); - GNUNET_free (pth); + { + GNUNET_assert(0 < cp->ppd.pending_replies--); + } + GNUNET_LOAD_update(cp->ppd.transmission_delay, + GNUNET_TIME_absolute_get_duration + (pth->transmission_request_start_time).rel_value_us); + GNUNET_MQ_send(cp->mq, + pth->env); + GNUNET_free(pth); if (NULL != (pos = cp->pth_head)) - { - GNUNET_assert (pos != pth); - schedule_transmission (pos); - } + { + GNUNET_assert(pos != pth); + schedule_transmission(pos); + } } @@ -450,18 +438,18 @@ peer_transmit (struct GSF_ConnectedPeer *cp) * @param cls the `struct GSF_ConnectedPeer` to reserve from */ static void -retry_reservation (void *cls) +retry_reservation(void *cls) { struct GSF_ConnectedPeer *cp = cls; struct GNUNET_PeerIdentity target; - GNUNET_PEER_resolve (cp->ppd.pid, &target); + GNUNET_PEER_resolve(cp->ppd.pid, &target); cp->rc_delay_task = NULL; cp->rc = - GNUNET_ATS_reserve_bandwidth (GSF_ats, - &target, - DBLOCK_SIZE, - &ats_reserve_callback, cp); + GNUNET_ATS_reserve_bandwidth(GSF_ats, + &target, + DBLOCK_SIZE, + &ats_reserve_callback, cp); } @@ -476,34 +464,34 @@ retry_reservation (void *cls) * long should the client wait until re-trying? */ static void -ats_reserve_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, - struct GNUNET_TIME_Relative res_delay) +ats_reserve_callback(void *cls, + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + struct GNUNET_TIME_Relative res_delay) { struct GSF_ConnectedPeer *cp = cls; struct GSF_PeerTransmitHandle *pth; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reserved %d bytes / need to wait %s for reservation\n", - (int) amount, - GNUNET_STRINGS_relative_time_to_string (res_delay, GNUNET_YES)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Reserved %d bytes / need to wait %s for reservation\n", + (int)amount, + GNUNET_STRINGS_relative_time_to_string(res_delay, GNUNET_YES)); cp->rc = NULL; if (0 == amount) - { - cp->rc_delay_task = - GNUNET_SCHEDULER_add_delayed (res_delay, - &retry_reservation, - cp); - return; - } + { + cp->rc_delay_task = + GNUNET_SCHEDULER_add_delayed(res_delay, + &retry_reservation, + cp); + return; + } cp->did_reserve = GNUNET_YES; pth = cp->pth_head; if (NULL != pth) - { - /* reservation success, try transmission now! */ - peer_transmit (cp); - } + { + /* reservation success, try transmission now! */ + peer_transmit(cp); + } } @@ -515,22 +503,22 @@ ats_reserve_callback (void *cls, * @param emsg error message, or NULL if no errors */ static void -peer_respect_cb (void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +peer_respect_cb(void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct GSF_ConnectedPeer *cp = cls; - GNUNET_assert (NULL != cp->respect_iterate_req); - if ( (NULL != record) && - (sizeof (cp->disk_respect) == record->value_size)) - { - cp->disk_respect = *((uint32_t *)record->value); - cp->ppd.respect += *((uint32_t *)record->value); - } - GSF_push_start_ (cp); + GNUNET_assert(NULL != cp->respect_iterate_req); + if ((NULL != record) && + (sizeof(cp->disk_respect) == record->value_size)) + { + cp->disk_respect = *((uint32_t *)record->value); + cp->ppd.respect += *((uint32_t *)record->value); + } + GSF_push_start_(cp); if (NULL != record) - GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); + GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); cp->respect_iterate_req = NULL; } @@ -546,27 +534,27 @@ peer_respect_cb (void *cls, * @return #GNUNET_YES to continue to iterate */ static int -consider_peer_for_forwarding (void *cls, - const struct GNUNET_HashCode *key, - struct GSF_PendingRequest *pr) +consider_peer_for_forwarding(void *cls, + const struct GNUNET_HashCode *key, + struct GSF_PendingRequest *pr) { struct GSF_ConnectedPeer *cp = cls; struct GNUNET_PeerIdentity pid; if (GNUNET_YES != - GSF_pending_request_test_active_ (pr)) + GSF_pending_request_test_active_(pr)) return GNUNET_YES; /* request is not actually active, skip! */ - GSF_connected_peer_get_identity_ (cp, &pid); + GSF_connected_peer_get_identity_(cp, &pid); if (GNUNET_YES != - GSF_pending_request_test_target_ (pr, &pid)) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Loopback routes suppressed"), - 1, - GNUNET_NO); - return GNUNET_YES; - } - GSF_plan_add_ (cp, pr); + GSF_pending_request_test_target_(pr, &pid)) + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Loopback routes suppressed"), + 1, + GNUNET_NO); + return GNUNET_YES; + } + GSF_plan_add_(cp, pr); return GNUNET_YES; } @@ -581,49 +569,49 @@ consider_peer_for_forwarding (void *cls, * @return our internal handle for the peer */ void * -GSF_peer_connect_handler (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +GSF_peer_connect_handler(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct GSF_ConnectedPeer *cp; if (0 == - GNUNET_memcmp (&GSF_my_id, - peer)) + GNUNET_memcmp(&GSF_my_id, + peer)) return NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connected to peer %s\n", - GNUNET_i2s (peer)); - cp = GNUNET_new (struct GSF_ConnectedPeer); - cp->ppd.pid = GNUNET_PEER_intern (peer); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Connected to peer %s\n", + GNUNET_i2s(peer)); + cp = GNUNET_new(struct GSF_ConnectedPeer); + cp->ppd.pid = GNUNET_PEER_intern(peer); cp->ppd.peer = peer; cp->mq = mq; - cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); + cp->ppd.transmission_delay = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_ZERO); cp->rc = - GNUNET_ATS_reserve_bandwidth (GSF_ats, - peer, - DBLOCK_SIZE, - &ats_reserve_callback, cp); - cp->request_map = GNUNET_CONTAINER_multihashmap_create (128, - GNUNET_YES); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (cp_map, - GSF_connected_peer_get_identity2_ (cp), - cp, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# peers connected"), - GNUNET_CONTAINER_multipeermap_size (cp_map), - GNUNET_NO); - cp->respect_iterate_req - = GNUNET_PEERSTORE_iterate (peerstore, - "fs", - peer, - "respect", - &peer_respect_cb, + GNUNET_ATS_reserve_bandwidth(GSF_ats, + peer, + DBLOCK_SIZE, + &ats_reserve_callback, cp); + cp->request_map = GNUNET_CONTAINER_multihashmap_create(128, + GNUNET_YES); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put(cp_map, + GSF_connected_peer_get_identity2_(cp), + cp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# peers connected"), + GNUNET_CONTAINER_multipeermap_size(cp_map), + GNUNET_NO); + cp->respect_iterate_req + = GNUNET_PEERSTORE_iterate(peerstore, + "fs", + peer, + "respect", + &peer_respect_cb, + cp); + GSF_iterate_pending_requests_(&consider_peer_for_forwarding, cp); - GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, - cp); return cp; } @@ -635,21 +623,21 @@ GSF_peer_connect_handler (void *cls, * @param cls the `struct GSF_ConnectedPeer` */ static void -revive_migration (void *cls) +revive_migration(void *cls) { struct GSF_ConnectedPeer *cp = cls; struct GNUNET_TIME_Relative bt; cp->mig_revive_task = NULL; - bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); + bt = GNUNET_TIME_absolute_get_remaining(cp->ppd.migration_blocked_until); if (0 != bt.rel_value_us) - { - /* still time left... */ - cp->mig_revive_task = - GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); - return; - } - GSF_push_start_ (cp); + { + /* still time left... */ + cp->mig_revive_task = + GNUNET_SCHEDULER_add_delayed(bt, &revive_migration, cp); + return; + } + GSF_push_start_(cp); } @@ -660,44 +648,44 @@ revive_migration (void *cls) * @return NULL if the peer is not currently connected */ struct GSF_ConnectedPeer * -GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) +GSF_peer_get_(const struct GNUNET_PeerIdentity *peer) { if (NULL == cp_map) return NULL; - return GNUNET_CONTAINER_multipeermap_get (cp_map, peer); + return GNUNET_CONTAINER_multipeermap_get(cp_map, peer); } /** - * Handle P2P #GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message. + * Handle P2P #GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message. * * @param cls closure, the `struct GSF_ConnectedPeer` * @param msm the actual message */ void -handle_p2p_migration_stop (void *cls, - const struct MigrationStopMessage *msm) +handle_p2p_migration_stop(void *cls, + const struct MigrationStopMessage *msm) { struct GSF_ConnectedPeer *cp = cls; struct GNUNET_TIME_Relative bt; - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# migration stop messages received"), - 1, GNUNET_NO); - bt = GNUNET_TIME_relative_ntoh (msm->duration); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Migration of content to peer `%s' blocked for %s\n"), - GNUNET_i2s (cp->ppd.peer), - GNUNET_STRINGS_relative_time_to_string (bt, GNUNET_YES)); - cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); - if ( (NULL == cp->mig_revive_task) && - (NULL == cp->respect_iterate_req) ) - { - GSF_push_stop_ (cp); - cp->mig_revive_task = - GNUNET_SCHEDULER_add_delayed (bt, - &revive_migration, cp); - } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# migration stop messages received"), + 1, GNUNET_NO); + bt = GNUNET_TIME_relative_ntoh(msm->duration); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Migration of content to peer `%s' blocked for %s\n"), + GNUNET_i2s(cp->ppd.peer), + GNUNET_STRINGS_relative_time_to_string(bt, GNUNET_YES)); + cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute(bt); + if ((NULL == cp->mig_revive_task) && + (NULL == cp->respect_iterate_req)) + { + GSF_push_stop_(cp); + cp->mig_revive_task = + GNUNET_SCHEDULER_add_delayed(bt, + &revive_migration, cp); + } } @@ -707,26 +695,26 @@ handle_p2p_migration_stop (void *cls, * @param peerreq request to free */ static void -free_pending_request (struct PeerRequest *peerreq) +free_pending_request(struct PeerRequest *peerreq) { struct GSF_ConnectedPeer *cp = peerreq->cp; struct GSF_PendingRequestData *prd; - prd = GSF_pending_request_get_data_ (peerreq->pr); + prd = GSF_pending_request_get_data_(peerreq->pr); if (NULL != peerreq->kill_task) - { - GNUNET_SCHEDULER_cancel (peerreq->kill_task); - peerreq->kill_task = NULL; - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# P2P searches active"), - -1, - GNUNET_NO); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (cp->request_map, - &prd->query, - peerreq)); - GNUNET_free (peerreq); + { + GNUNET_SCHEDULER_cancel(peerreq->kill_task); + peerreq->kill_task = NULL; + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# P2P searches active"), + -1, + GNUNET_NO); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(cp->request_map, + &prd->query, + peerreq)); + GNUNET_free(peerreq); } @@ -739,16 +727,16 @@ free_pending_request (struct PeerRequest *peerreq) * @return #GNUNET_YES (continue to iterate) */ static int -cancel_pending_request (void *cls, - const struct GNUNET_HashCode *query, - void *value) +cancel_pending_request(void *cls, + const struct GNUNET_HashCode *query, + void *value) { struct PeerRequest *peerreq = value; struct GSF_PendingRequest *pr = peerreq->pr; - free_pending_request (peerreq); - GSF_pending_request_cancel_ (pr, - GNUNET_NO); + free_pending_request(peerreq); + GSF_pending_request_cancel_(pr, + GNUNET_NO); return GNUNET_OK; } @@ -759,17 +747,17 @@ cancel_pending_request (void *cls, * @param cls the request to free */ static void -peer_request_destroy (void *cls) +peer_request_destroy(void *cls) { struct PeerRequest *peerreq = cls; struct GSF_PendingRequest *pr = peerreq->pr; struct GSF_PendingRequestData *prd; peerreq->kill_task = NULL; - prd = GSF_pending_request_get_data_ (pr); - cancel_pending_request (NULL, - &prd->query, - peerreq); + prd = GSF_pending_request_get_data_(pr); + cancel_pending_request(NULL, + &prd->query, + peerreq); } @@ -779,20 +767,20 @@ peer_request_destroy (void *cls) * @param cls the `struct GSF_DelayedHandle` with the message */ static void -transmit_delayed_now (void *cls) +transmit_delayed_now(void *cls) { struct GSF_DelayedHandle *dh = cls; struct GSF_ConnectedPeer *cp = dh->cp; - GNUNET_CONTAINER_DLL_remove (cp->delayed_head, - cp->delayed_tail, - dh); + GNUNET_CONTAINER_DLL_remove(cp->delayed_head, + cp->delayed_tail, + dh); cp->delay_queue_size--; - GSF_peer_transmit_ (cp, - GNUNET_NO, - UINT32_MAX, - dh->env); - GNUNET_free (dh); + GSF_peer_transmit_(cp, + GNUNET_NO, + UINT32_MAX, + dh->env); + GNUNET_free(dh); } @@ -802,20 +790,20 @@ transmit_delayed_now (void *cls) * @return desired delay */ static struct GNUNET_TIME_Relative -get_randomized_delay () +get_randomized_delay() { struct GNUNET_TIME_Relative ret; ret = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - GNUNET_CRYPTO_random_u32 - (GNUNET_CRYPTO_QUALITY_WEAK, - 2 * GSF_avg_latency.rel_value_us + 1)); + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, + GNUNET_CRYPTO_random_u32 + (GNUNET_CRYPTO_QUALITY_WEAK, + 2 * GSF_avg_latency.rel_value_us + 1)); #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# artificial delays introduced (ms)"), - ret.rel_value_us / 1000LL, GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# artificial delays introduced (ms)"), + ret.rel_value_us / 1000LL, GNUNET_NO); #endif return ret; } @@ -840,15 +828,15 @@ get_randomized_delay () * @param data_len number of bytes in @a data */ static void -handle_p2p_reply (void *cls, - enum GNUNET_BLOCK_EvaluationResult eval, - struct GSF_PendingRequest *pr, - uint32_t reply_anonymity_level, - struct GNUNET_TIME_Absolute expiration, - struct GNUNET_TIME_Absolute last_transmission, - enum GNUNET_BLOCK_Type type, - const void *data, - size_t data_len) +handle_p2p_reply(void *cls, + enum GNUNET_BLOCK_EvaluationResult eval, + struct GSF_PendingRequest *pr, + uint32_t reply_anonymity_level, + struct GNUNET_TIME_Absolute expiration, + struct GNUNET_TIME_Absolute last_transmission, + enum GNUNET_BLOCK_Type type, + const void *data, + size_t data_len) { struct PeerRequest *peerreq = cls; struct GSF_ConnectedPeer *cp = peerreq->cp; @@ -857,96 +845,96 @@ handle_p2p_reply (void *cls, struct PutMessage *pm; size_t msize; - GNUNET_assert (data_len + sizeof (struct PutMessage) < - GNUNET_MAX_MESSAGE_SIZE); - GNUNET_assert (peerreq->pr == pr); - prd = GSF_pending_request_get_data_ (pr); + GNUNET_assert(data_len + sizeof(struct PutMessage) < + GNUNET_MAX_MESSAGE_SIZE); + GNUNET_assert(peerreq->pr == pr); + prd = GSF_pending_request_get_data_(pr); if (NULL == data) - { - free_pending_request (peerreq); - return; - } - GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); + { + free_pending_request(peerreq); + return; + } + GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type)) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# replies dropped due to type mismatch"), - 1, GNUNET_NO); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting result for query `%s' to peer\n", - GNUNET_h2s (&prd->query)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# replies received for other peers"), - 1, GNUNET_NO); - msize = sizeof (struct PutMessage) + data_len; + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# replies dropped due to type mismatch"), + 1, GNUNET_NO); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Transmitting result for query `%s' to peer\n", + GNUNET_h2s(&prd->query)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# replies received for other peers"), + 1, GNUNET_NO); + msize = sizeof(struct PutMessage) + data_len; if (msize >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } - if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) - { - if (reply_anonymity_level - 1 > GSF_cover_content_count) { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# replies dropped due to insufficient cover traffic"), - 1, GNUNET_NO); + GNUNET_break(0); return; } - GSF_cover_content_count -= (reply_anonymity_level - 1); - } - - env = GNUNET_MQ_msg_extra (pm, - data_len, - GNUNET_MESSAGE_TYPE_FS_PUT); - pm->type = htonl (type); - pm->expiration = GNUNET_TIME_absolute_hton (expiration); - GNUNET_memcpy (&pm[1], - data, - data_len); - if ( (UINT32_MAX != reply_anonymity_level) && - (0 != reply_anonymity_level) && - (GNUNET_YES == GSF_enable_randomized_delays) ) - { - struct GSF_DelayedHandle *dh; - - dh = GNUNET_new (struct GSF_DelayedHandle); - dh->cp = cp; - dh->env = env; - dh->msize = msize; - GNUNET_CONTAINER_DLL_insert (cp->delayed_head, - cp->delayed_tail, - dh); - cp->delay_queue_size++; - dh->delay_task = - GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), - &transmit_delayed_now, - dh); - } + if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) + { + if (reply_anonymity_level - 1 > GSF_cover_content_count) + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# replies dropped due to insufficient cover traffic"), + 1, GNUNET_NO); + return; + } + GSF_cover_content_count -= (reply_anonymity_level - 1); + } + + env = GNUNET_MQ_msg_extra(pm, + data_len, + GNUNET_MESSAGE_TYPE_FS_PUT); + pm->type = htonl(type); + pm->expiration = GNUNET_TIME_absolute_hton(expiration); + GNUNET_memcpy(&pm[1], + data, + data_len); + if ((UINT32_MAX != reply_anonymity_level) && + (0 != reply_anonymity_level) && + (GNUNET_YES == GSF_enable_randomized_delays)) + { + struct GSF_DelayedHandle *dh; + + dh = GNUNET_new(struct GSF_DelayedHandle); + dh->cp = cp; + dh->env = env; + dh->msize = msize; + GNUNET_CONTAINER_DLL_insert(cp->delayed_head, + cp->delayed_tail, + dh); + cp->delay_queue_size++; + dh->delay_task = + GNUNET_SCHEDULER_add_delayed(get_randomized_delay(), + &transmit_delayed_now, + dh); + } else - { - GSF_peer_transmit_ (cp, - GNUNET_NO, - UINT32_MAX, - env); - } + { + GSF_peer_transmit_(cp, + GNUNET_NO, + UINT32_MAX, + env); + } if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) return; if (NULL == peerreq->kill_task) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# P2P searches destroyed due to ultimate reply"), - 1, - GNUNET_NO); - peerreq->kill_task = - GNUNET_SCHEDULER_add_now (&peer_request_destroy, - peerreq); - } + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# P2P searches destroyed due to ultimate reply"), + 1, + GNUNET_NO); + peerreq->kill_task = + GNUNET_SCHEDULER_add_now(&peer_request_destroy, + peerreq); + } } @@ -959,31 +947,31 @@ handle_p2p_reply (void *cls, * @returns the actual change in respect (positive or negative) */ static int -change_peer_respect (struct GSF_ConnectedPeer *cp, int value) +change_peer_respect(struct GSF_ConnectedPeer *cp, int value) { if (0 == value) return 0; - GNUNET_assert (NULL != cp); + GNUNET_assert(NULL != cp); if (value > 0) - { - if (cp->ppd.respect + value < cp->ppd.respect) { - value = UINT32_MAX - cp->ppd.respect; - cp->ppd.respect = UINT32_MAX; + if (cp->ppd.respect + value < cp->ppd.respect) + { + value = UINT32_MAX - cp->ppd.respect; + cp->ppd.respect = UINT32_MAX; + } + else + cp->ppd.respect += value; } - else - cp->ppd.respect += value; - } else - { - if (cp->ppd.respect < -value) { - value = -cp->ppd.respect; - cp->ppd.respect = 0; + if (cp->ppd.respect < -value) + { + value = -cp->ppd.respect; + cp->ppd.respect = 0; + } + else + cp->ppd.respect += value; } - else - cp->ppd.respect += value; - } return value; } @@ -997,58 +985,58 @@ change_peer_respect (struct GSF_ConnectedPeer *cp, int value) * @return effective priority */ static int32_t -bound_priority (uint32_t prio_in, - struct GSF_ConnectedPeer *cp) +bound_priority(uint32_t prio_in, + struct GSF_ConnectedPeer *cp) { #define N ((double)128.0) uint32_t ret; double rret; int ld; - ld = GSF_test_get_load_too_high_ (0); + ld = GSF_test_get_load_too_high_(0); if (GNUNET_SYSERR == ld) - { + { #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# requests done for free (low load)"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# requests done for free (low load)"), 1, + GNUNET_NO); #endif - return 0; /* excess resources */ - } + return 0; /* excess resources */ + } if (prio_in > INT32_MAX) prio_in = INT32_MAX; - ret = -change_peer_respect (cp, -(int) prio_in); + ret = -change_peer_respect(cp, -(int)prio_in); if (ret > 0) - { - if (ret > GSF_current_priorities + N) - rret = GSF_current_priorities + N; - else - rret = ret; - GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; - } + { + if (ret > GSF_current_priorities + N) + rret = GSF_current_priorities + N; + else + rret = ret; + GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; + } if ((GNUNET_YES == ld) && (ret > 0)) - { - /* try with charging */ - ld = GSF_test_get_load_too_high_ (ret); - } + { + /* try with charging */ + ld = GSF_test_get_load_too_high_(ret); + } if (GNUNET_YES == ld) - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# request dropped, priority insufficient"), 1, - GNUNET_NO); - /* undo charge */ - change_peer_respect (cp, (int) ret); - return -1; /* not enough resources */ - } + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# request dropped, priority insufficient"), 1, + GNUNET_NO); + /* undo charge */ + change_peer_respect(cp, (int)ret); + return -1; /* not enough resources */ + } else - { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# requests done for a price (normal load)"), 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# requests done for a price (normal load)"), 1, + GNUNET_NO); + } #undef N return ret; } @@ -1064,20 +1052,20 @@ bound_priority (uint32_t prio_in, * otherwise the ttl-limit for the given @a prio */ static int32_t -bound_ttl (int32_t ttl_in, - uint32_t prio) +bound_ttl(int32_t ttl_in, + uint32_t prio) { unsigned long long allowed; if (ttl_in <= 0) return ttl_in; - allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000; + allowed = ((unsigned long long)prio) * TTL_DECREMENT / 1000; if (ttl_in > allowed) - { - if (allowed >= (1 << 30)) - return 1 << 30; - return allowed; - } + { + if (allowed >= (1 << 30)) + return 1 << 30; + return allowed; + } return ttl_in; } @@ -1085,9 +1073,7 @@ bound_ttl (int32_t ttl_in, /** * Closure for #test_exist_cb(). */ -struct TestExistClosure -{ - +struct TestExistClosure { /** * Priority of the incoming request. */ @@ -1107,7 +1093,6 @@ struct TestExistClosure * Set to #GNUNET_YES if we are done handling the query. */ int finished; - }; @@ -1122,9 +1107,9 @@ struct TestExistClosure * #GNUNET_NO if we successfully merged */ static int -test_exist_cb (void *cls, - const struct GNUNET_HashCode *hc, - void *value) +test_exist_cb(void *cls, + const struct GNUNET_HashCode *hc, + void *value) { struct TestExistClosure *tec = cls; struct PeerRequest *peerreq = value; @@ -1132,28 +1117,28 @@ test_exist_cb (void *cls, struct GSF_PendingRequestData *prd; pr = peerreq->pr; - prd = GSF_pending_request_get_data_ (pr); + prd = GSF_pending_request_get_data_(pr); if (prd->type != tec->type) return GNUNET_YES; if (prd->ttl.abs_value_us >= - GNUNET_TIME_absolute_get ().abs_value_us + tec->ttl * 1000LL) - { - /* existing request has higher TTL, drop new one! */ - prd->priority += tec->priority; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Have existing request with higher TTL, dropping new request.\n"); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# requests dropped due to higher-TTL request"), - 1, GNUNET_NO); - tec->finished = GNUNET_YES; - return GNUNET_NO; - } + GNUNET_TIME_absolute_get().abs_value_us + tec->ttl * 1000LL) + { + /* existing request has higher TTL, drop new one! */ + prd->priority += tec->priority; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Have existing request with higher TTL, dropping new request.\n"); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# requests dropped due to higher-TTL request"), + 1, GNUNET_NO); + tec->finished = GNUNET_YES; + return GNUNET_NO; + } /* existing request has lower TTL, drop old one! */ tec->priority += prd->priority; - free_pending_request (peerreq); - GSF_pending_request_cancel_ (pr, - GNUNET_YES); + free_pending_request(peerreq); + GSF_pending_request_cancel_(pr, + GNUNET_YES); return GNUNET_NO; } @@ -1168,8 +1153,8 @@ test_exist_cb (void *cls, * @param gm the GET message */ void -handle_p2p_get (void *cls, - const struct GetMessage *gm) +handle_p2p_get(void *cls, + const struct GetMessage *gm) { struct GSF_ConnectedPeer *cps = cls; struct PeerRequest *peerreq; @@ -1187,167 +1172,167 @@ handle_p2p_get (void *cls, GNUNET_PEER_Id spid; const struct GSF_PendingRequestData *prd; - msize = ntohs (gm->header.size); - tec.type = ntohl (gm->type); - bm = ntohl (gm->hash_bitmap); + msize = ntohs(gm->header.size); + tec.type = ntohl(gm->type); + bm = ntohl(gm->hash_bitmap); bits = 0; while (bm > 0) - { - if (1 == (bm & 1)) - bits++; - bm >>= 1; - } - opt = (const struct GNUNET_PeerIdentity *) &gm[1]; - bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# GET requests received (from other peers)"), - 1, - GNUNET_NO); + { + if (1 == (bm & 1)) + bits++; + bm >>= 1; + } + opt = (const struct GNUNET_PeerIdentity *)&gm[1]; + bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# GET requests received (from other peers)"), + 1, + GNUNET_NO); GSF_cover_query_count++; - bm = ntohl (gm->hash_bitmap); + bm = ntohl(gm->hash_bitmap); bits = 0; if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) - cp = GSF_peer_get_ (&opt[bits++]); + cp = GSF_peer_get_(&opt[bits++]); else cp = cps; if (NULL == cp) - { - if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", - GNUNET_i2s (&opt[bits - 1])); - - else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to find peer `%s' in connection set. Dropping query.\n", - GNUNET_i2s (cps->ppd.peer)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# requests dropped due to missing reverse route"), - 1, - GNUNET_NO); - return; - } - unsigned int queue_size = GNUNET_MQ_get_length (cp->mq); + { + if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", + GNUNET_i2s(&opt[bits - 1])); + + else + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Failed to find peer `%s' in connection set. Dropping query.\n", + GNUNET_i2s(cps->ppd.peer)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# requests dropped due to missing reverse route"), + 1, + GNUNET_NO); + return; + } + unsigned int queue_size = GNUNET_MQ_get_length(cp->mq); queue_size += cp->ppd.pending_replies + cp->delay_queue_size; if (queue_size > MAX_QUEUE_PER_PEER) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' has too many replies queued already. Dropping query.\n", - GNUNET_i2s (cps->ppd.peer)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# requests dropped due to full reply queue"), - 1, - GNUNET_NO); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' has too many replies queued already. Dropping query.\n", + GNUNET_i2s(cps->ppd.peer)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# requests dropped due to full reply queue"), + 1, + GNUNET_NO); + return; + } /* note that we can really only check load here since otherwise * peers could find out that we are overloaded by not being * disconnected after sending us a malformed query... */ - tec.priority = bound_priority (ntohl (gm->priority), - cps); + tec.priority = bound_priority(ntohl(gm->priority), + cps); if (tec.priority < 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Dropping query from `%s', this peer is too busy.\n", - GNUNET_i2s (cps->ppd.peer)); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received request for `%s' of type %u from peer `%s' with flags %u\n", - GNUNET_h2s (&gm->query), - (unsigned int) tec.type, - GNUNET_i2s (cps->ppd.peer), - (unsigned int) bm); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Dropping query from `%s', this peer is too busy.\n", + GNUNET_i2s(cps->ppd.peer)); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received request for `%s' of type %u from peer `%s' with flags %u\n", + GNUNET_h2s(&gm->query), + (unsigned int)tec.type, + GNUNET_i2s(cps->ppd.peer), + (unsigned int)bm); target = - (0 != - (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; + (0 != + (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; options = GSF_PRO_DEFAULTS; spid = 0; - if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + tec.priority)) - || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > + if ((GNUNET_LOAD_get_load(cp->ppd.transmission_delay) > 3 * (1 + tec.priority)) + || (GNUNET_LOAD_get_average(cp->ppd.transmission_delay) > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 + - GNUNET_LOAD_get_average (GSF_rt_entry_lifetime))) - { - /* don't have BW to send to peer, or would likely take longer than we have for it, - * so at best indirect the query */ - tec.priority = 0; - options |= GSF_PRO_FORWARD_ONLY; - spid = GNUNET_PEER_intern (cps->ppd.peer); - GNUNET_assert (0 != spid); - } - tec.ttl = bound_ttl (ntohl (gm->ttl), - tec.priority); + GNUNET_LOAD_get_average(GSF_rt_entry_lifetime))) + { + /* don't have BW to send to peer, or would likely take longer than we have for it, + * so at best indirect the query */ + tec.priority = 0; + options |= GSF_PRO_FORWARD_ONLY; + spid = GNUNET_PEER_intern(cps->ppd.peer); + GNUNET_assert(0 != spid); + } + tec.ttl = bound_ttl(ntohl(gm->ttl), + tec.priority); /* decrement ttl (always) */ ttl_decrement = - 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - TTL_DECREMENT); - if ( (tec.ttl < 0) && - (((int32_t) (tec.ttl - ttl_decrement)) > 0) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Dropping query from `%s' due to TTL underflow (%d - %u).\n", - GNUNET_i2s (cps->ppd.peer), - tec.ttl, - ttl_decrement); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# requests dropped due TTL underflow"), 1, - GNUNET_NO); - /* integer underflow => drop (should be very rare)! */ - return; - } + 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, + TTL_DECREMENT); + if ((tec.ttl < 0) && + (((int32_t)(tec.ttl - ttl_decrement)) > 0)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Dropping query from `%s' due to TTL underflow (%d - %u).\n", + GNUNET_i2s(cps->ppd.peer), + tec.ttl, + ttl_decrement); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop + ("# requests dropped due TTL underflow"), 1, + GNUNET_NO); + /* integer underflow => drop (should be very rare)! */ + return; + } tec.ttl -= ttl_decrement; /* test if the request already exists */ tec.finished = GNUNET_NO; - GNUNET_CONTAINER_multihashmap_get_multiple (cp->request_map, - &gm->query, - &test_exist_cb, - &tec); + GNUNET_CONTAINER_multihashmap_get_multiple(cp->request_map, + &gm->query, + &test_exist_cb, + &tec); if (GNUNET_YES == tec.finished) return; /* merged into existing request, we're done */ - peerreq = GNUNET_new (struct PeerRequest); + peerreq = GNUNET_new(struct PeerRequest); peerreq->cp = cp; - pr = GSF_pending_request_create_ (options, - tec.type, - &gm->query, - target, - (bfsize > 0) - ? (const char *) &opt[bits] - : NULL, - bfsize, - ntohl (gm->filter_mutator), - 1 /* anonymity */, - (uint32_t) tec.priority, - tec.ttl, - spid, - GNUNET_PEER_intern (cps->ppd.peer), - NULL, 0, /* replies_seen */ - &handle_p2p_reply, - peerreq); - GNUNET_assert (NULL != pr); - prd = GSF_pending_request_get_data_ (pr); + pr = GSF_pending_request_create_(options, + tec.type, + &gm->query, + target, + (bfsize > 0) + ? (const char *)&opt[bits] + : NULL, + bfsize, + ntohl(gm->filter_mutator), + 1 /* anonymity */, + (uint32_t)tec.priority, + tec.ttl, + spid, + GNUNET_PEER_intern(cps->ppd.peer), + NULL, 0, /* replies_seen */ + &handle_p2p_reply, + peerreq); + GNUNET_assert(NULL != pr); + prd = GSF_pending_request_get_data_(pr); peerreq->pr = pr; - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (cp->request_map, - &prd->query, - peerreq, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# P2P query messages received and processed"), - 1, - GNUNET_NO); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# P2P searches active"), - 1, - GNUNET_NO); - GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; - GSF_local_lookup_ (pr, - &GSF_consider_forwarding, - NULL); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(cp->request_map, + &prd->query, + peerreq, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# P2P query messages received and processed"), + 1, + GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# P2P searches active"), + 1, + GNUNET_NO); + GSF_pending_request_get_data_(pr)->has_started = GNUNET_YES; + GSF_local_lookup_(pr, + &GSF_consider_forwarding, + NULL); } @@ -1359,22 +1344,22 @@ handle_p2p_get (void *cls, * @param cp target peer * @param is_query is this a query (#GNUNET_YES) or content (#GNUNET_NO) or neither (#GNUNET_SYSERR) * @param priority how important is this request? - * @param timeout when does this request timeout + * @param timeout when does this request timeout * @param size number of bytes we would like to send to the peer * @param env message to send */ void -GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, - int is_query, - uint32_t priority, - struct GNUNET_MQ_Envelope *env) +GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, + int is_query, + uint32_t priority, + struct GNUNET_MQ_Envelope *env) { struct GSF_PeerTransmitHandle *pth; struct GSF_PeerTransmitHandle *pos; struct GSF_PeerTransmitHandle *prev; - pth = GNUNET_new (struct GSF_PeerTransmitHandle); - pth->transmission_request_start_time = GNUNET_TIME_absolute_get (); + pth = GNUNET_new(struct GSF_PeerTransmitHandle); + pth->transmission_request_start_time = GNUNET_TIME_absolute_get(); pth->env = env; pth->is_query = is_query; pth->priority = priority; @@ -1383,19 +1368,19 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, prev = NULL; pos = cp->pth_head; while ((NULL != pos) && (pos->priority > priority)) - { - prev = pos; - pos = pos->next; - } - GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, - cp->pth_tail, - prev, - pth); + { + prev = pos; + pos = pos->next; + } + GNUNET_CONTAINER_DLL_insert_after(cp->pth_head, + cp->pth_tail, + prev, + pth); if (GNUNET_YES == is_query) cp->ppd.pending_queries++; else if (GNUNET_NO == is_query) cp->ppd.pending_replies++; - schedule_transmission (pth); + schedule_transmission(pth); } @@ -1407,19 +1392,19 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, * @param request_priority priority of the original request */ void -GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, - struct GNUNET_TIME_Absolute request_time, - uint32_t request_priority) +GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, + struct GNUNET_TIME_Absolute request_time, + uint32_t request_priority) { struct GNUNET_TIME_Relative delay; - delay = GNUNET_TIME_absolute_get_duration (request_time); + delay = GNUNET_TIME_absolute_get_duration(request_time); cp->ppd.avg_reply_delay.rel_value_us = - (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) + - delay.rel_value_us) / RUNAVG_DELAY_N; + (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) + + delay.rel_value_us) / RUNAVG_DELAY_N; cp->ppd.avg_priority = - (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) + - request_priority) / RUNAVG_DELAY_N; + (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) + + request_priority) / RUNAVG_DELAY_N; } @@ -1431,8 +1416,8 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, * @param initiator_client local client on responsible for query */ void -GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, - struct GSF_LocalClient *initiator_client) +GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, + struct GSF_LocalClient *initiator_client) { cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client; @@ -1447,15 +1432,15 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, * @param initiator_peer other peer responsible for query */ void -GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, - const struct GSF_ConnectedPeer *initiator_peer) +GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, + const struct GSF_ConnectedPeer *initiator_peer) { unsigned int woff; woff = cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE; - GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[woff], -1); + GNUNET_PEER_change_rc(cp->ppd.last_p2p_replies[woff], -1); cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid; - GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1); + GNUNET_PEER_change_rc(initiator_peer->ppd.pid, 1); cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE; } @@ -1469,23 +1454,23 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, * @return #GNUNET_OK to continue iteration */ static int -flush_respect (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +flush_respect(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GSF_ConnectedPeer *cp = value; struct GNUNET_PeerIdentity pid; if (cp->ppd.respect == cp->disk_respect) return GNUNET_OK; /* unchanged */ - GNUNET_assert (0 != cp->ppd.pid); - GNUNET_PEER_resolve (cp->ppd.pid, &pid); - GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect, - sizeof (cp->ppd.respect), - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, - NULL); + GNUNET_assert(0 != cp->ppd.pid); + GNUNET_PEER_resolve(cp->ppd.pid, &pid); + GNUNET_PEERSTORE_store(peerstore, "fs", &pid, "respect", &cp->ppd.respect, + sizeof(cp->ppd.respect), + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, + NULL); return GNUNET_OK; } @@ -1499,9 +1484,9 @@ flush_respect (void *cls, * @param internal_cls the corresponding `struct GSF_ConnectedPeer` */ void -GSF_peer_disconnect_handler (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +GSF_peer_disconnect_handler(void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { struct GSF_ConnectedPeer *cp = internal_cls; struct GSF_PeerTransmitHandle *pth; @@ -1509,84 +1494,83 @@ GSF_peer_disconnect_handler (void *cls, if (NULL == cp) return; /* must have been disconnect from core with - * 'peer' == my_id, ignore */ - flush_respect (NULL, - peer, - cp); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (cp_map, - peer, - cp)); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# peers connected"), - GNUNET_CONTAINER_multipeermap_size (cp_map), - GNUNET_NO); + * 'peer' == my_id, ignore */ + flush_respect(NULL, + peer, + cp); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(cp_map, + peer, + cp)); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# peers connected"), + GNUNET_CONTAINER_multipeermap_size(cp_map), + GNUNET_NO); if (NULL != cp->respect_iterate_req) - { - GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); - cp->respect_iterate_req = NULL; - } + { + GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); + cp->respect_iterate_req = NULL; + } if (NULL != cp->rc) - { - GNUNET_ATS_reserve_bandwidth_cancel (cp->rc); - cp->rc = NULL; - } + { + GNUNET_ATS_reserve_bandwidth_cancel(cp->rc); + cp->rc = NULL; + } if (NULL != cp->rc_delay_task) - { - GNUNET_SCHEDULER_cancel (cp->rc_delay_task); - cp->rc_delay_task = NULL; - } - GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, - &cancel_pending_request, - cp); - GNUNET_CONTAINER_multihashmap_destroy (cp->request_map); + { + GNUNET_SCHEDULER_cancel(cp->rc_delay_task); + cp->rc_delay_task = NULL; + } + GNUNET_CONTAINER_multihashmap_iterate(cp->request_map, + &cancel_pending_request, + cp); + GNUNET_CONTAINER_multihashmap_destroy(cp->request_map); cp->request_map = NULL; - GSF_plan_notify_peer_disconnect_ (cp); - GNUNET_LOAD_value_free (cp->ppd.transmission_delay); - GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, - P2P_SUCCESS_LIST_SIZE); - memset (cp->ppd.last_p2p_replies, - 0, - sizeof (cp->ppd.last_p2p_replies)); - GSF_push_stop_ (cp); + GSF_plan_notify_peer_disconnect_(cp); + GNUNET_LOAD_value_free(cp->ppd.transmission_delay); + GNUNET_PEER_decrement_rcs(cp->ppd.last_p2p_replies, + P2P_SUCCESS_LIST_SIZE); + memset(cp->ppd.last_p2p_replies, + 0, + sizeof(cp->ppd.last_p2p_replies)); + GSF_push_stop_(cp); while (NULL != (pth = cp->pth_head)) - { - GNUNET_CONTAINER_DLL_remove (cp->pth_head, - cp->pth_tail, - pth); - if (GNUNET_YES == pth->is_query) - GNUNET_assert (0 < cp->ppd.pending_queries--); - else if (GNUNET_NO == pth->is_query) - GNUNET_assert (0 < cp->ppd.pending_replies--); - GNUNET_free (pth); - } + { + GNUNET_CONTAINER_DLL_remove(cp->pth_head, + cp->pth_tail, + pth); + if (GNUNET_YES == pth->is_query) + GNUNET_assert(0 < cp->ppd.pending_queries--); + else if (GNUNET_NO == pth->is_query) + GNUNET_assert(0 < cp->ppd.pending_replies--); + GNUNET_free(pth); + } while (NULL != (dh = cp->delayed_head)) - { - GNUNET_CONTAINER_DLL_remove (cp->delayed_head, - cp->delayed_tail, - dh); - GNUNET_MQ_discard (dh->env); - cp->delay_queue_size--; - GNUNET_SCHEDULER_cancel (dh->delay_task); - GNUNET_free (dh); - } - GNUNET_PEER_change_rc (cp->ppd.pid, -1); + { + GNUNET_CONTAINER_DLL_remove(cp->delayed_head, + cp->delayed_tail, + dh); + GNUNET_MQ_discard(dh->env); + cp->delay_queue_size--; + GNUNET_SCHEDULER_cancel(dh->delay_task); + GNUNET_free(dh); + } + GNUNET_PEER_change_rc(cp->ppd.pid, -1); if (NULL != cp->mig_revive_task) - { - GNUNET_SCHEDULER_cancel (cp->mig_revive_task); - cp->mig_revive_task = NULL; - } - GNUNET_break (0 == cp->ppd.pending_queries); - GNUNET_break (0 == cp->ppd.pending_replies); - GNUNET_free (cp); + { + GNUNET_SCHEDULER_cancel(cp->mig_revive_task); + cp->mig_revive_task = NULL; + } + GNUNET_break(0 == cp->ppd.pending_queries); + GNUNET_break(0 == cp->ppd.pending_replies); + GNUNET_free(cp); } /** * Closure for #call_iterator(). */ -struct IterationContext -{ +struct IterationContext { /** * Function to call on each entry. */ @@ -1608,16 +1592,16 @@ struct IterationContext * @return #GNUNET_YES to continue iteration */ static int -call_iterator (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +call_iterator(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct IterationContext *ic = cls; struct GSF_ConnectedPeer *cp = value; - ic->it (ic->it_cls, - key, cp, - &cp->ppd); + ic->it(ic->it_cls, + key, cp, + &cp->ppd); return GNUNET_YES; } @@ -1629,16 +1613,16 @@ call_iterator (void *cls, * @param it_cls closure for @a it */ void -GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, - void *it_cls) +GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, + void *it_cls) { struct IterationContext ic; ic.it = it; ic.it_cls = it_cls; - GNUNET_CONTAINER_multipeermap_iterate (cp_map, - &call_iterator, - &ic); + GNUNET_CONTAINER_multipeermap_iterate(cp_map, + &call_iterator, + &ic); } @@ -1649,11 +1633,11 @@ GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, * @param id identity to set (written to) */ void -GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, - struct GNUNET_PeerIdentity *id) +GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, + struct GNUNET_PeerIdentity *id) { - GNUNET_assert (0 != cp->ppd.pid); - GNUNET_PEER_resolve (cp->ppd.pid, id); + GNUNET_assert(0 != cp->ppd.pid); + GNUNET_PEER_resolve(cp->ppd.pid, id); } @@ -1664,10 +1648,10 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, * @return reference to peer identity, valid until peer disconnects (!) */ const struct GNUNET_PeerIdentity * -GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) +GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp) { - GNUNET_assert (0 != cp->ppd.pid); - return GNUNET_PEER_resolve2 (cp->ppd.pid); + GNUNET_assert(0 != cp->ppd.pid); + return GNUNET_PEER_resolve2(cp->ppd.pid); } @@ -1679,38 +1663,38 @@ GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) * @param block_time until when to block */ void -GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, - struct GNUNET_TIME_Absolute block_time) +GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, + struct GNUNET_TIME_Absolute block_time) { struct GNUNET_MQ_Envelope *env; struct MigrationStopMessage *msm; - + if (cp->last_migration_block.abs_value_us > block_time.abs_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Migration already blocked for another %s\n", - GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining - (cp->last_migration_block), GNUNET_YES)); - return; /* already blocked */ - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", - GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (block_time), - GNUNET_YES)); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Migration already blocked for another %s\n", + GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining + (cp->last_migration_block), GNUNET_YES)); + return; /* already blocked */ + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", + GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(block_time), + GNUNET_YES)); cp->last_migration_block = block_time; - env = GNUNET_MQ_msg (msm, - GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); - msm->reserved = htonl (0); + env = GNUNET_MQ_msg(msm, + GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); + msm->reserved = htonl(0); msm->duration - = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining - (cp->last_migration_block)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# migration stop messages sent"), - 1, - GNUNET_NO); - GSF_peer_transmit_ (cp, - GNUNET_SYSERR, - UINT32_MAX, - env); + = GNUNET_TIME_relative_hton(GNUNET_TIME_absolute_get_remaining + (cp->last_migration_block)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# migration stop messages sent"), + 1, + GNUNET_NO); + GSF_peer_transmit_(cp, + GNUNET_SYSERR, + UINT32_MAX, + env); } @@ -1724,8 +1708,8 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, * @param pref preference change */ void -GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, - uint64_t pref) +GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, + uint64_t pref) { cp->inc_preference += pref; } @@ -1737,15 +1721,15 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, * @param cls closure, not used */ static void -cron_flush_respect (void *cls) +cron_flush_respect(void *cls) { fr_task = NULL; - GNUNET_CONTAINER_multipeermap_iterate (cp_map, - &flush_respect, - NULL); - fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ, - GNUNET_SCHEDULER_PRIORITY_HIGH, - &cron_flush_respect, NULL); + GNUNET_CONTAINER_multipeermap_iterate(cp_map, + &flush_respect, + NULL); + fr_task = GNUNET_SCHEDULER_add_delayed_with_priority(RESPECT_FLUSH_FREQ, + GNUNET_SCHEDULER_PRIORITY_HIGH, + &cron_flush_respect, NULL); } @@ -1753,12 +1737,12 @@ cron_flush_respect (void *cls) * Initialize peer management subsystem. */ void -GSF_connected_peer_init_ () +GSF_connected_peer_init_() { - cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); - peerstore = GNUNET_PEERSTORE_connect (GSF_cfg); - fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH, - &cron_flush_respect, NULL); + cp_map = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); + peerstore = GNUNET_PEERSTORE_connect(GSF_cfg); + fr_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_HIGH, + &cron_flush_respect, NULL); } @@ -1766,18 +1750,17 @@ GSF_connected_peer_init_ () * Shutdown peer management subsystem. */ void -GSF_connected_peer_done_ () +GSF_connected_peer_done_() { - GNUNET_CONTAINER_multipeermap_iterate (cp_map, - &flush_respect, - NULL); - GNUNET_SCHEDULER_cancel (fr_task); + GNUNET_CONTAINER_multipeermap_iterate(cp_map, + &flush_respect, + NULL); + GNUNET_SCHEDULER_cancel(fr_task); fr_task = NULL; - GNUNET_CONTAINER_multipeermap_destroy (cp_map); + GNUNET_CONTAINER_multipeermap_destroy(cp_map); cp_map = NULL; - GNUNET_PEERSTORE_disconnect (peerstore, - GNUNET_YES); - + GNUNET_PEERSTORE_disconnect(peerstore, + GNUNET_YES); } @@ -1790,9 +1773,9 @@ GSF_connected_peer_done_ () * @return #GNUNET_YES (we should continue to iterate) */ static int -clean_local_client (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +clean_local_client(void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { const struct GSF_LocalClient *lc = cls; struct GSF_ConnectedPeer *cp = value; @@ -1812,13 +1795,13 @@ clean_local_client (void *cls, * @param lc handle to the local client (henceforth invalid) */ void -GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc) +GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc) { if (NULL == cp_map) return; /* already cleaned up */ - GNUNET_CONTAINER_multipeermap_iterate (cp_map, - &clean_local_client, - (void *) lc); + GNUNET_CONTAINER_multipeermap_iterate(cp_map, + &clean_local_client, + (void *)lc); } diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h index 486b696ba..9eab3d9de 100644 --- a/src/fs/gnunet-service-fs_cp.h +++ b/src/fs/gnunet-service-fs_cp.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_cp.h @@ -60,9 +60,7 @@ /** * Performance data kept for a peer. */ -struct GSF_PeerPerformanceData -{ - +struct GSF_PeerPerformanceData { /** * List of the last clients for which this peer successfully * answered a query. @@ -128,7 +126,7 @@ struct GSF_PeerPerformanceData * The peer's identity (pointer). */ const struct GNUNET_PeerIdentity *peer; - + /** * Respect rating for this peer */ @@ -143,7 +141,6 @@ struct GSF_PeerPerformanceData * Number of pending replies (queries are not counted) */ unsigned int pending_replies; - }; @@ -205,9 +202,9 @@ struct GSF_PeerTransmitHandle; * @return internal handle for the peer */ void * -GSF_peer_connect_handler (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq); +GSF_peer_connect_handler(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq); /** @@ -217,7 +214,7 @@ GSF_peer_connect_handler (void *cls, * @return NULL if this peer is not currently connected */ struct GSF_ConnectedPeer * -GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); +GSF_peer_get_(const struct GNUNET_PeerIdentity *peer); /** @@ -227,8 +224,8 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); * @param latency current latency value */ void -GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, - struct GNUNET_TIME_Relative latency); +GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, + struct GNUNET_TIME_Relative latency); /** @@ -242,10 +239,10 @@ GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, * @param env envelope of message to send */ void -GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, - int is_query, - uint32_t priority, - struct GNUNET_MQ_Envelope *env); +GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, + int is_query, + uint32_t priority, + struct GNUNET_MQ_Envelope *env); /** @@ -256,9 +253,9 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, * @param request_priority priority of the original request */ void -GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, - struct GNUNET_TIME_Absolute request_time, - uint32_t request_priority); +GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, + struct GNUNET_TIME_Absolute request_time, + uint32_t request_priority); /** @@ -269,8 +266,8 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, * @param initiator_client local client on responsible for query */ void -GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, - struct GSF_LocalClient *initiator_client); +GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, + struct GSF_LocalClient *initiator_client); /** @@ -281,9 +278,9 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, * @param initiator_peer other peer responsible for query */ void -GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, - const struct GSF_ConnectedPeer - *initiator_peer); +GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, + const struct GSF_ConnectedPeer + *initiator_peer); /** @@ -293,8 +290,8 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, * @param msm the actual message */ void -handle_p2p_migration_stop (void *cls, - const struct MigrationStopMessage *message); +handle_p2p_migration_stop(void *cls, + const struct MigrationStopMessage *message); /** @@ -304,8 +301,8 @@ handle_p2p_migration_stop (void *cls, * @param gm the actual message */ void -handle_p2p_get (void *cls, - const struct GetMessage *gm); +handle_p2p_get(void *cls, + const struct GetMessage *gm); /** @@ -315,7 +312,7 @@ handle_p2p_get (void *cls, * @return performance data record for the peer */ struct GSF_PeerPerformanceData * -GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); +GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp); /** @@ -326,8 +323,8 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); * @param block_time until when to block */ void -GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, - struct GNUNET_TIME_Absolute block_time); +GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, + struct GNUNET_TIME_Absolute block_time); /** @@ -339,9 +336,9 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer */ void -GSF_peer_disconnect_handler (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls); +GSF_peer_disconnect_handler(void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls); /** @@ -351,7 +348,7 @@ GSF_peer_disconnect_handler (void *cls, * @param lc handle to the local client (henceforth invalid) */ void -GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc); +GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc); /** @@ -364,8 +361,8 @@ GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc); * @param pref preference change */ void -GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, - uint64_t pref); +GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, + uint64_t pref); /** @@ -375,8 +372,8 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, * @param id identity to set (written to) */ void -GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, - struct GNUNET_PeerIdentity *id); +GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, + struct GNUNET_PeerIdentity *id); /** @@ -386,7 +383,7 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, * @return reference to peer identity, valid until peer disconnects (!) */ const struct GNUNET_PeerIdentity * -GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp); +GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp); @@ -397,21 +394,21 @@ GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp); * @param it_cls closure for it */ void -GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls); +GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, void *it_cls); /** * Initialize peer management subsystem. */ void -GSF_connected_peer_init_ (void); +GSF_connected_peer_init_(void); /** * Shutdown peer management subsystem. */ void -GSF_connected_peer_done_ (void); +GSF_connected_peer_done_(void); #endif diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index df5f70b3d..e21b2ca57 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_indexing.c @@ -39,9 +39,7 @@ * In-memory information about indexed files (also available * on-disk). */ -struct IndexInfo -{ - +struct IndexInfo { /** * This is a doubly linked list. */ @@ -110,44 +108,44 @@ static struct GNUNET_DATASTORE_Handle *dsh; * Write the current index information list to disk. */ static void -write_index_list () +write_index_list() { struct GNUNET_BIO_WriteHandle *wh; char *fn; struct IndexInfo *pos; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "fs", - "INDEXDB"); - return; - } - wh = GNUNET_BIO_write_open (fn); + GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "fs", + "INDEXDB"); + return; + } + wh = GNUNET_BIO_write_open(fn); if (NULL == wh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _ ("Could not open `%s'.\n"), - fn); - GNUNET_free (fn); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + _("Could not open `%s'.\n"), + fn); + GNUNET_free(fn); + return; + } for (pos = indexed_files_head; NULL != pos; pos = pos->next) - if ((GNUNET_OK != GNUNET_BIO_write (wh, - &pos->file_id, - sizeof (struct GNUNET_HashCode))) || - (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) + if ((GNUNET_OK != GNUNET_BIO_write(wh, + &pos->file_id, + sizeof(struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_write_string(wh, pos->filename))) break; - if (GNUNET_OK != GNUNET_BIO_write_close (wh)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _ ("Error writing `%s'.\n"), - fn); - GNUNET_free (fn); - return; - } - GNUNET_free (fn); + if (GNUNET_OK != GNUNET_BIO_write_close(wh)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + _("Error writing `%s'.\n"), + fn); + GNUNET_free(fn); + return; + } + GNUNET_free(fn); } @@ -155,7 +153,7 @@ write_index_list () * Read index information from disk. */ static void -read_index_list () +read_index_list() { struct GNUNET_BIO_ReadHandle *rh; char *fn; @@ -166,59 +164,59 @@ read_index_list () char *emsg; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "fs", - "INDEXDB"); - return; - } - if (GNUNET_NO == GNUNET_DISK_file_test (fn)) - { - /* no index info yet */ - GNUNET_free (fn); - return; - } - rh = GNUNET_BIO_read_open (fn); + GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "fs", + "INDEXDB"); + return; + } + if (GNUNET_NO == GNUNET_DISK_file_test(fn)) + { + /* no index info yet */ + GNUNET_free(fn); + return; + } + rh = GNUNET_BIO_read_open(fn); if (NULL == rh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _ ("Could not open `%s'.\n"), - fn); - GNUNET_free (fn); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + _("Could not open `%s'.\n"), + fn); + GNUNET_free(fn); + return; + } while ( - (GNUNET_OK == GNUNET_BIO_read (rh, - "Hash of indexed file", - &hc, - sizeof (struct GNUNET_HashCode))) && + (GNUNET_OK == GNUNET_BIO_read(rh, + "Hash of indexed file", + &hc, + sizeof(struct GNUNET_HashCode))) && (GNUNET_OK == - GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && + GNUNET_BIO_read_string(rh, "Name of indexed file", &fname, 1024 * 16)) && (fname != NULL)) - { - slen = strlen (fname) + 1; - pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); - pos->file_id = hc; - pos->filename = (const char *) &pos[1]; - GNUNET_memcpy (&pos[1], fname, slen); - if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( - ifm, - &pos->file_id, - pos, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) - { - GNUNET_free (pos); - } - else { - GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); + slen = strlen(fname) + 1; + pos = GNUNET_malloc(sizeof(struct IndexInfo) + slen); + pos->file_id = hc; + pos->filename = (const char *)&pos[1]; + GNUNET_memcpy(&pos[1], fname, slen); + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( + ifm, + &pos->file_id, + pos, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + { + GNUNET_free(pos); + } + else + { + GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, pos); + } + GNUNET_free(fname); } - GNUNET_free (fname); - } - if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) - GNUNET_free (emsg); - GNUNET_free (fn); + if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) + GNUNET_free(emsg); + GNUNET_free(fn); } @@ -232,15 +230,15 @@ read_index_list () * @param msg error message */ static void -remove_cont (void *cls, - int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +remove_cont(void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { if (GNUNET_OK != success) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to delete bogus block: %s\n"), - msg); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to delete bogus block: %s\n"), + msg); } @@ -265,17 +263,17 @@ remove_cont (void *cls, * @return GNUNET_OK on success */ int -GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, - uint32_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid, - GNUNET_DATASTORE_DatumProcessor cont, - void *cont_cls) +GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid, + GNUNET_DATASTORE_DatumProcessor cont, + void *cont_cls) { const struct OnDemandBlock *odb; struct GNUNET_HashCode nkey; @@ -290,79 +288,79 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, uint64_t off; struct IndexInfo *ii; - if (size != sizeof (struct OnDemandBlock)) - { - GNUNET_break (0); - GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); - return GNUNET_SYSERR; - } - odb = (const struct OnDemandBlock *) data; - off = GNUNET_ntohll (odb->offset); - ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); + if (size != sizeof(struct OnDemandBlock)) + { + GNUNET_break(0); + GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); + return GNUNET_SYSERR; + } + odb = (const struct OnDemandBlock *)data; + off = GNUNET_ntohll(odb->offset); + ii = GNUNET_CONTAINER_multihashmap_get(ifm, &odb->file_id); if (NULL == ii) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to find index %s\n", - GNUNET_h2s (&odb->file_id)); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to find index %s\n", + GNUNET_h2s(&odb->file_id)); + return GNUNET_SYSERR; + } fn = ii->filename; - if ((NULL == fn) || (0 != access (fn, R_OK))) - { - GNUNET_STATISTICS_update ( - GSF_stats, - gettext_noop ("# index blocks removed: original file inaccessible"), - 1, - GNUNET_YES); - GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); - return GNUNET_SYSERR; - } - if ((NULL == (fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE))) || - (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || - (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ( - "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), - GNUNET_h2s (&odb->file_id), - fn, - (unsigned long long) off, - (fn == NULL) ? _ ("not indexed") : strerror (errno)); - if (fh != NULL) - GNUNET_DISK_file_close (fh); - GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); - return GNUNET_SYSERR; - } - GNUNET_DISK_file_close (fh); - GNUNET_CRYPTO_hash (ndata, nsize, &nkey); - GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); - GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); - GNUNET_CRYPTO_hash (edata, nsize, &query); - if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Indexed file `%s' changed at offset %llu\n"), - fn, - (unsigned long long) off); - GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); - return GNUNET_SYSERR; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "On-demand encoded block for query `%s'\n", - GNUNET_h2s (key)); - cont (cont_cls, - key, - nsize, - edata, - GNUNET_BLOCK_TYPE_FS_DBLOCK, - priority, - anonymity, - replication, - expiration, - uid); + if ((NULL == fn) || (0 != access(fn, R_OK))) + { + GNUNET_STATISTICS_update( + GSF_stats, + gettext_noop("# index blocks removed: original file inaccessible"), + 1, + GNUNET_YES); + GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); + return GNUNET_SYSERR; + } + if ((NULL == (fh = GNUNET_DISK_file_open(fn, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE))) || + (off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET)) || + (-1 == (nsize = GNUNET_DISK_file_read(fh, ndata, sizeof(ndata))))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _( + "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), + GNUNET_h2s(&odb->file_id), + fn, + (unsigned long long)off, + (fn == NULL) ? _("not indexed") : strerror(errno)); + if (fh != NULL) + GNUNET_DISK_file_close(fh); + GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); + return GNUNET_SYSERR; + } + GNUNET_DISK_file_close(fh); + GNUNET_CRYPTO_hash(ndata, nsize, &nkey); + GNUNET_CRYPTO_hash_to_aes_key(&nkey, &skey, &iv); + GNUNET_CRYPTO_symmetric_encrypt(ndata, nsize, &skey, &iv, edata); + GNUNET_CRYPTO_hash(edata, nsize, &query); + if (0 != memcmp(&query, key, sizeof(struct GNUNET_HashCode))) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Indexed file `%s' changed at offset %llu\n"), + fn, + (unsigned long long)off); + GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); + return GNUNET_SYSERR; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "On-demand encoded block for query `%s'\n", + GNUNET_h2s(key)); + cont(cont_cls, + key, + nsize, + edata, + GNUNET_BLOCK_TYPE_FS_DBLOCK, + priority, + anonymity, + replication, + expiration, + uid); return GNUNET_OK; } @@ -373,7 +371,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, * @param mq message queue to send information to */ void -GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) +GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) { struct GNUNET_MQ_Envelope *env; struct IndexInfoMessage *iim; @@ -383,23 +381,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) struct IndexInfo *pos; for (pos = indexed_files_head; NULL != pos; pos = pos->next) - { - fn = pos->filename; - slen = strlen (fn) + 1; - if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - break; + fn = pos->filename; + slen = strlen(fn) + 1; + if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) + { + GNUNET_break(0); + break; + } + env = + GNUNET_MQ_msg_extra(iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); + iim->reserved = 0; + iim->file_id = pos->file_id; + GNUNET_memcpy(&iim[1], fn, slen); + GNUNET_MQ_send(mq, env); } - env = - GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); - iim->reserved = 0; - iim->file_id = pos->file_id; - GNUNET_memcpy (&iim[1], fn, slen); - GNUNET_MQ_send (mq, env); - } - env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); - GNUNET_MQ_send (mq, env); + env = GNUNET_MQ_msg(iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); + GNUNET_MQ_send(mq, env); } @@ -410,23 +408,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) * @return #GNUNET_YES if the @a fid was found */ int -GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) +GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) { struct IndexInfo *pos; for (pos = indexed_files_head; NULL != pos; pos = pos->next) - { - if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode))) { - GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); - GNUNET_break ( - GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); - GNUNET_free (pos); - write_index_list (); - return GNUNET_YES; + if (0 == memcmp(&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) + { + GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); + GNUNET_break( + GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); + GNUNET_free(pos); + write_index_list(); + return GNUNET_YES; + } } - } return GNUNET_NO; } @@ -438,40 +436,40 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) * @param file_id hash identifier for @a filename */ void -GNUNET_FS_add_to_index (const char *filename, - const struct GNUNET_HashCode *file_id) +GNUNET_FS_add_to_index(const char *filename, + const struct GNUNET_HashCode *file_id) { struct IndexInfo *ii; size_t slen; - ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); + ii = GNUNET_CONTAINER_multihashmap_get(ifm, file_id); if (NULL != ii) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_INFO, - _ ( - "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), - filename, - ii->filename); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding file %s to index as %s\n", - filename, - GNUNET_h2s (file_id)); - slen = strlen (filename) + 1; - ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); + { + GNUNET_log( + GNUNET_ERROR_TYPE_INFO, + _( + "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), + filename, + ii->filename); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Adding file %s to index as %s\n", + filename, + GNUNET_h2s(file_id)); + slen = strlen(filename) + 1; + ii = GNUNET_malloc(sizeof(struct IndexInfo) + slen); ii->file_id = *file_id; - ii->filename = (const char *) &ii[1]; - GNUNET_memcpy (&ii[1], filename, slen); - GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - ifm, - &ii->file_id, - ii, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - write_index_list (); + ii->filename = (const char *)&ii[1]; + GNUNET_memcpy(&ii[1], filename, slen); + GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, ii); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + ifm, + &ii->file_id, + ii, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + write_index_list(); } @@ -479,21 +477,21 @@ GNUNET_FS_add_to_index (const char *filename, * Shutdown the module. */ void -GNUNET_FS_indexing_done () +GNUNET_FS_indexing_done() { struct IndexInfo *pos; while (NULL != (pos = indexed_files_head)) - { - GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); - if (pos->fhc != NULL) - GNUNET_CRYPTO_hash_file_cancel (pos->fhc); - GNUNET_break ( - GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); - GNUNET_free (pos); - } - GNUNET_CONTAINER_multihashmap_destroy (ifm); + { + GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); + if (pos->fhc != NULL) + GNUNET_CRYPTO_hash_file_cancel(pos->fhc); + GNUNET_break( + GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); + GNUNET_free(pos); + } + GNUNET_CONTAINER_multihashmap_destroy(ifm); ifm = NULL; cfg = NULL; } @@ -506,13 +504,13 @@ GNUNET_FS_indexing_done () * @param d datastore to use */ int -GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_DATASTORE_Handle *d) +GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_DATASTORE_Handle *d) { cfg = c; dsh = d; - ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); - read_index_list (); + ifm = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_YES); + read_index_list(); return GNUNET_OK; } diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h index d6166f0a9..4c137d7a6 100644 --- a/src/fs/gnunet-service-fs_indexing.h +++ b/src/fs/gnunet-service-fs_indexing.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_indexing.h @@ -56,17 +56,17 @@ * @return #GNUNET_OK on success */ int -GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, - uint32_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid, - GNUNET_DATASTORE_DatumProcessor cont, - void *cont_cls); +GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid, + GNUNET_DATASTORE_DatumProcessor cont, + void *cont_cls); /** @@ -75,7 +75,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, * @param mq message queue to send information to */ void -GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq); +GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq); /** @@ -85,7 +85,7 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq); * @return #GNUNET_YES if the @a fid was found */ int -GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid); +GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid); /** @@ -95,8 +95,8 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid); * @param file_id hash identifier for @a filename */ void -GNUNET_FS_add_to_index (const char *filename, - const struct GNUNET_HashCode *file_id); +GNUNET_FS_add_to_index(const char *filename, + const struct GNUNET_HashCode *file_id); /** @@ -107,15 +107,15 @@ GNUNET_FS_add_to_index (const char *filename, * @return GNUNET_OK on success */ int -GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_DATASTORE_Handle *d); +GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_DATASTORE_Handle *d); /** * Shutdown the module. */ void -GNUNET_FS_indexing_done (void); +GNUNET_FS_indexing_done(void); #endif diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c index 5e85bfdb7..3c1112333 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_pe.c @@ -63,9 +63,7 @@ struct PeerPlan; * to be able to lookup all plan entries corresponding * to a given pending request.) */ -struct GSF_PendingRequestPlanBijection -{ - +struct GSF_PendingRequestPlanBijection { /** * This is a doubly-linked list. */ @@ -97,7 +95,6 @@ struct GSF_PendingRequestPlanBijection * and one of the origins of the request). */ struct GSF_PendingRequest *pr; - }; @@ -107,9 +104,7 @@ struct GSF_PendingRequestPlanBijection * with one entry in each heap of each `struct PeerPlan`. Each * entry tracks information relevant for this request and this peer. */ -struct GSF_RequestPlan -{ - +struct GSF_RequestPlan { /** * This is a doubly-linked list. */ @@ -161,15 +156,13 @@ struct GSF_RequestPlan * How often did we transmit this request to this peer? */ unsigned int transmission_counter; - }; /** * Transmission plan for a peer. */ -struct PeerPlan -{ +struct PeerPlan { /** * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority. */ @@ -202,7 +195,6 @@ struct PeerPlan * Current message under transmission for the plan. */ struct GNUNET_MQ_Envelope *env; - }; @@ -235,9 +227,9 @@ static unsigned long long plan_count; * @return the associated query */ static const struct GNUNET_HashCode * -get_rp_key (struct GSF_RequestPlan *rp) +get_rp_key(struct GSF_RequestPlan *rp) { - return &GSF_pending_request_get_data_ (rp->pe_head->pr)->query; + return &GSF_pending_request_get_data_(rp->pe_head->pr)->query; } @@ -248,8 +240,8 @@ get_rp_key (struct GSF_RequestPlan *rp) * @param rp request to plan */ static void -plan (struct PeerPlan *pp, - struct GSF_RequestPlan *rp) +plan(struct PeerPlan *pp, + struct GSF_RequestPlan *rp) { #define N ((double)128.0) /** @@ -260,28 +252,28 @@ plan (struct PeerPlan *pp, struct GSF_PendingRequestData *prd; struct GNUNET_TIME_Relative delay; - GNUNET_assert (rp->pp == pp); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# average retransmission delay (ms)"), - total_delay * 1000LL / plan_count, GNUNET_NO); - prd = GSF_pending_request_get_data_ (rp->pe_head->pr); + GNUNET_assert(rp->pp == pp); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# average retransmission delay (ms)"), + total_delay * 1000LL / plan_count, GNUNET_NO); + prd = GSF_pending_request_get_data_(rp->pe_head->pr); if (rp->transmission_counter < 8) delay = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - rp->transmission_counter); + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + rp->transmission_counter); else if (rp->transmission_counter < 32) delay = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 8 + - (1LL << (rp->transmission_counter - 8))); + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + 8 + + (1LL << (rp->transmission_counter - 8))); else delay = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 8 + (1LL << 24)); + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + 8 + (1LL << 24)); delay.rel_value_us = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - delay.rel_value_us + 1); + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, + delay.rel_value_us + 1); /* Add 0.01 to avg_delay to avoid division-by-zero later */ avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01; @@ -307,36 +299,36 @@ plan (struct PeerPlan *pp, * Note: M_PI_4 = PI/4 = arctan(1) */ rp->priority = - round ((GSF_current_priorities + - 1.0) * atan (delay.rel_value_us / avg_delay)) / M_PI_4; + round((GSF_current_priorities + + 1.0) * atan(delay.rel_value_us / avg_delay)) / M_PI_4; /* Note: usage of 'round' and 'atan' requires -lm */ if (rp->transmission_counter != 0) delay.rel_value_us += TTL_DECREMENT * 1000; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Considering (re)transmission number %u in %s\n", - (unsigned int) rp->transmission_counter, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Earliest (re)transmission for `%s' in %us\n", - GNUNET_h2s (&prd->query), - rp->transmission_counter); - GNUNET_assert (rp->hn == NULL); - if (0 == GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value_us) - rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, - rp, - rp->priority); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Considering (re)transmission number %u in %s\n", + (unsigned int)rp->transmission_counter, + GNUNET_STRINGS_relative_time_to_string(delay, + GNUNET_YES)); + rp->earliest_transmission = GNUNET_TIME_relative_to_absolute(delay); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Earliest (re)transmission for `%s' in %us\n", + GNUNET_h2s(&prd->query), + rp->transmission_counter); + GNUNET_assert(rp->hn == NULL); + if (0 == GNUNET_TIME_absolute_get_remaining(rp->earliest_transmission).rel_value_us) + rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, + rp, + rp->priority); else rp->hn = - GNUNET_CONTAINER_heap_insert (pp->delay_heap, - rp, - rp->earliest_transmission.abs_value_us); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, - get_rp_key (rp), - rp)); + GNUNET_CONTAINER_heap_insert(pp->delay_heap, + rp, + rp->earliest_transmission.abs_value_us); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains_value(pp->plan_map, + get_rp_key(rp), + rp)); #undef N } @@ -348,7 +340,7 @@ plan (struct PeerPlan *pp, * @return pending request with highest TTL */ struct GSF_PendingRequest * -get_latest (const struct GSF_RequestPlan *rp) +get_latest(const struct GSF_RequestPlan *rp) { struct GSF_PendingRequest *ret; struct GSF_PendingRequestPlanBijection *bi; @@ -359,18 +351,18 @@ get_latest (const struct GSF_RequestPlan *rp) if (NULL == bi) return NULL; /* should never happen */ ret = bi->pr; - rprd = GSF_pending_request_get_data_ (ret); + rprd = GSF_pending_request_get_data_(ret); for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) - { - GNUNET_break (GNUNET_YES == - GSF_pending_request_test_active_ (bi->pr)); - prd = GSF_pending_request_get_data_ (bi->pr); - if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us) { - ret = bi->pr; - rprd = prd; + GNUNET_break(GNUNET_YES == + GSF_pending_request_test_active_(bi->pr)); + prd = GSF_pending_request_get_data_(bi->pr); + if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us) + { + ret = bi->pr; + rprd = prd; + } } - } return ret; } @@ -381,102 +373,100 @@ get_latest (const struct GSF_RequestPlan *rp) * @param cls the `struct PeerPlan` */ static void -schedule_peer_transmission (void *cls) +schedule_peer_transmission(void *cls) { struct PeerPlan *pp = cls; struct GSF_RequestPlan *rp; struct GNUNET_TIME_Relative delay; if (NULL != pp->task) - { - pp->task = NULL; - } + { + pp->task = NULL; + } else - { - GNUNET_assert (NULL != pp->env); - pp->env = NULL; - } + { + GNUNET_assert(NULL != pp->env); + pp->env = NULL; + } /* move ready requests to priority queue */ - while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && + while ((NULL != (rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap))) && (0 == GNUNET_TIME_absolute_get_remaining - (rp->earliest_transmission).rel_value_us)) - { - GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)); - rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, - rp, - rp->priority); - } - if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap)) - { - /* priority heap (still) empty, check for delay... */ - rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap); - if (NULL == rp) + (rp->earliest_transmission).rel_value_us)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No active requests for plan %p.\n", - pp); - return; /* both queues empty */ + GNUNET_assert(rp == GNUNET_CONTAINER_heap_remove_root(pp->delay_heap)); + rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, + rp, + rp->priority); + } + if (0 == GNUNET_CONTAINER_heap_get_size(pp->priority_heap)) + { + /* priority heap (still) empty, check for delay... */ + rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap); + if (NULL == rp) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No active requests for plan %p.\n", + pp); + return; /* both queues empty */ + } + delay = GNUNET_TIME_absolute_get_remaining(rp->earliest_transmission); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sleeping for %s before retrying requests on plan %p.\n", + GNUNET_STRINGS_relative_time_to_string(delay, + GNUNET_YES), + pp); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# delay heap timeout (ms)"), + delay.rel_value_us / 1000LL, GNUNET_NO); + + pp->task + = GNUNET_SCHEDULER_add_at(rp->earliest_transmission, + &schedule_peer_transmission, + pp); + return; } - delay = GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sleeping for %s before retrying requests on plan %p.\n", - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES), - pp); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# delay heap timeout (ms)"), - delay.rel_value_us / 1000LL, GNUNET_NO); - - pp->task - = GNUNET_SCHEDULER_add_at (rp->earliest_transmission, - &schedule_peer_transmission, - pp); - return; - } #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# query plans executed"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# query plans executed"), + 1, + GNUNET_NO); #endif /* process from priority heap */ - rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Executing query plan %p\n", - rp); - GNUNET_assert (NULL != rp); + rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Executing query plan %p\n", + rp); + GNUNET_assert(NULL != rp); rp->hn = NULL; - rp->last_transmission = GNUNET_TIME_absolute_get (); + rp->last_transmission = GNUNET_TIME_absolute_get(); rp->transmission_counter++; total_delay++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Executing plan %p executed %u times, planning retransmission\n", - rp, - rp->transmission_counter); - GNUNET_assert (NULL == pp->env); - pp->env = GSF_pending_request_get_message_ (get_latest (rp)); - GNUNET_MQ_notify_sent (pp->env, - &schedule_peer_transmission, - pp); - GSF_peer_transmit_ (pp->cp, - GNUNET_YES, - rp->priority, - pp->env); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# query messages sent to other peers"), - 1, - GNUNET_NO); - plan (pp, - rp); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Executing plan %p executed %u times, planning retransmission\n", + rp, + rp->transmission_counter); + GNUNET_assert(NULL == pp->env); + pp->env = GSF_pending_request_get_message_(get_latest(rp)); + GNUNET_MQ_notify_sent(pp->env, + &schedule_peer_transmission, + pp); + GSF_peer_transmit_(pp->cp, + GNUNET_YES, + rp->priority, + pp->env); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# query messages sent to other peers"), + 1, + GNUNET_NO); + plan(pp, + rp); } /** * Closure for merge_pr(). */ -struct MergeContext -{ - +struct MergeContext { /** * Request we are trying to merge. */ @@ -486,7 +476,6 @@ struct MergeContext * Set to #GNUNET_YES if we succeeded to merge. */ int merged; - }; @@ -501,9 +490,9 @@ struct MergeContext * #GNUNET_NO if not (merge success) */ static int -merge_pr (void *cls, - const struct GNUNET_HashCode *query, - void *element) +merge_pr(void *cls, + const struct GNUNET_HashCode *query, + void *element) { struct MergeContext *mpr = cls; struct GSF_RequestPlan *rp = element; @@ -511,44 +500,44 @@ merge_pr (void *cls, struct GSF_PendingRequestPlanBijection *bi; struct GSF_PendingRequest *latest; - GNUNET_break (GNUNET_YES == - GSF_pending_request_test_active_ (mpr->pr)); + GNUNET_break(GNUNET_YES == + GSF_pending_request_test_active_(mpr->pr)); if (GNUNET_OK != - GSF_pending_request_is_compatible_ (mpr->pr, - rp->pe_head->pr)) + GSF_pending_request_is_compatible_(mpr->pr, + rp->pe_head->pr)) return GNUNET_YES; /* merge new request with existing request plan */ - bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); + bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); bi->rp = rp; bi->pr = mpr->pr; - prd = GSF_pending_request_get_data_ (mpr->pr); - GNUNET_CONTAINER_MDLL_insert (PR, - prd->pr_head, - prd->pr_tail, - bi); - GNUNET_CONTAINER_MDLL_insert (PE, - rp->pe_head, - rp->pe_tail, - bi); + prd = GSF_pending_request_get_data_(mpr->pr); + GNUNET_CONTAINER_MDLL_insert(PR, + prd->pr_head, + prd->pr_tail, + bi); + GNUNET_CONTAINER_MDLL_insert(PE, + rp->pe_head, + rp->pe_tail, + bi); mpr->merged = GNUNET_YES; #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# requests merged"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# requests merged"), + 1, + GNUNET_NO); #endif - latest = get_latest (rp); - if (GSF_pending_request_get_data_ (latest)->ttl.abs_value_us < + latest = get_latest(rp); + if (GSF_pending_request_get_data_(latest)->ttl.abs_value_us < prd->ttl.abs_value_us) - { + { #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# requests refreshed"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# requests refreshed"), + 1, + GNUNET_NO); #endif - rp->transmission_counter = 0; /* reset */ - } + rp->transmission_counter = 0; /* reset */ + } return GNUNET_NO; } @@ -560,8 +549,8 @@ merge_pr (void *cls, * @param pr request with the entry */ void -GSF_plan_add_ (struct GSF_ConnectedPeer *cp, - struct GSF_PendingRequest *pr) +GSF_plan_add_(struct GSF_ConnectedPeer *cp, + struct GSF_PendingRequest *pr) { const struct GNUNET_PeerIdentity *id; struct PeerPlan *pp; @@ -570,66 +559,66 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequestPlanBijection *bi; struct MergeContext mpc; - GNUNET_assert (GNUNET_YES == - GSF_pending_request_test_active_ (pr)); - GNUNET_assert (NULL != cp); - id = GSF_connected_peer_get_identity2_ (cp); - pp = GNUNET_CONTAINER_multipeermap_get (plans, id); + GNUNET_assert(GNUNET_YES == + GSF_pending_request_test_active_(pr)); + GNUNET_assert(NULL != cp); + id = GSF_connected_peer_get_identity2_(cp); + pp = GNUNET_CONTAINER_multipeermap_get(plans, id); if (NULL == pp) - { - pp = GNUNET_new (struct PeerPlan); - pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); - pp->priority_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); - pp->delay_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); - pp->cp = cp; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (plans, + { + pp = GNUNET_new(struct PeerPlan); + pp->plan_map = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_NO); + pp->priority_heap = + GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); + pp->delay_heap = + GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); + pp->cp = cp; + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put(plans, id, pp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, - pp); - } + pp->task = GNUNET_SCHEDULER_add_now(&schedule_peer_transmission, + pp); + } mpc.merged = GNUNET_NO; mpc.pr = pr; - prd = GSF_pending_request_get_data_ (pr); - GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, - &prd->query, - &merge_pr, - &mpc); + prd = GSF_pending_request_get_data_(pr); + GNUNET_CONTAINER_multihashmap_get_multiple(pp->plan_map, + &prd->query, + &merge_pr, + &mpc); if (GNUNET_NO != mpc.merged) return; plan_count++; - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# query plan entries"), - 1, - GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Planning transmission of query `%s' to peer `%s'\n", - GNUNET_h2s (&prd->query), - GNUNET_i2s (id)); - rp = GNUNET_new (struct GSF_RequestPlan); - bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# query plan entries"), + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Planning transmission of query `%s' to peer `%s'\n", + GNUNET_h2s(&prd->query), + GNUNET_i2s(id)); + rp = GNUNET_new(struct GSF_RequestPlan); + bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); bi->rp = rp; bi->pr = pr; - GNUNET_CONTAINER_MDLL_insert (PR, - prd->pr_head, - prd->pr_tail, - bi); - GNUNET_CONTAINER_MDLL_insert (PE, - rp->pe_head, - rp->pe_tail, - bi); + GNUNET_CONTAINER_MDLL_insert(PR, + prd->pr_head, + prd->pr_tail, + bi); + GNUNET_CONTAINER_MDLL_insert(PE, + rp->pe_head, + rp->pe_tail, + bi); rp->pp = pp; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (pp->plan_map, - get_rp_key (rp), - rp, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - plan (pp, - rp); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put(pp->plan_map, + get_rp_key(rp), + rp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + plan(pp, + rp); } @@ -640,7 +629,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, * @param cp connected peer */ void -GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) +GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp) { const struct GNUNET_PeerIdentity *id; struct PeerPlan *pp; @@ -648,70 +637,70 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) struct GSF_PendingRequestData *prd; struct GSF_PendingRequestPlanBijection *bi; - id = GSF_connected_peer_get_identity2_ (cp); - pp = GNUNET_CONTAINER_multipeermap_get (plans, id); + id = GSF_connected_peer_get_identity2_(cp); + pp = GNUNET_CONTAINER_multipeermap_get(plans, id); if (NULL == pp) return; /* nothing was ever planned for this peer */ - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (plans, id, - pp)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(plans, id, + pp)); if (NULL != pp->task) - { - GNUNET_SCHEDULER_cancel (pp->task); - pp->task = NULL; - } - while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) - { - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, - get_rp_key (rp), - rp)); - while (NULL != (bi = rp->pe_head)) { - GNUNET_CONTAINER_MDLL_remove (PE, - rp->pe_head, - rp->pe_tail, - bi); - prd = GSF_pending_request_get_data_ (bi->pr); - GNUNET_CONTAINER_MDLL_remove (PR, - prd->pr_head, - prd->pr_tail, - bi); - GNUNET_free (bi); + GNUNET_SCHEDULER_cancel(pp->task); + pp->task = NULL; } - plan_count--; - GNUNET_free (rp); - } - GNUNET_CONTAINER_heap_destroy (pp->priority_heap); - while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) - { - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, - get_rp_key (rp), + while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap))) + { + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, + get_rp_key(rp), rp)); - while (NULL != (bi = rp->pe_head)) + while (NULL != (bi = rp->pe_head)) + { + GNUNET_CONTAINER_MDLL_remove(PE, + rp->pe_head, + rp->pe_tail, + bi); + prd = GSF_pending_request_get_data_(bi->pr); + GNUNET_CONTAINER_MDLL_remove(PR, + prd->pr_head, + prd->pr_tail, + bi); + GNUNET_free(bi); + } + plan_count--; + GNUNET_free(rp); + } + GNUNET_CONTAINER_heap_destroy(pp->priority_heap); + while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root(pp->delay_heap))) { - prd = GSF_pending_request_get_data_ (bi->pr); - GNUNET_CONTAINER_MDLL_remove (PE, - rp->pe_head, - rp->pe_tail, - bi); - GNUNET_CONTAINER_MDLL_remove (PR, - prd->pr_head, - prd->pr_tail, - bi); - GNUNET_free (bi); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, + get_rp_key(rp), + rp)); + while (NULL != (bi = rp->pe_head)) + { + prd = GSF_pending_request_get_data_(bi->pr); + GNUNET_CONTAINER_MDLL_remove(PE, + rp->pe_head, + rp->pe_tail, + bi); + GNUNET_CONTAINER_MDLL_remove(PR, + prd->pr_head, + prd->pr_tail, + bi); + GNUNET_free(bi); + } + plan_count--; + GNUNET_free(rp); } - plan_count--; - GNUNET_free (rp); - } - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# query plan entries"), - plan_count, - GNUNET_NO); - GNUNET_CONTAINER_heap_destroy (pp->delay_heap); - GNUNET_CONTAINER_multihashmap_destroy (pp->plan_map); - GNUNET_free (pp); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# query plan entries"), + plan_count, + GNUNET_NO); + GNUNET_CONTAINER_heap_destroy(pp->delay_heap); + GNUNET_CONTAINER_multihashmap_destroy(pp->plan_map); + GNUNET_free(pp); } @@ -725,23 +714,23 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise. */ int -GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlanBijection *pr_head, - struct GSF_ConnectedPeer *sender, - struct GNUNET_TIME_Absolute *result) +GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanBijection *pr_head, + struct GSF_ConnectedPeer *sender, + struct GNUNET_TIME_Absolute *result) { struct GSF_PendingRequestPlanBijection *bi; for (bi = pr_head; NULL != bi; bi = bi->next_PR) - { - if (bi->rp->pp->cp == sender) { - if (0 == bi->rp->last_transmission.abs_value_us) - *result = GNUNET_TIME_UNIT_FOREVER_ABS; - else - *result = bi->rp->last_transmission; - return GNUNET_YES; + if (bi->rp->pp->cp == sender) + { + if (0 == bi->rp->last_transmission.abs_value_us) + *result = GNUNET_TIME_UNIT_FOREVER_ABS; + else + *result = bi->rp->last_transmission; + return GNUNET_YES; + } } - } return GNUNET_NO; } @@ -753,41 +742,41 @@ GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlan * @param pr request that is done */ void -GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) +GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr) { struct GSF_RequestPlan *rp; struct GSF_PendingRequestData *prd; struct GSF_PendingRequestPlanBijection *bi; - prd = GSF_pending_request_get_data_ (pr); + prd = GSF_pending_request_get_data_(pr); while (NULL != (bi = prd->pr_head)) - { - rp = bi->rp; - GNUNET_CONTAINER_MDLL_remove (PR, - prd->pr_head, - prd->pr_tail, - bi); - GNUNET_CONTAINER_MDLL_remove (PE, - rp->pe_head, - rp->pe_tail, - bi); - GNUNET_assert (bi->pr == pr); - if (NULL == rp->pe_head) { - GNUNET_CONTAINER_heap_remove_node (rp->hn); - plan_count--; - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, - &prd->query, - rp)); - GNUNET_free (rp); + rp = bi->rp; + GNUNET_CONTAINER_MDLL_remove(PR, + prd->pr_head, + prd->pr_tail, + bi); + GNUNET_CONTAINER_MDLL_remove(PE, + rp->pe_head, + rp->pe_tail, + bi); + GNUNET_assert(bi->pr == pr); + if (NULL == rp->pe_head) + { + GNUNET_CONTAINER_heap_remove_node(rp->hn); + plan_count--; + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(rp->pp->plan_map, + &prd->query, + rp)); + GNUNET_free(rp); + } + GNUNET_free(bi); } - GNUNET_free (bi); - } - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# query plan entries"), - plan_count, - GNUNET_NO); + GNUNET_STATISTICS_set(GSF_stats, + gettext_noop("# query plan entries"), + plan_count, + GNUNET_NO); } @@ -795,10 +784,10 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) * Initialize plan subsystem. */ void -GSF_plan_init () +GSF_plan_init() { - plans = GNUNET_CONTAINER_multipeermap_create (256, - GNUNET_YES); + plans = GNUNET_CONTAINER_multipeermap_create(256, + GNUNET_YES); } @@ -806,10 +795,10 @@ GSF_plan_init () * Shutdown plan subsystem. */ void -GSF_plan_done () +GSF_plan_done() { - GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (plans)); - GNUNET_CONTAINER_multipeermap_destroy (plans); + GNUNET_assert(0 == GNUNET_CONTAINER_multipeermap_size(plans)); + GNUNET_CONTAINER_multipeermap_destroy(plans); } diff --git a/src/fs/gnunet-service-fs_pe.h b/src/fs/gnunet-service-fs_pe.h index 10f7daea5..dfad71be9 100644 --- a/src/fs/gnunet-service-fs_pe.h +++ b/src/fs/gnunet-service-fs_pe.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_pe.h @@ -36,8 +36,8 @@ * @param pr request with the entry */ void -GSF_plan_add_ (struct GSF_ConnectedPeer *cp, - struct GSF_PendingRequest *pr); +GSF_plan_add_(struct GSF_ConnectedPeer *cp, + struct GSF_PendingRequest *pr); /** @@ -47,7 +47,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, * @param cp connected peer */ void -GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp); +GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp); /** @@ -57,7 +57,7 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp); * @param pr request that is done */ void -GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr); +GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr); /** * Get the last transmission attempt time for the request plan list @@ -69,22 +69,22 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr); * @return GNUNET_YES if 'result' was changed, GNUNET_NO otherwise. */ int -GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlanBijection *pr_head, - struct GSF_ConnectedPeer *sender, - struct GNUNET_TIME_Absolute *result); +GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanBijection *pr_head, + struct GSF_ConnectedPeer *sender, + struct GNUNET_TIME_Absolute *result); /** * Initialize plan subsystem. */ void -GSF_plan_init (void); +GSF_plan_init(void); /** * Shutdown plan subsystem. */ void -GSF_plan_done (void); +GSF_plan_done(void); #endif diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index f9702486a..90587cfa0 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_pr.c @@ -74,8 +74,7 @@ /** * An active request. */ -struct GSF_PendingRequest -{ +struct GSF_PendingRequest { /** * Public data for the request. */ @@ -247,31 +246,31 @@ static unsigned long long max_pending_requests = (32 * 1024); * @param pr request for which the BF is to be recomputed */ static void -refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) +refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) { if (NULL != pr->bg) - { - GNUNET_BLOCK_group_destroy (pr->bg); - pr->bg = NULL; - } + { + GNUNET_BLOCK_group_destroy(pr->bg); + pr->bg = NULL; + } if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) return; /* no need */ pr->bg = - GNUNET_BLOCK_group_create (GSF_block_ctx, - type, - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX), - NULL, - 0, - "seen-set-size", - pr->replies_seen_count, - NULL); + GNUNET_BLOCK_group_create(GSF_block_ctx, + type, + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX), + NULL, + 0, + "seen-set-size", + pr->replies_seen_count, + NULL); if (NULL == pr->bg) return; - GNUNET_break (GNUNET_OK == - GNUNET_BLOCK_group_set_seen (pr->bg, - pr->replies_seen, - pr->replies_seen_count)); + GNUNET_break(GNUNET_OK == + GNUNET_BLOCK_group_set_seen(pr->bg, + pr->replies_seen, + pr->replies_seen_count)); } @@ -297,129 +296,129 @@ refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) * @return handle for the new pending request */ struct GSF_PendingRequest * -GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, - enum GNUNET_BLOCK_Type type, - const struct GNUNET_HashCode *query, - const struct GNUNET_PeerIdentity *target, - const char *bf_data, - size_t bf_size, - uint32_t mingle, - uint32_t anonymity_level, - uint32_t priority, - int32_t ttl, - GNUNET_PEER_Id sender_pid, - GNUNET_PEER_Id origin_pid, - const struct GNUNET_HashCode *replies_seen, - unsigned int replies_seen_count, - GSF_PendingRequestReplyHandler rh, - void *rh_cls) +GSF_pending_request_create_(enum GSF_PendingRequestOptions options, + enum GNUNET_BLOCK_Type type, + const struct GNUNET_HashCode *query, + const struct GNUNET_PeerIdentity *target, + const char *bf_data, + size_t bf_size, + uint32_t mingle, + uint32_t anonymity_level, + uint32_t priority, + int32_t ttl, + GNUNET_PEER_Id sender_pid, + GNUNET_PEER_Id origin_pid, + const struct GNUNET_HashCode *replies_seen, + unsigned int replies_seen_count, + GSF_PendingRequestReplyHandler rh, + void *rh_cls) { struct GSF_PendingRequest *pr; struct GSF_PendingRequest *dpr; size_t extra; struct GNUNET_HashCode *eptr; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating request handle for `%s' of type %d\n", - GNUNET_h2s (query), - type); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating request handle for `%s' of type %d\n", + GNUNET_h2s(query), + type); #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Pending requests created"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Pending requests created"), + 1, + GNUNET_NO); #endif extra = 0; if (NULL != target) - extra += sizeof (struct GNUNET_PeerIdentity); - pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest) + extra); + extra += sizeof(struct GNUNET_PeerIdentity); + pr = GNUNET_malloc(sizeof(struct GSF_PendingRequest) + extra); pr->public_data.query = *query; - eptr = (struct GNUNET_HashCode *) &pr[1]; + eptr = (struct GNUNET_HashCode *)&pr[1]; if (NULL != target) - { - pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr; - GNUNET_memcpy (eptr, target, sizeof (struct GNUNET_PeerIdentity)); - } + { + pr->public_data.target = (struct GNUNET_PeerIdentity *)eptr; + GNUNET_memcpy(eptr, target, sizeof(struct GNUNET_PeerIdentity)); + } pr->public_data.anonymity_level = anonymity_level; pr->public_data.priority = priority; pr->public_data.original_priority = priority; pr->public_data.options = options; pr->public_data.type = type; - pr->public_data.start_time = GNUNET_TIME_absolute_get (); + pr->public_data.start_time = GNUNET_TIME_absolute_get(); pr->sender_pid = sender_pid; pr->origin_pid = origin_pid; pr->rh = rh; pr->rh_cls = rh_cls; - GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); + GNUNET_assert((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); if (ttl >= 0) - pr->public_data.ttl = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (uint32_t) ttl)); + pr->public_data.ttl = GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (uint32_t)ttl)); else - pr->public_data.ttl = GNUNET_TIME_absolute_subtract ( + pr->public_data.ttl = GNUNET_TIME_absolute_subtract( pr->public_data.start_time, - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - (uint32_t) (-ttl))); + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + (uint32_t)(-ttl))); if (replies_seen_count > 0) - { - pr->replies_seen_size = replies_seen_count; - pr->replies_seen = - GNUNET_new_array (pr->replies_seen_size, struct GNUNET_HashCode); - GNUNET_memcpy (pr->replies_seen, - replies_seen, - replies_seen_count * sizeof (struct GNUNET_HashCode)); - pr->replies_seen_count = replies_seen_count; - } + { + pr->replies_seen_size = replies_seen_count; + pr->replies_seen = + GNUNET_new_array(pr->replies_seen_size, struct GNUNET_HashCode); + GNUNET_memcpy(pr->replies_seen, + replies_seen, + replies_seen_count * sizeof(struct GNUNET_HashCode)); + pr->replies_seen_count = replies_seen_count; + } if ((NULL != bf_data) && (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type)) - { - pr->bg = GNUNET_BLOCK_group_create (GSF_block_ctx, - pr->public_data.type, - mingle, - bf_data, - bf_size, - "seen-set-size", - 0, - NULL); - } + { + pr->bg = GNUNET_BLOCK_group_create(GSF_block_ctx, + pr->public_data.type, + mingle, + bf_data, + bf_size, + "seen-set-size", + 0, + NULL); + } else if ((replies_seen_count > 0) && (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) - { - refresh_bloomfilter (pr->public_data.type, pr); - } - GNUNET_CONTAINER_multihashmap_put (pr_map, - &pr->public_data.query, - pr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + { + refresh_bloomfilter(pr->public_data.type, pr); + } + GNUNET_CONTAINER_multihashmap_put(pr_map, + &pr->public_data.query, + pr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) - { - pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, - pr, - pr->public_data.ttl.abs_value_us); - /* make sure we don't track too many requests */ - while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > - max_pending_requests) { - dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); - GNUNET_assert (NULL != dpr); - if (pr == dpr) - break; /* let the request live briefly... */ - if (NULL != dpr->rh) - dpr->rh (dpr->rh_cls, - GNUNET_BLOCK_EVALUATION_REQUEST_VALID, - dpr, - UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_BLOCK_TYPE_ANY, - NULL, - 0); - GSF_pending_request_cancel_ (dpr, GNUNET_YES); + pr->hnode = GNUNET_CONTAINER_heap_insert(requests_by_expiration_heap, + pr, + pr->public_data.ttl.abs_value_us); + /* make sure we don't track too many requests */ + while (GNUNET_CONTAINER_heap_get_size(requests_by_expiration_heap) > + max_pending_requests) + { + dpr = GNUNET_CONTAINER_heap_peek(requests_by_expiration_heap); + GNUNET_assert(NULL != dpr); + if (pr == dpr) + break; /* let the request live briefly... */ + if (NULL != dpr->rh) + dpr->rh(dpr->rh_cls, + GNUNET_BLOCK_EVALUATION_REQUEST_VALID, + dpr, + UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_BLOCK_TYPE_ANY, + NULL, + 0); + GSF_pending_request_cancel_(dpr, GNUNET_YES); + } } - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Pending requests active"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Pending requests active"), + 1, + GNUNET_NO); return pr; } @@ -430,7 +429,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, * @return associated public data */ struct GSF_PendingRequestData * -GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr) +GSF_pending_request_get_data_(struct GSF_PendingRequest *pr) { return &pr->public_data; } @@ -446,13 +445,13 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr) * @return #GNUNET_OK if the requests are compatible */ int -GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, - struct GSF_PendingRequest *prb) +GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, + struct GSF_PendingRequest *prb) { if ((pra->public_data.type != prb->public_data.type) || - (0 != memcmp (&pra->public_data.query, - &prb->public_data.query, - sizeof (struct GNUNET_HashCode)))) + (0 != memcmp(&pra->public_data.query, + &prb->public_data.query, + sizeof(struct GNUNET_HashCode)))) return GNUNET_NO; return GNUNET_OK; } @@ -467,45 +466,45 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, * @param replies_seen_count size of the replies_seen array */ void -GSF_pending_request_update_ (struct GSF_PendingRequest *pr, - const struct GNUNET_HashCode *replies_seen, - unsigned int replies_seen_count) +GSF_pending_request_update_(struct GSF_PendingRequest *pr, + const struct GNUNET_HashCode *replies_seen, + unsigned int replies_seen_count) { if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) return; /* integer overflow */ if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) - { - /* we're responsible for the BF, full refresh */ - if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) - GNUNET_array_grow (pr->replies_seen, - pr->replies_seen_size, - replies_seen_count + pr->replies_seen_count); - GNUNET_memcpy (&pr->replies_seen[pr->replies_seen_count], - replies_seen, - sizeof (struct GNUNET_HashCode) * replies_seen_count); - pr->replies_seen_count += replies_seen_count; - refresh_bloomfilter (pr->public_data.type, pr); - } - else - { - if (NULL == pr->bg) { - /* we're not the initiator, but the initiator did not give us - * any bloom-filter, so we need to create one on-the-fly */ - refresh_bloomfilter (pr->public_data.type, pr); + /* we're responsible for the BF, full refresh */ + if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) + GNUNET_array_grow(pr->replies_seen, + pr->replies_seen_size, + replies_seen_count + pr->replies_seen_count); + GNUNET_memcpy(&pr->replies_seen[pr->replies_seen_count], + replies_seen, + sizeof(struct GNUNET_HashCode) * replies_seen_count); + pr->replies_seen_count += replies_seen_count; + refresh_bloomfilter(pr->public_data.type, pr); } - else + else { - GNUNET_break (GNUNET_OK == - GNUNET_BLOCK_group_set_seen (pr->bg, - replies_seen, - pr->replies_seen_count)); + if (NULL == pr->bg) + { + /* we're not the initiator, but the initiator did not give us + * any bloom-filter, so we need to create one on-the-fly */ + refresh_bloomfilter(pr->public_data.type, pr); + } + else + { + GNUNET_break(GNUNET_OK == + GNUNET_BLOCK_group_set_seen(pr->bg, + replies_seen, + pr->replies_seen_count)); + } } - } if (NULL != pr->gh) - GNUNET_DHT_get_filter_known_results (pr->gh, - replies_seen_count, - replies_seen); + GNUNET_DHT_get_filter_known_results(pr->gh, + replies_seen_count, + replies_seen); } @@ -517,7 +516,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, * @return envelope with the request message */ struct GNUNET_MQ_Envelope * -GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) +GSF_pending_request_get_message_(struct GSF_PendingRequest *pr) { struct GNUNET_MQ_Envelope *env; struct GetMessage *gm; @@ -532,61 +531,61 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) void *bf_data; uint32_t bf_nonce; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Building request message for `%s' of type %d\n", - GNUNET_h2s (&pr->public_data.query), - pr->public_data.type); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Building request message for `%s' of type %d\n", + GNUNET_h2s(&pr->public_data.query), + pr->public_data.type); k = 0; bm = 0; do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); - if ((! do_route) && (pr->sender_pid == 0)) - { - GNUNET_break (0); - do_route = GNUNET_YES; - } - if (! do_route) - { - bm |= GET_MESSAGE_BIT_RETURN_TO; - k++; - } + if ((!do_route) && (pr->sender_pid == 0)) + { + GNUNET_break(0); + do_route = GNUNET_YES; + } + if (!do_route) + { + bm |= GET_MESSAGE_BIT_RETURN_TO; + k++; + } if (NULL != pr->public_data.target) - { - bm |= GET_MESSAGE_BIT_TRANSMIT_TO; - k++; - } + { + bm |= GET_MESSAGE_BIT_TRANSMIT_TO; + k++; + } if (GNUNET_OK != - GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size)) - { - bf_size = 0; - bf_data = NULL; - } - env = GNUNET_MQ_msg_extra (gm, - bf_size + k * sizeof (struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_FS_GET); - gm->type = htonl (pr->public_data.type); + GNUNET_BLOCK_group_serialize(pr->bg, &bf_nonce, &bf_data, &bf_size)) + { + bf_size = 0; + bf_data = NULL; + } + env = GNUNET_MQ_msg_extra(gm, + bf_size + k * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_FS_GET); + gm->type = htonl(pr->public_data.type); if (do_route) - prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - pr->public_data.priority + 1); + prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, + pr->public_data.priority + 1); else prio = 0; pr->public_data.priority -= prio; pr->public_data.num_transmissions++; pr->public_data.respect_offered += prio; - gm->priority = htonl (prio); - now = GNUNET_TIME_absolute_get (); - ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us); - gm->ttl = htonl (ttl / 1000LL / 1000LL); - gm->filter_mutator = htonl (bf_nonce); - gm->hash_bitmap = htonl (bm); + gm->priority = htonl(prio); + now = GNUNET_TIME_absolute_get(); + ttl = (int64_t)(pr->public_data.ttl.abs_value_us - now.abs_value_us); + gm->ttl = htonl(ttl / 1000LL / 1000LL); + gm->filter_mutator = htonl(bf_nonce); + gm->hash_bitmap = htonl(bm); gm->query = pr->public_data.query; - ext = (struct GNUNET_PeerIdentity *) &gm[1]; + ext = (struct GNUNET_PeerIdentity *)&gm[1]; k = 0; - if (! do_route) - GNUNET_PEER_resolve (pr->sender_pid, &ext[k++]); + if (!do_route) + GNUNET_PEER_resolve(pr->sender_pid, &ext[k++]); if (NULL != pr->public_data.target) ext[k++] = *pr->public_data.target; - GNUNET_memcpy (&ext[k], bf_data, bf_size); - GNUNET_free_non_null (bf_data); + GNUNET_memcpy(&ext[k], bf_data, bf_size); + GNUNET_free_non_null(bf_data); return env; } @@ -600,61 +599,61 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) * @return #GNUNET_YES (we should continue to iterate) */ static int -clean_request (void *cls, const struct GNUNET_HashCode *key, void *value) +clean_request(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GSF_PendingRequest *pr = value; GSF_LocalLookupContinuation cont; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up pending request for `%s'.\n", - GNUNET_h2s (key)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up pending request for `%s'.\n", + GNUNET_h2s(key)); if (NULL != pr->cadet_request) - { - pr->cadet_retry_count = CADET_RETRY_MAX; - GSF_cadet_query_cancel (pr->cadet_request); - pr->cadet_request = NULL; - } + { + pr->cadet_retry_count = CADET_RETRY_MAX; + GSF_cadet_query_cancel(pr->cadet_request); + pr->cadet_request = NULL; + } if (NULL != (cont = pr->llc_cont)) - { - pr->llc_cont = NULL; - cont (pr->llc_cont_cls, pr, pr->local_result); - } - GSF_plan_notify_request_done_ (pr); - GNUNET_free_non_null (pr->replies_seen); - GNUNET_BLOCK_group_destroy (pr->bg); + { + pr->llc_cont = NULL; + cont(pr->llc_cont_cls, pr, pr->local_result); + } + GSF_plan_notify_request_done_(pr); + GNUNET_free_non_null(pr->replies_seen); + GNUNET_BLOCK_group_destroy(pr->bg); pr->bg = NULL; - GNUNET_PEER_change_rc (pr->sender_pid, -1); + GNUNET_PEER_change_rc(pr->sender_pid, -1); pr->sender_pid = 0; - GNUNET_PEER_change_rc (pr->origin_pid, -1); + GNUNET_PEER_change_rc(pr->origin_pid, -1); pr->origin_pid = 0; if (NULL != pr->hnode) - { - GNUNET_CONTAINER_heap_remove_node (pr->hnode); - pr->hnode = NULL; - } + { + GNUNET_CONTAINER_heap_remove_node(pr->hnode); + pr->hnode = NULL; + } if (NULL != pr->qe) - { - GNUNET_DATASTORE_cancel (pr->qe); - pr->qe = NULL; - } + { + GNUNET_DATASTORE_cancel(pr->qe); + pr->qe = NULL; + } if (NULL != pr->gh) - { - GNUNET_DHT_get_stop (pr->gh); - pr->gh = NULL; - } + { + GNUNET_DHT_get_stop(pr->gh); + pr->gh = NULL; + } if (NULL != pr->warn_task) - { - GNUNET_SCHEDULER_cancel (pr->warn_task); - pr->warn_task = NULL; - } - GNUNET_assert ( + { + GNUNET_SCHEDULER_cancel(pr->warn_task); + pr->warn_task = NULL; + } + GNUNET_assert( GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (pr_map, &pr->public_data.query, pr)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Pending requests active"), - -1, - GNUNET_NO); - GNUNET_free (pr); + GNUNET_CONTAINER_multihashmap_remove(pr_map, &pr->public_data.query, pr)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Pending requests active"), + -1, + GNUNET_NO); + GNUNET_free(pr); return GNUNET_YES; } @@ -666,49 +665,49 @@ clean_request (void *cls, const struct GNUNET_HashCode *key, void *value) * @param full_cleanup fully purge the request */ void -GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup) +GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup) { GSF_LocalLookupContinuation cont; if (NULL == pr_map) return; /* already cleaned up! */ if (GNUNET_NO == full_cleanup) - { - /* make request inactive (we're no longer interested in more results), - * but do NOT remove from our data-structures, we still need it there - * to prevent the request from looping */ - pr->rh = NULL; - if (NULL != pr->cadet_request) { - pr->cadet_retry_count = CADET_RETRY_MAX; - GSF_cadet_query_cancel (pr->cadet_request); - pr->cadet_request = NULL; + /* make request inactive (we're no longer interested in more results), + * but do NOT remove from our data-structures, we still need it there + * to prevent the request from looping */ + pr->rh = NULL; + if (NULL != pr->cadet_request) + { + pr->cadet_retry_count = CADET_RETRY_MAX; + GSF_cadet_query_cancel(pr->cadet_request); + pr->cadet_request = NULL; + } + if (NULL != (cont = pr->llc_cont)) + { + pr->llc_cont = NULL; + cont(pr->llc_cont_cls, pr, pr->local_result); + } + GSF_plan_notify_request_done_(pr); + if (NULL != pr->qe) + { + GNUNET_DATASTORE_cancel(pr->qe); + pr->qe = NULL; + } + if (NULL != pr->gh) + { + GNUNET_DHT_get_stop(pr->gh); + pr->gh = NULL; + } + if (NULL != pr->warn_task) + { + GNUNET_SCHEDULER_cancel(pr->warn_task); + pr->warn_task = NULL; + } + return; } - if (NULL != (cont = pr->llc_cont)) - { - pr->llc_cont = NULL; - cont (pr->llc_cont_cls, pr, pr->local_result); - } - GSF_plan_notify_request_done_ (pr); - if (NULL != pr->qe) - { - GNUNET_DATASTORE_cancel (pr->qe); - pr->qe = NULL; - } - if (NULL != pr->gh) - { - GNUNET_DHT_get_stop (pr->gh); - pr->gh = NULL; - } - if (NULL != pr->warn_task) - { - GNUNET_SCHEDULER_cancel (pr->warn_task); - pr->warn_task = NULL; - } - return; - } - GNUNET_assert (GNUNET_YES == - clean_request (NULL, &pr->public_data.query, pr)); + GNUNET_assert(GNUNET_YES == + clean_request(NULL, &pr->public_data.query, pr)); } @@ -719,11 +718,11 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup) * @param cls closure for @a it */ void -GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls) +GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, void *cls) { - GNUNET_CONTAINER_multihashmap_iterate ( + GNUNET_CONTAINER_multihashmap_iterate( pr_map, - (GNUNET_CONTAINER_MulitHashMapIteratorCallback) it, + (GNUNET_CONTAINER_MulitHashMapIteratorCallback)it, cls); } @@ -731,8 +730,7 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls) /** * Closure for process_reply() function. */ -struct ProcessReplyClosure -{ +struct ProcessReplyClosure { /** * The data for the reply. */ @@ -793,14 +791,14 @@ struct ProcessReplyClosure * @param pr request that was satisfied */ static void -update_request_performance_data (struct ProcessReplyClosure *prq, - struct GSF_PendingRequest *pr) +update_request_performance_data(struct ProcessReplyClosure *prq, + struct GSF_PendingRequest *pr) { if (prq->sender == NULL) return; - GSF_peer_update_performance_ (prq->sender, - pr->public_data.start_time, - prq->priority); + GSF_peer_update_performance_(prq->sender, + pr->public_data.start_time, + prq->priority); } @@ -813,7 +811,7 @@ update_request_performance_data (struct ProcessReplyClosure *prq, * @return #GNUNET_YES (we should continue to iterate) */ static int -process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) +process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) { struct ProcessReplyClosure *prq = cls; struct GSF_PendingRequest *pr = value; @@ -822,121 +820,128 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) if (NULL == pr->rh) return GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Matched result (type %u) for query `%s' with pending request\n", - (unsigned int) prq->type, - GNUNET_h2s (key)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# replies received and matched"), - 1, - GNUNET_NO); - prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx, - prq->type, - pr->bg, - prq->eo, - key, - NULL, - 0, - prq->data, - prq->size); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Matched result (type %u) for query `%s' with pending request\n", + (unsigned int)prq->type, + GNUNET_h2s(key)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# replies received and matched"), + 1, + GNUNET_NO); + prq->eval = GNUNET_BLOCK_evaluate(GSF_block_ctx, + prq->type, + pr->bg, + prq->eo, + key, + NULL, + 0, + prq->data, + prq->size); switch (prq->eval) - { - case GNUNET_BLOCK_EVALUATION_OK_MORE: - update_request_performance_data (prq, pr); - break; - case GNUNET_BLOCK_EVALUATION_OK_LAST: - /* short cut: stop processing early, no BF-update, etc. */ - update_request_performance_data (prq, pr); - GNUNET_LOAD_update (GSF_rt_entry_lifetime, - GNUNET_TIME_absolute_get_duration ( - pr->public_data.start_time) - .rel_value_us); - if (GNUNET_YES != - GSF_request_plan_reference_get_last_transmission_ (pr->public_data - .pr_head, - prq->sender, - &last_transmission)) - last_transmission.abs_value_us = - GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; - /* pass on to other peers / local clients */ - pr->rh (pr->rh_cls, - prq->eval, - pr, - prq->anonymity_level, - prq->expiration, - last_transmission, - prq->type, - prq->data, - prq->size); - return GNUNET_YES; - case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: + { + case GNUNET_BLOCK_EVALUATION_OK_MORE: + update_request_performance_data(prq, pr); + break; + + case GNUNET_BLOCK_EVALUATION_OK_LAST: + /* short cut: stop processing early, no BF-update, etc. */ + update_request_performance_data(prq, pr); + GNUNET_LOAD_update(GSF_rt_entry_lifetime, + GNUNET_TIME_absolute_get_duration( + pr->public_data.start_time) + .rel_value_us); + if (GNUNET_YES != + GSF_request_plan_reference_get_last_transmission_(pr->public_data + .pr_head, + prq->sender, + &last_transmission)) + last_transmission.abs_value_us = + GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; + /* pass on to other peers / local clients */ + pr->rh(pr->rh_cls, + prq->eval, + pr, + prq->anonymity_level, + prq->expiration, + last_transmission, + prq->type, + prq->data, + prq->size); + return GNUNET_YES; + + case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# duplicate replies discarded (bloomfilter)"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# duplicate replies discarded (bloomfilter)"), + 1, + GNUNET_NO); #endif - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); - return GNUNET_YES; /* duplicate */ - case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# irrelevant replies discarded"), - 1, - GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); - return GNUNET_YES; - case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: - return GNUNET_YES; /* wrong namespace */ - case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: - GNUNET_break (0); - return GNUNET_YES; - case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: - GNUNET_break (0); - return GNUNET_YES; - case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Unsupported block type %u\n"), - prq->type); - return GNUNET_NO; - } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); + return GNUNET_YES; /* duplicate */ + + case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# irrelevant replies discarded"), + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); + return GNUNET_YES; + + case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: + return GNUNET_YES; /* wrong namespace */ + + case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: + GNUNET_break(0); + return GNUNET_YES; + + case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: + GNUNET_break(0); + return GNUNET_YES; + + case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Unsupported block type %u\n"), + prq->type); + return GNUNET_NO; + } /* update bloomfilter */ - GNUNET_CRYPTO_hash (prq->data, prq->size, &chash); - GSF_pending_request_update_ (pr, &chash, 1); + GNUNET_CRYPTO_hash(prq->data, prq->size, &chash); + GSF_pending_request_update_(pr, &chash, 1); if (NULL == prq->sender) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found result for query `%s' in local datastore\n", - GNUNET_h2s (key)); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# results found locally"), - 1, - GNUNET_NO); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Found result for query `%s' in local datastore\n", + GNUNET_h2s(key)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# results found locally"), + 1, + GNUNET_NO); + } else - { - GSF_dht_lookup_ (pr); - } + { + GSF_dht_lookup_(pr); + } prq->priority += pr->public_data.original_priority; pr->public_data.priority = 0; pr->public_data.original_priority = 0; pr->public_data.results_found++; prq->request_found = GNUNET_YES; /* finally, pass on to other peer / local client */ - if (! GSF_request_plan_reference_get_last_transmission_ (pr->public_data - .pr_head, - prq->sender, - &last_transmission)) + if (!GSF_request_plan_reference_get_last_transmission_(pr->public_data + .pr_head, + prq->sender, + &last_transmission)) last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; - pr->rh (pr->rh_cls, - prq->eval, - pr, - prq->anonymity_level, - prq->expiration, - last_transmission, - prq->type, - prq->data, - prq->size); + pr->rh(pr->rh_cls, + prq->eval, + pr, + prq->anonymity_level, + prq->expiration, + last_transmission, + prq->type, + prq->data, + prq->size); return GNUNET_YES; } @@ -944,9 +949,7 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) /** * Context for put_migration_continuation(). */ -struct PutMigrationContext -{ - +struct PutMigrationContext { /** * Start time for the operation. */ @@ -975,10 +978,10 @@ struct PutMigrationContext * @param msg NULL on success, otherwise an error message */ static void -put_migration_continuation (void *cls, - int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +put_migration_continuation(void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { struct PutMigrationContext *pmc = cls; struct GSF_ConnectedPeer *cp; @@ -986,67 +989,67 @@ put_migration_continuation (void *cls, struct GSF_PeerPerformanceData *ppd; if (NULL != datastore_put_load) - { - if (GNUNET_SYSERR != success) { - GNUNET_LOAD_update (datastore_put_load, - GNUNET_TIME_absolute_get_duration (pmc->start) - .rel_value_us); + if (GNUNET_SYSERR != success) + { + GNUNET_LOAD_update(datastore_put_load, + GNUNET_TIME_absolute_get_duration(pmc->start) + .rel_value_us); + } + else + { + /* on queue failure / timeout, increase the put load dramatically */ + GNUNET_LOAD_update(datastore_put_load, + GNUNET_TIME_UNIT_MINUTES.rel_value_us); + } } - else - { - /* on queue failure / timeout, increase the put load dramatically */ - GNUNET_LOAD_update (datastore_put_load, - GNUNET_TIME_UNIT_MINUTES.rel_value_us); - } - } - cp = GSF_peer_get_ (&pmc->origin); + cp = GSF_peer_get_(&pmc->origin); if (GNUNET_OK == success) - { - if (NULL != cp) { - ppd = GSF_get_peer_performance_data_ (cp); - ppd->migration_delay.rel_value_us /= 2; + if (NULL != cp) + { + ppd = GSF_get_peer_performance_data_(cp); + ppd->migration_delay.rel_value_us /= 2; + } + GNUNET_free(pmc); + return; } - GNUNET_free (pmc); - return; - } if ((GNUNET_NO == success) && (GNUNET_NO == pmc->requested) && (NULL != cp)) - { - ppd = GSF_get_peer_performance_data_ (cp); - if (min_expiration.abs_value_us > 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking to stop migration for %s because datastore is full\n", - GNUNET_STRINGS_relative_time_to_string ( - GNUNET_TIME_absolute_get_remaining (min_expiration), - GNUNET_YES)); - GSF_block_peer_migration_ (cp, min_expiration); - } - else { - ppd->migration_delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_SECONDS, - ppd->migration_delay); - ppd->migration_delay = - GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, ppd->migration_delay); - mig_pause.rel_value_us = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - ppd->migration_delay.rel_value_us); - ppd->migration_delay = - GNUNET_TIME_relative_saturating_multiply (ppd->migration_delay, 2); - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Replicated content already exists locally, asking to stop migration for %s\n", - GNUNET_STRINGS_relative_time_to_string (mig_pause, GNUNET_YES)); - GSF_block_peer_migration_ (cp, - GNUNET_TIME_relative_to_absolute (mig_pause)); + ppd = GSF_get_peer_performance_data_(cp); + if (min_expiration.abs_value_us > 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Asking to stop migration for %s because datastore is full\n", + GNUNET_STRINGS_relative_time_to_string( + GNUNET_TIME_absolute_get_remaining(min_expiration), + GNUNET_YES)); + GSF_block_peer_migration_(cp, min_expiration); + } + else + { + ppd->migration_delay = GNUNET_TIME_relative_max(GNUNET_TIME_UNIT_SECONDS, + ppd->migration_delay); + ppd->migration_delay = + GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS, ppd->migration_delay); + mig_pause.rel_value_us = + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, + ppd->migration_delay.rel_value_us); + ppd->migration_delay = + GNUNET_TIME_relative_saturating_multiply(ppd->migration_delay, 2); + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Replicated content already exists locally, asking to stop migration for %s\n", + GNUNET_STRINGS_relative_time_to_string(mig_pause, GNUNET_YES)); + GSF_block_peer_migration_(cp, + GNUNET_TIME_relative_to_absolute(mig_pause)); + } } - } - GNUNET_free (pmc); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Datastore `PUT' failures"), - 1, - GNUNET_NO); + GNUNET_free(pmc); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Datastore `PUT' failures"), + 1, + GNUNET_NO); } @@ -1060,22 +1063,22 @@ put_migration_continuation (void *cls, * #GNUNET_NO to process normally (load normal or low) */ static int -test_put_load_too_high (uint32_t priority) +test_put_load_too_high(uint32_t priority) { double ld; if (NULL == datastore_put_load) return GNUNET_NO; - if (GNUNET_LOAD_get_average (datastore_put_load) < 50) + if (GNUNET_LOAD_get_average(datastore_put_load) < 50) return GNUNET_NO; /* very fast */ - ld = GNUNET_LOAD_get_load (datastore_put_load); + ld = GNUNET_LOAD_get_load(datastore_put_load); if (ld < 2.0 * (1 + priority)) return GNUNET_NO; - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# storage requests dropped due to high load"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# storage requests dropped due to high load"), + 1, + GNUNET_NO); return GNUNET_YES; } @@ -1096,67 +1099,67 @@ test_put_load_too_high (uint32_t priority) * @param data pointer to the result data */ static void -handle_dht_reply (void *cls, - struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, - size_t size, - const void *data) +handle_dht_reply(void *cls, + struct GNUNET_TIME_Absolute exp, + const struct GNUNET_HashCode *key, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, + enum GNUNET_BLOCK_Type type, + size_t size, + const void *data) { struct GSF_PendingRequest *pr = cls; struct ProcessReplyClosure prq; struct PutMigrationContext *pmc; - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Replies received from DHT"), - 1, - GNUNET_NO); - memset (&prq, 0, sizeof (prq)); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Replies received from DHT"), + 1, + GNUNET_NO); + memset(&prq, 0, sizeof(prq)); prq.data = data; prq.expiration = exp; /* do not allow migrated content to live longer than 1 year */ - prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_YEARS), - prq.expiration); + prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_UNIT_YEARS), + prq.expiration); prq.size = size; prq.type = type; prq.eo = GNUNET_BLOCK_EO_NONE; - process_reply (&prq, key, pr); + process_reply(&prq, key, pr); if ((GNUNET_YES == active_to_migration) && - (GNUNET_NO == test_put_load_too_high (prq.priority))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Replicating result for query `%s' with priority %u\n", - GNUNET_h2s (key), - prq.priority); - pmc = GNUNET_new (struct PutMigrationContext); - pmc->start = GNUNET_TIME_absolute_get (); - pmc->requested = GNUNET_YES; - if (NULL == GNUNET_DATASTORE_put (GSF_dsh, - 0, - key, - size, - data, - type, - prq.priority, - 1 /* anonymity */, - 0 /* replication */, - exp, - 1 + prq.priority, - MAX_DATASTORE_QUEUE, - &put_migration_continuation, - pmc)) + (GNUNET_NO == test_put_load_too_high(prq.priority))) { - put_migration_continuation (pmc, - GNUNET_SYSERR, - GNUNET_TIME_UNIT_ZERO_ABS, - NULL); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Replicating result for query `%s' with priority %u\n", + GNUNET_h2s(key), + prq.priority); + pmc = GNUNET_new(struct PutMigrationContext); + pmc->start = GNUNET_TIME_absolute_get(); + pmc->requested = GNUNET_YES; + if (NULL == GNUNET_DATASTORE_put(GSF_dsh, + 0, + key, + size, + data, + type, + prq.priority, + 1 /* anonymity */, + 0 /* replication */, + exp, + 1 + prq.priority, + MAX_DATASTORE_QUEUE, + &put_migration_continuation, + pmc)) + { + put_migration_continuation(pmc, + GNUNET_SYSERR, + GNUNET_TIME_UNIT_ZERO_ABS, + NULL); + } } - } } @@ -1166,42 +1169,42 @@ handle_dht_reply (void *cls, * @param pr the pending request to process */ void -GSF_dht_lookup_ (struct GSF_PendingRequest *pr) +GSF_dht_lookup_(struct GSF_PendingRequest *pr) { const void *xquery; size_t xquery_size; struct GNUNET_PeerIdentity pi; - char buf[sizeof (struct GNUNET_HashCode) * 2] GNUNET_ALIGN; + char buf[sizeof(struct GNUNET_HashCode) * 2] GNUNET_ALIGN; if (0 != pr->public_data.anonymity_level) return; if (NULL != pr->gh) - { - GNUNET_DHT_get_stop (pr->gh); - pr->gh = NULL; - } + { + GNUNET_DHT_get_stop(pr->gh); + pr->gh = NULL; + } xquery = NULL; xquery_size = 0; if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) - { - GNUNET_assert (0 != pr->sender_pid); - GNUNET_PEER_resolve (pr->sender_pid, &pi); - GNUNET_memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity)); - xquery_size += sizeof (struct GNUNET_PeerIdentity); - } - pr->gh = GNUNET_DHT_get_start (GSF_dht, - pr->public_data.type, - &pr->public_data.query, - DHT_GET_REPLICATION, - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - xquery, - xquery_size, - &handle_dht_reply, - pr); + { + GNUNET_assert(0 != pr->sender_pid); + GNUNET_PEER_resolve(pr->sender_pid, &pi); + GNUNET_memcpy(&buf[xquery_size], &pi, sizeof(struct GNUNET_PeerIdentity)); + xquery_size += sizeof(struct GNUNET_PeerIdentity); + } + pr->gh = GNUNET_DHT_get_start(GSF_dht, + pr->public_data.type, + &pr->public_data.query, + DHT_GET_REPLICATION, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + xquery, + xquery_size, + &handle_dht_reply, + pr); if ((NULL != pr->gh) && (0 != pr->replies_seen_count)) - GNUNET_DHT_get_filter_known_results (pr->gh, - pr->replies_seen_count, - pr->replies_seen); + GNUNET_DHT_get_filter_known_results(pr->gh, + pr->replies_seen_count, + pr->replies_seen); } @@ -1215,11 +1218,11 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr) * @param data reply block data, NULL on error */ static void -cadet_reply_proc (void *cls, - enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration, - size_t data_size, - const void *data) +cadet_reply_proc(void *cls, + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute expiration, + size_t data_size, + const void *data) { struct GSF_PendingRequest *pr = cls; struct ProcessReplyClosure prq; @@ -1227,46 +1230,46 @@ cadet_reply_proc (void *cls, pr->cadet_request = NULL; if (GNUNET_BLOCK_TYPE_ANY == type) - { - GNUNET_break (NULL == data); - GNUNET_break (0 == data_size); - pr->cadet_retry_count++; - if (pr->cadet_retry_count >= CADET_RETRY_MAX) - return; /* give up on cadet */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); - /* retry -- without delay, as this is non-anonymous - and cadet/cadet connect will take some time anyway */ - pr->cadet_request = GSF_cadet_query (pr->public_data.target, - &pr->public_data.query, - pr->public_data.type, - &cadet_reply_proc, - pr); - return; - } + { + GNUNET_break(NULL == data); + GNUNET_break(0 == data_size); + pr->cadet_retry_count++; + if (pr->cadet_retry_count >= CADET_RETRY_MAX) + return; /* give up on cadet */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); + /* retry -- without delay, as this is non-anonymous + and cadet/cadet connect will take some time anyway */ + pr->cadet_request = GSF_cadet_query(pr->public_data.target, + &pr->public_data.query, + pr->public_data.type, + &cadet_reply_proc, + pr); + return; + } if (GNUNET_YES != - GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, data_size, &query)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to derive key for block of type %d\n", - (int) type); - GNUNET_break_op (0); - return; - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Replies received from CADET"), - 1, - GNUNET_NO); - memset (&prq, 0, sizeof (prq)); + GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, data_size, &query)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Failed to derive key for block of type %d\n", + (int)type); + GNUNET_break_op(0); + return; + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Replies received from CADET"), + 1, + GNUNET_NO); + memset(&prq, 0, sizeof(prq)); prq.data = data; prq.expiration = expiration; /* do not allow migrated content to live longer than 1 year */ - prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_YEARS), - prq.expiration); + prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_UNIT_YEARS), + prq.expiration); prq.size = data_size; prq.type = type; prq.eo = GNUNET_BLOCK_EO_NONE; - process_reply (&prq, &query, pr); + process_reply(&prq, &query, pr); } @@ -1276,23 +1279,23 @@ cadet_reply_proc (void *cls, * @param pr the pending request to process */ void -GSF_cadet_lookup_ (struct GSF_PendingRequest *pr) +GSF_cadet_lookup_(struct GSF_PendingRequest *pr) { if (0 != pr->public_data.anonymity_level) return; if (0 == pr->public_data.target) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cannot do cadet-based download, target peer not known\n"); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Cannot do cadet-based download, target peer not known\n"); + return; + } if (NULL != pr->cadet_request) return; - pr->cadet_request = GSF_cadet_query (pr->public_data.target, - &pr->public_data.query, - pr->public_data.type, - &cadet_reply_proc, - pr); + pr->cadet_request = GSF_cadet_query(pr->public_data.target, + &pr->public_data.query, + pr->public_data.type, + &cadet_reply_proc, + pr); } @@ -1302,18 +1305,18 @@ GSF_cadet_lookup_ (struct GSF_PendingRequest *pr) * @param cls the `struct GSF_PendingRequest` */ static void -warn_delay_task (void *cls) +warn_delay_task(void *cls) { struct GSF_PendingRequest *pr = cls; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _ ("Datastore lookup already took %s!\n"), - GNUNET_STRINGS_relative_time_to_string ( - GNUNET_TIME_absolute_get_duration (pr->qe_start), - GNUNET_YES)); - pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &warn_delay_task, - pr); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _("Datastore lookup already took %s!\n"), + GNUNET_STRINGS_relative_time_to_string( + GNUNET_TIME_absolute_get_duration(pr->qe_start), + GNUNET_YES)); + pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, + &warn_delay_task, + pr); } @@ -1323,140 +1326,140 @@ warn_delay_task (void *cls) * @param cls the `struct GSF_PendingRequest` */ static void -odc_warn_delay_task (void *cls) +odc_warn_delay_task(void *cls) { struct GSF_PendingRequest *pr = cls; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("On-demand lookup already took %s!\n"), - GNUNET_STRINGS_relative_time_to_string ( - GNUNET_TIME_absolute_get_duration (pr->qe_start), - GNUNET_YES)); - pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &odc_warn_delay_task, - pr); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("On-demand lookup already took %s!\n"), + GNUNET_STRINGS_relative_time_to_string( + GNUNET_TIME_absolute_get_duration(pr->qe_start), + GNUNET_YES)); + pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, + &odc_warn_delay_task, + pr); } /* Call our continuation (if we have any) */ static void -call_continuation (struct GSF_PendingRequest *pr) +call_continuation(struct GSF_PendingRequest *pr) { GSF_LocalLookupContinuation cont = pr->llc_cont; - GNUNET_assert (NULL == pr->qe); + GNUNET_assert(NULL == pr->qe); if (NULL != pr->warn_task) - { - GNUNET_SCHEDULER_cancel (pr->warn_task); - pr->warn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(pr->warn_task); + pr->warn_task = NULL; + } if (NULL == cont) return; /* no continuation */ pr->llc_cont = NULL; if (0 != (GSF_PRO_LOCAL_ONLY & pr->public_data.options)) - { - if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) { - /* Signal that we are done and that there won't be any - additional results to allow client to clean up state. */ - pr->rh (pr->rh_cls, - GNUNET_BLOCK_EVALUATION_OK_LAST, - pr, - UINT32_MAX, - GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_BLOCK_TYPE_ANY, - NULL, - 0); + if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) + { + /* Signal that we are done and that there won't be any + additional results to allow client to clean up state. */ + pr->rh(pr->rh_cls, + GNUNET_BLOCK_EVALUATION_OK_LAST, + pr, + UINT32_MAX, + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_BLOCK_TYPE_ANY, + NULL, + 0); + } + /* Finally, call our continuation to signal that we are + done with local processing of this request; i.e. to + start reading again from the client. */ + cont(pr->llc_cont_cls, NULL, GNUNET_BLOCK_EVALUATION_OK_LAST); + return; } - /* Finally, call our continuation to signal that we are - done with local processing of this request; i.e. to - start reading again from the client. */ - cont (pr->llc_cont_cls, NULL, GNUNET_BLOCK_EVALUATION_OK_LAST); - return; - } - cont (pr->llc_cont_cls, pr, pr->local_result); + cont(pr->llc_cont_cls, pr, pr->local_result); } /* Update stats and call continuation */ static void -no_more_local_results (struct GSF_PendingRequest *pr) +no_more_local_results(struct GSF_PendingRequest *pr) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "No further local responses available.\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "No further local responses available.\n"); #if INSANE_STATISTICS if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == pr->public_data.type) || (GNUNET_BLOCK_TYPE_FS_IBLOCK == pr->public_data.type)) - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# requested DBLOCK or IBLOCK not found"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# requested DBLOCK or IBLOCK not found"), + 1, + GNUNET_NO); #endif - call_continuation (pr); + call_continuation(pr); } /* forward declaration */ static void -process_local_reply (void *cls, - const struct GNUNET_HashCode *key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid); +process_local_reply(void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid); /* Start a local query */ static void -start_local_query (struct GSF_PendingRequest *pr, - uint64_t next_uid, - bool random) +start_local_query(struct GSF_PendingRequest *pr, + uint64_t next_uid, + bool random) { - pr->qe_start = GNUNET_TIME_absolute_get (); - pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &warn_delay_task, - pr); - pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, - next_uid, - random, - &pr->public_data.query, - pr->public_data.type == - GNUNET_BLOCK_TYPE_FS_DBLOCK - ? GNUNET_BLOCK_TYPE_ANY - : pr->public_data.type, - (0 != (GSF_PRO_PRIORITY_UNLIMITED & - pr->public_data.options)) - ? UINT_MAX - : 1 - /* queue priority */, - (0 != (GSF_PRO_PRIORITY_UNLIMITED & - pr->public_data.options)) - ? UINT_MAX - : GSF_datastore_queue_size - /* max queue size */, - &process_local_reply, - pr); + pr->qe_start = GNUNET_TIME_absolute_get(); + pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, + &warn_delay_task, + pr); + pr->qe = GNUNET_DATASTORE_get_key(GSF_dsh, + next_uid, + random, + &pr->public_data.query, + pr->public_data.type == + GNUNET_BLOCK_TYPE_FS_DBLOCK + ? GNUNET_BLOCK_TYPE_ANY + : pr->public_data.type, + (0 != (GSF_PRO_PRIORITY_UNLIMITED & + pr->public_data.options)) + ? UINT_MAX + : 1 + /* queue priority */, + (0 != (GSF_PRO_PRIORITY_UNLIMITED & + pr->public_data.options)) + ? UINT_MAX + : GSF_datastore_queue_size + /* max queue size */, + &process_local_reply, + pr); if (NULL != pr->qe) return; - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "ERROR Requesting `%s' of type %d with next_uid %llu from datastore.\n", - GNUNET_h2s (&pr->public_data.query), + GNUNET_h2s(&pr->public_data.query), pr->public_data.type, - (unsigned long long) next_uid); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# Datastore lookups concluded (error queueing)"), - 1, - GNUNET_NO); - call_continuation (pr); + (unsigned long long)next_uid); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# Datastore lookups concluded (error queueing)"), + 1, + GNUNET_NO); + call_continuation(pr); } @@ -1479,178 +1482,178 @@ start_local_query (struct GSF_PendingRequest *pr, * maybe 0 if no unique identifier is available */ static void -process_local_reply (void *cls, - const struct GNUNET_HashCode *key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid) +process_local_reply(void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid) { struct GSF_PendingRequest *pr = cls; struct ProcessReplyClosure prq; struct GNUNET_HashCode query; unsigned int old_rf; - GNUNET_SCHEDULER_cancel (pr->warn_task); + GNUNET_SCHEDULER_cancel(pr->warn_task); pr->warn_task = NULL; if (NULL == pr->qe) goto called_from_on_demand; pr->qe = NULL; if ( (NULL == key) && pr->seen_null && - ! pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ - { - /* No results */ + !pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ + { + /* No results */ #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# Datastore lookups concluded (no results)"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# Datastore lookups concluded (no results)"), + 1, + GNUNET_NO); #endif - no_more_local_results (pr); - return; - } + no_more_local_results(pr); + return; + } if (((NULL == key) && pr->seen_null) || /* We have hit the end for the 2nd time OR */ (pr->seen_null && pr->have_first_uid && (uid >= pr->first_uid))) /* We have hit the end and past first UID */ - { - /* Seen all results */ - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# Datastore lookups concluded (seen all)"), - 1, - GNUNET_NO); - no_more_local_results (pr); - return; - } + { + /* Seen all results */ + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# Datastore lookups concluded (seen all)"), + 1, + GNUNET_NO); + no_more_local_results(pr); + return; + } if (NULL == key) - { - GNUNET_assert (! pr->seen_null); - pr->seen_null = true; - start_local_query (pr, 0 /* next_uid */, false /* random */); - return; - } - if (! pr->have_first_uid) - { - pr->first_uid = uid; - pr->have_first_uid = true; - } + { + GNUNET_assert(!pr->seen_null); + pr->seen_null = true; + start_local_query(pr, 0 /* next_uid */, false /* random */); + return; + } + if (!pr->have_first_uid) + { + pr->first_uid = uid; + pr->have_first_uid = true; + } pr->result_count++; if (pr->result_count > MAX_RESULTS) - { - GNUNET_STATISTICS_update ( - GSF_stats, - gettext_noop ("# Datastore lookups aborted (more than MAX_RESULTS)"), - 1, - GNUNET_NO); - no_more_local_results (pr); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received reply for `%s' of type %d with UID %llu from datastore.\n", - GNUNET_h2s (key), - type, - (unsigned long long) uid); + { + GNUNET_STATISTICS_update( + GSF_stats, + gettext_noop("# Datastore lookups aborted (more than MAX_RESULTS)"), + 1, + GNUNET_NO); + no_more_local_results(pr); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received reply for `%s' of type %d with UID %llu from datastore.\n", + GNUNET_h2s(key), + type, + (unsigned long long)uid); if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found ONDEMAND block, performing on-demand encoding\n"); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# on-demand blocks matched requests"), - 1, - GNUNET_NO); - pr->qe_start = GNUNET_TIME_absolute_get (); - pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &odc_warn_delay_task, - pr); - if (GNUNET_OK == GNUNET_FS_handle_on_demand_block (key, - size, - data, - type, - priority, - anonymity, - replication, - expiration, - uid, - &process_local_reply, - pr)) { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# on-demand lookups performed successfully"), - 1, - GNUNET_NO); - return; /* we're done */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Found ONDEMAND block, performing on-demand encoding\n"); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# on-demand blocks matched requests"), + 1, + GNUNET_NO); + pr->qe_start = GNUNET_TIME_absolute_get(); + pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, + &odc_warn_delay_task, + pr); + if (GNUNET_OK == GNUNET_FS_handle_on_demand_block(key, + size, + data, + type, + priority, + anonymity, + replication, + expiration, + uid, + &process_local_reply, + pr)) + { + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# on-demand lookups performed successfully"), + 1, + GNUNET_NO); + return; /* we're done */ + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# on-demand lookups failed"), + 1, + GNUNET_NO); + GNUNET_SCHEDULER_cancel(pr->warn_task); + start_local_query(pr, uid + 1 /* next_uid */, false /* random */); + return; } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# on-demand lookups failed"), - 1, - GNUNET_NO); - GNUNET_SCHEDULER_cancel (pr->warn_task); - start_local_query (pr, uid + 1 /* next_uid */, false /* random */); - return; - } called_from_on_demand: old_rf = pr->public_data.results_found; - memset (&prq, 0, sizeof (prq)); + memset(&prq, 0, sizeof(prq)); prq.data = data; prq.expiration = expiration; prq.size = size; if (GNUNET_OK != - GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) - { - GNUNET_break (0); - GNUNET_DATASTORE_remove (GSF_dsh, - key, - size, - data, - UINT_MAX, - UINT_MAX, - NULL, - NULL); - start_local_query (pr, uid + 1 /* next_uid */, false /* random */); - return; - } + GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, size, &query)) + { + GNUNET_break(0); + GNUNET_DATASTORE_remove(GSF_dsh, + key, + size, + data, + UINT_MAX, + UINT_MAX, + NULL, + NULL); + start_local_query(pr, uid + 1 /* next_uid */, false /* random */); + return; + } prq.type = type; prq.priority = priority; prq.request_found = GNUNET_NO; prq.anonymity_level = anonymity; if ((0 == old_rf) && (0 == pr->public_data.results_found)) - GSF_update_datastore_delay_ (pr->public_data.start_time); + GSF_update_datastore_delay_(pr->public_data.start_time); prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; - process_reply (&prq, key, pr); + process_reply(&prq, key, pr); pr->local_result = prq.eval; if (GNUNET_BLOCK_EVALUATION_OK_LAST == prq.eval) - { - GNUNET_STATISTICS_update ( - GSF_stats, - gettext_noop ("# Datastore lookups concluded (found last result)"), - 1, - GNUNET_NO); - call_continuation (pr); - return; - } + { + GNUNET_STATISTICS_update( + GSF_stats, + gettext_noop("# Datastore lookups concluded (found last result)"), + 1, + GNUNET_NO); + call_continuation(pr); + return; + } if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && - ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) || + ((GNUNET_YES == GSF_test_get_load_too_high_(0)) || (pr->public_data.results_found > 5 + 2 * pr->public_data.priority))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ( - "# Datastore lookups concluded (load too high)"), - 1, - GNUNET_NO); - call_continuation (pr); - return; - } - start_local_query (pr, uid + 1 /* next_uid */, false /* random */); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop( + "# Datastore lookups concluded (load too high)"), + 1, + GNUNET_NO); + call_continuation(pr); + return; + } + start_local_query(pr, uid + 1 /* next_uid */, false /* random */); } @@ -1662,17 +1665,17 @@ called_from_on_demand: * @return #GNUNET_YES if this request could be forwarded to the given peer */ int -GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, - const struct GNUNET_PeerIdentity *target) +GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, + const struct GNUNET_PeerIdentity *target) { struct GNUNET_PeerIdentity pi; if (0 == pr->origin_pid) return GNUNET_YES; - GNUNET_PEER_resolve (pr->origin_pid, &pi); - return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) - ? GNUNET_NO - : GNUNET_YES; + GNUNET_PEER_resolve(pr->origin_pid, &pi); + return (0 == memcmp(&pi, target, sizeof(struct GNUNET_PeerIdentity))) + ? GNUNET_NO + : GNUNET_YES; } @@ -1684,22 +1687,22 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, * @param cont_cls closure for @a cont */ void -GSF_local_lookup_ (struct GSF_PendingRequest *pr, - GSF_LocalLookupContinuation cont, - void *cont_cls) +GSF_local_lookup_(struct GSF_PendingRequest *pr, + GSF_LocalLookupContinuation cont, + void *cont_cls) { - GNUNET_assert (NULL == pr->gh); - GNUNET_assert (NULL == pr->cadet_request); - GNUNET_assert (NULL == pr->llc_cont); + GNUNET_assert(NULL == pr->gh); + GNUNET_assert(NULL == pr->cadet_request); + GNUNET_assert(NULL == pr->llc_cont); pr->llc_cont = cont; pr->llc_cont_cls = cont_cls; #if INSANE_STATISTICS - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# Datastore lookups initiated"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# Datastore lookups initiated"), + 1, + GNUNET_NO); #endif - start_local_query (pr, 0 /* next_uid */, true /* random */); + start_local_query(pr, 0 /* next_uid */, true /* random */); } @@ -1713,7 +1716,7 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, * @param put the actual message */ void -handle_p2p_put (void *cls, const struct PutMessage *put) +handle_p2p_put(void *cls, const struct PutMessage *put) { struct GSF_ConnectedPeer *cp = cls; uint16_t msize; @@ -1726,30 +1729,30 @@ handle_p2p_put (void *cls, const struct PutMessage *put) double putl; struct PutMigrationContext *pmc; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received P2P PUT from %s\n", - GNUNET_i2s (GSF_get_peer_performance_data_ (cp)->peer)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received P2P PUT from %s\n", + GNUNET_i2s(GSF_get_peer_performance_data_(cp)->peer)); GSF_cover_content_count++; - msize = ntohs (put->header.size); - dsize = msize - sizeof (struct PutMessage); - type = ntohl (put->type); - expiration = GNUNET_TIME_absolute_ntoh (put->expiration); + msize = ntohs(put->header.size); + dsize = msize - sizeof(struct PutMessage); + type = ntohl(put->type); + expiration = GNUNET_TIME_absolute_ntoh(put->expiration); /* do not allow migrated content to live longer than 1 year */ - expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_YEARS), - expiration); + expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_UNIT_YEARS), + expiration); if (GNUNET_OK != - GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query)) - { - GNUNET_break_op (0); - return; - } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# GAP PUT messages received"), - 1, - GNUNET_NO); + GNUNET_BLOCK_get_key(GSF_block_ctx, type, &put[1], dsize, &query)) + { + GNUNET_break_op(0); + return; + } + GNUNET_STATISTICS_update(GSF_stats, + gettext_noop("# GAP PUT messages received"), + 1, + GNUNET_NO); /* now, lookup 'query' */ - prq.data = (const void *) &put[1]; + prq.data = (const void *)&put[1]; prq.sender = cp; prq.size = dsize; prq.type = type; @@ -1758,80 +1761,80 @@ handle_p2p_put (void *cls, const struct PutMessage *put) prq.anonymity_level = UINT32_MAX; prq.request_found = GNUNET_NO; prq.eo = GNUNET_BLOCK_EO_NONE; - GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, - &query, - &process_reply, - &prq); + GNUNET_CONTAINER_multihashmap_get_multiple(pr_map, + &query, + &process_reply, + &prq); if (NULL != cp) - { - GSF_connected_peer_change_preference_ (cp, - CONTENT_BANDWIDTH_VALUE + - 1000 * prq.priority); - GSF_get_peer_performance_data_ (cp)->respect += prq.priority; - } + { + GSF_connected_peer_change_preference_(cp, + CONTENT_BANDWIDTH_VALUE + + 1000 * prq.priority); + GSF_get_peer_performance_data_(cp)->respect += prq.priority; + } if ((GNUNET_YES == active_to_migration) && (NULL != cp) && - (GNUNET_NO == test_put_load_too_high (prq.priority))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Replicating result for query `%s' with priority %u\n", - GNUNET_h2s (&query), - prq.priority); - pmc = GNUNET_new (struct PutMigrationContext); - pmc->start = GNUNET_TIME_absolute_get (); - pmc->requested = prq.request_found; - GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid); - GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, - &pmc->origin); - if (NULL == GNUNET_DATASTORE_put (GSF_dsh, - 0, - &query, - dsize, - &put[1], - type, - prq.priority, - 1 /* anonymity */, - 0 /* replication */, - expiration, - 1 + prq.priority, - MAX_DATASTORE_QUEUE, - &put_migration_continuation, - pmc)) + (GNUNET_NO == test_put_load_too_high(prq.priority))) { - put_migration_continuation (pmc, - GNUNET_SYSERR, - GNUNET_TIME_UNIT_ZERO_ABS, - NULL); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Replicating result for query `%s' with priority %u\n", + GNUNET_h2s(&query), + prq.priority); + pmc = GNUNET_new(struct PutMigrationContext); + pmc->start = GNUNET_TIME_absolute_get(); + pmc->requested = prq.request_found; + GNUNET_assert(0 != GSF_get_peer_performance_data_(cp)->pid); + GNUNET_PEER_resolve(GSF_get_peer_performance_data_(cp)->pid, + &pmc->origin); + if (NULL == GNUNET_DATASTORE_put(GSF_dsh, + 0, + &query, + dsize, + &put[1], + type, + prq.priority, + 1 /* anonymity */, + 0 /* replication */, + expiration, + 1 + prq.priority, + MAX_DATASTORE_QUEUE, + &put_migration_continuation, + pmc)) + { + put_migration_continuation(pmc, + GNUNET_SYSERR, + GNUNET_TIME_UNIT_ZERO_ABS, + NULL); + } } - } else if (NULL != cp) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Choosing not to keep content `%s' (%d/%d)\n", - GNUNET_h2s (&query), - active_to_migration, - test_put_load_too_high (prq.priority)); - } - putl = GNUNET_LOAD_get_load (datastore_put_load); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Choosing not to keep content `%s' (%d/%d)\n", + GNUNET_h2s(&query), + active_to_migration, + test_put_load_too_high(prq.priority)); + } + putl = GNUNET_LOAD_get_load(datastore_put_load); if ((NULL != cp) && (GNUNET_NO == prq.request_found) && ((GNUNET_YES != active_to_migration) || (putl > 2.5 * (1 + prq.priority)))) - { - if (GNUNET_YES != active_to_migration) - putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5); - block_time = GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - 5000 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - (unsigned int) (60000 * putl * putl))); - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Asking to stop migration for %s because of load %f and events %d/%d\n", - GNUNET_STRINGS_relative_time_to_string (block_time, GNUNET_YES), - putl, - active_to_migration, - (GNUNET_NO == prq.request_found)); - GSF_block_peer_migration_ (cp, - GNUNET_TIME_relative_to_absolute (block_time)); - } + { + if (GNUNET_YES != active_to_migration) + putl = 1.0 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 5); + block_time = GNUNET_TIME_relative_multiply( + GNUNET_TIME_UNIT_MILLISECONDS, + 5000 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, + (unsigned int)(60000 * putl * putl))); + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Asking to stop migration for %s because of load %f and events %d/%d\n", + GNUNET_STRINGS_relative_time_to_string(block_time, GNUNET_YES), + putl, + active_to_migration, + (GNUNET_NO == prq.request_found)); + GSF_block_peer_migration_(cp, + GNUNET_TIME_relative_to_absolute(block_time)); + } } @@ -1842,7 +1845,7 @@ handle_p2p_put (void *cls, const struct PutMessage *put) * @return #GNUNET_YES if the request is still active */ int -GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr) +GSF_pending_request_test_active_(struct GSF_PendingRequest *pr) { return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO; } @@ -1852,24 +1855,24 @@ GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr) * Setup the subsystem. */ void -GSF_pending_request_init_ () +GSF_pending_request_init_() { if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (GSF_cfg, - "fs", - "MAX_PENDING_REQUESTS", - &max_pending_requests)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, - "fs", - "MAX_PENDING_REQUESTS"); - } + GNUNET_CONFIGURATION_get_value_number(GSF_cfg, + "fs", + "MAX_PENDING_REQUESTS", + &max_pending_requests)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, + "fs", + "MAX_PENDING_REQUESTS"); + } active_to_migration = - GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING"); - datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); - pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024, GNUNET_YES); + GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, "FS", "CONTENT_CACHING"); + datastore_put_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); + pr_map = GNUNET_CONTAINER_multihashmap_create(32 * 1024, GNUNET_YES); requests_by_expiration_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); } @@ -1877,14 +1880,14 @@ GSF_pending_request_init_ () * Shutdown the subsystem. */ void -GSF_pending_request_done_ () +GSF_pending_request_done_() { - GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL); - GNUNET_CONTAINER_multihashmap_destroy (pr_map); + GNUNET_CONTAINER_multihashmap_iterate(pr_map, &clean_request, NULL); + GNUNET_CONTAINER_multihashmap_destroy(pr_map); pr_map = NULL; - GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap); + GNUNET_CONTAINER_heap_destroy(requests_by_expiration_heap); requests_by_expiration_heap = NULL; - GNUNET_LOAD_value_free (datastore_put_load); + GNUNET_LOAD_value_free(datastore_put_load); datastore_put_load = NULL; } diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h index abdb0c9f6..39e471c4d 100644 --- a/src/fs/gnunet-service-fs_pr.h +++ b/src/fs/gnunet-service-fs_pr.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_pr.h @@ -32,9 +32,7 @@ /** * Options for pending requests (bits to be ORed). */ -enum GSF_PendingRequestOptions -{ - +enum GSF_PendingRequestOptions { /** * No special options (P2P-default). */ @@ -69,7 +67,7 @@ enum GSF_PendingRequestOptions * Option mask for typical local requests. */ GSF_PRO_LOCAL_REQUEST = - (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES) + (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES) }; @@ -78,9 +76,7 @@ enum GSF_PendingRequestOptions * 'gnunet-service-fs_pr', not in the sense of network-wide * known) associated with each pending request. */ -struct GSF_PendingRequestData -{ - +struct GSF_PendingRequestData { /** * Primary query hash for this request. */ @@ -163,7 +159,6 @@ struct GSF_PendingRequestData * we still constructing it? */ int has_started; - }; @@ -220,22 +215,22 @@ typedef void * @return handle for the new pending request */ struct GSF_PendingRequest * -GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, - enum GNUNET_BLOCK_Type type, - const struct GNUNET_HashCode *query, - const struct GNUNET_PeerIdentity *target, - const char *bf_data, - size_t bf_size, - uint32_t mingle, - uint32_t anonymity_level, - uint32_t priority, - int32_t ttl, - GNUNET_PEER_Id sender_pid, - GNUNET_PEER_Id origin_pid, - const struct GNUNET_HashCode *replies_seen, - unsigned int replies_seen_count, - GSF_PendingRequestReplyHandler rh, - void *rh_cls); +GSF_pending_request_create_(enum GSF_PendingRequestOptions options, + enum GNUNET_BLOCK_Type type, + const struct GNUNET_HashCode *query, + const struct GNUNET_PeerIdentity *target, + const char *bf_data, + size_t bf_size, + uint32_t mingle, + uint32_t anonymity_level, + uint32_t priority, + int32_t ttl, + GNUNET_PEER_Id sender_pid, + GNUNET_PEER_Id origin_pid, + const struct GNUNET_HashCode *replies_seen, + unsigned int replies_seen_count, + GSF_PendingRequestReplyHandler rh, + void *rh_cls); /** @@ -247,9 +242,9 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, * @param replies_seen_count size of the @a replies_seen array */ void -GSF_pending_request_update_ (struct GSF_PendingRequest *pr, - const struct GNUNET_HashCode *replies_seen, - unsigned int replies_seen_count); +GSF_pending_request_update_(struct GSF_PendingRequest *pr, + const struct GNUNET_HashCode *replies_seen, + unsigned int replies_seen_count); /** @@ -259,7 +254,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, * @return associated public data */ struct GSF_PendingRequestData * -GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); +GSF_pending_request_get_data_(struct GSF_PendingRequest *pr); /** @@ -269,7 +264,7 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); * @return #GNUNET_YES if the request is still active */ int -GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr); +GSF_pending_request_test_active_(struct GSF_PendingRequest *pr); /** @@ -282,8 +277,8 @@ GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr); * @return #GNUNET_OK if the requests are compatible */ int -GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, - struct GSF_PendingRequest *prb); +GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, + struct GSF_PendingRequest *prb); /** @@ -294,7 +289,7 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, * @return envelope with the request message */ struct GNUNET_MQ_Envelope * -GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr); +GSF_pending_request_get_message_(struct GSF_PendingRequest *pr); /** @@ -304,8 +299,8 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr); * @param full_cleanup fully purge the request */ void -GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, - int full_cleanup); +GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, + int full_cleanup); /** @@ -330,8 +325,8 @@ typedef int * @param cls closure for it */ void -GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, - void *cls); +GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, + void *cls); /** @@ -344,8 +339,8 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, * @param put the actual message */ void -handle_p2p_put (void *cls, - const struct PutMessage *put); +handle_p2p_put(void *cls, + const struct PutMessage *put); /** @@ -354,7 +349,7 @@ handle_p2p_put (void *cls, * @param pr the pending request to process */ void -GSF_dht_lookup_ (struct GSF_PendingRequest *pr); +GSF_dht_lookup_(struct GSF_PendingRequest *pr); /** @@ -363,7 +358,7 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr); * @param pr the pending request to process */ void -GSF_cadet_lookup_ (struct GSF_PendingRequest *pr); +GSF_cadet_lookup_(struct GSF_PendingRequest *pr); /** @@ -388,9 +383,9 @@ typedef void * @param cont_cls closure for @a cont */ void -GSF_local_lookup_ (struct GSF_PendingRequest *pr, - GSF_LocalLookupContinuation cont, - void *cont_cls); +GSF_local_lookup_(struct GSF_PendingRequest *pr, + GSF_LocalLookupContinuation cont, + void *cont_cls); /** @@ -401,8 +396,8 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, * @return #GNUNET_YES if this request could be forwarded to the given peer */ int -GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, - const struct GNUNET_PeerIdentity *target); +GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, + const struct GNUNET_PeerIdentity *target); @@ -410,14 +405,14 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, * Setup the subsystem. */ void -GSF_pending_request_init_ (void); +GSF_pending_request_init_(void); /** * Shutdown the subsystem. */ void -GSF_pending_request_done_ (void); +GSF_pending_request_done_(void); #endif diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index a75f17f82..162dcc0b5 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_push.c @@ -49,15 +49,13 @@ * that if this value is increased, the migration testcase may need to be * adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c). */ -#define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) +#define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) /** * Block that is ready for migration to other peers. Actual data is at the end of the block. */ -struct MigrationReadyBlock -{ - +struct MigrationReadyBlock { /** * This is a doubly-linked list. */ @@ -104,8 +102,7 @@ struct MigrationReadyBlock /** * Information about a peer waiting for migratable data. */ -struct MigrationReadyPeer -{ +struct MigrationReadyPeer { /** * This is a doubly-linked list. */ @@ -186,15 +183,15 @@ static int value_found; * @param mb block to delete */ static void -delete_migration_block (struct MigrationReadyBlock *mb) +delete_migration_block(struct MigrationReadyBlock *mb) { - GNUNET_CONTAINER_DLL_remove (mig_head, - mig_tail, - mb); - GNUNET_PEER_decrement_rcs (mb->target_list, - MIGRATION_LIST_SIZE); + GNUNET_CONTAINER_DLL_remove(mig_head, + mig_tail, + mb); + GNUNET_PEER_decrement_rcs(mb->target_list, + MIGRATION_LIST_SIZE); mig_size--; - GNUNET_free (mb); + GNUNET_free(mb); } @@ -204,7 +201,7 @@ delete_migration_block (struct MigrationReadyBlock *mb) * @param cls a `struct MigrationReadyPeer *` */ static void -find_content (void *cls); +find_content(void *cls); /** @@ -215,50 +212,50 @@ find_content (void *cls); * @return #GNUNET_YES if the block was deleted (!) */ static int -transmit_content (struct MigrationReadyPeer *mrp, - struct MigrationReadyBlock *block) +transmit_content(struct MigrationReadyPeer *mrp, + struct MigrationReadyBlock *block) { struct PutMessage *msg; unsigned int i; struct GSF_PeerPerformanceData *ppd; int ret; - ppd = GSF_get_peer_performance_data_ (mrp->peer); - GNUNET_assert (NULL == mrp->env); - mrp->env = GNUNET_MQ_msg_extra (msg, - block->size, - GNUNET_MESSAGE_TYPE_FS_PUT); - msg->type = htonl (block->type); - msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); - GNUNET_memcpy (&msg[1], - &block[1], - block->size); + ppd = GSF_get_peer_performance_data_(mrp->peer); + GNUNET_assert(NULL == mrp->env); + mrp->env = GNUNET_MQ_msg_extra(msg, + block->size, + GNUNET_MESSAGE_TYPE_FS_PUT); + msg->type = htonl(block->type); + msg->expiration = GNUNET_TIME_absolute_hton(block->expiration); + GNUNET_memcpy(&msg[1], + &block[1], + block->size); for (i = 0; i < MIGRATION_LIST_SIZE; i++) - { - if (block->target_list[i] == 0) { - block->target_list[i] = ppd->pid; - GNUNET_PEER_change_rc (block->target_list[i], - 1); - break; + if (block->target_list[i] == 0) + { + block->target_list[i] = ppd->pid; + GNUNET_PEER_change_rc(block->target_list[i], + 1); + break; + } } - } if (MIGRATION_LIST_SIZE == i) - { - delete_migration_block (block); - ret = GNUNET_YES; - } + { + delete_migration_block(block); + ret = GNUNET_YES; + } else - { - ret = GNUNET_NO; - } - GNUNET_MQ_notify_sent (mrp->env, - &find_content, - mrp); - GSF_peer_transmit_ (mrp->peer, - GNUNET_NO, - 0 /* priority */ , - mrp->env); + { + ret = GNUNET_NO; + } + GNUNET_MQ_notify_sent(mrp->env, + &find_content, + mrp); + GSF_peer_transmit_(mrp->peer, + GNUNET_NO, + 0 /* priority */, + mrp->env); return ret; } @@ -271,7 +268,7 @@ transmit_content (struct MigrationReadyPeer *mrp, * @return number of times block was forwarded */ static unsigned int -count_targets (struct MigrationReadyBlock *block) +count_targets(struct MigrationReadyBlock *block) { unsigned int i; @@ -291,8 +288,8 @@ count_targets (struct MigrationReadyBlock *block) * @return score (>= 0: feasible, negative: infeasible) */ static long -score_content (struct MigrationReadyPeer *mrp, - struct MigrationReadyBlock *block) +score_content(struct MigrationReadyPeer *mrp, + struct MigrationReadyBlock *block) { unsigned int i; struct GSF_PeerPerformanceData *ppd; @@ -300,18 +297,18 @@ score_content (struct MigrationReadyPeer *mrp, struct GNUNET_HashCode hc; uint32_t dist; - ppd = GSF_get_peer_performance_data_ (mrp->peer); + ppd = GSF_get_peer_performance_data_(mrp->peer); for (i = 0; i < MIGRATION_LIST_SIZE; i++) if (block->target_list[i] == ppd->pid) return -1; - GNUNET_assert (0 != ppd->pid); - GNUNET_PEER_resolve (ppd->pid, - &id); - GNUNET_CRYPTO_hash (&id, - sizeof (struct GNUNET_PeerIdentity), - &hc); - dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, - &hc); + GNUNET_assert(0 != ppd->pid); + GNUNET_PEER_resolve(ppd->pid, + &id); + GNUNET_CRYPTO_hash(&id, + sizeof(struct GNUNET_PeerIdentity), + &hc); + dist = GNUNET_CRYPTO_hash_distance_u32(&block->query, + &hc); /* closer distance, higher score: */ return UINT32_MAX - dist; } @@ -322,7 +319,7 @@ score_content (struct MigrationReadyPeer *mrp, * (re)scheduling it with the appropriate delay. */ static void -consider_gathering (void); +consider_gathering(void); /** @@ -331,7 +328,7 @@ consider_gathering (void); * @param cls peer to find content for */ static void -find_content (void *cls) +find_content(void *cls) { struct MigrationReadyPeer *mrp = cls; struct MigrationReadyBlock *pos; @@ -344,48 +341,48 @@ find_content (void *cls) best_score = -1; pos = mig_head; while (NULL != pos) - { - score = score_content (mrp, pos); - if (score > best_score) { - best_score = score; - best = pos; + score = score_content(mrp, pos); + if (score > best_score) + { + best_score = score; + best = pos; + } + pos = pos->next; } - pos = pos->next; - } if (NULL == best) - { - if (mig_size < MAX_MIGRATION_QUEUE) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No content found for pushing, waiting for queue to fill\n"); - return; /* will fill up eventually... */ - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No suitable content found, purging content from full queue\n"); - /* failed to find migration target AND - * queue is full, purge most-forwarded - * block from queue to make room for more */ - pos = mig_head; - while (NULL != pos) - { - score = count_targets (pos); - if (score >= best_score) - { - best_score = score; - best = pos; - } - pos = pos->next; + if (mig_size < MAX_MIGRATION_QUEUE) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No content found for pushing, waiting for queue to fill\n"); + return; /* will fill up eventually... */ + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No suitable content found, purging content from full queue\n"); + /* failed to find migration target AND + * queue is full, purge most-forwarded + * block from queue to make room for more */ + pos = mig_head; + while (NULL != pos) + { + score = count_targets(pos); + if (score >= best_score) + { + best_score = score; + best = pos; + } + pos = pos->next; + } + GNUNET_assert(NULL != best); + delete_migration_block(best); + consider_gathering(); + return; } - GNUNET_assert (NULL != best); - delete_migration_block (best); - consider_gathering (); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing to push best content to peer\n"); - transmit_content (mrp, - best); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Preparing to push best content to peer\n"); + transmit_content(mrp, + best); } @@ -396,7 +393,7 @@ find_content (void *cls) * @param cls unused */ static void -gather_migration_blocks (void *cls); +gather_migration_blocks(void *cls); /** @@ -404,7 +401,7 @@ gather_migration_blocks (void *cls); * (re)scheduling it with the appropriate delay. */ static void -consider_gathering () +consider_gathering() { struct GNUNET_TIME_Relative delay; @@ -416,25 +413,25 @@ consider_gathering () return; if (mig_size >= MAX_MIGRATION_QUEUE) return; - delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - mig_size); - delay = GNUNET_TIME_relative_divide (delay, - MAX_MIGRATION_QUEUE); - delay = GNUNET_TIME_relative_max (delay, - min_migration_delay); + delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + mig_size); + delay = GNUNET_TIME_relative_divide(delay, + MAX_MIGRATION_QUEUE); + delay = GNUNET_TIME_relative_max(delay, + min_migration_delay); if (GNUNET_NO == value_found) - { - /* wait at least 5s if the datastore is empty */ - delay = GNUNET_TIME_relative_max (delay, - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + { + /* wait at least 5s if the datastore is empty */ + delay = GNUNET_TIME_relative_max(delay, + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling gathering task (queue size: %u)\n", - mig_size); - mig_task = GNUNET_SCHEDULER_add_delayed (delay, - &gather_migration_blocks, - NULL); + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Scheduling gathering task (queue size: %u)\n", + mig_size); + mig_task = GNUNET_SCHEDULER_add_delayed(delay, + &gather_migration_blocks, + NULL); } @@ -454,81 +451,82 @@ consider_gathering () * maybe 0 if no unique identifier is available */ static void -process_migration_content (void *cls, - const struct GNUNET_HashCode *key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid) +process_migration_content(void *cls, + const struct GNUNET_HashCode *key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid) { struct MigrationReadyBlock *mb; struct MigrationReadyPeer *pos; mig_qe = NULL; if (NULL == key) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No content found for migration...\n"); - consider_gathering (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No content found for migration...\n"); + consider_gathering(); + return; + } value_found = GNUNET_YES; - if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < + if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) - { - /* content will expire soon, don't bother */ - consider_gathering (); - return; - } + { + /* content will expire soon, don't bother */ + consider_gathering(); + return; + } if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) - { - if (GNUNET_OK != - GNUNET_FS_handle_on_demand_block (key, - size, - data, - type, - priority, - anonymity, - replication, - expiration, - uid, - &process_migration_content, - NULL)) - consider_gathering (); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", - GNUNET_h2s (key), - type, mig_size + 1, - MAX_MIGRATION_QUEUE); - mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size); + { + if (GNUNET_OK != + GNUNET_FS_handle_on_demand_block(key, + size, + data, + type, + priority, + anonymity, + replication, + expiration, + uid, + &process_migration_content, + NULL)) + consider_gathering(); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", + GNUNET_h2s(key), + type, mig_size + 1, + MAX_MIGRATION_QUEUE); + mb = GNUNET_malloc(sizeof(struct MigrationReadyBlock) + size); mb->query = *key; mb->expiration = expiration; mb->size = size; mb->type = type; - GNUNET_memcpy (&mb[1], data, size); - GNUNET_CONTAINER_DLL_insert_after (mig_head, - mig_tail, - mig_tail, - mb); + GNUNET_memcpy(&mb[1], data, size); + GNUNET_CONTAINER_DLL_insert_after(mig_head, + mig_tail, + mig_tail, + mb); mig_size++; for (pos = peer_head; NULL != pos; pos = pos->next) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing to push best content to peer %s\n", - GNUNET_i2s (GSF_connected_peer_get_identity2_(pos->peer))); - if ( (NULL == pos->env) && - (GNUNET_YES == transmit_content (pos, - mb)) ) { - break; /* 'mb' was freed! */ + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Preparing to push best content to peer %s\n", + GNUNET_i2s(GSF_connected_peer_get_identity2_(pos->peer))); + if ((NULL == pos->env) && + (GNUNET_YES == transmit_content(pos, + mb))) + { + break; /* 'mb' was freed! */ + } } - } - consider_gathering (); + consider_gathering(); } @@ -539,24 +537,24 @@ process_migration_content (void *cls, * @param cls unused */ static void -gather_migration_blocks (void *cls) +gather_migration_blocks(void *cls) { mig_task = NULL; if (mig_size >= MAX_MIGRATION_QUEUE) return; if (NULL == GSF_dsh) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking datastore for content for replication (queue size: %u)\n", - mig_size); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Asking datastore for content for replication (queue size: %u)\n", + mig_size); value_found = GNUNET_NO; - mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, - 0, - UINT_MAX, - &process_migration_content, - NULL); + mig_qe = GNUNET_DATASTORE_get_for_replication(GSF_dsh, + 0, + UINT_MAX, + &process_migration_content, + NULL); if (NULL == mig_qe) - consider_gathering (); + consider_gathering(); } @@ -567,7 +565,7 @@ gather_migration_blocks (void *cls) * @param peer handle for the peer that connected */ void -GSF_push_start_ (struct GSF_ConnectedPeer *peer) +GSF_push_start_(struct GSF_ConnectedPeer *peer) { struct MigrationReadyPeer *mrp; @@ -577,22 +575,22 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer) if (mrp->peer == peer) break; if (NULL != mrp) - { - /* same peer added twice, must not happen */ - GNUNET_break (0); - return; - } + { + /* same peer added twice, must not happen */ + GNUNET_break(0); + return; + } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding peer %s to list for pushing\n", - GNUNET_i2s (GSF_connected_peer_get_identity2_(peer))); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Adding peer %s to list for pushing\n", + GNUNET_i2s(GSF_connected_peer_get_identity2_(peer))); - mrp = GNUNET_new (struct MigrationReadyPeer); + mrp = GNUNET_new(struct MigrationReadyPeer); mrp->peer = peer; - find_content (mrp); - GNUNET_CONTAINER_DLL_insert (peer_head, - peer_tail, - mrp); + find_content(mrp); + GNUNET_CONTAINER_DLL_insert(peer_head, + peer_tail, + mrp); } @@ -603,7 +601,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer) * @param peer handle for the peer that disconnected */ void -GSF_push_stop_ (struct GSF_ConnectedPeer *peer) +GSF_push_stop_(struct GSF_ConnectedPeer *peer) { struct MigrationReadyPeer *pos; @@ -613,11 +611,11 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer) if (NULL == pos) return; if (NULL != pos->env) - GNUNET_MQ_send_cancel (pos->env); - GNUNET_CONTAINER_DLL_remove (peer_head, - peer_tail, - pos); - GNUNET_free (pos); + GNUNET_MQ_send_cancel(pos->env); + GNUNET_CONTAINER_DLL_remove(peer_head, + peer_tail, + pos); + GNUNET_free(pos); } @@ -625,28 +623,28 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer) * Setup the module. */ void -GSF_push_init_ () +GSF_push_init_() { enabled = - GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, - "FS", - "CONTENT_PUSHING"); + GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, + "FS", + "CONTENT_PUSHING"); if (GNUNET_YES != enabled) return; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (GSF_cfg, - "fs", - "MIN_MIGRATION_DELAY", - &min_migration_delay)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, - "fs", - "MIN_MIGRATION_DELAY", - _("time required, content pushing disabled")); - return; - } - consider_gathering (); + GNUNET_CONFIGURATION_get_value_time(GSF_cfg, + "fs", + "MIN_MIGRATION_DELAY", + &min_migration_delay)) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, + "fs", + "MIN_MIGRATION_DELAY", + _("time required, content pushing disabled")); + return; + } + consider_gathering(); } @@ -654,21 +652,21 @@ GSF_push_init_ () * Shutdown the module. */ void -GSF_push_done_ () +GSF_push_done_() { if (NULL != mig_task) - { - GNUNET_SCHEDULER_cancel (mig_task); - mig_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(mig_task); + mig_task = NULL; + } if (NULL != mig_qe) - { - GNUNET_DATASTORE_cancel (mig_qe); - mig_qe = NULL; - } + { + GNUNET_DATASTORE_cancel(mig_qe); + mig_qe = NULL; + } while (NULL != mig_head) - delete_migration_block (mig_head); - GNUNET_assert (0 == mig_size); + delete_migration_block(mig_head); + GNUNET_assert(0 == mig_size); } /* end of gnunet-service-fs_push.c */ diff --git a/src/fs/gnunet-service-fs_push.h b/src/fs/gnunet-service-fs_push.h index ab2d2204a..0917364e2 100644 --- a/src/fs/gnunet-service-fs_push.h +++ b/src/fs/gnunet-service-fs_push.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_push.h @@ -33,14 +33,14 @@ * Setup the module. */ void -GSF_push_init_ (void); +GSF_push_init_(void); /** * Shutdown the module. */ void -GSF_push_done_ (void); +GSF_push_done_(void); /** @@ -50,7 +50,7 @@ GSF_push_done_ (void); * @param peer handle for the peer that connected */ void -GSF_push_start_ (struct GSF_ConnectedPeer *peer); +GSF_push_start_(struct GSF_ConnectedPeer *peer); /** @@ -60,7 +60,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer); * @param peer handle for the peer that disconnected */ void -GSF_push_stop_ (struct GSF_ConnectedPeer *peer); +GSF_push_stop_(struct GSF_ConnectedPeer *peer); #endif diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index 78a4b98df..deba91a0c 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_put.c @@ -31,7 +31,7 @@ /** * How often do we at most PUT content into the DHT? */ -#define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /** * How many replicas do we try to create per PUT? @@ -42,9 +42,7 @@ /** * Context for each zero-anonymity iterator. */ -struct PutOperator -{ - +struct PutOperator { /** * Request to datastore for DHT PUTs (or NULL). */ @@ -88,8 +86,8 @@ struct PutOperator * of block that we're putting into the DHT). */ static struct PutOperator operators[] = { - {NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0}, - {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0} + { NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0 }, + { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 } }; @@ -100,7 +98,7 @@ static struct PutOperator operators[] = { * @param tc scheduler context (unused) */ static void -gather_dht_put_blocks (void *cls); +gather_dht_put_blocks(void *cls); /** @@ -109,25 +107,25 @@ gather_dht_put_blocks (void *cls); * @param po put operator to schedule */ static void -schedule_next_put (struct PutOperator *po) +schedule_next_put(struct PutOperator *po) { struct GNUNET_TIME_Relative delay; if (po->zero_anonymity_count_estimate > 0) - { - delay = - GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, - po->zero_anonymity_count_estimate); - delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ); - } + { + delay = + GNUNET_TIME_relative_divide(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, + po->zero_anonymity_count_estimate); + delay = GNUNET_TIME_relative_min(delay, MAX_DHT_PUT_FREQ); + } else - { - /* if we have NO zero-anonymity content yet, wait 5 minutes for some to - * (hopefully) appear */ - delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); - } + { + /* if we have NO zero-anonymity content yet, wait 5 minutes for some to + * (hopefully) appear */ + delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5); + } po->dht_task = - GNUNET_SCHEDULER_add_delayed (delay, &gather_dht_put_blocks, po); + GNUNET_SCHEDULER_add_delayed(delay, &gather_dht_put_blocks, po); } @@ -137,12 +135,12 @@ schedule_next_put (struct PutOperator *po) * @param cls type of blocks to gather */ static void -delay_dht_put_blocks (void *cls) +delay_dht_put_blocks(void *cls) { struct PutOperator *po = cls; po->dht_put = NULL; - schedule_next_put (po); + schedule_next_put(po); } @@ -152,12 +150,12 @@ delay_dht_put_blocks (void *cls) * @param cls type of blocks to gather */ static void -delay_dht_put_task (void *cls) +delay_dht_put_task(void *cls) { struct PutOperator *po = cls; po->dht_task = NULL; - schedule_next_put (po); + schedule_next_put(po); } @@ -177,45 +175,45 @@ delay_dht_put_task (void *cls) * maybe 0 if no unique identifier is available */ static void -process_dht_put_content (void *cls, - const struct GNUNET_HashCode * key, - size_t size, - const void *data, - enum GNUNET_BLOCK_Type type, - uint32_t priority, - uint32_t anonymity, - uint32_t replication, - struct GNUNET_TIME_Absolute expiration, - uint64_t uid) +process_dht_put_content(void *cls, + const struct GNUNET_HashCode * key, + size_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid) { struct PutOperator *po = cls; po->dht_qe = NULL; if (key == NULL) - { - po->zero_anonymity_count_estimate = po->result_count; - po->result_count = 0; - po->next_uid = 0; - po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); - return; - } + { + po->zero_anonymity_count_estimate = po->result_count; + po->result_count = 0; + po->next_uid = 0; + po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); + return; + } po->result_count++; po->next_uid = uid + 1; po->zero_anonymity_count_estimate = - GNUNET_MAX (po->result_count, po->zero_anonymity_count_estimate); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), - type); - po->dht_put = GNUNET_DHT_put (GSF_dht, - key, - DEFAULT_PUT_REPLICATION, - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - type, - size, - data, - expiration, - &delay_dht_put_blocks, - po); + GNUNET_MAX(po->result_count, po->zero_anonymity_count_estimate); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s(key), + type); + po->dht_put = GNUNET_DHT_put(GSF_dht, + key, + DEFAULT_PUT_REPLICATION, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + type, + size, + data, + expiration, + &delay_dht_put_blocks, + po); } @@ -225,21 +223,21 @@ process_dht_put_content (void *cls, * @param cls type of blocks to gather */ static void -gather_dht_put_blocks (void *cls) +gather_dht_put_blocks(void *cls) { struct PutOperator *po = cls; po->dht_task = NULL; po->dht_qe = - GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, - po->next_uid, - 0, - UINT_MAX, - po->dht_put_type, - &process_dht_put_content, - po); + GNUNET_DATASTORE_get_zero_anonymity(GSF_dsh, + po->next_uid, + 0, + UINT_MAX, + po->dht_put_type, + &process_dht_put_content, + po); if (NULL == po->dht_qe) - po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); + po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); } @@ -247,17 +245,17 @@ gather_dht_put_blocks (void *cls) * Setup the module. */ void -GSF_put_init_ () +GSF_put_init_() { unsigned int i; i = 0; while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) - { - operators[i].dht_task = - GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); - i++; - } + { + operators[i].dht_task = + GNUNET_SCHEDULER_add_now(&gather_dht_put_blocks, &operators[i]); + i++; + } } @@ -265,31 +263,31 @@ GSF_put_init_ () * Shutdown the module. */ void -GSF_put_done_ () +GSF_put_done_() { struct PutOperator *po; unsigned int i; i = 0; while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) - { - if (NULL != po->dht_task) - { - GNUNET_SCHEDULER_cancel (po->dht_task); - po->dht_task = NULL; - } - if (NULL != po->dht_put) - { - GNUNET_DHT_put_cancel (po->dht_put); - po->dht_put = NULL; - } - if (NULL != po->dht_qe) { - GNUNET_DATASTORE_cancel (po->dht_qe); - po->dht_qe = NULL; + if (NULL != po->dht_task) + { + GNUNET_SCHEDULER_cancel(po->dht_task); + po->dht_task = NULL; + } + if (NULL != po->dht_put) + { + GNUNET_DHT_put_cancel(po->dht_put); + po->dht_put = NULL; + } + if (NULL != po->dht_qe) + { + GNUNET_DATASTORE_cancel(po->dht_qe); + po->dht_qe = NULL; + } + i++; } - i++; - } } /* end of gnunet-service-fs_put.c */ diff --git a/src/fs/gnunet-service-fs_put.h b/src/fs/gnunet-service-fs_put.h index de9751842..2d85d9831 100644 --- a/src/fs/gnunet-service-fs_put.h +++ b/src/fs/gnunet-service-fs_put.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-service-fs_put.h @@ -33,14 +33,14 @@ * Setup the module. */ void -GSF_put_init_ (void); +GSF_put_init_(void); /** * Shutdown the module. */ void -GSF_put_done_ (void); +GSF_put_done_(void); #endif diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index 4d13e7ef3..873dfa5eb 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/gnunet-unindex.c * @brief unindex files published on GNUnet @@ -40,24 +40,24 @@ static struct GNUNET_FS_UnindexContext *uc; static void -cleanup_task (void *cls) +cleanup_task(void *cls) { - GNUNET_FS_stop (ctx); + GNUNET_FS_stop(ctx); ctx = NULL; } static void -shutdown_task (void *cls) +shutdown_task(void *cls) { struct GNUNET_FS_UnindexContext *u; if (uc != NULL) - { - u = uc; - uc = NULL; - GNUNET_FS_unindex_stop (u); - } + { + u = uc; + uc = NULL; + GNUNET_FS_unindex_stop(u); + } } /** @@ -74,43 +74,48 @@ shutdown_task (void *cls) * field in the GNUNET_FS_ProgressInfo struct. */ static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) { const char *s; switch (info->status) - { - case GNUNET_FS_STATUS_UNINDEX_START: - break; - case GNUNET_FS_STATUS_UNINDEX_PROGRESS: - if (verbose) { - s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, - GNUNET_YES); - fprintf (stdout, - _ ("Unindexing at %llu/%llu (%s remaining)\n"), - (unsigned long long) info->value.unindex.completed, - (unsigned long long) info->value.unindex.size, - s); + case GNUNET_FS_STATUS_UNINDEX_START: + break; + + case GNUNET_FS_STATUS_UNINDEX_PROGRESS: + if (verbose) + { + s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta, + GNUNET_YES); + fprintf(stdout, + _("Unindexing at %llu/%llu (%s remaining)\n"), + (unsigned long long)info->value.unindex.completed, + (unsigned long long)info->value.unindex.size, + s); + } + break; + + case GNUNET_FS_STATUS_UNINDEX_ERROR: + fprintf(stderr, + _("Error unindexing: %s.\n"), + info->value.unindex.specifics.error.message); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_UNINDEX_COMPLETED: + fprintf(stdout, "%s", _("Unindexing done.\n")); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_UNINDEX_STOPPED: + GNUNET_SCHEDULER_add_now(&cleanup_task, NULL); + break; + + default: + fprintf(stderr, _("Unexpected status: %d\n"), info->status); + break; } - break; - case GNUNET_FS_STATUS_UNINDEX_ERROR: - fprintf (stderr, - _ ("Error unindexing: %s.\n"), - info->value.unindex.specifics.error.message); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - fprintf (stdout, "%s", _ ("Unindexing done.\n")); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_UNINDEX_STOPPED: - GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); - break; - default: - fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); - break; - } return NULL; } @@ -124,39 +129,39 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { /* check arguments */ if ((args[0] == NULL) || (args[1] != NULL)) - { - printf (_ ("You must specify one and only one filename for unindexing.\n")); - ret = -1; - return; - } + { + printf(_("You must specify one and only one filename for unindexing.\n")); + ret = -1; + return; + } cfg = c; - ctx = GNUNET_FS_start (cfg, - "gnunet-unindex", - &progress_cb, - NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start(cfg, + "gnunet-unindex", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) - { - fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); - ret = 1; - return; - } - uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); + { + fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + ret = 1; + return; + } + uc = GNUNET_FS_unindex_start(ctx, args[0], NULL); if (NULL == uc) - { - fprintf (stderr, "%s", _ ("Could not start unindex operation.\n")); - GNUNET_FS_stop (ctx); - return; - } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + { + fprintf(stderr, "%s", _("Could not start unindex operation.\n")); + GNUNET_FS_stop(ctx); + return; + } + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); } @@ -168,30 +173,30 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_verbose(&verbose), - GNUNET_GETOPT_option_verbose (&verbose), - - GNUNET_GETOPT_OPTION_END}; + GNUNET_GETOPT_OPTION_END + }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run ( + GNUNET_PROGRAM_run( argc, argv, "gnunet-unindex [OPTIONS] FILENAME", - gettext_noop ( + gettext_noop( "Unindex a file that was previously indexed with gnunet-publish."), options, &run, NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 0d76dfc3d..515144eb1 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/perf_gnunet_service_fs_p2p.c @@ -37,7 +37,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) #define NUM_DAEMONS 2 @@ -57,16 +57,14 @@ static struct GNUNET_TIME_Absolute start_time; /** * Master context for 'stat_run'. */ -struct StatMaster -{ +struct StatMaster { struct GNUNET_STATISTICS_Handle *stat; struct GNUNET_TESTBED_Operation *op; unsigned int daemon; unsigned int value; }; -struct StatValues -{ +struct StatValues { const char *subsystem; const char *name; }; @@ -75,28 +73,28 @@ struct StatValues * Statistics we print out. */ static struct StatValues stats[] = { - {"fs", "# queries forwarded"}, - {"fs", "# replies received and matched"}, - {"fs", "# results found locally"}, - {"fs", "# requests forwarded due to high load"}, - {"fs", "# requests done for free (low load)"}, - {"fs", "# requests dropped, priority insufficient"}, - {"fs", "# requests done for a price (normal load)"}, - {"fs", "# requests dropped by datastore (queue length limit)"}, - {"fs", "# P2P searches received"}, - {"fs", "# P2P searches discarded (queue length bound)"}, - {"fs", "# replies received for local clients"}, - {"fs", "# queries retransmitted to same target"}, - {"core", "# bytes decrypted"}, - {"core", "# bytes encrypted"}, - {"core", "# discarded CORE_SEND requests"}, - {"core", "# discarded CORE_SEND request bytes"}, - {"core", "# discarded lower priority CORE_SEND requests"}, - {"core", "# discarded lower priority CORE_SEND request bytes"}, - {"transport", "# bytes received via TCP"}, - {"transport", "# bytes transmitted via TCP"}, - {"datacache", "# bytes stored"}, - {NULL, NULL} + { "fs", "# queries forwarded" }, + { "fs", "# replies received and matched" }, + { "fs", "# results found locally" }, + { "fs", "# requests forwarded due to high load" }, + { "fs", "# requests done for free (low load)" }, + { "fs", "# requests dropped, priority insufficient" }, + { "fs", "# requests done for a price (normal load)" }, + { "fs", "# requests dropped by datastore (queue length limit)" }, + { "fs", "# P2P searches received" }, + { "fs", "# P2P searches discarded (queue length bound)" }, + { "fs", "# replies received for local clients" }, + { "fs", "# queries retransmitted to same target" }, + { "core", "# bytes decrypted" }, + { "core", "# bytes encrypted" }, + { "core", "# discarded CORE_SEND requests" }, + { "core", "# discarded CORE_SEND request bytes" }, + { "core", "# discarded lower priority CORE_SEND requests" }, + { "core", "# discarded lower priority CORE_SEND request bytes" }, + { "transport", "# bytes received via TCP" }, + { "transport", "# bytes transmitted via TCP" }, + { "datacache", "# bytes stored" }, + { NULL, NULL } }; @@ -111,17 +109,17 @@ static struct StatValues stats[] = { * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration */ static int -print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent) +print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, + int is_persistent) { struct StatMaster *sm = cls; - fprintf (stderr, - "Peer %2u: %12s/%50s = %12llu\n", - sm->daemon, - subsystem, - name, - (unsigned long long) value); + fprintf(stderr, + "Peer %2u: %12s/%50s = %12llu\n", + sm->daemon, + subsystem, + name, + (unsigned long long)value); return GNUNET_OK; } @@ -130,23 +128,23 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, * Function that gathers stats from all daemons. */ static void -stat_run (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg); +stat_run(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg); /** * Function called when GET operation on stats is done. */ static void -get_done (void *cls, int success) +get_done(void *cls, int success) { struct StatMaster *sm = cls; - GNUNET_break (GNUNET_OK == success); + GNUNET_break(GNUNET_OK == success); sm->value++; - stat_run (sm, sm->op, sm->stat, NULL); + stat_run(sm, sm->op, sm->stat, NULL); } @@ -161,11 +159,11 @@ get_done (void *cls, int success) * @return service handle to return in 'op_result', NULL on error */ static void * -statistics_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +statistics_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - return GNUNET_STATISTICS_create ("", - cfg); + return GNUNET_STATISTICS_create("", + cfg); } @@ -177,10 +175,10 @@ statistics_connect_adapter (void *cls, * @param op_result service handle returned from the connect adapter */ static void -statistics_disconnect_adapter (void *cls, - void *op_result) +statistics_disconnect_adapter(void *cls, + void *op_result) { - GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); + GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); } @@ -188,57 +186,57 @@ statistics_disconnect_adapter (void *cls, * Function that gathers stats from all daemons. */ static void -stat_run (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +stat_run(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct StatMaster *sm = cls; if (NULL != emsg) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to statistics service: %s\n", - emsg); - GNUNET_SCHEDULER_shutdown (); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to statistics service: %s\n", + emsg); + GNUNET_SCHEDULER_shutdown(); return; } sm->stat = ca_result; if (stats[sm->value].name != NULL) - { - GNUNET_STATISTICS_get (sm->stat, + { + GNUNET_STATISTICS_get(sm->stat, #if 0 - NULL, NULL, + NULL, NULL, #else - stats[sm->value].subsystem, stats[sm->value].name, + stats[sm->value].subsystem, stats[sm->value].name, #endif - &get_done, &print_stat, - sm); - return; - } - GNUNET_TESTBED_operation_done (sm->op); + &get_done, &print_stat, + sm); + return; + } + GNUNET_TESTBED_operation_done(sm->op); sm->value = 0; sm->daemon++; if (NUM_DAEMONS == sm->daemon) - { - GNUNET_free (sm); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_free(sm); + GNUNET_SCHEDULER_shutdown(); + return; + } sm->op = - GNUNET_TESTBED_service_connect (NULL, - daemons[sm->daemon], - "statistics", - &stat_run, sm, - &statistics_connect_adapter, - &statistics_disconnect_adapter, - NULL); + GNUNET_TESTBED_service_connect(NULL, + daemons[sm->daemon], + "statistics", + &stat_run, sm, + &statistics_connect_adapter, + &statistics_disconnect_adapter, + NULL); } static void -do_report (void *cls) +do_report(void *cls) { char *fn = cls; struct GNUNET_TIME_Relative del; @@ -246,120 +244,120 @@ do_report (void *cls) struct StatMaster *sm; if (NULL != fn) - { - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); - } + { + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); + } if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, - TIMEOUT)).rel_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout during download, shutting down with error\n"); - ok = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - - del = GNUNET_TIME_absolute_get_duration (start_time); + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, + TIMEOUT)).rel_value_us) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout during download, shutting down with error\n"); + ok = 1; + GNUNET_SCHEDULER_shutdown(); + return; + } + + del = GNUNET_TIME_absolute_get_duration(start_time); if (del.rel_value_us == 0) del.rel_value_us = 1; fancy = - GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * - 1000000LL / del.rel_value_us); - fprintf (stdout, - "Download speed was %s/s\n", - fancy); - GNUNET_free (fancy); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished download, shutting down\n"); - sm = GNUNET_new (struct StatMaster); + GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * + 1000000LL / del.rel_value_us); + fprintf(stdout, + "Download speed was %s/s\n", + fancy); + GNUNET_free(fancy); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished download, shutting down\n"); + sm = GNUNET_new(struct StatMaster); sm->op = - GNUNET_TESTBED_service_connect (NULL, - daemons[sm->daemon], - "statistics", - &stat_run, sm, - &statistics_connect_adapter, - &statistics_disconnect_adapter, - NULL); + GNUNET_TESTBED_service_connect(NULL, + daemons[sm->daemon], + "statistics", + &stat_run, sm, + &statistics_connect_adapter, + &statistics_disconnect_adapter, + NULL); } static void -do_download (void *cls, - const struct GNUNET_FS_Uri *uri, - const char *fn) +do_download(void *cls, + const struct GNUNET_FS_Uri *uri, + const char *fn) { int anonymity; if (NULL == uri) - { - GNUNET_SCHEDULER_shutdown (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout during upload attempt, shutting down with error\n"); - ok = 1; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", - (unsigned long long) FILESIZE); - start_time = GNUNET_TIME_absolute_get (); - if (NULL != strstr (progname, "dht")) + { + GNUNET_SCHEDULER_shutdown(); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout during upload attempt, shutting down with error\n"); + ok = 1; + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", + (unsigned long long)FILESIZE); + start_time = GNUNET_TIME_absolute_get(); + if (NULL != strstr(progname, "dht")) anonymity = 0; else anonymity = 1; - start_time = GNUNET_TIME_absolute_get (); - GNUNET_FS_TEST_download (daemons[0], - TIMEOUT, - anonymity, - SEED, - uri, - VERBOSE, - &do_report, - (NULL == fn) ? NULL : GNUNET_strdup (fn)); + start_time = GNUNET_TIME_absolute_get(); + GNUNET_FS_TEST_download(daemons[0], + TIMEOUT, + anonymity, + SEED, + uri, + VERBOSE, + &do_report, + (NULL == fn) ? NULL : GNUNET_strdup(fn)); } static void -do_publish (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +do_publish(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int i; int do_index; int anonymity; - GNUNET_assert (NUM_DAEMONS == num_peers); - for (i=0;i. SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/perf_gnunet_service_fs_p2p_respect.c @@ -57,7 +57,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) /** * Number of daemons in clique, must be at least 3 (!). @@ -93,16 +93,14 @@ static char *fn2; /** * Master context for 'stat_run'. */ -struct StatMaster -{ +struct StatMaster { struct GNUNET_STATISTICS_Handle *stat; struct GNUNET_TESTBED_Operation *op; unsigned int daemon; unsigned int value; }; -struct StatValues -{ +struct StatValues { const char *subsystem; const char *name; }; @@ -111,44 +109,44 @@ struct StatValues * Statistics we print out. */ static struct StatValues stats[] = { - {"fs", "# artificial delays introduced (ms)"}, - {"fs", "# queries forwarded"}, - {"fs", "# replies received and matched"}, - {"fs", "# results found locally"}, - {"fs", "# requests forwarded due to high load"}, - {"fs", "# requests done for free (low load)"}, - {"fs", "# requests dropped, priority insufficient"}, - {"fs", "# requests done for a price (normal load)"}, - {"fs", "# requests dropped by datastore (queue length limit)"}, - {"fs", "# P2P searches received"}, - {"fs", "# P2P searches discarded (queue length bound)"}, - {"fs", "# replies received for local clients"}, - {"fs", "# queries retransmitted to same target"}, - {"core", "# bytes decrypted"}, - {"core", "# bytes encrypted"}, - {"core", "# discarded CORE_SEND requests"}, - {"core", "# discarded lower priority CORE_SEND requests"}, - {"transport", "# bytes received via TCP"}, - {"transport", "# bytes transmitted via TCP"}, - {"datacache", "# bytes stored"}, - {NULL, NULL} + { "fs", "# artificial delays introduced (ms)" }, + { "fs", "# queries forwarded" }, + { "fs", "# replies received and matched" }, + { "fs", "# results found locally" }, + { "fs", "# requests forwarded due to high load" }, + { "fs", "# requests done for free (low load)" }, + { "fs", "# requests dropped, priority insufficient" }, + { "fs", "# requests done for a price (normal load)" }, + { "fs", "# requests dropped by datastore (queue length limit)" }, + { "fs", "# P2P searches received" }, + { "fs", "# P2P searches discarded (queue length bound)" }, + { "fs", "# replies received for local clients" }, + { "fs", "# queries retransmitted to same target" }, + { "core", "# bytes decrypted" }, + { "core", "# bytes encrypted" }, + { "core", "# discarded CORE_SEND requests" }, + { "core", "# discarded lower priority CORE_SEND requests" }, + { "transport", "# bytes received via TCP" }, + { "transport", "# bytes transmitted via TCP" }, + { "datacache", "# bytes stored" }, + { NULL, NULL } }; static void -cleanup () +cleanup() { - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); if (NULL != fn1) - { - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); - } + { + GNUNET_DISK_directory_remove(fn1); + GNUNET_free(fn1); + } if (NULL != fn2) - { - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); - } + { + GNUNET_DISK_directory_remove(fn2); + GNUNET_free(fn2); + } } @@ -163,13 +161,13 @@ cleanup () * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent) +print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, + int is_persistent) { struct StatMaster *sm = cls; - fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, - name, (unsigned long long) value); + fprintf(stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, + name, (unsigned long long)value); return GNUNET_OK; } @@ -178,23 +176,23 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, * Function that gathers stats from all daemons. */ static void -stat_run (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg); +stat_run(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg); /** * Function called when GET operation on stats is done. */ static void -get_done (void *cls, int success) +get_done(void *cls, int success) { struct StatMaster *sm = cls; - GNUNET_break (GNUNET_OK == success); + GNUNET_break(GNUNET_OK == success); sm->value++; - stat_run (sm, sm->op, sm->stat, NULL); + stat_run(sm, sm->op, sm->stat, NULL); } @@ -210,11 +208,11 @@ get_done (void *cls, int success) * @return service handle to return in 'op_result', NULL on error */ static void * -statistics_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +statistics_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - return GNUNET_STATISTICS_create ("", - cfg); + return GNUNET_STATISTICS_create("", + cfg); } @@ -226,10 +224,10 @@ statistics_connect_adapter (void *cls, * @param op_result service handle returned from the connect adapter */ static void -statistics_disconnect_adapter (void *cls, - void *op_result) +statistics_disconnect_adapter(void *cls, + void *op_result) { - GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); + GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); } @@ -237,49 +235,49 @@ statistics_disconnect_adapter (void *cls, * Function that gathers stats from all daemons. */ static void -stat_run (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +stat_run(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct StatMaster *sm = cls; sm->stat = ca_result; - GNUNET_assert (NULL != sm->stat); + GNUNET_assert(NULL != sm->stat); if (NULL != stats[sm->value].name) - { - GNUNET_STATISTICS_get (sm->stat, + { + GNUNET_STATISTICS_get(sm->stat, #if 0 - NULL, NULL, + NULL, NULL, #else - stats[sm->value].subsystem, stats[sm->value].name, + stats[sm->value].subsystem, stats[sm->value].name, #endif - &get_done, &print_stat, - sm); - return; - } - GNUNET_TESTBED_operation_done (sm->op); + &get_done, &print_stat, + sm); + return; + } + GNUNET_TESTBED_operation_done(sm->op); sm->value = 0; sm->daemon++; if (NUM_DAEMONS == sm->daemon) - { - GNUNET_free (sm); - cleanup (); - return; - } + { + GNUNET_free(sm); + cleanup(); + return; + } sm->op = - GNUNET_TESTBED_service_connect (NULL, - daemons[sm->daemon], - "statistics", - &stat_run, sm, - &statistics_connect_adapter, - &statistics_disconnect_adapter, - NULL); + GNUNET_TESTBED_service_connect(NULL, + daemons[sm->daemon], + "statistics", + &stat_run, sm, + &statistics_connect_adapter, + &statistics_disconnect_adapter, + NULL); } static void -do_report (void *cls) +do_report(void *cls) { static int download_counter; const char *type = cls; @@ -288,62 +286,62 @@ do_report (void *cls) struct StatMaster *sm; if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, - TIMEOUT)).rel_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout during download for type `%s', shutting down with error\n", - type); - ok = 1; - cleanup (); - return; - } - del = GNUNET_TIME_absolute_get_duration (start_time); + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, + TIMEOUT)).rel_value_us) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout during download for type `%s', shutting down with error\n", + type); + ok = 1; + cleanup(); + return; + } + del = GNUNET_TIME_absolute_get_duration(start_time); if (del.rel_value_us == 0) del.rel_value_us = 1; fancy = - GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * - 1000000LL / del.rel_value_us); - fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); - GNUNET_free (fancy); + GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * + 1000000LL / del.rel_value_us); + fprintf(stderr, "Download speed of type `%s' was %s/s\n", type, fancy); + GNUNET_free(fancy); if (NUM_DAEMONS != ++download_counter) return; /* more downloads to come */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished all downloads, getting statistics\n"); - sm = GNUNET_new (struct StatMaster); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished all downloads, getting statistics\n"); + sm = GNUNET_new(struct StatMaster); sm->op = - GNUNET_TESTBED_service_connect (NULL, - daemons[sm->daemon], - "statistics", - &stat_run, sm, - &statistics_connect_adapter, - &statistics_disconnect_adapter, - NULL); + GNUNET_TESTBED_service_connect(NULL, + daemons[sm->daemon], + "statistics", + &stat_run, sm, + &statistics_connect_adapter, + &statistics_disconnect_adapter, + NULL); } static void -do_downloads (void *cls, const struct GNUNET_FS_Uri *u2, - const char *fn) +do_downloads(void *cls, const struct GNUNET_FS_Uri *u2, + const char *fn) { int anonymity; unsigned int i; if (NULL == u2) - { - cleanup (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout during upload attempt, shutting down with error\n"); - ok = 1; - return; - } + { + cleanup(); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout during upload attempt, shutting down with error\n"); + ok = 1; + return; + } if (NULL != fn) - fn2 = GNUNET_strdup (fn); - uri2 = GNUNET_FS_uri_dup (u2); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", - (unsigned long long) FILESIZE); - start_time = GNUNET_TIME_absolute_get (); - if (NULL != strstr (progname, "dht")) + fn2 = GNUNET_strdup(fn); + uri2 = GNUNET_FS_uri_dup(u2); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", + (unsigned long long)FILESIZE); + start_time = GNUNET_TIME_absolute_get(); + if (NULL != strstr(progname, "dht")) anonymity = 0; else anonymity = 1; @@ -351,127 +349,127 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2, * these peers do participate in sharing, they just * don't have to offer anything *initially*. */ for (i = 0; i < NUM_DAEMONS - 2; i++) - GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity, - 0 == (i % 2) ? SEED1 : SEED2, - 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, - "leach"); + GNUNET_FS_TEST_download(daemons[i], TIMEOUT, anonymity, + 0 == (i % 2) ? SEED1 : SEED2, + 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, + "leach"); /* mutual downloads of (primary) sharing peers */ - GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, - uri1, VERBOSE, &do_report, "seeder 2"); - GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, - uri2, VERBOSE, &do_report, "seeder 1"); + GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, + uri1, VERBOSE, &do_report, "seeder 2"); + GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, + uri2, VERBOSE, &do_report, "seeder 1"); } static void -do_publish2 (void *cls, - const struct GNUNET_FS_Uri *u1, - const char *fn) +do_publish2(void *cls, + const struct GNUNET_FS_Uri *u1, + const char *fn) { int do_index; int anonymity; if (NULL == u1) - { - cleanup (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout during upload attempt, shutting down with error\n"); - ok = 1; - return; - } + { + cleanup(); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Timeout during upload attempt, shutting down with error\n"); + ok = 1; + return; + } if (NULL != fn) - fn1 = GNUNET_strdup (fn); - uri1 = GNUNET_FS_uri_dup (u1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", - (unsigned long long) FILESIZE); - if (NULL != strstr (progname, "index")) + fn1 = GNUNET_strdup(fn); + uri1 = GNUNET_FS_uri_dup(u1); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", + (unsigned long long)FILESIZE); + if (NULL != strstr(progname, "index")) do_index = GNUNET_YES; else do_index = GNUNET_NO; - if (NULL != strstr (progname, "dht")) + if (NULL != strstr(progname, "dht")) anonymity = 0; else anonymity = 1; - GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, - do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, - NULL); + GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, + do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, + NULL); } static void -do_publish1 (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +do_publish1(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { unsigned int *coco = cls; int do_index; int anonymity; - GNUNET_TESTBED_operation_done (op); + GNUNET_TESTBED_operation_done(op); if (NULL != emsg) - { - cleanup (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); - ok = 1; - return; - } + { + cleanup(); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); + ok = 1; + return; + } if (0 != (--(*coco))) return; /* more connections to be created */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", - (unsigned long long) FILESIZE); - if (NULL != strstr (progname, "index")) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", + (unsigned long long)FILESIZE); + if (NULL != strstr(progname, "index")) do_index = GNUNET_YES; else do_index = GNUNET_NO; - if (NULL != strstr (progname, "dht")) + if (NULL != strstr(progname, "dht")) anonymity = 0; else anonymity = 1; - GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, - do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, - NULL); + GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, + do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, + NULL); } static void -do_connect (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +do_connect(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { static unsigned int coco; unsigned int i; unsigned int j; - GNUNET_assert (NUM_DAEMONS == num_peers); - for (i=0;i. SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/plugin_block_fs.c @@ -51,58 +51,61 @@ * by this @a type of block (this is not an error) */ static struct GNUNET_BLOCK_Group * -block_plugin_fs_create_group (void *cls, - enum GNUNET_BLOCK_Type type, - uint32_t nonce, - const void *raw_data, - size_t raw_data_size, - va_list va) +block_plugin_fs_create_group(void *cls, + enum GNUNET_BLOCK_Type type, + uint32_t nonce, + const void *raw_data, + size_t raw_data_size, + va_list va) { unsigned int size; const char *guard; switch (type) - { - case GNUNET_BLOCK_TYPE_FS_DBLOCK: - GNUNET_break (NULL == va_arg (va, const char *)); - return NULL; - case GNUNET_BLOCK_TYPE_FS_IBLOCK: - GNUNET_break (NULL == va_arg (va, const char *)); - return NULL; - case GNUNET_BLOCK_TYPE_FS_UBLOCK: - guard = va_arg (va, const char *); - if (0 == strcmp (guard, - "seen-set-size")) - { - size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), - BLOOMFILTER_K); - } - else if (0 == strcmp (guard, - "filter-size")) - { - size = va_arg (va, unsigned int); - } - else { - /* va-args invalid! bad bug, complain! */ - GNUNET_break (0); - size = 8; + case GNUNET_BLOCK_TYPE_FS_DBLOCK: + GNUNET_break(NULL == va_arg(va, const char *)); + return NULL; + + case GNUNET_BLOCK_TYPE_FS_IBLOCK: + GNUNET_break(NULL == va_arg(va, const char *)); + return NULL; + + case GNUNET_BLOCK_TYPE_FS_UBLOCK: + guard = va_arg(va, const char *); + if (0 == strcmp(guard, + "seen-set-size")) + { + size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), + BLOOMFILTER_K); + } + else if (0 == strcmp(guard, + "filter-size")) + { + size = va_arg(va, unsigned int); + } + else + { + /* va-args invalid! bad bug, complain! */ + GNUNET_break(0); + size = 8; + } + if (0 == size) + size = raw_data_size; /* not for us to determine, use what we got! */ + GNUNET_break(NULL == va_arg(va, const char *)); + return GNUNET_BLOCK_GROUP_bf_create(cls, + size, + BLOOMFILTER_K, + type, + nonce, + raw_data, + raw_data_size); + + default: + GNUNET_break(NULL == va_arg(va, const char *)); + GNUNET_break(0); + return NULL; } - if (0 == size) - size = raw_data_size; /* not for us to determine, use what we got! */ - GNUNET_break (NULL == va_arg (va, const char *)); - return GNUNET_BLOCK_GROUP_bf_create (cls, - size, - BLOOMFILTER_K, - type, - nonce, - raw_data, - raw_data_size); - default: - GNUNET_break (NULL == va_arg (va, const char *)); - GNUNET_break (0); - return NULL; - } } @@ -126,84 +129,86 @@ block_plugin_fs_create_group (void *cls, * @return characterization of result */ static enum GNUNET_BLOCK_EvaluationResult -block_plugin_fs_evaluate (void *cls, - struct GNUNET_BLOCK_Context *ctx, - enum GNUNET_BLOCK_Type type, - struct GNUNET_BLOCK_Group *bg, - enum GNUNET_BLOCK_EvaluationOptions eo, - const struct GNUNET_HashCode *query, - const void *xquery, - size_t xquery_size, - const void *reply_block, - size_t reply_block_size) +block_plugin_fs_evaluate(void *cls, + struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BLOCK_Group *bg, + enum GNUNET_BLOCK_EvaluationOptions eo, + const struct GNUNET_HashCode *query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) { const struct UBlock *ub; struct GNUNET_HashCode hc; struct GNUNET_HashCode chash; switch (type) - { - case GNUNET_BLOCK_TYPE_FS_DBLOCK: - case GNUNET_BLOCK_TYPE_FS_IBLOCK: - if (0 != xquery_size) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; - } - if (NULL == reply_block) - return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; - return GNUNET_BLOCK_EVALUATION_OK_LAST; - case GNUNET_BLOCK_TYPE_FS_UBLOCK: - if (0 != xquery_size) { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; - } - if (NULL == reply_block) - return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + case GNUNET_BLOCK_TYPE_FS_DBLOCK: + case GNUNET_BLOCK_TYPE_FS_IBLOCK: + if (0 != xquery_size) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; + } + if (NULL == reply_block) + return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + return GNUNET_BLOCK_EVALUATION_OK_LAST; - if (reply_block_size < sizeof (struct UBlock)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - ub = reply_block; - GNUNET_CRYPTO_hash (&ub->verification_key, - sizeof (ub->verification_key), - &hc); - if (0 != memcmp (&hc, - query, - sizeof (struct GNUNET_HashCode))) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - if (reply_block_size != ntohl (ub->purpose.size) + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - if ( (0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && - (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, + case GNUNET_BLOCK_TYPE_FS_UBLOCK: + if (0 != xquery_size) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; + } + if (NULL == reply_block) + return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + + if (reply_block_size < sizeof(struct UBlock)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + ub = reply_block; + GNUNET_CRYPTO_hash(&ub->verification_key, + sizeof(ub->verification_key), + &hc); + if (0 != memcmp(&hc, + query, + sizeof(struct GNUNET_HashCode))) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if (reply_block_size != ntohl(ub->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && + (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, &ub->purpose, &ub->signature, - &ub->verification_key)) ) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + &ub->verification_key))) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + GNUNET_CRYPTO_hash(reply_block, + reply_block_size, + &chash); + if (GNUNET_YES == + GNUNET_BLOCK_GROUP_bf_test_and_set(bg, + &chash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + return GNUNET_BLOCK_EVALUATION_OK_MORE; + + default: + return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; } - GNUNET_CRYPTO_hash (reply_block, - reply_block_size, - &chash); - if (GNUNET_YES == - GNUNET_BLOCK_GROUP_bf_test_and_set (bg, - &chash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - return GNUNET_BLOCK_EVALUATION_OK_MORE; - default: - return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; - } } @@ -219,35 +224,37 @@ block_plugin_fs_evaluate (void *cls, * (or if extracting a key from a block of this type does not work) */ static int -block_plugin_fs_get_key (void *cls, - enum GNUNET_BLOCK_Type type, - const void *block, - size_t block_size, - struct GNUNET_HashCode *key) +block_plugin_fs_get_key(void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + struct GNUNET_HashCode *key) { const struct UBlock *ub; switch (type) - { - case GNUNET_BLOCK_TYPE_FS_DBLOCK: - case GNUNET_BLOCK_TYPE_FS_IBLOCK: - GNUNET_CRYPTO_hash (block, block_size, key); - return GNUNET_OK; - case GNUNET_BLOCK_TYPE_FS_UBLOCK: - if (block_size < sizeof (struct UBlock)) { - GNUNET_break (0); + case GNUNET_BLOCK_TYPE_FS_DBLOCK: + case GNUNET_BLOCK_TYPE_FS_IBLOCK: + GNUNET_CRYPTO_hash(block, block_size, key); + return GNUNET_OK; + + case GNUNET_BLOCK_TYPE_FS_UBLOCK: + if (block_size < sizeof(struct UBlock)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + ub = block; + GNUNET_CRYPTO_hash(&ub->verification_key, + sizeof(ub->verification_key), + key); + return GNUNET_OK; + + default: + GNUNET_break(0); return GNUNET_SYSERR; } - ub = block; - GNUNET_CRYPTO_hash (&ub->verification_key, - sizeof (ub->verification_key), - key); - return GNUNET_OK; - default: - GNUNET_break (0); - return GNUNET_SYSERR; - } } @@ -255,7 +262,7 @@ block_plugin_fs_get_key (void *cls, * Entry point for the plugin. */ void * -libgnunet_plugin_block_fs_init (void *cls) +libgnunet_plugin_block_fs_init(void *cls) { static enum GNUNET_BLOCK_Type types[] = { @@ -266,7 +273,7 @@ libgnunet_plugin_block_fs_init (void *cls) }; struct GNUNET_BLOCK_PluginFunctions *api; - api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); api->evaluate = &block_plugin_fs_evaluate; api->get_key = &block_plugin_fs_get_key; api->create_group = &block_plugin_fs_create_group; @@ -279,11 +286,11 @@ libgnunet_plugin_block_fs_init (void *cls) * Exit point from the plugin. */ void * -libgnunet_plugin_block_fs_done (void *cls) +libgnunet_plugin_block_fs_done(void *cls) { struct GNUNET_BLOCK_PluginFunctions *api = cls; - GNUNET_free (api); + GNUNET_free(api); return NULL; } diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c index e88c74464..e88bacf59 100644 --- a/src/fs/test_fs.c +++ b/src/fs/test_fs.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs.c @@ -33,16 +33,16 @@ #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto FAILURE; } static char * -makeName (unsigned int i) +makeName(unsigned int i) { char *fn; - fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + - 14); - GNUNET_snprintf (fn, - strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, - "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); - GNUNET_disk_directory_create_for_file (NULL, fn); + fn = GNUNET_malloc(strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + + 14); + GNUNET_snprintf(fn, + strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, + "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); + GNUNET_disk_directory_create_for_file(NULL, fn); return fn; } @@ -55,42 +55,47 @@ static struct GNUNET_ECRS_URI *search_uri; static struct GNUNET_FSUI_Context *ctx; static void * -eventCallback (void *cls, const GNUNET_FSUI_Event * event) +eventCallback(void *cls, const GNUNET_FSUI_Event * event) { static char unused; switch (event->type) - { - case GNUNET_FSUI_search_resumed: - case GNUNET_FSUI_download_resumed: - case GNUNET_FSUI_upload_resumed: - case GNUNET_FSUI_unindex_resumed: - return &unused; - case GNUNET_FSUI_search_result: + { + case GNUNET_FSUI_search_resumed: + case GNUNET_FSUI_download_resumed: + case GNUNET_FSUI_upload_resumed: + case GNUNET_FSUI_unindex_resumed: + return &unused; + + case GNUNET_FSUI_search_result: #if DEBUG_VERBOSE - printf ("Received search result\n"); + printf("Received search result\n"); #endif - search_uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri); - search_meta = GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta); - break; - case GNUNET_FSUI_upload_completed: + search_uri = GNUNET_ECRS_uri_duplicate(event->data.SearchResult.fi.uri); + search_meta = GNUNET_meta_data_duplicate(event->data.SearchResult.fi.meta); + break; + + case GNUNET_FSUI_upload_completed: #if DEBUG_VERBOSE - printf ("Upload complete.\n"); + printf("Upload complete.\n"); #endif - break; - case GNUNET_FSUI_download_completed: + break; + + case GNUNET_FSUI_download_completed: #if DEBUG_VERBOSE - printf ("Download complete.\n"); + printf("Download complete.\n"); #endif - break; - case GNUNET_FSUI_unindex_completed: + break; + + case GNUNET_FSUI_unindex_completed: #if DEBUG_VERBOSE - printf ("Unindex complete.\n"); + printf("Unindex complete.\n"); #endif - break; - default: - break; - } + break; + + default: + break; + } lastEvent = event->type; return NULL; } @@ -98,7 +103,7 @@ eventCallback (void *cls, const GNUNET_FSUI_Event * event) #define START_DAEMON 1 int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { #if START_DAEMON struct GNUNET_OS_Process *daemon; @@ -122,128 +127,128 @@ main (int argc, char *argv[]) struct GNUNET_FSUI_UnindexList *unindex = NULL; struct GNUNET_FSUI_DownloadList *download = NULL; - cfg = GNUNET_GC_create (); - if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) - { - GNUNET_GC_free (cfg); - return -1; - } + cfg = GNUNET_GC_create(); + if (-1 == GNUNET_GC_parse_configuration(cfg, "check.conf")) + { + GNUNET_GC_free(cfg); + return -1; + } #if START_DAEMON - daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); - GNUNET_GE_ASSERT (NULL, daemon != NULL); - CHECK (GNUNET_OK == - GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS)); + daemon = GNUNET_daemon_start(NULL, cfg, "peer.conf", GNUNET_NO); + GNUNET_GE_ASSERT(NULL, daemon != NULL); + CHECK(GNUNET_OK == + GNUNET_wait_for_daemon_running(NULL, cfg, 60 * GNUNET_CRON_SECONDS)); #endif - GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ + GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); /* give apps time to start */ ok = GNUNET_YES; /* ACTUAL TEST CODE */ - ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ - GNUNET_NO, /* no resume */ - &eventCallback, NULL); - CHECK (ctx != NULL); - filename = makeName (42); - GNUNET_disk_file_write (NULL, filename, "foo bar test!", - strlen ("foo bar test!"), "600"); - meta = GNUNET_meta_data_create (); + ctx = GNUNET_FSUI_start(NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ + GNUNET_NO, /* no resume */ + &eventCallback, NULL); + CHECK(ctx != NULL); + filename = makeName(42); + GNUNET_disk_file_write(NULL, filename, "foo bar test!", + strlen("foo bar test!"), "600"); + meta = GNUNET_meta_data_create(); kuri = - GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, - (const char **) keywords); + GNUNET_ECRS_keyword_command_line_to_uri(NULL, 2, + (const char **)keywords); /* upload */ - upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ - 0, /* priority */ - GNUNET_YES, GNUNET_NO, GNUNET_NO, - GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, - meta, kuri, kuri); - CHECK (upload != NULL); - GNUNET_ECRS_uri_destroy (kuri); - GNUNET_meta_data_destroy (meta); + upload = GNUNET_FSUI_upload_start(ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ + 0, /* priority */ + GNUNET_YES, GNUNET_NO, GNUNET_NO, + GNUNET_get_time() + 5 * GNUNET_CRON_HOURS, + meta, kuri, kuri); + CHECK(upload != NULL); + GNUNET_ECRS_uri_destroy(kuri); + GNUNET_meta_data_destroy(meta); prog = 0; while (lastEvent != GNUNET_FSUI_upload_completed) - { - prog++; - CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); - if (GNUNET_shutdown_test () == GNUNET_YES) - break; - } + { + prog++; + CHECK(prog < 10000) GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); + if (GNUNET_shutdown_test() == GNUNET_YES) + break; + } /* search */ - GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]); - uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword); - search = GNUNET_FSUI_search_start (ctx, 0, uri); - GNUNET_ECRS_uri_destroy (uri); - CHECK (search != NULL); + GNUNET_snprintf(keyword, 40, "+%s +%s", keywords[0], keywords[1]); + uri = GNUNET_ECRS_keyword_string_to_uri(NULL, keyword); + search = GNUNET_FSUI_search_start(ctx, 0, uri); + GNUNET_ECRS_uri_destroy(uri); + CHECK(search != NULL); prog = 0; while (lastEvent != GNUNET_FSUI_search_result) - { - prog++; - CHECK (prog < 10000); - GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); - if (GNUNET_shutdown_test () == GNUNET_YES) - break; - } - GNUNET_FSUI_search_abort (search); - GNUNET_FSUI_search_stop (search); + { + prog++; + CHECK(prog < 10000); + GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); + if (GNUNET_shutdown_test() == GNUNET_YES) + break; + } + GNUNET_FSUI_search_abort(search); + GNUNET_FSUI_search_stop(search); /* download */ - fn = makeName (43); + fn = makeName(43); download = - GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, search_uri, search_meta, - fn, NULL, NULL); - GNUNET_free (fn); + GNUNET_FSUI_download_start(ctx, 0, GNUNET_NO, search_uri, search_meta, + fn, NULL, NULL); + GNUNET_free(fn); prog = 0; while (lastEvent != GNUNET_FSUI_download_completed) - { - prog++; - CHECK (prog < 10000); - GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); - if (GNUNET_shutdown_test () == GNUNET_YES) - break; - } - GNUNET_FSUI_download_stop (download); + { + prog++; + CHECK(prog < 10000); + GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); + if (GNUNET_shutdown_test() == GNUNET_YES) + break; + } + GNUNET_FSUI_download_stop(download); download = NULL; - GNUNET_ECRS_uri_destroy (search_uri); - GNUNET_meta_data_destroy (search_meta); + GNUNET_ECRS_uri_destroy(search_uri); + GNUNET_meta_data_destroy(search_meta); /* unindex */ - unindex = GNUNET_FSUI_unindex_start (ctx, filename); + unindex = GNUNET_FSUI_unindex_start(ctx, filename); prog = 0; while (lastEvent != GNUNET_FSUI_unindex_completed) - { - prog++; - CHECK (prog < 10000); - GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); - if (GNUNET_shutdown_test () == GNUNET_YES) - break; - } + { + prog++; + CHECK(prog < 10000); + GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); + if (GNUNET_shutdown_test() == GNUNET_YES) + break; + } if (lastEvent != GNUNET_FSUI_unindex_completed) - GNUNET_FSUI_unindex_abort (unindex); - GNUNET_FSUI_unindex_stop (unindex); + GNUNET_FSUI_unindex_abort(unindex); + GNUNET_FSUI_unindex_stop(unindex); /* END OF TEST CODE */ FAILURE: if (ctx != NULL) - GNUNET_FSUI_stop (ctx); + GNUNET_FSUI_stop(ctx); if (filename != NULL) - { - unlink (filename); - GNUNET_free (filename); - } + { + unlink(filename); + GNUNET_free(filename); + } if (download != NULL) - { - GNUNET_FSUI_download_abort (download); - GNUNET_FSUI_download_stop (download); - } - filename = makeName (43); + { + GNUNET_FSUI_download_abort(download); + GNUNET_FSUI_download_stop(download); + } + filename = makeName(43); /* TODO: verify file 'filename(42)' == file 'filename(43)' */ - unlink (filename); - GNUNET_free (filename); + unlink(filename); + GNUNET_free(filename); #if START_DAEMON - GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); - GNUNET_OS_process_destroy (daemon); + GNUNET_GE_ASSERT(NULL, GNUNET_OK == GNUNET_daemon_stop(NULL, daemon)); + GNUNET_OS_process_destroy(daemon); #endif - GNUNET_GC_free (cfg); + GNUNET_GC_free(cfg); return (ok == GNUNET_YES) ? 0 : 1; } diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index 5cdbd9d07..936c3bed4 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_directory.c * @brief Test for fs_directory.c @@ -32,8 +32,7 @@ #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } -struct PCLS -{ +struct PCLS { struct GNUNET_FS_Uri **uri; struct GNUNET_CONTAINER_MetaData **md; unsigned int pos; @@ -41,9 +40,9 @@ struct PCLS }; static void -processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *md, size_t length, - const void *data) +processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *md, size_t length, + const void *data) { struct PCLS *p = cls; int i; @@ -51,19 +50,19 @@ processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, if (NULL == uri) return; /* ignore directory's meta data */ for (i = 0; i < p->max; i++) - { - if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) && - GNUNET_FS_uri_test_equal (p->uri[i], uri)) { - p->pos++; - return; + if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) && + GNUNET_FS_uri_test_equal(p->uri[i], uri)) + { + p->pos++; + return; + } } - } - fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); + fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); } static int -testDirectory (unsigned int i) +testDirectory(unsigned int i) { struct GNUNET_FS_DirectoryBuilder *db; char *data; @@ -82,99 +81,99 @@ testDirectory (unsigned int i) const char *s; cls.max = i; - uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i); - mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i); - meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_CONTAINER_meta_data_insert (meta, "", EXTRACTOR_METATYPE_TITLE, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - "A title", strlen ("A title") + 1); - GNUNET_CONTAINER_meta_data_insert (meta, "", - EXTRACTOR_METATYPE_AUTHOR_NAME, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - "An author", strlen ("An author") + 1); + uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i); + mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i); + meta = GNUNET_CONTAINER_meta_data_create(); + GNUNET_CONTAINER_meta_data_insert(meta, "", EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + "A title", strlen("A title") + 1); + GNUNET_CONTAINER_meta_data_insert(meta, "", + EXTRACTOR_METATYPE_AUTHOR_NAME, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + "An author", strlen("An author") + 1); for (p = 0; p < i; p++) - { - mds[p] = GNUNET_CONTAINER_meta_data_create (); - for (q = 0; q <= p; q++) { - GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q); - GNUNET_CONTAINER_meta_data_insert (mds[p], "", + mds[p] = GNUNET_CONTAINER_meta_data_create(); + for (q = 0; q <= p; q++) + { + GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q); + GNUNET_CONTAINER_meta_data_insert(mds[p], "", #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR - q % EXTRACTOR_metatype_get_max (), + q % EXTRACTOR_metatype_get_max(), #else - q % 128, + q % 128, #endif - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", txt, strlen (txt) + 1); - } - GNUNET_snprintf (uri, sizeof (uri), - "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", - p); - emsg = NULL; - uris[p] = GNUNET_FS_uri_parse (uri, &emsg); - if (uris[p] == NULL) - { - GNUNET_CONTAINER_meta_data_destroy (mds[p]); - while (--p > 0) - { - GNUNET_CONTAINER_meta_data_destroy (mds[p]); - GNUNET_FS_uri_destroy (uris[p]); - } - GNUNET_free (mds); - GNUNET_free (uris); - GNUNET_free (emsg); - GNUNET_CONTAINER_meta_data_destroy (meta); - ABORT (); /* error in testcase */ + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", txt, strlen(txt) + 1); + } + GNUNET_snprintf(uri, sizeof(uri), + "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", + p); + emsg = NULL; + uris[p] = GNUNET_FS_uri_parse(uri, &emsg); + if (uris[p] == NULL) + { + GNUNET_CONTAINER_meta_data_destroy(mds[p]); + while (--p > 0) + { + GNUNET_CONTAINER_meta_data_destroy(mds[p]); + GNUNET_FS_uri_destroy(uris[p]); + } + GNUNET_free(mds); + GNUNET_free(uris); + GNUNET_free(emsg); + GNUNET_CONTAINER_meta_data_destroy(meta); + ABORT(); /* error in testcase */ + } + GNUNET_assert(emsg == NULL); } - GNUNET_assert (emsg == NULL); - } - start = GNUNET_TIME_absolute_get (); - db = GNUNET_FS_directory_builder_create (meta); + start = GNUNET_TIME_absolute_get(); + db = GNUNET_FS_directory_builder_create(meta); for (p = 0; p < i; p++) - GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); - GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); - s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration - (start), - GNUNET_YES); - fprintf (stdout, - "Creating directory with %u entires and total size %llu took %s\n", - i, (unsigned long long) dlen, s); + GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL); + GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data); + s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration + (start), + GNUNET_YES); + fprintf(stdout, + "Creating directory with %u entires and total size %llu took %s\n", + i, (unsigned long long)dlen, s); if (i < 100) - { - cls.pos = 0; - cls.uri = uris; - cls.md = mds; - GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); - GNUNET_assert (cls.pos == i); - } - GNUNET_free (data); - GNUNET_CONTAINER_meta_data_destroy (meta); + { + cls.pos = 0; + cls.uri = uris; + cls.md = mds; + GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls); + GNUNET_assert(cls.pos == i); + } + GNUNET_free(data); + GNUNET_CONTAINER_meta_data_destroy(meta); for (p = 0; p < i; p++) - { - GNUNET_CONTAINER_meta_data_destroy (mds[p]); - GNUNET_FS_uri_destroy (uris[p]); - } - GNUNET_free (uris); - GNUNET_free (mds); + { + GNUNET_CONTAINER_meta_data_destroy(mds[p]); + GNUNET_FS_uri_destroy(uris[p]); + } + GNUNET_free(uris); + GNUNET_free(mds); return ret; } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { int failureCount = 0; int i; - GNUNET_log_setup ("test_fs_directory", + GNUNET_log_setup("test_fs_directory", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); for (i = 17; i < 1000; i *= 2) - failureCount += testDirectory (i); + failureCount += testDirectory(i); if (failureCount != 0) return 1; return 0; diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 242e6f1aa..f7c35a680 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_download.c @@ -38,12 +38,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static unsigned int anonymity_level; @@ -67,187 +67,198 @@ static int err; static void -timeout_kill_task (void *cls) +timeout_kill_task(void *cls) { if (NULL != download) - { - GNUNET_FS_download_stop (download, GNUNET_YES); - download = NULL; - } + { + GNUNET_FS_download_stop(download, GNUNET_YES); + download = NULL; + } else if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); timeout_kill = NULL; err = 1; } static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } } static void -stop_fs_task (void *cls) +stop_fs_task(void *cls) { - GNUNET_FS_stop (fs); + GNUNET_FS_stop(fs); fs = NULL; } static void -abort_download_task (void *cls) +abort_download_task(void *cls) { uint64_t size; if (NULL != download) - { - GNUNET_FS_download_stop (download, GNUNET_YES); - download = NULL; - } - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES, GNUNET_NO)); - GNUNET_assert (size == FILESIZE); - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); + { + GNUNET_FS_download_stop(download, GNUNET_YES); + download = NULL; + } + GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_size(fn, &size, GNUNET_YES, GNUNET_NO)); + GNUNET_assert(size == FILESIZE); + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); fn = NULL; - GNUNET_SCHEDULER_cancel (timeout_kill); + GNUNET_SCHEDULER_cancel(timeout_kill); timeout_kill = NULL; } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { - switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - fprintf (stdout, - "Publishing complete, %llu kb/s.\n", - (unsigned long long) (FILESIZE * 1000000LL / - (1 + - GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL)); - GAUGER ("FS", - (GNUNET_YES == indexed) - ? "Publishing speed (indexing)" - : "Publishing speed (insertion)", - (unsigned long long) (FILESIZE * 1000000LL / - (1 + - GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL), "kb/s"); - fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); - start = GNUNET_TIME_absolute_get (); - download = - GNUNET_FS_download_start (fs, - event->value.publish.specifics. - completed.chk_uri, NULL, fn, NULL, 0, - FILESIZE, anonymity_level, - GNUNET_FS_DOWNLOAD_OPTION_NONE, - "download", NULL); - GNUNET_assert (download != NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - fprintf (stdout, - "Download complete, %llu kb/s.\n", - (unsigned long long) (FILESIZE * 1000000LL / - (1 + - GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL)); - GAUGER ("FS", - (GNUNET_YES == indexed) - ? "Local download speed (indexed)" - : "Local download speed (inserted)", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + fprintf(stdout, + "Publishing complete, %llu kb/s.\n", + (unsigned long long)(FILESIZE * 1000000LL / + (1 + + GNUNET_TIME_absolute_get_duration + (start).rel_value_us) / 1024LL)); + GAUGER("FS", + (GNUNET_YES == indexed) + ? "Publishing speed (indexing)" + : "Publishing speed (insertion)", + (unsigned long long)(FILESIZE * 1000000LL / + (1 + + GNUNET_TIME_absolute_get_duration + (start).rel_value_us) / 1024LL), "kb/s"); + fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); + start = GNUNET_TIME_absolute_get(); + download = + GNUNET_FS_download_start(fs, + event->value.publish.specifics. + completed.chk_uri, NULL, fn, NULL, 0, + FILESIZE, anonymity_level, + GNUNET_FS_DOWNLOAD_OPTION_NONE, + "download", NULL); + GNUNET_assert(download != NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + fprintf(stdout, + "Download complete, %llu kb/s.\n", + (unsigned long long)(FILESIZE * 1000000LL / + (1 + + GNUNET_TIME_absolute_get_duration + (start).rel_value_us) / 1024LL)); + GAUGER("FS", + (GNUNET_YES == indexed) + ? "Local download speed (indexed)" + : "Local download speed (inserted)", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL), "kb/s"); - GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - GNUNET_assert (download == event->value.download.dc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.download.completed, - (unsigned long long) event->value.download.size, - event->value.download.specifics.progress.depth, - (unsigned long long) event->value.download.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - fprintf (stderr, "Error downloading file: %s\n", - event->value.download.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_START: - GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); - GNUNET_assert (NULL == event->value.download.pctx); - GNUNET_assert (NULL != event->value.download.uri); - GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); - GNUNET_assert (FILESIZE == event->value.download.size); - GNUNET_assert (0 == event->value.download.completed); - GNUNET_assert (1 == event->value.download.anonymity); - break; - case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: - GNUNET_assert (download == event->value.download.dc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } + (start).rel_value_us) / 1024LL), "kb/s"); + GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + GNUNET_assert(download == event->value.download.dc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Download is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.download.completed, + (unsigned long long)event->value.download.size, + event->value.download.specifics.progress.depth, + (unsigned long long)event->value.download.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + fprintf(stderr, "Error downloading file: %s\n", + event->value.download.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_SCHEDULER_add_now(&stop_fs_task, NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_START: + GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); + GNUNET_assert(NULL == event->value.download.pctx); + GNUNET_assert(NULL != event->value.download.uri); + GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); + GNUNET_assert(FILESIZE == event->value.download.size); + GNUNET_assert(0 == event->value.download.completed); + GNUNET_assert(1 == event->value.download.anonymity); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + GNUNET_assert(download == event->value.download.dc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *binary_name = cls; const char *keywords[] = { @@ -262,89 +273,89 @@ run (void *cls, struct GNUNET_FS_BlockOptions bo; if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (cfg, - "download-test", - "USE_STREAM")) + GNUNET_CONFIGURATION_get_value_yesno(cfg, + "download-test", + "USE_STREAM")) anonymity_level = 0; else anonymity_level = 1; - fs = GNUNET_FS_start (cfg, binary_name, &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, binary_name, &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = anonymity_level; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (cfg, - "download-test", - "USE_INDEX")) - { - fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn1, - kuri, meta, GNUNET_YES, - &bo); - indexed = GNUNET_YES; - } + GNUNET_CONFIGURATION_get_value_yesno(cfg, + "download-test", + "USE_INDEX")) + { + fn1 = GNUNET_DISK_mktemp("gnunet-download-indexed-test"); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn1, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn1, + kuri, meta, GNUNET_YES, + &bo); + indexed = GNUNET_YES; + } else - { - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - /* note: buf will be free'd as part of 'fi' now */ - indexed = GNUNET_NO; - } - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); + { + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + /* note: buf will be free'd as part of 'fi' now */ + indexed = GNUNET_NO; + } + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); timeout_kill = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); - start = GNUNET_TIME_absolute_get (); + GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { const char *binary_name; const char *config_name; binary_name = "test-fs-download"; config_name = "test_fs_download_data.conf"; - if (NULL != strstr (argv[0], "indexed")) - { - binary_name = "test-fs-download-indexed"; - config_name = "test_fs_download_indexed.conf"; - } - if (NULL != strstr (argv[0], "cadet")) - { - binary_name = "test-fs-download-cadet"; - config_name = "test_fs_download_cadet.conf"; - } - if (0 != GNUNET_TESTING_peer_run (binary_name, - config_name, - &run, (void *) binary_name)) + if (NULL != strstr(argv[0], "indexed")) + { + binary_name = "test-fs-download-indexed"; + config_name = "test_fs_download_indexed.conf"; + } + if (NULL != strstr(argv[0], "cadet")) + { + binary_name = "test-fs-download-cadet"; + config_name = "test_fs_download_cadet.conf"; + } + if (0 != GNUNET_TESTING_peer_run(binary_name, + config_name, + &run, (void *)binary_name)) return 1; if (NULL != fn1) - { - unlink (fn1); - GNUNET_free (fn1); - } + { + unlink(fn1); + GNUNET_free(fn1); + } return err; } diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index 97c2a338c..78dbe821e 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_download_persistence.c @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -62,66 +62,66 @@ static int err; static void -timeout_kill_task (void *cls) +timeout_kill_task(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); if (download != NULL) - { - GNUNET_FS_download_stop (download, GNUNET_YES); - download = NULL; - } + { + GNUNET_FS_download_stop(download, GNUNET_YES); + download = NULL; + } else if (publish != NULL) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } timeout_kill = NULL; err = 1; } static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (publish != NULL) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } } static void -abort_download_task (void *cls) +abort_download_task(void *cls) { uint64_t size; if (download != NULL) - { - GNUNET_FS_download_stop (download, GNUNET_YES); - download = NULL; - } - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES, GNUNET_NO)); - GNUNET_assert (size == FILESIZE); - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); + { + GNUNET_FS_download_stop(download, GNUNET_YES); + download = NULL; + } + GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_size(fn, &size, GNUNET_YES, GNUNET_NO)); + GNUNET_assert(size == FILESIZE); + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); fn = NULL; - GNUNET_SCHEDULER_cancel (timeout_kill); + GNUNET_SCHEDULER_cancel(timeout_kill); timeout_kill = NULL; } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); static void -restart_fs_task (void *cls) +restart_fs_task(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); - GNUNET_FS_stop (fs); - fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); + GNUNET_FS_stop(fs); + fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); } @@ -133,7 +133,7 @@ restart_fs_task (void *cls) * @param ev type of the event to consider */ static void -consider_restart (int ev) +consider_restart(int ev) { static int prev[32]; static int off; @@ -143,141 +143,158 @@ consider_restart (int ev) if (prev[i] == ev) return; prev[off++] = ev; - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, - &restart_fs_task, NULL); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, + &restart_fs_task, NULL); } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - printf ("Publishing complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + printf("Publishing complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL)); - fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); - start = GNUNET_TIME_absolute_get (); - GNUNET_assert (download == NULL); - GNUNET_FS_download_start (fs, - event->value.publish.specifics.completed.chk_uri, - NULL, fn, NULL, 0, FILESIZE, 1, - GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - printf ("Download complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + (start).rel_value_us) / 1024LL)); + fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); + start = GNUNET_TIME_absolute_get(); + GNUNET_assert(download == NULL); + GNUNET_FS_download_start(fs, + event->value.publish.specifics.completed.chk_uri, + NULL, fn, NULL, 0, FILESIZE, 1, + GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + printf("Download complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024LL)); - GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: - consider_restart (event->status); - GNUNET_assert (download == event->value.download.dc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.download.completed, - (unsigned long long) event->value.download.size, - event->value.download.specifics.progress.depth, - (unsigned long long) event->value.download.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - fprintf (stderr, "Error downloading file: %s\n", - event->value.download.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_SUSPEND: - GNUNET_assert (event->value.publish.pc == publish); - publish = NULL; - break; - case GNUNET_FS_STATUS_PUBLISH_RESUME: - GNUNET_assert (NULL == publish); - publish = event->value.publish.pc; - break; - case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); - GNUNET_assert (event->value.download.dc == download); - download = NULL; - break; - case GNUNET_FS_STATUS_DOWNLOAD_RESUME: - GNUNET_assert (NULL == download); - download = event->value.download.dc; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); - break; - case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: - consider_restart (event->status); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); - break; - case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: - consider_restart (event->status); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_DOWNLOAD_START: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); - consider_restart (event->status); - GNUNET_assert (download == NULL); - download = event->value.download.dc; - GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); - GNUNET_assert (NULL == event->value.download.pctx); - GNUNET_assert (NULL != event->value.download.uri); - GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); - GNUNET_assert (FILESIZE == event->value.download.size); - GNUNET_assert (0 == event->value.download.completed); - GNUNET_assert (1 == event->value.download.anonymity); - break; - case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: - GNUNET_assert (download == event->value.download.dc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - download = NULL; - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } + (start).rel_value_us) / 1024LL)); + GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + consider_restart(event->status); + GNUNET_assert(download == event->value.download.dc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Download is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.download.completed, + (unsigned long long)event->value.download.size, + event->value.download.specifics.progress.depth, + (unsigned long long)event->value.download.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + fprintf(stderr, "Error downloading file: %s\n", + event->value.download.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_SUSPEND: + GNUNET_assert(event->value.publish.pc == publish); + publish = NULL; + break; + + case GNUNET_FS_STATUS_PUBLISH_RESUME: + GNUNET_assert(NULL == publish); + publish = event->value.publish.pc; + break; + + case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); + GNUNET_assert(event->value.download.dc == download); + download = NULL; + break; + + case GNUNET_FS_STATUS_DOWNLOAD_RESUME: + GNUNET_assert(NULL == download); + download = event->value.download.dc; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + consider_restart(event->status); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + consider_restart(event->status); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_DOWNLOAD_START: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); + consider_restart(event->status); + GNUNET_assert(download == NULL); + download = event->value.download.dc; + GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); + GNUNET_assert(NULL == event->value.download.pctx); + GNUNET_assert(NULL != event->value.download.uri); + GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); + GNUNET_assert(FILESIZE == event->value.download.size); + GNUNET_assert(0 == event->value.download.completed); + GNUNET_assert(1 == event->value.download.anonymity); + break; + + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + GNUNET_assert(download == event->value.download.dc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + download = NULL; + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -291,40 +308,40 @@ run (void *cls, struct GNUNET_FS_BlockOptions bo; cfg = c; - fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); timeout_kill = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); - start = GNUNET_TIME_absolute_get (); + GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-download-persistence", - "test_fs_download_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-download-persistence", + "test_fs_download_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index 06682043a..1f008997f 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_file_information.c @@ -44,21 +44,21 @@ /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static int -mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, - struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) +mycleaner(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) { return GNUNET_OK; } static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *keywords[] = { "down_foo", @@ -76,67 +76,67 @@ run (void *cls, char *const *args, const char *cfgfile, size_t i; struct GNUNET_FS_BlockOptions bo; - fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-file-information", NULL, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + fn1 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); - buf = GNUNET_malloc (FILESIZE); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn1, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + fn2 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn2, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn2, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); fi1 = - GNUNET_FS_file_information_create_from_file (fs, - "file_information-context1", - fn1, kuri, meta, GNUNET_YES, - &bo); - GNUNET_assert (fi1 != NULL); + GNUNET_FS_file_information_create_from_file(fs, + "file_information-context1", + fn1, kuri, meta, GNUNET_YES, + &bo); + GNUNET_assert(fi1 != NULL); fi2 = - GNUNET_FS_file_information_create_from_file (fs, - "file_information-context2", - fn2, kuri, meta, GNUNET_YES, - &bo); - GNUNET_assert (fi2 != NULL); + GNUNET_FS_file_information_create_from_file(fs, + "file_information-context2", + fn2, kuri, meta, GNUNET_YES, + &bo); + GNUNET_assert(fi2 != NULL); fidir = - GNUNET_FS_file_information_create_empty_directory (fs, - "file_information-context-dir", - kuri, meta, &bo, NULL); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fidir); + GNUNET_FS_file_information_create_empty_directory(fs, + "file_information-context-dir", + kuri, meta, &bo, NULL); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fidir); /* FIXME: test more of API! */ - GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL); - GNUNET_DISK_directory_remove (fn1); - GNUNET_DISK_directory_remove (fn2); - GNUNET_free_non_null (fn1); - GNUNET_free_non_null (fn2); - GNUNET_FS_stop (fs); + GNUNET_FS_file_information_destroy(fidir, &mycleaner, NULL); + GNUNET_DISK_directory_remove(fn1); + GNUNET_DISK_directory_remove(fn2); + GNUNET_free_non_null(fn1); + GNUNET_free_non_null(fn2); + GNUNET_FS_stop(fs); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { char *const argvx[] = { "test-fs-file_information", @@ -148,12 +148,12 @@ main (int argc, char *argv[]) GNUNET_GETOPT_OPTION_END }; - GNUNET_log_setup ("test_fs_file_information", - "WARNING", - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-file_information", "nohelp", options, &run, - NULL); + GNUNET_log_setup("test_fs_file_information", + "WARNING", + NULL); + GNUNET_PROGRAM_run((sizeof(argvx) / sizeof(char *)) - 1, argvx, + "test-fs-file_information", "nohelp", options, &run, + NULL); return 0; } diff --git a/src/fs/test_fs_getopt.c b/src/fs/test_fs_getopt.c index 3562069e1..48777b0e0 100644 --- a/src/fs/test_fs_getopt.c +++ b/src/fs/test_fs_getopt.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_getopt.c * @brief test for fs_getopt.c @@ -27,11 +27,11 @@ int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - GNUNET_log_setup ("test_fs_getopt", - "WARNING", - NULL); - fprintf (stderr, "%s", "WARNING: testcase not yet written.\n"); + GNUNET_log_setup("test_fs_getopt", + "WARNING", + NULL); + fprintf(stderr, "%s", "WARNING: testcase not yet written.\n"); return 0; /* testcase passed */ } diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index a4e7eb53f..b5e5982d0 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_list_indexed.c @@ -40,12 +40,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -62,115 +62,121 @@ static int err; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { - GNUNET_FS_publish_stop (publish); + GNUNET_FS_publish_stop(publish); publish = NULL; - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); + GNUNET_DISK_directory_remove(fn1); + GNUNET_free(fn1); fn1 = NULL; - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); + GNUNET_DISK_directory_remove(fn2); + GNUNET_free(fn2); fn2 = NULL; } static void -list_indexed_task (void *cls) +list_indexed_task(void *cls) { - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { void *ret; ret = NULL; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - ret = event->value.publish.cctx; - printf ("Publish complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + ret = event->value.publish.cctx; + printf("Publish complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) - GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL); - - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - ret = event->value.publish.cctx; - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - ret = event->value.publish.cctx; - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - ret = event->value.publish.cctx; - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - err = 1; - if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - ret = event->value.publish.cctx; - if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("list_indexed-context-dir", - event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - } - else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("list_indexed-context-dir", - event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (2 == event->value.publish.anonymity); - } - else if (0 == - strcmp ("list_indexed-context-dir", event->value.publish.cctx)) - { - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (3 == event->value.publish.anonymity); - } - else - GNUNET_assert (0); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) - { - GNUNET_assert (publish == event->value.publish.pc); - publish = NULL; + (start).rel_value_us) / 1024)); + if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) + GNUNET_SCHEDULER_add_now(&list_indexed_task, NULL); + + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + ret = event->value.publish.cctx; + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + ret = event->value.publish.cctx; + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + ret = event->value.publish.cctx; + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + err = 1; + if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + ret = event->value.publish.cctx; + if (0 == strcmp("list_indexed-context1", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("list_indexed-context-dir", + event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + } + else if (0 == strcmp("list_indexed-context2", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("list_indexed-context-dir", + event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(2 == event->value.publish.anonymity); + } + else if (0 == + strcmp("list_indexed-context-dir", event->value.publish.cctx)) + { + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(3 == event->value.publish.anonymity); + } + else + GNUNET_assert(0); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) + { + GNUNET_assert(publish == event->value.publish.pc); + publish = NULL; + } + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; } - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } return ret; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -185,70 +191,70 @@ run (void *cls, size_t i; struct GNUNET_FS_BlockOptions bo; - fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-list_indexed", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + fn1 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); - buf = GNUNET_malloc (FILESIZE); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn1, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + fn2 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn2, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn2, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); fi1 = - GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1", - fn1, kuri, meta, GNUNET_YES, - &bo); - GNUNET_assert (NULL != fi1); + GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context1", + fn1, kuri, meta, GNUNET_YES, + &bo); + GNUNET_assert(NULL != fi1); bo.anonymity_level = 2; fi2 = - GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2", - fn2, kuri, meta, GNUNET_YES, - &bo); - GNUNET_assert (NULL != fi2); + GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context2", + fn2, kuri, meta, GNUNET_YES, + &bo); + GNUNET_assert(NULL != fi2); bo.anonymity_level = 3; fidir = - GNUNET_FS_file_information_create_empty_directory (fs, - "list_indexed-context-dir", - kuri, meta, &bo, NULL); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fidir); - start = GNUNET_TIME_absolute_get (); + GNUNET_FS_file_information_create_empty_directory(fs, + "list_indexed-context-dir", + kuri, meta, &bo, NULL); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fidir); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed", - "test_fs_list_indexed_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-list-indexed", + "test_fs_list_indexed_data.conf", + &run, NULL)) return 1; return 0; } diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 43c899b72..3abbd5063 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_namespace.c @@ -49,118 +49,123 @@ static int err; static void -abort_ksk_search_task (void *cls) +abort_ksk_search_task(void *cls) { if (ksk_search != NULL) - { - GNUNET_FS_search_stop (ksk_search); - ksk_search = NULL; - if (sks_search == NULL) { - GNUNET_FS_stop (fs); - if (NULL != kill_task) - GNUNET_SCHEDULER_cancel (kill_task); + GNUNET_FS_search_stop(ksk_search); + ksk_search = NULL; + if (sks_search == NULL) + { + GNUNET_FS_stop(fs); + if (NULL != kill_task) + GNUNET_SCHEDULER_cancel(kill_task); + } } - } } static void -abort_sks_search_task (void *cls) +abort_sks_search_task(void *cls) { if (sks_search == NULL) return; - GNUNET_FS_search_stop (sks_search); + GNUNET_FS_search_stop(sks_search); sks_search = NULL; if (ksk_search == NULL) - { - GNUNET_FS_stop (fs); - if (NULL != kill_task) - GNUNET_SCHEDULER_cancel (kill_task); - } + { + GNUNET_FS_stop(fs); + if (NULL != kill_task) + GNUNET_SCHEDULER_cancel(kill_task); + } } static void -do_timeout (void *cls) +do_timeout(void *cls) { err = 1; - fprintf (stderr, "%s", "Operation timed out\n"); + fprintf(stderr, "%s", "Operation timed out\n"); kill_task = NULL; - abort_sks_search_task (NULL); - abort_ksk_search_task (NULL); + abort_sks_search_task(NULL); + abort_ksk_search_task(NULL); } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { switch (event->status) - { - case GNUNET_FS_STATUS_SEARCH_RESULT: - if (sks_search == event->value.search.sc) - { - if (!GNUNET_FS_uri_test_equal - (sks_expect_uri, event->value.search.specifics.result.uri)) - { - fprintf (stderr, "%s", "Wrong result for sks search!\n"); - err = 1; - } - /* give system 1ms to initiate update search! */ - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, - &abort_sks_search_task, NULL); - } - else if (ksk_search == event->value.search.sc) - { - if (!GNUNET_FS_uri_test_equal - (ksk_expect_uri, event->value.search.specifics.result.uri)) - { - fprintf (stderr, "%s", "Wrong result for ksk search!\n"); - err = 1; - } - GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); - } - else - { - fprintf (stderr, "%s", "Unexpected search result received!\n"); - GNUNET_break (0); - } - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, "Error searching file: %s\n", - event->value.search.specifics.error.message); - if (sks_search == event->value.search.sc) - GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); - else if (ksk_search == event->value.search.sc) - GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); - else - GNUNET_break (0); - break; - case GNUNET_FS_STATUS_SEARCH_START: - GNUNET_assert ((NULL == event->value.search.cctx) || - (0 == strcmp ("sks_search", event->value.search.cctx)) || - (0 == strcmp ("ksk_search", event->value.search.cctx))); - if (NULL == event->value.search.cctx) { - GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx)); - update_started = GNUNET_YES; + case GNUNET_FS_STATUS_SEARCH_RESULT: + if (sks_search == event->value.search.sc) + { + if (!GNUNET_FS_uri_test_equal + (sks_expect_uri, event->value.search.specifics.result.uri)) + { + fprintf(stderr, "%s", "Wrong result for sks search!\n"); + err = 1; + } + /* give system 1ms to initiate update search! */ + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, + &abort_sks_search_task, NULL); + } + else if (ksk_search == event->value.search.sc) + { + if (!GNUNET_FS_uri_test_equal + (ksk_expect_uri, event->value.search.specifics.result.uri)) + { + fprintf(stderr, "%s", "Wrong result for ksk search!\n"); + err = 1; + } + GNUNET_SCHEDULER_add_now(&abort_ksk_search_task, NULL); + } + else + { + fprintf(stderr, "%s", "Unexpected search result received!\n"); + GNUNET_break(0); + } + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, "Error searching file: %s\n", + event->value.search.specifics.error.message); + if (sks_search == event->value.search.sc) + GNUNET_SCHEDULER_add_now(&abort_sks_search_task, NULL); + else if (ksk_search == event->value.search.sc) + GNUNET_SCHEDULER_add_now(&abort_ksk_search_task, NULL); + else + GNUNET_break(0); + break; + + case GNUNET_FS_STATUS_SEARCH_START: + GNUNET_assert((NULL == event->value.search.cctx) || + (0 == strcmp("sks_search", event->value.search.cctx)) || + (0 == strcmp("ksk_search", event->value.search.cctx))); + if (NULL == event->value.search.cctx) + { + GNUNET_assert(0 == strcmp("sks_search", event->value.search.pctx)); + update_started = GNUNET_YES; + } + GNUNET_assert(1 == event->value.search.anonymity); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + return NULL; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + return NULL; + + default: + fprintf(stderr, "Unexpected event: %d\n", event->status); + break; } - GNUNET_assert (1 == event->value.search.anonymity); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - return NULL; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - return NULL; - default: - fprintf (stderr, "Unexpected event: %d\n", event->status); - break; - } return event->value.search.cctx; } static void -publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) +publish_cont(void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) { char *msg; struct GNUNET_FS_Uri *sks_uri; @@ -169,37 +174,37 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) char *ret; if (NULL != emsg) - { - fprintf (stderr, "Error publishing: %s\n", emsg); - err = 1; - GNUNET_FS_stop (fs); - return; - } - ret = GNUNET_STRINGS_data_to_string (&nsid, sizeof (nsid), buf, sizeof (buf)); - GNUNET_assert (NULL != ret); + { + fprintf(stderr, "Error publishing: %s\n", emsg); + err = 1; + GNUNET_FS_stop(fs); + return; + } + ret = GNUNET_STRINGS_data_to_string(&nsid, sizeof(nsid), buf, sizeof(buf)); + GNUNET_assert(NULL != ret); ret[0] = '\0'; - GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", buf); - sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); + GNUNET_snprintf(sbuf, sizeof(sbuf), "gnunet://fs/sks/%s/this", buf); + sks_uri = GNUNET_FS_uri_parse(sbuf, &msg); if (NULL == sks_uri) - { - fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); - err = 1; - GNUNET_FS_stop (fs); - GNUNET_free_non_null (msg); - return; - } + { + fprintf(stderr, "failed to parse URI `%s': %s\n", sbuf, msg); + err = 1; + GNUNET_FS_stop(fs); + GNUNET_free_non_null(msg); + return; + } ksk_search = - GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "ksk_search"); + GNUNET_FS_search_start(fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "ksk_search"); sks_search = - GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "sks_search"); - GNUNET_FS_uri_destroy (sks_uri); + GNUNET_FS_search_start(fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "sks_search"); + GNUNET_FS_uri_destroy(sks_uri); } static void -sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) +sks_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Uri *ksk_uri; @@ -207,61 +212,61 @@ sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) struct GNUNET_FS_BlockOptions bo; if (NULL == uri) - { - fprintf (stderr, "Error publishing: %s\n", emsg); - err = 1; - GNUNET_FS_stop (fs); - return; - } - meta = GNUNET_CONTAINER_meta_data_create (); + { + fprintf(stderr, "Error publishing: %s\n", emsg); + err = 1; + GNUNET_FS_stop(fs); + return; + } + meta = GNUNET_CONTAINER_meta_data_create(); msg = NULL; - ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg); - GNUNET_assert (NULL == msg); - ksk_expect_uri = GNUNET_FS_uri_dup (uri); + ksk_uri = GNUNET_FS_uri_parse("gnunet://fs/ksk/ns-search", &msg); + GNUNET_assert(NULL == msg); + ksk_expect_uri = GNUNET_FS_uri_dup(uri); bo.content_priority = 1; bo.anonymity_level = 1; bo.replication_level = 0; bo.expiration_time = - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); - GNUNET_FS_publish_ksk (fs, ksk_uri, meta, uri, &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); - GNUNET_FS_uri_destroy (ksk_uri); - GNUNET_CONTAINER_meta_data_destroy (meta); + GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); + GNUNET_FS_publish_ksk(fs, ksk_uri, meta, uri, &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); + GNUNET_FS_uri_destroy(ksk_uri); + GNUNET_CONTAINER_meta_data_destroy(meta); } static void -adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) +adv_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; struct GNUNET_FS_BlockOptions bo; if (NULL != emsg) - { - fprintf (stderr, "Error publishing: %s\n", emsg); - err = 1; - GNUNET_FS_stop (fs); - return; - } - ns = GNUNET_CRYPTO_ecdsa_key_create (); - meta = GNUNET_CONTAINER_meta_data_create (); - sks_expect_uri = GNUNET_FS_uri_dup (uri); + { + fprintf(stderr, "Error publishing: %s\n", emsg); + err = 1; + GNUNET_FS_stop(fs); + return; + } + ns = GNUNET_CRYPTO_ecdsa_key_create(); + meta = GNUNET_CONTAINER_meta_data_create(); + sks_expect_uri = GNUNET_FS_uri_dup(uri); bo.content_priority = 1; bo.anonymity_level = 1; bo.replication_level = 0; bo.expiration_time = - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); - GNUNET_CRYPTO_ecdsa_key_get_public (ns, &nsid); - GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, - &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_free (ns); + GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); + GNUNET_CRYPTO_ecdsa_key_get_public(ns, &nsid); + GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri, + &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_free(ns); } static void -testNamespace () +testNamespace() { struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; struct GNUNET_FS_BlockOptions bo; @@ -269,46 +274,46 @@ testNamespace () struct GNUNET_FS_Uri *ksk_uri; struct GNUNET_FS_Uri *sks_uri; - ns = GNUNET_CRYPTO_ecdsa_key_create (); - meta = GNUNET_CONTAINER_meta_data_create (); - ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); + ns = GNUNET_CRYPTO_ecdsa_key_create(); + meta = GNUNET_CONTAINER_meta_data_create(); + ksk_uri = GNUNET_FS_uri_parse("gnunet://fs/ksk/testnsa", NULL); bo.content_priority = 1; bo.anonymity_level = 1; bo.replication_level = 0; bo.expiration_time = - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); - sks_uri = GNUNET_FS_uri_sks_create (&nsid, "root"); - GNUNET_FS_publish_ksk (fs, - ksk_uri, meta, sks_uri, - &bo, GNUNET_FS_PUBLISH_OPTION_NONE, - &adv_cont, NULL); - GNUNET_FS_uri_destroy (sks_uri); + GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); + sks_uri = GNUNET_FS_uri_sks_create(&nsid, "root"); + GNUNET_FS_publish_ksk(fs, + ksk_uri, meta, sks_uri, + &bo, GNUNET_FS_PUBLISH_OPTION_NONE, + &adv_cont, NULL); + GNUNET_FS_uri_destroy(sks_uri); kill_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout, - NULL); - GNUNET_FS_uri_destroy (ksk_uri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_free (ns); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &do_timeout, + NULL); + GNUNET_FS_uri_destroy(ksk_uri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_free(ns); } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - testNamespace (); + fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + testNamespace(); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace", - "test_fs_namespace_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-namespace", + "test_fs_namespace_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index 99c0967b8..9a28fcb1b 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_namespace_list_updateable.c @@ -45,129 +45,128 @@ static struct GNUNET_FS_BlockOptions bo; static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { return NULL; } static void -do_shutdown () +do_shutdown() { if (uri_this != NULL) - GNUNET_FS_uri_destroy (uri_this); + GNUNET_FS_uri_destroy(uri_this); if (uri_next != NULL) - GNUNET_FS_uri_destroy (uri_next); + GNUNET_FS_uri_destroy(uri_next); if (ns != NULL) - GNUNET_free (ns); + GNUNET_free(ns); if (meta != NULL) - GNUNET_CONTAINER_meta_data_destroy (meta); + GNUNET_CONTAINER_meta_data_destroy(meta); } static void -check_next (void *cls, const char *last_id, - const struct GNUNET_FS_Uri *last_uri, - const struct GNUNET_CONTAINER_MetaData *last_meta, - const char *next_id) +check_next(void *cls, const char *last_id, + const struct GNUNET_FS_Uri *last_uri, + const struct GNUNET_CONTAINER_MetaData *last_meta, + const char *next_id) { - GNUNET_break (0 == strcmp (last_id, "next")); - GNUNET_break (0 == strcmp (next_id, "future")); + GNUNET_break(0 == strcmp(last_id, "next")); + GNUNET_break(0 == strcmp(next_id, "future")); err -= 4; } static void -check_this_next (void *cls, const char *last_id, - const struct GNUNET_FS_Uri *last_uri, - const struct GNUNET_CONTAINER_MetaData *last_meta, - const char *next_id) +check_this_next(void *cls, const char *last_id, + const struct GNUNET_FS_Uri *last_uri, + const struct GNUNET_CONTAINER_MetaData *last_meta, + const char *next_id) { - GNUNET_break (0 == strcmp (last_id, "this")); - GNUNET_break (0 == strcmp (next_id, "next")); + GNUNET_break(0 == strcmp(last_id, "this")); + GNUNET_break(0 == strcmp(next_id, "next")); err -= 2; err += 4; - GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL); + GNUNET_FS_namespace_list_updateable(fs, ns, next_id, &check_next, NULL); } static void -sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) +sks_cont_next(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { - GNUNET_assert (NULL == emsg); + GNUNET_assert(NULL == emsg); err += 2; - GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL); + GNUNET_FS_namespace_list_updateable(fs, ns, NULL, &check_this_next, NULL); } static void -check_this (void *cls, const char *last_id, - const struct GNUNET_FS_Uri *last_uri, - const struct GNUNET_CONTAINER_MetaData *last_meta, - const char *next_id) +check_this(void *cls, const char *last_id, + const struct GNUNET_FS_Uri *last_uri, + const struct GNUNET_CONTAINER_MetaData *last_meta, + const char *next_id) { - GNUNET_break (0 == strcmp (last_id, "this")); - GNUNET_break (0 == strcmp (next_id, "next")); + GNUNET_break(0 == strcmp(last_id, "this")); + GNUNET_break(0 == strcmp(next_id, "next")); err -= 1; } static void -sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) +sks_cont_this(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { - GNUNET_assert (NULL == emsg); + GNUNET_assert(NULL == emsg); err = 1; - GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL); - GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); - + GNUNET_FS_namespace_list_updateable(fs, ns, NULL, &check_this, NULL); + GNUNET_FS_publish_sks(fs, ns, "next", "future", meta, uri_next, &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); } static void -testNamespace () +testNamespace() { - ns = GNUNET_CRYPTO_ecdsa_key_create (); - GNUNET_assert (NULL != ns); + ns = GNUNET_CRYPTO_ecdsa_key_create(); + GNUNET_assert(NULL != ns); bo.content_priority = 1; bo.anonymity_level = 1; bo.replication_level = 0; bo.expiration_time = - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); - meta = GNUNET_CONTAINER_meta_data_create (); + GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); + meta = GNUNET_CONTAINER_meta_data_create(); uri_this = - GNUNET_FS_uri_parse + GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", - NULL); + NULL); uri_next = - GNUNET_FS_uri_parse + GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", - NULL); - GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); + NULL); + GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri_this, &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - testNamespace (); + fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + testNamespace(); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable", - "test_fs_namespace_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-namespace-list-updateable", + "test_fs_namespace_data.conf", + &run, NULL)) return 1; - do_shutdown (); + do_shutdown(); return err; } diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index fe54bb552..02c1587d2 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_publish.c * @brief simple testcase for publish operation (indexing, listing @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -58,105 +58,111 @@ static int err; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { - GNUNET_FS_publish_stop (publish); + GNUNET_FS_publish_stop(publish); publish = NULL; - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); + GNUNET_DISK_directory_remove(fn1); + GNUNET_free(fn1); fn1 = NULL; - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); + GNUNET_DISK_directory_remove(fn2); + GNUNET_free(fn2); fn2 = NULL; } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { void *ret; ret = NULL; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - ret = event->value.publish.cctx; - printf ("Publish complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + ret = event->value.publish.cctx; + printf("Publish complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - ret = event->value.publish.cctx; - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - ret = event->value.publish.cctx; - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - ret = event->value.publish.cctx; - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - err = 1; - if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) - { - fprintf (stderr, "Scheduling abort task for error on `%s'\n", - (const char *) event->value.publish.cctx); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - } - break; - case GNUNET_FS_STATUS_PUBLISH_START: - ret = event->value.publish.cctx; - if (0 == strcmp ("publish-context1", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("publish-context-dir", event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - } - else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("publish-context-dir", event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (2 == event->value.publish.anonymity); - } - else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) - { - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (3 == event->value.publish.anonymity); + (start).rel_value_us) / 1024)); + if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + ret = event->value.publish.cctx; + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + ret = event->value.publish.cctx; + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + ret = event->value.publish.cctx; + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + err = 1; + if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) + { + fprintf(stderr, "Scheduling abort task for error on `%s'\n", + (const char *)event->value.publish.cctx); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + } + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + ret = event->value.publish.cctx; + if (0 == strcmp("publish-context1", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("publish-context-dir", event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + } + else if (0 == strcmp("publish-context2", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("publish-context-dir", event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(2 == event->value.publish.anonymity); + } + else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) + { + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(3 == event->value.publish.anonymity); + } + else + GNUNET_assert(0); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) + GNUNET_assert(publish == event->value.publish.pc); + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; } - else - GNUNET_assert (0); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) - GNUNET_assert (publish == event->value.publish.pc); - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } return ret; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -171,70 +177,70 @@ run (void *cls, size_t i; struct GNUNET_FS_BlockOptions bo; - fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-publish", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); - buf = GNUNET_malloc (FILESIZE); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn1, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn2, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn2, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); fi1 = - GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, - kuri, meta, GNUNET_YES, &bo); + GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, + kuri, meta, GNUNET_YES, &bo); - GNUNET_assert (NULL != fi1); + GNUNET_assert(NULL != fi1); bo.anonymity_level = 2; fi2 = - GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, - kuri, meta, GNUNET_YES, &bo); - GNUNET_assert (NULL != fi2); + GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, + kuri, meta, GNUNET_YES, &bo); + GNUNET_assert(NULL != fi2); bo.anonymity_level = 3; fidir = - GNUNET_FS_file_information_create_empty_directory (fs, - "publish-context-dir", - kuri, meta, &bo, NULL); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fidir); - start = GNUNET_TIME_absolute_get (); + GNUNET_FS_file_information_create_empty_directory(fs, + "publish-context-dir", + kuri, meta, &bo, NULL); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fidir); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-publish", - "test_fs_publish_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-publish", + "test_fs_publish_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 6242e66f8..7cba55179 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_publish_persistence.c * @brief simple testcase for persistence of simple publish operation @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -64,39 +64,39 @@ static struct GNUNET_SCHEDULER_Task *rtask; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { - GNUNET_FS_publish_stop (publish); + GNUNET_FS_publish_stop(publish); publish = NULL; - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); + GNUNET_DISK_directory_remove(fn1); + GNUNET_free(fn1); fn1 = NULL; - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); + GNUNET_DISK_directory_remove(fn2); + GNUNET_free(fn2); fn2 = NULL; - GNUNET_FS_stop (fs); + GNUNET_FS_stop(fs); fs = NULL; if (NULL != rtask) - { - GNUNET_SCHEDULER_cancel (rtask); - rtask = NULL; - } + { + GNUNET_SCHEDULER_cancel(rtask); + rtask = NULL; + } } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); static void -restart_fs_task (void *cls) +restart_fs_task(void *cls) { rtask = NULL; - GNUNET_FS_stop (fs); - fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", - &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, - GNUNET_FS_OPTIONS_END); + GNUNET_FS_stop(fs); + fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", + &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, + GNUNET_FS_OPTIONS_END); } @@ -108,7 +108,7 @@ restart_fs_task (void *cls) * @param ev type of the event to consider */ static void -consider_restart (int ev) +consider_restart(int ev) { static int prev[32]; static int off; @@ -119,115 +119,123 @@ consider_restart (int ev) return; prev[off++] = ev; rtask = - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, - &restart_fs_task, NULL); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, + &restart_fs_task, NULL); } static void * -progress_cb (void *cls, - const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, + const struct GNUNET_FS_ProgressInfo *event) { void *ret; ret = NULL; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - ret = event->value.publish.cctx; - printf ("Publish complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + ret = event->value.publish.cctx; + printf("Publish complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - if ( (NULL != event->value.publish.cctx) && - (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - ret = event->value.publish.cctx; - return ret; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - consider_restart (event->status); - ret = event->value.publish.cctx; - GNUNET_assert (publish == event->value.publish.pc); + (start).rel_value_us) / 1024)); + if ((NULL != event->value.publish.cctx) && + (0 == strcmp("publish-context-dir", event->value.publish.cctx))) + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + ret = event->value.publish.cctx; + return ret; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + consider_restart(event->status); + ret = event->value.publish.cctx; + GNUNET_assert(publish == event->value.publish.pc); #if VERBOSE - printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); + printf("Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); #endif - break; - case GNUNET_FS_STATUS_PUBLISH_SUSPEND: - if (event->value.publish.pc == publish) - publish = NULL; - break; - case GNUNET_FS_STATUS_PUBLISH_RESUME: - if (NULL == publish) - { - GNUNET_assert (GNUNET_YES == - GNUNET_FS_file_information_is_directory (event-> - value.publish. - fi)); + break; + + case GNUNET_FS_STATUS_PUBLISH_SUSPEND: + if (event->value.publish.pc == publish) + publish = NULL; + break; + + case GNUNET_FS_STATUS_PUBLISH_RESUME: + if (NULL == publish) + { + GNUNET_assert(GNUNET_YES == + GNUNET_FS_file_information_is_directory(event-> + value.publish. + fi)); + publish = event->value.publish.pc; + return "publish-context-dir"; + } + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + ret = event->value.publish.cctx; + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + err = 1; + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + consider_restart(event->status); publish = event->value.publish.pc; - return "publish-context-dir"; - } - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - ret = event->value.publish.cctx; - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - err = 1; - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - consider_restart (event->status); - publish = event->value.publish.pc; - ret = event->value.publish.cctx; - if (0 == strcmp ("publish-context1", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("publish-context-dir", event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - } - else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) - { - GNUNET_assert (0 == - strcmp ("publish-context-dir", event->value.publish.pctx)); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (2 == event->value.publish.anonymity); - } - else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) - { - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (3 == event->value.publish.anonymity); + ret = event->value.publish.cctx; + if (0 == strcmp("publish-context1", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("publish-context-dir", event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + } + else if (0 == strcmp("publish-context2", event->value.publish.cctx)) + { + GNUNET_assert(0 == + strcmp("publish-context-dir", event->value.publish.pctx)); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(2 == event->value.publish.anonymity); + } + else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) + { + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(3 == event->value.publish.anonymity); + } + else + GNUNET_assert(0); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + consider_restart(event->status); + if ((NULL != event->value.publish.cctx) && + (0 == strcmp("publish-context-dir", event->value.publish.cctx))) + GNUNET_assert(publish == event->value.publish.pc); + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; } - else - GNUNET_assert (0); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - consider_restart (event->status); - if ( (NULL != event->value.publish.cctx) && - (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) - GNUNET_assert (publish == event->value.publish.pc); - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } return ret; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -243,67 +251,67 @@ run (void *cls, struct GNUNET_FS_BlockOptions bo; cfg = c; - fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); - buf = GNUNET_malloc (FILESIZE); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn1, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn2, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn2, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); fi1 = - GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, - kuri, meta, GNUNET_YES, &bo); - GNUNET_assert (NULL != fi1); + GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, + kuri, meta, GNUNET_YES, &bo); + GNUNET_assert(NULL != fi1); bo.anonymity_level = 2; fi2 = - GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, - kuri, meta, GNUNET_YES, &bo); - GNUNET_assert (NULL != fi2); + GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, + kuri, meta, GNUNET_YES, &bo); + GNUNET_assert(NULL != fi2); bo.anonymity_level = 3; fidir = - GNUNET_FS_file_information_create_empty_directory (fs, - "publish-context-dir", - kuri, meta, &bo, NULL); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); - GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fidir); - start = GNUNET_TIME_absolute_get (); - GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_file_information_create_empty_directory(fs, + "publish-context-dir", + kuri, meta, &bo, NULL); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); + GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fidir); + start = GNUNET_TIME_absolute_get(); + GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence", - "test_fs_publish_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-publish-persistence", + "test_fs_publish_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 2a7f4b1dd..7906a4163 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_search.c * @brief simple testcase for simple publish + search operation @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -58,54 +58,54 @@ static int err; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } } static void -abort_error (void *cls) +abort_error(void *cls) { - fprintf (stderr, - "Timeout\n"); + fprintf(stderr, + "Timeout\n"); timeout_task = NULL; if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } err = 1; } static void -abort_search_task (void *cls) +abort_search_task(void *cls) { if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { const char *keywords[] = { "down_foo" @@ -113,80 +113,91 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) struct GNUNET_FS_Uri *kuri; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); - start = GNUNET_TIME_absolute_get (); - search = - GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "search"); - GNUNET_FS_uri_destroy (kuri); - GNUNET_assert (search != NULL); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Search complete.\n"); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, "Error searching file: %s\n", - event->value.search.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_SEARCH_START: - GNUNET_assert (search == NULL); - GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); - GNUNET_assert (1 == event->value.search.anonymity); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - break; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - GNUNET_assert (search == event->value.search.sc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - fprintf (stderr, "Unexpected event: %d\n", event->status); - break; - } + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); + start = GNUNET_TIME_absolute_get(); + search = + GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "search"); + GNUNET_FS_uri_destroy(kuri); + GNUNET_assert(search != NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Search complete.\n"); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, "Error searching file: %s\n", + event->value.search.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_SEARCH_START: + GNUNET_assert(search == NULL); + GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); + GNUNET_assert(1 == event->value.search.anonymity); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + break; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_assert(search == event->value.search.sc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + fprintf(stderr, "Unexpected event: %d\n", event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -199,40 +210,40 @@ run (void *cls, struct GNUNET_FS_FileInformation *fi; size_t i; - fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, - &abort_error, NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, + &abort_error, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-search", - "test_fs_search_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-search", + "test_fs_search_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index 68e3a4a62..b01abe75f 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_search_persistence.c * @brief simple testcase for persistence of search operation @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -60,62 +60,62 @@ static int err; static void -abort_error (void *cls) +abort_error(void *cls) { timeout_task = NULL; - fprintf (stderr, - "Timeout\n"); + fprintf(stderr, + "Timeout\n"); if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } err = 1; } static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } } static void -abort_search_task (void *cls) +abort_search_task(void *cls) { if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); static void -restart_fs_task (void *cls) +restart_fs_task(void *cls) { - GNUNET_FS_stop (fs); - fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_FS_stop(fs); + fs = GNUNET_FS_start(cfg, "test-fs-search-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); } @@ -127,7 +127,7 @@ restart_fs_task (void *cls) * @param ev type of the event to consider */ static void -consider_restart (int ev) +consider_restart(int ev) { static int prev[32]; static int off; @@ -137,13 +137,13 @@ consider_restart (int ev) if (prev[i] == ev) return; prev[off++] = ev; - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, - &restart_fs_task, NULL); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, + &restart_fs_task, NULL); } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { const char *keywords[] = { "down_foo" @@ -151,103 +151,118 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) struct GNUNET_FS_Uri *kuri; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); - start = GNUNET_TIME_absolute_get (); - GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "search"); - GNUNET_FS_uri_destroy (kuri); - GNUNET_assert (search != NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_SUSPEND: - if (event->value.publish.pc == publish) - publish = NULL; - break; - case GNUNET_FS_STATUS_PUBLISH_RESUME: - if (NULL == publish) - publish = event->value.publish.pc; - break; - case GNUNET_FS_STATUS_SEARCH_RESULT: - /* FIXME: consider_restart (event->status); cannot be tested with - * search result since we exit here after the first one... */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Search complete.\n"); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, "Error searching file: %s\n", - event->value.search.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_SUSPEND: - if (event->value.search.sc == search) - search = NULL; - break; - case GNUNET_FS_STATUS_SEARCH_RESUME: - if (NULL == search) { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); + start = GNUNET_TIME_absolute_get(); + GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "search"); + GNUNET_FS_uri_destroy(kuri); + GNUNET_assert(search != NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_SUSPEND: + if (event->value.publish.pc == publish) + publish = NULL; + break; + + case GNUNET_FS_STATUS_PUBLISH_RESUME: + if (NULL == publish) + publish = event->value.publish.pc; + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + /* FIXME: consider_restart (event->status); cannot be tested with + * search result since we exit here after the first one... */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Search complete.\n"); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, "Error searching file: %s\n", + event->value.search.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_SUSPEND: + if (event->value.search.sc == search) + search = NULL; + break; + + case GNUNET_FS_STATUS_SEARCH_RESUME: + if (NULL == search) + { + search = event->value.search.sc; + return "search"; + } + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_SEARCH_START: + consider_restart(event->status); + GNUNET_assert(search == NULL); search = event->value.search.sc; - return "search"; + GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); + GNUNET_assert(1 == event->value.search.anonymity); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + break; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_assert(search == event->value.search.sc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + search = NULL; + break; + + default: + fprintf(stderr, "Unexpected event: %d\n", event->status); + break; } - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_SEARCH_START: - consider_restart (event->status); - GNUNET_assert (search == NULL); - search = event->value.search.sc; - GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); - GNUNET_assert (1 == event->value.search.anonymity); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - break; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - GNUNET_assert (search == event->value.search.sc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - search = NULL; - break; - default: - fprintf (stderr, "Unexpected event: %d\n", event->status); - break; - } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -261,40 +276,40 @@ run (void *cls, struct GNUNET_FS_BlockOptions bo; cfg = c; - fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-search-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, - &abort_error, NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, + &abort_error, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-search-persistence", - "test_fs_search_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-search-persistence", + "test_fs_search_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c index c65649108..5584efca7 100644 --- a/src/fs/test_fs_search_probes.c +++ b/src/fs/test_fs_search_probes.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_search_probes.c @@ -37,12 +37,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -59,52 +59,52 @@ static int err; static void -abort_error (void *cls) +abort_error(void *cls) { timeout_task = NULL; - fprintf (stderr, - "Timeout\n"); + fprintf(stderr, + "Timeout\n"); if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } err = 1; } static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } } static void -abort_search_task (void *cls) +abort_search_task(void *cls) { if (search != NULL) - GNUNET_FS_search_stop (search); + GNUNET_FS_search_stop(search); search = NULL; } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { const char *keywords[] = { "down_foo" @@ -112,85 +112,97 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) struct GNUNET_FS_Uri *kuri; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); - start = GNUNET_TIME_absolute_get (); - search = - GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "search"); - GNUNET_FS_uri_destroy (kuri); - GNUNET_assert (search != NULL); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, "Error searching file: %s\n", - event->value.search.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_SEARCH_UPDATE: - if ( (0 < event->value.search.specifics.update.availability_rank) && - (0 < event->value.search.specifics.update.availability_certainty) ) - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_START: - GNUNET_assert (search == NULL); - GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); - GNUNET_assert (1 == event->value.search.anonymity); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - break; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - GNUNET_assert (search == event->value.search.sc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - fprintf (stderr, - "Unexpected event: %d\n", - event->status); - break; - } + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); + start = GNUNET_TIME_absolute_get(); + search = + GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "search"); + GNUNET_FS_uri_destroy(kuri); + GNUNET_assert(search != NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, "Error searching file: %s\n", + event->value.search.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_SEARCH_UPDATE: + if ((0 < event->value.search.specifics.update.availability_rank) && + (0 < event->value.search.specifics.update.availability_certainty)) + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_START: + GNUNET_assert(search == NULL); + GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); + GNUNET_assert(1 == event->value.search.anonymity); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + break; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_assert(search == event->value.search.sc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + fprintf(stderr, + "Unexpected event: %d\n", + event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -203,41 +215,41 @@ run (void *cls, struct GNUNET_FS_FileInformation *fi; size_t i; - fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, - GNUNET_FS_FLAGS_DO_PROBES, - GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, + GNUNET_FS_FLAGS_DO_PROBES, + GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, - &abort_error, NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, + &abort_error, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-search-probes", - "test_fs_search_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-search-probes", + "test_fs_search_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_search_with_and.c b/src/fs/test_fs_search_with_and.c index f1072a4a1..e43b8e25a 100644 --- a/src/fs/test_fs_search_with_and.c +++ b/src/fs/test_fs_search_with_and.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_search_with_and.c * @brief testcase for publishing multiple files and search with a and operator @@ -42,12 +42,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -66,140 +66,150 @@ static int processed_files; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } } static void -abort_error (void *cls) +abort_error(void *cls) { - fprintf (stderr, - "Timeout\n"); + fprintf(stderr, + "Timeout\n"); timeout_task = NULL; if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } if (NULL != publish) - { - GNUNET_FS_publish_stop (publish); - publish = NULL; - } + { + GNUNET_FS_publish_stop(publish); + publish = NULL; + } err = 1; } static void -abort_search_task (void *cls) +abort_search_task(void *cls) { if (NULL != search) - { - GNUNET_FS_search_stop (search); - search = NULL; - } + { + GNUNET_FS_search_stop(search); + search = NULL; + } } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { - struct GNUNET_FS_Uri *kuri; switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - processed_files++; - if(processed_files == NUM_FILES) - { - char *emsg = NULL; - kuri = GNUNET_FS_uri_ksk_create ("+down_foo +down_bar", &emsg); - GNUNET_assert (kuri != NULL); - - start = GNUNET_TIME_absolute_get (); - search = - GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, - "search"); - GNUNET_FS_uri_destroy (kuri); - GNUNET_assert (search != NULL); - } - break; - case GNUNET_FS_STATUS_SEARCH_RESULT: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Search complete.\n"); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_SEARCH_ERROR: - fprintf (stderr, "Error searching file: %s\n", - event->value.search.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_SEARCH_START: - GNUNET_assert (search == NULL); - GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); - GNUNET_assert (1 == event->value.search.anonymity); - break; - case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: - break; - case GNUNET_FS_STATUS_SEARCH_STOPPED: - GNUNET_assert (search == event->value.search.sc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - fprintf (stderr, "Unexpected event: %d\n", event->status); - break; - } + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + processed_files++; + if (processed_files == NUM_FILES) + { + char *emsg = NULL; + kuri = GNUNET_FS_uri_ksk_create("+down_foo +down_bar", &emsg); + GNUNET_assert(kuri != NULL); + + start = GNUNET_TIME_absolute_get(); + search = + GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, + "search"); + GNUNET_FS_uri_destroy(kuri); + GNUNET_assert(search != NULL); + } + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Search complete.\n"); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf(stderr, "Error searching file: %s\n", + event->value.search.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_SEARCH_START: + GNUNET_assert(search == NULL); + GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); + GNUNET_assert(1 == event->value.search.anonymity); + break; + + case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: + break; + + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_assert(search == event->value.search.sc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + fprintf(stderr, "Unexpected event: %d\n", event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -213,46 +223,47 @@ run (void *cls, size_t i; size_t j; - fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); + fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); processed_files = 0; - for(j = 0; j < NUM_FILES; j++){ - buf = GNUNET_malloc (FILESIZE); - for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); - bo.content_priority = 42; - bo.anonymity_level = 1; - bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", - FILESIZE, buf, kuri, meta, - GNUNET_NO, &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); - publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, + for (j = 0; j < NUM_FILES; j++) + { + buf = GNUNET_malloc(FILESIZE); + for (i = 0; i < FILESIZE; i++) + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); + bo.content_priority = 42; + bo.anonymity_level = 1; + bo.replication_level = 0; + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", + FILESIZE, buf, kuri, meta, + GNUNET_NO, &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); + publish = + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); - } + GNUNET_assert(publish != NULL); + } - timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, - &abort_error, NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, + &abort_error, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-search-with-and", - "test_fs_search_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-search-with-and", + "test_fs_search_data.conf", + &run, NULL)) return 1; return err; } diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index e20e00996..4e3c17db0 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_start_stop.c * @brief testcase for fs.c (start-stop only) @@ -30,32 +30,32 @@ static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { struct GNUNET_FS_Handle *fs; - fs = GNUNET_FS_start (cfg, "test-fs-start-stop", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - GNUNET_FS_stop (fs); + fs = GNUNET_FS_start(cfg, "test-fs-start-stop", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + GNUNET_FS_stop(fs); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-start-stop", - "test_fs_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-start-stop", + "test_fs_data.conf", + &run, NULL)) return 1; return 0; } diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c index 52b0bf2c0..7e27469cc 100644 --- a/src/fs/test_fs_test_lib.c +++ b/src/fs/test_fs_test_lib.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_test_lib.c @@ -36,7 +36,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) #define NUM_DAEMONS 2 @@ -50,75 +50,74 @@ static int ret; static void -do_stop (void *cls) +do_stop(void *cls) { char *fn = cls; if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, - TIMEOUT)).rel_value_us) - { - GNUNET_break (0); - ret = 1; - } + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, + TIMEOUT)).rel_value_us) + { + GNUNET_break(0); + ret = 1; + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished download, shutting down\n"); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished download, shutting down\n"); + } if (NULL != fn) - { - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); + } + GNUNET_SCHEDULER_shutdown(); } static void -do_download (void *cls, - const struct GNUNET_FS_Uri *uri, - const char *fn) +do_download(void *cls, + const struct GNUNET_FS_Uri *uri, + const char *fn) { if (NULL == uri) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - ret = 1; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Downloading %llu bytes\n", - (unsigned long long) FILESIZE); - start_time = GNUNET_TIME_absolute_get (); - GNUNET_FS_TEST_download (the_peers[0], - TIMEOUT, 1, SEED, - uri, - VERBOSE, - &do_stop, - (NULL == fn) ? NULL : GNUNET_strdup (fn)); + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + ret = 1; + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Downloading %llu bytes\n", + (unsigned long long)FILESIZE); + start_time = GNUNET_TIME_absolute_get(); + GNUNET_FS_TEST_download(the_peers[0], + TIMEOUT, 1, SEED, + uri, + VERBOSE, + &do_stop, + (NULL == fn) ? NULL : GNUNET_strdup(fn)); } static void -do_publish (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +do_publish(void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { - GNUNET_TESTBED_operation_done (op); + GNUNET_TESTBED_operation_done(op); if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); - GNUNET_break (0); - ret = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", - (unsigned long long) FILESIZE); - GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, - VERBOSE, &do_download, NULL); - + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); + GNUNET_break(0); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", + (unsigned long long)FILESIZE); + GNUNET_FS_TEST_publish(the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, + VERBOSE, &do_download, NULL); } @@ -135,23 +134,23 @@ do_publish (void *cls, * failed */ static void -run (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +run(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int i; - GNUNET_assert (NUM_DAEMONS == num_peers); - for (i=0;i. SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_unindex.c @@ -37,12 +37,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -57,117 +57,127 @@ static char *fn; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { - GNUNET_FS_publish_stop (publish); + GNUNET_FS_publish_stop(publish); publish = NULL; } static void -abort_unindex_task (void *cls) +abort_unindex_task(void *cls) { - GNUNET_FS_unindex_stop (unindex); + GNUNET_FS_unindex_stop(unindex); unindex = NULL; - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); fn = NULL; } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { - switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - printf ("Publishing complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + printf("Publishing complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - start = GNUNET_TIME_absolute_get (); - unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); - GNUNET_assert (unindex != NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - printf ("Unindex complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + (start).rel_value_us) / 1024)); + start = GNUNET_TIME_absolute_get(); + unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); + GNUNET_assert(unindex != NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_COMPLETED: + printf("Unindex complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_PROGRESS: - GNUNET_assert (unindex == event->value.unindex.uc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.unindex.completed, - (unsigned long long) event->value.unindex.size, - event->value.unindex.specifics.progress.depth, - (unsigned long long) event->value.unindex.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_ERROR: - fprintf (stderr, "Error unindexing file: %s\n", - event->value.unindex.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_UNINDEX_START: - GNUNET_assert (unindex == NULL); - GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); - GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); - GNUNET_assert (FILESIZE == event->value.unindex.size); - GNUNET_assert (0 == event->value.unindex.completed); - break; - case GNUNET_FS_STATUS_UNINDEX_STOPPED: - GNUNET_assert (unindex == event->value.unindex.uc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } + (start).rel_value_us) / 1024)); + GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_PROGRESS: + GNUNET_assert(unindex == event->value.unindex.uc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.unindex.completed, + (unsigned long long)event->value.unindex.size, + event->value.unindex.specifics.progress.depth, + (unsigned long long)event->value.unindex.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_ERROR: + fprintf(stderr, "Error unindexing file: %s\n", + event->value.unindex.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_UNINDEX_START: + GNUNET_assert(unindex == NULL); + GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx)); + GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename)); + GNUNET_assert(FILESIZE == event->value.unindex.size); + GNUNET_assert(0 == event->value.unindex.completed); + break; + + case GNUNET_FS_STATUS_UNINDEX_STOPPED: + GNUNET_assert(unindex == event->value.unindex.uc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; + } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -180,44 +190,44 @@ run (void *cls, size_t i; struct GNUNET_FS_BlockOptions bo; - fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); - fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); + fs = GNUNET_FS_start(cfg, "test-fs-unindex", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn, - kuri, meta, GNUNET_YES, - &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn, + kuri, meta, GNUNET_YES, + &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex", - "test_fs_unindex_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-unindex", + "test_fs_unindex_data.conf", + &run, NULL)) return 1; return 0; } diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index 50d45708a..7deebb95b 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_unindex_persistence.c @@ -36,12 +36,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * How long should our test-content live? */ -#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) static struct GNUNET_TIME_Absolute start; @@ -58,40 +58,40 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; static void -abort_publish_task (void *cls) +abort_publish_task(void *cls) { - GNUNET_FS_publish_stop (publish); + GNUNET_FS_publish_stop(publish); publish = NULL; } static void -abort_unindex_task (void *cls) +abort_unindex_task(void *cls) { if (unindex != NULL) - { - GNUNET_FS_unindex_stop (unindex); - unindex = NULL; - } + { + GNUNET_FS_unindex_stop(unindex); + unindex = NULL; + } if (fn != NULL) - { - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); - fn = NULL; - } + { + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); + fn = NULL; + } } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); static void -restart_fs_task (void *cls) +restart_fs_task(void *cls) { - GNUNET_FS_stop (fs); - fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_FS_stop(fs); + fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); } @@ -103,7 +103,7 @@ restart_fs_task (void *cls) * @param ev type of the event to consider */ static void -consider_restart (int ev) +consider_restart(int ev) { static int prev[32]; static int off; @@ -113,125 +113,140 @@ consider_restart (int ev) if (prev[i] == ev) return; prev[off++] = ev; - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, - &restart_fs_task, NULL); + GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, + &restart_fs_task, NULL); } static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) { switch (event->status) - { - case GNUNET_FS_STATUS_PUBLISH_PROGRESS: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: - break; - case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - printf ("Publishing complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + { + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.publish.completed, + (unsigned long long)event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long)event->value.publish.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: + break; + + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + printf("Publishing complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - start = GNUNET_TIME_absolute_get (); - unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); - GNUNET_assert (unindex != NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - printf ("Unindex complete, %llu kbps.\n", - (unsigned long long) (FILESIZE * 1000000LL / + (start).rel_value_us) / 1024)); + start = GNUNET_TIME_absolute_get(); + unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); + GNUNET_assert(unindex != NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_COMPLETED: + printf("Unindex complete, %llu kbps.\n", + (unsigned long long)(FILESIZE * 1000000LL / (1 + GNUNET_TIME_absolute_get_duration - (start).rel_value_us) / 1024)); - GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_PROGRESS: - consider_restart (event->status); - GNUNET_assert (unindex == event->value.unindex.uc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.unindex.completed, - (unsigned long long) event->value.unindex.size, - event->value.unindex.specifics.progress.depth, - (unsigned long long) event->value.unindex.specifics. - progress.offset); - break; - case GNUNET_FS_STATUS_PUBLISH_SUSPEND: - if (event->value.publish.pc == publish) - publish = NULL; - break; - case GNUNET_FS_STATUS_PUBLISH_RESUME: - if (NULL == publish) - { - publish = event->value.publish.pc; - return "publish-context"; + (start).rel_value_us) / 1024)); + GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_PROGRESS: + consider_restart(event->status); + GNUNET_assert(unindex == event->value.unindex.uc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long)event->value.unindex.completed, + (unsigned long long)event->value.unindex.size, + event->value.unindex.specifics.progress.depth, + (unsigned long long)event->value.unindex.specifics. + progress.offset); + break; + + case GNUNET_FS_STATUS_PUBLISH_SUSPEND: + if (event->value.publish.pc == publish) + publish = NULL; + break; + + case GNUNET_FS_STATUS_PUBLISH_RESUME: + if (NULL == publish) + { + publish = event->value.publish.pc; + return "publish-context"; + } + break; + + case GNUNET_FS_STATUS_UNINDEX_SUSPEND: + GNUNET_assert(event->value.unindex.uc == unindex); + unindex = NULL; + break; + + case GNUNET_FS_STATUS_UNINDEX_RESUME: + GNUNET_assert(NULL == unindex); + unindex = event->value.unindex.uc; + return "unindex"; + + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf(stderr, "Error publishing file: %s\n", + event->value.publish.specifics.error.message); + GNUNET_break(0); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + case GNUNET_FS_STATUS_UNINDEX_ERROR: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Error unindexing file: %s\n", + event->value.unindex.specifics.error.message); + GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); + break; + + case GNUNET_FS_STATUS_PUBLISH_START: + GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); + GNUNET_assert(NULL == event->value.publish.pctx); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(0 == event->value.publish.completed); + GNUNET_assert(1 == event->value.publish.anonymity); + break; + + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + GNUNET_assert(publish == event->value.publish.pc); + GNUNET_assert(FILESIZE == event->value.publish.size); + GNUNET_assert(1 == event->value.publish.anonymity); + GNUNET_FS_stop(fs); + fs = NULL; + break; + + case GNUNET_FS_STATUS_UNINDEX_START: + consider_restart(event->status); + GNUNET_assert(unindex == NULL); + GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx)); + GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename)); + GNUNET_assert(FILESIZE == event->value.unindex.size); + GNUNET_assert(0 == event->value.unindex.completed); + break; + + case GNUNET_FS_STATUS_UNINDEX_STOPPED: + GNUNET_assert(unindex == event->value.unindex.uc); + GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); + break; + + default: + printf("Unexpected event: %d\n", event->status); + break; } - break; - case GNUNET_FS_STATUS_UNINDEX_SUSPEND: - GNUNET_assert (event->value.unindex.uc == unindex); - unindex = NULL; - break; - case GNUNET_FS_STATUS_UNINDEX_RESUME: - GNUNET_assert (NULL == unindex); - unindex = event->value.unindex.uc; - return "unindex"; - case GNUNET_FS_STATUS_PUBLISH_ERROR: - fprintf (stderr, "Error publishing file: %s\n", - event->value.publish.specifics.error.message); - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - case GNUNET_FS_STATUS_UNINDEX_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Error unindexing file: %s\n", - event->value.unindex.specifics.error.message); - GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); - break; - case GNUNET_FS_STATUS_PUBLISH_START: - GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); - GNUNET_assert (NULL == event->value.publish.pctx); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (0 == event->value.publish.completed); - GNUNET_assert (1 == event->value.publish.anonymity); - break; - case GNUNET_FS_STATUS_PUBLISH_STOPPED: - GNUNET_assert (publish == event->value.publish.pc); - GNUNET_assert (FILESIZE == event->value.publish.size); - GNUNET_assert (1 == event->value.publish.anonymity); - GNUNET_FS_stop (fs); - fs = NULL; - break; - case GNUNET_FS_STATUS_UNINDEX_START: - consider_restart (event->status); - GNUNET_assert (unindex == NULL); - GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); - GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); - GNUNET_assert (FILESIZE == event->value.unindex.size); - GNUNET_assert (0 == event->value.unindex.completed); - break; - case GNUNET_FS_STATUS_UNINDEX_STOPPED: - GNUNET_assert (unindex == event->value.unindex.uc); - GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); - break; - default: - printf ("Unexpected event: %d\n", event->status); - break; - } return NULL; } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", @@ -245,44 +260,44 @@ run (void *cls, struct GNUNET_FS_BlockOptions bo; cfg = c; - fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); - fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); - GNUNET_assert (NULL != fs); - buf = GNUNET_malloc (FILESIZE); + fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); + fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + GNUNET_assert(NULL != fs); + buf = GNUNET_malloc(FILESIZE); for (i = 0; i < FILESIZE; i++) - buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn, buf, FILESIZE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)); - GNUNET_free (buf); - meta = GNUNET_CONTAINER_meta_data_create (); - kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); + buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); + GNUNET_assert(FILESIZE == + GNUNET_DISK_fn_write(fn, buf, FILESIZE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)); + GNUNET_free(buf); + meta = GNUNET_CONTAINER_meta_data_create(); + kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; - bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); - fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn, - kuri, meta, GNUNET_YES, - &bo); - GNUNET_FS_uri_destroy (kuri); - GNUNET_CONTAINER_meta_data_destroy (meta); - GNUNET_assert (NULL != fi); - start = GNUNET_TIME_absolute_get (); + bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); + fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn, + kuri, meta, GNUNET_YES, + &bo); + GNUNET_FS_uri_destroy(kuri); + GNUNET_CONTAINER_meta_data_destroy(meta); + GNUNET_assert(NULL != fi); + start = GNUNET_TIME_absolute_get(); publish = - GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, - GNUNET_FS_PUBLISH_OPTION_NONE); - GNUNET_assert (publish != NULL); + GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, + GNUNET_FS_PUBLISH_OPTION_NONE); + GNUNET_assert(publish != NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex-persistence", - "test_fs_unindex_data.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test-fs-unindex-persistence", + "test_fs_unindex_data.conf", + &run, NULL)) return 1; return 0; } diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index e0a2ecea7..3cbbc27d3 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_fs_uri.c * @brief Test for fs_uri.c @@ -29,52 +29,52 @@ static int -testKeyword () +testKeyword() { char *uri; struct GNUNET_FS_Uri *ret; char *emsg; - if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); - ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg); + if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/++", &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); + ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/foo+bar", &emsg); if (NULL == ret) - { - GNUNET_free (emsg); - GNUNET_assert (0); - } - if (! GNUNET_FS_uri_test_ksk (ret)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } + { + GNUNET_free(emsg); + GNUNET_assert(0); + } + if (!GNUNET_FS_uri_test_ksk(ret)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } if ((2 != ret->data.ksk.keywordCount) || - (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || - (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } + (0 != strcmp(" foo", ret->data.ksk.keywords[0])) || + (0 != strcmp(" bar", ret->data.ksk.keywords[1]))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } - uri = GNUNET_FS_uri_to_string (ret); - if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar")) - { - GNUNET_free (uri); - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (uri); - GNUNET_FS_uri_destroy (ret); + uri = GNUNET_FS_uri_to_string(ret); + if (0 != strcmp(uri, "gnunet://fs/ksk/foo+bar")) + { + GNUNET_free(uri); + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(uri); + GNUNET_FS_uri_destroy(ret); return 0; } static int -testLocation () +testLocation() { struct GNUNET_FS_Uri *uri; char *uric; @@ -84,71 +84,71 @@ testLocation () struct GNUNET_CRYPTO_EddsaPrivateKey *pk; baseURI = - GNUNET_FS_uri_parse + GNUNET_FS_uri_parse ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999", - &emsg); - GNUNET_assert (baseURI != NULL); - GNUNET_assert (emsg == NULL); - pk = GNUNET_CRYPTO_eddsa_key_create (); - uri = GNUNET_FS_uri_loc_create (baseURI, - pk, - GNUNET_TIME_absolute_get ()); - GNUNET_free (pk); + &emsg); + GNUNET_assert(baseURI != NULL); + GNUNET_assert(emsg == NULL); + pk = GNUNET_CRYPTO_eddsa_key_create(); + uri = GNUNET_FS_uri_loc_create(baseURI, + pk, + GNUNET_TIME_absolute_get()); + GNUNET_free(pk); if (NULL == uri) - { - GNUNET_break (0); - GNUNET_FS_uri_destroy (baseURI); - return 1; - } - if (! GNUNET_FS_uri_test_loc (uri)) - { - GNUNET_break (0); - GNUNET_FS_uri_destroy (uri); - GNUNET_FS_uri_destroy (baseURI); - return 1; - } - uri2 = GNUNET_FS_uri_loc_get_uri (uri); - if (! GNUNET_FS_uri_test_equal (baseURI, uri2)) - { - GNUNET_break (0); - GNUNET_FS_uri_destroy (uri); - GNUNET_FS_uri_destroy (uri2); - GNUNET_FS_uri_destroy (baseURI); - return 1; - } - GNUNET_FS_uri_destroy (uri2); - GNUNET_FS_uri_destroy (baseURI); - uric = GNUNET_FS_uri_to_string (uri); + { + GNUNET_break(0); + GNUNET_FS_uri_destroy(baseURI); + return 1; + } + if (!GNUNET_FS_uri_test_loc(uri)) + { + GNUNET_break(0); + GNUNET_FS_uri_destroy(uri); + GNUNET_FS_uri_destroy(baseURI); + return 1; + } + uri2 = GNUNET_FS_uri_loc_get_uri(uri); + if (!GNUNET_FS_uri_test_equal(baseURI, uri2)) + { + GNUNET_break(0); + GNUNET_FS_uri_destroy(uri); + GNUNET_FS_uri_destroy(uri2); + GNUNET_FS_uri_destroy(baseURI); + return 1; + } + GNUNET_FS_uri_destroy(uri2); + GNUNET_FS_uri_destroy(baseURI); + uric = GNUNET_FS_uri_to_string(uri); #if 0 /* not for the faint of heart: */ - printf ("URI: `%s'\n", uric); + printf("URI: `%s'\n", uric); #endif - uri2 = GNUNET_FS_uri_parse (uric, &emsg); - GNUNET_free (uric); + uri2 = GNUNET_FS_uri_parse(uric, &emsg); + GNUNET_free(uric); if (uri2 == NULL) - { - fprintf (stderr, "URI parsing failed: %s\n", emsg); - GNUNET_break (0); - GNUNET_FS_uri_destroy (uri); - GNUNET_free (emsg); - return 1; - } - GNUNET_assert (NULL == emsg); - if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) - { - GNUNET_break (0); - GNUNET_FS_uri_destroy (uri); - GNUNET_FS_uri_destroy (uri2); - return 1; - } - GNUNET_FS_uri_destroy (uri2); - GNUNET_FS_uri_destroy (uri); + { + fprintf(stderr, "URI parsing failed: %s\n", emsg); + GNUNET_break(0); + GNUNET_FS_uri_destroy(uri); + GNUNET_free(emsg); + return 1; + } + GNUNET_assert(NULL == emsg); + if (GNUNET_YES != GNUNET_FS_uri_test_equal(uri, uri2)) + { + GNUNET_break(0); + GNUNET_FS_uri_destroy(uri); + GNUNET_FS_uri_destroy(uri2); + return 1; + } + GNUNET_FS_uri_destroy(uri2); + GNUNET_FS_uri_destroy(uri); return 0; } static int -testNamespace (int i) +testNamespace(int i) { char *uri; struct GNUNET_FS_Uri *ret; @@ -161,71 +161,71 @@ testNamespace (int i) if (NULL != (ret = - GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", - &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); + GNUNET_FS_uri_parse("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", + &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); if (NULL != (ret = - GNUNET_FS_uri_parse - ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); - if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); - ph = GNUNET_CRYPTO_ecdsa_key_create (); - GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id); - sret = GNUNET_STRINGS_data_to_string (&id, sizeof (id), - ubuf, sizeof (ubuf) - 1); - GNUNET_assert (NULL != sret); + GNUNET_FS_uri_parse + ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); + if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/sks/test", &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); + ph = GNUNET_CRYPTO_ecdsa_key_create(); + GNUNET_CRYPTO_ecdsa_key_get_public(ph, &id); + sret = GNUNET_STRINGS_data_to_string(&id, sizeof(id), + ubuf, sizeof(ubuf) - 1); + GNUNET_assert(NULL != sret); sret[0] = '\0'; - GNUNET_snprintf (buf, sizeof (buf), - "gnunet://fs/sks/%s/test", - ubuf); - ret = GNUNET_FS_uri_parse (buf, &emsg); + GNUNET_snprintf(buf, sizeof(buf), + "gnunet://fs/sks/%s/test", + ubuf); + ret = GNUNET_FS_uri_parse(buf, &emsg); if (NULL == ret) - { - GNUNET_free (emsg); - GNUNET_assert (0); - } - if (GNUNET_FS_uri_test_ksk (ret)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - if (!GNUNET_FS_uri_test_sks (ret)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } + { + GNUNET_free(emsg); + GNUNET_assert(0); + } + if (GNUNET_FS_uri_test_ksk(ret)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + if (!GNUNET_FS_uri_test_sks(ret)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } - uri = GNUNET_FS_uri_to_string (ret); + uri = GNUNET_FS_uri_to_string(ret); if (0 != - strcmp (uri, - buf)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_free (uri); - GNUNET_assert (0); - } - GNUNET_free (uri); - GNUNET_FS_uri_destroy (ret); + strcmp(uri, + buf)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_free(uri); + GNUNET_assert(0); + } + GNUNET_free(uri); + GNUNET_FS_uri_destroy(ret); return 0; } static int -testFile (int i) +testFile(int i) { char *uri; struct GNUNET_FS_Uri *ret; @@ -233,93 +233,93 @@ testFile (int i) if (NULL != (ret = - GNUNET_FS_uri_parse - ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", - &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); + GNUNET_FS_uri_parse + ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", + &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); if (NULL != (ret = - GNUNET_FS_uri_parse - ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", - &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); + GNUNET_FS_uri_parse + ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", + &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); if (NULL != (ret = - GNUNET_FS_uri_parse - ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", - &emsg))) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (emsg); + GNUNET_FS_uri_parse + ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", + &emsg))) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(emsg); ret = - GNUNET_FS_uri_parse + GNUNET_FS_uri_parse ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42", - &emsg); + &emsg); if (ret == NULL) - { - GNUNET_free (emsg); - GNUNET_assert (0); - } - if (GNUNET_FS_uri_test_ksk (ret)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - if (GNUNET_FS_uri_test_sks (ret)) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - if (GNUNET_ntohll (ret->data.chk.file_length) != 42) - { - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } + { + GNUNET_free(emsg); + GNUNET_assert(0); + } + if (GNUNET_FS_uri_test_ksk(ret)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + if (GNUNET_FS_uri_test_sks(ret)) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + if (GNUNET_ntohll(ret->data.chk.file_length) != 42) + { + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } - uri = GNUNET_FS_uri_to_string (ret); + uri = GNUNET_FS_uri_to_string(ret); if (0 != - strcmp (uri, - "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) - { - GNUNET_free (uri); - GNUNET_FS_uri_destroy (ret); - GNUNET_assert (0); - } - GNUNET_free (uri); - GNUNET_FS_uri_destroy (ret); + strcmp(uri, + "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) + { + GNUNET_free(uri); + GNUNET_FS_uri_destroy(ret); + GNUNET_assert(0); + } + GNUNET_free(uri); + GNUNET_FS_uri_destroy(ret); return 0; } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { int failureCount = 0; int i; - GNUNET_log_setup ("test_fs_uri", - "WARNING", - NULL); - failureCount += testKeyword (); - failureCount += testLocation (); + GNUNET_log_setup("test_fs_uri", + "WARNING", + NULL); + failureCount += testKeyword(); + failureCount += testLocation(); for (i = 0; i < 255; i++) - { - /* fprintf (stderr, "%s", "."); */ - failureCount += testNamespace (i); - failureCount += testFile (i); - } + { + /* fprintf (stderr, "%s", "."); */ + failureCount += testNamespace(i); + failureCount += testFile(i); + } /* fprintf (stderr, "%s", "\n"); */ - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); + GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-uri"); if (failureCount != 0) return 1; return 0; diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index f7daf6b1a..c56e89e11 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_gnunet_service_fs_migration.c @@ -37,12 +37,12 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) /** * How long do we give the peers for content migration? */ -#define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) +#define MIGRATION_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) #define SEED 42 @@ -55,8 +55,7 @@ static struct GNUNET_TIME_Absolute start_time; static struct GNUNET_TESTBED_Operation *op; -struct DownloadContext -{ +struct DownloadContext { char *fn; struct GNUNET_FS_Uri *uri; @@ -64,154 +63,154 @@ struct DownloadContext static void -do_stop (void *cls) +do_stop(void *cls) { struct GNUNET_TIME_Relative del; char *fancy; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, - TIMEOUT)).rel_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout during download, shutting down with error\n"); - ok = 1; - } + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, + TIMEOUT)).rel_value_us) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout during download, shutting down with error\n"); + ok = 1; + } else - { - del = GNUNET_TIME_absolute_get_duration (start_time); - if (del.rel_value_us == 0) - del.rel_value_us = 1; - fancy = - GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * - 1000000LL / del.rel_value_us); - fprintf (stdout, - "Download speed was %s/s\n", - fancy); - GNUNET_free (fancy); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished download, shutting down\n"); - } + { + del = GNUNET_TIME_absolute_get_duration(start_time); + if (del.rel_value_us == 0) + del.rel_value_us = 1; + fancy = + GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * + 1000000LL / del.rel_value_us); + fprintf(stdout, + "Download speed was %s/s\n", + fancy); + GNUNET_free(fancy); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished download, shutting down\n"); + } } static void -do_download (void *cls, - const char *emsg) +do_download(void *cls, + const char *emsg) { struct DownloadContext *dc = cls; struct GNUNET_FS_Uri *uri = dc->uri; - GNUNET_TESTBED_operation_done (op); + GNUNET_TESTBED_operation_done(op); op = NULL; if (NULL != dc->fn) - { - GNUNET_DISK_directory_remove (dc->fn); - GNUNET_free (dc->fn); - } - GNUNET_free (dc); + { + GNUNET_DISK_directory_remove(dc->fn); + GNUNET_free(dc->fn); + } + GNUNET_free(dc); if (NULL != emsg) - { - GNUNET_SCHEDULER_shutdown (); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to stop source daemon: %s\n", - emsg); - GNUNET_FS_uri_destroy (uri); - ok = 1; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Downloading %llu bytes\n", - (unsigned long long) FILESIZE); - start_time = GNUNET_TIME_absolute_get (); - GNUNET_FS_TEST_download (daemons[0], - TIMEOUT, - 1, - SEED, - uri, - VERBOSE, - &do_stop, - NULL); - GNUNET_FS_uri_destroy (uri); + { + GNUNET_SCHEDULER_shutdown(); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Failed to stop source daemon: %s\n", + emsg); + GNUNET_FS_uri_destroy(uri); + ok = 1; + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Downloading %llu bytes\n", + (unsigned long long)FILESIZE); + start_time = GNUNET_TIME_absolute_get(); + GNUNET_FS_TEST_download(daemons[0], + TIMEOUT, + 1, + SEED, + uri, + VERBOSE, + &do_stop, + NULL); + GNUNET_FS_uri_destroy(uri); } static void -stop_source_peer (void *cls) +stop_source_peer(void *cls) { struct DownloadContext *dc = cls; /* FIXME: We should not interact with testbed when shutting down */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stopping source peer\n"); - op = GNUNET_TESTBED_peer_stop (NULL, - daemons[1], - &do_download, dc); - GNUNET_assert (NULL != op); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Stopping source peer\n"); + op = GNUNET_TESTBED_peer_stop(NULL, + daemons[1], + &do_download, dc); + GNUNET_assert(NULL != op); } static void -do_wait (void *cls, - const struct GNUNET_FS_Uri *uri, - const char *fn) +do_wait(void *cls, + const struct GNUNET_FS_Uri *uri, + const char *fn) { struct DownloadContext *dc; if (NULL == uri) - { - GNUNET_SCHEDULER_shutdown (); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout during upload attempt, shutting down with error\n"); - ok = 1; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Waiting to allow content to migrate\n"); - dc = GNUNET_new (struct DownloadContext); - dc->uri = GNUNET_FS_uri_dup (uri); + { + GNUNET_SCHEDULER_shutdown(); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout during upload attempt, shutting down with error\n"); + ok = 1; + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Waiting to allow content to migrate\n"); + dc = GNUNET_new(struct DownloadContext); + dc->uri = GNUNET_FS_uri_dup(uri); if (NULL != fn) - dc->fn = GNUNET_strdup (fn); - (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, - &stop_source_peer, - dc); + dc->fn = GNUNET_strdup(fn); + (void)GNUNET_SCHEDULER_add_delayed(MIGRATION_DELAY, + &stop_source_peer, + dc); } static void -do_publish (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +do_publish(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int i; - GNUNET_assert (2 == num_peers); - for (i=0;i. SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_gnunet_service_fs_p2p.c @@ -36,7 +36,7 @@ /** * How long until we give up on the download? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) #define NUM_DAEMONS 2 @@ -54,110 +54,110 @@ static struct GNUNET_TIME_Absolute start_time; static void -do_stop (void *cls) +do_stop(void *cls) { char *fn = cls; struct GNUNET_TIME_Relative del; char *fancy; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, - TIMEOUT)).rel_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout during download, shutting down with error\n"); - ok = 1; - } + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, + TIMEOUT)).rel_value_us) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout during download, shutting down with error\n"); + ok = 1; + } else - { - del = GNUNET_TIME_absolute_get_duration (start_time); - if (0 == del.rel_value_us) - del.rel_value_us = 1; - fancy = - GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * - 1000000LL / del.rel_value_us); - fprintf (stdout, - "Download speed was %s/s\n", - fancy); - GNUNET_free (fancy); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished download, shutting down\n"); - } + { + del = GNUNET_TIME_absolute_get_duration(start_time); + if (0 == del.rel_value_us) + del.rel_value_us = 1; + fancy = + GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * + 1000000LL / del.rel_value_us); + fprintf(stdout, + "Download speed was %s/s\n", + fancy); + GNUNET_free(fancy); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Finished download, shutting down\n"); + } if (NULL != fn) - { - GNUNET_DISK_directory_remove (fn); - GNUNET_free (fn); - } + { + GNUNET_DISK_directory_remove(fn); + GNUNET_free(fn); + } } static void -do_download (void *cls, const struct GNUNET_FS_Uri *uri, - const char *fn) +do_download(void *cls, const struct GNUNET_FS_Uri *uri, + const char *fn) { if (NULL == uri) - { - GNUNET_SCHEDULER_shutdown (); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout during upload attempt, shutting down with error\n"); - ok = 1; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", - (unsigned long long) FILESIZE); - start_time = GNUNET_TIME_absolute_get (); - GNUNET_FS_TEST_download (daemons[0], TIMEOUT, - anonymity_level, SEED, uri, - VERBOSE, &do_stop, - (NULL == fn) - ? NULL - : GNUNET_strdup (fn)); + { + GNUNET_SCHEDULER_shutdown(); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout during upload attempt, shutting down with error\n"); + ok = 1; + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", + (unsigned long long)FILESIZE); + start_time = GNUNET_TIME_absolute_get(); + GNUNET_FS_TEST_download(daemons[0], TIMEOUT, + anonymity_level, SEED, uri, + VERBOSE, &do_stop, + (NULL == fn) + ? NULL + : GNUNET_strdup(fn)); } static void -do_publish (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +do_publish(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int i; - if (NULL != strstr (progname, "cadet")) + if (NULL != strstr(progname, "cadet")) anonymity_level = 0; else anonymity_level = 1; - GNUNET_assert (NUM_DAEMONS == num_peers); - for (i=0;i. SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file fs/test_plugin_block_fs.c * @brief test for plugin_block_fs.c @@ -27,64 +27,64 @@ static int -test_fs (struct GNUNET_BLOCK_Context *ctx) +test_fs(struct GNUNET_BLOCK_Context *ctx) { struct GNUNET_HashCode key; char block[4]; - memset (block, 1, sizeof (block)); + memset(block, 1, sizeof(block)); if (GNUNET_OK != - GNUNET_BLOCK_get_key (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, block, - sizeof (block), &key)) + GNUNET_BLOCK_get_key(ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, block, + sizeof(block), &key)) return 1; if (GNUNET_BLOCK_EVALUATION_OK_LAST != - GNUNET_BLOCK_evaluate (ctx, - GNUNET_BLOCK_TYPE_FS_DBLOCK, - NULL, - GNUNET_BLOCK_EO_NONE, - &key, - NULL, 0, - block, sizeof (block))) + GNUNET_BLOCK_evaluate(ctx, + GNUNET_BLOCK_TYPE_FS_DBLOCK, + NULL, + GNUNET_BLOCK_EO_NONE, + &key, + NULL, 0, + block, sizeof(block))) return 2; if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != - GNUNET_BLOCK_evaluate (ctx, - GNUNET_BLOCK_TYPE_FS_DBLOCK, - NULL, - GNUNET_BLOCK_EO_NONE, - &key, - NULL, 0, - NULL, 0)) + GNUNET_BLOCK_evaluate(ctx, + GNUNET_BLOCK_TYPE_FS_DBLOCK, + NULL, + GNUNET_BLOCK_EO_NONE, + &key, + NULL, 0, + NULL, 0)) return 4; - GNUNET_log_skip (1, GNUNET_NO); + GNUNET_log_skip(1, GNUNET_NO); if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != - GNUNET_BLOCK_evaluate (ctx, - GNUNET_BLOCK_TYPE_FS_DBLOCK, - NULL, - GNUNET_BLOCK_EO_NONE, - &key, - "bogus", 5, - NULL, 0)) + GNUNET_BLOCK_evaluate(ctx, + GNUNET_BLOCK_TYPE_FS_DBLOCK, + NULL, + GNUNET_BLOCK_EO_NONE, + &key, + "bogus", 5, + NULL, 0)) return 8; - GNUNET_log_skip (0, GNUNET_YES); + GNUNET_log_skip(0, GNUNET_YES); return 0; } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { int ret; struct GNUNET_BLOCK_Context *ctx; struct GNUNET_CONFIGURATION_Handle *cfg; - GNUNET_log_setup ("test-block", "WARNING", NULL); - cfg = GNUNET_CONFIGURATION_create (); - ctx = GNUNET_BLOCK_context_create (cfg); - ret = test_fs (ctx); - GNUNET_BLOCK_context_destroy (ctx); - GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_log_setup("test-block", "WARNING", NULL); + cfg = GNUNET_CONFIGURATION_create(); + ctx = GNUNET_BLOCK_context_create(cfg); + ret = test_fs(ctx); + GNUNET_BLOCK_context_destroy(ctx); + GNUNET_CONFIGURATION_destroy(cfg); if (ret != 0) - fprintf (stderr, "Tests failed: %d\n", ret); + fprintf(stderr, "Tests failed: %d\n", ret); return ret; } -- cgit v1.2.3