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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file auction/gnunet-auction-create.c
21 * @brief tool to create a new auction
22 * @author Markus Teich
28 #include "gnunet_util_lib.h"
29 #include "gnunet_json_lib.h"
30 /* #include "gnunet_auction_service.h" */
33 #define OUTCOME_PRIVATE 0
34 #define OUTCOME_PUBLIC 1
36 static int ret; /** Final status code. */
37 static char *fndesc; /** filename of the item description */
38 static char *fnprices; /** filename of the price map */
39 static struct GNUNET_TIME_Relative dround; /** max round duration */
40 static struct GNUNET_TIME_Relative dstart; /** time until auction starts */
41 static unsigned int m = FIRST_PRICE; /** auction parameter m */
42 static int outcome = OUTCOME_PRIVATE; /** outcome */
43 static int interactive; /** keep running in foreground */
47 * Main function that will be run by the scheduler.
50 * @param args remaining command-line arguments
51 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
52 * @param cfg configuration
58 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 double cur, prev = DBL_MAX;
68 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
70 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
71 "required argument --regtime missing or invalid (zero)\n");
74 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
77 "required argument --roundtime missing or invalid (zero)\n");
82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
83 "required argument --description missing\n");
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 "required argument --pricemap missing\n");
93 /* parse and check pricemap validity */
94 if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
96 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
97 "parsing pricemap json at %d:%d: %s\n",
98 jerr.line, jerr.column, jerr.text);
101 if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
102 "{s:s, s:[]}", "currency", "prices"))
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 "validating pricemap: %s\n", jerr.text);
108 if (!(parray = json_object_get (pmap, "prices")) || !json_is_array (parray))
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
111 "could not get `prices` array node from pricemap\n");
114 if (0 == json_array_size (parray))
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
119 json_array_foreach (parray, i, pnode)
121 if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
124 "validating pricearray index %d: %s\n", i, jerr.text);
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "validating pricearray index %d: "
131 "prices must be strictly monotonically decreasing\n",
149 * @param argc number of arguments from the command line
150 * @param argv command line arguments
151 * @return 0 ok, 1 on error
154 main (int argc, char *const *argv)
156 struct GNUNET_GETOPT_CommandLineOption options[] = {
158 GNUNET_GETOPT_option_filename ('d',
161 gettext_noop ("description of the item to be sold"),
164 GNUNET_GETOPT_option_filename ('p',
167 gettext_noop ("mapping of possible prices"),
170 GNUNET_GETOPT_option_relative_time ('r',
173 gettext_noop ("max duration per round"),
176 GNUNET_GETOPT_option_relative_time ('s',
179 gettext_noop ("duration until auction starts"),
181 GNUNET_GETOPT_option_uint ('m',
184 gettext_noop ("number of items to sell\n"
185 "0 for first price auction\n"
186 ">0 for vickrey/M+1st price auction"),
189 GNUNET_GETOPT_option_flag ('u',
191 gettext_noop ("public auction outcome"),
194 GNUNET_GETOPT_option_flag ('i',
196 gettext_noop ("keep running in foreground until auction completes"),
199 GNUNET_GETOPT_OPTION_END
201 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
205 GNUNET_PROGRAM_run (argc, argv,
206 "gnunet-auction-create",
207 gettext_noop ("create a new auction and "
208 "start listening for bidders"),
212 GNUNET_free ((void*) argv);