diff options
Diffstat (limited to 'src/peerinfo/gnunet-service-peerinfo.c')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index d5d153b65..0d86e483c 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -51,6 +51,8 @@ | |||
51 | */ | 51 | */ |
52 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) | 52 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) |
53 | 53 | ||
54 | #define WRITE_TO_DISK GNUNET_NO | ||
55 | |||
54 | /** | 56 | /** |
55 | * In-memory cache of known hosts. | 57 | * In-memory cache of known hosts. |
56 | */ | 58 | */ |
@@ -113,6 +115,7 @@ make_info_message (const struct HostEntry *he) | |||
113 | } | 115 | } |
114 | 116 | ||
115 | 117 | ||
118 | #if WRITE_TO_DISK | ||
116 | /** | 119 | /** |
117 | * Address iterator that causes expired entries to be discarded. | 120 | * Address iterator that causes expired entries to be discarded. |
118 | * | 121 | * |
@@ -157,6 +160,7 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
157 | "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); | 160 | "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); |
158 | return fn; | 161 | return fn; |
159 | } | 162 | } |
163 | #endif | ||
160 | 164 | ||
161 | 165 | ||
162 | /** | 166 | /** |
@@ -187,12 +191,14 @@ static void | |||
187 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | 191 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) |
188 | { | 192 | { |
189 | struct HostEntry *entry; | 193 | struct HostEntry *entry; |
194 | #if WRITE_TO_DISK | ||
190 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 195 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
191 | const struct GNUNET_HELLO_Message *hello; | 196 | const struct GNUNET_HELLO_Message *hello; |
192 | struct GNUNET_HELLO_Message *hello_clean; | 197 | struct GNUNET_HELLO_Message *hello_clean; |
193 | int size; | 198 | int size; |
194 | struct GNUNET_TIME_Absolute now; | 199 | struct GNUNET_TIME_Absolute now; |
195 | char *fn; | 200 | char *fn; |
201 | #endif | ||
196 | 202 | ||
197 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, | 203 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, |
198 | &identity->hashPubKey); | 204 | &identity->hashPubKey); |
@@ -204,7 +210,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
204 | GNUNET_NO); | 210 | GNUNET_NO); |
205 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 211 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
206 | entry->identity = *identity; | 212 | entry->identity = *identity; |
207 | 213 | #if WRITE_TO_DISK | |
208 | fn = get_host_filename (identity); | 214 | fn = get_host_filename (identity); |
209 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) | 215 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) |
210 | { | 216 | { |
@@ -230,6 +236,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
230 | } | 236 | } |
231 | } | 237 | } |
232 | GNUNET_free (fn); | 238 | GNUNET_free (fn); |
239 | #endif | ||
233 | GNUNET_CONTAINER_multihashmap_put (hostmap, | 240 | GNUNET_CONTAINER_multihashmap_put (hostmap, |
234 | &identity->hashPubKey, | 241 | &identity->hashPubKey, |
235 | entry, | 242 | entry, |
@@ -237,7 +244,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
237 | notify_all (entry); | 244 | notify_all (entry); |
238 | } | 245 | } |
239 | 246 | ||
240 | 247 | #if WRITE_TO_DISK | |
241 | /** | 248 | /** |
242 | * Remove a file that should not be there. LOG | 249 | * Remove a file that should not be there. LOG |
243 | * success or failure. | 250 | * success or failure. |
@@ -319,7 +326,7 @@ cron_scan_directory_data_hosts (void *cls, | |||
319 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, | 326 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, |
320 | &cron_scan_directory_data_hosts, NULL); | 327 | &cron_scan_directory_data_hosts, NULL); |
321 | } | 328 | } |
322 | 329 | #endif | |
323 | 330 | ||
324 | /** | 331 | /** |
325 | * Bind a host address (hello) to a hostId. | 332 | * Bind a host address (hello) to a hostId. |
@@ -331,7 +338,9 @@ static void | |||
331 | bind_address (const struct GNUNET_PeerIdentity *peer, | 338 | bind_address (const struct GNUNET_PeerIdentity *peer, |
332 | const struct GNUNET_HELLO_Message *hello) | 339 | const struct GNUNET_HELLO_Message *hello) |
333 | { | 340 | { |
341 | #if WRITE_TO_DISK | ||
334 | char *fn; | 342 | char *fn; |
343 | #endif | ||
335 | struct HostEntry *host; | 344 | struct HostEntry *host; |
336 | struct GNUNET_HELLO_Message *mrg; | 345 | struct GNUNET_HELLO_Message *mrg; |
337 | struct GNUNET_TIME_Absolute delta; | 346 | struct GNUNET_TIME_Absolute delta; |
@@ -359,6 +368,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
359 | GNUNET_free (host->hello); | 368 | GNUNET_free (host->hello); |
360 | host->hello = mrg; | 369 | host->hello = mrg; |
361 | } | 370 | } |
371 | #if WRITE_TO_DISK | ||
362 | fn = get_host_filename (peer); | 372 | fn = get_host_filename (peer); |
363 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) | 373 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) |
364 | { | 374 | { |
@@ -374,6 +384,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
374 | 384 | ||
375 | } | 385 | } |
376 | GNUNET_free (fn); | 386 | GNUNET_free (fn); |
387 | #endif | ||
377 | notify_all (host); | 388 | notify_all (host); |
378 | } | 389 | } |
379 | 390 | ||
@@ -417,7 +428,7 @@ add_to_tc (void *cls, | |||
417 | return GNUNET_YES; | 428 | return GNUNET_YES; |
418 | } | 429 | } |
419 | 430 | ||
420 | 431 | #if WRITE_TO_DISK | |
421 | /** | 432 | /** |
422 | * @brief delete expired HELLO entries in data/hosts/ | 433 | * @brief delete expired HELLO entries in data/hosts/ |
423 | */ | 434 | */ |
@@ -478,6 +489,7 @@ cron_clean_data_hosts (void *cls, | |||
478 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 489 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, |
479 | &cron_clean_data_hosts, NULL); | 490 | &cron_clean_data_hosts, NULL); |
480 | } | 491 | } |
492 | #endif | ||
481 | 493 | ||
482 | 494 | ||
483 | /** | 495 | /** |
@@ -683,6 +695,7 @@ run (void *cls, | |||
683 | hostmap = GNUNET_CONTAINER_multihashmap_create (1024); | 695 | hostmap = GNUNET_CONTAINER_multihashmap_create (1024); |
684 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); | 696 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); |
685 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); | 697 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); |
698 | #if WRITE_TO_DISK | ||
686 | GNUNET_assert (GNUNET_OK == | 699 | GNUNET_assert (GNUNET_OK == |
687 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 700 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
688 | "peerinfo", | 701 | "peerinfo", |
@@ -693,6 +706,7 @@ run (void *cls, | |||
693 | &cron_scan_directory_data_hosts, NULL); | 706 | &cron_scan_directory_data_hosts, NULL); |
694 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 707 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
695 | &cron_clean_data_hosts, NULL); | 708 | &cron_clean_data_hosts, NULL); |
709 | #endif | ||
696 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 710 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
697 | &shutdown_task, NULL); | 711 | &shutdown_task, NULL); |
698 | GNUNET_SERVER_add_handlers (server, handlers); | 712 | GNUNET_SERVER_add_handlers (server, handlers); |