gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r266 - in GNUnet/src: applications/datastore applications/f


From: grothoff
Subject: [GNUnet-SVN] r266 - in GNUnet/src: applications/datastore applications/fs/lib applications/fs/module applications/sqstore_mysql include
Date: Mon, 14 Feb 2005 19:45:08 -0800 (PST)

Author: grothoff
Date: 2005-02-14 19:45:07 -0800 (Mon, 14 Feb 2005)
New Revision: 266

Modified:
   GNUnet/src/applications/datastore/datastore.c
   GNUnet/src/applications/fs/lib/fslib.c
   GNUnet/src/applications/fs/lib/fslibtest.c
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/fs/module/ondemand.c
   GNUnet/src/applications/sqstore_mysql/mysql.c
   GNUnet/src/include/gnunet_fs_lib.h
Log:
various bugfixes discovered with fslibtest -- more pending

Modified: GNUnet/src/applications/datastore/datastore.c
===================================================================
--- GNUnet/src/applications/datastore/datastore.c       2005-02-15 02:45:30 UTC 
(rev 265)
+++ GNUnet/src/applications/datastore/datastore.c       2005-02-15 03:45:07 UTC 
(rev 266)
@@ -96,13 +96,38 @@
 static int del(const HashCode160 * query,
               const Datastore_Value * value) {
   int ok;
+  EncName enc;
+  int i;
 
-  if (! testAvailable(query)) 
+  if (! testAvailable(query)) {
+    IFLOG(LOG_WARNING,
+         hash2enc(query,
+                  &enc));
+    LOG(LOG_WARNING,
+       _("Availability test failed for '%s' at %s:%d.\n"),
+       &enc,
+       __FILE__, __LINE__);
     return 0;
+  }
   ok = sq->del(query, value);
-  if (OK == ok) {
-    makeUnavailable(query); /* update filter! */
-    available += ntohl(value->size);
+  if (0 < ok) {
+    for (i=0;i<ok;i++) {
+      makeUnavailable(query); /* update filter! */ 
+      available += ntohl(value->size);
+    }
+    IFLOG(LOG_DEBUG,
+         hash2enc(query,
+                  &enc));
+    LOG(LOG_DEBUG,
+       "Deleted '%s' from database.\n",
+       &enc);
+  } else {
+    IFLOG(LOG_WARNING,
+         hash2enc(query,
+                  &enc));
+    LOG(LOG_WARNING,
+       _("Database failed to delete %s.\n"),
+       &enc);
   }
   return ok;
 }

Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c      2005-02-15 02:45:30 UTC (rev 
265)
+++ GNUnet/src/applications/fs/lib/fslib.c      2005-02-15 03:45:07 UTC (rev 
266)
@@ -333,10 +333,12 @@
 }
 
 /**
- * Delete a block. 
+ * Delete a block.  The arguments are the same as the ones for
+ * FS_insert. 
  * 
  * @param block the block (properly encoded and all)
- * @return OK on success, SYSERR on error
+ * @return number of items deleted on success, 
+ *    SYSERR on error
  */
 int FS_delete(GNUNET_TCP_SOCKET * sock,
              const Datastore_Value * block) {

Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c  2005-02-15 02:45:30 UTC (rev 
265)
+++ GNUnet/src/applications/fs/lib/fslibtest.c  2005-02-15 03:45:07 UTC (rev 
266)
@@ -117,10 +117,11 @@
   Mutex lock;
   GNUNET_TCP_SOCKET * sock;
   Datastore_Value * block;
+  Datastore_Value * eblock;
   HashCode160 hc;
+  HashCode160 query;
   int i;
 
-  memset(&hc, 42, sizeof(HashCode160));
   daemon = fork();
   if (daemon == 0) {
     /* FIXME: would be nice to be able to tell
@@ -154,11 +155,19 @@
   /* ACTUAL TEST CODE */
   for (i=1;i<32;i++) {
     block = makeBlock(i);
+    fileBlockGetQuery((DBlock*) &block[1],
+                     ntohl(block->size) - sizeof(Datastore_Value),
+                     &query);
+    CHECK(OK == fileBlockEncode((DBlock*) &block[1],
+                               ntohl(block->size) - sizeof(Datastore_Value),
+                               &query,
+                               &eblock));
     CHECK(OK == FS_insert(sock, 
-                         block));
+                         eblock));
     CHECK(OK == trySearch(ctx, i));
-    CHECK(OK == FS_delete(sock,
-                         block));
+    CHECK(1 == FS_delete(sock,
+                        eblock));
+    FREE(eblock);
     hash(&((DBlock*)&block[1])[1],
         ntohl(block->size) - sizeof(Datastore_Value) - sizeof(DBlock),
         &hc);
@@ -174,11 +183,19 @@
   }
   for (i=32;i<MAX_BUFFER_SIZE;i*=2) {
     block = makeBlock(i);
+    fileBlockGetQuery((DBlock*) &block[1],
+                     ntohl(block->size) - sizeof(Datastore_Value),
+                     &query);
+    CHECK(OK == fileBlockEncode((DBlock*) &block[1],
+                               ntohl(block->size) - sizeof(Datastore_Value),
+                               &query,
+                               &eblock));
     CHECK(OK == FS_insert(sock, 
-                         block));
+                         eblock));
     CHECK(OK == trySearch(ctx, i));
-    CHECK(OK == FS_delete(sock,
-                         block));
+    CHECK(1 == FS_delete(sock,
+                        eblock));
+    FREE(eblock);
     hash(&((DBlock*)&block[1])[1],
         ntohl(block->size) - sizeof(Datastore_Value) - sizeof(DBlock),
         &hc);

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-02-15 02:45:30 UTC (rev 
265)
+++ GNUnet/src/applications/fs/module/fs.c      2005-02-15 03:45:07 UTC (rev 
266)
@@ -104,6 +104,7 @@
   HashCode160 hc;
   cron_t et;
   cron_t now;
+  EncName enc;
 
   if (ntohl(value->size) < sizeof(GapWrapper)) {
     BREAK();
@@ -149,9 +150,12 @@
     return SYSERR;
   }
   processResponse(key, dv); 
+  IFLOG(LOG_DEBUG,
+       hash2enc(key,
+                &enc));
   LOG(LOG_DEBUG,
-      "FS received GAP-PUT request (key: %u)\n",
-      key->a);
+      "FS received GAP-PUT request (query: %s)\n",
+      &enc);
   ret = datastore->putUpdate(key,
                             dv);
   FREE(dv);
@@ -193,7 +197,7 @@
  */ 
 static int csHandleRequestQueryStart(ClientHandle sock,
                                     const CS_HEADER * req) {
-  RequestSearch * rs;
+  const RequestSearch * rs;
   unsigned int keyCount;
   EncName enc;
 
@@ -201,7 +205,7 @@
     BREAK();
     return SYSERR;
   }
-  rs = (RequestSearch*) req;
+  rs = (const RequestSearch*) req;
   IFLOG(LOG_DEBUG,
        hash2enc(&rs->query[0],
                 &enc));
@@ -246,15 +250,19 @@
 static int csHandleRequestQueryStop(ClientHandle sock,
                                    const CS_HEADER * req) {
   RequestSearch * rs;
+  EncName enc;
 
   if (ntohs(req->size) < sizeof(RequestSearch)) {
     BREAK();
     return SYSERR;
   }
   rs = (RequestSearch*) req;
+  IFLOG(LOG_DEBUG,
+       hash2enc(&rs->query[0],
+                &enc));
   LOG(LOG_DEBUG,
-      "FS received QUERY STOP (key: %u)\n",
-      rs->query[0].a);
+      "FS received QUERY STOP (query: %s)\n",
+      &enc);
   if (ntohl(rs->anonymityLevel) == 0) {
     /* FIXME 0.7.1: cancel with dht? */
   }
@@ -272,7 +280,7 @@
  */
 static int csHandleRequestInsert(ClientHandle sock,
                                 const CS_HEADER * req) {
-  RequestInsert * ri;
+  const RequestInsert * ri;
   Datastore_Value * datum;
   int ret;
   HashCode160 query;
@@ -283,7 +291,7 @@
     BREAK();
     return SYSERR;
   }
-  ri = (RequestInsert*) req;
+  ri = (const RequestInsert*) req;
   datum = MALLOC(sizeof(Datastore_Value) + 
                 ntohs(req->size) - sizeof(RequestInsert));
   datum->size = htonl(sizeof(Datastore_Value) + 
@@ -380,7 +388,8 @@
                       ntohs(ri->header.size) - sizeof(RequestIndex),
                       (const DBlock*) &ri[1]);
   LOG(LOG_DEBUG,
-      "Sending confirmation of index request to client\n");
+      "Sending confirmation (%s) of index request to client\n",
+      ret == OK ? "success" : "failure");
   return coreAPI->sendValueToClient(sock,
                                    ret);
 }
@@ -399,9 +408,18 @@
   if ( (comp->size != value->size) ||
        (0 != memcmp(&value[1],
                    &comp[1],
-                   ntohl(value->size) - sizeof(Datastore_Value))) )
+                   ntohl(value->size) - sizeof(Datastore_Value))) ) {
+    LOG(LOG_DEBUG,
+       "'%s' found value that does not match (%u, %u).\n",
+       __FUNCTION__,
+       ntohl(comp->size),
+       ntohl(value->size));
     return OK;
+  }
   *comp = *value; /* make copy! */
+  LOG(LOG_DEBUG,
+      "'%s' found value that matches.\n",
+      __FUNCTION__);
   return SYSERR;
 }
 
@@ -413,16 +431,17 @@
 static int csHandleRequestDelete(ClientHandle sock,
                                 const CS_HEADER * req) {
   int ret;
-  RequestDelete * rd;
+  const RequestDelete * rd;
   Datastore_Value * value;
   HashCode160 query;
   unsigned int type;
+  EncName enc;
   
   if (ntohs(req->size) < sizeof(RequestDelete)) {
     BREAK();
     return SYSERR;
   }
-  rd = (RequestDelete*) req;  
+  rd = (const RequestDelete*) req;  
   value = MALLOC(sizeof(Datastore_Value) +
                 ntohs(req->size) - sizeof(RequestDelete));
   value->size = ntohl(sizeof(Datastore_Value) +
@@ -430,6 +449,9 @@
   type = getTypeOfBlock(ntohs(rd->header.size) - sizeof(RequestDelete),
                        (const DBlock*)&rd[1]);
   value->type = htonl(type);
+  memcpy(&value[1],
+        &rd[1],
+        ntohs(req->size) - sizeof(RequestDelete));
   if (OK != getQueryFor(ntohs(rd->header.size) - sizeof(RequestDelete),
                        (const DBlock*)&rd[1],
                        &query)) {
@@ -437,9 +459,12 @@
     BREAK();
     return SYSERR;
   }
+  IFLOG(LOG_DEBUG,
+       hash2enc(&query,
+                &enc));
   LOG(LOG_DEBUG,
-      "FS received REQUEST DELETE (key: %u, type: %u)\n",
-      query.a,
+      "FS received REQUEST DELETE (query: %s, type: %u)\n",
+      &enc,
       type);
 
   MUTEX_LOCK(&lock);
@@ -453,6 +478,9 @@
     ret = SYSERR;
   MUTEX_UNLOCK(&lock);
   FREE(value);
+  LOG(LOG_DEBUG,
+      "Sending confirmation (%s) of delete request to client\n",
+      ret != SYSERR ? "success" : "failure");
   return coreAPI->sendValueToClient(sock, 
                                    ret);
 }

Modified: GNUnet/src/applications/fs/module/ondemand.c
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.c        2005-02-15 02:45:30 UTC 
(rev 265)
+++ GNUnet/src/applications/fs/module/ondemand.c        2005-02-15 03:45:07 UTC 
(rev 266)
@@ -129,8 +129,15 @@
     return SYSERR;
   }
   fn = getOnDemandFile(fileId);
+  LOG(LOG_DEBUG,
+      "Storing on-demand encoded data in '%s'.\n",
+      fn);
   fd = OPEN(fn, 
+#ifdef O_LARGEFILE
+           O_CREAT|O_WRONLY|O_LARGEFILE,
+#else
            O_CREAT|O_WRONLY,
+#endif
            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); /* 644 */
   if(fd == -1) {    
     LOG_FILE_STRERROR(LOG_ERROR, "open", fn);
@@ -228,7 +235,11 @@
   odb = (OnDemandBlock*) dbv;
   fn = getOnDemandFile(&odb->fileId);
 
-  fileHandle = OPEN(fn, O_EXCL, S_IRUSR);
+#ifdef O_LARGEFILE
+  fileHandle = OPEN(fn, O_RDONLY|O_LARGEFILE, 0);
+#else
+  fileHandle = OPEN(fn, O_RDONLY, 0);
+#endif
   if (fileHandle == -1) {
     LOG_FILE_STRERROR(LOG_ERROR, "open", fn);
     FREE(fn);
@@ -342,8 +353,15 @@
   DBlock * block;
 
   fn = getOnDemandFile(fileId);
+  LOG(LOG_DEBUG,
+      "Removing on-demand encoded data stored in '%s'.\n",
+      fn);
   fd = OPEN(fn, 
+#ifdef O_LARGEFILE
+           O_RDONLY | O_LARGEFILE,
+#else
            O_RDONLY,
+#endif
            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); /* 644 */
   if(fd == -1) {    
     LOG_FILE_STRERROR(LOG_ERROR, "open", fn);
@@ -377,7 +395,7 @@
     odb.fileId = *fileId;
     /* compute the primary key */
     fileBlockGetQuery(block,
-                     delta,
+                     delta + sizeof(DBlock),
                      &key);  
     ret = datastore->del(&key,
                         &odb.header);

Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c       2005-02-15 02:45:30 UTC 
(rev 265)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c       2005-02-15 03:45:07 UTC 
(rev 266)
@@ -845,11 +845,19 @@
   IFLOG(LOG_DEBUG,
        hash2enc(query,
                 &enc));
-  LOG(LOG_DEBUG,
-      "MySQL found %u results for %s of type %u\n",
-      count,
-      &enc,
-      type);
+  if (count > 0) {
+    LOG(LOG_DEBUG,
+       "MySQL found %d results for '%s' of type %u.\n",
+       count,
+       &enc,
+       type);
+  } else {
+    LOG(LOG_DEBUG,
+       "MySQL iteration aborted looking for '%s' of type %u.\n",
+       &enc,
+       type);
+  }
+      
   return count;
 }
 
@@ -941,7 +949,15 @@
   size_t n;
   int count;
   int contentSize;
-
+  EncName enc;
+  
+  IFLOG(LOG_DEBUG,
+       hash2enc(key, 
+                &enc));
+  LOG(LOG_DEBUG,
+      "MySQL is executing deletion request for content of query '%s' and type 
%u\n",
+      &enc,
+      ntohl(value->type));
   MUTEX_LOCK(&dbh->DATABASE_Lock_);
   contentSize = ntohl(value->size)-sizeof(Datastore_Value);
   escapedHash = MALLOC(2*sizeof(HashCode160)+1);
@@ -956,7 +972,7 @@
                           contentSize);
 
   n = sizeof(HashCode160)*2+contentSize*2+400+1;
-  scratch=MALLOC(n);
+  scratch = MALLOC(n);
   if(value == NULL) {
     SNPRINTF(scratch, 
             n,
@@ -990,6 +1006,9 @@
   }
   count = mysql_affected_rows(dbh->dbf);
   MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
+  LOG(LOG_DEBUG,
+      "MySQL DELETE operation affected %d rows.\n",
+      count);
   return count;
 }
 

Modified: GNUnet/src/include/gnunet_fs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fs_lib.h  2005-02-15 02:45:30 UTC (rev 265)
+++ GNUnet/src/include/gnunet_fs_lib.h  2005-02-15 03:45:07 UTC (rev 266)
@@ -74,16 +74,21 @@
 unsigned int FS_getAveragePriority(GNUNET_TCP_SOCKET * sock);
 
 /**
- * Insert a block. 
+ * Insert a block.  Note that while the API is VERY similar to
+ * FS_index in terms of signature, the block for FS_index must be in
+ * plaintext, whereas the block passed to FS_insert must be encrypted!
  * 
  * @param block the block (properly encoded and all)
  * @return OK on success, SYSERR on error
+ * @see ecrs_core.h::fileBlockEncode
  */
 int FS_insert(GNUNET_TCP_SOCKET * sock,
              const Datastore_Value * block);
 
 /**
- * Index a block. 
+ * Index a block.  Note that while the API is VERY similar to
+ * FS_insert in terms of signature, the block for FS_index must be in
+ * plaintext, whereas the block passed to FS_insert must be encrypted!
  * 
  * @param fileHc the hash of the entire file
  * @param block the data from the file (in plaintext)
@@ -96,10 +101,12 @@
             unsigned long long offset);
 
 /**
- * Delete a block. 
+ * Delete a block.  The arguments are the same as the ones for
+ * FS_insert.
  * 
  * @param block the block (properly encoded and all)
- * @return OK on success, SYSERR on error
+ * @return number of items deleted on success, 
+ *    SYSERR on error
  */
 int FS_delete(GNUNET_TCP_SOCKET * sock,
              const Datastore_Value * block);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]