use fflush for stdout; minor changes
This commit is contained in:
parent
6bda23fb38
commit
a423fdb1d0
88
replay.c
88
replay.c
@ -31,8 +31,6 @@
|
|||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
|
||||||
|
|
||||||
struct msg
|
struct msg
|
||||||
{
|
{
|
||||||
uint16_t sender;
|
uint16_t sender;
|
||||||
@ -74,7 +72,7 @@ static struct transcript tr;
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_result( struct transcript *tr,
|
print_result (struct transcript *tr,
|
||||||
char *error)
|
char *error)
|
||||||
{
|
{
|
||||||
json_t *output;
|
json_t *output;
|
||||||
@ -82,46 +80,55 @@ print_result( struct transcript *tr,
|
|||||||
|
|
||||||
if (NULL != error)
|
if (NULL != error)
|
||||||
{
|
{
|
||||||
output = json_pack("{s:s}", "error", error);
|
output = json_pack ("{s:s}", "error", error);
|
||||||
GNUNET_assert(output);
|
GNUNET_assert (output);
|
||||||
|
|
||||||
json_dumpfd(output, 1, JSON_INDENT(2));
|
json_dumpfd (output, 1, JSON_INDENT (2));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GNUNET_assert(NULL != tr);
|
GNUNET_assert (NULL != tr);
|
||||||
|
|
||||||
output = json_object();
|
output = json_object ();
|
||||||
results = json_array();
|
results = json_array ();
|
||||||
GNUNET_assert(output);
|
GNUNET_assert (output);
|
||||||
GNUNET_assert(results);
|
GNUNET_assert (results);
|
||||||
|
|
||||||
for (size_t i = 0; i < tr->results_len; i++)
|
for (size_t i = 0; i < tr->results_len; i++)
|
||||||
{
|
{
|
||||||
json_t *result = json_pack("{s:i, s:s}",
|
json_t *result = json_pack ("{s:i, s:s}",
|
||||||
"bidder", tr->results[i].bidder,
|
"bidder", tr->results[i].bidder,
|
||||||
"price", tr->results[i].price);
|
"price", tr->results[i].price);
|
||||||
GNUNET_assert(result);
|
GNUNET_assert (result);
|
||||||
|
|
||||||
GNUNET_assert(-1 !=
|
GNUNET_assert (-1 !=
|
||||||
json_array_append_new(results, result));
|
json_array_append_new (results, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
GNUNET_assert(-1 !=
|
GNUNET_assert (-1 !=
|
||||||
json_object_set_new(output,
|
json_object_set_new (output,
|
||||||
"winners",
|
"winners",
|
||||||
results));
|
results));
|
||||||
|
|
||||||
json_dumpfd(output, 1, JSON_INDENT(2));
|
{
|
||||||
|
FILE *f = fdopen (1, "w");
|
||||||
|
GNUNET_assert(f);
|
||||||
|
|
||||||
|
json_dumpf (output, f, JSON_INDENT (2));
|
||||||
|
fflush (f);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decref (output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tr_result (void *arg,
|
cb_result (void *arg,
|
||||||
struct BRANDT_Result results[],
|
struct BRANDT_Result results[],
|
||||||
uint16_t results_len)
|
uint16_t results_len)
|
||||||
{
|
{
|
||||||
struct transcript *tr = (struct transcript *) arg;
|
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;
|
tr->results_len = results_len;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < results_len; i++)
|
for (uint16_t i = 0; i < results_len; i++)
|
||||||
@ -149,14 +156,13 @@ tr_result (void *arg,
|
|||||||
tr->expected[i].price);
|
tr->expected[i].price);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_result (tr, NULL);
|
||||||
// TODO: compare computed and expected results!
|
// TODO: compare computed and expected results!
|
||||||
|
|
||||||
print_result(tr, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16_t
|
static uint16_t
|
||||||
tr_start (void *auction_closure)
|
cb_start (void *auction_closure)
|
||||||
{
|
{
|
||||||
struct transcript *tr = (struct transcript *) auction_closure;
|
struct transcript *tr = (struct transcript *) auction_closure;
|
||||||
struct cls
|
struct cls
|
||||||
@ -200,9 +206,9 @@ replay_transcript (void *arg)
|
|||||||
"REPLAY calling BRANDT_new with %s outcome.\n",
|
"REPLAY calling BRANDT_new with %s outcome.\n",
|
||||||
tr->public ? "public" : "private");
|
tr->public ? "public" : "private");
|
||||||
|
|
||||||
tr->auction = BRANDT_new (&tr_result,
|
tr->auction = BRANDT_new (&cb_result,
|
||||||
NULL,
|
NULL,
|
||||||
&tr_start,
|
&cb_start,
|
||||||
tr,
|
tr,
|
||||||
&desc,
|
&desc,
|
||||||
&desc_len,
|
&desc_len,
|
||||||
@ -214,10 +220,9 @@ replay_transcript (void *arg)
|
|||||||
tr->public ? tr->edc : NULL);
|
tr->public ? tr->edc : NULL);
|
||||||
if (!tr->auction)
|
if (!tr->auction)
|
||||||
{
|
{
|
||||||
print_result(NULL, "REPLAY BRANDT_new() failed.");
|
print_result (NULL, "REPLAY BRANDT_new() failed.");
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,11 +240,11 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
if (!jtr)
|
if (!jtr)
|
||||||
{
|
{
|
||||||
char err[4096];
|
char err[4096];
|
||||||
snprintf(err,
|
snprintf (err,
|
||||||
sizeof(err),
|
sizeof(err),
|
||||||
"failed to parse json: %s in line %d, column %d (pos %d)",
|
"failed to parse json: %s in line %d, column %d (pos %d)",
|
||||||
jerror.text, jerror.line, jerror.column, jerror.position);
|
jerror.text, jerror.line, jerror.column, jerror.position);
|
||||||
print_result(NULL, err);
|
print_result (NULL, err);
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +262,7 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
auc = json_object_get (jtr, "auction");
|
auc = json_object_get (jtr, "auction");
|
||||||
if (NULL == auc)
|
if (NULL == auc)
|
||||||
{
|
{
|
||||||
print_result(NULL,
|
print_result (NULL,
|
||||||
"no auction found in input");
|
"no auction found in input");
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
@ -277,7 +282,7 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
|
|
||||||
if (!json_is_array (prices))
|
if (!json_is_array (prices))
|
||||||
{
|
{
|
||||||
print_result(NULL,
|
print_result (NULL,
|
||||||
"no prices found in input");
|
"no prices found in input");
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
@ -289,10 +294,10 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
if (!json_is_string (val))
|
if (!json_is_string (val))
|
||||||
{
|
{
|
||||||
char err[256];
|
char err[256];
|
||||||
snprintf(err,
|
snprintf (err,
|
||||||
sizeof(err),
|
sizeof(err),
|
||||||
"price %ld is not a string\n", idx);
|
"price %ld is not a string\n", idx);
|
||||||
print_result(NULL,
|
print_result (NULL,
|
||||||
err);
|
err);
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
@ -312,7 +317,7 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"bidders missing or not an array\n");
|
"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);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +335,7 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
messages = json_object_get (jtr, "transcript");
|
messages = json_object_get (jtr, "transcript");
|
||||||
if (!json_is_array (messages))
|
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);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +343,7 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
|
|
||||||
if (nm != (4 * tr->n))
|
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);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,12 +370,12 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
char err[4096];
|
char err[4096];
|
||||||
snprintf(err,
|
snprintf (err,
|
||||||
sizeof(err),
|
sizeof(err),
|
||||||
"error parsing message[%ld] in transcript: %s",
|
"error parsing message[%ld] in transcript: %s",
|
||||||
idx,
|
idx,
|
||||||
error);
|
error);
|
||||||
print_result(NULL, err);
|
print_result (NULL, err);
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,17 +415,17 @@ parse_json_stdin (struct transcript *tr)
|
|||||||
&(tr->expected[idx].price_idx)),
|
&(tr->expected[idx].price_idx)),
|
||||||
GNUNET_JSON_spec_string ("price",
|
GNUNET_JSON_spec_string ("price",
|
||||||
&(tr->expected[idx].price)),
|
&(tr->expected[idx].price)),
|
||||||
GNUNET_JSON_spec_end()
|
GNUNET_JSON_spec_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_JSON_parse(val,
|
GNUNET_JSON_parse (val,
|
||||||
spec,
|
spec,
|
||||||
(const char**) &error,
|
(const char**) &error,
|
||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
char err[4096];
|
char err[4096];
|
||||||
snprintf(err,
|
snprintf (err,
|
||||||
sizeof(err),
|
sizeof(err),
|
||||||
"error parsing winners[%ld] in transcript: %s",
|
"error parsing winners[%ld] in transcript: %s",
|
||||||
idx,
|
idx,
|
||||||
@ -451,6 +456,7 @@ main (int argc, char *argv[])
|
|||||||
tr.edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024 * 1024 * 40, 1024);
|
tr.edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024 * 1024 * 40, 1024);
|
||||||
GNUNET_SCHEDULER_run (&replay_transcript, &tr);
|
GNUNET_SCHEDULER_run (&replay_transcript, &tr);
|
||||||
GNUNET_CRYPTO_ecc_dlog_release (tr.edc);
|
GNUNET_CRYPTO_ecc_dlog_release (tr.edc);
|
||||||
|
GNUNET_free (tr.msgs);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user