doxygen
[oweals/gnunet.git] / src / experimentation / gnunet-daemon-experimentation_experiments.c
index 300b37d2895bd24144433406e993b264f00268ae..09fd8d1ec47bf4a087a8c53c26da5e9778f6daaf 100644 (file)
 #include "gnunet-daemon-experimentation.h"
 
 
-/**
- * Struct to store information about a specific experiment
- */
-struct Experiment
-{
-       /* Header */
-       /* ----------------- */
-       char *name;
-
-       /* Experiment issuer */
-       struct GNUNET_PeerIdentity issuer;
-
-       /* Experiment version as timestamp of creation */
-       struct GNUNET_TIME_Absolute version;
-
-       /* Description */
-       char *description;
-
-       /* Required capabilities  */
-       uint32_t required_capabilities;
-
-       /* Experiment timing */
-       /* ----------------- */
-
-       /* When to start experiment */
-       struct GNUNET_TIME_Absolute start;
-
-       /* When to end experiment */
-       struct GNUNET_TIME_Absolute stop;
-
-       /* How often to run experiment */
-       struct GNUNET_TIME_Relative frequency;
-
-       /* How long to run each execution  */
-       struct GNUNET_TIME_Relative duration;
-
-
-       /* Experiment itself */
-       /* ----------------- */
-
-       /* TBD */
-};
-
 
 /**
  * Struct to store information about an experiment issuer
@@ -97,6 +54,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
 static struct GNUNET_CONTAINER_MultiHashMap *experiments;
 
 
+uint32_t GSE_my_issuer_count;
+
+struct Experimentation_Issuer *GSE_my_issuer;
+
+
 /**
  * Verify experiment signature
  *
@@ -145,6 +107,20 @@ int free_issuer (void *cls,
        return GNUNET_OK;
 }
 
+int create_issuer (void *cls,
+                                                                const struct GNUNET_HashCode * key,
+                                                                void *value)
+{
+       static int i = 0;
+       GNUNET_assert (i < GSE_my_issuer_count);
+       GSE_my_issuer[i].issuer_id.hashPubKey = *key;
+
+       i++;
+       return GNUNET_OK;
+
+}
+
+
 
 /**
  * Is peer a valid issuer
@@ -160,6 +136,47 @@ GNUNET_EXPERIMENTATION_experiments_issuer_accepted (struct GNUNET_PeerIdentity *
                return GNUNET_NO;
 }
 
+struct GetCtx
+{
+       struct Node *n;
+       GNUNET_EXPERIMENTATION_experiments_get_cb get_cb;
+};
+
+static int
+get_it (void *cls,
+                               const struct GNUNET_HashCode * key,
+                               void *value)
+{
+       struct GetCtx *get_ctx = cls;
+       struct Experiment *e = value;
+
+       get_ctx->get_cb (get_ctx->n, e);
+
+       return GNUNET_OK;
+}
+
+
+
+
+void
+GNUNET_EXPERIMENTATION_experiments_get (struct Node *n,
+                                                                                                                                                               struct GNUNET_PeerIdentity *issuer,
+                                                                                                                                                               GNUNET_EXPERIMENTATION_experiments_get_cb get_cb)
+{
+       struct GetCtx get_ctx;
+
+       GNUNET_assert (NULL != n);
+       GNUNET_assert (NULL != experiments);
+       GNUNET_assert (NULL != get_cb);
+
+       get_ctx.n = n;
+       get_ctx.get_cb = get_cb;
+
+       GNUNET_CONTAINER_multihashmap_get_multiple (experiments,
+                       &issuer->hashPubKey, &get_it, &get_ctx);
+
+       get_cb (n, NULL);
+}
 
 /**
  * Add a new experiment
@@ -189,8 +206,6 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i,
        e->duration = duration;
        e->stop = stop;
 
-
-
        /* verify experiment */
        if (GNUNET_SYSERR == experiment_verify (i, e))
        {
@@ -218,7 +233,7 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i,
  * Parse a configuration section containing experiments
  *
  * @param cls configuration handle
- * @param section section name
+ * @param name section name
  */
 void exp_file_iterator (void *cls,
                                                                                                const char *name)
@@ -398,6 +413,11 @@ GNUNET_EXPERIMENTATION_experiments_start ()
                        GNUNET_free (pubkey);
        }
 
+       GSE_my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
+       GSE_my_issuer = GNUNET_malloc (GSE_my_issuer_count * sizeof (struct Experimentation_Issuer));
+       GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &create_issuer, GSE_my_issuer);
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Daemon has %u issuers\n"), GSE_my_issuer_count);
+
   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))
@@ -421,6 +441,12 @@ GNUNET_EXPERIMENTATION_experiments_start ()
 void
 GNUNET_EXPERIMENTATION_experiments_stop ()
 {
+       if (NULL != GSE_my_issuer)
+       {
+               GNUNET_free (GSE_my_issuer);
+               GSE_my_issuer = NULL;
+               GSE_my_issuer_count = 0;
+       }
        if (NULL != valid_issuers)
        {
                GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &free_issuer, NULL);