diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hostlist/gnunet-daemon-hostlist.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 267 |
1 files changed, 136 insertions, 131 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 7c1863dc0..bf6542d7f 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -102,7 +102,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
102 | * unaligned!) | 102 | * unaligned!) |
103 | * 4) address (address-length bytes; possibly unaligned!) | 103 | * 4) address (address-length bytes; possibly unaligned!) |
104 | */ | 104 | */ |
105 | struct GNUNET_HOSTLIST_ADV_Message { | 105 | struct GNUNET_HOSTLIST_ADV_Message |
106 | { | ||
106 | /** | 107 | /** |
107 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. | 108 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. |
108 | */ | 109 | */ |
@@ -129,8 +130,8 @@ static struct GNUNET_PeerIdentity me; | |||
129 | * @param my_identity our peer's identity | 130 | * @param my_identity our peer's identity |
130 | */ | 131 | */ |
131 | static void | 132 | static void |
132 | core_init(void *cls, | 133 | core_init (void *cls, |
133 | const struct GNUNET_PeerIdentity *my_identity) | 134 | const struct GNUNET_PeerIdentity *my_identity) |
134 | { | 135 | { |
135 | me = *my_identity; | 136 | me = *my_identity; |
136 | } | 137 | } |
@@ -144,26 +145,26 @@ core_init(void *cls, | |||
144 | * @return #GNUNET_OK if message is well-formed | 145 | * @return #GNUNET_OK if message is well-formed |
145 | */ | 146 | */ |
146 | static int | 147 | static int |
147 | check_advertisement(void *cls, | 148 | check_advertisement (void *cls, |
148 | const struct GNUNET_MessageHeader *message) | 149 | const struct GNUNET_MessageHeader *message) |
149 | { | 150 | { |
150 | size_t size; | 151 | size_t size; |
151 | size_t uri_size; | 152 | size_t uri_size; |
152 | const char *uri; | 153 | const char *uri; |
153 | 154 | ||
154 | size = ntohs(message->size); | 155 | size = ntohs (message->size); |
155 | if (size <= sizeof(struct GNUNET_MessageHeader)) | 156 | if (size <= sizeof(struct GNUNET_MessageHeader)) |
156 | { | 157 | { |
157 | GNUNET_break_op(0); | 158 | GNUNET_break_op (0); |
158 | return GNUNET_SYSERR; | 159 | return GNUNET_SYSERR; |
159 | } | 160 | } |
160 | uri = (const char *)&message[1]; | 161 | uri = (const char *) &message[1]; |
161 | uri_size = size - sizeof(struct GNUNET_MessageHeader); | 162 | uri_size = size - sizeof(struct GNUNET_MessageHeader); |
162 | if (uri[uri_size - 1] != '\0') | 163 | if (uri[uri_size - 1] != '\0') |
163 | { | 164 | { |
164 | GNUNET_break_op(0); | 165 | GNUNET_break_op (0); |
165 | return GNUNET_SYSERR; | 166 | return GNUNET_SYSERR; |
166 | } | 167 | } |
167 | return GNUNET_OK; | 168 | return GNUNET_OK; |
168 | } | 169 | } |
169 | 170 | ||
@@ -176,13 +177,13 @@ check_advertisement(void *cls, | |||
176 | * @return #GNUNET_OK on success | 177 | * @return #GNUNET_OK on success |
177 | */ | 178 | */ |
178 | static void | 179 | static void |
179 | handle_advertisement(void *cls, | 180 | handle_advertisement (void *cls, |
180 | const struct GNUNET_MessageHeader *message) | 181 | const struct GNUNET_MessageHeader *message) |
181 | { | 182 | { |
182 | const char *uri = (const char *)&message[1]; | 183 | const char *uri = (const char *) &message[1]; |
183 | 184 | ||
184 | GNUNET_assert(NULL != client_adv_handler); | 185 | GNUNET_assert (NULL != client_adv_handler); |
185 | (void)(*client_adv_handler)(uri); | 186 | (void) (*client_adv_handler)(uri); |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
@@ -196,28 +197,28 @@ handle_advertisement(void *cls, | |||
196 | * @return peer | 197 | * @return peer |
197 | */ | 198 | */ |
198 | static void * | 199 | static void * |
199 | connect_handler(void *cls, | 200 | connect_handler (void *cls, |
200 | const struct GNUNET_PeerIdentity *peer, | 201 | const struct GNUNET_PeerIdentity *peer, |
201 | struct GNUNET_MQ_Handle *mq) | 202 | struct GNUNET_MQ_Handle *mq) |
202 | { | 203 | { |
203 | if (0 == GNUNET_memcmp(&me, | 204 | if (0 == GNUNET_memcmp (&me, |
204 | peer)) | 205 | peer)) |
205 | return NULL; | 206 | return NULL; |
206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
207 | "A new peer connected, notifying client and server\n"); | 208 | "A new peer connected, notifying client and server\n"); |
208 | if (NULL != client_ch) | 209 | if (NULL != client_ch) |
209 | GNUNET_assert(NULL == | 210 | GNUNET_assert (NULL == |
210 | (*client_ch)(cls, | 211 | (*client_ch)(cls, |
211 | peer, | 212 | peer, |
212 | mq)); | 213 | mq)); |
213 | #if HAVE_MHD | 214 | #if HAVE_MHD |
214 | if (NULL != server_ch) | 215 | if (NULL != server_ch) |
215 | GNUNET_assert(NULL == | 216 | GNUNET_assert (NULL == |
216 | (*server_ch)(cls, | 217 | (*server_ch)(cls, |
217 | peer, | 218 | peer, |
218 | mq)); | 219 | mq)); |
219 | #endif | 220 | #endif |
220 | return (void *)peer; | 221 | return (void *) peer; |
221 | } | 222 | } |
222 | 223 | ||
223 | 224 | ||
@@ -229,12 +230,12 @@ connect_handler(void *cls, | |||
229 | * @param peer peer identity this notification is about | 230 | * @param peer peer identity this notification is about |
230 | */ | 231 | */ |
231 | static void | 232 | static void |
232 | disconnect_handler(void *cls, | 233 | disconnect_handler (void *cls, |
233 | const struct GNUNET_PeerIdentity *peer, | 234 | const struct GNUNET_PeerIdentity *peer, |
234 | void *internal_cls) | 235 | void *internal_cls) |
235 | { | 236 | { |
236 | if (0 == GNUNET_memcmp(&me, | 237 | if (0 == GNUNET_memcmp (&me, |
237 | peer)) | 238 | peer)) |
238 | return; | 239 | return; |
239 | /* call hostlist client disconnect handler */ | 240 | /* call hostlist client disconnect handler */ |
240 | if (NULL != client_dh) | 241 | if (NULL != client_dh) |
@@ -251,31 +252,31 @@ disconnect_handler(void *cls, | |||
251 | * @param cls NULL | 252 | * @param cls NULL |
252 | */ | 253 | */ |
253 | static void | 254 | static void |
254 | cleaning_task(void *cls) | 255 | cleaning_task (void *cls) |
255 | { | 256 | { |
256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
257 | "Hostlist daemon is shutting down\n"); | 258 | "Hostlist daemon is shutting down\n"); |
258 | if (NULL != core) | 259 | if (NULL != core) |
259 | { | 260 | { |
260 | GNUNET_CORE_disconnect(core); | 261 | GNUNET_CORE_disconnect (core); |
261 | core = NULL; | 262 | core = NULL; |
262 | } | 263 | } |
263 | if (bootstrapping) | 264 | if (bootstrapping) |
264 | { | 265 | { |
265 | GNUNET_HOSTLIST_client_stop(); | 266 | GNUNET_HOSTLIST_client_stop (); |
266 | } | 267 | } |
267 | #if HAVE_MHD | 268 | #if HAVE_MHD |
268 | if (provide_hostlist) | 269 | if (provide_hostlist) |
269 | { | 270 | { |
270 | GNUNET_HOSTLIST_server_stop(); | 271 | GNUNET_HOSTLIST_server_stop (); |
271 | } | 272 | } |
272 | #endif | 273 | #endif |
273 | if (NULL != stats) | 274 | if (NULL != stats) |
274 | { | 275 | { |
275 | GNUNET_STATISTICS_destroy(stats, | 276 | GNUNET_STATISTICS_destroy (stats, |
276 | GNUNET_NO); | 277 | GNUNET_NO); |
277 | stats = NULL; | 278 | stats = NULL; |
278 | } | 279 | } |
279 | } | 280 | } |
280 | 281 | ||
281 | 282 | ||
@@ -288,72 +289,73 @@ cleaning_task(void *cls) | |||
288 | * @param cfg configuration | 289 | * @param cfg configuration |
289 | */ | 290 | */ |
290 | static void | 291 | static void |
291 | run(void *cls, | 292 | run (void *cls, |
292 | char *const *args, | 293 | char *const *args, |
293 | const char *cfgfile, | 294 | const char *cfgfile, |
294 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 295 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
295 | { | 296 | { |
296 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 297 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
297 | GNUNET_MQ_hd_var_size(advertisement, | 298 | GNUNET_MQ_hd_var_size (advertisement, |
298 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 299 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
299 | struct GNUNET_MessageHeader, | 300 | struct GNUNET_MessageHeader, |
300 | NULL), | 301 | NULL), |
301 | GNUNET_MQ_handler_end() | 302 | GNUNET_MQ_handler_end () |
302 | }; | 303 | }; |
303 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { | 304 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { |
304 | GNUNET_MQ_handler_end() | 305 | GNUNET_MQ_handler_end () |
305 | }; | 306 | }; |
306 | 307 | ||
307 | if ((!bootstrapping) && (!learning) | 308 | if ((! bootstrapping) && (! learning) |
308 | #if HAVE_MHD | 309 | #if HAVE_MHD |
309 | && (!provide_hostlist) | 310 | && (! provide_hostlist) |
310 | #endif | 311 | #endif |
311 | ) | 312 | ) |
312 | { | 313 | { |
313 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
314 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); | 315 | _ ( |
315 | return; | 316 | "None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); |
316 | } | 317 | return; |
317 | stats = GNUNET_STATISTICS_create("hostlist", cfg); | 318 | } |
319 | stats = GNUNET_STATISTICS_create ("hostlist", cfg); | ||
318 | if (NULL == stats) | 320 | if (NULL == stats) |
319 | { | 321 | { |
320 | GNUNET_break(0); | 322 | GNUNET_break (0); |
321 | return; | 323 | return; |
322 | } | 324 | } |
323 | if (bootstrapping) | 325 | if (bootstrapping) |
324 | GNUNET_HOSTLIST_client_start(cfg, | 326 | GNUNET_HOSTLIST_client_start (cfg, |
325 | stats, | 327 | stats, |
326 | &client_ch, | 328 | &client_ch, |
327 | &client_dh, | 329 | &client_dh, |
328 | &client_adv_handler, | 330 | &client_adv_handler, |
329 | learning); | 331 | learning); |
330 | core = | 332 | core = |
331 | GNUNET_CORE_connect(cfg, | 333 | GNUNET_CORE_connect (cfg, |
332 | NULL, | 334 | NULL, |
333 | &core_init, | 335 | &core_init, |
334 | &connect_handler, | 336 | &connect_handler, |
335 | &disconnect_handler, | 337 | &disconnect_handler, |
336 | learning ? learn_handlers : no_learn_handlers); | 338 | learning ? learn_handlers : no_learn_handlers); |
337 | 339 | ||
338 | 340 | ||
339 | #if HAVE_MHD | 341 | #if HAVE_MHD |
340 | if (provide_hostlist) | 342 | if (provide_hostlist) |
341 | GNUNET_HOSTLIST_server_start(cfg, | 343 | GNUNET_HOSTLIST_server_start (cfg, |
342 | stats, | 344 | stats, |
343 | core, | 345 | core, |
344 | &server_ch, | 346 | &server_ch, |
345 | advertising); | 347 | advertising); |
346 | #endif | 348 | #endif |
347 | GNUNET_SCHEDULER_add_shutdown(&cleaning_task, | 349 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, |
348 | NULL); | 350 | NULL); |
349 | 351 | ||
350 | if (NULL == core) | 352 | if (NULL == core) |
351 | { | 353 | { |
352 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
353 | _("Failed to connect to `%s' service.\n"), "core"); | 355 | _ ("Failed to connect to `%s' service.\n"), "core"); |
354 | GNUNET_SCHEDULER_shutdown(); | 356 | GNUNET_SCHEDULER_shutdown (); |
355 | return; | 357 | return; |
356 | } | 358 | } |
357 | } | 359 | } |
358 | 360 | ||
359 | 361 | ||
@@ -365,46 +367,49 @@ run(void *cls, | |||
365 | * @return 0 ok, 1 on error | 367 | * @return 0 ok, 1 on error |
366 | */ | 368 | */ |
367 | int | 369 | int |
368 | main(int argc, char *const *argv) | 370 | main (int argc, char *const *argv) |
369 | { | 371 | { |
370 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 372 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
371 | #if HAVE_MHD | 373 | #if HAVE_MHD |
372 | GNUNET_GETOPT_option_flag('a', | 374 | GNUNET_GETOPT_option_flag ('a', |
373 | "advertise", | 375 | "advertise", |
374 | gettext_noop("advertise our hostlist to other peers"), | 376 | gettext_noop ( |
375 | &advertising), | 377 | "advertise our hostlist to other peers"), |
378 | &advertising), | ||
376 | #endif | 379 | #endif |
377 | GNUNET_GETOPT_option_flag('b', | 380 | GNUNET_GETOPT_option_flag ('b', |
378 | "bootstrap", | 381 | "bootstrap", |
379 | gettext_noop("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 382 | gettext_noop ( |
380 | &bootstrapping), | 383 | "bootstrap using hostlists (it is highly recommended that you always use this option)"), |
381 | GNUNET_GETOPT_option_flag('e', | 384 | &bootstrapping), |
382 | "enable-learning", | 385 | GNUNET_GETOPT_option_flag ('e', |
383 | gettext_noop("enable learning about hostlist servers from other peers"), | 386 | "enable-learning", |
384 | &learning), | 387 | gettext_noop ( |
388 | "enable learning about hostlist servers from other peers"), | ||
389 | &learning), | ||
385 | #if HAVE_MHD | 390 | #if HAVE_MHD |
386 | GNUNET_GETOPT_option_flag('p', | 391 | GNUNET_GETOPT_option_flag ('p', |
387 | "provide-hostlist", | 392 | "provide-hostlist", |
388 | gettext_noop("provide a hostlist server"), | 393 | gettext_noop ("provide a hostlist server"), |
389 | &provide_hostlist), | 394 | &provide_hostlist), |
390 | #endif | 395 | #endif |
391 | GNUNET_GETOPT_OPTION_END | 396 | GNUNET_GETOPT_OPTION_END |
392 | }; | 397 | }; |
393 | 398 | ||
394 | int ret; | 399 | int ret; |
395 | 400 | ||
396 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 401 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
397 | return 2; | 402 | return 2; |
398 | 403 | ||
399 | GNUNET_log_setup("hostlist", "WARNING", NULL); | 404 | GNUNET_log_setup ("hostlist", "WARNING", NULL); |
400 | ret = | 405 | ret = |
401 | (GNUNET_OK == | 406 | (GNUNET_OK == |
402 | GNUNET_PROGRAM_run(argc, argv, | 407 | GNUNET_PROGRAM_run (argc, argv, |
403 | "hostlist", | 408 | "hostlist", |
404 | _("GNUnet hostlist server and client"), | 409 | _ ("GNUnet hostlist server and client"), |
405 | options, | 410 | options, |
406 | &run, NULL)) ? 0 : 1; | 411 | &run, NULL)) ? 0 : 1; |
407 | GNUNET_free((void*)argv); | 412 | GNUNET_free ((void*) argv); |
408 | return ret; | 413 | return ret; |
409 | } | 414 | } |
410 | 415 | ||