2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file auction/gnunet-auction-create.c
18 * @brief tool to create a new auction
19 * @author Markus Teich
25 #include "gnunet_util_lib.h"
26 #include "gnunet_json_lib.h"
27 /* #include "gnunet_auction_service.h" */
30 #define OUTCOME_PRIVATE 0
31 #define OUTCOME_PUBLIC 1
33 static int ret; /** Final status code. */
34 static char *fndesc; /** filename of the item description */
35 static char *fnprices; /** filename of the price map */
36 static struct GNUNET_TIME_Relative dround; /** max round duration */
37 static struct GNUNET_TIME_Relative dstart; /** time until auction starts */
38 static unsigned int m = FIRST_PRICE; /** auction parameter m */
39 static int outcome = OUTCOME_PRIVATE; /** outcome */
40 static int interactive; /** keep running in foreground */
44 * Main function that will be run by the scheduler.
47 * @param args remaining command-line arguments
48 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
49 * @param cfg configuration
55 const struct GNUNET_CONFIGURATION_Handle *cfg)
58 double cur, prev = DBL_MAX;
65 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
67 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
68 "required argument --regtime missing or invalid (zero)\n");
71 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
73 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
74 "required argument --roundtime missing or invalid (zero)\n");
79 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
80 "required argument --description missing\n");
85 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
86 "required argument --pricemap missing\n");
90 /* parse and check pricemap validity */
91 if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
93 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
94 "parsing pricemap json at %d:%d: %s\n",
95 jerr.line, jerr.column, jerr.text);
98 if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
99 "{s:s, s:[]}", "currency", "prices"))
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
102 "validating pricemap: %s\n", jerr.text);
105 if (!(parray = json_object_get (pmap, "prices")) || !json_is_array (parray))
107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 "could not get `prices` array node from pricemap\n");
111 if (0 == json_array_size (parray))
113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
116 json_array_foreach (parray, i, pnode)
118 if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
121 "validating pricearray index %d: %s\n", i, jerr.text);
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
127 "validating pricearray index %d: "
128 "prices must be strictly monotonically decreasing\n",
146 * @param argc number of arguments from the command line
147 * @param argv command line arguments
148 * @return 0 ok, 1 on error
151 main (int argc, char *const *argv)
153 struct GNUNET_GETOPT_CommandLineOption options[] = {
155 GNUNET_GETOPT_option_filename ('d',
158 gettext_noop ("description of the item to be sold"),
161 GNUNET_GETOPT_option_filename ('p',
164 gettext_noop ("mapping of possible prices"),
167 GNUNET_GETOPT_option_relative_time ('r',
170 gettext_noop ("max duration per round"),
173 GNUNET_GETOPT_option_relative_time ('s',
176 gettext_noop ("duration until auction starts"),
178 GNUNET_GETOPT_option_uint ('m',
181 gettext_noop ("number of items to sell\n"
182 "0 for first price auction\n"
183 ">0 for vickrey/M+1st price auction"),
186 GNUNET_GETOPT_option_flag ('u',
188 gettext_noop ("public auction outcome"),
191 GNUNET_GETOPT_option_flag ('i',
193 gettext_noop ("keep running in foreground until auction completes"),
196 GNUNET_GETOPT_OPTION_END
198 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
202 GNUNET_PROGRAM_run (argc, argv,
203 "gnunet-auction-create",
204 gettext_noop ("create a new auction and "
205 "start listening for bidders"),
209 GNUNET_free ((void*) argv);