static void restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_FS_stop (fs); fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); }
/** * 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) { /* check arguments */ if ((args[0] == NULL) || (args[1] != NULL)) { 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); if (NULL == ctx) { 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); }
static void 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 (); }
static void 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); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_FS_Handle *fs; setup_peer (&p1, "test_fs_data.conf"); 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); }
static void 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); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", "down_bar" }; char *buf; struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Uri *kuri; struct GNUNET_FS_BlockOptions bo; struct GNUNET_FS_FileInformation *fi; 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); 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, GNUNET_FS_PUBLISH_OPTION_NONE); GNUNET_assert (publish != NULL); } timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, &abort_error, 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; unsigned int argc; enum GNUNET_FS_SearchOptions options; argc = 0; while (NULL != args[argc]) argc++; 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; } cfg = c; 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; } if (output_filename != 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); if (NULL == sc) { FPRINTF (stderr, "%s", _("Could not start searching.\n")); GNUNET_FS_stop (ctx); ret = 1; return; } if (0 != timeout.rel_value_us) GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL); else GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_TESTING_Peer *peer) { const char *keywords[] = { "down_foo", "down_bar", }; char *buf; struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Uri *kuri; struct GNUNET_FS_FileInformation *fi; size_t i; 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); 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); 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 (); publish = GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, GNUNET_FS_PUBLISH_OPTION_NONE); GNUNET_assert (publish != NULL); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { const char *keywords[] = { "down_foo", "down_bar", }; 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; size_t i; struct GNUNET_FS_BlockOptions bo; cfg = c; setup_peer (&p1, "test_fs_publish_data.conf"); 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); 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, "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); 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); }
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); }
/** * 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); }