From 81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 26 Jul 2011 18:22:54 +0000 Subject: start service --- src/peerinfo/Makefile.am | 3 ++- src/peerinfo/gnunet-service-peerinfo.c | 22 ++++++++++++++++++---- src/peerinfo/test_peerinfo_api.c | 19 ++++++++++--------- 3 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src/peerinfo') diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am index d58425730..2a078536f 100644 --- a/src/peerinfo/Makefile.am +++ b/src/peerinfo/Makefile.am @@ -13,7 +13,8 @@ lib_LTLIBRARIES = libgnunetpeerinfo.la libgnunetpeerinfo_la_SOURCES = \ peerinfo_api.c peerinfo.h \ - peerinfo_api_notify.c + peerinfo_api_notify.c \ + standalone-peerinfo.c libgnunetpeerinfo_la_LIBADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ 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 @@ */ #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) +#define WRITE_TO_DISK GNUNET_NO + /** * In-memory cache of known hosts. */ @@ -113,6 +115,7 @@ make_info_message (const struct HostEntry *he) } +#if WRITE_TO_DISK /** * Address iterator that causes expired entries to be discarded. * @@ -157,6 +160,7 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); return fn; } +#endif /** @@ -187,12 +191,14 @@ static void add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) { struct HostEntry *entry; +#if WRITE_TO_DISK char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const struct GNUNET_HELLO_Message *hello; struct GNUNET_HELLO_Message *hello_clean; int size; struct GNUNET_TIME_Absolute now; char *fn; +#endif entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); @@ -204,7 +210,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) GNUNET_NO); entry = GNUNET_malloc (sizeof (struct HostEntry)); entry->identity = *identity; - +#if WRITE_TO_DISK fn = get_host_filename (identity); if (GNUNET_DISK_file_test (fn) == GNUNET_YES) { @@ -230,6 +236,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) } } GNUNET_free (fn); +#endif GNUNET_CONTAINER_multihashmap_put (hostmap, &identity->hashPubKey, entry, @@ -237,7 +244,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) notify_all (entry); } - +#if WRITE_TO_DISK /** * Remove a file that should not be there. LOG * success or failure. @@ -319,7 +326,7 @@ cron_scan_directory_data_hosts (void *cls, GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, &cron_scan_directory_data_hosts, NULL); } - +#endif /** * Bind a host address (hello) to a hostId. @@ -331,7 +338,9 @@ static void bind_address (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello) { +#if WRITE_TO_DISK char *fn; +#endif struct HostEntry *host; struct GNUNET_HELLO_Message *mrg; struct GNUNET_TIME_Absolute delta; @@ -359,6 +368,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, GNUNET_free (host->hello); host->hello = mrg; } +#if WRITE_TO_DISK fn = get_host_filename (peer); if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) { @@ -374,6 +384,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, } GNUNET_free (fn); +#endif notify_all (host); } @@ -417,7 +428,7 @@ add_to_tc (void *cls, return GNUNET_YES; } - +#if WRITE_TO_DISK /** * @brief delete expired HELLO entries in data/hosts/ */ @@ -478,6 +489,7 @@ cron_clean_data_hosts (void *cls, GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, NULL); } +#endif /** @@ -683,6 +695,7 @@ run (void *cls, hostmap = GNUNET_CONTAINER_multihashmap_create (1024); stats = GNUNET_STATISTICS_create ("peerinfo", cfg); notify_list = GNUNET_SERVER_notification_context_create (server, 0); +#if WRITE_TO_DISK GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo", @@ -693,6 +706,7 @@ run (void *cls, &cron_scan_directory_data_hosts, NULL); GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &cron_clean_data_hosts, NULL); +#endif GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); GNUNET_SERVER_add_handlers (server, handlers); diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 460a3764d..15efeccad 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -44,6 +44,8 @@ static struct GNUNET_PEERINFO_Handle *h; static unsigned int retries; +struct GNUNET_PeerIdentity pid; + static int check_it (void *cls, const char *tname, @@ -83,7 +85,6 @@ static void add_peer () { struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; - struct GNUNET_PeerIdentity pid; struct GNUNET_HELLO_Message *h2; size_t agc; @@ -91,7 +92,7 @@ add_peer () memset (&pkey, 32, sizeof (pkey)); GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); - GNUNET_PEERINFO_add_peer (h, h2); + GNUNET_PEERINFO_standalone_add_peer (h, h2); GNUNET_free (h2); } @@ -108,7 +109,7 @@ process (void *cls, if (err_msg != NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Error in communication with PEERINFO service\n")); } @@ -121,8 +122,8 @@ process (void *cls, /* try again */ retries++; add_peer (); - ic = GNUNET_PEERINFO_iterate (h, - NULL, + ic = GNUNET_PEERINFO_standalone_iterate (h, + &pid, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); @@ -130,7 +131,7 @@ process (void *cls, } GNUNET_assert (peer == NULL); GNUNET_assert (2 == *ok); - GNUNET_PEERINFO_disconnect (h); + GNUNET_PEERINFO_standalone_disconnect (h); h = NULL; *ok = 0; return; @@ -153,11 +154,11 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c) { cfg = c; - h = GNUNET_PEERINFO_connect (cfg); + h = GNUNET_PEERINFO_standalone_connect (cfg); GNUNET_assert (h != NULL); add_peer (); - ic = GNUNET_PEERINFO_iterate (h, - NULL, + ic = GNUNET_PEERINFO_standalone_iterate (h, + &pid, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); -- cgit v1.2.3