From: Christian Grothoff Date: Sun, 4 Apr 2010 22:04:00 +0000 (+0000) Subject: bugfixes, more tests X-Git-Tag: initial-import-from-subversion-38251~22293 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0663125e0f41ee120736944ef153074f6251b957;p=oweals%2Fgnunet.git bugfixes, more tests --- diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index df781e1e6..53a6a1b41 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -130,7 +130,12 @@ check_PROGRAMS = \ test_fs_uri \ test_gnunet_service_fs_p2p -TESTS = \ +if HAVE_PYTHON_PEXPECT +check_SCRIPTS = \ + test_gnunet_fs.py +endif + +TESTS = $(check_SCRIPTS) \ test_fs_directory \ test_fs_download \ test_fs_file_information \ diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 18b064698..0931b6829 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -707,6 +707,7 @@ hash_for_index_cb (void *cls, struct GNUNET_CLIENT_Connection *client; uint32_t dev; uint64_t ino; + char *fn; p = sc->fi_pos; if (NULL == res) @@ -724,13 +725,15 @@ hash_for_index_cb (void *cls, publish_content (sc); return; } - slen = strlen (p->data.file.filename) + 1; + fn = GNUNET_STRINGS_filename_expand (p->data.file.filename); + slen = strlen (fn) + 1; if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Can not index file `%s': %s. Will try to insert instead.\n"), - p->data.file.filename, + fn, _("filename too long")); + GNUNET_free (fn); p->data.file.do_index = GNUNET_NO; publish_content (sc); return; @@ -752,6 +755,7 @@ hash_for_index_cb (void *cls, _("could not connect to `fs' service")); p->data.file.do_index = GNUNET_NO; publish_content (sc); + GNUNET_free (fn); return; } p->data.file.file_id = *res; @@ -777,8 +781,9 @@ hash_for_index_cb (void *cls, } ism->file_id = *res; memcpy (&ism[1], - p->data.file.filename, + fn, slen); + GNUNET_free (fn); sc->client = client; GNUNET_break (GNUNET_YES == GNUNET_CLIENT_transmit_and_get_response (client, @@ -1465,7 +1470,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, struct GNUNET_FS_Namespace *namespace, const char *identifier, const char *update, - struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, struct GNUNET_TIME_Absolute expirationTime, uint32_t anonymity, @@ -1487,17 +1492,22 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, struct SBlock *sb; struct SBlock *sb_enc; char *dest; + struct GNUNET_CONTAINER_MetaData *mmeta; GNUNET_HashCode key; /* hash of thisId = key */ GNUNET_HashCode id; /* hash of hc = identifier */ GNUNET_HashCode query; /* id ^ nsid = DB query */ + if (NULL == meta) + mmeta = GNUNET_CONTAINER_meta_data_create (); + else + mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); uris = GNUNET_FS_uri_to_string (uri); slen = strlen (uris) + 1; idlen = strlen (identifier); if (update == NULL) update = ""; nidlen = strlen (update) + 1; - mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); + mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta); size = sizeof (struct SBlock) + slen + nidlen + mdsize; if (size > MAX_SBLOCK_SIZE) { @@ -1510,10 +1520,11 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, dest += nidlen; memcpy (dest, uris, slen); dest += slen; - mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, + mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta, &dest, mdsize, GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); + GNUNET_CONTAINER_meta_data_destroy (mmeta); if (mdsize == -1) { GNUNET_break (0); diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index c4994b6a6..ce4af43fc 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -24,7 +24,9 @@ * @author Christian Grothoff * * TODO: - * - handle namespace advertisements (can wait; might already work!?) + * - handle namespace advertisements (NBlocks, see FIXME; + * note that we currently use KBLOCK instead of ANY when + * searching => NBLOCKS would not fit! FIX this as well!) * - add support for pushing "already seen" information * to FS service for bloomfilter (can wait) * - handle availability probes (can wait) @@ -382,8 +384,11 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, return; } j = eos - pt + 1; - meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], - sizeof (pt) - j); + if (sizeof (pt) == j) + meta = GNUNET_CONTAINER_meta_data_create (); + else + meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], + sizeof (pt) - j); if (meta == NULL) { GNUNET_break_op (0); /* kblock malformed */ @@ -529,6 +534,9 @@ process_result (struct GNUNET_FS_SearchContext *sc, } process_sblock (sc, data, size); break; + case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: + GNUNET_break (0); // FIXME: not implemented! + break; case GNUNET_DATASTORE_BLOCKTYPE_ANY: case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: case GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND: diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c index b0b53c925..e7b2bb8dd 100644 --- a/src/fs/gnunet-pseudonym.c +++ b/src/fs/gnunet-pseudonym.c @@ -343,12 +343,12 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { ("add an additional keyword for the advertisment" " (this option can be specified multiple times)"), 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri}, - {'l', "local-only", NULL, - gettext_noop ("print names of local namespaces"), - 0, &GNUNET_GETOPT_set_one, &print_local_only}, {'m', "meta", "TYPE:VALUE", gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, + {'o', "only-local", NULL, + gettext_noop ("print names of local namespaces"), + 0, &GNUNET_GETOPT_set_one, &print_local_only}, {'p', "priority", "PRIORITY", gettext_noop ("use the given PRIORITY for the advertisments"), 1, &GNUNET_GETOPT_set_uint, &priority}, diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index bcfc8967b..767e84af2 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -46,6 +46,8 @@ static struct GNUNET_CONTAINER_MetaData *meta; static struct GNUNET_FS_Uri *topKeywords; +static struct GNUNET_FS_Uri *uri; + static unsigned int anonymity = 1; static unsigned int priority = 365; @@ -327,11 +329,32 @@ publish_inspector (void *cls, } +static void +uri_sks_continuation (void *cls, + const struct GNUNET_FS_Uri *ksk_uri, + const char *emsg) +{ + if (emsg != NULL) + { + fprintf (stderr, + "%s\n", + emsg); + ret = 1; + } + GNUNET_FS_uri_destroy (uri); + uri = NULL; + GNUNET_FS_stop (ctx); + ctx = NULL; +} + + static void uri_ksk_continuation (void *cls, - const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) { + struct GNUNET_FS_Namespace *ns; + if (emsg != NULL) { fprintf (stderr, @@ -339,7 +362,40 @@ uri_ksk_continuation (void *cls, emsg); ret = 1; } + if (pseudonym != NULL) + { + ns = GNUNET_FS_namespace_create (ctx, + pseudonym); + if (ns == NULL) + { + fprintf (stderr, + _("Failed to create namespace `%s'\n"), + pseudonym); + ret = 1; + } + else + { + GNUNET_FS_publish_sks (ctx, + ns, + this_id, + next_id, + meta, + uri, + GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION), + anonymity, + priority, + GNUNET_FS_PUBLISH_OPTION_NONE, + uri_sks_continuation, + NULL); + GNUNET_assert (GNUNET_OK == + GNUNET_FS_namespace_delete (ns, GNUNET_NO)); + return; + } + } + GNUNET_FS_uri_destroy (uri); + uri = NULL; GNUNET_FS_stop (ctx); + ctx = NULL; } @@ -365,7 +421,6 @@ run (void *cls, struct stat sbuf; char *ex; char *emsg; - struct GNUNET_FS_Uri *uri; sched = s; /* check arguments */ @@ -419,7 +474,8 @@ run (void *cls, return; } } - if (args[0] == NULL) + if ( (args[0] == NULL) && + (uri_string == NULL) ) { fprintf (stderr, _("Need the name of a file to publish!\n")); diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index ed0c7b3b7..22e826536 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -2852,7 +2852,7 @@ handle_start_search (void *cls, type, &process_local_reply, pr, - GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_CONSTANTS_SERVICE_TIMEOUT, GNUNET_YES); } diff --git a/src/fs/gnunet-service-fs_drq.c b/src/fs/gnunet-service-fs_drq.c index dc9560be6..b83a12547 100644 --- a/src/fs/gnunet-service-fs_drq.c +++ b/src/fs/gnunet-service-fs_drq.c @@ -26,6 +26,7 @@ #include "platform.h" #include "gnunet-service-fs_drq.h" +#define DEBUG_DRQ GNUNET_NO /** * Signature of a function that is called whenever a datastore @@ -165,17 +166,32 @@ get_iterator (void *cls, if (gc->iter == NULL) { /* stop the iteration */ +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Iteration terminated\n"); +#endif if (key != NULL) GNUNET_DATASTORE_get_next (dsh, GNUNET_NO); } else { +#if DEBUG_DRQ + if (key != NULL) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Iteration produced %u-byte result for `%s'\n", + size, + GNUNET_h2s (key)); +#endif gc->iter (gc->iter_cls, key, size, data, type, priority, anonymity, expiration, uid); } if (key == NULL) { +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Iteration completed\n"); +#endif GNUNET_assert (gc == drq_running); GNUNET_free (gc); drq_running = NULL; @@ -197,6 +213,12 @@ run_next_request (void *cls, struct DatastoreRequestQueue *gc = cls; gc->task = GNUNET_SCHEDULER_NO_TASK; +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Running datastore request for `%s' of type %u\n", + GNUNET_h2s (&gc->key), + gc->type); +#endif GNUNET_DATASTORE_get (dsh, &gc->key, gc->type, &get_iterator, gc, @@ -239,6 +261,10 @@ timeout_ds_request (void *cls, { struct DatastoreRequestQueue *e = cls; +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Datastore request timed out in queue before transmission\n"); +#endif e->task = GNUNET_SCHEDULER_NO_TASK; GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e); if (e->iter != NULL) @@ -261,6 +287,10 @@ shutdown_task (void *cls, { struct DatastoreRequestQueue *drq; +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DRQ shutdown initiated\n"); +#endif GNUNET_assert (NULL != dsh); GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO); @@ -306,6 +336,12 @@ GNUNET_FS_drq_get (const GNUNET_HashCode * key, struct DatastoreRequestQueue *e; struct DatastoreRequestQueue *bef; +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DRQ receives request for `%s' of type %u\n", + GNUNET_h2s (key), + type); +#endif e = GNUNET_malloc (sizeof (struct DatastoreRequestQueue)); e->timeout = GNUNET_TIME_relative_to_absolute (timeout); e->forced_head = immediate; @@ -348,6 +384,10 @@ GNUNET_FS_drq_get (const GNUNET_HashCode * key, void GNUNET_FS_drq_get_cancel (struct DatastoreRequestQueue *drq) { +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DRQ receives request cancellation request\n"); +#endif if (drq == drq_running) { /* 'DATASTORE_get' has already been started (and this call might @@ -376,10 +416,41 @@ GNUNET_FS_drq_get_cancel (struct DatastoreRequestQueue *drq) void GNUNET_FS_drq_get_next (int more) { +#if DEBUG_DRQ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DRQ receives request for next result (more is %d)\n", + more); +#endif GNUNET_DATASTORE_get_next (dsh, more); } +/** + * Closure for 'drq_remove_cont'. + */ +struct RemoveContext +{ + struct GNUNET_DATASTORE_Handle *rmdsh; + GNUNET_DATASTORE_ContinuationWithStatus cont; + void *cont_cls; +}; + + +static void +drq_remove_cont (void *cls, + int success, + const char *msg) +{ + struct RemoveContext *rc = cls; + + rc->cont (rc->cont_cls, + success, + msg); + GNUNET_DATASTORE_disconnect (rc->rmdsh, GNUNET_NO); + GNUNET_free (rc); +} + + /** * Explicitly remove some content from the database. * The "cont"inuation will be called with status @@ -401,13 +472,26 @@ GNUNET_FS_drq_remove (const GNUNET_HashCode *key, void *cont_cls, struct GNUNET_TIME_Relative timeout) { - if (dsh == NULL) + struct GNUNET_DATASTORE_Handle *rmdsh; + struct RemoveContext *rc; + + rmdsh = GNUNET_DATASTORE_connect (cfg, + sched); + if (rmdsh == NULL) { GNUNET_break (0); + cont (cont_cls, + GNUNET_SYSERR, + _("Failed to connect to datastore")); return; } - GNUNET_DATASTORE_remove (dsh, key, size, data, - cont, cont_cls, timeout); + rc = GNUNET_malloc (sizeof (struct RemoveContext)); + rc->cont = cont; + rc->cont_cls = cont_cls; + rc->rmdsh = rmdsh; + GNUNET_DATASTORE_remove (rmdsh, key, size, data, + &drq_remove_cont, + rc, timeout); } diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 525da1a91..5bae211ba 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -322,7 +322,7 @@ GNUNET_FS_handle_index_start (void *cls, const struct GNUNET_MessageHeader *message) { const struct IndexStartMessage *ism; - const char *fn; + char *fn; uint16_t msize; struct IndexInfo *ii; size_t slen; @@ -341,7 +341,7 @@ GNUNET_FS_handle_index_start (void *cls, return; } ism = (const struct IndexStartMessage*) message; - fn = (const char*) &ism[1]; + fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]); dev = ntohl (ism->device); ino = GNUNET_ntohll (ism->inode); ism = (const struct IndexStartMessage*) message; @@ -363,6 +363,7 @@ GNUNET_FS_handle_index_start (void *cls, { /* fast validation OK! */ signal_index_ok (ii); + GNUNET_free (fn); return; } #if DEBUG_FS @@ -380,6 +381,7 @@ GNUNET_FS_handle_index_start (void *cls, HASHING_BLOCKSIZE, &hash_for_index_val, ii); + GNUNET_free (fn); } diff --git a/src/fs/test_gnunet_fs.py b/src/fs/test_gnunet_fs.py new file mode 100755 index 000000000..9e3fc8daa --- /dev/null +++ b/src/fs/test_gnunet_fs.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +import pexpect +import os +import signal +import re + +os.system ('gnunet-arm -s') +try: +# first, basic publish-search-download run + pub = pexpect.spawn ('gnunet-publish -k gpl ../../COPYING') + pub.expect ('Publishing `../../COPYING\' done.\r') + pub.expect ("URI is `gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147'.\r") + pub.expect (pexpect.EOF) + + search = pexpect.spawn ('gnunet-search gpl') + search.expect ("gnunet-download -o \"COPYING\" gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147\r") + search.kill (signal.SIGTERM) + search.expect (pexpect.EOF) +# FIXME: check for meta-data (also need to add meta data in publish call!) + + down = pexpect.spawn ('gnunet-download -o \"COPYING\" gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147') + down.expect (re.compile ("Downloading `COPYING\' done \(.*\).\r")); + down.expect (pexpect.EOF); + os.system ('rm COPYING'); + +# second, same with namespace creation + pseu = pexpect.spawn ('gnunet-pseudonym -C licenses -k gpl -k test -m "description:Free Software Licenses"') + pseu.expect (pexpect.EOF) + pseu = pexpect.spawn ('gnunet-pseudonym -o') + pseu.expect (re.compile("licenses \(.*\)\r")) + pseu.expect (pexpect.EOF) + + pub = pexpect.spawn ('gnunet-publish -k licenses -P licenses -u gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147 -t gpl -N gpl3') + pub.expect (pexpect.EOF) + +# search = pexpect.spawn ('gnunet-search licenses') +# FIXME: check that namespace was found +# FIXME: check for meta-data! + +finally: + os.system ('gnunet-arm -e')