Author: grothoff Date: 2008-02-18 19:47:32 -0700 (Mon, 18 Feb 2008) New Revision: 6374
Modified: GNUnet/doc/man/gnunet-insert.1 GNUnet/src/applications/bootstrap_http/http.c GNUnet/src/applications/fs/ecrs/upload.c GNUnet/src/applications/fs/fsui/upload.c GNUnet/src/applications/fs/tools/gnunet-insert.c GNUnet/src/include/gnunet_ecrs_lib.h GNUnet/src/include/gnunet_fsui_lib.h Log: adding mantis 937 and 1308 support Modified: GNUnet/doc/man/gnunet-insert.1 =================================================================== --- GNUnet/doc/man/gnunet-insert.1 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/doc/man/gnunet-insert.1 2008-02-19 02:47:32 UTC (rev 6374) @@ -218,6 +218,12 @@ file into the namespace specified by the pseudonym NAME. .TP +\fB\-s\fR, \fB\-\-simulate-only\fR +When this option is used, gnunet\-insert will not actually publish +the file but just simulate what would be done. This can be used to +compute the GNUnet URI for a file without actually sharing it. + +.TP \fB\-S\fR, \fB\-\-sporadic\fR This option specifies that the file will be updated sporadically but not periodically. It is only valid in conjunction with the \-P @@ -248,6 +254,22 @@ time is the current time. .TP +\fB\-u \fIURI\fR, \fB\-\-uri=\fIURI\fR +This option can be used to specify the URI of a file instead of +a filename (this is the only case where the otherwise mandatory +filename argument must be omitted). Instead of publishing a file +or directory and using the corresponding URI, gnunet\-insert will +use this URI and perform the selected namespace or keyword +operations. This can be used to add additional keywords to a +file that has already been shared or to add files to a namespace +for which the URI is known but the content is not locally available. + +.TP +\fB\-U \fIID\fR, \fB\-\-update=\fIID\fR +When updating an entry in the namespace, this option can be used +to specify the ID of the previous entry. + +.TP \fB\-v\fR, \fB\-\-version\fR Print the version number. Modified: GNUnet/src/applications/bootstrap_http/http.c =================================================================== --- GNUnet/src/applications/bootstrap_http/http.c 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/applications/bootstrap_http/http.c 2008-02-19 02:47:32 UTC (rev 6374) @@ -30,6 +30,7 @@ #include "gnunet_protocols.h" #include "gnunet_bootstrap_service.h" #include "gnunet_stats_service.h" +#include "gnunet_transport_service.h" #include <curl/curl.h> @@ -38,6 +39,8 @@ */ static GNUNET_Stats_ServiceAPI *stats; +static GNUNET_Transport_ServiceAPI *transport; + static GNUNET_CoreAPIForPlugins *coreAPI; static int stat_hellodownloaded; @@ -129,7 +132,9 @@ GNUNET_BootstrapTerminateCallback termTest, void *targ) { BootstrapContext bctx; + unsigned long long protocols; char *url; + char *purl; char *proxy; CURL *curl; CURLcode ret; @@ -146,6 +151,7 @@ #endif unsigned int urls; size_t pos; + int i; if (0 != curl_global_init (CURL_GLOBAL_WIN32)) { @@ -217,6 +223,14 @@ GNUNET_GE_LOG (ectx, GNUNET_GE_INFO | GNUNET_GE_BULK | GNUNET_GE_USER, _("Bootstrapping using `%s'.\n"), url); + purl = GNUNET_malloc(strlen(url) + 40); + protocols = 0; + for (i=GNUNET_TRANSPORT_PROTOCOL_NUMBER_MAX;i>GNUNET_TRANSPORT_PROTOCOL_NUMBER_NAT;i--) + if (transport->isAvailable((unsigned short)i)) + protocols |= (1LL << i); + sprintf(purl, "%s&p=%llu", url, protocols); + GNUNET_free(url); + url = purl; bctx.url = url; bctx.total = 0; proxy = NULL; @@ -271,7 +285,7 @@ { GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("%s failed at %s:%d: `%s'\n"), + GNUNET_GE_BULK, _("%s failed at %s:%d: `%s'\n"), "curl_multi_fdset", __FILE__, __LINE__, curl_multi_strerror (mret)); goto cleanup; @@ -390,6 +404,9 @@ coreAPI = capi; ectx = capi->ectx; + transport = coreAPI->request_service ("transport"); + if (transport == NULL) + return NULL; stats = coreAPI->request_service ("stats"); if (stats != NULL) { @@ -405,6 +422,8 @@ { if (stats != NULL) coreAPI->release_service (stats); + coreAPI->release_service (transport); + transport = NULL; coreAPI = NULL; } Modified: GNUnet/src/applications/fs/ecrs/upload.c =================================================================== --- GNUnet/src/applications/fs/ecrs/upload.c 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/applications/fs/ecrs/upload.c 2008-02-19 02:47:32 UTC (rev 6374) @@ -104,7 +104,8 @@ * @param priority what is the priority for OUR node to * keep this file available? Use 0 for maximum anonymity and * minimum reliability... - * @param doIndex GNUNET_YES for index, GNUNET_NO for insertion + * @param doIndex GNUNET_YES for index, GNUNET_NO for insertion, + * GNUNET_SYSERR for simulation * @param uri set to the URI of the uploaded file * @return GNUNET_SYSERR if the upload failed (i.e. not enough space * or gnunetd not running) @@ -173,7 +174,7 @@ eta = 0; if (upcb != NULL) upcb (filesize, 0, eta, upcbClosure); - if (doIndex) + if (doIndex == GNUNET_YES) { if (GNUNET_SYSERR == GNUNET_hash_file (ectx, filename, &fileId)) { @@ -208,7 +209,7 @@ _ ("Indexing file `%s' failed. Trying to insert file...\n"), filename); - doIndex = GNUNET_YES; + doIndex = GNUNET_NO; break; default: break; @@ -293,7 +294,7 @@ "Query for current block of size %u is `%s'\n", size, (const char *) &enc); #endif - if (doIndex) + if (doIndex == GNUNET_YES) { if (GNUNET_SYSERR == GNUNET_FS_index (sock, &fileId, dblock, pos)) { @@ -318,8 +319,8 @@ } GNUNET_GE_ASSERT (ectx, value != NULL); *value = *dblock; /* copy options! */ - - if (GNUNET_SYSERR == GNUNET_FS_insert (sock, value)) + if ( (doIndex == GNUNET_NO) && + (GNUNET_SYSERR == GNUNET_FS_insert (sock, value)) ) { GNUNET_GE_BREAK (ectx, 0); GNUNET_free (value); @@ -392,7 +393,8 @@ } value->expirationTime = GNUNET_htonll (expirationTime); value->prio = htonl (priority); - if (GNUNET_SYSERR == GNUNET_FS_insert (sock, value)) + if ( (doIndex != GNUNET_SYSERR) && + (GNUNET_SYSERR == GNUNET_FS_insert (sock, value)) ) { GNUNET_GE_BREAK (ectx, 0); GNUNET_free (value); Modified: GNUnet/src/applications/fs/fsui/upload.c =================================================================== --- GNUnet/src/applications/fs/fsui/upload.c 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/applications/fs/fsui/upload.c 2008-02-19 02:47:32 UTC (rev 6374) @@ -347,7 +347,7 @@ utc->shared->doIndex == GNUNET_YES ? (utc->child == NULL ? GNUNET_YES : GNUNET_NO) : - GNUNET_NO, utc->shared->anonymityLevel, + utc->shared->doIndex, utc->shared->anonymityLevel, utc->shared->priority, utc->shared->expiration, &progressCallback, utc, &testTerminate, utc, &utc->uri); @@ -382,104 +382,110 @@ return NULL; } utc->state = GNUNET_FSUI_COMPLETED; - if (utc->child == NULL) - GNUNET_ECRS_meta_data_extract_from_file (utc->shared->ctx->ectx, - utc->meta, utc->filename, - utc->shared->extractors); - while (GNUNET_OK == - GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_FILENAME, NULL)); - /* only publish the last part of the path - -- we do not want to publish $HOME or similar - trivially deanonymizing information */ - tpos = strlen (utc->filename) - 1; - if ((utc->filename[tpos] == DIR_SEPARATOR) && (tpos > 0)) - tpos--; - while ((tpos > 0) && (utc->filename[tpos] != DIR_SEPARATOR)) - tpos--; - pfn = GNUNET_malloc (strlen (&utc->filename[tpos + 1]) + 2); - strcpy (pfn, &utc->filename[tpos + 1]); - if ((utc->child != NULL) && - ((strlen (pfn) == 0) || (pfn[strlen (pfn) - 1] != DIR_SEPARATOR))) - strcat (pfn, DIR_SEPARATOR_STR); - GNUNET_ECRS_meta_data_insert (utc->meta, EXTRACTOR_FILENAME, pfn); - GNUNET_free (pfn); - if ((utc->shared->anonymityLevel == 0) - && (utc->shared->doIndex == GNUNET_YES)) + if (utc->shared->doIndex != GNUNET_SYSERR) { - /* generate location URI for non-anonymous download */ - struct GNUNET_ClientServerConnection *sock; - GNUNET_MessageHello *hello; - - sock = GNUNET_client_connection_create (utc->shared->ctx->ectx, - utc->shared->ctx->cfg); - - if (GNUNET_OK == GNUNET_IDENTITY_get_self (sock, &hello)) - { - loc = GNUNET_ECRS_location_to_uri (utc->uri, - &hello->publicKey, - ntohl (hello->expirationTime), - (GNUNET_ECRS_SignFunction) & - GNUNET_IDENTITY_sign_function, - sock); - - GNUNET_free (hello); - } + if (utc->child == NULL) + GNUNET_ECRS_meta_data_extract_from_file (utc->shared->ctx->ectx, + utc->meta, utc->filename, + utc->shared->extractors); + while (GNUNET_OK == + GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_FILENAME, NULL)); + /* only publish the last part of the path + -- we do not want to publish $HOME or similar + trivially deanonymizing information */ + tpos = strlen (utc->filename) - 1; + if ((utc->filename[tpos] == DIR_SEPARATOR) && (tpos > 0)) + tpos--; + while ((tpos > 0) && (utc->filename[tpos] != DIR_SEPARATOR)) + tpos--; + pfn = GNUNET_malloc (strlen (&utc->filename[tpos + 1]) + 2); + strcpy (pfn, &utc->filename[tpos + 1]); + if ((utc->child != NULL) && + ((strlen (pfn) == 0) || (pfn[strlen (pfn) - 1] != DIR_SEPARATOR))) + strcat (pfn, DIR_SEPARATOR_STR); + GNUNET_ECRS_meta_data_insert (utc->meta, EXTRACTOR_FILENAME, pfn); + GNUNET_free (pfn); + if ((utc->shared->anonymityLevel == 0) + && (utc->shared->doIndex == GNUNET_YES)) + { + /* generate location URI for non-anonymous download */ + struct GNUNET_ClientServerConnection *sock; + GNUNET_MessageHello *hello; + + sock = GNUNET_client_connection_create (utc->shared->ctx->ectx, + utc->shared->ctx->cfg); + + if (GNUNET_OK == GNUNET_IDENTITY_get_self (sock, &hello)) + { + loc = GNUNET_ECRS_location_to_uri (utc->uri, + &hello->publicKey, + ntohl (hello->expirationTime), + (GNUNET_ECRS_SignFunction) & + GNUNET_IDENTITY_sign_function, + sock); + + GNUNET_free (hello); + } + else + { + /* may happen if no transports are available... */ + loc = GNUNET_ECRS_uri_duplicate (utc->uri); + } + GNUNET_client_connection_destroy (sock); + } else - { - /* may happen if no transports are available... */ - loc = GNUNET_ECRS_uri_duplicate (utc->uri); - } - GNUNET_client_connection_destroy (sock); + { + /* no location URI, use standard URI + (copied here to allow free later) */ + loc = GNUNET_ECRS_uri_duplicate (utc->uri); + } + while (GNUNET_OK == + GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_SPLIT, NULL)); + while (GNUNET_OK == + GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_LOWERCASE, NULL)); + if (utc->shared->global_keywords != NULL) + GNUNET_ECRS_publish_under_keyword (ectx, + utc->shared->ctx->cfg, + utc->shared->global_keywords, + utc->shared->anonymityLevel, + utc->shared->priority, + utc->shared->expiration, loc, + utc->meta); + if (utc->keywords != NULL) + GNUNET_ECRS_publish_under_keyword (ectx, + utc->shared->ctx->cfg, + utc->keywords, + utc->shared->anonymityLevel, + utc->shared->priority, + utc->shared->expiration, loc, + utc->meta); + if (utc->shared->individualKeywords == GNUNET_YES) + { + uri = GNUNET_ECRS_meta_data_to_uri (utc->meta); + GNUNET_ECRS_publish_under_keyword (ectx, + utc->shared->ctx->cfg, + uri, + utc->shared->anonymityLevel, + utc->shared->priority, + utc->shared->expiration, loc, + utc->meta); + GNUNET_ECRS_uri_destroy (uri); + } + GNUNET_ECRS_uri_destroy (loc); + loc = NULL; + fi.meta = utc->meta; + fi.uri = utc->uri; + if (utc->shared->doIndex != GNUNET_SYSERR) + { + GNUNET_URITRACK_track (ectx, utc->shared->ctx->cfg, &fi); + GNUNET_URITRACK_add_state (ectx, + utc->shared->ctx->cfg, + utc->uri, + utc->shared->doIndex == + GNUNET_YES ? GNUNET_URITRACK_INDEXED : + GNUNET_URITRACK_INSERTED); + } } - else - { - /* no location URI, use standard URI - (copied here to allow free later) */ - loc = GNUNET_ECRS_uri_duplicate (utc->uri); - } - while (GNUNET_OK == - GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_SPLIT, NULL)); - while (GNUNET_OK == - GNUNET_ECRS_meta_data_delete (utc->meta, EXTRACTOR_LOWERCASE, NULL)); - if (utc->shared->global_keywords != NULL) - GNUNET_ECRS_publish_under_keyword (ectx, - utc->shared->ctx->cfg, - utc->shared->global_keywords, - utc->shared->anonymityLevel, - utc->shared->priority, - utc->shared->expiration, loc, - utc->meta); - if (utc->keywords != NULL) - GNUNET_ECRS_publish_under_keyword (ectx, - utc->shared->ctx->cfg, - utc->keywords, - utc->shared->anonymityLevel, - utc->shared->priority, - utc->shared->expiration, loc, - utc->meta); - if (utc->shared->individualKeywords == GNUNET_YES) - { - uri = GNUNET_ECRS_meta_data_to_uri (utc->meta); - GNUNET_ECRS_publish_under_keyword (ectx, - utc->shared->ctx->cfg, - uri, - utc->shared->anonymityLevel, - utc->shared->priority, - utc->shared->expiration, loc, - utc->meta); - GNUNET_ECRS_uri_destroy (uri); - } - GNUNET_ECRS_uri_destroy (loc); - loc = NULL; - fi.meta = utc->meta; - fi.uri = utc->uri; - GNUNET_URITRACK_track (ectx, utc->shared->ctx->cfg, &fi); - GNUNET_URITRACK_add_state (ectx, - utc->shared->ctx->cfg, - utc->uri, - utc->shared->doIndex == - GNUNET_YES ? GNUNET_URITRACK_INDEXED : - GNUNET_URITRACK_INSERTED); event.type = GNUNET_FSUI_upload_completed; event.data.UploadCompleted.uc.pos = utc; event.data.UploadCompleted.uc.cctx = utc->cctx; Modified: GNUnet/src/applications/fs/tools/gnunet-insert.c =================================================================== --- GNUnet/src/applications/fs/tools/gnunet-insert.c 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/applications/fs/tools/gnunet-insert.c 2008-02-19 02:47:32 UTC (rev 6374) @@ -67,6 +67,8 @@ static unsigned int interval = 0; +static char *uri_string; + static char *next_id; static char *this_id; @@ -85,6 +87,8 @@ static int is_sporadic; +static int do_simulate; + static int extract_only; static int do_disable_creation_time; @@ -319,6 +323,10 @@ gettext_noop ("publish the files under the pseudonym NAME (place file into namespace)"), 1, &GNUNET_getopt_configure_set_string, &pseudonym}, + {'s', "simulate-only", NULL, + gettext_noop ("only simulte the process but do not do any " + "actual publishing (useful to compute URIs)"), + 0, &GNUNET_getopt_configure_set_one, &do_simulate}, {'S', "sporadic", NULL, gettext_noop ("specifies this as an aperiodic but updated publication" " (for namespace insertions only)"), @@ -331,7 +339,11 @@ gettext_noop ("specify creation time for SBlock (see man-page for format)"), 1, &GNUNET_getopt_configure_set_string, &creation_time}, - {'u', "update", "ID", + {'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)"), + 1, &GNUNET_getopt_configure_set_string, &uri_string}, + {'U', "update", "ID", gettext_noop ("ID of the previous version of the content" " (for namespace update only)"), 1, &GNUNET_getopt_configure_set_string, &prev_id}, @@ -365,14 +377,33 @@ errorCode = -1; goto quit; } - if (i != argc - 1) + if ( ( (uri_string == NULL) || + (extract_only) ) && + (i != argc - 1) ) { printf (_ ("You must specify one and only one filename for insertion.\n")); errorCode = -1; goto quit; } - filename = argv[i]; + if ( (uri_string != NULL) && + (i != argc) ) + { + printf (_ + ("You must NOT specify an URI and a filename.\n")); + errorCode = -1; + goto quit; + } + if ( (uri_string != NULL) && + (extract_only) ) + { + printf (_ + ("Cannot extract metadata from a URI!\n")); + errorCode = -1; + goto quit; + } + if (uri_string == NULL) + filename = argv[i]; if (extract_only) { @@ -487,40 +518,72 @@ } } + if (uri_string != NULL) + { + struct GNUNET_ECRS_URI * us + = GNUNET_ECRS_string_to_uri(ectx, uri_string); + if (us == NULL) + { + errorCode = -1; + goto quit; + } + postProcess(us); + if (gloKeywords != NULL) + GNUNET_ECRS_publish_under_keyword(ectx, + cfg, + gloKeywords, + anonymity, + priority, + start_time + 2 * GNUNET_CRON_YEARS, + us, + meta); + if (topKeywords != NULL) + GNUNET_ECRS_publish_under_keyword(ectx, + cfg, + topKeywords, + anonymity, + priority, + start_time + 2 * GNUNET_CRON_YEARS, + us, + meta); + GNUNET_ECRS_uri_destroy(us); + goto quit; + } + /* fundamental init */ ctx = GNUNET_FSUI_start (ectx, cfg, "gnunet-insert", GNUNET_NO, 32, /* make configurable */ &printstatus, &verbose); - /* first insert all of the top-level files or directories */ + /* first insert all of the top-level files or directories */ tmp = GNUNET_expand_file_name (ectx, filename); if (!do_disable_creation_time) GNUNET_ECRS_meta_data_add_publication_date (meta); start_time = GNUNET_get_time (); errorCode = 1; ul = GNUNET_FSUI_upload_start (ctx, - tmp, - (GNUNET_FSUI_DirectoryScanCallback) & - GNUNET_disk_directory_scan, ectx, anonymity, - priority, !do_insert, GNUNET_YES, - !do_no_direct_references, - start_time + 2 * GNUNET_CRON_YEARS, meta, - gloKeywords, topKeywords); - if (gloKeywords != NULL) - GNUNET_ECRS_uri_destroy (gloKeywords); - if (topKeywords != NULL) - GNUNET_ECRS_uri_destroy (topKeywords); + tmp, + (GNUNET_FSUI_DirectoryScanCallback) & + GNUNET_disk_directory_scan, ectx, anonymity, + priority, do_simulate? GNUNET_SYSERR : (!do_insert), GNUNET_YES, + !do_no_direct_references, + start_time + 2 * GNUNET_CRON_YEARS, meta, + gloKeywords, topKeywords); GNUNET_free (tmp); if (ul != NULL) { GNUNET_shutdown_wait_for (); if (errorCode == 1) - GNUNET_FSUI_upload_abort (ctx, ul); + GNUNET_FSUI_upload_abort (ctx, ul); GNUNET_FSUI_upload_stop (ctx, ul); } - GNUNET_ECRS_meta_data_destroy (meta); GNUNET_FSUI_stop (ctx); - quit: + if (meta != NULL) + GNUNET_ECRS_meta_data_destroy (meta); + if (gloKeywords != NULL) + GNUNET_ECRS_uri_destroy (gloKeywords); + if (topKeywords != NULL) + GNUNET_ECRS_uri_destroy (topKeywords); GNUNET_fini (ectx, cfg); return errorCode; } Modified: GNUnet/src/include/gnunet_ecrs_lib.h =================================================================== --- GNUnet/src/include/gnunet_ecrs_lib.h 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/include/gnunet_ecrs_lib.h 2008-02-19 02:47:32 UTC (rev 6374) @@ -166,7 +166,7 @@ /** * Get the first matching MD entry of the given types. - * @param ... -1-terminated list of types + * @paarm ... -1-terminated list of types * @return NULL if we do not have any such entry, * otherwise client is responsible for freeing the value! */ @@ -538,7 +538,8 @@ * @param priority what is the priority for OUR node to * keep this file available? Use 0 for maximum anonymity and * minimum reliability... - * @param doIndex GNUNET_YES for index, GNUNET_NO for insertion + * @param doIndex GNUNET_YES for index, GNUNET_NO for insertion, + * GNUNET_SYSERR for simulation * @param uri set to the URI of the uploaded file * @return GNUNET_SYSERR if the upload failed (i.e. not enough space * or gnunetd not running) Modified: GNUnet/src/include/gnunet_fsui_lib.h =================================================================== --- GNUnet/src/include/gnunet_fsui_lib.h 2008-02-19 02:04:44 UTC (rev 6373) +++ GNUnet/src/include/gnunet_fsui_lib.h 2008-02-19 02:47:32 UTC (rev 6374) @@ -920,7 +920,7 @@ * @param ctx * @param filename name of file or directory to upload (directory * implies use of recursion) - * @param doIndex use indexing, not insertion + * @param doIndex GNUNET_YES: use indexing; GNUNET_NO: use insertion; GNUNET_SYSERR: "simulate" * @param doExtract use libextractor * @param individualKeywords add KBlocks for non-top-level files * @param topLevelMetaData metadata for top-level file or directory _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn