gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27295 - gnunet/src/experimentation


From: gnunet
Subject: [GNUnet-SVN] r27295 - gnunet/src/experimentation
Date: Fri, 24 May 2013 16:21:16 +0200

Author: wachs
Date: 2013-05-24 16:21:16 +0200 (Fri, 24 May 2013)
New Revision: 27295

Modified:
   gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
Log:
experiments


Modified: gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c      
2013-05-24 13:35:02 UTC (rev 27294)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c      
2013-05-24 14:21:16 UTC (rev 27295)
@@ -34,6 +34,7 @@
 struct Experiment
 {
        /* Header */
+       char *name;
 
        /* Experiment issuer */
        struct GNUNET_PeerIdentity issuer;
@@ -52,17 +53,61 @@
        /* TBD */
 };
 
+struct Issuer
+{
+       struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+};
+
 /**
  * Hashmap containing valid experiment issuer
  */
 static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
 
-void
-GNUNET_EXPERIMENTATION_experiments_verify ()
+/**
+ * Hashmap containing valid experiments
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *experiments;
+
+/**
+ * Verify experiment signature
+ *
+ * @param i issuer
+ * @param e experiment
+ * @return GNUNET_OK or GNUNET_SYSERR
+ */
+
+int
+experiment_verify (struct Issuer *i, struct Experiment *e)
 {
+       GNUNET_assert (NULL != i);
+       GNUNET_assert (NULL != e);
 
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Verification: to be 
implemented\n");
+       return GNUNET_OK;
 }
 
+int free_experiment (void *cls,
+                                                                               
 const struct GNUNET_HashCode * key,
+                                                                               
 void *value)
+{
+       struct Experiment *e = value;
+       GNUNET_CONTAINER_multihashmap_remove (experiments, key, value);
+       GNUNET_free_non_null (e->description);
+       GNUNET_free_non_null (e->name);
+       GNUNET_free (e);
+       return GNUNET_OK;
+}
+
+int free_issuer (void *cls,
+                                                                const struct 
GNUNET_HashCode * key,
+                                                                void *value)
+{
+       struct Issuer *i = value;
+       GNUNET_CONTAINER_multihashmap_remove (valid_issuers, key, value);
+       GNUNET_free (i);
+       return GNUNET_OK;
+}
+
 /**
  * Is peer a valid issuer
  *
@@ -77,6 +122,7 @@
                return GNUNET_NO;
 }
 
+
 void exp_file_iterator (void *cls,
                                                                                
                const char *section)
 {
@@ -95,31 +141,30 @@
        /* Issuer */
        if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (exp, 
section, "ISSUER", &val))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': 
Issuer missing\n", section);
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment 
`%s': Issuer missing\n"), section);
                        GNUNET_free (e);
                        return;
        }
-       if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string (section, 
&e->issuer.hashPubKey))
+       if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string (val, 
&e->issuer.hashPubKey))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': 
Issuer invalid\n", section);
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment 
`%s': Issuer invalid\n"), section);
                        GNUNET_free (val);
                        GNUNET_free (e);
                        return;
        }
        if (NULL == (i = GNUNET_CONTAINER_multihashmap_get (valid_issuers, 
&e->issuer.hashPubKey)))
        {
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer not 
accepted!\n", section);
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment `%s': Issuer 
not accepted!\n"), section);
                GNUNET_free (val);
                GNUNET_free (e);
                return;
        }
-
        GNUNET_free (val);
 
        /* Version */
        if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, 
section, "VERSION", &number))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': 
Version missing \n", section);
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment 
`%s': Version missing or invalid \n"), section);
                        GNUNET_free (e);
                        return;
        }
@@ -128,31 +173,39 @@
        /* Required capabilities */
        if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, 
section, "CAPABILITIES", &number))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': 
Required capabilities missing \n", section);
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment 
`%s': Required capabilities missing \n"), section);
                        GNUNET_free (e);
                        return;
        }
        if (number > UINT32_MAX)
        {
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Required 
capabilities invalid \n", section);
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment `%s': 
Required capabilities invalid \n"), section);
                GNUNET_free (e);
                return;
        }
        e->required_capabilities = number;
+       e->name = GNUNET_strdup (section);
 
-       /* Optional fields  */
-
+       /* Optional fields */
        /* Description */
        GNUNET_CONFIGURATION_get_value_string (exp, section, "DESCRIPTION", 
&e->description);
 
-
        /* verify experiment */
-
+       if (GNUNET_SYSERR == experiment_verify (i, e))
+       {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Experiment 
`%s': Experiment signature is invalid\n"), section);
+                       GNUNET_free (e);
+                       GNUNET_free_non_null (e->name);
+                       GNUNET_free_non_null (e->description);
+                       return;
+       }
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Adding experiment `%s'\n"), 
e->name);
+       GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, 
e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  GNUNET_STATISTICS_set (GSE_stats, "# expeeriments", 
GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO);
 }
 
 /**
  * Load experiments from file
- * FIXME: Not yet sure how to store that on disk ...
  *
  * @param file source file
  */
@@ -182,6 +235,7 @@
 int
 GNUNET_EXPERIMENTATION_experiments_start ()
 {
+       struct Issuer *i;
        char *issuers;
        char *file;
        char *pos;
@@ -195,7 +249,6 @@
        }
 
        valid_issuers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
-
   for (pos = strtok (issuers, " "); pos != NULL; pos = strtok (NULL, " "))
   {
 
@@ -206,8 +259,9 @@
                else
                {
                                GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' is a 
valid issuer \n", GNUNET_i2s (&issuer_ID));
+                               i = GNUNET_malloc (sizeof (struct Issuer));
                                GNUNET_CONTAINER_multihashmap_put 
(valid_issuers, &issuer_ID.hashPubKey,
-                                               NULL, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+                                               i, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
                }
   }
   GNUNET_free (issuers);
@@ -220,6 +274,7 @@
   }
   GNUNET_STATISTICS_set (GSE_stats, "# issuer", 
GNUNET_CONTAINER_multihashmap_size (valid_issuers), GNUNET_NO);
 
+  experiments = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
   /* Load experiments from file */
        if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, 
"EXPERIMENTATION", "EXPERIMENTS", &file))
                return GNUNET_OK;
@@ -227,13 +282,17 @@
        if (GNUNET_YES != GNUNET_DISK_file_test (file))
        {
                GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot read experiments 
file `%s'\n"), file);
+               GNUNET_free (file);
                        return GNUNET_OK;
        }
        load_file (file);
+       GNUNET_free (file);
 
        return GNUNET_OK;
 }
 
+
+
 /**
  * Stop experiments management
  */
@@ -241,8 +300,17 @@
 GNUNET_EXPERIMENTATION_experiments_stop ()
 {
        if (NULL != valid_issuers)
+       {
+               GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, 
&free_issuer, NULL);
                GNUNET_CONTAINER_multihashmap_destroy (valid_issuers);
+       }
        valid_issuers = NULL;
+       if (NULL != experiments)
+       {
+               GNUNET_CONTAINER_multihashmap_iterate (experiments, 
&free_experiment, NULL);
+               GNUNET_CONTAINER_multihashmap_destroy (experiments);
+       }
+       experiments = NULL;
 }
 
 /* end of gnunet-daemon-experimentation_experiments.c */




reply via email to

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