diff options
Diffstat (limited to 'src/dht/gnunet-dht-put.c')
-rw-r--r-- | src/dht/gnunet-dht-put.c | 173 |
1 files changed, 86 insertions, 87 deletions
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index 0432dc4a0..330b2ac62 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file dht/gnunet-dht-put.c | 21 | * @file dht/gnunet-dht-put.c |
22 | * @brief search for data in DHT | 22 | * @brief search for data in DHT |
@@ -89,13 +89,13 @@ static char *data; | |||
89 | 89 | ||
90 | 90 | ||
91 | static void | 91 | static void |
92 | shutdown_task (void *cls) | 92 | shutdown_task(void *cls) |
93 | { | 93 | { |
94 | if (NULL != dht_handle) | 94 | if (NULL != dht_handle) |
95 | { | 95 | { |
96 | GNUNET_DHT_disconnect (dht_handle); | 96 | GNUNET_DHT_disconnect(dht_handle); |
97 | dht_handle = NULL; | 97 | dht_handle = NULL; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
@@ -105,9 +105,9 @@ shutdown_task (void *cls) | |||
105 | * @param cls closure | 105 | * @param cls closure |
106 | */ | 106 | */ |
107 | static void | 107 | static void |
108 | message_sent_cont (void *cls) | 108 | message_sent_cont(void *cls) |
109 | { | 109 | { |
110 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 110 | GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
@@ -120,52 +120,52 @@ message_sent_cont (void *cls) | |||
120 | * @param c configuration | 120 | * @param c configuration |
121 | */ | 121 | */ |
122 | static void | 122 | static void |
123 | run (void *cls, | 123 | run(void *cls, |
124 | char *const *args, | 124 | char *const *args, |
125 | const char *cfgfile, | 125 | const char *cfgfile, |
126 | const struct GNUNET_CONFIGURATION_Handle *c) | 126 | const struct GNUNET_CONFIGURATION_Handle *c) |
127 | { | 127 | { |
128 | enum GNUNET_DHT_RouteOption ro; | 128 | enum GNUNET_DHT_RouteOption ro; |
129 | 129 | ||
130 | cfg = c; | 130 | cfg = c; |
131 | if ((NULL == query_key) || (NULL == data)) | 131 | if ((NULL == query_key) || (NULL == data)) |
132 | { | 132 | { |
133 | fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n")); | 133 | fprintf(stderr, "%s", _("Must provide KEY and DATA for DHT put!\n")); |
134 | ret = 1; | 134 | ret = 1; |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | 137 | ||
138 | if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) | 138 | if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1))) |
139 | { | 139 | { |
140 | fprintf (stderr, _ ("Could not connect to DHT service!\n")); | 140 | fprintf(stderr, _("Could not connect to DHT service!\n")); |
141 | ret = 1; | 141 | ret = 1; |
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */ | 144 | if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */ |
145 | query_type = GNUNET_BLOCK_TYPE_TEST; | 145 | query_type = GNUNET_BLOCK_TYPE_TEST; |
146 | 146 | ||
147 | GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); | 147 | GNUNET_CRYPTO_hash(query_key, strlen(query_key), &key); |
148 | 148 | ||
149 | if (verbose) | 149 | if (verbose) |
150 | fprintf (stderr, | 150 | fprintf(stderr, |
151 | _ ("Issuing put request for `%s' with data `%s'!\n"), | 151 | _("Issuing put request for `%s' with data `%s'!\n"), |
152 | query_key, | 152 | query_key, |
153 | data); | 153 | data); |
154 | ro = GNUNET_DHT_RO_NONE; | 154 | ro = GNUNET_DHT_RO_NONE; |
155 | if (demultixplex_everywhere) | 155 | if (demultixplex_everywhere) |
156 | ro |= GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; | 156 | ro |= GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; |
157 | if (record_route) | 157 | if (record_route) |
158 | ro |= GNUNET_DHT_RO_RECORD_ROUTE; | 158 | ro |= GNUNET_DHT_RO_RECORD_ROUTE; |
159 | GNUNET_DHT_put (dht_handle, | 159 | GNUNET_DHT_put(dht_handle, |
160 | &key, | 160 | &key, |
161 | replication, | 161 | replication, |
162 | ro, | 162 | ro, |
163 | query_type, | 163 | query_type, |
164 | strlen (data), | 164 | strlen(data), |
165 | data, | 165 | data, |
166 | GNUNET_TIME_relative_to_absolute (expiration), | 166 | GNUNET_TIME_relative_to_absolute(expiration), |
167 | &message_sent_cont, | 167 | &message_sent_cont, |
168 | NULL); | 168 | NULL); |
169 | } | 169 | } |
170 | 170 | ||
171 | /** | 171 | /** |
@@ -176,65 +176,64 @@ run (void *cls, | |||
176 | * @return 0 ok, 1 on error | 176 | * @return 0 ok, 1 on error |
177 | */ | 177 | */ |
178 | int | 178 | int |
179 | main (int argc, char *const *argv) | 179 | main(int argc, char *const *argv) |
180 | { | 180 | { |
181 | |||
182 | struct GNUNET_GETOPT_CommandLineOption options[] = | 181 | struct GNUNET_GETOPT_CommandLineOption options[] = |
183 | {GNUNET_GETOPT_option_string ('d', | 182 | { GNUNET_GETOPT_option_string('d', |
184 | "data", | 183 | "data", |
185 | "DATA", | 184 | "DATA", |
186 | gettext_noop ( | 185 | gettext_noop( |
187 | "the data to insert under the key"), | 186 | "the data to insert under the key"), |
188 | &data), | 187 | &data), |
189 | GNUNET_GETOPT_option_relative_time ( | 188 | GNUNET_GETOPT_option_relative_time( |
190 | 'e', | 189 | 'e', |
191 | "expiration", | 190 | "expiration", |
192 | "EXPIRATION", | 191 | "EXPIRATION", |
193 | gettext_noop ("how long to store this entry in the dht (in seconds)"), | 192 | gettext_noop("how long to store this entry in the dht (in seconds)"), |
194 | &expiration), | 193 | &expiration), |
195 | GNUNET_GETOPT_option_string ('k', | 194 | GNUNET_GETOPT_option_string('k', |
196 | "key", | 195 | "key", |
197 | "KEY", | 196 | "KEY", |
198 | gettext_noop ("the query key"), | 197 | gettext_noop("the query key"), |
199 | &query_key), | 198 | &query_key), |
200 | GNUNET_GETOPT_option_flag ('x', | 199 | GNUNET_GETOPT_option_flag('x', |
201 | "demultiplex", | 200 | "demultiplex", |
202 | gettext_noop ( | 201 | gettext_noop( |
203 | "use DHT's demultiplex everywhere option"), | 202 | "use DHT's demultiplex everywhere option"), |
204 | &demultixplex_everywhere), | 203 | &demultixplex_everywhere), |
205 | GNUNET_GETOPT_option_uint ('r', | 204 | GNUNET_GETOPT_option_uint('r', |
206 | "replication", | 205 | "replication", |
207 | "LEVEL", | 206 | "LEVEL", |
208 | gettext_noop ("how many replicas to create"), | 207 | gettext_noop("how many replicas to create"), |
209 | &replication), | 208 | &replication), |
210 | GNUNET_GETOPT_option_flag ('R', | 209 | GNUNET_GETOPT_option_flag('R', |
211 | "record", | 210 | "record", |
212 | gettext_noop ("use DHT's record route option"), | 211 | gettext_noop("use DHT's record route option"), |
213 | &record_route), | 212 | &record_route), |
214 | GNUNET_GETOPT_option_uint ('t', | 213 | GNUNET_GETOPT_option_uint('t', |
215 | "type", | 214 | "type", |
216 | "TYPE", | 215 | "TYPE", |
217 | gettext_noop ("the type to insert data as"), | 216 | gettext_noop("the type to insert data as"), |
218 | &query_type), | 217 | &query_type), |
219 | GNUNET_GETOPT_option_verbose (&verbose), | 218 | GNUNET_GETOPT_option_verbose(&verbose), |
220 | GNUNET_GETOPT_OPTION_END}; | 219 | GNUNET_GETOPT_OPTION_END }; |
221 | 220 | ||
222 | 221 | ||
223 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 222 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
224 | return 2; | 223 | return 2; |
225 | expiration = GNUNET_TIME_UNIT_HOURS; | 224 | expiration = GNUNET_TIME_UNIT_HOURS; |
226 | return (GNUNET_OK == | 225 | return (GNUNET_OK == |
227 | GNUNET_PROGRAM_run ( | 226 | GNUNET_PROGRAM_run( |
228 | argc, | 227 | argc, |
229 | argv, | 228 | argv, |
230 | "gnunet-dht-put", | 229 | "gnunet-dht-put", |
231 | gettext_noop ( | 230 | gettext_noop( |
232 | "Issue a PUT request to the GNUnet DHT insert DATA under KEY."), | 231 | "Issue a PUT request to the GNUnet DHT insert DATA under KEY."), |
233 | options, | 232 | options, |
234 | &run, | 233 | &run, |
235 | NULL)) | 234 | NULL)) |
236 | ? ret | 235 | ? ret |
237 | : 1; | 236 | : 1; |
238 | } | 237 | } |
239 | 238 | ||
240 | /* end of gnunet-dht-put.c */ | 239 | /* end of gnunet-dht-put.c */ |