gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated (09d0b535d -> 9f03df3be)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (09d0b535d -> 9f03df3be)
Date: Sat, 01 Jun 2019 00:58:46 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository gnunet.

    from 09d0b535d Change and improved comments.
     new 47a7c12c4 stash
     new 9f03df3be improve performance of identity_api_lookup.c logic to not be 
O(n)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/identity/gnunet-service-identity.c |  63 +++++++++++-
 src/identity/identity.h                |  48 +++++++--
 src/identity/identity_api.c            |  40 +-------
 src/identity/identity_api_lookup.c     | 173 ++++++++++++++++++++++----------
 src/identity/test_identity.c           | 152 ++++++++++++----------------
 src/identity/test_identity_defaults.c  | 175 +++++++++++++++++----------------
 src/include/gnunet_protocols.h         |   8 ++
 7 files changed, 388 insertions(+), 271 deletions(-)

diff --git a/src/identity/gnunet-service-identity.c 
b/src/identity/gnunet-service-identity.c
index 0a2fbbcb8..a675a01f0 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -291,16 +291,15 @@ create_set_default_message (struct Ego *ego,
  * adds the client to the notification context for future
  * updates.
  *
- * @param cls unused
- * @param client who sent the message
+ * @param cls a `struct GNUNET_SERVICE_Client *`
  * @param message the message received
  */
 static void
 handle_start_message (void *cls,
                       const struct GNUNET_MessageHeader *message)
 {
-  struct UpdateMessage *ume;
   struct GNUNET_SERVICE_Client *client = cls;
+  struct UpdateMessage *ume;
   struct GNUNET_MQ_Envelope *env;
   struct Ego *ego;
 
@@ -324,6 +323,60 @@ handle_start_message (void *cls,
   GNUNET_SERVICE_client_continue (client);
 }
 
+
+/**
+ * Handler for LOOKUP message from client, sends information
+ * about ONE identity to the client immediately.
+ *
+ * @param cls unused
+ * @param message the message received
+ * @return #GNUNET_SYSERR if message was ill-formed
+ */
+static int
+check_lookup_message (void *cls,
+                       const struct LookupMessage *message)
+{
+  GNUNET_MQ_check_zero_termination (message);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handler for LOOKUP message from client, sends information
+ * about ONE identity to the client immediately.
+ *
+ * @param cls a `struct GNUNET_SERVICE_Client *`
+ * @param message the message received
+ */
+static void
+handle_lookup_message (void *cls,
+                       const struct LookupMessage *message)
+{
+  struct GNUNET_SERVICE_Client *client = cls;
+  const char *name;
+  struct GNUNET_MQ_Envelope *env;
+  struct Ego *ego;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received LOOKUP message from client\n");
+  name = (const char *) &message[1];
+  for (ego = ego_head; NULL != ego; ego = ego->next)
+  {
+    if (0 != strcasecmp (name,
+                         ego->identifier))
+      continue;
+    env = create_update_message (ego);
+    GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
+    GNUNET_SERVICE_client_continue (client);
+    return;
+  }
+  send_result_code (client,
+                    0,
+                    "ego not found");
+  GNUNET_SERVICE_client_continue (client);
+}
+
+
 /**
  * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
  *
@@ -1061,6 +1114,10 @@ GNUNET_SERVICE_MAIN
                           GNUNET_MESSAGE_TYPE_IDENTITY_START,
                           struct GNUNET_MessageHeader,
                           NULL),
+ GNUNET_MQ_hd_var_size (lookup_message,
+                        GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
+                        struct LookupMessage,
+                        NULL),
  GNUNET_MQ_hd_var_size (get_default_message,
                         GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
                         struct GetDefaultMessage,
diff --git a/src/identity/identity.h b/src/identity/identity.h
index 7e7b5d4cd..96550bdf2 100644
--- a/src/identity/identity.h
+++ b/src/identity/identity.h
@@ -11,7 +11,7 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -53,7 +53,20 @@ struct ResultCodeMessage
   uint32_t result_code GNUNET_PACKED;
 
   /* followed by 0-terminated error message (on error) */
+};
+
 
+/**
+ * Client informs service about desire to lookup a (single) pseudonym.
+ */
+struct LookupMessage
+{
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP
+   */
+  struct GNUNET_MessageHeader header;
+
+  /* followed by 0-terminated ego name */
 };
 
 
@@ -84,11 +97,9 @@ struct UpdateMessage
   struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
 
   /* followed by 0-terminated ego name */
-
 };
 
 
-
 /**
  * Client requests knowledge about default identity for
  * a subsystem from identity service.
@@ -112,7 +123,6 @@ struct GetDefaultMessage
 
 
   /* followed by 0-terminated service name */
-
 };
 
 
@@ -143,7 +153,6 @@ struct SetDefaultMessage
   struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
 
   /* followed by 0-terminated service name */
-
 };
 
 
@@ -174,7 +183,6 @@ struct CreateRequestMessage
   struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
 
   /* followed by 0-terminated identity name */
-
 };
 
 
@@ -226,11 +234,35 @@ struct DeleteMessage
   uint16_t reserved GNUNET_PACKED;
 
   /* followed by 0-terminated name */
-
 };
 
+GNUNET_NETWORK_STRUCT_END
 
+/**
+ * Handle for an ego.
+ */
+struct GNUNET_IDENTITY_Ego
+{
+  /**
+   * Private key associated with this ego.
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
+
+  /**
+   * Current name associated with this ego.
+   */
+  char *name;
+
+  /**
+   * Client context associated with this ego.
+   */
+  void *ctx;
+
+  /**
+   * Hash of the public key of this ego.
+   */
+  struct GNUNET_HashCode id;
+};
 
-GNUNET_NETWORK_STRUCT_END
 
 #endif
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 6cf1b65ca..c463da641 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -32,32 +32,6 @@
 
 #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
 
-/**
- * Handle for an ego.
- */
-struct GNUNET_IDENTITY_Ego
-{
-  /**
-   * Private key associated with this ego.
-   */
-  struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
-
-  /**
-   * Current name associated with this ego.
-   */
-  char *name;
-
-  /**
-   * Client context associated with this ego.
-   */
-  void *ctx;
-
-  /**
-   * Hash of the public key of this ego.
-   */
-  struct GNUNET_HashCode id;
-};
-
 
 /**
  * Handle for an operation with the identity service.
@@ -298,16 +272,8 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 static int
 check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 {
-  uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm);
-  const char *str = (const char *) &rcm[1];
-
-  if (0 == size)
-    return GNUNET_OK;
-  if ('\0' != str[size - 1])
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+  if (sizeof (*rcm) != htons (rcm->header.size))
+    GNUNET_MQ_check_zero_termination (rcm);
   return GNUNET_OK;
 }
 
@@ -630,6 +596,7 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
 
   if (NULL == h->mq)
     return NULL;
+  GNUNET_assert (NULL != h->cb);
   slen = strlen (service_name) + 1;
   if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GetDefaultMessage))
   {
@@ -675,6 +642,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
 
   if (NULL == h->mq)
     return NULL;
+  GNUNET_assert (NULL != h->cb);
   slen = strlen (service_name) + 1;
   if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct SetDefaultMessage))
   {
diff --git a/src/identity/identity_api_lookup.c 
b/src/identity/identity_api_lookup.c
index 40a22c262..56ebf6f47 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.c
@@ -26,8 +26,9 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_identity_service.h"
+#include "identity.h"
 
-#define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
 
 
 /**
@@ -37,9 +38,9 @@ struct GNUNET_IDENTITY_EgoLookup
 {
 
   /**
-   * Handle to the identity service.
+   * Connection to service.
    */
-  struct GNUNET_IDENTITY_Handle *identity;
+  struct GNUNET_MQ_Handle *mq;
 
   /**
    * Name of the ego we are looking up.
@@ -59,53 +60,103 @@ struct GNUNET_IDENTITY_EgoLookup
 
 
 /**
- * Method called to inform about the egos of this peer.
+ * We received a result code from the service.  Check the message
+ * is well-formed.
  *
- * When used with #GNUNET_IDENTITY_connect, this function is
- * initially called for all egos and then again whenever a
- * ego's name changes or if it is deleted.  At the end of
- * the initial pass over all egos, the function is once called
- * with 'NULL' for @a ego. That does NOT mean that the callback won't
- * be invoked in the future or that there was an error.
- *
- * If the @a name matches the name from @a cls, we found the zone
- * for our computation and will invoke the callback.
- * If we have iterated over all egos and not found the name, we
- * invoke the callback with NULL.
+ * @param cls closure
+ * @param rcm result message received
+ * @return #GNUNET_OK if the message is well-formed
+ */
+static int
+check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
+{
+  if (sizeof (*rcm) != htons (rcm->header.size))
+    GNUNET_MQ_check_zero_termination (rcm);
+  return GNUNET_OK;
+}
+
+
+/**
+ * We received a result code from the service.
  *
- * @param cls closure with the `struct GNUNET_IDENTITY_EgoLookup`
- * @param ego ego handle
- * @param ctx context for application to store data for this ego
- *                 (during the lifetime of this process, initially NULL)
- * @param name name assigned by the user for this ego,
- *                   NULL if the user just deleted the ego and it
- *                   must thus no longer be used
+ * @param cls closure
+ * @param rcm result message received
  */
 static void
-identity_cb (void *cls,
-            struct GNUNET_IDENTITY_Ego *ego,
-            void **ctx,
-            const char *name)
+handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 {
   struct GNUNET_IDENTITY_EgoLookup *el = cls;
 
-  if ( (NULL != name) &&
-       (0 == strcmp (name,
-                    el->name)) )
-  {
-    el->cb (el->cb_cls,
-           ego);
-    GNUNET_IDENTITY_ego_lookup_cancel (el);
-    return;
-  }
-  if (NULL == ego)
+  el->cb (el->cb_cls, NULL);
+  GNUNET_IDENTITY_ego_lookup_cancel (el);
+}
+
+
+/**
+ * Check validity of identity update message.
+ *
+ * @param cls closure
+ * @param um message received
+ * @return #GNUNET_OK if the message is well-formed
+ */
+static int
+check_identity_update (void *cls, const struct UpdateMessage *um)
+{
+  uint16_t size = ntohs (um->header.size);
+  uint16_t name_len = ntohs (um->name_len);
+  const char *str = (const char *) &um[1];
+
+  if ((size != name_len + sizeof (struct UpdateMessage)) ||
+      ((0 != name_len) && ('\0' != str[name_len - 1])))
   {
-    /* not found */
-    el->cb (el->cb_cls,
-           NULL);
-    GNUNET_IDENTITY_ego_lookup_cancel (el);
-    return;
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle identity update message.
+ *
+ * @param cls closure
+ * @param um message received
+ */
+static void
+handle_identity_update (void *cls, const struct UpdateMessage *um)
+{
+  struct GNUNET_IDENTITY_EgoLookup *el = cls;
+  uint16_t name_len = ntohs (um->name_len);
+  const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
+  struct GNUNET_CRYPTO_EcdsaPublicKey pub;
+  struct GNUNET_HashCode id;
+  struct GNUNET_IDENTITY_Ego ego;
+
+  GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
+  GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
+  GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
+  ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key;
+  ego.name = (char *) str;
+  ego.id = id;
+  el->cb (el->cb_cls, &ego);
+  GNUNET_IDENTITY_ego_lookup_cancel (el);
+}
+
+
+/**
+ * Generic error handler, called with the appropriate error code and
+ * the same closure specified at the creation of the message queue.
+ * Not every message queue implementation supports an error handler.
+ *
+ * @param cls closure with the `struct GNUNET_IDENTITY_EgoLookup *`
+ * @param error error code
+ */
+static void
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
+{
+  struct GNUNET_IDENTITY_EgoLookup *el = cls;
+
+  el->cb (el->cb_cls, NULL);
 }
 
 
@@ -120,25 +171,45 @@ identity_cb (void *cls,
  */
 struct GNUNET_IDENTITY_EgoLookup *
 GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                           const char *name,
-                           GNUNET_IDENTITY_EgoCallback cb,
-                           void *cb_cls)
+                            const char *name,
+                            GNUNET_IDENTITY_EgoCallback cb,
+                            void *cb_cls)
 {
   struct GNUNET_IDENTITY_EgoLookup *el;
+  struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_MessageHeader *req;
+  size_t nlen;
 
+  GNUNET_assert (NULL != cb);
   el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup);
-  el->name = GNUNET_strdup (name);
   el->cb = cb;
   el->cb_cls = cb_cls;
-  el->identity = GNUNET_IDENTITY_connect (cfg,
-                                         &identity_cb,
-                                         el);
-  if (NULL == el->identity)
   {
-    GNUNET_free (el->name);
+    struct GNUNET_MQ_MessageHandler handlers[] =
+      {GNUNET_MQ_hd_var_size (identity_result_code,
+                              GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
+                              struct ResultCodeMessage,
+                              el),
+       GNUNET_MQ_hd_var_size (identity_update,
+                              GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
+                              struct UpdateMessage,
+                              el),
+       GNUNET_MQ_handler_end ()};
+
+    el->mq =
+      GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el);
+  }
+  if (NULL == el->mq)
+  {
+    GNUNET_break (0);
     GNUNET_free (el);
     return NULL;
   }
+  el->name = GNUNET_strdup (name);
+  nlen = strlen (name) + 1;
+  env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP);
+  memcpy (&req[1], name, nlen);
+  GNUNET_MQ_send (el->mq, env);
   return el;
 }
 
@@ -151,7 +222,7 @@ GNUNET_IDENTITY_ego_lookup (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
 void
 GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el)
 {
-  GNUNET_IDENTITY_disconnect (el->identity);
+  GNUNET_MQ_destroy (el->mq);
   GNUNET_free (el->name);
   GNUNET_free (el);
 }
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index 163394801..74c052917 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -11,7 +11,7 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -52,13 +52,25 @@ static struct GNUNET_IDENTITY_Operation *op;
  */
 static struct GNUNET_SCHEDULER_Task *endbadly_task;
 
+#define CHECK(cond)     \
+  do                    \
+  {                     \
+    if (! (cond))       \
+    {                   \
+      GNUNET_break (0); \
+      end ();           \
+      return;           \
+    }                   \
+  } while (0)
+
 
 /**
  * Clean up all resources used.
  */
 static void
-cleanup ()
+cleanup (void *cls)
 {
+  (void) cls;
   if (NULL != op)
   {
     GNUNET_IDENTITY_cancel (op);
@@ -69,7 +81,6 @@ cleanup ()
     GNUNET_IDENTITY_disconnect (h);
     h = NULL;
   }
-  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -81,21 +92,7 @@ cleanup ()
 static void
 endbadly (void *cls)
 {
-  cleanup ();
-  res = 1;
-}
-
-
-/**
- * Termiante the testcase (success).
- *
- * @param cls NULL
- */
-static void
-end_normally (void *cls)
-{
-  cleanup ();
-  res = 0;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -127,9 +124,9 @@ end ()
  */
 static void
 notification_cb (void *cls,
-                struct GNUNET_IDENTITY_Ego *ego,
-                void **ctx,
-                const char *identifier)
+                 struct GNUNET_IDENTITY_Ego *ego,
+                 void **ctx,
+                 const char *identifier)
 {
   static struct GNUNET_IDENTITY_Ego *my_ego;
   static int round;
@@ -137,45 +134,45 @@ notification_cb (void *cls,
   switch (round)
   {
   case 0: /* end of initial iteration */
-    GNUNET_assert (NULL == ego);
-    GNUNET_assert (NULL == identifier);
+    CHECK (NULL == ego);
+    CHECK (NULL == identifier);
     break;
   case 1: /* create */
-    GNUNET_assert (NULL != ego);
-    GNUNET_assert (0 == strcmp (identifier,
-                                "test-id"));
+    CHECK (NULL != ego);
+    CHECK (NULL != identifier);
+    CHECK (0 == strcmp (identifier, "test-id"));
     my_ego = ego;
     *ctx = &round;
     break;
   case 2: /* rename */
-    GNUNET_assert (my_ego == ego);
-    GNUNET_assert (0 == strcmp (identifier,
-                                "test"));
-    GNUNET_assert (*ctx == &round);
+    CHECK (my_ego == ego);
+    CHECK (NULL != identifier);
+    CHECK (0 == strcmp (identifier, "test"));
+    CHECK (*ctx == &round);
     break;
   case 3: /* reconnect-down */
-    GNUNET_assert (my_ego == ego);
-    GNUNET_assert (NULL == identifier);
-    GNUNET_assert (*ctx == &round);
+    CHECK (my_ego == ego);
+    CHECK (NULL == identifier);
+    CHECK (*ctx == &round);
     *ctx = NULL;
     break;
   case 4: /* reconnect-up */
-    GNUNET_assert (0 == strcmp (identifier,
-                                "test"));
+    CHECK (NULL != identifier);
+    CHECK (0 == strcmp (identifier, "test"));
     my_ego = ego;
     *ctx = &round;
     break;
   case 5: /* end of iteration after reconnect */
-    GNUNET_assert (NULL == ego);
-    GNUNET_assert (NULL == identifier);
+    CHECK (NULL == ego);
+    CHECK (NULL == identifier);
     break;
   case 6: /* delete */
-    GNUNET_assert (my_ego == ego);
-    GNUNET_assert (*ctx == &round);
+    CHECK (my_ego == ego);
+    CHECK (*ctx == &round);
     *ctx = NULL;
     break;
   default:
-    GNUNET_break (0);
+    CHECK (0);
   }
   round++;
 }
@@ -188,11 +185,11 @@ notification_cb (void *cls,
  * @param emsg (should also be NULL)
  */
 static void
-delete_cont (void *cls,
-            const char *emsg)
+delete_cont (void *cls, const char *emsg)
 {
   op = NULL;
-  GNUNET_assert (NULL == emsg);
+  CHECK (NULL == emsg);
+  res = 0;
   end ();
 }
 
@@ -205,10 +202,7 @@ delete_cont (void *cls,
 static void
 finally_delete (void *cls)
 {
-  op = GNUNET_IDENTITY_delete (h,
-                              "test",
-                              &delete_cont,
-                              NULL);
+  op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL);
 }
 
 
@@ -219,10 +213,9 @@ finally_delete (void *cls)
  * @param emsg (should also be NULL)
  */
 static void
-fail_rename_cont (void *cls,
-                 const char *emsg)
+fail_rename_cont (void *cls, const char *emsg)
 {
-  GNUNET_assert (NULL != emsg);
+  CHECK (NULL != emsg);
   op = NULL;
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                 &finally_delete,
@@ -237,15 +230,10 @@ fail_rename_cont (void *cls,
  * @param emsg (should also be NULL)
  */
 static void
-success_rename_cont (void *cls,
-                    const char *emsg)
+success_rename_cont (void *cls, const char *emsg)
 {
-  GNUNET_assert (NULL == emsg);
-  op = GNUNET_IDENTITY_rename (h,
-                              "test-id",
-                              "test",
-                              &fail_rename_cont,
-                              NULL);
+  CHECK (NULL == emsg);
+  op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL);
 }
 
 
@@ -258,16 +246,13 @@ success_rename_cont (void *cls,
  */
 static void
 create_cb (void *cls,
-          const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
-          const char *emsg)
+           const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
+           const char *emsg)
 {
-  GNUNET_assert (NULL != pk);
-  GNUNET_assert (NULL == emsg);
-  op = GNUNET_IDENTITY_rename (h,
-                              "test-id",
-                              "test",
-                              &success_rename_cont,
-                              NULL);
+  CHECK (NULL != pk);
+  CHECK (NULL == emsg);
+  op =
+    GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL);
 }
 
 
@@ -283,35 +268,26 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly,
-                                                NULL);
-  GNUNET_SCHEDULER_add_shutdown (&end_normally,
-                                 NULL);
-  h = GNUNET_IDENTITY_connect (cfg,
-                               &notification_cb,
-                               NULL);
-  GNUNET_assert (NULL != h);
-  op = GNUNET_IDENTITY_create (h,
-                              "test-id",
-                              &create_cb,
-                              NULL);
-
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
+  h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
+  CHECK (NULL != h);
+  op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
 }
 
 
 int
 main (int argc, char *argv[])
 {
-  GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
+  GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
   res = 1;
-  if (0 !=
-      GNUNET_TESTING_service_run ("test-identity",
-                                 "identity",
-                                 "test_identity.conf",
-                                 &run,
-                                 NULL))
+  if (0 != GNUNET_TESTING_service_run ("test-identity",
+                                       "identity",
+                                       "test_identity.conf",
+                                       &run,
+                                       NULL))
     return 1;
+  GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
   return res;
 }
 
diff --git a/src/identity/test_identity_defaults.c 
b/src/identity/test_identity_defaults.c
index bcd75e84c..71e70e7ba 100644
--- a/src/identity/test_identity_defaults.c
+++ b/src/identity/test_identity_defaults.c
@@ -11,7 +11,7 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -50,15 +50,27 @@ static struct GNUNET_IDENTITY_Operation *op;
 /**
  * Handle for task for timeout termination.
  */
-static struct GNUNET_SCHEDULER_Task * endbadly_task;
+static struct GNUNET_SCHEDULER_Task *endbadly_task;
+
+#define CHECK(cond)     \
+  do                    \
+  {                     \
+    if (! (cond))       \
+    {                   \
+      GNUNET_break (0); \
+      end ();           \
+      return;           \
+    }                   \
+  } while (0)
 
 
 /**
  * Clean up all resources used.
  */
 static void
-cleanup ()
+cleanup (void *cls)
 {
+  (void) cls;
   if (NULL != op)
   {
     GNUNET_IDENTITY_cancel (op);
@@ -69,7 +81,6 @@ cleanup ()
     GNUNET_IDENTITY_disconnect (h);
     h = NULL;
   }
-  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -81,37 +92,23 @@ cleanup ()
 static void
 endbadly (void *cls)
 {
-  cleanup ();
+  GNUNET_SCHEDULER_shutdown ();
   res = 1;
 }
 
 
 /**
- * Termiante the testcase (success).
- *
- * @param cls NULL
- */
-static void
-end_normally (void *cls)
-{
-  cleanup ();
-  res = 0;
-}
-
-
-/**
- * Finish the testcase (successfully).
+ * Termiante the testcase.
  */
 static void
 end ()
 {
-  if (endbadly_task != NULL)
+  if (NULL != endbadly_task)
   {
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = NULL;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
-                               &end_normally, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -122,11 +119,11 @@ end ()
  * @param emsg (should also be NULL)
  */
 static void
-delete_cont (void *cls,
-            const char *emsg)
+delete_cont (void *cls, const char *emsg)
 {
   op = NULL;
-  GNUNET_assert (NULL == emsg);
+  CHECK (NULL == emsg);
+  res = 0;
   end ();
 }
 
@@ -139,17 +136,39 @@ delete_cont (void *cls,
  */
 static void
 get_cb (void *cls,
-       struct GNUNET_IDENTITY_Ego *ego,
-       void **ctx,
-       const char *identifier)
+        struct GNUNET_IDENTITY_Ego *ego,
+        void **ctx,
+        const char *identifier)
+{
+  op = NULL;
+  CHECK (NULL != ego);
+  CHECK (NULL != identifier);
+  CHECK (0 == strcmp (identifier, "test-id"));
+  op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL);
+}
+
+
+/**
+ * Called with events about egos.
+ *
+ * @param cls NULL
+ * @param ego ego handle
+ * @param ego_ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param identifier identifier assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
+ */
+static void
+dummy_cb (void *cls,
+          struct GNUNET_IDENTITY_Ego *ego,
+          void **ctx,
+          const char *identifier)
 {
-  GNUNET_assert (NULL != ego);
-  GNUNET_assert (NULL != identifier);
-  GNUNET_assert (0 == strcmp (identifier, "test-id"));
-  op = GNUNET_IDENTITY_delete (h,
-                              "test-id",
-                              &delete_cont,
-                              NULL);
+  (void) cls;
+  (void) ego;
+  (void) ctx;
+  (void) identifier;
 }
 
 
@@ -162,17 +181,14 @@ get_cb (void *cls,
  */
 static void
 run_get (void *cls,
-        const struct GNUNET_CONFIGURATION_Handle *cfg,
-        struct GNUNET_TESTING_Peer *peer)
+         const struct GNUNET_CONFIGURATION_Handle *cfg,
+         struct GNUNET_TESTING_Peer *peer)
 {
-  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
-  GNUNET_assert (NULL != h);
-  op = GNUNET_IDENTITY_get (h,
-                           "test-service",
-                           &get_cb,
-                           NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
+  h = GNUNET_IDENTITY_connect (cfg, &dummy_cb, NULL);
+  CHECK (NULL != h);
+  op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL);
 }
 
 
@@ -183,11 +199,10 @@ run_get (void *cls,
  * @param emsg (should also be NULL)
  */
 static void
-success_set_cont (void *cls,
-                 const char *emsg)
+success_set_cont (void *cls, const char *emsg)
 {
   op = NULL;
-  GNUNET_assert (NULL == emsg);
+  CHECK (NULL == emsg);
   end ();
 }
 
@@ -205,19 +220,15 @@ success_set_cont (void *cls,
  */
 static void
 notification_cb (void *cls,
-                struct GNUNET_IDENTITY_Ego *ego,
-                void **ctx,
-                const char *identifier)
+                 struct GNUNET_IDENTITY_Ego *ego,
+                 void **ctx,
+                 const char *identifier)
 {
   if (NULL == ego)
     return; /* skip first call */
   if (NULL == identifier)
     return; /* deletion / shutdown */
-  op = GNUNET_IDENTITY_set (h,
-                           "test-service",
-                           ego,
-                           &success_set_cont,
-                           NULL);
+  op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL);
 }
 
 
@@ -230,11 +241,11 @@ notification_cb (void *cls,
  */
 static void
 create_cb (void *cls,
-          const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
-          const char *emsg)
+           const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
+           const char *emsg)
 {
-  GNUNET_assert (NULL == emsg);
-  GNUNET_assert (NULL != pk);
+  CHECK (NULL == emsg);
+  CHECK (NULL != pk);
   op = NULL;
 }
 
@@ -248,43 +259,37 @@ create_cb (void *cls,
  */
 static void
 run_set (void *cls,
-        const struct GNUNET_CONFIGURATION_Handle *cfg,
-        struct GNUNET_TESTING_Peer *peer)
+         const struct GNUNET_CONFIGURATION_Handle *cfg,
+         struct GNUNET_TESTING_Peer *peer)
 {
-  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
   h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
-  GNUNET_assert (NULL != h);
-  op = GNUNET_IDENTITY_create (h,
-                              "test-id",
-                              &create_cb,
-                              NULL);
-
+  CHECK (NULL != h);
+  op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
 }
 
 
 int
 main (int argc, char *argv[])
 {
-  GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
+  GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
   res = 1;
-  if (0 !=
-      GNUNET_TESTING_service_run ("test-identity-defaults",
-                                 "identity",
-                                 "test_identity.conf",
-                                 &run_set,
-                                 NULL))
+  if (0 != GNUNET_TESTING_service_run ("test-identity-defaults",
+                                       "identity",
+                                       "test_identity.conf",
+                                       &run_set,
+                                       NULL))
     return 1;
-  if (0 !=
-      GNUNET_TESTING_service_run ("test-identity-defaults",
-                                 "identity",
-                                 "test_identity.conf",
-                                 &run_get,
-                                 NULL))
+  if (0 != GNUNET_TESTING_service_run ("test-identity-defaults",
+                                       "identity",
+                                       "test_identity.conf",
+                                       &run_get,
+                                       NULL))
     return 1;
-  GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
+  GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
   return res;
 }
 
 
-/* end of test_identity.c */
+/* end of test_identity_defaults.c */
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 73da40038..a00ddacca 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1940,6 +1940,14 @@ extern "C" {
  */
 #define GNUNET_MESSAGE_TYPE_IDENTITY_DELETE 631
 
+/**
+ * First message send from identity client to service to
+ * lookup a single ego.  The service will respond with a
+ * #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE message if the ego
+ * exists, or a #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE if not.
+ */
+#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP 632
+
 
 
/*******************************************************************************
  * REVOCATION message types

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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