diff options
Diffstat (limited to 'src/contrib/service/auction')
-rw-r--r-- | src/contrib/service/auction/.gitignore | 5 | ||||
-rw-r--r-- | src/contrib/service/auction/Makefile.am | 75 | ||||
-rw-r--r-- | src/contrib/service/auction/auction.conf | 4 | ||||
-rw-r--r-- | src/contrib/service/auction/auction.h | 77 | ||||
-rw-r--r-- | src/contrib/service/auction/gnunet-auction-create.c | 219 | ||||
-rw-r--r-- | src/contrib/service/auction/gnunet-auction-info.c | 86 | ||||
-rw-r--r-- | src/contrib/service/auction/gnunet-auction-join.c | 86 | ||||
-rw-r--r-- | src/contrib/service/auction/gnunet-service-auction.c | 155 | ||||
-rw-r--r-- | src/contrib/service/auction/test_auction_api.c | 44 | ||||
-rwxr-xr-x | src/contrib/service/auction/test_auction_create.sh | 80 |
10 files changed, 831 insertions, 0 deletions
diff --git a/src/contrib/service/auction/.gitignore b/src/contrib/service/auction/.gitignore new file mode 100644 index 000000000..5c3ec20cb --- /dev/null +++ b/src/contrib/service/auction/.gitignore | |||
@@ -0,0 +1,5 @@ | |||
1 | gnunet-auction-create | ||
2 | gnunet-auction-info | ||
3 | gnunet-auction-join | ||
4 | gnunet-service-auction | ||
5 | test_auction_api | ||
diff --git a/src/contrib/service/auction/Makefile.am b/src/contrib/service/auction/Makefile.am new file mode 100644 index 000000000..ec0ffaf33 --- /dev/null +++ b/src/contrib/service/auction/Makefile.am | |||
@@ -0,0 +1,75 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | pkgcfgdir = $(pkgdatadir)/config.d/ | ||
5 | |||
6 | libexecdir = $(pkglibdir)/libexec/ | ||
7 | |||
8 | |||
9 | pkgcfg_DATA = \ | ||
10 | auction.conf | ||
11 | |||
12 | if USE_COVERAGE | ||
13 | AM_CFLAGS = -fprofile-arcs -ftest-coverage | ||
14 | endif | ||
15 | |||
16 | |||
17 | libexec_PROGRAMS = \ | ||
18 | gnunet-service-auction | ||
19 | |||
20 | gnunet_service_auction_SOURCES = \ | ||
21 | gnunet-service-auction.c | ||
22 | gnunet_service_auction_LDADD = \ | ||
23 | $(top_builddir)/src/lib/util/libgnunetutil.la \ | ||
24 | -ljansson \ | ||
25 | $(GN_LIBINTL) | ||
26 | |||
27 | |||
28 | bin_PROGRAMS = \ | ||
29 | gnunet-auction-create \ | ||
30 | gnunet-auction-info \ | ||
31 | gnunet-auction-join | ||
32 | |||
33 | gnunet_auction_create_SOURCES = \ | ||
34 | gnunet-auction-create.c | ||
35 | gnunet_auction_create_LDADD = \ | ||
36 | $(top_builddir)/src/lib/util/libgnunetutil.la \ | ||
37 | -ljansson \ | ||
38 | $(GN_LIBINTL) | ||
39 | |||
40 | gnunet_auction_info_SOURCES = \ | ||
41 | gnunet-auction-info.c | ||
42 | gnunet_auction_info_LDADD = \ | ||
43 | $(top_builddir)/src/lib/util/libgnunetutil.la \ | ||
44 | -ljansson \ | ||
45 | $(GN_LIBINTL) | ||
46 | |||
47 | gnunet_auction_join_SOURCES = \ | ||
48 | gnunet-auction-join.c | ||
49 | gnunet_auction_join_LDADD = \ | ||
50 | $(top_builddir)/src/lib/util/libgnunetutil.la \ | ||
51 | -ljansson \ | ||
52 | $(GN_LIBINTL) | ||
53 | |||
54 | |||
55 | check_PROGRAMS = \ | ||
56 | test_auction_api | ||
57 | |||
58 | test_auction_api_SOURCES = \ | ||
59 | test_auction_api.c | ||
60 | test_auction_api_LDADD = \ | ||
61 | $(top_builddir)/src/lib/util/libgnunetutil.la | ||
62 | |||
63 | |||
64 | check_SCRIPTS = \ | ||
65 | test_auction_create.sh | ||
66 | |||
67 | EXTRA_DIST = \ | ||
68 | auction.h \ | ||
69 | auction.conf \ | ||
70 | $(check_SCRIPTS) | ||
71 | |||
72 | if ENABLE_TEST_RUN | ||
73 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | ||
74 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | ||
75 | endif | ||
diff --git a/src/contrib/service/auction/auction.conf b/src/contrib/service/auction/auction.conf new file mode 100644 index 000000000..deb9ac1fc --- /dev/null +++ b/src/contrib/service/auction/auction.conf | |||
@@ -0,0 +1,4 @@ | |||
1 | [auction] | ||
2 | START_ON_DEMAND = NO | ||
3 | BINARY = gnunet-service-auction | ||
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-auction.sock | ||
diff --git a/src/contrib/service/auction/auction.h b/src/contrib/service/auction/auction.h new file mode 100644 index 000000000..dc8b933f6 --- /dev/null +++ b/src/contrib/service/auction/auction.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001-2011 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Markus Teich | ||
23 | * @file auction/auction.h | ||
24 | * | ||
25 | * @brief Common type definitions for the auction service and API. | ||
26 | */ | ||
27 | #ifndef AUCTION_H | ||
28 | #define AUCTION_H | ||
29 | |||
30 | #include "gnunet_common.h" | ||
31 | |||
32 | GNUNET_NETWORK_STRUCT_BEGIN | ||
33 | |||
34 | /** | ||
35 | * Auction creation request sent from the client to the service | ||
36 | */ | ||
37 | struct GNUNET_AUCTION_ClientCreateMessage | ||
38 | { | ||
39 | /** | ||
40 | * Type: GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE | ||
41 | */ | ||
42 | struct GNUNET_MessageHeader header; | ||
43 | |||
44 | /** | ||
45 | * When should the auction start | ||
46 | */ | ||
47 | struct GNUNET_TIME_AbsoluteNBO time_start; | ||
48 | |||
49 | /** | ||
50 | * How long is each round allowed to be maximally | ||
51 | */ | ||
52 | struct GNUNET_TIME_RelativeNBO time_round; | ||
53 | |||
54 | /** | ||
55 | * Auction parameter m. | ||
56 | * 0 for first price auctions. | ||
57 | * >0 for M+1st price auctions. | ||
58 | */ | ||
59 | uint16_t m GNUNET_PACKED; | ||
60 | |||
61 | /** | ||
62 | * Should the auction outcome be public? | ||
63 | * 0 for private outcome auctions. | ||
64 | * 1 for public outcome auctions. | ||
65 | */ | ||
66 | uint16_t outcome_public GNUNET_PACKED; | ||
67 | |||
68 | /** | ||
69 | * TODO: Price mapping. | ||
70 | */ | ||
71 | |||
72 | /* DESCRIPTION text copied to end of this message */ | ||
73 | }; | ||
74 | |||
75 | GNUNET_NETWORK_STRUCT_END | ||
76 | |||
77 | #endif | ||
diff --git a/src/contrib/service/auction/gnunet-auction-create.c b/src/contrib/service/auction/gnunet-auction-create.c new file mode 100644 index 000000000..93947b89c --- /dev/null +++ b/src/contrib/service/auction/gnunet-auction-create.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file auction/gnunet-auction-create.c | ||
23 | * @brief tool to create a new auction | ||
24 | * @author Markus Teich | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | |||
28 | #include <float.h> | ||
29 | |||
30 | #include "gnunet_util_lib.h" | ||
31 | #include <jansson.h> | ||
32 | /* #include "gnunet_auction_service.h" */ | ||
33 | |||
34 | #define FIRST_PRICE 0 | ||
35 | #define OUTCOME_PRIVATE 0 | ||
36 | #define OUTCOME_PUBLIC 1 | ||
37 | |||
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 */ | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Main function that will be run by the scheduler. | ||
50 | * | ||
51 | * @param cls closure | ||
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 | ||
55 | */ | ||
56 | static void | ||
57 | run (void *cls, | ||
58 | char *const *args, | ||
59 | const char *cfgfile, | ||
60 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
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 | { | ||
72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
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 | { | ||
78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
79 | "required argument --roundtime missing or invalid (zero)\n"); | ||
80 | goto fail; | ||
81 | } | ||
82 | if (! fndesc) | ||
83 | { | ||
84 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
85 | "required argument --description missing\n"); | ||
86 | goto fail; | ||
87 | } | ||
88 | if (! fnprices) | ||
89 | { | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
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 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
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 | { | ||
106 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
107 | "validating pricemap: %s\n", jerr.text); | ||
108 | goto fail; | ||
109 | } | ||
110 | if (! (parray = json_object_get (pmap, "prices")) || ! json_is_array (parray)) | ||
111 | { | ||
112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
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 | { | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
126 | "validating pricearray index %d: %s\n", i, jerr.text); | ||
127 | goto fail; | ||
128 | } | ||
129 | if (prev <= cur) | ||
130 | { | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
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 | |||
142 | fail: | ||
143 | ret = 1; | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
149 | * The main function. | ||
150 | * | ||
151 | * @param argc number of arguments from the command line | ||
152 | * @param argv command line arguments | ||
153 | * @return 0 ok, 1 on error | ||
154 | */ | ||
155 | int | ||
156 | main (int argc, char *const *argv) | ||
157 | { | ||
158 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
159 | GNUNET_GETOPT_option_filename ('d', | ||
160 | "description", | ||
161 | "FILE", | ||
162 | gettext_noop ( | ||
163 | "description of the item to be sold"), | ||
164 | &fndesc), | ||
165 | |||
166 | GNUNET_GETOPT_option_filename ('p', | ||
167 | "pricemap", | ||
168 | "FILE", | ||
169 | gettext_noop ("mapping of possible prices"), | ||
170 | &fnprices), | ||
171 | |||
172 | GNUNET_GETOPT_option_relative_time ('r', | ||
173 | "roundtime", | ||
174 | "DURATION", | ||
175 | gettext_noop ("max duration per round"), | ||
176 | &dround), | ||
177 | |||
178 | GNUNET_GETOPT_option_relative_time ('s', | ||
179 | "regtime", | ||
180 | "DURATION", | ||
181 | gettext_noop ( | ||
182 | "duration until auction starts"), | ||
183 | &dstart), | ||
184 | GNUNET_GETOPT_option_uint ('m', | ||
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 | |||
192 | GNUNET_GETOPT_option_flag ('u', | ||
193 | "public", | ||
194 | gettext_noop ("public auction outcome"), | ||
195 | &outcome), | ||
196 | |||
197 | GNUNET_GETOPT_option_flag ('i', | ||
198 | "interactive", | ||
199 | gettext_noop ( | ||
200 | "keep running in foreground until auction completes"), | ||
201 | &interactive), | ||
202 | |||
203 | GNUNET_GETOPT_OPTION_END | ||
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 | } | ||
diff --git a/src/contrib/service/auction/gnunet-auction-info.c b/src/contrib/service/auction/gnunet-auction-info.c new file mode 100644 index 000000000..dded45ce6 --- /dev/null +++ b/src/contrib/service/auction/gnunet-auction-info.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file auction/gnunet-auction.c | ||
23 | * @brief auction for writing a tool | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | /* #include "gnunet_auction_service.h" */ | ||
29 | |||
30 | /** | ||
31 | * Final status code. | ||
32 | */ | ||
33 | static int ret; | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Main function that will be run by the scheduler. | ||
38 | * | ||
39 | * @param cls closure | ||
40 | * @param args remaining command-line arguments | ||
41 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
42 | * @param cfg configuration | ||
43 | */ | ||
44 | static void | ||
45 | run (void *cls, | ||
46 | char *const *args, | ||
47 | const char *cfgfile, | ||
48 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
49 | { | ||
50 | /* main code here */ | ||
51 | } | ||
52 | |||
53 | |||
54 | /** | ||
55 | * The main function. | ||
56 | * | ||
57 | * @param argc number of arguments from the command line | ||
58 | * @param argv command line arguments | ||
59 | * @return 0 ok, 1 on error | ||
60 | */ | ||
61 | int | ||
62 | main (int argc, char *const *argv) | ||
63 | { | ||
64 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
65 | /* FIMXE: add options here */ | ||
66 | GNUNET_GETOPT_OPTION_END | ||
67 | }; | ||
68 | |||
69 | if (GNUNET_OK != | ||
70 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
71 | &argc, &argv)) | ||
72 | return 2; | ||
73 | |||
74 | ret = (GNUNET_OK == | ||
75 | GNUNET_PROGRAM_run (argc, argv, | ||
76 | "gnunet-auction", | ||
77 | gettext_noop ("help text"), | ||
78 | options, | ||
79 | &run, | ||
80 | NULL)) ? ret : 1; | ||
81 | GNUNET_free_nz ((void *) argv); | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | |||
86 | /* end of gnunet-auction.c */ | ||
diff --git a/src/contrib/service/auction/gnunet-auction-join.c b/src/contrib/service/auction/gnunet-auction-join.c new file mode 100644 index 000000000..dded45ce6 --- /dev/null +++ b/src/contrib/service/auction/gnunet-auction-join.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file auction/gnunet-auction.c | ||
23 | * @brief auction for writing a tool | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | /* #include "gnunet_auction_service.h" */ | ||
29 | |||
30 | /** | ||
31 | * Final status code. | ||
32 | */ | ||
33 | static int ret; | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Main function that will be run by the scheduler. | ||
38 | * | ||
39 | * @param cls closure | ||
40 | * @param args remaining command-line arguments | ||
41 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
42 | * @param cfg configuration | ||
43 | */ | ||
44 | static void | ||
45 | run (void *cls, | ||
46 | char *const *args, | ||
47 | const char *cfgfile, | ||
48 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
49 | { | ||
50 | /* main code here */ | ||
51 | } | ||
52 | |||
53 | |||
54 | /** | ||
55 | * The main function. | ||
56 | * | ||
57 | * @param argc number of arguments from the command line | ||
58 | * @param argv command line arguments | ||
59 | * @return 0 ok, 1 on error | ||
60 | */ | ||
61 | int | ||
62 | main (int argc, char *const *argv) | ||
63 | { | ||
64 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
65 | /* FIMXE: add options here */ | ||
66 | GNUNET_GETOPT_OPTION_END | ||
67 | }; | ||
68 | |||
69 | if (GNUNET_OK != | ||
70 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
71 | &argc, &argv)) | ||
72 | return 2; | ||
73 | |||
74 | ret = (GNUNET_OK == | ||
75 | GNUNET_PROGRAM_run (argc, argv, | ||
76 | "gnunet-auction", | ||
77 | gettext_noop ("help text"), | ||
78 | options, | ||
79 | &run, | ||
80 | NULL)) ? ret : 1; | ||
81 | GNUNET_free_nz ((void *) argv); | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | |||
86 | /* end of gnunet-auction.c */ | ||
diff --git a/src/contrib/service/auction/gnunet-service-auction.c b/src/contrib/service/auction/gnunet-service-auction.c new file mode 100644 index 000000000..c20f0bdbe --- /dev/null +++ b/src/contrib/service/auction/gnunet-service-auction.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file auction/gnunet-service-auction.c | ||
23 | * @brief service for executing auctions | ||
24 | * @author Markus Teich | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | |||
29 | #include "auction.h" | ||
30 | |||
31 | /** | ||
32 | * Check AUCTION CREATE messages from the client. | ||
33 | * | ||
34 | * @param cls the client we received this message from | ||
35 | * @param msg the actual message received | ||
36 | * @return #GNUNET_OK (always) | ||
37 | */ | ||
38 | static int | ||
39 | check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg) | ||
40 | { | ||
41 | /* always well-formed due to arbitrary length description */ | ||
42 | return GNUNET_OK; | ||
43 | } | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Handler for CREATE messages. | ||
48 | * | ||
49 | * @param cls the client we received this message from | ||
50 | * @param msg the actual message received | ||
51 | */ | ||
52 | static void | ||
53 | handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg) | ||
54 | { | ||
55 | struct GNUNET_SERVICE_Client *client = cls; | ||
56 | // struct GNUNET_MQ_Handle *mq; | ||
57 | // struct GNUNET_MQ_Envelope *env; | ||
58 | // struct GNUNET_AUCTION_blabla em; | ||
59 | //uint16_t size; | ||
60 | |||
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
62 | "Received CREATE message from client\n"); | ||
63 | |||
64 | //size = ntohs (msg->header.size); | ||
65 | |||
66 | /**TODO: create auction and return auction object */ | ||
67 | // mq = GNUNET_SERVICE_client_get_mq (client); | ||
68 | // setup_info_message (&em); | ||
69 | // env = GNUNET_MQ_msg_copy (&em.header); | ||
70 | // GNUNET_MQ_send (mq, env); | ||
71 | |||
72 | GNUNET_SERVICE_client_continue (client); | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Task run during shutdown. | ||
78 | * | ||
79 | * @param cls unused | ||
80 | */ | ||
81 | static void | ||
82 | cleanup_task (void *cls) | ||
83 | { | ||
84 | /* FIXME: do clean up here */ | ||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Callback called when a client connects to the service. | ||
90 | * | ||
91 | * @param cls closure for the service | ||
92 | * @param c the new client that connected to the service | ||
93 | * @param mq the message queue used to send messages to the client | ||
94 | * @return @a c | ||
95 | */ | ||
96 | static void * | ||
97 | client_connect_cb (void *cls, | ||
98 | struct GNUNET_SERVICE_Client *c, | ||
99 | struct GNUNET_MQ_Handle *mq) | ||
100 | { | ||
101 | return c; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Callback called when a client disconnected from the service | ||
107 | * | ||
108 | * @param cls closure for the service | ||
109 | * @param c the client that disconnected | ||
110 | * @param internal_cls should be equal to @a c | ||
111 | */ | ||
112 | static void | ||
113 | client_disconnect_cb (void *cls, | ||
114 | struct GNUNET_SERVICE_Client *c, | ||
115 | void *internal_cls) | ||
116 | { | ||
117 | GNUNET_assert (c == internal_cls); | ||
118 | } | ||
119 | |||
120 | |||
121 | /** | ||
122 | * Process auction requests. | ||
123 | * | ||
124 | * @param cls closure | ||
125 | * @param cfg configuration to use | ||
126 | * @param service the initialized service | ||
127 | */ | ||
128 | static void | ||
129 | run (void *cls, | ||
130 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
131 | struct GNUNET_SERVICE_Handle *service) | ||
132 | { | ||
133 | /* FIXME: do setup here */ | ||
134 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Define "main" method using service macro. | ||
140 | */ | ||
141 | GNUNET_SERVICE_MAIN | ||
142 | ("auction", | ||
143 | GNUNET_SERVICE_OPTION_NONE, | ||
144 | &run, | ||
145 | &client_connect_cb, | ||
146 | &client_disconnect_cb, | ||
147 | NULL, | ||
148 | GNUNET_MQ_hd_var_size (create, | ||
149 | GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE, | ||
150 | struct GNUNET_AUCTION_ClientCreateMessage, | ||
151 | NULL), | ||
152 | GNUNET_MQ_handler_end ()) | ||
153 | |||
154 | |||
155 | /* end of gnunet-service-auction.c */ | ||
diff --git a/src/contrib/service/auction/test_auction_api.c b/src/contrib/service/auction/test_auction_api.c new file mode 100644 index 000000000..1eac9b5c4 --- /dev/null +++ b/src/contrib/service/auction/test_auction_api.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file auction/test_auction_api.c | ||
22 | * @brief testcase for auction.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | |||
26 | static int | ||
27 | check () | ||
28 | { | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | |||
33 | int | ||
34 | main (int argc, char *argv[]) | ||
35 | { | ||
36 | int ret; | ||
37 | |||
38 | ret = check (); | ||
39 | |||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | |||
44 | /* end of test_auction_api.c */ | ||
diff --git a/src/contrib/service/auction/test_auction_create.sh b/src/contrib/service/auction/test_auction_create.sh new file mode 100755 index 000000000..b0f4de738 --- /dev/null +++ b/src/contrib/service/auction/test_auction_create.sh | |||
@@ -0,0 +1,80 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | trap 'rm -f test.json' EXIT | ||
4 | |||
5 | |||
6 | # missing required cmdline args | ||
7 | gnunet-auction-create -r 1 -d foo -p test.json && exit 1 | ||
8 | gnunet-auction-create -s 1 -d foo -p test.json && exit 1 | ||
9 | gnunet-auction-create -s 1 -r 1 -p test.json && exit 1 | ||
10 | gnunet-auction-create -s 1 -r 1 -d foo && exit 1 | ||
11 | |||
12 | |||
13 | # no pricemap | ||
14 | rm -f test.json | ||
15 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
16 | |||
17 | |||
18 | # json errors | ||
19 | cat <<DOG >test.json | ||
20 | [,] | ||
21 | DOG | ||
22 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
23 | |||
24 | cat <<DOG >test.json | ||
25 | bla | ||
26 | DOG | ||
27 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
28 | |||
29 | |||
30 | # unexpected structures | ||
31 | cat <<DOG >test.json | ||
32 | {"foo": "bar"} | ||
33 | DOG | ||
34 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
35 | |||
36 | cat <<DOG >test.json | ||
37 | {"currency": "foo"} | ||
38 | DOG | ||
39 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
40 | |||
41 | cat <<DOG >test.json | ||
42 | {"prices": []} | ||
43 | DOG | ||
44 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
45 | |||
46 | cat <<DOG >test.json | ||
47 | {"currency": "foo", "prices": "bar"} | ||
48 | DOG | ||
49 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
50 | |||
51 | |||
52 | # wrong array content | ||
53 | cat <<DOG >test.json | ||
54 | {"currency": "foo", "prices": []} | ||
55 | DOG | ||
56 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
57 | |||
58 | cat <<DOG >test.json | ||
59 | {"currency": "foo", "prices": ["bar"]} | ||
60 | DOG | ||
61 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
62 | |||
63 | cat <<DOG >test.json | ||
64 | {"currency": "foo", "prices": [null]} | ||
65 | DOG | ||
66 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
67 | |||
68 | cat <<DOG >test.json | ||
69 | {"currency": "foo", "prices": [1, 2]} | ||
70 | DOG | ||
71 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 | ||
72 | |||
73 | |||
74 | # correct example | ||
75 | cat <<DOG >test.json | ||
76 | {"currency": "foo", "prices": [2, 1]} | ||
77 | DOG | ||
78 | gnunet-auction-create -s 1 -r 1 -d foo -p test.json || exit 1 | ||
79 | |||
80 | rm -f test.json | ||