aboutsummaryrefslogtreecommitdiff
path: root/replay.c
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-10-03 11:07:14 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2022-10-03 11:07:14 +0200
commita423fdb1d0c05e743deaf4f0e2332ca376d4329d (patch)
tree28981c9731b6fa4a7ae9b823a0488049bb5c8a00 /replay.c
parent6bda23fb384760626d62c722ca1e08c681b5d9a0 (diff)
use fflush for stdout; minor changes
Diffstat (limited to 'replay.c')
-rw-r--r--replay.c134
1 files changed, 70 insertions, 64 deletions
diff --git a/replay.c b/replay.c
index f9838cb..5a81526 100644
--- a/replay.c
+++ b/replay.c
@@ -31,8 +31,6 @@
#include "crypto.h"
#include "util.h"
-#define MIN(A, B) ((A) < (B) ? (A) : (B))
-
struct msg
{
uint16_t sender;
@@ -74,7 +72,7 @@ static struct transcript tr;
static void
-print_result( struct transcript *tr,
+print_result (struct transcript *tr,
char *error)
{
json_t *output;
@@ -82,46 +80,55 @@ print_result( struct transcript *tr,
if (NULL != error)
{
- output = json_pack("{s:s}", "error", error);
- GNUNET_assert(output);
+ output = json_pack ("{s:s}", "error", error);
+ GNUNET_assert (output);
- json_dumpfd(output, 1, JSON_INDENT(2));
+ json_dumpfd (output, 1, JSON_INDENT (2));
return;
}
- GNUNET_assert(NULL != tr);
+ GNUNET_assert (NULL != tr);
- output = json_object();
- results = json_array();
- GNUNET_assert(output);
- GNUNET_assert(results);
+ output = json_object ();
+ results = json_array ();
+ GNUNET_assert (output);
+ GNUNET_assert (results);
for (size_t i = 0; i < tr->results_len; i++)
{
- json_t *result = json_pack("{s:i, s:s}",
- "bidder", tr->results[i].bidder,
- "price", tr->results[i].price);
- GNUNET_assert(result);
+ json_t *result = json_pack ("{s:i, s:s}",
+ "bidder", tr->results[i].bidder,
+ "price", tr->results[i].price);
+ GNUNET_assert (result);
- GNUNET_assert(-1 !=
- json_array_append_new(results, result));
+ GNUNET_assert (-1 !=
+ json_array_append_new (results, result));
}
- GNUNET_assert(-1 !=
- json_object_set_new(output,
- "winners",
- results));
+ GNUNET_assert (-1 !=
+ json_object_set_new (output,
+ "winners",
+ results));
+
+ {
+ FILE *f = fdopen (1, "w");
+ GNUNET_assert(f);
- json_dumpfd(output, 1, JSON_INDENT(2));
+ json_dumpf (output, f, JSON_INDENT (2));
+ fflush (f);
+ }
+
+ json_decref (output);
}
+
static void
-tr_result (void *arg,
+cb_result (void *arg,
struct BRANDT_Result results[],
uint16_t results_len)
{
struct transcript *tr = (struct transcript *) arg;
- tr->results = GNUNET_new_array(results_len, struct result);
+ tr->results = GNUNET_new_array (results_len, struct result);
tr->results_len = results_len;
for (uint16_t i = 0; i < results_len; i++)
@@ -149,14 +156,13 @@ tr_result (void *arg,
tr->expected[i].price);
}
+ print_result (tr, NULL);
// TODO: compare computed and expected results!
-
- print_result(tr, NULL);
}
static uint16_t
-tr_start (void *auction_closure)
+cb_start (void *auction_closure)
{
struct transcript *tr = (struct transcript *) auction_closure;
struct cls
@@ -200,9 +206,9 @@ replay_transcript (void *arg)
"REPLAY calling BRANDT_new with %s outcome.\n",
tr->public ? "public" : "private");
- tr->auction = BRANDT_new (&tr_result,
+ tr->auction = BRANDT_new (&cb_result,
NULL,
- &tr_start,
+ &cb_start,
tr,
&desc,
&desc_len,
@@ -214,10 +220,9 @@ replay_transcript (void *arg)
tr->public ? tr->edc : NULL);
if (!tr->auction)
{
- print_result(NULL, "REPLAY BRANDT_new() failed.");
+ print_result (NULL, "REPLAY BRANDT_new() failed.");
_exit (1);
}
-
}
@@ -235,11 +240,11 @@ parse_json_stdin (struct transcript *tr)
if (!jtr)
{
char err[4096];
- snprintf(err,
- sizeof(err),
- "failed to parse json: %s in line %d, column %d (pos %d)",
- jerror.text, jerror.line, jerror.column, jerror.position);
- print_result(NULL, err);
+ snprintf (err,
+ sizeof(err),
+ "failed to parse json: %s in line %d, column %d (pos %d)",
+ jerror.text, jerror.line, jerror.column, jerror.position);
+ print_result (NULL, err);
_exit (1);
}
@@ -257,8 +262,8 @@ parse_json_stdin (struct transcript *tr)
auc = json_object_get (jtr, "auction");
if (NULL == auc)
{
- print_result(NULL,
- "no auction found in input");
+ print_result (NULL,
+ "no auction found in input");
_exit (1);
}
@@ -277,8 +282,8 @@ parse_json_stdin (struct transcript *tr)
if (!json_is_array (prices))
{
- print_result(NULL,
- "no prices found in input");
+ print_result (NULL,
+ "no prices found in input");
_exit (1);
}
@@ -289,11 +294,11 @@ parse_json_stdin (struct transcript *tr)
if (!json_is_string (val))
{
char err[256];
- snprintf(err,
- sizeof(err),
- "price %ld is not a string\n", idx);
- print_result(NULL,
- err);
+ snprintf (err,
+ sizeof(err),
+ "price %ld is not a string\n", idx);
+ print_result (NULL,
+ err);
_exit (1);
}
tr->prices[idx] = (char *) json_string_value (val);
@@ -312,7 +317,7 @@ parse_json_stdin (struct transcript *tr)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"bidders missing or not an array\n");
- print_result(NULL, "bidders missing or not an array");
+ print_result (NULL, "bidders missing or not an array");
_exit (1);
}
@@ -330,7 +335,7 @@ parse_json_stdin (struct transcript *tr)
messages = json_object_get (jtr, "transcript");
if (!json_is_array (messages))
{
- print_result(NULL, "transcript missing or not an array");
+ print_result (NULL, "transcript missing or not an array");
_exit (1);
}
@@ -338,7 +343,7 @@ parse_json_stdin (struct transcript *tr)
if (nm != (4 * tr->n))
{
- print_result(NULL, "wrong number of messages in transript");
+ print_result (NULL, "wrong number of messages in transript");
_exit (1);
}
@@ -365,12 +370,12 @@ parse_json_stdin (struct transcript *tr)
NULL))
{
char err[4096];
- snprintf(err,
- sizeof(err),
- "error parsing message[%ld] in transcript: %s",
- idx,
- error);
- print_result(NULL, err);
+ snprintf (err,
+ sizeof(err),
+ "error parsing message[%ld] in transcript: %s",
+ idx,
+ error);
+ print_result (NULL, err);
_exit (1);
}
@@ -410,21 +415,21 @@ parse_json_stdin (struct transcript *tr)
&(tr->expected[idx].price_idx)),
GNUNET_JSON_spec_string ("price",
&(tr->expected[idx].price)),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse(val,
- spec,
- (const char**) &error,
- NULL))
+ GNUNET_JSON_parse (val,
+ spec,
+ (const char**) &error,
+ NULL))
{
char err[4096];
- snprintf(err,
- sizeof(err),
- "error parsing winners[%ld] in transcript: %s",
- idx,
- error);
+ snprintf (err,
+ sizeof(err),
+ "error parsing winners[%ld] in transcript: %s",
+ idx,
+ error);
_exit (1);
}
@@ -451,6 +456,7 @@ main (int argc, char *argv[])
tr.edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024 * 1024 * 40, 1024);
GNUNET_SCHEDULER_run (&replay_transcript, &tr);
GNUNET_CRYPTO_ecc_dlog_release (tr.edc);
+ GNUNET_free (tr.msgs);
return ret;
}