aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.h1
-rw-r--r--src/fs/fs_publish.c139
-rw-r--r--src/fs/fs_search.c43
-rw-r--r--src/fs/gnunet-service-fs.c25
-rw-r--r--src/fs/test_fs_namespace.c239
-rw-r--r--src/fs/test_fs_namespace_data.conf5
6 files changed, 258 insertions, 194 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 0d4ed268a..b7fab55f0 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -1306,7 +1306,6 @@ struct SearchMessage
1306 1306
1307 /** 1307 /**
1308 * Type of the content that we're looking for. 1308 * Type of the content that we're looking for.
1309 * 0 for any.
1310 */ 1309 */
1311 uint32_t type GNUNET_PACKED; 1310 uint32_t type GNUNET_PACKED;
1312 1311
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 50c6bdd7b..f6e66e456 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -40,7 +40,7 @@
40#include "fs.h" 40#include "fs.h"
41#include "fs_tree.h" 41#include "fs_tree.h"
42 42
43#define DEBUG_PUBLISH GNUNET_NO 43#define DEBUG_PUBLISH GNUNET_YES
44 44
45/** 45/**
46 * Main function that performs the upload. 46 * Main function that performs the upload.
@@ -1487,8 +1487,9 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1487 struct SBlock *sb; 1487 struct SBlock *sb;
1488 struct SBlock *sb_enc; 1488 struct SBlock *sb_enc;
1489 char *dest; 1489 char *dest;
1490 GNUNET_HashCode key; /* hash of thisId = key */ 1490 GNUNET_HashCode key; /* hash of thisId = key */
1491 GNUNET_HashCode id; /* hash of hc = identifier */ 1491 GNUNET_HashCode id; /* hash of hc = identifier */
1492 GNUNET_HashCode query; /* id ^ nsid = DB query */
1492 1493
1493 uris = GNUNET_FS_uri_to_string (uri); 1494 uris = GNUNET_FS_uri_to_string (uri);
1494 slen = strlen (uris) + 1; 1495 slen = strlen (uris) + 1;
@@ -1575,10 +1576,12 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1575 _("Failed to connect to datastore.")); 1576 _("Failed to connect to datastore."));
1576 return; 1577 return;
1577 } 1578 }
1578 1579 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
1580 &id,
1581 &query);
1579 GNUNET_DATASTORE_put (psc->dsh, 1582 GNUNET_DATASTORE_put (psc->dsh,
1580 0, 1583 0,
1581 &sb->identifier, 1584 &sb_enc->identifier,
1582 size, 1585 size,
1583 sb_enc, 1586 sb_enc,
1584 GNUNET_DATASTORE_BLOCKTYPE_SBLOCK, 1587 GNUNET_DATASTORE_BLOCKTYPE_SBLOCK,
@@ -1588,133 +1591,9 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1588 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1591 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1589 &sb_put_cont, 1592 &sb_put_cont,
1590 psc); 1593 psc);
1594
1591 GNUNET_free (sb); 1595 GNUNET_free (sb);
1592 GNUNET_free (sb_enc); 1596 GNUNET_free (sb_enc);
1593} 1597}
1594 1598
1595
1596#if 0
1597
1598/**
1599 * Add an entry into a namespace.
1600 *
1601 * @param dstU to which URI should the namespace entry refer?
1602 * @param md what meta-data should be associated with the
1603 * entry?
1604 * @param thisId name of this entry in the namespace (keyword/identifier)
1605 * @param nextId name of the update for this entry (to be published in
1606 * the future; maybe NULL)
1607 * @param pid unique identifier of the namespace/pseudonym
1608 * @return URI on success, NULL on error
1609 */
1610struct GNUNET_ECRS_URI *
1611GNUNET_ECRS_namespace_add_content (struct GNUNET_GE_Context *ectx,
1612 struct GNUNET_GC_Configuration *cfg,
1613 const GNUNET_HashCode * pid,
1614 uint32_t anonymityLevel,
1615 uint32_t priority,
1616 GNUNET_CronTime expiration,
1617 const char *thisId,
1618 const char *nextId,
1619 const struct GNUNET_ECRS_URI *dstU,
1620 const struct GNUNET_MetaData *md)
1621{
1622 struct GNUNET_ECRS_URI *uri;
1623 struct GNUNET_ClientServerConnection *sock;
1624 GNUNET_DatastoreValue *value;
1625 unsigned int size;
1626 unsigned int mdsize;
1627 struct GNUNET_RSA_PrivateKey *hk;
1628 GNUNET_EC_SBlock *sb;
1629 char *dstURI;
1630 char *destPos;
1631 GNUNET_HashCode hc; /* hash of thisId = key */
1632 GNUNET_HashCode hc2; /* hash of hc = identifier */
1633 int ret;
1634 unsigned int nidlen;
1635
1636 hk = read_namespace_key (cfg, pid);
1637 if (hk == NULL)
1638 return NULL;
1639
1640 /* THEN: construct GNUNET_EC_SBlock */
1641 dstURI = GNUNET_ECRS_uri_to_string (dstU);
1642 mdsize = GNUNET_meta_data_get_serialized_size (md, GNUNET_SERIALIZE_PART);
1643 if (nextId == NULL)
1644 nextId = "";
1645 nidlen = strlen (nextId) + 1;
1646 size = mdsize + sizeof (GNUNET_EC_SBlock) + strlen (dstURI) + 1 + nidlen;
1647 if (size > MAX_SBLOCK_SIZE)
1648 {
1649 size = MAX_SBLOCK_SIZE;
1650 mdsize =
1651 size - (sizeof (GNUNET_EC_SBlock) + strlen (dstURI) + 1 + nidlen);
1652 }
1653 value = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + size);
1654 sb = (GNUNET_EC_SBlock *) & value[1];
1655 sb->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED);
1656 destPos = (char *) &sb[1];
1657 memcpy (destPos, nextId, nidlen);
1658 destPos += nidlen;
1659 memcpy (destPos, dstURI, strlen (dstURI) + 1);
1660 destPos += strlen (dstURI) + 1;
1661 mdsize = GNUNET_meta_data_serialize (ectx,
1662 md,
1663 destPos,
1664 mdsize, GNUNET_SERIALIZE_PART);
1665 if (mdsize == -1)
1666 {
1667 GNUNET_GE_BREAK (ectx, 0);
1668 GNUNET_free (dstURI);
1669 GNUNET_RSA_free_key (hk);
1670 GNUNET_free (value);
1671 return NULL;
1672 }
1673 size = sizeof (GNUNET_EC_SBlock) + mdsize + strlen (dstURI) + 1 + nidlen;
1674 value->size = htonl (sizeof (GNUNET_DatastoreValue) + size);
1675 value->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED);
1676 value->priority = htonl (priority);
1677 value->anonymity_level = htonl (anonymityLevel);
1678 value->expiration_time = GNUNET_htonll (expiration);
1679 GNUNET_hash (thisId, strlen (thisId), &hc);
1680 GNUNET_hash (&hc, sizeof (GNUNET_HashCode), &hc2);
1681 uri = GNUNET_malloc (sizeof (URI));
1682 uri->type = sks;
1683 GNUNET_RSA_get_public_key (hk, &sb->subspace);
1684 GNUNET_hash (&sb->subspace,
1685 sizeof (GNUNET_RSA_PublicKey), &uri->data.sks.namespace);
1686 GNUNET_GE_BREAK (ectx, 0 == memcmp (&uri->data.sks.namespace,
1687 pid, sizeof (GNUNET_HashCode)));
1688 uri->data.sks.identifier = GNUNET_strdup (thisId);
1689 GNUNET_hash_xor (&hc2, &uri->data.sks.namespace, &sb->identifier);
1690 GNUNET_ECRS_encryptInPlace (&hc, &sb[1], size - sizeof (GNUNET_EC_SBlock));
1691 GNUNET_GE_ASSERT (ectx,
1692 GNUNET_OK == GNUNET_RSA_sign (hk,
1693 size
1694 -
1695 sizeof
1696 (GNUNET_RSA_Signature) -
1697 sizeof
1698 (GNUNET_RSA_PublicKey) -
1699 sizeof (unsigned int),
1700 &sb->identifier,
1701 &sb->signature));
1702 GNUNET_RSA_free_key (hk);
1703 sock = GNUNET_client_connection_create (ectx, cfg);
1704 ret = GNUNET_FS_insert (sock, value);
1705 if (ret != GNUNET_OK)
1706 {
1707 GNUNET_free (uri);
1708 uri = NULL;
1709 }
1710 GNUNET_client_connection_destroy (sock);
1711 GNUNET_free (value);
1712 GNUNET_free (dstURI);
1713
1714 return uri;
1715}
1716
1717#endif
1718
1719
1720/* end of fs_publish.c */ 1599/* end of fs_publish.c */
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index a03e9becb..746a2f19d 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -38,7 +38,7 @@
38#include "gnunet_protocols.h" 38#include "gnunet_protocols.h"
39#include "fs.h" 39#include "fs.h"
40 40
41#define DEBUG_SEARCH GNUNET_NO 41#define DEBUG_SEARCH GNUNET_YES
42 42
43 43
44 44
@@ -161,8 +161,8 @@ struct GetResultContext
161 161
162 162
163/** 163/**
164 * Check if the given result is identical 164 * Check if the given result is identical to the given URI and if so
165 * to the given URI and if so return it. 165 * return it.
166 * 166 *
167 * @param cls a "struct GetResultContext" 167 * @param cls a "struct GetResultContext"
168 * @param key not used 168 * @param key not used
@@ -186,9 +186,8 @@ get_result_present (void *cls,
186 186
187 187
188/** 188/**
189 * We have received a KSK result. Check 189 * We have received a KSK result. Check how it fits in with the
190 * how it fits in with the overall query 190 * overall query and notify the client accordingly.
191 * and notify the client accordingly.
192 * 191 *
193 * @param sc context for the overall query 192 * @param sc context for the overall query
194 * @param ent entry for the specific keyword 193 * @param ent entry for the specific keyword
@@ -208,14 +207,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
208 int is_new; 207 int is_new;
209 208
210 /* check if new */ 209 /* check if new */
211 if (! GNUNET_FS_uri_test_chk (uri)) 210 GNUNET_FS_uri_to_key (uri, &key);
212 {
213 GNUNET_break_op (0);
214 return;
215 }
216 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
217 &uri->data.chk.chk.query,
218 &key);
219 if (GNUNET_SYSERR == 211 if (GNUNET_SYSERR ==
220 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, 212 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
221 &key, 213 &key,
@@ -281,9 +273,8 @@ search_start (struct GNUNET_FS_Handle *h,
281 273
282 274
283/** 275/**
284 * We have received an SKS result. Start 276 * We have received an SKS result. Start searching for updates and
285 * searching for updates and notify the 277 * notify the client if it is a new result.
286 * client if it is a new result.
287 * 278 *
288 * @param sc context for the overall query 279 * @param sc context for the overall query
289 * @param id_update identifier for updates, NULL for none 280 * @param id_update identifier for updates, NULL for none
@@ -301,11 +292,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
301 struct SearchResult *sr; 292 struct SearchResult *sr;
302 293
303 /* check if new */ 294 /* check if new */
304 if (! GNUNET_FS_uri_test_ksk (uri)) 295 GNUNET_FS_uri_to_key (uri, &key);
305 {
306 GNUNET_break_op (0);
307 return;
308 }
309 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, 296 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
310 &uri->data.chk.chk.query, 297 &uri->data.chk.chk.query,
311 &key); 298 &key);
@@ -618,6 +605,7 @@ transmit_search_request (void *cls,
618 struct SearchMessage *sm; 605 struct SearchMessage *sm;
619 unsigned int i; 606 unsigned int i;
620 const char *identifier; 607 const char *identifier;
608 GNUNET_HashCode key;
621 GNUNET_HashCode idh; 609 GNUNET_HashCode idh;
622 610
623 if (NULL == buf) 611 if (NULL == buf)
@@ -635,28 +623,34 @@ transmit_search_request (void *cls,
635 { 623 {
636 sm[i].header.size = htons (sizeof (struct SearchMessage)); 624 sm[i].header.size = htons (sizeof (struct SearchMessage));
637 sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); 625 sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
638 sm[i].anonymity_level = htonl (sc->anonymity); 626 sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_KBLOCK);
627 sm[i].anonymity_level = htonl (sc->anonymity);
639 sm[i].query = sc->requests[i].query; 628 sm[i].query = sc->requests[i].query;
640 } 629 }
641 } 630 }
642 else 631 else
643 { 632 {
633 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
644 msize = sizeof (struct SearchMessage); 634 msize = sizeof (struct SearchMessage);
645 GNUNET_assert (size >= msize); 635 GNUNET_assert (size >= msize);
646 sm = buf; 636 sm = buf;
647 memset (sm, 0, msize); 637 memset (sm, 0, msize);
648 sm->header.size = htons (sizeof (struct SearchMessage)); 638 sm->header.size = htons (sizeof (struct SearchMessage));
649 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); 639 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
640 sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_SBLOCK);
650 sm->anonymity_level = htonl (sc->anonymity); 641 sm->anonymity_level = htonl (sc->anonymity);
651 sm->target = sc->uri->data.sks.namespace; 642 sm->target = sc->uri->data.sks.namespace;
652 identifier = sc->uri->data.sks.identifier; 643 identifier = sc->uri->data.sks.identifier;
653 GNUNET_CRYPTO_hash (identifier, 644 GNUNET_CRYPTO_hash (identifier,
654 strlen (identifier), 645 strlen (identifier),
646 &key);
647 GNUNET_CRYPTO_hash (&key,
648 sizeof (GNUNET_HashCode),
655 &idh); 649 &idh);
656 GNUNET_CRYPTO_hash_xor (&idh, 650 GNUNET_CRYPTO_hash_xor (&idh,
657 &sm->target, 651 &sm->target,
658 &sm->query); 652 &sm->query);
659 } 653 }
660 GNUNET_CLIENT_receive (sc->client, 654 GNUNET_CLIENT_receive (sc->client,
661 &receive_results, 655 &receive_results,
662 sc, 656 sc,
@@ -785,6 +779,7 @@ search_start (struct GNUNET_FS_Handle *h,
785 sc->client_info = cctx; 779 sc->client_info = cctx;
786 if (GNUNET_FS_uri_test_ksk (uri)) 780 if (GNUNET_FS_uri_test_ksk (uri))
787 { 781 {
782 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
788 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) * 783 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
789 sc->uri->data.ksk.keywordCount); 784 sc->uri->data.ksk.keywordCount);
790 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 785 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index b8c9d91fa..e230a5e77 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -1657,7 +1657,7 @@ check_sblock (const struct SBlock *sb,
1657 return GNUNET_SYSERR; 1657 return GNUNET_SYSERR;
1658 } 1658 }
1659 if (dsize != 1659 if (dsize !=
1660 ntohs (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature)) 1660 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
1661 { 1661 {
1662 GNUNET_break_op (0); 1662 GNUNET_break_op (0);
1663 return GNUNET_SYSERR; 1663 return GNUNET_SYSERR;
@@ -1836,6 +1836,11 @@ process_reply (void *cls,
1836 do_remove = GNUNET_YES; 1836 do_remove = GNUNET_YES;
1837 break; 1837 break;
1838 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK: 1838 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
1839 if (pr->namespace == NULL)
1840 {
1841 GNUNET_break (0);
1842 return GNUNET_YES;
1843 }
1839 if (0 != memcmp (pr->namespace, 1844 if (0 != memcmp (pr->namespace,
1840 &prq->namespace, 1845 &prq->namespace,
1841 sizeof (GNUNET_HashCode))) 1846 sizeof (GNUNET_HashCode)))
@@ -2484,10 +2489,11 @@ handle_p2p_get (void *cls,
2484 2489
2485#if DEBUG_FS 2490#if DEBUG_FS
2486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2487 "Received request for `%s' of type %u from peer `%4s'\n", 2492 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
2488 GNUNET_h2s (&gm->query), 2493 GNUNET_h2s (&gm->query),
2489 (unsigned int) type, 2494 (unsigned int) type,
2490 GNUNET_i2s (other)); 2495 GNUNET_i2s (other),
2496 (unsigned int) bm);
2491#endif 2497#endif
2492 have_ns = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)); 2498 have_ns = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE));
2493 pr = GNUNET_malloc (sizeof (struct PendingRequest) + 2499 pr = GNUNET_malloc (sizeof (struct PendingRequest) +
@@ -2685,9 +2691,14 @@ handle_start_search (void *cls,
2685 client_list = cl; 2691 client_list = cl;
2686 } 2692 }
2687 type = ntohl (sm->type); 2693 type = ntohl (sm->type);
2694#if DEBUG_FS
2695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2696 "Received request for `%s' of type %u from local client\n",
2697 GNUNET_h2s (&sm->query),
2698 (unsigned int) type);
2699#endif
2688 switch (type) 2700 switch (type)
2689 { 2701 {
2690 case GNUNET_DATASTORE_BLOCKTYPE_ANY:
2691 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: 2702 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
2692 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK: 2703 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
2693 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK: 2704 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
@@ -2699,12 +2710,6 @@ handle_start_search (void *cls,
2699 GNUNET_SYSERR); 2710 GNUNET_SYSERR);
2700 return; 2711 return;
2701 } 2712 }
2702#if DEBUG_FS
2703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2704 "Received request for `%s' of type %u from local client\n",
2705 GNUNET_h2s (&sm->query),
2706 (unsigned int) type);
2707#endif
2708 2713
2709 /* detect duplicate KBLOCK requests */ 2714 /* detect duplicate KBLOCK requests */
2710 if (type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) 2715 if (type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK)
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
index ea9e00c90..6014e4394 100644
--- a/src/fs/test_fs_namespace.c
+++ b/src/fs/test_fs_namespace.c
@@ -22,21 +22,38 @@
22 * @file fs/test_fs_namespace.c 22 * @file fs/test_fs_namespace.c
23 * @brief Test for fs_namespace.c 23 * @brief Test for fs_namespace.c
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 *
26 * TODO:
27 * - add timeout task
25 */ 28 */
26
27#include "platform.h" 29#include "platform.h"
28#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
29#include "gnunet_arm_service.h" 31#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
31 33
34#define VERBOSE GNUNET_YES
35
32#define START_ARM GNUNET_YES 36#define START_ARM GNUNET_YES
33 37
34static struct GNUNET_SCHEDULER_Handle *sched; 38static struct GNUNET_SCHEDULER_Handle *sched;
35 39
36static struct PeerContext p1; 40static struct PeerContext p1;
37 41
42static GNUNET_HashCode nsid;
43
44static struct GNUNET_FS_Uri *sks_expect_uri;
45
46static struct GNUNET_FS_Uri *ksk_expect_uri;
47
38static struct GNUNET_FS_Handle *fs; 48static struct GNUNET_FS_Handle *fs;
39 49
50static struct GNUNET_FS_SearchContext *sks_search;
51
52static struct GNUNET_FS_SearchContext *ksk_search;
53
54static int update_started;
55
56static int err;
40 57
41struct PeerContext 58struct PeerContext
42{ 59{
@@ -79,21 +96,131 @@ stop_arm (struct PeerContext *p)
79} 96}
80 97
81 98
82#if 0
83static void 99static void
84spcb (void *cls, 100abort_ksk_search_task (void *cls,
85 const char *name, 101 const struct GNUNET_SCHEDULER_TaskContext *tc)
86 const GNUNET_HashCode * key)
87{ 102{
103 if (ksk_search != NULL)
104 {
105 GNUNET_FS_search_stop (ksk_search);
106 ksk_search = NULL;
107 if (sks_search == NULL)
108 GNUNET_FS_stop (fs);
109 }
88} 110}
89#endif
90 111
91 112
113static void
114abort_sks_search_task (void *cls,
115 const struct GNUNET_SCHEDULER_TaskContext *tc)
116{
117 struct GNUNET_FS_Namespace *ns;
118
119 if (sks_search != NULL)
120 {
121 GNUNET_FS_search_stop (sks_search);
122 sks_search = NULL;
123 ns = GNUNET_FS_namespace_create (fs,
124 "testNamespace");
125 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES));
126 if (ksk_search == NULL)
127 GNUNET_FS_stop (fs);
128 }
129}
130
92 131
93static void * 132static void *
94progress_cb (void *cls, 133progress_cb (void *cls,
95 const struct GNUNET_FS_ProgressInfo *event) 134 const struct GNUNET_FS_ProgressInfo *event)
96{ 135{
136 switch (event->status)
137 {
138 case GNUNET_FS_STATUS_SEARCH_RESULT:
139 if (sks_search == event->value.search.sc)
140 {
141 fprintf (stderr,
142 "Search result for sks received\n");
143 if (! GNUNET_FS_uri_test_equal (sks_expect_uri,
144 event->value.search.specifics.result.uri))
145 {
146 fprintf (stderr,
147 "Wrong result for sks search!\n");
148 err = 1;
149 }
150 /* give system 1ms to initiate update search! */
151 GNUNET_SCHEDULER_add_delayed (sched,
152 GNUNET_TIME_UNIT_MILLISECONDS,
153 &abort_sks_search_task,
154 NULL);
155 }
156 else if (ksk_search == event->value.search.sc)
157 {
158 fprintf (stderr,
159 "Search result for ksk received\n");
160 if (! GNUNET_FS_uri_test_equal (ksk_expect_uri,
161 event->value.search.specifics.result.uri))
162 {
163 fprintf (stderr,
164 "Wrong result for ksk search!\n");
165 err = 1;
166 }
167 GNUNET_SCHEDULER_add_continuation (sched,
168 &abort_ksk_search_task,
169 NULL,
170 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
171 }
172 else
173 {
174 fprintf (stderr,
175 "Search result received!?\n");
176 GNUNET_break (0);
177 }
178 break;
179 case GNUNET_FS_STATUS_SEARCH_ERROR:
180 fprintf (stderr,
181 "Error searching file: %s\n",
182 event->value.search.specifics.error.message);
183 if (sks_search == event->value.search.sc)
184 GNUNET_SCHEDULER_add_continuation (sched,
185 &abort_sks_search_task,
186 NULL,
187 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
188 else if (ksk_search == event->value.search.sc)
189 GNUNET_SCHEDULER_add_continuation (sched,
190 &abort_ksk_search_task,
191 NULL,
192 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
193 else
194 GNUNET_break (0);
195 break;
196 case GNUNET_FS_STATUS_SEARCH_START:
197 fprintf (stderr,
198 "Search start event for `%s' received\n",
199 (const char*) event->value.search.cctx);
200 GNUNET_assert ( (NULL == event->value.search.cctx) ||
201 (0 == strcmp ("sks_search", event->value.search.cctx)) ||
202 (0 == strcmp ("ksk_search", event->value.search.cctx)));
203 if (NULL == event->value.search.cctx)
204 {
205 GNUNET_assert (sks_search == event->value.search.pctx);
206 update_started = GNUNET_YES;
207 }
208 GNUNET_assert (1 == event->value.search.anonymity);
209 break;
210 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
211 break;
212 case GNUNET_FS_STATUS_SEARCH_STOPPED:
213 fprintf (stderr,
214 "Search stop event received\n");
215 GNUNET_assert ( (ksk_search == event->value.search.sc) ||
216 (sks_search == event->value.search.sc));
217 break;
218 default:
219 fprintf (stderr,
220 "Unexpected event: %d\n",
221 event->status);
222 break;
223 }
97 return NULL; 224 return NULL;
98} 225}
99 226
@@ -103,11 +230,39 @@ publish_cont (void *cls,
103 const struct GNUNET_FS_Uri *ksk_uri, 230 const struct GNUNET_FS_Uri *ksk_uri,
104 const char *emsg) 231 const char *emsg)
105{ 232{
106 struct GNUNET_FS_SearchContext *search; 233 char *msg;
107 234 struct GNUNET_FS_Uri *sks_uri;
108 GNUNET_assert (NULL == emsg); 235 char sbuf[1024];
236 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
237
238 if (NULL != emsg)
239 {
240 fprintf (stderr, "Error publishing: %s\n", emsg);
241 err = 1;
242 GNUNET_FS_stop (fs);
243 return;
244 }
245 GNUNET_CRYPTO_hash_to_enc (&nsid,
246 &enc);
247 GNUNET_snprintf (sbuf,
248 sizeof (sbuf),
249 "gnunet://fs/sks/%s/this",
250 &enc);
251 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
252 if (msg != NULL)
253 {
254 fprintf (stderr, "failed to parse URI `%s': %s\n",
255 sbuf,
256 msg);
257 err = 1;
258 GNUNET_FS_stop (fs);
259 return;
260 }
109 fprintf (stderr, "Starting keyword search...\n"); 261 fprintf (stderr, "Starting keyword search...\n");
110 search = GNUNET_FS_search_start (fs, ksk_uri, 1, NULL); 262 ksk_search = GNUNET_FS_search_start (fs, ksk_uri, 1, "ksk_search");
263 fprintf (stderr, "Starting namespace search...\n") ;
264 sks_search = GNUNET_FS_search_start (fs, sks_uri, 1, "sks_search");
265 GNUNET_FS_uri_destroy (sks_uri);
111} 266}
112 267
113 268
@@ -127,6 +282,7 @@ sks_cont (void *cls,
127 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg); 282 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg);
128 GNUNET_assert (NULL == msg); 283 GNUNET_assert (NULL == msg);
129 fprintf (stderr, "Advertising update 'this' namespace entry under keyword...\n"); 284 fprintf (stderr, "Advertising update 'this' namespace entry under keyword...\n");
285 ksk_expect_uri = GNUNET_FS_uri_dup (uri);
130 GNUNET_FS_publish_ksk (fs, 286 GNUNET_FS_publish_ksk (fs,
131 ksk_uri, 287 ksk_uri,
132 meta, 288 meta,
@@ -136,6 +292,7 @@ sks_cont (void *cls,
136 GNUNET_FS_PUBLISH_OPTION_NONE, 292 GNUNET_FS_PUBLISH_OPTION_NONE,
137 &publish_cont, 293 &publish_cont,
138 NULL); 294 NULL);
295 GNUNET_FS_uri_destroy (ksk_uri);
139 GNUNET_CONTAINER_meta_data_destroy (meta); 296 GNUNET_CONTAINER_meta_data_destroy (meta);
140} 297}
141 298
@@ -149,18 +306,26 @@ adv_cont (void *cls,
149 struct GNUNET_FS_Namespace *ns; 306 struct GNUNET_FS_Namespace *ns;
150 struct GNUNET_TIME_Absolute expiration; 307 struct GNUNET_TIME_Absolute expiration;
151 308
309 if (NULL != emsg)
310 {
311 fprintf (stderr, "Error publishing: %s\n", emsg);
312 err = 1;
313 GNUNET_FS_stop (fs);
314 return;
315 }
152 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 316 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
153 ns = GNUNET_FS_namespace_create (fs, 317 ns = GNUNET_FS_namespace_create (fs,
154 "testNamespace"); 318 "testNamespace");
155 meta = GNUNET_CONTAINER_meta_data_create (); 319 meta = GNUNET_CONTAINER_meta_data_create ();
156 GNUNET_assert (NULL == emsg); 320 GNUNET_assert (NULL == emsg);
157 fprintf (stderr, "Advertising update 'this->next' namespace update...\n"); 321 fprintf (stderr, "Advertising update 'this->next' namespace update...\n");
322 sks_expect_uri = GNUNET_FS_uri_dup (uri);
158 GNUNET_FS_publish_sks (fs, 323 GNUNET_FS_publish_sks (fs,
159 ns, 324 ns,
160 "this", 325 "this",
161 "next", 326 "next",
162 meta, 327 meta,
163 uri, /* FIXME: this is non-sense (use CHK URI!) */ 328 uri, /* FIXME: this is non-sense (use CHK URI!?) */
164 expiration, 329 expiration,
165 1, 1, 330 1, 1,
166 GNUNET_FS_PUBLISH_OPTION_NONE, 331 GNUNET_FS_PUBLISH_OPTION_NONE,
@@ -172,17 +337,43 @@ adv_cont (void *cls,
172 337
173 338
174static void 339static void
340ns_iterator (void *cls,
341 const char *name,
342 const GNUNET_HashCode *id)
343{
344 int *ok = cls;
345
346 if (0 != strcmp (name,
347 "testNamespace"))
348 return;
349 *ok = GNUNET_YES;
350 nsid = *id;
351}
352
353
354static void
175testNamespace () 355testNamespace ()
176{ 356{
177 struct GNUNET_FS_Namespace *ns; 357 struct GNUNET_FS_Namespace *ns;
178 struct GNUNET_TIME_Absolute expiration; 358 struct GNUNET_TIME_Absolute expiration;
179 struct GNUNET_CONTAINER_MetaData *meta; 359 struct GNUNET_CONTAINER_MetaData *meta;
360 int ok;
180 361
181 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
182 meta = GNUNET_CONTAINER_meta_data_create ();
183 ns = GNUNET_FS_namespace_create (fs, 362 ns = GNUNET_FS_namespace_create (fs,
184 "testNamespace"); 363 "testNamespace");
364 ok = GNUNET_NO;
365 GNUNET_FS_namespace_list (fs, &ns_iterator, &ok);
366 if (GNUNET_NO == ok)
367 {
368 fprintf (stderr, "namespace_list failed to find namespace!\n");
369 GNUNET_FS_namespace_delete (ns, GNUNET_YES);
370 GNUNET_FS_stop (fs);
371 err = 1;
372 return;
373 }
185 fprintf (stderr, "Advertising namespace root...\n"); 374 fprintf (stderr, "Advertising namespace root...\n");
375 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
376 meta = GNUNET_CONTAINER_meta_data_create ();
186 GNUNET_FS_namespace_advertise (fs, 377 GNUNET_FS_namespace_advertise (fs,
187 ns, 378 ns,
188 meta, 379 meta,
@@ -194,17 +385,6 @@ testNamespace ()
194 GNUNET_CONTAINER_meta_data_destroy (meta); 385 GNUNET_CONTAINER_meta_data_destroy (meta);
195} 386}
196 387
197#if 0
198 fprintf (stderr, "Completed namespace search...\n");
199 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
200 GNUNET_assert (GNUNET_SYSERR == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
201 GNUNET_FS_uri_destroy (rootURI);
202 GNUNET_FS_uri_destroy (advURI);
203 GNUNET_assert (match == 1);
204 return 0;
205}
206#endif
207
208 388
209static void 389static void
210run (void *cls, 390run (void *cls,
@@ -214,7 +394,7 @@ run (void *cls,
214 const struct GNUNET_CONFIGURATION_Handle *cfg) 394 const struct GNUNET_CONFIGURATION_Handle *cfg)
215{ 395{
216 sched = s; 396 sched = s;
217 setup_peer (&p1, "test_fs_download_data.conf"); 397 setup_peer (&p1, "test_fs_namespace_data.conf");
218 fs = GNUNET_FS_start (sched, 398 fs = GNUNET_FS_start (sched,
219 cfg, 399 cfg,
220 "test-fs-namespace", 400 "test-fs-namespace",
@@ -253,10 +433,15 @@ main (int argc, char *argv[])
253 argvx, "test-fs-namespace", 433 argvx, "test-fs-namespace",
254 "nohelp", options, &run, NULL); 434 "nohelp", options, &run, NULL);
255 stop_arm (&p1); 435 stop_arm (&p1);
436 if (GNUNET_YES != update_started)
437 {
438 fprintf (stderr,
439 "Update search never started!\n");
440 err = 1;
441 }
256 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/"); 442 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
257 return 0; 443 return err;
258} 444}
259 445
260 446
261
262/* end of test_fs_namespace.c */ 447/* end of test_fs_namespace.c */
diff --git a/src/fs/test_fs_namespace_data.conf b/src/fs/test_fs_namespace_data.conf
index d7c2af4c4..3316da3da 100644
--- a/src/fs/test_fs_namespace_data.conf
+++ b/src/fs/test_fs_namespace_data.conf
@@ -19,7 +19,7 @@ HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs 19DEFAULTSERVICES = resolver datastore transport core fs
20 20
21[datastore] 21[datastore]
22#DEBUG = YES 22DEBUG = YES
23 23
24[statistics] 24[statistics]
25PORT = 42467 25PORT = 42467
@@ -36,7 +36,8 @@ HOSTNAME = localhost
36[fs] 36[fs]
37PORT = 42471 37PORT = 42471
38HOSTNAME = localhost 38HOSTNAME = localhost
39#DEBUG = YES 39IDENTITY_DIR = $SERVICEHOME/pseudos/
40DEBUG = YES
40 41
41[testing] 42[testing]
42WEAKRANDOM = YES 43WEAKRANDOM = YES