gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/07: work on reducer cli


From: gnunet
Subject: [taler-anastasis] 03/07: work on reducer cli
Date: Sat, 12 Sep 2020 11:01:50 +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 09977c9576eae33571b945c424dac3efd1b7782b
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Sep 11 12:18:06 2020 +0200

    work on reducer cli
---
 src/cli/Makefile.am           | 13 +++++-
 src/cli/anastasis-cli-redux.c | 99 ++++++++++++++++++++++++++++++++++++++++++-
 src/include/anastasis_redux.h |  4 +-
 src/lib/Makefile.am           | 16 ++++++-
 4 files changed, 126 insertions(+), 6 deletions(-)

diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index e7352b5..a6f4409 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -3,7 +3,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
 bin_PROGRAMS = \
   anastasis-splitter \
-  anastasis-assembler
+  anastasis-assembler \
+  anastasis-reducer
 
 if USE_COVERAGE
   AM_CFLAGS = --coverage -O0
@@ -44,6 +45,16 @@ anastasis_assembler_LDADD = \
   -lreadline \
   $(XLIB)
 
+anastasis_reducer_SOURCES = \
+  anastasis-cli-redux.c
+anastasis_reducer_LDADD = \
+  $(top_builddir)/src/lib/libanastasisredux.la \
+  -lgnunetjson \
+  -lgnunetcurl \
+  -lgnunetutil \
+  -ljansson \
+  $(XLIB)
+
 if HAVE_LIBCURL
 anastasis_splitter_LDADD += -lcurl
 anastasis_assembler_LDADD += -lcurl
diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index 9992600..61623e4 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -47,6 +47,32 @@ static int b_flag;
  */
 static int r_flag;
 
+/**
+ * -i option given.
+ */
+static int i_flag;
+
+/**
+ * JSON containing previous state
+ */
+static json_t *prev_state;
+
+/**
+ * JSON containing new state
+ */
+static json_t *new_state;
+
+/**
+ * path to new state
+ */
+static char *path_new_state;
+
+/**
+ * action to do with previous state
+ */
+static char *action;
+
+
 /**
  * @brief Shutdown the application.
  *
@@ -88,6 +114,8 @@ run (void *cls,
   (void) cls;
   (void) args;
   (void) cfgfile;
+  // FIXME: error handling json error
+  json_error_t error;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Starting anastasis-reducer\n");
@@ -100,13 +128,76 @@ run (void *cls,
                                    "WARNING",
                                    NULL));
 
-  if (! (r_flag ^ b_flag))
+  if (! (r_flag ^ b_flag ^ i_flag) || (r_flag && b_flag && i_flag))
   {
-    printf ("Please set one option: -b or -r !\n");
+    printf ("Please set one option: -b, -r, -i!\n");
+    printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+    printf ("Example: anastasis-reducer -i init.json\n");
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
 
+  if (i_flag)
+  {
+    if (args[0])
+    {
+      path_new_state = (char *) args[0];
+      new_state = ANASTASIS_backup_start (cfg);
+      if (! (0 == json_dump_file (new_state,
+                                  path_new_state,
+                                  JSON_COMPACT)))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "At %s:%u failed to dump json into file!\n",
+                    __FILE__,
+                    __LINE__);
+        GNUNET_SCHEDULER_shutdown ();
+        return;
+      }
+    }
+    else
+    {
+      printf ("Please give path for json containing initial state!\n");
+      printf ("Example: anastasis-reducer -i init.json\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+  }
+
+  if ((r_flag ^ b_flag))
+  {
+    if (args[0])
+      prev_state = json_load_file ((char *) args[0], JSON_DECODE_ANY, &error);
+    else
+    {
+      printf ("Please give path for json containing previous state!\n");
+      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+
+    if (args[1])
+      action = (char *) args[1];
+    else
+    {
+      printf ("Please give an action!\n");
+      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+
+    if (args[2])
+      path_new_state = (char *) args[2];
+    else
+    {
+      printf ("Please give path for json containing new state!\n");
+      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+  }
+
+
   /* initialize HTTP client FIXME: Do we need http client?*/
   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
                           &rc);
@@ -130,6 +221,10 @@ main (int argc,
                                "restore",
                                "use reducer to handle states for restore 
process",
                                &r_flag),
+    GNUNET_GETOPT_option_flag ('i',
+                               "init",
+                               "returns an initial state to start with",
+                               &i_flag),
 
     GNUNET_GETOPT_OPTION_END
   };
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 72ab34e..1d066e4 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -43,7 +43,7 @@ extern json_t *redux_id_attr;
  * @return NULL on failure
  */
 json_t *
-ANASTASIS_backup_start (void);
+ANASTASIS_backup_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
@@ -52,7 +52,7 @@ ANASTASIS_backup_start (void);
  * @return NULL on failure
  */
 json_t *
-ANASTASIS_recovery_start (void);
+ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 3bf9ac8..1607748 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -11,7 +11,8 @@ endif
 lib_LTLIBRARIES = \
   libanastasisrest.la \
   libanastasis.la \
-  libanastasistesting.la
+  libanastasistesting.la \
+  libanastasisredux.la
 
 libanastasisrest_la_LDFLAGS = \
   -version-info 0:0:0 \
@@ -95,6 +96,19 @@ libanastasistesting_la_LIBADD = \
   $(XLIB)
 
 
+libanastasisredux_la_LDFLAGS = \
+  -version-info 0:0:0 \
+  -no-undefined
+libanastasisredux_la_SOURCES = \
+  anastasis_api_backup_redux.c
+libanastasisredux_la_LIBADD = \
+  -lgnunetjson \
+  -lgnunetcurl \
+  -lgnunetutil \
+  -ljansson \
+  $(XLIB)
+
+
 check_PROGRAMS = \
   test_anastasisrest_api \
   test_anastasis

-- 
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]