static void cleanup_task (void *cls) { GNUNET_FS_stop (ctx); ctx = NULL; }
static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) { const char *keywords[] = { "down_foo" }; 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_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_continuation (&abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 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_continuation (&abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; case GNUNET_FS_STATUS_SEARCH_ERROR: FPRINTF (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 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; 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_continuation (&abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); search = NULL; break; default: FPRINTF (stderr, "Unexpected event: %d\n", event->status); break; } return NULL; }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *keywords[] = { "down_foo", "down_bar", }; char *fn1; char *fn2; char *buf; struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Uri *kuri; struct GNUNET_FS_FileInformation *fi1; struct GNUNET_FS_FileInformation *fi2; struct GNUNET_FS_FileInformation *fidir; struct GNUNET_FS_Handle *fs; 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); 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); 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); bo.content_priority = 42; bo.anonymity_level = 1; bo.replication_level = 0; 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); fi2 = 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); /* 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); }
static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) { const char *keywords[] = { "down_foo" }; 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; } return NULL; }
static void * 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 / (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 / (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"; } 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 * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) { switch (event->status) { case GNUNET_FS_STATUS_PUBLISH_PROGRESS: #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); #endif break; case GNUNET_FS_STATUS_PUBLISH_COMPLETED: printf ("Publishing complete, %llu kbps.\n", (unsigned long long) (FILESIZE * 1000 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value) / 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 * 1000 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; case GNUNET_FS_STATUS_UNINDEX_PROGRESS: GNUNET_assert (unindex == event->value.unindex.uc); #if VERBOSE printf ("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); #endif 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_continuation (&abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; case GNUNET_FS_STATUS_UNINDEX_ERROR: FPRINTF (stderr, "Error unindexing file: %s\n", event->value.unindex.specifics.error.message); GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 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_continuation (&abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; default: printf ("Unexpected event: %d\n", event->status); break; } return NULL; }
static void cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_FS_stop (ctx); ctx = NULL; }
/** * Main function that will be run by the scheduler. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param c configuration */ static void 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); 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; } if (NULL == filename) { 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); if (NULL == ctx) { 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); if (dc == NULL) { GNUNET_FS_stop (ctx); ctx = NULL; return; } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }