GNUnet 0.21.1
gnunet-auction-create.c File Reference

tool to create a new auction More...

#include "platform.h"
#include <float.h>
#include "gnunet_util_lib.h"
#include <jansson.h>
Include dependency graph for gnunet-auction-create.c:

Go to the source code of this file.

Macros

#define FIRST_PRICE   0
 
#define OUTCOME_PRIVATE   0
 
#define OUTCOME_PUBLIC   1
 

Functions

static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 keep running in foreground More...
 
int main (int argc, char *const *argv)
 The main function. More...
 

Variables

static int ret
 
static char * fndesc
 Final status code. More...
 
static char * fnprices
 filename of the item description More...
 
static struct GNUNET_TIME_Relative dround
 filename of the price map More...
 
static struct GNUNET_TIME_Relative dstart
 max round duration More...
 
static unsigned int m = 0
 time until auction starts More...
 
static int outcome = 0
 auction parameter m More...
 
static int interactive
 outcome More...
 

Detailed Description

tool to create a new auction

Author
Markus Teich

Definition in file gnunet-auction-create.c.

Macro Definition Documentation

◆ FIRST_PRICE

#define FIRST_PRICE   0

Definition at line 34 of file gnunet-auction-create.c.

◆ OUTCOME_PRIVATE

#define OUTCOME_PRIVATE   0

Definition at line 35 of file gnunet-auction-create.c.

◆ OUTCOME_PUBLIC

#define OUTCOME_PUBLIC   1

Definition at line 36 of file gnunet-auction-create.c.

Function Documentation

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

keep running in foreground

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 57 of file gnunet-auction-create.c.

61{
62 unsigned int i;
63 double cur, prev = DBL_MAX;
64 json_t *pmap;
65 json_t *parray;
66 json_t *pnode;
67 json_error_t jerr;
68
69 /* cmdline parsing */
70 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
71 {
73 "required argument --regtime missing or invalid (zero)\n");
74 goto fail;
75 }
76 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
77 {
79 "required argument --roundtime missing or invalid (zero)\n");
80 goto fail;
81 }
82 if (! fndesc)
83 {
85 "required argument --description missing\n");
86 goto fail;
87 }
88 if (! fnprices)
89 {
91 "required argument --pricemap missing\n");
92 goto fail;
93 }
94
95 /* parse and check pricemap validity */
96 if (! (pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
97 {
99 "parsing pricemap json at %d:%d: %s\n",
100 jerr.line, jerr.column, jerr.text);
101 goto fail;
102 }
103 if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
104 "{s:s, s:[]}", "currency", "prices"))
105 {
107 "validating pricemap: %s\n", jerr.text);
108 goto fail;
109 }
110 if (! (parray = json_object_get (pmap, "prices")) || ! json_is_array (parray))
111 {
113 "could not get `prices` array node from pricemap\n");
114 goto fail;
115 }
116 if (0 == json_array_size (parray))
117 {
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
119 goto fail;
120 }
121 json_array_foreach (parray, i, pnode)
122 {
123 if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
124 {
126 "validating pricearray index %d: %s\n", i, jerr.text);
127 goto fail;
128 }
129 if (prev <= cur)
130 {
132 "validating pricearray index %d: "
133 "prices must be strictly monotonically decreasing\n",
134 i);
135 goto fail;
136 }
137 prev = cur;
138 }
139
140 return;
141
142fail:
143 ret = 1;
144 return;
145}
static int ret
static struct GNUNET_TIME_Relative dstart
max round duration
static char * fnprices
filename of the item description
static struct GNUNET_TIME_Relative dround
filename of the price map
static char * fndesc
Final status code.
static const struct ParameterMap pmap[]
Map of names with TeX definitions, used during PDF generation.
Definition: gnunet-bcd.c:127
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
uint64_t rel_value_us
The actual value.

References dround, dstart, fndesc, fnprices, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_TIME_UNIT_ZERO, pmap, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 156 of file gnunet-auction-create.c.

157{
160 "description",
161 "FILE",
163 "description of the item to be sold"),
164 &fndesc),
165
167 "pricemap",
168 "FILE",
169 gettext_noop ("mapping of possible prices"),
170 &fnprices),
171
173 "roundtime",
174 "DURATION",
175 gettext_noop ("max duration per round"),
176 &dround),
177
179 "regtime",
180 "DURATION",
182 "duration until auction starts"),
183 &dstart),
185 "m",
186 "NUMBER",
187 gettext_noop ("number of items to sell\n"
188 "0 for first price auction\n"
189 ">0 for vickrey/M+1st price auction"),
190 &m),
191
193 "public",
194 gettext_noop ("public auction outcome"),
195 &outcome),
196
198 "interactive",
200 "keep running in foreground until auction completes"),
201 &interactive),
202
204 };
205
206 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
207 return 2;
208
209 ret = (GNUNET_OK ==
210 GNUNET_PROGRAM_run (argc, argv,
211 "gnunet-auction-create",
212 gettext_noop ("create a new auction and "
213 "start listening for bidders"),
214 options,
215 &run,
216 NULL)) ? ret : 1;
217 GNUNET_free_nz ((void *) argv);
218 return ret;
219}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static unsigned int m
time until auction starts
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
keep running in foreground
static int interactive
outcome
static int outcome
auction parameter m
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a filename (automatically path expanded).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
@ GNUNET_OK
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
Definition of a command line option.

References dround, dstart, fndesc, fnprices, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_filename(), GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), interactive, m, options, outcome, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Definition at line 38 of file gnunet-auction-create.c.

Referenced by main(), and run().

◆ fndesc

char* fndesc
static

Final status code.

Definition at line 39 of file gnunet-auction-create.c.

Referenced by main(), and run().

◆ fnprices

char* fnprices
static

filename of the item description

Definition at line 40 of file gnunet-auction-create.c.

Referenced by main(), and run().

◆ dround

struct GNUNET_TIME_Relative dround
static

filename of the price map

Definition at line 41 of file gnunet-auction-create.c.

Referenced by main(), and run().

◆ dstart

struct GNUNET_TIME_Relative dstart
static

max round duration

Definition at line 42 of file gnunet-auction-create.c.

Referenced by main(), and run().

◆ m

unsigned int m = 0
static

time until auction starts

Definition at line 43 of file gnunet-auction-create.c.

Referenced by main().

◆ outcome

int outcome = 0
static

auction parameter m

Definition at line 44 of file gnunet-auction-create.c.

Referenced by main().

◆ interactive

int interactive
static

outcome

Definition at line 45 of file gnunet-auction-create.c.

Referenced by main().