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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file auction/gnunet-auction-create.c
23 * @brief tool to create a new auction
24 * @author Markus Teich
30 #include "gnunet_util_lib.h"
31 #include "gnunet_json_lib.h"
32 /* #include "gnunet_auction_service.h" */
35 #define OUTCOME_PRIVATE 0
36 #define OUTCOME_PUBLIC 1
38 static int ret; /** Final status code. */
39 static char *fndesc; /** filename of the item description */
40 static char *fnprices; /** filename of the price map */
41 static struct GNUNET_TIME_Relative dround; /** max round duration */
42 static struct GNUNET_TIME_Relative dstart; /** time until auction starts */
43 static unsigned int m = FIRST_PRICE; /** auction parameter m */
44 static int outcome = OUTCOME_PRIVATE; /** outcome */
45 static int interactive; /** keep running in foreground */
49 * Main function that will be run by the scheduler.
52 * @param args remaining command-line arguments
53 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
54 * @param cfg configuration
60 const struct GNUNET_CONFIGURATION_Handle *cfg)
63 double cur, prev = DBL_MAX;
70 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
72 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
73 "required argument --regtime missing or invalid (zero)\n");
76 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
79 "required argument --roundtime missing or invalid (zero)\n");
84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
85 "required argument --description missing\n");
90 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
91 "required argument --pricemap missing\n");
95 /* parse and check pricemap validity */
96 if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 "parsing pricemap json at %d:%d: %s\n",
100 jerr.line, jerr.column, jerr.text);
103 if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
104 "{s:s, s:[]}", "currency", "prices"))
106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
107 "validating pricemap: %s\n", jerr.text);
110 if (!(parray = json_object_get (pmap, "prices")) || !json_is_array (parray))
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 "could not get `prices` array node from pricemap\n");
116 if (0 == json_array_size (parray))
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
121 json_array_foreach (parray, i, pnode)
123 if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
126 "validating pricearray index %d: %s\n", i, jerr.text);
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
132 "validating pricearray index %d: "
133 "prices must be strictly monotonically decreasing\n",
151 * @param argc number of arguments from the command line
152 * @param argv command line arguments
153 * @return 0 ok, 1 on error
156 main (int argc, char *const *argv)
158 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
159 {'d', "description", "FILE",
160 gettext_noop ("description of the item to be sold"),
161 1, &GNUNET_GETOPT_set_filename, &fndesc},
162 {'p', "pricemap", "FILE",
163 gettext_noop ("mapping of possible prices"),
164 1, &GNUNET_GETOPT_set_filename, &fnprices},
165 {'r', "roundtime", "DURATION",
166 gettext_noop ("max duration per round"),
167 1, &GNUNET_GETOPT_set_relative_time, &dround},
168 {'s', "regtime", "DURATION",
169 gettext_noop ("duration until auction starts"),
170 1, &GNUNET_GETOPT_set_relative_time, &dstart},
172 gettext_noop ("number of items to sell\n"
173 "0 for first price auction\n"
174 ">0 for vickrey/M+1st price auction"),
175 1, &GNUNET_GETOPT_set_uint, &m},
176 {'u', "public", NULL,
177 gettext_noop ("public auction outcome"),
178 0, &GNUNET_GETOPT_set_one, &outcome},
179 {'i', "interactive", NULL,
180 gettext_noop ("keep running in foreground until auction completes"),
181 0, &GNUNET_GETOPT_set_one, &interactive},
182 GNUNET_GETOPT_OPTION_END
184 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
188 GNUNET_PROGRAM_run (argc, argv,
189 "gnunet-auction-create",
190 gettext_noop ("create a new auction and "
191 "start listening for bidders"),
195 GNUNET_free ((void*) argv);