gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19948 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r19948 - gnunet/src/namestore
Date: Wed, 22 Feb 2012 19:05:18 +0100

Author: wachs
Date: 2012-02-22 19:05:18 +0100 (Wed, 22 Feb 2012)
New Revision: 19948

Modified:
   gnunet/src/namestore/gnunet-service-namestore.c
   gnunet/src/namestore/namestore.h
   gnunet/src/namestore/namestore_api.c
   gnunet/src/namestore/test_namestore_api.c
Log:
- more code


Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-02-22 17:49:55 UTC 
(rev 19947)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-02-22 18:05:18 UTC 
(rev 19948)
@@ -54,12 +54,37 @@
   GNUNET_free (db_lib_name);
 }
 
-static void handle_start ()
+/**
+ * Called whenever a client is disconnected.  Frees our
+ * resources associated with that client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ */
+static void
+client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "START");
+  if (NULL != client)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
 }
 
+static void handle_start (void *cls,
+                          struct GNUNET_SERVER_Client * client,
+                          const struct GNUNET_MessageHeader * message)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n");
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
 
+static void handle_lookup_name (void *cls,
+                          struct GNUNET_SERVER_Client * client,
+                          const struct GNUNET_MessageHeader * message)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 
"NAMESTORE_LOOKUP_NAME");
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
 /**
  * Process template requests.
  *
@@ -78,6 +103,8 @@
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_start, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
+    {&handle_lookup_name, NULL,
+     GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
     {NULL, NULL, 0, 0}
   };
 
@@ -98,6 +125,9 @@
 
   /* Configuring server handles */
   GNUNET_SERVER_add_handlers (server, handlers);
+  GNUNET_SERVER_disconnect_notify (server,
+                                   &client_disconnect_notification,
+                                   NULL);
 
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
                                 NULL);

Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h    2012-02-22 17:49:55 UTC (rev 19947)
+++ gnunet/src/namestore/namestore.h    2012-02-22 18:05:18 UTC (rev 19948)
@@ -26,10 +26,14 @@
 #ifndef NAMESTORE_H
 #define NAMESTORE_H
 
+/*
+ * Collect message types here, move to protocols later
+ */
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431
+
 GNUNET_NETWORK_STRUCT_BEGIN
 /**
- * Change in blacklisting (either request or notification,
- * depending on which direction it is going).
+ * Connect to namestore service
  */
 struct StartMessage
 {
@@ -42,5 +46,21 @@
 };
 GNUNET_NETWORK_STRUCT_END
 
+GNUNET_NETWORK_STRUCT_BEGIN
+/**
+ * Connect to namestore service
+ */
+struct LookupNameMessage
+{
+
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME
+   */
+  struct GNUNET_MessageHeader header;
+
+};
+GNUNET_NETWORK_STRUCT_END
+
+
 /* end of namestore.h */
 #endif

Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c        2012-02-22 17:49:55 UTC (rev 
19947)
+++ gnunet/src/namestore/namestore_api.c        2012-02-22 18:05:18 UTC (rev 
19948)
@@ -248,6 +248,7 @@
     return;
   if (NULL == nsh->client)
     return;                     /* currently reconnecting */
+
   nsh->th = GNUNET_CLIENT_notify_transmit_ready (nsh->client, p->size,
                                            GNUNET_TIME_UNIT_FOREVER_REL,
                                            GNUNET_NO, 
&transmit_message_to_namestore,
@@ -579,7 +580,7 @@
  *         cancel
  */
 struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *h, 
+GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *nsh,
                               const GNUNET_HashCode *zone,
                               const char *name,
                               uint32_t record_type,
@@ -601,6 +602,22 @@
   proc(proc_cls, zone, name, record_type,
        GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/
 #endif
+
+  GNUNET_assert (NULL != nsh);
+
+  struct PendingMessage * p;
+  struct LookupNameMessage * msg;
+  size_t msg_len = sizeof (struct LookupNameMessage);
+
+  p = GNUNET_malloc (sizeof (struct PendingMessage) + msg_len);
+  p->size = msg_len;
+  p->is_init = GNUNET_NO;
+  msg = (struct LookupNameMessage *) &p[1];
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
+  msg->header.size = htons (msg_len);
+  GNUNET_CONTAINER_DLL_insert (nsh->pending_head, nsh->pending_tail, p);
+  do_transmit (nsh);
+
   return qe;
 }
 

Modified: gnunet/src/namestore/test_namestore_api.c
===================================================================
--- gnunet/src/namestore/test_namestore_api.c   2012-02-22 17:49:55 UTC (rev 
19947)
+++ gnunet/src/namestore/test_namestore_api.c   2012-02-22 18:05:18 UTC (rev 
19948)
@@ -72,8 +72,13 @@
 static void
 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (nsh != NULL)
+    GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+  nsh = NULL;
+
   if (NULL != arm)
     stop_arm();
+
   res = 1;
 }
 
@@ -87,6 +92,11 @@
     endbadly_task = GNUNET_SCHEDULER_NO_TASK;
   }
 
+  if (nsh != NULL)
+    GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+  nsh = NULL;
+
+
   if (NULL != arm)
     stop_arm();
 
@@ -105,8 +115,9 @@
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
-  GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
 
+  GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL);
+
   //stop_arm ();
   //end ();
   res = 0;




reply via email to

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