gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r20005 - gnunet/src/namestore
Date: Fri, 24 Feb 2012 14:49:26 +0100

Author: wachs
Date: 2012-02-24 14:49:26 +0100 (Fri, 24 Feb 2012)
New Revision: 20005

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:
- communication


Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-02-24 12:43:42 UTC 
(rev 20004)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-02-24 13:49:26 UTC 
(rev 20005)
@@ -69,6 +69,11 @@
 
 static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
 
+/**
+ * Our notification context.
+ */
+static struct GNUNET_SERVER_NotificationContext *snc;
+
 static char *db_lib_name;
 
 static struct GNUNET_NAMESTORE_Client *client_head;
@@ -101,10 +106,29 @@
   GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
   GNUNET_free (nc);
 
+  GNUNET_SERVER_notification_context_destroy (snc);
+  snc = NULL;
+
   GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
   GNUNET_free (db_lib_name);
 }
 
+static struct GNUNET_NAMESTORE_Client *
+client_lookup (struct GNUNET_SERVER_Client *client)
+{
+  struct GNUNET_NAMESTORE_Client * nc;
+
+  GNUNET_assert (NULL != client);
+
+  for (nc = client_head; nc != NULL; nc = nc->next)
+  {
+    if (client == nc->client)
+      break;
+  }
+  return nc;
+}
+
+
 /**
  * Called whenever a client is disconnected.  Frees our
  * resources associated with that client.
@@ -122,12 +146,9 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
 
-  for (nc = client_head; nc != NULL; nc = nc->next)
-  {
-    if (client == nc->client)
-      break;
-  }
-  if (NULL == client)
+  nc = client_lookup (client);
+
+  if ((NULL == client) || (NULL == nc))
     return;
 
   for (no = nc->op_head; no != NULL; no = no->next)
@@ -144,11 +165,11 @@
                           struct GNUNET_SERVER_Client * client,
                           const struct GNUNET_MessageHeader * message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
 
   struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct 
GNUNET_NAMESTORE_Client));
   nc->client = client;
-
+  GNUNET_SERVER_notification_context_add (snc, client);
   GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -159,6 +180,33 @@
                           const struct GNUNET_MessageHeader * message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 
"NAMESTORE_LOOKUP_NAME");
+
+  struct GNUNET_NAMESTORE_Client *nc;
+  uint32_t id = 0;
+  size_t r_size = 0;
+
+  nc = client_lookup(client);
+  if (nc == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
+  id = ntohl (ln_msg->op_id);
+
+  /* do the actual lookup */
+
+  /* send response */
+  struct LookupNameResponseMessage lnr_msg;
+  r_size = sizeof (struct LookupNameResponseMessage);
+
+  lnr_msg.header.type = ntohs 
(GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
+  lnr_msg.header.size = ntohs (r_size);
+  lnr_msg.op_id = htonl (id);
+
+  GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct 
GNUNET_MessageHeader *) &lnr_msg, GNUNET_NO);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -182,7 +230,7 @@
     {&handle_start, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
     {&handle_lookup_name, NULL,
-     GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
+     GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, sizeof (struct 
LookupNameMessage)},
     {NULL, NULL, 0, 0}
   };
 
@@ -203,6 +251,7 @@
 
   /* Configuring server handles */
   GNUNET_SERVER_add_handlers (server, handlers);
+  snc = GNUNET_SERVER_notification_context_create (server, 16);
   GNUNET_SERVER_disconnect_notify (server,
                                    &client_disconnect_notification,
                                    NULL);

Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h    2012-02-24 12:43:42 UTC (rev 20004)
+++ gnunet/src/namestore/namestore.h    2012-02-24 13:49:26 UTC (rev 20005)
@@ -30,6 +30,7 @@
  * Collect message types here, move to protocols later
  */
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432
 
 GNUNET_NETWORK_STRUCT_BEGIN
 /**
@@ -46,21 +47,61 @@
 };
 GNUNET_NETWORK_STRUCT_END
 
+
 GNUNET_NETWORK_STRUCT_BEGIN
 /**
+ * Generic namestore message with op id
+ */
+struct GenericMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
+};
+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;
 
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
 };
 GNUNET_NETWORK_STRUCT_END
 
+GNUNET_NETWORK_STRUCT_BEGIN
 
+struct LookupNameResponseMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
+};
+
+
+GNUNET_NETWORK_STRUCT_END
+
+
 /* end of namestore.h */
 #endif

Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c        2012-02-24 12:43:42 UTC (rev 
20004)
+++ gnunet/src/namestore/namestore_api.c        2012-02-24 13:49:26 UTC (rev 
20005)
@@ -45,7 +45,7 @@
 
   struct GNUNET_NAMESTORE_Handle *nsh;
 
-  uint64_t op_id;
+  uint32_t op_id;
 
   GNUNET_NAMESTORE_ContinuationWithStatus cont;
   void *cont_cls;
@@ -148,7 +148,7 @@
   struct GNUNET_NAMESTORE_QueueEntry * op_head;
   struct GNUNET_NAMESTORE_QueueEntry * op_tail;
 
-  uint64_t op_id;
+  uint32_t op_id;
 
   /**
    * Pending namestore zone iterator entries
@@ -187,7 +187,37 @@
 static void
 force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh);
 
+static void
+handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
+                             struct LookupNameResponseMessage * msg,
+                             size_t size)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
+              "LOOKUP_NAME_RESPONSE");
 
+  struct GNUNET_NAMESTORE_Handle *nsh = qe->nsh;
+
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key = NULL;
+  struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get_forever();
+  const char *name = "";
+  unsigned int rd_count = 0;
+  const struct GNUNET_NAMESTORE_RecordData *rd = NULL;
+  const struct GNUNET_CRYPTO_RsaSignature *signature = NULL;
+
+  /* TODO: extract real values */
+
+  /* Lookup complete, remove queue entry */
+  GNUNET_CONTAINER_DLL_remove (nsh->op_head, nsh->op_tail, qe);
+
+  /* Notify */
+  if (qe->proc != NULL)
+    qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature);
+
+  GNUNET_free (qe);
+
+}
+
+
 /**
  * Type of a function to call when we receive a message
  * from the service.
@@ -199,10 +229,11 @@
 process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_NAMESTORE_Handle *nsh = cls;
+  struct GenericMessage * gm;
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   uint16_t size;
   uint16_t type;
-  uint64_t op_id = UINT64_MAX;
+  uint32_t op_id = UINT32_MAX;
 
   if (NULL == msg)
   {
@@ -213,9 +244,23 @@
   size = ntohs (msg->size);
   type = ntohs (msg->type);
 
-  /* find matching operation */
+  if (size < sizeof (struct GenericMessage))
+  {
+    GNUNET_break_op (0);
+    GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    return;
+  }
+
+  gm = (struct GenericMessage *) msg;
+  op_id = ntohl (gm->op_id);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %i size %i op 
%u\n", type, size, op_id);
+
+  /* Find matching operation */
   if (op_id > nsh->op_id)
   {
+    /* No matching pending operation found */
     GNUNET_break_op (0);
     GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
                            GNUNET_TIME_UNIT_FOREVER_REL);
@@ -228,20 +273,23 @@
   }
   if (qe == NULL)
   {
+    /* No matching pending operation found */
     GNUNET_break_op (0);
     GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
                            GNUNET_TIME_UNIT_FOREVER_REL);
     return;
   }
 
+  /* handle different message type */
   switch (type) {
-    case GNUNET_MESSAGE_TYPE_TEST:
-      /* handle message here */
+    case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE:
+        handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) 
msg, size);
       break;
     default:
+      GNUNET_break_op (0);
       break;
   }
-  size++; // FIXME: just working around compiler warning here...
+
   GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
                          GNUNET_TIME_UNIT_FOREVER_REL);
 
@@ -387,12 +435,12 @@
                                     nsh);
 }
 
-static void
-enqeue_namestore_operation (struct GNUNET_NAMESTORE_Handle *nsh, struct 
GNUNET_NAMESTORE_QueueEntry *qe)
+static uint32_t
+get_op_id (struct GNUNET_NAMESTORE_Handle *nsh)
 {
-  qe->op_id = nsh->op_id;
+  uint32_t op_id = nsh->op_id;
   nsh->op_id ++;
-  GNUNET_CONTAINER_DLL_insert(nsh->op_head, nsh->op_tail, qe);
+  return op_id;
 }
 
 /**
@@ -492,14 +540,16 @@
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct PendingMessage *pe;
   size_t msg_size = 0;
+  uint32_t id = 0;
 
   GNUNET_assert (NULL != h);
-
+  id = get_op_id(h);
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
   qe->nsh = h;
   qe->cont = cont;
   qe->cont_cls = cont_cls;
-  enqeue_namestore_operation(h, qe);
+  qe->op_id = id;
+  GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe);
 
   /* set msg_size*/
   pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
@@ -576,7 +626,7 @@
   qe->nsh = h;
   qe->cont = cont;
   qe->cont_cls = cont_cls;
-  enqeue_namestore_operation(h, qe);
+  get_op_id(h);
 
   /* set msg_size*/
   pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
@@ -622,7 +672,7 @@
   qe->nsh = h;
   qe->cont = cont;
   qe->cont_cls = cont_cls;
-  enqeue_namestore_operation(h, qe);
+  get_op_id(h);
 
   /* set msg_size*/
   pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
@@ -674,50 +724,34 @@
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct PendingMessage *pe;
   size_t msg_size = 0;
+  uint32_t id = 0;
 
   GNUNET_assert (NULL != h);
-
+  id = get_op_id(h);
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
   qe->nsh = h;
   qe->proc = proc;
   qe->proc_cls = proc_cls;
-  enqeue_namestore_operation(h, qe);
+  qe->op_id = id;
+  GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe);
 
   /* set msg_size*/
   msg_size = sizeof (struct LookupNameMessage);
   pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
 
   /* create msg here */
-
   struct LookupNameMessage * msg;
   pe->size = msg_size;
   pe->is_init = GNUNET_NO;
   msg = (struct LookupNameMessage *) &pe[1];
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
   msg->header.size = htons (msg_size);
+  msg->op_id = htonl (id);
 
-  /* create msg done */
-
+  /* transmit message */
   GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
   do_transmit(h);
 
-#if 0
-  struct GNUNET_NAMESTORE_SimpleRecord *iter;
-  for (iter=h->records_head; iter != NULL; iter=iter->next)
-  {
-    proc(proc_cls, iter->zone, iter->name, iter->record_type,
-       iter->expiration,
-       iter->flags,
-       NULL /*sig loc*/,
-       iter->data_size /*size*/,
-       iter->data /* data */);
-  }
-  proc(proc_cls, zone, name, record_type,
-       GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/
-#endif
-
-
-
   return qe;
 }
 

Modified: gnunet/src/namestore/test_namestore_api.c
===================================================================
--- gnunet/src/namestore/test_namestore_api.c   2012-02-24 12:43:42 UTC (rev 
20004)
+++ gnunet/src/namestore/test_namestore_api.c   2012-02-24 13:49:26 UTC (rev 
20005)
@@ -82,9 +82,9 @@
   res = 1;
 }
 
-/*
+
 static void
-end (void)
+end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
   {
@@ -102,9 +102,20 @@
 
   res = 0;
 }
-*/
 
 
+void name_lookup_proc (void *cls,
+                            const struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                            struct GNUNET_TIME_Absolute expire,
+                            const char *name,
+                            unsigned int rd_count,
+                            const struct GNUNET_NAMESTORE_RecordData *rd,
+                            const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+  res = 0;
+  GNUNET_SCHEDULER_add_now(&end, NULL);
+}
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -117,11 +128,7 @@
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
 
-  //GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL);
-
-  //stop_arm ();
-  //end ();
-  res = 0;
+  GNUNET_NAMESTORE_lookup_record (nsh, NULL, NULL, 0, &name_lookup_proc, NULL);
 }
 
 static int




reply via email to

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