[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r416 - in GNUnet: . src/applications/fs src/applications/fs
From: |
grothoff |
Subject: |
[GNUnet-SVN] r416 - in GNUnet: . src/applications/fs src/applications/fs/ecrs |
Date: |
Tue, 8 Mar 2005 07:56:13 -0800 (PST) |
Author: grothoff
Date: 2005-03-08 07:56:11 -0800 (Tue, 08 Mar 2005)
New Revision: 416
Added:
GNUnet/src/applications/fs/ecrs/searchtest.c
Modified:
GNUnet/src/applications/fs/ecrs/Makefile.am
GNUnet/src/applications/fs/ecrs/ecrstest.c
GNUnet/src/applications/fs/ecrs/search.c
GNUnet/src/applications/fs/ecrs_core.c
GNUnet/todo
Log:
testcase for ecrs search, still failing
Modified: GNUnet/src/applications/fs/ecrs/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/ecrs/Makefile.am 2005-03-08 13:40:15 UTC (rev
415)
+++ GNUnet/src/applications/fs/ecrs/Makefile.am 2005-03-08 15:56:11 UTC (rev
416)
@@ -25,9 +25,10 @@
check_PROGRAMS = \
- directorytest \
uritest \
metatest \
+ searchtest \
+ directorytest \
ecrstest
TESTS = $(check_PROGRAMS)
@@ -47,6 +48,11 @@
ecrstest_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la
+searchtest_SOURCES = \
+ searchtest.c
+searchtest_LDADD = \
+ $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la
+
directorytest_SOURCES = \
directorytest.c
directorytest_LDADD = \
Modified: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c 2005-03-08 13:40:15 UTC (rev
415)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c 2005-03-08 15:56:11 UTC (rev
416)
@@ -257,7 +257,6 @@
pid_t daemon;
int status;
int ok;
- Mutex lock;
GNUNET_TCP_SOCKET * sock;
struct ECRS_URI * uri;
int i;
@@ -281,7 +280,6 @@
ok = YES;
initUtil(argc, argv, &parseCommandLine);
startCron();
- MUTEX_CREATE(&lock);
gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
sock = getClientSocket();
CHECK(sock != NULL);
@@ -307,7 +305,6 @@
FAILURE:
if (sock != NULL)
releaseClientSocket(sock);
- MUTEX_DESTROY(&lock);
stopCron();
doneUtil();
if (daemon != -1) {
Modified: GNUnet/src/applications/fs/ecrs/search.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/search.c 2005-03-08 13:40:15 UTC (rev
415)
+++ GNUnet/src/applications/fs/ecrs/search.c 2005-03-08 15:56:11 UTC (rev
416)
@@ -315,15 +315,22 @@
unsigned int size;
PendingSearch * ps;
int ret;
+ HashCode512 query;
type = ntohl(value->type);
size = ntohl(value->size) - sizeof(Datastore_Value);
LOG(LOG_DEBUG,
"Search received reply of type %u and size %u.\n",
type, size);
+ if (OK != getQueryFor(size,
+ (const DBlock*) &value[1],
+ &query))
+ return SYSERR;
for (i=0;i<sqc->queryCount;i++) {
- ps = sqc->queries[i];
- if ( ( (ps->type == type) ||
+ ps = sqc->queries[i];
+ if ( equalsHashCode512(&query,
+ &ps->keys[0]) &&
+ ( (ps->type == type) ||
(ps->type == ANY_BLOCK) ) &&
(YES == isDatumApplicable(type,
size,
@@ -332,14 +339,14 @@
ps->keys)) ) {
switch (type) {
case K_BLOCK: {
- KBlock * kb;
- char * dstURI;
+ const KBlock * kb;
+ const char * dstURI;
EncName enc;
int j;
if (size < sizeof(KBlock))
return SYSERR;
- kb = (KBlock*) &value[1];
+ kb = (const KBlock*) &value[1];
IFLOG(LOG_DEBUG,
hash2enc(&ps->decryptKey,
&enc));
@@ -351,13 +358,13 @@
size - sizeof(KBlock));
j = sizeof(KBlock);
while ( (j < size) &&
- (((char*)kb)[j] != '\0') )
+ (((const char*)kb)[j] != '\0') )
j++;
if (j == size) {
BREAK(); /* kblock malformed */
return SYSERR;
}
- dstURI = (char*) &kb[1];
+ dstURI = (const char*) &kb[1];
j++;
if (OK != ECRS_deserializeMetaData(&fi.meta,
&((char*)kb)[j],
@@ -384,22 +391,22 @@
return ret;
}
case N_BLOCK: {
- NBlock * nb;
+ const NBlock * nb;
if (size < sizeof(NBlock))
return SYSERR;
- nb = (NBlock*) &value[1];
+ nb = (const NBlock*) &value[1];
return processNBlock(nb,
NULL,
size,
sqc);
}
case KN_BLOCK: {
- KNBlock * kb;
+ const KNBlock * kb;
if (size < sizeof(KNBlock))
return SYSERR;
- kb = (KNBlock*) &value[1];
+ kb = (const KNBlock*) &value[1];
ECRS_decryptInPlace(&ps->decryptKey,
&kb->nblock,
size - sizeof(KBlock));
@@ -409,8 +416,8 @@
sqc);
}
case S_BLOCK: {
- SBlock * sb;
- char * dstURI;
+ const SBlock * sb;
+ const char * dstURI;
int j;
cron_t now;
HashCode512 updateId;
@@ -418,7 +425,7 @@
if (size < sizeof(SBlock))
return SYSERR;
- sb = (SBlock*) &value[1];
+ sb = (const SBlock*) &value[1];
ECRS_decryptInPlace(&ps->decryptKey,
&sb->creationTime,
size
@@ -433,7 +440,7 @@
BREAK(); /* sblock malformed */
return SYSERR;
}
- dstURI = (char*) &sb[1];
+ dstURI = (const char*) &sb[1];
j++;
if (OK != ECRS_deserializeMetaData(&fi.meta,
&dstURI[j],
Added: GNUnet/src/applications/fs/ecrs/searchtest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/searchtest.c 2005-03-08 13:40:15 UTC
(rev 415)
+++ GNUnet/src/applications/fs/ecrs/searchtest.c 2005-03-08 15:56:11 UTC
(rev 416)
@@ -0,0 +1,194 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/ecrs/searchtest.c
+ * @brief testcase for search
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_ecrs_lib.h"
+#include "tree.h"
+#include <sys/wait.h>
+
+#define CHECK(a) if (!(a)) { ok = NO; BREAK(); goto FAILURE; }
+
+static int parseCommandLine(int argc,
+ char * argv[]) {
+ FREENONNULL(setConfigurationString("GNUNETD",
+ "_MAGIC_",
+ "NO"));
+ FREENONNULL(setConfigurationString("GNUNETD",
+ "LOGFILE",
+ NULL));
+ FREENONNULL(setConfigurationString("GNUNET",
+ "LOGLEVEL",
+ "DEBUG"));
+ return OK;
+}
+
+static int testTerminate(void * unused) {
+ return OK;
+}
+
+static int searchCB(const ECRS_FileInfo * fi,
+ const HashCode512 * key,
+ void * closure) {
+ int * cnt = closure;
+ char * st;
+
+ st = ECRS_uriToString(fi->uri);
+ printf("Got result '%s'\n",
+ st);
+ FREE(st);
+ (*cnt)--;
+ if (0 == *cnt)
+ return SYSERR; /* abort search */
+ else
+ return OK;
+}
+
+/**
+ * @param *uri In: keyword URI
+ * @return OK on success, SYSERR on error
+ */
+static int searchFile(const struct ECRS_URI * uri,
+ int resultCount) {
+ ECRS_search(uri,
+ 0,
+ 15 * cronSECONDS,
+ &searchCB,
+ &resultCount,
+ &testTerminate,
+ NULL);
+ if (resultCount == 0)
+ return OK;
+ else
+ return SYSERR;
+}
+
+int main(int argc, char * argv[]){
+ pid_t daemon;
+ int status;
+ int ok;
+ GNUNET_TCP_SOCKET * sock;
+ struct ECRS_URI * uri;
+ struct ECRS_MetaData * meta;
+ struct ECRS_URI * key;
+ const char * keywords[6];
+
+ daemon = fork();
+ if (daemon == 0) {
+ if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
+ "gnunetd", /* arg0, path to gnunet binary */
+ "-d", /* do not daemonize so we can easily kill you */
+ "-c",
+ "check.conf", /* configuration file */
+ NULL)) {
+ fprintf(stderr,
+ _("'%s' failed: %s\n"),
+ "execlp",
+ STRERROR(errno));
+ return -1;
+ }
+ }
+ ok = YES;
+ initUtil(argc, argv, &parseCommandLine);
+ startCron();
+ gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
+ sock = getClientSocket();
+ CHECK(sock != NULL);
+
+ /* ACTUAL TEST CODE */
+
+ /* first, simple insertion => one result */
+ printf("Testing search for 'XXtest' with one result.\n");
+ uri =
ECRS_stringToUri("gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test");
+ meta = ECRS_createMetaData();
+ keywords[0] = "XXtest";
+ keywords[1] = NULL;
+
+ key = ECRS_keywordsToUri(keywords);
+ CHECK(OK == ECRS_addToKeyspace(key,
+ 0,
+ 0,
+ cronTime(NULL) + 10 * cronMINUTES, /* expire */
+ uri,
+ meta));
+ CHECK(OK == searchFile(key,
+ 1));
+ ECRS_freeUri(key);
+ ECRS_freeUri(uri);
+
+ /* inserting another URI under the 'XXtest' keyword and under 'binary'
+ should give both URIs since ECRS knows nothing about 'AND'ing: */
+ printf("Testing search for 'XXtest AND binary' with two results.\n");
+ uri =
ECRS_stringToUri("gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test-different");
+ keywords[1] = "binary";
+ keywords[2] = NULL;
+ key = ECRS_keywordsToUri(keywords);
+ CHECK(OK == ECRS_addToKeyspace(key,
+ 0,
+ 0,
+ cronTime(NULL) + 10 * cronMINUTES, /* expire */
+ uri,
+ meta));
+ CHECK(OK == searchFile(key,
+ 2));
+ ECRS_freeUri(key);
+ ECRS_freeUri(uri);
+ ECRS_freeMetaData(meta);
+
+ /* now searching just for 'XXtest' should again give 2 results! */
+ printf("Testing search for 'XXtest' with two results.\n");
+ keywords[1] = NULL;
+ key = ECRS_keywordsToUri(keywords);
+ CHECK(OK == searchFile(key,
+ 2));
+ ECRS_freeUri(key);
+
+
+
+ ECRS_freeUri(key);
+ /* END OF TEST CODE */
+ FAILURE:
+ if (sock != NULL)
+ releaseClientSocket(sock);
+ stopCron();
+ doneUtil();
+ if (daemon != -1) {
+ if (0 != kill(daemon, SIGTERM))
+ DIE_STRERROR("kill");
+ if (daemon != waitpid(daemon, &status, 0))
+ DIE_STRERROR("waitpid");
+
+ if ( (WEXITSTATUS(status) == 0) &&
+ (ok == YES) )
+ return 0;
+ else
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/* end of searchtest.c */
Modified: GNUnet/src/applications/fs/ecrs_core.c
===================================================================
--- GNUnet/src/applications/fs/ecrs_core.c 2005-03-08 13:40:15 UTC (rev
415)
+++ GNUnet/src/applications/fs/ecrs_core.c 2005-03-08 15:56:11 UTC (rev
416)
@@ -286,7 +286,7 @@
case S_BLOCK:
if (keyCount != 2)
return SYSERR; /* no match */
- hash(&((SBlock*)data)->subspace,
+ hash(&((const SBlock*)data)->subspace,
sizeof(PublicKey),
&hc);
if (equalsHashCode512(&keys[1],
@@ -297,7 +297,7 @@
case N_BLOCK:
if (keyCount != 2)
return SYSERR; /* no match */
- hash(&((NBlock*)data)->subspace,
+ hash(&((const NBlock*)data)->subspace,
sizeof(PublicKey),
&hc);
if (equalsHashCode512(&keys[1],
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-03-08 13:40:15 UTC (rev 415)
+++ GNUnet/todo 2005-03-08 15:56:11 UTC (rev 416)
@@ -9,7 +9,7 @@
- uni-peer testing:
* sqlite: test concurrency with iterators
* gnunet-pseudonym
- * gnunet-search: multiple search results don't work (yet); test on ECRS
level!
+ * gnunet-search: multiple search results don't work? Fix searchtest!
- multi-peer testing: (see sessiontest.c and tbenchtest.c for templates)
* gap
* dht / gnunet-dht-join and gnunet-dht-query
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r416 - in GNUnet: . src/applications/fs src/applications/fs/ecrs,
grothoff <=