gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r10803 - gnunet/src/dht
Date: Mon, 5 Apr 2010 21:40:07 +0200

Author: nevans
Date: 2010-04-05 21:40:07 +0200 (Mon, 05 Apr 2010)
New Revision: 10803

Modified:
   gnunet/src/dht/Makefile.am
   gnunet/src/dht/dht_api.c
   gnunet/src/dht/gnunet-service-dht.c
   gnunet/src/dht/test_dht_api.c
Log:
basic find peer functionality, added to test_dht_api testcase

Modified: gnunet/src/dht/Makefile.am
===================================================================
--- gnunet/src/dht/Makefile.am  2010-04-05 18:41:41 UTC (rev 10802)
+++ gnunet/src/dht/Makefile.am  2010-04-05 19:40:07 UTC (rev 10803)
@@ -31,6 +31,8 @@
 gnunet_service_dht_LDADD = \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/core/libgnunetcore.la \
+  $(top_builddir)/src/transport/libgnunettransport.la \
+  $(top_builddir)/src/hello/libgnunethello.la \
   $(top_builddir)/src/datacache/libgnunetdatacache.la \
   $(top_builddir)/src/util/libgnunetutil.la 
 

Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c    2010-04-05 18:41:41 UTC (rev 10802)
+++ gnunet/src/dht/dht_api.c    2010-04-05 19:40:07 UTC (rev 10803)
@@ -662,6 +662,10 @@
   size_t data_size;
   struct GNUNET_MessageHeader *result_data;
 
+#if DEBUG_DHT_API
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Find peer iterator called.\n");
+#endif
   if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
     return;
 
@@ -670,7 +674,7 @@
   result = (struct GNUNET_DHT_FindPeerResultMessage *) reply;
   data_size = ntohs (result->data_size);
   GNUNET_assert (ntohs (reply->size) ==
-                 sizeof (struct GNUNET_DHT_GetResultMessage) + data_size);
+                 sizeof (struct GNUNET_DHT_FindPeerResultMessage) + data_size);
 
   if (data_size > 0)
     result_data = (struct GNUNET_MessageHeader *) &result[1];   /* Set data 
pointer to end of message */

Modified: gnunet/src/dht/gnunet-service-dht.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht.c 2010-04-05 18:41:41 UTC (rev 10802)
+++ gnunet/src/dht/gnunet-service-dht.c 2010-04-05 19:40:07 UTC (rev 10803)
@@ -35,6 +35,8 @@
 #include "gnunet_signal_lib.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_datacache_lib.h"
+#include "gnunet_transport_service.h"
+#include "gnunet_hello_lib.h"
 #include "dht.h"
 
 /**
@@ -63,11 +65,21 @@
 static struct GNUNET_CORE_Handle *coreAPI;
 
 /**
+ * Handle to the transport service, for getting our hello
+ */
+static struct GNUNET_TRANSPORT_Handle *transport_handle;
+
+/**
  * The identity of our peer.
  */
 static struct GNUNET_PeerIdentity my_identity;
 
 /**
+ * Our HELLO
+ */
+static struct GNUNET_MessageHeader *my_hello;
+
+/**
  * Task to run when we shut down, cleaning up all our trash
  */
 static GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
@@ -395,7 +407,6 @@
 
   pending_message = GNUNET_malloc (sizeof (struct PendingMessage));
   pending_message->msg = &reply->header;
-  pending_message->next = NULL; /* We insert at the end of the list */
 
   add_pending_message (client, pending_message);
 }
@@ -506,6 +517,9 @@
 handle_dht_find_peer (void *cls, struct GNUNET_DHT_FindPeerMessage *find_msg,
                       struct DHT_MessageContext *message_context)
 {
+  struct GNUNET_DHT_FindPeerResultMessage *find_peer_result;
+  size_t hello_size;
+  size_t tsize;
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "`%s': Received `%s' request from client, key %s (msg size %d, 
we expected %d)\n",
@@ -517,6 +531,29 @@
   GNUNET_assert (ntohs (find_msg->header.size) >=
                  sizeof (struct GNUNET_DHT_FindPeerMessage));
 
+  if (my_hello == NULL)
+  {
+#if DEBUG_DHT
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "`%s': Our HELLO is null, can't return.\n",
+                "DHT");
+#endif
+
+    return;
+  }
+
+  /* Simplistic find_peer functionality, always return our hello */
+  hello_size = ntohs(my_hello->size);
+  tsize = hello_size + sizeof (struct GNUNET_DHT_FindPeerResultMessage);
+  find_peer_result = GNUNET_malloc (tsize);
+  find_peer_result->header.type = htons 
(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT);
+  find_peer_result->header.size = htons (tsize);
+  find_peer_result->data_size = htons (hello_size);
+  memcpy(&find_peer_result->peer, &my_identity, sizeof(struct 
GNUNET_PeerIdentity));
+  memcpy (&find_peer_result[1], &my_hello, hello_size);
+
+  send_reply_to_client(message_context->client, &find_peer_result->header, 
message_context->unique_id);
+
   /* FIXME: Implement find peer functionality here */
 }
 
@@ -784,7 +821,30 @@
   return GNUNET_YES;
 }
 
+
 /**
+ * Receive the HELLO from transport service,
+ * free current and replace if necessary.
+ *
+ * @param cls NULL
+ * @param message HELLO message of peer
+ */
+static void
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+{
+#if DEBUG_DHT
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received our `%s' from transport service\n",
+              "HELLO");
+#endif
+
+  GNUNET_assert (message != NULL);
+  GNUNET_free_non_null(my_hello);
+  my_hello = GNUNET_malloc(ntohs(message->size));
+  memcpy(my_hello, message, ntohs(message->size));
+}
+
+/**
  * Task run during shutdown.
  *
  * @param cls unused
@@ -793,9 +853,16 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (transport_handle != NULL)
+  {
+    GNUNET_free_non_null(my_hello);
+    GNUNET_TRANSPORT_get_hello_cancel(transport_handle, &process_hello, NULL);
+    GNUNET_TRANSPORT_disconnect(transport_handle);
+  }
   GNUNET_CORE_disconnect (coreAPI);
 }
 
+
 /**
  * To be called on core init/fail.
  *
@@ -828,6 +895,7 @@
   coreAPI = server;
 }
 
+
 /**
  * Process dht requests.
  *
@@ -865,6 +933,14 @@
                                  GNUNET_NO,     /* For header only outbound 
notification */
                                  core_handlers);        /* Register these 
handlers */
 
+  transport_handle = GNUNET_TRANSPORT_connect(sched, cfg, NULL, NULL, NULL, 
NULL);
+
+  if (transport_handle != NULL)
+    GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL);
+  else
+    GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to connect to transport 
service!\n");
+
+
   if (coreAPI == NULL)
     return;
 

Modified: gnunet/src/dht/test_dht_api.c
===================================================================
--- gnunet/src/dht/test_dht_api.c       2010-04-05 18:41:41 UTC (rev 10802)
+++ gnunet/src/dht/test_dht_api.c       2010-04-05 19:40:07 UTC (rev 10803)
@@ -147,7 +147,29 @@
 
 }
 
+
 /**
+ * Iterator called on each result obtained from a find peer
+ * operation
+ *
+ * @param cls closure (NULL)
+ * @param peer the peer we learned about
+ * @param reply response
+ */
+void test_find_peer_processor (void *cls,
+                          const struct GNUNET_PeerIdentity *peer,
+                          const struct GNUNET_MessageHeader *reply)
+{
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "test_find_peer_processor called (peer `%s'), stopping find peer 
request!\n", GNUNET_i2s(peer));
+
+  GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1,
+                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
+/**
  * Signature of the main function of a task.
  *
  * @param cls closure
@@ -165,7 +187,7 @@
 
   peer->find_peer_handle =
     GNUNET_DHT_find_peer_start (peer->dht_handle, TIMEOUT, 0, NULL, &hash,
-                                NULL, NULL, &test_find_peer_stop, &p1);
+                                &test_find_peer_processor, NULL, NULL, NULL);
 
   if (peer->find_peer_handle == NULL)
     GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);





reply via email to

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