gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r167 - in GNUnet/src: applications/dht/module applications/


From: grothoff
Subject: [GNUnet-SVN] r167 - in GNUnet/src: applications/dht/module applications/rpc include
Date: Thu, 3 Feb 2005 03:37:12 -0800 (PST)

Author: grothoff
Date: 2005-02-03 03:37:11 -0800 (Thu, 03 Feb 2005)
New Revision: 167

Modified:
   GNUnet/src/applications/dht/module/cs.c
   GNUnet/src/applications/dht/module/datastore_dht_master.c
   GNUnet/src/applications/dht/module/datastore_memory.c
   GNUnet/src/applications/dht/module/dht.c
   GNUnet/src/applications/rpc/parameters.c
   GNUnet/src/include/gnunet_blockstore.h
   GNUnet/src/include/gnunet_dht.h
   GNUnet/src/include/gnunet_dht_service.h
   GNUnet/src/include/gnunet_rpc_service.h
Log:
dht code simplification -- no more type for put and remove

Modified: GNUnet/src/applications/dht/module/cs.c
===================================================================
--- GNUnet/src/applications/dht/module/cs.c     2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/applications/dht/module/cs.c     2005-02-03 11:37:11 UTC (rev 
167)
@@ -219,7 +219,6 @@
  */
 static int tcp_put(void * closure,
                   const HashCode160 * key,
-                  unsigned int type,
                   const DataContainer * value,
                   unsigned int prio) {
   DHT_CS_REQUEST_PUT * req;
@@ -267,7 +266,6 @@
  */
 static int tcp_del(void * closure,
                   const HashCode160 * key,
-                  unsigned int type,
                   const DataContainer * value) {
   DHT_CS_REQUEST_REMOVE * req;
   CS_TableHandlers * handlers = closure;
@@ -477,20 +475,6 @@
   FREE(record);
 }
 
-/**
- * Notification: peer 'store' agreed to store data.
- */
-static void cs_put_complete_callback(const PeerIdentity * store,
-                                    CS_PUT_RECORD * record) {
-  MUTEX_LOCK(&csLock);
-  record->replicas++;
-  MUTEX_UNLOCK(&csLock);
-  /* trigger cron-job early if replication confirmed. */
-  advanceCronJob((CronJob) &cs_put_abort,
-                0,
-                record);  
-}
-
 struct CSPutClosure {
   ClientHandle client;
   DHT_CS_REQUEST_PUT * message;
@@ -533,17 +517,12 @@
        putRecordsSize,
        putRecordsSize+1);
   putRecords[putRecordsSize-1] = ptr;
-  addCronJob((CronJob) &cs_put_abort,
-            ntohll(req->timeout),
-            0,
-            ptr);
   MUTEX_UNLOCK(&csLock);
   ptr->put_record = dhtAPI->put_start(&req->table,
                                      &req->key,
-                                     ntohl(req->type),
                                      ntohll(req->timeout),
                                      data,
-                                     (DHT_OP_Complete) 
&cs_put_complete_callback,
+                                     (DHT_OP_Complete) &cs_put_abort,
                                      ptr);
   FREE(data);
   FREE(req);
@@ -596,20 +575,6 @@
   FREE(record);
 }
 
-/**
- * Notification: peer 'store' agreed to store data.
- */
-static void cs_remove_complete_callback(const PeerIdentity * store,
-                                       CS_REMOVE_RECORD * record) {
-  MUTEX_LOCK(&csLock);
-  record->replicas++;
-  MUTEX_UNLOCK(&csLock);
-  /* trigger cron-job early if remove confirmed. */
-  advanceCronJob((CronJob) &cs_remove_abort,
-                0,
-                record);
-}
-
 struct CSRemoveClosure {
   ClientHandle client;
   DHT_CS_REQUEST_REMOVE * message;
@@ -646,10 +611,6 @@
   ptr->replicas = 0;
   ptr->table = req->table;
   ptr->remove_record = NULL;
-  addCronJob((CronJob) &cs_remove_abort,
-            ntohll(req->timeout),
-            0,
-            ptr);
   MUTEX_LOCK(&csLock);
   GROW(removeRecords,
        removeRecordsSize,
@@ -658,10 +619,9 @@
   MUTEX_UNLOCK(&csLock);
   ptr->remove_record = dhtAPI->remove_start(&req->table,
                                            &req->key,
-                                           ntohl(req->type),
                                            ntohll(req->timeout),
                                            data,
-                                           (DHT_OP_Complete) 
&cs_remove_complete_callback,
+                                           (DHT_OP_Complete) &cs_remove_abort,
                                            ptr);
   FREE(req);
   FREE(data);
@@ -758,16 +718,6 @@
   FREE(record);
 }
 
-/**
- * Notification: peer 'get' operation complete (or timeout)
- */
-static void cs_get_complete_callback(const PeerIdentity * peer,
-                                    CS_GET_RECORD * record) {
-  advanceCronJob((CronJob) &cs_get_abort,
-                0,
-                record);  
-}
-
 struct CSGetClosure {
   ClientHandle client;
   DHT_CS_REQUEST_GET * message;
@@ -793,10 +743,6 @@
   ptr->table = req->table;
   ptr->get_record = NULL;
 
-  addCronJob((CronJob) &cs_get_abort,
-            ntohll(req->timeout),
-            0,
-            ptr);
   MUTEX_LOCK(&csLock);
   GROW(getRecords,
        getRecordsSize,
@@ -810,7 +756,7 @@
                                      ntohll(req->timeout),
                                      (DataProcessor) &cs_get_result_callback,
                                      ptr,
-                                     (DHT_OP_Complete) 
&cs_get_complete_callback,
+                                     (DHT_OP_Complete) &cs_get_abort,
                                      ptr);
   return OK;
 }

Modified: GNUnet/src/applications/dht/module/datastore_dht_master.c
===================================================================
--- GNUnet/src/applications/dht/module/datastore_dht_master.c   2005-02-03 
10:56:27 UTC (rev 166)
+++ GNUnet/src/applications/dht/module/datastore_dht_master.c   2005-02-03 
11:37:11 UTC (rev 167)
@@ -30,7 +30,7 @@
  * timed-out after a certain time of inactivity.  Also,
  * duplicate entries are removed.<p>
  *
- * The type and priorities are ignored, except in get where
+ * The priorities are ignored, except in get where
  * the priority is the maximum number of results to return.
  * The number of keys specified in a GET must always be one.
  */
@@ -143,7 +143,6 @@
  */
 static int store(void * closure,
                 const HashCode160 * key,
-                unsigned int type,
                 const DataContainer * value,
                 unsigned int prio) {
   MemoryDatastore * ds = (MemoryDatastore*) closure;
@@ -212,7 +211,6 @@
  */
 static int ds_remove(void * closure,
                     const HashCode160 * key,
-                    unsigned int type,
                     const DataContainer * value) {
   MemoryDatastore * ds = (MemoryDatastore*) closure;
   HT_Entry * pos;

Modified: GNUnet/src/applications/dht/module/datastore_memory.c
===================================================================
--- GNUnet/src/applications/dht/module/datastore_memory.c       2005-02-03 
10:56:27 UTC (rev 166)
+++ GNUnet/src/applications/dht/module/datastore_memory.c       2005-02-03 
11:37:11 UTC (rev 167)
@@ -111,7 +111,6 @@
  */
 static int store(void * closure,
                 const HashCode160 * key,
-                unsigned int type,
                 const DataContainer * value,
                 unsigned int prio) {
   MemoryDatastore * ds = (MemoryDatastore*) closure;
@@ -173,7 +172,6 @@
  */
 static int ds_remove(void * closure,
                     const HashCode160 * key,
-                    unsigned int type,
                     const DataContainer * value) {
   MemoryDatastore * ds = closure;
   HT_Entry * pos;

Modified: GNUnet/src/applications/dht/module/dht.c
===================================================================
--- GNUnet/src/applications/dht/module/dht.c    2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/applications/dht/module/dht.c    2005-02-03 11:37:11 UTC (rev 
167)
@@ -1,5 +1,6 @@
  /*
       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
@@ -35,17 +36,9 @@
  * Todo:
  * 1) document (lots!)
  *   
- * Issues to investigate:
- * 1) put: to ensure we hit the replication level with reasonable
- *    precision, we must only store data locally if we're in the
- *    k-best peers for the datum by our best estimate (verify!)
- * 2) put: check consistency between table-replication level
- *    and the user-specified replication level!
- * 
  * Desirable features:
- * 1) error handling: how to communicate errors (RPC vs. DHT errors)
- * 2) security: how to pick priorities?  Access rights? 
- * 3) performance: add optional HELO messages
+ * 1) security: how to pick priorities?  Access rights? 
+ * 2) performance: add optional HELO messages
  */
 
 #include "platform.h"
@@ -69,8 +62,7 @@
 #endif
 
 /**
- * Number of replications for the master table.  At maximum since
- * that table is quite important.
+ * Number of replications / parallel requests.
  */
 #define ALPHA 7
 
@@ -2313,7 +2305,6 @@
 static struct DHT_PUT_RECORD * 
 dht_put_async_start(const DHT_TableId * table,
                    const HashCode160 * key,
-                   unsigned int type, /* REMOVE! */
                    cron_t timeout,
                    const DataContainer * value,
                    DHT_OP_Complete callback,
@@ -2404,7 +2395,6 @@
                             &hosts[i])) {
        if (OK == ltd->store->put(ltd->store->closure,
                                  key,
-                                 type,
                                  value,
                                  0 /* FIXME: priority */)) 
          ret->confirmed_stores++;
@@ -2595,7 +2585,6 @@
 static struct DHT_REMOVE_RECORD * 
 dht_remove_async_start(const DHT_TableId * table,
                       const HashCode160 * key,
-                      unsigned int type,
                       cron_t timeout,
                       const DataContainer * value,
                       DHT_OP_Complete callback,
@@ -2662,7 +2651,6 @@
                             &hosts[i])) {
        if (OK == ltd->store->del(ltd->store->closure,
                                  key,
-                                 type,
                                  value)) 
          ret->confirmed_stores++;
        break;
@@ -2765,7 +2753,6 @@
   cls->puts[cls->putsPos] 
     = dht_put_async_start(&cls->table,
                          key,
-                         0, /* FIXME: type */
                          cls->timeout,
                          value,
                          NULL,
@@ -2838,7 +2825,6 @@
           sizeof(PeerIdentity));
     remRec = dht_remove_async_start(&masterTableId,
                                    table,
-                                   0, /* FIXME: type */
                                    timeout,
                                    value,
                                    NULL,
@@ -3214,7 +3200,6 @@
   fw_context->put_record 
     = dht_put_async_start(table,
                          key,
-                         0, /* FIXME: type */
                          ntohll(*timeout),
                          value,
                          (DHT_OP_Complete) &rpc_dht_store_callback,
@@ -3343,7 +3328,6 @@
   fw_context->remove_record 
     = dht_remove_async_start(table,
                             key,
-                            0, /* FIXME, type */
                             ntohll(*timeout),
                             value,
                             (DHT_OP_Complete) &rpc_dht_remove_callback,
@@ -3477,7 +3461,6 @@
       putRecords[putRecordsSize-1] 
        = dht_put_async_start(&masterTableId,
                              &tables[i].id,
-                             0, /* FIXME: type */
                              DHT_MAINTAIN_BUCKET_FREQUENCY,
                              value,
                              NULL,

Modified: GNUnet/src/applications/rpc/parameters.c
===================================================================
--- GNUnet/src/applications/rpc/parameters.c    2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/applications/rpc/parameters.c    2005-02-03 11:37:11 UTC (rev 
167)
@@ -223,6 +223,38 @@
 
 
 /**
+ * Add a new parameter to the RPC parameter structure. The parameter name and
+ * value are copied to memory private to the RPC parameter collection. The
+ * pointers returned by other functions point to this private memory and should
+ * not be freed by the user of the abstraction.
+ *
+ * @param param Target RPC parameter structure
+ * @param name Name of the parameter
+ * @param dataLength Length of the value of the parameter
+ * @param data Value of the parameter
+ */
+void RPC_paramAddDataContainer(RPC_Param *param, 
+                              const char *name,
+                              const DataContainer * data) {
+  Parameter * new;
+
+  if (param == NULL)
+    return;
+  new = MALLOC(sizeof(Parameter));
+  new->name = STRDUP(name);
+  new->dataLength = ntohl(data->size) - sizeof(DataContainer);
+  if (dataLength == 0) {
+    new->data = NULL;
+  } else {
+    new->data = MALLOC(new->dataLength);
+    memcpy(new->data, 
+          &data[1], 
+          new->dataLength);
+  }
+  vectorInsertLast(param, new);
+}
+
+/**
  * Return the name of the given parameter in the RPC parameter structure, the
  * first parameter being parameter number zero.
  *
@@ -272,6 +304,38 @@
 }
 
 /**
+ * Return the value of the named parameter in the RPC parameter structure.
+ *
+ * @param param Target RPC parameter structure
+ * @param value set to the value of the named parameter
+ * @return SYSERR on error
+ */
+DataContainer * RPC_paramDataContainerByName(RPC_Param *param,
+                                            const char *name) {
+  Parameter * p;
+  DataContainer * ret;
+
+  if (param == NULL)
+    return NULL;
+  p = vectorGetFirst (param);
+  while (p != NULL) {
+    if (!strcmp (p->name, name)) {
+      ret = MALLOC(sizeof(DataContainer)
+                  + p->dataLength);
+      ret->size = htonl(sizeof(DataContainer)
+                       + p->dataLength);
+      memcpy(&ret[1],
+            p->data,
+            p->dataLength);
+      return ret;
+    }
+    p = vectorGetNext(param);
+  }
+                     
+  return NULL;
+}
+
+/**
  * Return the value of the given parameter in the RPC parameter structure.
  *
  * @param param Target RPC parameter structure
@@ -294,5 +358,33 @@
   return SYSERR;
 }
 
+/**
+ * Return the value of the given parameter in the RPC parameter structure.
+ *
+ * @param param Target RPC parameter structure
+ * @param value set to the value of the parameter
+ */
+DataContainer *
+RPC_paramDataContainerByPosition(RPC_Param *param, 
+                                unsigned int i) {
+  Parameter * p;
+  DataContainer * ret;
+ 
+  if (param == NULL)
+    return NULL;
+  p = vectorGetAt(param, i);
+  if (p != NULL) {
+    ret = MALLOC(sizeof(DataContainer)
+                + p->dataLength);
+    ret->size = htonl(sizeof(DataContainer)
+                     + p->dataLength);
+    memcpy(&ret[1],
+          p->data,
+          p->dataLength);
+    return ret;
+  }
+  return NULL;
+}
+
 /* end of parameters.c */
 

Modified: GNUnet/src/include/gnunet_blockstore.h
===================================================================
--- GNUnet/src/include/gnunet_blockstore.h      2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/include/gnunet_blockstore.h      2005-02-03 11:37:11 UTC (rev 
167)
@@ -106,7 +106,6 @@
    */
   int (*put)(void * closure,
             const HashCode160 * key,
-            unsigned int type,
             const DataContainer * value,
             unsigned int prio);
 
@@ -119,7 +118,6 @@
    */
   int (*del)(void * closure,
             const HashCode160 * key,
-            unsigned int type,
             const DataContainer * value);
 
   /**

Modified: GNUnet/src/include/gnunet_dht.h
===================================================================
--- GNUnet/src/include/gnunet_dht.h     2005-02-03 10:56:27 UTC (rev 166)
+++ GNUnet/src/include/gnunet_dht.h     2005-02-03 11:37:11 UTC (rev 167)
@@ -94,8 +94,6 @@
   
   HashCode160 key;
 
-  unsigned int type; /* nbo */
-
   unsigned int priority; /* nbo */
 
 } DHT_CS_REQUEST_PUT;
@@ -144,8 +142,6 @@
   
   unsigned long long timeout; /* nbo */
 
-  unsigned int type; /* nbo */
-
   HashCode160 key;
 
 } DHT_CS_REQUEST_REMOVE;

Modified: GNUnet/src/include/gnunet_dht_service.h
===================================================================
--- GNUnet/src/include/gnunet_dht_service.h     2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/include/gnunet_dht_service.h     2005-02-03 11:37:11 UTC (rev 
167)
@@ -42,10 +42,9 @@
 struct DHT_REMOVE_RECORD;
 
 /**
- * @param peer identity of a peer that acknowledged the request
+ * DHT operation 'complete' (i.e timed out)
  */
-typedef void (*DHT_OP_Complete)(const PeerIdentity * peer,
-                               void * closure);
+typedef void (*DHT_OP_Complete)(void * closure);
 
 /**
  * Functions of the DHT Service API.
@@ -127,7 +126,6 @@
    */
   struct DHT_PUT_RECORD * (*put_start)(const DHT_TableId * table,
                                       const HashCode160 * key,
-                                      unsigned int type,
                                       cron_t timeout,
                                       const DataContainer * value,
                                       DHT_OP_Complete callback,
@@ -154,7 +152,6 @@
    */
   struct DHT_REMOVE_RECORD * (*remove_start)(const DHT_TableId * table,
                                             const HashCode160 * key,
-                                            unsigned int type,
                                             cron_t timeout,
                                             const DataContainer * value,
                                             DHT_OP_Complete callback,

Modified: GNUnet/src/include/gnunet_rpc_service.h
===================================================================
--- GNUnet/src/include/gnunet_rpc_service.h     2005-02-03 10:56:27 UTC (rev 
166)
+++ GNUnet/src/include/gnunet_rpc_service.h     2005-02-03 11:37:11 UTC (rev 
167)
@@ -28,8 +28,8 @@
 
 #include "gnunet_util.h"
 #include "gnunet_core.h"
+#include "gnunet_blockstore.h"
 
-
 /**
  * The function was called successfully and the return values
  * are included in the message.
@@ -190,6 +190,10 @@
                  unsigned int dataLength, 
                  const void * data);
 
+void RPC_paramAddDataContainer(RPC_Param * param, 
+                              const char * name, 
+                              const DataContainer * data);
+
 const char * RPC_paramName(RPC_Param * param,
                           unsigned int i);
 
@@ -213,6 +217,27 @@
                             void ** data);
 
 /**
+ * Return the value of the given parameter in the RPC parameter structure.
+ *
+ * @param param Target RPC parameter structure
+ * @param value set to the value of the parameter
+ */
+DataContainer *
+RPC_paramDataContainerByPosition(RPC_Param *param, 
+                                unsigned int i);
+
+/**
+ * Return the value of the named parameter in the RPC parameter
+ * structure.
+ *
+ * @param param Target RPC parameter structure
+ * @param value set to the value of the named parameter
+ * @return SYSERR on error
+ */
+DataContainer * RPC_paramDataContainerByName(RPC_Param *param,
+                                            const char *name);
+
+/**
  * Serialize the param array.  target must point to at least
  * RPC_paramSize(param) bytes of memory.
  */





reply via email to

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