[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r331 - in GNUnet/src/applications: fs/lib sqstore_sqlite
From: |
grothoff |
Subject: |
[GNUnet-SVN] r331 - in GNUnet/src/applications: fs/lib sqstore_sqlite |
Date: |
Sat, 26 Feb 2005 22:32:42 -0800 (PST) |
Author: grothoff
Date: 2005-02-26 22:32:42 -0800 (Sat, 26 Feb 2005)
New Revision: 331
Modified:
GNUnet/src/applications/fs/lib/fslibtest.c
GNUnet/src/applications/sqstore_sqlite/sqlite.c
Log:
fixes
Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c 2005-02-27 05:35:04 UTC (rev
330)
+++ GNUnet/src/applications/fs/lib/fslibtest.c 2005-02-27 06:32:42 UTC (rev
331)
@@ -27,6 +27,8 @@
return OK;
}
+static cron_t now;
+
static Datastore_Value * makeBlock(int i) {
Datastore_Value * block;
DBlock * db;
@@ -38,7 +40,7 @@
block->type = htonl(D_BLOCK);
block->prio = htonl(0);
block->anonymityLevel = htonl(0);
- block->expirationTime = cronTime(NULL) + 1 * cronHOURS;
+ block->expirationTime = htonll(now + 1 * cronHOURS);
db = (DBlock*) &block[1];
db->type = htonl(D_BLOCK);
memset(&db[1],
@@ -60,10 +62,40 @@
static int searchResultCB(const HashCode160 * key,
const Datastore_Value * value,
TSC * cls) {
- /* FIXME: verify result... */
- cls->found = YES;
- SEMAPHORE_UP(cls->sem);
- return SYSERR;
+ HashCode160 ekey;
+ Datastore_Value * blk;
+ Datastore_Value * eblk;
+ int ret;
+
+ blk = makeBlock(cls->i);
+ blk->prio = htonl(0);
+ blk->anonymityLevel = htonl(0);
+ blk->expirationTime = htonll(0);
+ fileBlockGetQuery((DBlock*) &blk[1],
+ ntohl(blk->size) - sizeof(Datastore_Value),
+ &ekey);
+ GNUNET_ASSERT(OK ==
+ fileBlockEncode((DBlock*) &blk[1],
+ ntohl(blk->size) - sizeof(Datastore_Value),
+ &ekey,
+ &eblk));
+ if ( (equalsHashCode160(&ekey,
+ key)) &&
+ (value->size == blk->size) &&
+ (0 == memcmp(value,
+ eblk,
+ ntohl(value->size))) ) {
+ cls->found = YES;
+ SEMAPHORE_UP(cls->sem);
+ ret = SYSERR;
+ } else {
+ BREAK();
+ printf("Received unexpected result.\n");
+ ret = OK;
+ }
+ FREE(eblk);
+ FREE(blk);
+ return ret;
}
static int trySearch(struct FS_SEARCH_CONTEXT * ctx,
@@ -122,7 +154,8 @@
HashCode160 query;
int i;
- daemon = fork();
+ cronTime(&now);
+ daemon = -1; // fork();
if (daemon == 0) {
/* FIXME: would be nice to be able to tell
gnunetd to use the check/debug DB and not
@@ -165,8 +198,8 @@
CHECK(OK == FS_insert(sock,
eblock));
CHECK(OK == trySearch(ctx, i));
- CHECK(1 == FS_delete(sock,
- eblock));
+ CHECK(SYSERR != FS_delete(sock,
+ eblock));
FREE(eblock);
hash(&((DBlock*)&block[1])[1],
ntohl(block->size) - sizeof(Datastore_Value) - sizeof(DBlock),
@@ -222,16 +255,19 @@
MUTEX_DESTROY(&lock);
stopCron();
doneUtil();
- if (0 != kill(daemon, SIGTERM))
- DIE_STRERROR("kill");
- if (daemon != waitpid(daemon, &status, 0))
- DIE_STRERROR("waitpid");
+ 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) )
+ if ( (WEXITSTATUS(status) == 0) &&
+ (ok == YES) )
+ return 0;
+ else
+ return 1;
+ } else
return 0;
- else
- return 1;
}
/* end of fslibtest.c */
Modified: GNUnet/src/applications/sqstore_sqlite/sqlite.c
===================================================================
--- GNUnet/src/applications/sqstore_sqlite/sqlite.c 2005-02-27 05:35:04 UTC
(rev 330)
+++ GNUnet/src/applications/sqstore_sqlite/sqlite.c 2005-02-27 06:32:42 UTC
(rev 331)
@@ -169,8 +169,9 @@
contentSize = sqlite3_column_int(stmt, 0) - sizeof(Datastore_Value);
- if (contentSize < 0)
+ if (contentSize < 0) {
return NULL; /* error */
+ }
if (sqlite3_column_bytes(stmt, 5) > sizeof(HashCode160) * 2 + 1 ||
sqlite3_column_bytes(stmt, 6) > contentSize * 2 + 1) {
@@ -328,6 +329,13 @@
"(prio > :4 AND expire == :5) OR expire > :6)");
if (type)
strcat(scratch, " AND type = :7");
+ else
+ SNPRINTF(&scratch[strlen(scratch)],
+ 512 - strlen(scratch),
+ " AND type != %d",
+ RESERVED_BLOCK); /* otherwise we iterate over
+ the stats entry, which would
+ be bad */
if (sortByPriority)
strcat(scratch, " ORDER BY prio ASC, expire ASC, hash ASC");
else
@@ -587,6 +595,7 @@
_("Invalid data in database. Please verify integrity!\n"));
continue;
}
+
#if DEBUG_SQLITE
LOG(LOG_DEBUG,
"Found in database block with type %u.\n",
@@ -642,7 +651,7 @@
sqlite3_stmt *stmt;
unsigned long rowLen;
unsigned int contentSize;
-
+
if ( (ntohl(value->size) < sizeof(Datastore_Value)) ) {
BREAK();
return SYSERR;
@@ -693,7 +702,7 @@
dbh->lastSync++;
dbh->payload += (hashLen + blockLen + sizeof(long long) * 5);
MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
-
+
#if DEBUG_SQLITE
LOG(LOG_DEBUG,
"SQLite: done writing content\n");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r331 - in GNUnet/src/applications: fs/lib sqstore_sqlite,
grothoff <=