diff options
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/Makefile.am | 4 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 16 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 43 |
3 files changed, 27 insertions, 36 deletions
diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am index a8621a2b0..3b534de70 100644 --- a/src/hostlist/Makefile.am +++ b/src/hostlist/Makefile.am | |||
@@ -10,12 +10,10 @@ if USE_COVERAGE | |||
10 | AM_CFLAGS = --coverage -O0 | 10 | AM_CFLAGS = --coverage -O0 |
11 | endif | 11 | endif |
12 | 12 | ||
13 | if HAVE_MHD | ||
14 | HOSTLIST_SERVER_SOURCES = \ | 13 | HOSTLIST_SERVER_SOURCES = \ |
15 | gnunet-daemon-hostlist_server.c gnunet-daemon-hostlist_server.h | 14 | gnunet-daemon-hostlist_server.c gnunet-daemon-hostlist_server.h |
16 | GN_LIBMHD = $(MHD_LIBS) | 15 | GN_LIBMHD = $(MHD_LIBS) |
17 | GN_CPPMHD = $(MHD_CFLAGS) | 16 | GN_CPPMHD = $(MHD_CFLAGS) |
18 | endif | ||
19 | 17 | ||
20 | if HAVE_LIBGNURL | 18 | if HAVE_LIBGNURL |
21 | libexec_PROGRAMS = \ | 19 | libexec_PROGRAMS = \ |
@@ -70,13 +68,11 @@ check_PROGRAMS = \ | |||
70 | endif | 68 | endif |
71 | endif | 69 | endif |
72 | 70 | ||
73 | if HAVE_MHD | ||
74 | if ENABLE_TEST_RUN | 71 | if ENABLE_TEST_RUN |
75 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 72 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
76 | TESTS = \ | 73 | TESTS = \ |
77 | $(check_PROGRAMS) | 74 | $(check_PROGRAMS) |
78 | endif | 75 | endif |
79 | endif | ||
80 | 76 | ||
81 | test_gnunet_daemon_hostlist_SOURCES = \ | 77 | test_gnunet_daemon_hostlist_SOURCES = \ |
82 | test_gnunet_daemon_hostlist.c | 78 | test_gnunet_daemon_hostlist.c |
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 704c796b4..54e070f89 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -30,8 +30,6 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | 32 | ||
33 | #if HAVE_MHD | ||
34 | |||
35 | #include "gnunet-daemon-hostlist_server.h" | 33 | #include "gnunet-daemon-hostlist_server.h" |
36 | 34 | ||
37 | /** | 35 | /** |
@@ -49,8 +47,6 @@ static int provide_hostlist; | |||
49 | */ | 47 | */ |
50 | static GNUNET_CORE_ConnectEventHandler server_ch; | 48 | static GNUNET_CORE_ConnectEventHandler server_ch; |
51 | 49 | ||
52 | #endif | ||
53 | |||
54 | /** | 50 | /** |
55 | * Set if we are allowed to learn about peers by accessing | 51 | * Set if we are allowed to learn about peers by accessing |
56 | * hostlist servers. | 52 | * hostlist servers. |
@@ -211,13 +207,11 @@ connect_handler (void *cls, | |||
211 | (*client_ch)(cls, | 207 | (*client_ch)(cls, |
212 | peer, | 208 | peer, |
213 | mq)); | 209 | mq)); |
214 | #if HAVE_MHD | ||
215 | if (NULL != server_ch) | 210 | if (NULL != server_ch) |
216 | GNUNET_assert (NULL == | 211 | GNUNET_assert (NULL == |
217 | (*server_ch)(cls, | 212 | (*server_ch)(cls, |
218 | peer, | 213 | peer, |
219 | mq)); | 214 | mq)); |
220 | #endif | ||
221 | return (void *) peer; | 215 | return (void *) peer; |
222 | } | 216 | } |
223 | 217 | ||
@@ -265,12 +259,10 @@ cleaning_task (void *cls) | |||
265 | { | 259 | { |
266 | GNUNET_HOSTLIST_client_stop (); | 260 | GNUNET_HOSTLIST_client_stop (); |
267 | } | 261 | } |
268 | #if HAVE_MHD | ||
269 | if (provide_hostlist) | 262 | if (provide_hostlist) |
270 | { | 263 | { |
271 | GNUNET_HOSTLIST_server_stop (); | 264 | GNUNET_HOSTLIST_server_stop (); |
272 | } | 265 | } |
273 | #endif | ||
274 | if (NULL != stats) | 266 | if (NULL != stats) |
275 | { | 267 | { |
276 | GNUNET_STATISTICS_destroy (stats, | 268 | GNUNET_STATISTICS_destroy (stats, |
@@ -306,9 +298,7 @@ run (void *cls, | |||
306 | }; | 298 | }; |
307 | 299 | ||
308 | if ((! bootstrapping) && (! learning) | 300 | if ((! bootstrapping) && (! learning) |
309 | #if HAVE_MHD | ||
310 | && (! provide_hostlist) | 301 | && (! provide_hostlist) |
311 | #endif | ||
312 | ) | 302 | ) |
313 | { | 303 | { |
314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -338,14 +328,12 @@ run (void *cls, | |||
338 | learning ? learn_handlers : no_learn_handlers); | 328 | learning ? learn_handlers : no_learn_handlers); |
339 | 329 | ||
340 | 330 | ||
341 | #if HAVE_MHD | ||
342 | if (provide_hostlist) | 331 | if (provide_hostlist) |
343 | GNUNET_HOSTLIST_server_start (cfg, | 332 | GNUNET_HOSTLIST_server_start (cfg, |
344 | stats, | 333 | stats, |
345 | core, | 334 | core, |
346 | &server_ch, | 335 | &server_ch, |
347 | advertising); | 336 | advertising); |
348 | #endif | ||
349 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, | 337 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, |
350 | NULL); | 338 | NULL); |
351 | 339 | ||
@@ -370,13 +358,11 @@ int | |||
370 | main (int argc, char *const *argv) | 358 | main (int argc, char *const *argv) |
371 | { | 359 | { |
372 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 360 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
373 | #if HAVE_MHD | ||
374 | GNUNET_GETOPT_option_flag ('a', | 361 | GNUNET_GETOPT_option_flag ('a', |
375 | "advertise", | 362 | "advertise", |
376 | gettext_noop ( | 363 | gettext_noop ( |
377 | "advertise our hostlist to other peers"), | 364 | "advertise our hostlist to other peers"), |
378 | &advertising), | 365 | &advertising), |
379 | #endif | ||
380 | GNUNET_GETOPT_option_flag ('b', | 366 | GNUNET_GETOPT_option_flag ('b', |
381 | "bootstrap", | 367 | "bootstrap", |
382 | gettext_noop ( | 368 | gettext_noop ( |
@@ -387,12 +373,10 @@ main (int argc, char *const *argv) | |||
387 | gettext_noop ( | 373 | gettext_noop ( |
388 | "enable learning about hostlist servers from other peers"), | 374 | "enable learning about hostlist servers from other peers"), |
389 | &learning), | 375 | &learning), |
390 | #if HAVE_MHD | ||
391 | GNUNET_GETOPT_option_flag ('p', | 376 | GNUNET_GETOPT_option_flag ('p', |
392 | "provide-hostlist", | 377 | "provide-hostlist", |
393 | gettext_noop ("provide a hostlist server"), | 378 | gettext_noop ("provide a hostlist server"), |
394 | &provide_hostlist), | 379 | &provide_hostlist), |
395 | #endif | ||
396 | GNUNET_GETOPT_OPTION_END | 380 | GNUNET_GETOPT_OPTION_END |
397 | }; | 381 | }; |
398 | 382 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index a5ff9f9fa..c2e8f5d88 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -1404,7 +1404,7 @@ load_hostlist_file () | |||
1404 | return; | 1404 | return; |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | rh = GNUNET_BIO_read_open (filename); | 1407 | rh = GNUNET_BIO_read_open_file (filename); |
1408 | if (NULL == rh) | 1408 | if (NULL == rh) |
1409 | { | 1409 | { |
1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -1417,13 +1417,17 @@ load_hostlist_file () | |||
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | counter = 0; | 1419 | counter = 0; |
1420 | struct GNUNET_BIO_ReadSpec rs[] = { | ||
1421 | GNUNET_BIO_read_spec_int32 ("times used", (int32_t *)×_used), | ||
1422 | GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality), | ||
1423 | GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used), | ||
1424 | GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created), | ||
1425 | GNUNET_BIO_read_spec_int32 ("hellos returned", (int32_t *) &hellos_returned), | ||
1426 | GNUNET_BIO_read_spec_end (), | ||
1427 | }; | ||
1420 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && | 1428 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1421 | (NULL != uri) && | 1429 | (NULL != uri) && |
1422 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1430 | (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs))) |
1423 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && | ||
1424 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && | ||
1425 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && | ||
1426 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) | ||
1427 | { | 1431 | { |
1428 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); | 1432 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); |
1429 | hostlist->hello_count = hellos_returned; | 1433 | hostlist->hello_count = hellos_returned; |
@@ -1494,7 +1498,7 @@ save_hostlist_file (int shutdown) | |||
1494 | GNUNET_free (filename); | 1498 | GNUNET_free (filename); |
1495 | return; | 1499 | return; |
1496 | } | 1500 | } |
1497 | wh = GNUNET_BIO_write_open (filename); | 1501 | wh = GNUNET_BIO_write_open_file (filename); |
1498 | if (NULL == wh) | 1502 | if (NULL == wh) |
1499 | { | 1503 | { |
1500 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1504 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1521,14 +1525,21 @@ save_hostlist_file (int shutdown) | |||
1521 | } | 1525 | } |
1522 | if (GNUNET_YES == ok) | 1526 | if (GNUNET_YES == ok) |
1523 | { | 1527 | { |
1524 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1528 | struct GNUNET_BIO_WriteSpec ws[] = { |
1525 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1529 | GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri), |
1526 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) || | 1530 | GNUNET_BIO_write_spec_int32 ("times used", (int32_t *) &pos->times_used), |
1527 | (GNUNET_OK != | 1531 | GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality), |
1528 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) || | 1532 | GNUNET_BIO_write_spec_int64 ( |
1529 | (GNUNET_OK != | 1533 | "last usage", |
1530 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) || | 1534 | (int64_t *) &pos->time_last_usage.abs_value_us), |
1531 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) | 1535 | GNUNET_BIO_write_spec_int64 ( |
1536 | "creation time", | ||
1537 | (int64_t *) &pos->time_creation.abs_value_us), | ||
1538 | GNUNET_BIO_write_spec_int32 ("hellos count", | ||
1539 | (int32_t *) &pos->hello_count), | ||
1540 | GNUNET_BIO_write_spec_end (), | ||
1541 | }; | ||
1542 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1532 | { | 1543 | { |
1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1544 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1534 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1545 | _ ("Error writing hostlist URIs to file `%s'\n"), |
@@ -1548,7 +1559,7 @@ save_hostlist_file (int shutdown) | |||
1548 | counter, | 1559 | counter, |
1549 | GNUNET_YES); | 1560 | GNUNET_YES); |
1550 | 1561 | ||
1551 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1562 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1563 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1553 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1564 | _ ("Error writing hostlist URIs to file `%s'\n"), |
1554 | filename); | 1565 | filename); |