gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r176 - in GNUnet: . src/applications/fs src/applications/fs


From: grothoff
Subject: [GNUnet-SVN] r176 - in GNUnet: . src/applications/fs src/applications/fs/ecrs src/applications/fs/lib src/applications/fs/module src/include
Date: Fri, 4 Feb 2005 01:25:29 -0800 (PST)

Author: grothoff
Date: 2005-02-04 01:25:28 -0800 (Fri, 04 Feb 2005)
New Revision: 176

Modified:
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/ecrs/ecrs.c
   GNUnet/src/applications/fs/ecrs/keyspace.c
   GNUnet/src/applications/fs/ecrs/namespace.c
   GNUnet/src/applications/fs/ecrs/unindex.c
   GNUnet/src/applications/fs/ecrs/upload.c
   GNUnet/src/applications/fs/ecrs_core.c
   GNUnet/src/applications/fs/lib/fslib.c
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/include/ecrs_core.h
   GNUnet/src/include/fs.h
   GNUnet/src/include/gnunet_protocols.h
   GNUnet/todo
Log:
changing all blocks to come with a type as part of the block

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/download.c  2005-02-04 09:25:28 UTC (rev 
176)
@@ -872,7 +872,6 @@
   unsigned int priority;
   unsigned int mpriority;
   cron_t timeout;
-  unsigned int type;
   unsigned int ttl;
   int TTL_DECREMENT;
   static unsigned int lastmpriority;
@@ -945,13 +944,9 @@
     timeout = now + ttl;
   }
 
-  if (entry->node->level == 0)
-    type = D_BLOCK;
-  else
-    type = I_BLOCK;
   entry->searchHandle
     = FS_start_search(rm->sctx,
-                     type,
+                     D_BLOCK,
                      1,
                      &entry->node->chk.key,
                      entry->node->ctx->anonymityLevel,

Modified: GNUnet/src/applications/fs/ecrs/ecrs.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrs.c      2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/ecrs.c      2005-02-04 09:25:28 UTC (rev 
176)
@@ -21,7 +21,7 @@
 /**
  * @file applications/fs/ecrs/ecrs.c
  * @brief ECRS helper functions
- * @see http://www.ovmj.org/GNUnet/encoding.php3
+ * @see http://gnunet.org/encoding.php3
  * @author Krista Bennett
  * @author Christian Grothoff
  */

Modified: GNUnet/src/applications/fs/ecrs/keyspace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/keyspace.c  2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/keyspace.c  2005-02-04 09:25:28 UTC (rev 
176)
@@ -80,6 +80,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     kb = (KBlock*) &value[1];
+    kb->type = ntohl(K_BLOCK);
     memcpy(&kb[1],
           dstURI,
           strlen(dstURI)+1);
@@ -98,6 +99,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     kb = (KBlock*) &value[1];
+    kb->type = ntohl(K_BLOCK);
     memcpy(&kb[1],
           dstURI,
           strlen(dstURI)+1);

Modified: GNUnet/src/applications/fs/ecrs/namespace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespace.c 2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/namespace.c 2005-02-04 09:25:28 UTC (rev 
176)
@@ -155,6 +155,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     nb = (NBlock*) &value[1];
+    nb->type = htonl(N_BLOCK);
     mdsize = size - sizeof(NBlock);
     mdsize = ECRS_serializeMetaData(meta,
                                    (char*)&nb[1],
@@ -171,6 +172,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     nb = (NBlock*) &value[1];
+    nb->type = htonl(N_BLOCK);
     ECRS_serializeMetaData(meta,
                           (char*)&nb[1],
                           mdsize,
@@ -213,6 +215,7 @@
   knvalue->type = htonl(KN_BLOCK);
   knvalue->size = htonl(sizeof(Datastore_Value) + size);
   knb = (KNBlock*) &knvalue[1];
+  knb->type = htonl(KN_BLOCK);
   memcpy(&knb->nblock,
         &nb,
         sizeof(NBlock) + mdsize);
@@ -378,6 +381,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     sb = (SBlock*) &value[1];
+    sb->type = htonl(S_BLOCK);
     memcpy(&sb[1],
           dstURI,
           strlen(dstURI) + 1);
@@ -396,6 +400,7 @@
     value = MALLOC(sizeof(Datastore_Value) + 
                   size);
     sb = (SBlock*) &value[1];
+    sb->type = htonl(S_BLOCK);
     memcpy(&sb[1],
           dstURI,
           strlen(dstURI) + 1);

Modified: GNUnet/src/applications/fs/ecrs/unindex.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/unindex.c   2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/unindex.c   2005-02-04 09:25:28 UTC (rev 
176)
@@ -297,7 +297,7 @@
     iblocks[i]->size = htonl(sizeof(Datastore_Value));
     iblocks[i]->anonymityLevel = htonl(0);
     iblocks[i]->prio = htonl(0);
-    iblocks[i]->type = htonl(I_BLOCK);
+    iblocks[i]->type = htonl(D_BLOCK);
     iblocks[i]->expirationTime = htonll(0);
   }
 

Modified: GNUnet/src/applications/fs/ecrs/upload.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/upload.c    2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs/upload.c    2005-02-04 09:25:28 UTC (rev 
176)
@@ -263,7 +263,7 @@
     iblocks[i]->size = htonl(sizeof(Datastore_Value));
     iblocks[i]->anonymityLevel = htonl(anonymityLevel);
     iblocks[i]->prio = htonl(priority);
-    iblocks[i]->type = htonl(I_BLOCK);
+    iblocks[i]->type = htonl(D_BLOCK);
     iblocks[i]->expirationTime = htonll(expirationTime);
   }
 

Modified: GNUnet/src/applications/fs/ecrs_core.c
===================================================================
--- GNUnet/src/applications/fs/ecrs_core.c      2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/ecrs_core.c      2005-02-04 09:25:28 UTC (rev 
176)
@@ -56,12 +56,15 @@
   hashToKey(&hc,
            &skey,
            &iv[0]);
-  val = MALLOC(sizeof(Datastore_Value) + len);
-  val->size = htonl(sizeof(Datastore_Value) + len);
-  val->type = htonl(ONDEMAND_BLOCK);
+  val = MALLOC(sizeof(Datastore_Value)
+              + len + sizeof(DBlock));
+  val->size = htonl(sizeof(Datastore_Value) + 
+                   len + sizeof(DBlock));
+  val->type = htonl(D_BLOCK);
   val->prio = htonl(0);
   val->anonymityLevel = htonl(0);
   val->expirationTime = htonl(0);
+  ((DBlock*) &val[1])->type = htonl(D_BLOCK);
   GNUNET_ASSERT(len == encryptBlock(data,
                                    len,
                                    &skey,
@@ -117,23 +120,29 @@
   FREE(tmp);
 }
 
+unsigned int getTypeOfBlock(unsigned int size,
+                           const void * data) {
+  GNUNET_ASSERT(size > 4);
+  return *((const unsigned int*)data);
+}
+
 /**
  * What is the main query (the one that is used in routing and for the
  * DB lookup) for the given content and block type?
  *
- * @param type the type of the encoding
  * @param data the content (encoded)
  * @param query set to the query for the content
  * @return SYSERR if the content is invalid or
  *   the content type is not known
  */
-int getQueryFor(unsigned int type,
-               unsigned int size,
+int getQueryFor(unsigned int size,
                const char * data,
                HashCode160 * query) {  
+  unsigned int type;
+
+  type = getTypeOfBlock(size, data);
   switch (type) {
   case D_BLOCK: 
-  case I_BLOCK: 
     hash(data, size, query);
     return OK;  
   case S_BLOCK: {
@@ -224,8 +233,7 @@
  * Verify that the given Datum is a valid response
  * to a given query.
  *
- * @param type the type of the datum (and the query,
- *  this match was already confirmed)
+ * @param type the type of the query
  * @param size the size of the data
  * @param data the encoded data
  * @param keyCount the number of keys in the query
@@ -240,7 +248,12 @@
                      unsigned int keyCount,
                      const HashCode160 * keys) {
   HashCode160 hc;
-  if (OK != getQueryFor(type, size, data, &hc)) {
+
+  if (type != getTypeOfBlock(size, data)) {
+    BREAK();
+    return SYSERR; /* type mismatch */
+  }
+  if (OK != getQueryFor(size, data, &hc)) {
     BREAK(); /* malformed data */
     return SYSERR;
   }
@@ -273,7 +286,6 @@
     else
       return SYSERR;  
   case D_BLOCK:
-  case I_BLOCK:
   case K_BLOCK:
   case KN_BLOCK: 
     if (keyCount != 1)

Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c      2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/lib/fslib.c      2005-02-04 09:25:28 UTC (rev 
176)
@@ -71,8 +71,7 @@
       }
       rep = (ReplyContent*) ctx;
       size = ntohs(hdr->size) - sizeof(ReplyContent);
-      if (OK != getQueryFor(ntohl(rep->type),
-                           size,
+      if (OK != getQueryFor(size,
                            (char*)&rep[1],
                            &query)) {
        BREAK();
@@ -251,7 +250,6 @@
   ri->prio = block->prio;
   ri->expiration = block->expirationTime;
   ri->anonymityLevel = block->anonymityLevel;
-  ri->type = block->type;
   memcpy(&ri[1],
         &block[1],
         size);
@@ -328,7 +326,6 @@
   rd = MALLOC(sizeof(RequestDelete) + size);
   rd->header.size = htons(sizeof(RequestDelete) + size);
   rd->header.type = htons(AFS_CS_PROTO_DELETE);
-  rd->type = block->type;
   memcpy(&rd[1],
         &block[1],
         size);

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/applications/fs/module/fs.c      2005-02-04 09:25:28 UTC (rev 
176)
@@ -188,15 +188,15 @@
   datum->expirationTime = ri->expiration;
   datum->prio = ri->prio;
   datum->anonymityLevel = ri->anonymityLevel;
-  datum->type = ri->type;
-  if (OK != getQueryFor(ntohl(ri->type),
-                       ntohs(ri->header.size) - sizeof(RequestInsert),
+  if (OK != getQueryFor(ntohs(ri->header.size) - sizeof(RequestInsert),
                        (char*)&ri[1],
                        &query)) {
     BREAK();
     FREE(datum);
     return SYSERR;
   }
+  datum->type = htonl(getTypeOfBlock(ntohs(ri->header.size) - 
sizeof(RequestInsert),
+                                    &ri[1]));
   MUTEX_LOCK(&lock);
   ret = datastore->put(&query,
                       datum);
@@ -272,6 +272,7 @@
   RequestDelete * rd;
   Datastore_Value * value;
   HashCode160 query;
+  unsigned int type;
   
   if (ntohs(req->size) < sizeof(RequestDelete)) {
     BREAK();
@@ -282,10 +283,11 @@
                 ntohs(req->size) - sizeof(RequestDelete));
   value->size = ntohl(sizeof(Datastore_Value) +
                      ntohs(req->size) - sizeof(RequestDelete));
-  value->type = rd->type;
-  if (OK != getQueryFor(ntohl(rd->type),
-                       ntohs(rd->header.size) - sizeof(RequestDelete),
-                       (char*)&rd[1],
+  type = getTypeOfBlock(ntohs(rd->header.size) - sizeof(RequestDelete),
+                       (const char*)&rd[1]);
+  value->type = htonl(type);
+  if (OK != getQueryFor(ntohs(rd->header.size) - sizeof(RequestDelete),
+                       (const char*)&rd[1],
                        &query)) {
     FREE(value);
     BREAK();
@@ -293,7 +295,7 @@
   }
   MUTEX_LOCK(&lock);
   if (SYSERR == datastore->get(&query,
-                              ntohl(rd->type),
+                              type,
                               &completeValue,
                               value)) /* aborted == found! */
     ret = datastore->del(&query,
@@ -519,7 +521,6 @@
  */
 static int gapPut(void * closure,
                  const HashCode160 * key,
-                 unsigned int type,
                  const DataContainer * value,
                  unsigned int prio) {
   Datastore_Value * dv;
@@ -538,9 +539,7 @@
   size = ntohl(gw->dc.size) 
     - sizeof(GapWrapper) 
     + sizeof(Datastore_Value);
-  if ( (type != htonl(gw->type)) ||
-       (OK != getQueryFor(type,
-                         size - sizeof(Datastore_Value),
+  if ( (OK != getQueryFor(size - sizeof(Datastore_Value),
                          (char*)&gw[1],
                          &hc)) ||
        (! equalsHashCode160(&hc, key)) ) {
@@ -581,7 +580,6 @@
  */
 static int gapDel(void * closure,
                  const HashCode160 * key,
-                 unsigned int type,
                  const DataContainer * value) {
   BREAK(); /* gap does not use 'del'! */
   return SYSERR;

Modified: GNUnet/src/include/ecrs_core.h
===================================================================
--- GNUnet/src/include/ecrs_core.h      2005-02-04 08:52:30 UTC (rev 175)
+++ GNUnet/src/include/ecrs_core.h      2005-02-04 09:25:28 UTC (rev 176)
@@ -41,16 +41,16 @@
 } CHK;
 
 /**
- * @brief inner block
+ * @brief data block
  */
 typedef struct {
-  unsigned int crc32;
-} IBlock;
+  unsigned int type;
+} DBlock;
 
 typedef struct {
-  IBlock iblock;
+  DBlock iblock;
   CHK data[1];
-} IBlock_GENERIC;
+} IBlock;
 
 /**
  * @brief information required to download a file from GNUnet
@@ -75,6 +75,8 @@
  * @brief keyword block (advertising data under a keyword)
  */
 typedef struct {
+  unsigned int type;
+
   Signature signature; /* 256 b */
   /**
    * Key generated (!) from the H(keyword) as the seed!
@@ -86,6 +88,8 @@
 } KBlock;
 
 typedef struct {
+  unsigned int type;
+
   Signature signature; /* 256 b */
   /**
    * S = H(subspace); 264 b 
@@ -107,7 +111,10 @@
 } SBlock;
 
 typedef struct {
+  unsigned int type;
+
   Signature signature; /* 256 b */
+
   PublicKey subspace; /* S = H(subspace); 264 b */
   /**
    * Must be all zeros 
@@ -132,6 +139,8 @@
  * @brief keyword-NBlock (advertising namespace under a keyword)
  */
 typedef struct {
+  unsigned int type;
+
   KBlock kblock;
   NBlock nblock;
 } KNBlock;
@@ -175,6 +184,12 @@
                     HashCode160 * key);
 
 /**
+ * What is the type of the given block of data?
+ */
+unsigned int getTypeOfBlock(unsigned int size,
+                           const void * data);
+
+/**
  * What is the main query (the one that is used in
  * routing and for the DB lookup) for the given
  * content and block type?
@@ -185,8 +200,7 @@
  * @return SYSERR if the content is invalid or
  *   the content type is not known
  */
-int getQueryFor(unsigned int type,
-               unsigned int size,
+int getQueryFor(unsigned int size,
                const char * data,
                HashCode160 * query);
 
@@ -194,8 +208,7 @@
  * Verify that the given Datum is a valid response
  * to a given query.
  *
- * @param type the type of the datum (and the query,
- *  this match was already confirmed)
+ * @param type the type of the queryo
  * @param size the size of the data
  * @param data the encoded data
  * @param keyCount the number of keys in the query

Modified: GNUnet/src/include/fs.h
===================================================================
--- GNUnet/src/include/fs.h     2005-02-04 08:52:30 UTC (rev 175)
+++ GNUnet/src/include/fs.h     2005-02-04 09:25:28 UTC (rev 176)
@@ -113,11 +113,6 @@
   cron_t expiration;
 
   /**
-   * Type of the content.
-   */
-  unsigned int type;
-
-  /**
    * What are the anonymity requirements for this content?
    * Use 0 if anonymity is not required (enables direct
    * sharing / DHT routing).
@@ -179,19 +174,12 @@
 
 
 /**
- * Client to server: delete content.
- * This struct is followed by a variable
- * number of bytes of the content that is
- * to be deleted.
+ * Client to server: delete content.  This struct is followed by a
+ * variable number of bytes of the content that is to be deleted.
  */
 typedef struct {
   CS_HEADER header;
 
-  /**
-   * Type of the content.
-   */
-  unsigned int type;
-
 } RequestDelete;
 
 typedef struct {

Modified: GNUnet/src/include/gnunet_protocols.h
===================================================================
--- GNUnet/src/include/gnunet_protocols.h       2005-02-04 08:52:30 UTC (rev 
175)
+++ GNUnet/src/include/gnunet_protocols.h       2005-02-04 09:25:28 UTC (rev 
176)
@@ -361,34 +361,29 @@
 #define ANY_BLOCK 0
 
 /**
- * Data block (leaf).
+ * Data block (leaf or inner block).
  */
 #define D_BLOCK 1
 
 /**
- * Inner block in a file tree.
- */
-#define I_BLOCK 2
-
-/**
  * Namespace binding (subspace entry)
  */
-#define S_BLOCK 3
+#define S_BLOCK 2
 
 /**
  * Keyword binding (entry in keyword space)
  */
-#define K_BLOCK 4
+#define K_BLOCK 3
 
 /**
  * Namespace advertisement.
  */
-#define N_BLOCK 5
+#define N_BLOCK 4
 
 /**
  * Namespace advertisement in keyword space.
  */
-#define KN_BLOCK 6
+#define KN_BLOCK 5
 
 /**
  * DHT String2String (for dht-query/dht-join).

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-02-04 08:52:30 UTC (rev 175)
+++ GNUnet/todo 2005-02-04 09:25:28 UTC (rev 176)
@@ -8,6 +8,8 @@
 - 593???
 
 0.7.0pre0 [3'05] (aka "pre-preview"):
+- Known bugs:
+  * Block type field is not set at block creation (NEW, fatal!)
 - Missing Features:
   * fsui core (persistence, shutdown, multiple FSUIs) [ difficult ]
   * mysql sqstore implementation iterator problem (Igor?)





reply via email to

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