gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 04/04: worked on cli assembler command 'policies'


From: gnunet
Subject: [taler-anastasis] 04/04: worked on cli assembler command 'policies'
Date: Tue, 16 Jun 2020 15:25:48 +0200

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 6d970145c14684956f23460e627588ef6af16418
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Jun 16 13:25:13 2020 +0000

    worked on cli assembler command 'policies'
---
 src/backend/anastasis-httpd.c        | 12 ++----
 src/backend/anastasis-httpd_config.c |  4 +-
 src/cli/anastasis-cli-assembler.c    | 73 +++++++++++++++++++++++++++++++++---
 src/cli/anastasis-cli-splitter.c     |  9 +----
 src/include/anastasis.h              |  4 ++
 src/include/anastasis_service.h      |  6 +++
 src/lib/anastasis.c                  |  1 +
 src/lib/anastasis_api_config.c       |  3 ++
 src/lib/test_anastasis_api.conf      |  5 ++-
 9 files changed, 92 insertions(+), 25 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 437f330..8b91971 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -598,16 +598,10 @@ run (void *cls,
     return;
   }
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (config,
-                                             "taler",
-                                             "CURRENCY",
-                                             &AH_currency))
+      TALER_config_get_currency (config,
+                                 &AH_currency))
   {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
-                               "taler",
-                               "CURRENCY");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    return GNUNET_SYSERR;
   }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (config,
diff --git a/src/backend/anastasis-httpd_config.c 
b/src/backend/anastasis-httpd_config.c
index 1fcb8b8..2d56a5f 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -44,11 +44,13 @@ AH_handler_config (struct TMH_RequestHandler *rh,
 {
   return TALER_MHD_reply_json_pack (connection,
                                     MHD_HTTP_OK,
-                                    "{s:s, s:I, s:o, s:o, s:s}",
+                                    "{s:s, s:I, s:s, s:o, s:o, s:s}",
                                     "methods",
                                     (char *) AH_supported_methods,
                                     "storage_limit_in_megabytes",
                                     (json_int_t) AH_upload_limit_mb,
+                                    "currency",
+                                    (char *) AH_currency,
                                     "annual_fee",
                                     TALER_JSON_from_amount (&AH_annual_fee),
                                     "question_cost",
diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 72df7e1..ade518e 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -35,6 +35,11 @@
  */
 static char *import_id;
 
+/**
+ * Currency
+ */
+static char *currency;
+
 /**
  * Global option '--import' to import json containing recovery document.
  */
@@ -69,6 +74,16 @@ static struct ANASTASIS_ChallengeInformation *challenges;
  */
 static unsigned int challenges_length = 0;
 
+/**
+ * Policies with information how to decrypt master key
+ */
+static struct ANASTASIS_DecryptionPolicy *policies;
+
+/**
+ * Amount of policies.
+ */
+static unsigned int policies_length = 0;
+
 static void
 start_read_keyboard (void);
 
@@ -97,6 +112,11 @@ struct ConfigState
    */
   struct TALER_Amount cost;
 
+  /**
+   * Currency of the cost;
+   */
+  char *currency;
+
   /**
    * Supported methods.
    */
@@ -188,7 +208,7 @@ read_keyboard_command (void *cls)
         "'x' to quit\n"
         "'o' to show these options\n"
         "'truth' to show all truths\n"
-        "'policy' to show all policies\n"
+        "'policies' to show all policies with missing challenges\n"
         "'try' to check whether you have to pay for truth\n"
         "'answer' to solve a challenge\n"
         "\n"
@@ -213,7 +233,6 @@ read_keyboard_command (void *cls)
                      strlen ("truth")))
       && (characters == strlen ("truth")))
   {
-    // FIXME "truth" logic here
     for (unsigned int i = 0; i < challenges_length; i++)
     {
       char solved_state = '-';
@@ -234,11 +253,43 @@ read_keyboard_command (void *cls)
     return;
   }
 
-  if (0 == strncmp ("policy",
-                    buffer,
-                    strlen ("policy")))
+  if ((0 == strncmp ("policies",
+                     buffer,
+                     strlen ("policies")))
+      && (characters == strlen ("policies")))
   {
-    // FIXME "policy" logic here
+    for (unsigned int i = 0; i < policies_length; i++)
+    {
+      // Calculate costs
+      struct TALER_Amount cost;
+      GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (currency,
+                                                         &cost));
+      for (unsigned int j = 0; j < policies[i].uuids_length; j++)
+      {
+        for (unsigned int k = 0; k < challenges_length; k++)
+        {
+          if (0 == uuid_compare (policies[i].escrow_uuids[j],
+                                 challenges[k].uuid))
+            TALER_amount_add (&cost,
+                              &cost,
+                              challenges[k].cost);
+        }
+      }
+      printf ("policy#%u: %s ",
+              i,
+              TALER_amount_to_string (&cost));
+      for (unsigned int j = 0; j < policies[i].uuids_length; j++)
+      {
+        for (unsigned int k = 0; k < challenges_length; k++)
+        {
+          if (0 == uuid_compare (policies[i].escrow_uuids[j],
+                                 challenges[k].uuid))
+            if (1 != challenges[k].solved)
+              printf ("truth#%u ", k);
+        }
+      }
+      printf ("missing\n");
+    }
     start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
@@ -274,6 +325,7 @@ read_keyboard_command (void *cls)
   buffer = NULL;
   start_read_keyboard ();
 }
+
 /**
  * @brief Wait for a keyboard input
  */
@@ -309,6 +361,7 @@ start_read_keyboard ()
  * @param cls closure
  * @param http_status HTTP status of the request
  * @param methods supported methods by this provider
+ * @param conf_currency
  * @param annual_fee Annual fee of this service
  * @param question_cost Cost for authentication by question
  */
@@ -316,6 +369,7 @@ static void
 config_cb (void *cls,
            unsigned int http_status,
            const char *methods,
+           const char *conf_currency,
            const struct TALER_Amount *annual_fee,
            const struct TALER_Amount *question_cost)
 {
@@ -333,6 +387,10 @@ config_cb (void *cls,
   }
 
   cs->cost = *question_cost;
+  if (NULL == currency)
+  {
+    currency = conf_currency;
+  }
 }
 
 
@@ -386,6 +444,9 @@ policy_lookup_cb (void *cls,
     ANASTASIS_get_challenge (rss->ri->cs[i],
                              &challenge_cb);
   }
+  policies = rss->ri->dps;
+  policies_length = rss->ri->dps_len;
+
   start_read_keyboard ();
   return;
 }
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index c6ab843..ab8c7fe 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -558,6 +558,7 @@ static void
 config_cb (void *cls,
            unsigned int http_status,
            const char *methods,
+           const char *conf_currency,
            const struct TALER_Amount *annual_fee,
            const struct TALER_Amount *question_cost)
 {
@@ -749,7 +750,6 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("server add")))
   {
-    // FIXME "server add" logic here
     struct ServerInfo *server = GNUNET_new (struct ServerInfo);
     struct SaltState *ss = GNUNET_new (struct SaltState);
 
@@ -786,7 +786,6 @@ read_keyboard_command (void *cls)
                      strlen ("truth")))
       && (characters == strlen ("truth")))
   {
-    // FIXME "truth" logic here
     if (NULL != tu_states)
     {
       for (unsigned int i = 0; i < tu_states_length; i++)
@@ -820,7 +819,6 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("truth add")))
   {
-    // FIXME "truth add" logic here
     if (NULL != servers)
     {
       struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
@@ -908,7 +906,6 @@ read_keyboard_command (void *cls)
             GNUNET_SCHEDULER_shutdown ();
             return;
           }
-          // tus->index = (tu_states_length > 0) ? tu_states_length - 1 : 0;
           tus->index = tu_states_length;
           tus->tuo = ANASTASIS_truth_upload (ctx,
                                              tus->id_data,
@@ -957,7 +954,6 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("truth --secrets")))
   {
-    // FIXME "truth --secrets" logic here
     if (NULL != tu_states)
     {
       for (unsigned int i = 0; i < tu_states_length; i++)
@@ -992,7 +988,6 @@ read_keyboard_command (void *cls)
                      strlen ("policy")))
       && (characters == strlen ("policy")))
   {
-    // FIXME "policy" logic here
     if (NULL != pc_states)
     {
       for (unsigned int i = 0; i < pc_states_length; i++)
@@ -1018,7 +1013,6 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("policy add")))
   {
-    // FIXME "policy add" logic here
     struct PolicyCreateState *pcs = GNUNET_new (struct PolicyCreateState);
     char *token_start = &buffer[strlen ("policy add ")];
     char *token = strtok (token_start, " ");
@@ -1056,7 +1050,6 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("publish")))
   {
-    // FIXME "publish" logic here
     if (NULL != pc_states)
     {
       struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index be47f6c..4ca4e22 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -146,6 +146,8 @@ ANASTASIS_challenge_answer (struct GNUNET_CURL_Context *ctx,
  * @param instructions defines which steps need to be done e.g. ( please look 
for the pin for recovery #1234)
  * @param cost Cost to solve this challenge
  * @param solved 1 if solved, else 0
+ * @param uuid Uuid of the challenge
+ * @param currency Currency of the cost
  */
 struct ANASTASIS_ChallengeInformation
 {
@@ -154,6 +156,8 @@ struct ANASTASIS_ChallengeInformation
   const char *instructions;
   const struct TALER_Amount *cost;
   const unsigned int *solved;
+  const uuid_t *uuid;
+  const char *currency;
 };
 
 /**
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 0311754..9544458 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -252,6 +252,7 @@ typedef void
 (*ANASTASIS_ConfigCallback)(void *cls,
                             unsigned int http_status,
                             const char *methods,
+                            const char *conf_currency,
                             const struct TALER_Amount *annual_fee,
                             const struct TALER_Amount *question_cost);
 
@@ -314,6 +315,11 @@ struct ANASTASIS_ConfigOperation
    */
   struct TALER_Amount question_cost;
 
+  /**
+   * Currency of the cost;
+   */
+  const char *currency;
+
   // FIXME add configs
 };
 
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 1533ea9..aaab198 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -481,6 +481,7 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge 
*challenge,
   struct ANASTASIS_ChallengeInformation *ci;
   ci = GNUNET_new (struct ANASTASIS_ChallengeInformation);
   challenge->cc = cc;
+  ci->uuid = &challenge->challenge_uuid;
   ci->method = challenge->escrow_method;
   ci->url = challenge->url;
   ci->instructions = challenge->instructions;
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index 9f76a93..7f1a41b 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -60,6 +60,7 @@ handle_config_finished (void *cls,
     {
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_string ("methods", &co->methods),
+        GNUNET_JSON_spec_string ("currency", &co->currency),
         TALER_JSON_spec_amount ("annual_fee", &co->cost),
         TALER_JSON_spec_amount ("question_cost", &co->question_cost),
         // FIXME add configs
@@ -78,6 +79,7 @@ handle_config_finished (void *cls,
       co->cb (co->cb_cls,
               response_code,
               co->methods,
+              co->currency,
               &co->cost,
               &co->question_cost
               // FIXME add configs
@@ -111,6 +113,7 @@ handle_config_finished (void *cls,
             response_code,
             NULL,
             NULL,
+            NULL,
             NULL);
     co->cb = NULL;
   }
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 2a6e052..560b005 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -15,7 +15,7 @@ TALER_CACHE_HOME = $TALER_TEST_HOME/.cache/taler/
 
 [taler]
 # What currency do we use?
-CURRENCY = EUR
+currency = EUR
 CURRENCY_ROUND_UNIT = EUR:0.01
 
 [bank]
@@ -40,6 +40,9 @@ PAYMENT_BACKEND_URL = http://localhost:8080/
 ANNUAL_FEE = EUR:4.99
 #ANNUAL_FEE = EUR:0
 
+# Cost of authentication by question
+QUESTION_COST = EUR:0
+
 # Upload limit
 UPLOAD_LIMIT_MB = 1
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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