gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10636 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r10636 - gnunet/src/dht
Date: Wed, 17 Mar 2010 18:19:30 +0100

Author: nevans
Date: 2010-03-17 18:19:30 +0100 (Wed, 17 Mar 2010)
New Revision: 10636

Modified:
   gnunet/src/dht/dht.h
   gnunet/src/dht/dht_api.c
   gnunet/src/dht/gnunet-service-dht.c
   gnunet/src/dht/test_dht_api.c
   gnunet/src/dht/test_dht_api_peer1.conf
Log:
beginning of changes

Modified: gnunet/src/dht/dht.h
===================================================================
--- gnunet/src/dht/dht.h        2010-03-17 15:41:07 UTC (rev 10635)
+++ gnunet/src/dht/dht.h        2010-03-17 17:19:30 UTC (rev 10636)
@@ -33,6 +33,43 @@
                                                   struct GNUNET_MessageHeader 
*msg);
 
 /**
+ * Generic DHT message, wrapper for other message types
+ */
+struct GNUNET_DHT_Message
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_DHT_MESSAGE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * The key to search for
+   */
+  GNUNET_HashCode key;
+
+  /**
+   * Replication level for this message
+   */
+  uint16_t desired_replication_level;
+
+  /**
+   * Message options
+   */
+  uint16_t options;
+
+  /**
+   * Is this message uniquely identified?  If so it has
+   * a unique_id appended to it.
+   */
+  /* uint16_t unique; I don't think we need this, it should be held in the 
encapsulated message */
+
+  /* uint64_t unique_id*/
+  /* */
+  /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy 
do */
+
+};
+
+/**
  * Message to insert data into the DHT
  */
 struct GNUNET_DHT_PutMessage
@@ -48,11 +85,6 @@
   size_t type;
 
   /**
-   * The key to insert data under.
-   */
-  GNUNET_HashCode key;
-
-  /**
    * The size of the data, appended to the end of this message.
    */
   size_t data_size;
@@ -60,7 +92,7 @@
   /**
    * How long should this data persist?
    */
-  struct GNUNET_TIME_Relative timeout;
+  struct GNUNET_TIME_Absolute expiration;
 
 };
 
@@ -115,32 +147,44 @@
 };
 
 /**
- * Response to PUT request from the DHT
+ * Message to request data from the DHT
  */
-struct GNUNET_DHT_PutResultMessage
+struct GNUNET_DHT_FindPeerMessage
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_DHT_PUT_RESULT
+   * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * The type for the data for the GET request
+   * The key being looked up
    */
-  size_t type;
+  GNUNET_HashCode key;
 
+};
+
+/**
+ * Message to return data from the DHT
+ */
+struct GNUNET_DHT_FindPeerResultMessage
+{
   /**
-   * The key to search for
+   * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT
    */
-  GNUNET_HashCode key;
+  struct GNUNET_MessageHeader header;
 
   /**
-   * Was the put successful?  GNUNET_YES or GNUNET_NO
+   * The peer that was searched for
    */
-  size_t result;
+  struct GNUNET_PeerIdentity peer;
 
+  /**
+   * The size of the HELLO for the returned peer,
+   * appended to the end of this message, 0 if
+   * no hello.
+   */
+  size_t data_size;
+
 };
 
-
-
 #endif /* DHT_H_ */

Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c    2010-03-17 15:41:07 UTC (rev 10635)
+++ gnunet/src/dht/dht_api.c    2010-03-17 17:19:30 UTC (rev 10636)
@@ -135,11 +135,14 @@
  *
  * @param cfg configuration to use
  * @param sched scheduler to use
+ * @param ht_len size of the internal hash table to use for
+ *               processing multiple GET/FIND requests in parallel
  * @return NULL on error
  */
 struct GNUNET_DHT_Handle *
 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
-                    const struct GNUNET_CONFIGURATION_Handle *cfg)
+                    const struct GNUNET_CONFIGURATION_Handle *cfg,
+                    unsigned int ht_len)
 {
   struct GNUNET_DHT_Handle *handle;
 
@@ -233,6 +236,11 @@
    * Closure for the iterator callback
    */
   void *iter_cls;
+
+  /**
+   * Main handle to this DHT api
+   */
+  struct GNUNET_DHT_Handle *dht_handle;
 };
 
 /**
@@ -303,7 +311,6 @@
 transmit_pending (void *cls, size_t size, void *buf)
 {
   struct GNUNET_DHT_Handle *handle = cls;
-  size_t ret;
   size_t tsize;
 
   if (buf == NULL)
@@ -318,7 +325,6 @@
     }
 
   handle->th = NULL;
-  ret = 0;
 
   if (handle->current != NULL)
   {
@@ -330,14 +336,15 @@
                   "`%s': Sending message size %d\n", "DHT API", tsize);
 #endif
       memcpy(buf, handle->current->msg, tsize);
+      return tsize;
     }
     else
     {
-      return ret;
+      return 0;
     }
   }
-
-  return ret;
+  /* Have no pending request */
+  return 0;
 }
 
 
@@ -483,6 +490,10 @@
   get_handle->iter = iter;
   get_handle->iter_cls = iter_cls;
 
+#if DEBUG_DHT_API
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "`%s': Inserting pending get request with key %s\n", "DHT API", 
GNUNET_h2s(key));
+#endif
   GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, 
get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
 
   get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage));
@@ -503,9 +514,10 @@
  * @param record GET operation to stop.
  */
 void
-GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct 
GNUNET_DHT_GetHandle *get_handle)
+GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
 {
   struct GNUNET_DHT_GetMessage *get_msg;
+  struct GNUNET_DHT_Handle *handle;
 
   if (handle->do_destroy == GNUNET_NO)
     {
@@ -517,7 +529,10 @@
 
       add_pending(handle, &get_msg->header);
     }
-
+#if DEBUG_DHT_API
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "`%s': Removing pending get request with key %s\n", "DHT API", 
GNUNET_h2s(&get_handle->key));
+#endif
   
GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests,
 &get_handle->key, get_handle) == GNUNET_YES);
   GNUNET_free(get_handle);
 }
@@ -539,14 +554,16 @@
  *
  * @return GNUNET_YES if put message is queued for transmission
  */
-int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
-                    const GNUNET_HashCode * key,
-                    uint32_t type,
-                    uint32_t size,
-                    const char *data,
-                    struct GNUNET_TIME_Relative exp,
-                    GNUNET_SCHEDULER_Task cont,
-                    void *cont_cls)
+void
+GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
+                const GNUNET_HashCode * key,
+                uint32_t type,
+                uint32_t size,
+                const char *data,
+                struct GNUNET_TIME_Absolute exp,
+                struct GNUNET_TIME_Relative timeout,
+                GNUNET_SCHEDULER_Task cont,
+                void *cont_cls)
 {
   struct GNUNET_DHT_PutMessage *put_msg;
   struct GNUNET_DHT_PutHandle *put_handle;
@@ -560,13 +577,18 @@
        * A put has been previously queued, but not yet sent.
        * FIXME: change the continuation function and callback or something?
        */
-      return GNUNET_NO;
+      return;
     }
 
   put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle));
   put_handle->type = type;
   memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode));
 
+#if DEBUG_DHT_API
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "`%s': Inserting pending put request with key %s\n", "DHT API", 
GNUNET_h2s(key));
+#endif
+
   GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, 
put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
 
   msize = sizeof(struct GNUNET_DHT_PutMessage) + size;
@@ -579,5 +601,5 @@
 
   add_pending(handle, &put_msg->header);
 
-  return GNUNET_YES;
+  return;
 }

Modified: gnunet/src/dht/gnunet-service-dht.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht.c 2010-03-17 15:41:07 UTC (rev 10635)
+++ gnunet/src/dht/gnunet-service-dht.c 2010-03-17 17:19:30 UTC (rev 10636)
@@ -167,13 +167,23 @@
  * Server handler for initiating local dht get requests
  */
 static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client,
-                     const struct GNUNET_MessageHeader *message)
+                            const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage 
*)message;
+  GNUNET_HashCode get_key;
+  size_t get_type;
+
+  GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct 
GNUNET_DHT_GetMessage));
+  memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode));
+  get_type = ntohs(get_msg->type);
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "`%s': Received `%s' request from client\n", "DHT", "GET");
+              "`%s': Received `%s' request from client, message type %d, key 
%s\n", "DHT", "GET", get_type, GNUNET_h2s(&get_key));
 #endif
 
+  /* FIXME: Implement get stop functionality here */
+
 }
 
 /**
@@ -182,25 +192,43 @@
 static void handle_dht_get_stop (void *cls, struct GNUNET_SERVER_Client * 
client,
                           const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage 
*)message; /* Get message and get stop message are the same except for type */
+  GNUNET_HashCode get_key;
+  size_t get_type;
+
+  GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct 
GNUNET_DHT_GetMessage));
+
+  memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode));
+  get_type = ntohs(get_msg->type);
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "`%s': Received `%s' request from client\n", "DHT", "GET STOP");
+              "`%s': Received `%s' request from client, message type %d, key 
%s\n", "DHT", "GET STOP", get_type, GNUNET_h2s(&get_key));
 #endif
 
+  /* FIXME: Implement get stop functionality here */
+
 }
 
 /**
  * Server handler for initiating local dht find peer requests
  */
 static void handle_dht_find_peer (void *cls, struct GNUNET_SERVER_Client *
-                           client, const struct GNUNET_MessageHeader *
-                           message)
+                                  client, const struct GNUNET_MessageHeader *
+                                  message)
 {
+  struct GNUNET_DHT_FindPeerMessage *find_msg = (struct 
GNUNET_DHT_FindPeerMessage *)message;
+  struct GNUNET_PeerIdentity peer;
+
+  GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct 
GNUNET_DHT_FindPeerMessage));
+  memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity));
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "`%s': Received `%s' request from client\n", "DHT", "FIND PEER");
+              "`%s': Received `%s' request from client, peer id %s\n", "DHT", 
"FIND PEER", GNUNET_i2s(&peer));
 #endif
 
+  /* FIXME: Implement find peer functionality here */
 }
 
 /**
@@ -210,11 +238,19 @@
                            client, const struct GNUNET_MessageHeader *
                            message)
 {
+  struct GNUNET_DHT_FindPeerMessage *find_msg = (struct 
GNUNET_DHT_FindPeerMessage *)message; /* Find peer stop message is identical to 
find peer message */
+  struct GNUNET_PeerIdentity peer;
+
+  GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct 
GNUNET_DHT_FindPeerMessage));
+  memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity));
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "`%s': Received `%s' request from client\n", "DHT", "FIND PEER 
STOP");
+              "`%s': Received `%s' request from client, for peer id %s\n", 
"DHT", "FIND PEER STOP", GNUNET_i2s(&peer));
 #endif
 
+  /* FIXME: Implement find peer stop functionality here */
+
 }
 
 /**
@@ -223,21 +259,42 @@
 static void handle_dht_put (void *cls, struct GNUNET_SERVER_Client * client,
                      const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_DHT_PutMessage *put_msg = (struct GNUNET_DHT_PutMessage 
*)message;
+  GNUNET_HashCode put_key;
+  size_t put_type;
+  size_t data_size;
+  char *data;
+
+  GNUNET_assert(ntohs(put_msg->header.size) >= sizeof(struct 
GNUNET_DHT_PutMessage));
+
+  memcpy(&put_key, &put_msg->key, sizeof(GNUNET_HashCode));
+  put_type = ntohs(put_msg->type);
+  data_size = ntohs(put_msg->data_size);
+  GNUNET_assert(ntohs(put_msg->header.size) == sizeof(struct 
GNUNET_DHT_PutMessage) + data_size);
+  data = GNUNET_malloc(data_size);
+  memcpy(data, &put_msg[1], data_size);
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "`%s': Received `%s' request from client\n", "DHT", "PUT");
+              "`%s': Received `%s' request from client, message type %d, key 
%s\n", "DHT", "PUT", put_type, GNUNET_h2s(&put_key));
 #endif
 
+  /**
+   * FIXME: Implement dht put request functionality here!
+   */
+
+  GNUNET_free(data);
+
 }
 
 /**
  * Core handler for p2p dht get requests.
  */
 static int handle_dht_p2p_get (void *cls,
-                             const struct GNUNET_PeerIdentity * peer,
-                             const struct GNUNET_MessageHeader * message,
-                             struct GNUNET_TIME_Relative latency,
-                             uint32_t distance)
+                               const struct GNUNET_PeerIdentity * peer,
+                               const struct GNUNET_MessageHeader * message,
+                               struct GNUNET_TIME_Relative latency,
+                               uint32_t distance)
 {
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -340,23 +397,22 @@
   GNUNET_SERVER_add_handlers (server, plugin_handlers);
 
   coreAPI =
-  GNUNET_CORE_connect (sched,
-                       cfg,
-                       client_transmit_timeout,
+  GNUNET_CORE_connect (sched, /* Main scheduler */
+                       cfg,   /* Main configuration */
+                       client_transmit_timeout, /* Delay for connecting */
                        NULL, /* FIXME: anything we want to pass around? */
-                       &core_init,
+                       &core_init, /* Call core_init once connected */
                        NULL, /* Don't care about pre-connects */
                        NULL, /* Don't care about connects */
                        NULL, /* Don't care about disconnects */
-                       NULL,
-                       GNUNET_NO,
-                       NULL,
-                       GNUNET_NO,
-                       core_handlers);
+                       NULL, /* Don't want notified about all incoming 
messages */
+                       GNUNET_NO, /* For header only inbound notification */
+                       NULL, /* Don't want notified about all outbound 
messages */
+                       GNUNET_NO, /* For header only outbound notification */
+                       core_handlers); /* Register these handlers */
 
   if (coreAPI == NULL)
     return;
-  /* load (server); Huh? */
 
   /* Scheduled the task to clean up when shutdown is called */
   cleanup_task = GNUNET_SCHEDULER_add_delayed (sched,

Modified: gnunet/src/dht/test_dht_api.c
===================================================================
--- gnunet/src/dht/test_dht_api.c       2010-03-17 15:41:07 UTC (rev 10635)
+++ gnunet/src/dht/test_dht_api.c       2010-03-17 17:19:30 UTC (rev 10636)
@@ -51,6 +51,9 @@
   struct GNUNET_CONFIGURATION_Handle *cfg;
   struct GNUNET_DHT_Handle *dht_handle;
   struct GNUNET_PeerIdentity id;
+  struct GNUNET_DHT_GetHandle *get_handle;
+  struct GNUNET_DHT_GetHandle *find_peer_handle;
+
 #if START_ARM
   pid_t arm_pid;
 #endif
@@ -110,12 +113,60 @@
   return;
 }
 
+
 /**
  * Signature of the main function of a task.
  *
  * @param cls closure
  * @param tc context information (why was this task triggered now)
  */
+void test_put (void *cls,
+               const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+  struct PeerContext *peer = cls;
+  GNUNET_HashCode hash;
+  char *data;
+  size_t data_size = 42;
+  memset(&hash, 42, sizeof(GNUNET_HashCode));
+  data = GNUNET_malloc(data_size);
+  memset(data, 43, data_size);
+
+  GNUNET_assert (peer->dht_handle != NULL);
+
+  GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), NULL, NULL);
+
+  //GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
+
+  GNUNET_SCHEDULER_add_now(sched, &end, NULL);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void test_get_stop (void *cls,
+               const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+  struct PeerContext *peer = cls;
+  GNUNET_HashCode hash;
+  memset(&hash, 42, sizeof(GNUNET_HashCode));
+
+  GNUNET_assert (peer->dht_handle != NULL);
+
+  GNUNET_DHT_get_stop(peer->dht_handle, peer->get_handle);
+
+  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
+
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
 void test_get (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
@@ -126,9 +177,12 @@
   peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg);
   GNUNET_assert (peer->dht_handle != NULL);
 
-  GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL);
+  peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, 
NULL);
 
-  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &end, &p1);
+  if (peer->get_handle == NULL)
+    GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1);
+
+  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, 
&p1);
 }
 
 static void
@@ -162,7 +216,7 @@
 
   setup_peer (&p1, "test_dht_api_peer1.conf");
 
-  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &test_get, &p1);
+  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1);
 }
 
 static int

Modified: gnunet/src/dht/test_dht_api_peer1.conf
===================================================================
--- gnunet/src/dht/test_dht_api_peer1.conf      2010-03-17 15:41:07 UTC (rev 
10635)
+++ gnunet/src/dht/test_dht_api_peer1.conf      2010-03-17 17:19:30 UTC (rev 
10636)
@@ -31,8 +31,9 @@
 ACCEPT_FROM6 = ::1;
 ACCEPT_FROM = 127.0.0.1;
 BINARY = gnunet-service-dht
-#BINARY = 
/root/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht
+#BINARY = 
/home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht
 #PREFIX = xterm -T dvservice -e gdb --args
+OPTIONS=""
 CONFIG = $DEFAULTCONFIG
 HOME = $SERVICEHOME
 HOSTNAME = localhost





reply via email to

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