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 \
struct GNUNET_CLIENT_Connection *client;
uint32_t dev;
uint64_t ino;
+ char *fn;
p = sc->fi_pos;
if (NULL == res)
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;
_("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;
}
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,
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,
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)
{
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);
* @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)
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 */
}
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:
("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},
static struct GNUNET_FS_Uri *topKeywords;
+static struct GNUNET_FS_Uri *uri;
+
static unsigned int anonymity = 1;
static unsigned int priority = 365;
}
+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,
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;
}
struct stat sbuf;
char *ex;
char *emsg;
- struct GNUNET_FS_Uri *uri;
sched = s;
/* check arguments */
return;
}
}
- if (args[0] == NULL)
+ if ( (args[0] == NULL) &&
+ (uri_string == NULL) )
{
fprintf (stderr,
_("Need the name of a file to publish!\n"));
type,
&process_local_reply,
pr,
- GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
GNUNET_YES);
}
#include "platform.h"
#include "gnunet-service-fs_drq.h"
+#define DEBUG_DRQ GNUNET_NO
/**
* Signature of a function that is called whenever a datastore
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;
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,
{
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)
{
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);
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;
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
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
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);
}
const struct GNUNET_MessageHeader *message)
{
const struct IndexStartMessage *ism;
- const char *fn;
+ char *fn;
uint16_t msize;
struct IndexInfo *ii;
size_t slen;
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;
{
/* fast validation OK! */
signal_index_ok (ii);
+ GNUNET_free (fn);
return;
}
#if DEBUG_FS
HASHING_BLOCKSIZE,
&hash_for_index_val,
ii);
+ GNUNET_free (fn);
}
--- /dev/null
+#!/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')