aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-07-26 18:22:54 +0000
committerNathan S. Evans <evans@in.tum.de>2011-07-26 18:22:54 +0000
commit81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd (patch)
tree35b65462b9209af4bd610552bb485ad22487400e /src/peerinfo
parentbf4a9d8364675b34ac18d505e508006e2b773670 (diff)
downloadgnunet-81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd.tar.gz
gnunet-81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd.zip
start service
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/Makefile.am3
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c22
-rw-r--r--src/peerinfo/test_peerinfo_api.c19
3 files changed, 30 insertions, 14 deletions
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
13 13
14libgnunetpeerinfo_la_SOURCES = \ 14libgnunetpeerinfo_la_SOURCES = \
15 peerinfo_api.c peerinfo.h \ 15 peerinfo_api.c peerinfo.h \
16 peerinfo_api_notify.c 16 peerinfo_api_notify.c \
17 standalone-peerinfo.c
17libgnunetpeerinfo_la_LIBADD = \ 18libgnunetpeerinfo_la_LIBADD = \
18 $(top_builddir)/src/hello/libgnunethello.la \ 19 $(top_builddir)/src/hello/libgnunethello.la \
19 $(top_builddir)/src/util/libgnunetutil.la \ 20 $(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 @@
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
187add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) 191add_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
331bind_address (const struct GNUNET_PeerIdentity *peer, 338bind_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);
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;
44 44
45static unsigned int retries; 45static unsigned int retries;
46 46
47struct GNUNET_PeerIdentity pid;
48
47static int 49static int
48check_it (void *cls, 50check_it (void *cls,
49 const char *tname, 51 const char *tname,
@@ -83,7 +85,6 @@ static void
83add_peer () 85add_peer ()
84{ 86{
85 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 87 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
86 struct GNUNET_PeerIdentity pid;
87 struct GNUNET_HELLO_Message *h2; 88 struct GNUNET_HELLO_Message *h2;
88 size_t agc; 89 size_t agc;
89 90
@@ -91,7 +92,7 @@ add_peer ()
91 memset (&pkey, 32, sizeof (pkey)); 92 memset (&pkey, 32, sizeof (pkey));
92 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); 93 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
93 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); 94 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
94 GNUNET_PEERINFO_add_peer (h, h2); 95 GNUNET_PEERINFO_standalone_add_peer (h, h2);
95 GNUNET_free (h2); 96 GNUNET_free (h2);
96 97
97} 98}
@@ -108,7 +109,7 @@ process (void *cls,
108 109
109 if (err_msg != NULL) 110 if (err_msg != NULL)
110 { 111 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 _("Error in communication with PEERINFO service\n")); 113 _("Error in communication with PEERINFO service\n"));
113 } 114 }
114 115
@@ -121,8 +122,8 @@ process (void *cls,
121 /* try again */ 122 /* try again */
122 retries++; 123 retries++;
123 add_peer (); 124 add_peer ();
124 ic = GNUNET_PEERINFO_iterate (h, 125 ic = GNUNET_PEERINFO_standalone_iterate (h,
125 NULL, 126 &pid,
126 GNUNET_TIME_relative_multiply 127 GNUNET_TIME_relative_multiply
127 (GNUNET_TIME_UNIT_SECONDS, 15), 128 (GNUNET_TIME_UNIT_SECONDS, 15),
128 &process, cls); 129 &process, cls);
@@ -130,7 +131,7 @@ process (void *cls,
130 } 131 }
131 GNUNET_assert (peer == NULL); 132 GNUNET_assert (peer == NULL);
132 GNUNET_assert (2 == *ok); 133 GNUNET_assert (2 == *ok);
133 GNUNET_PEERINFO_disconnect (h); 134 GNUNET_PEERINFO_standalone_disconnect (h);
134 h = NULL; 135 h = NULL;
135 *ok = 0; 136 *ok = 0;
136 return; 137 return;
@@ -153,11 +154,11 @@ run (void *cls,
153 const struct GNUNET_CONFIGURATION_Handle *c) 154 const struct GNUNET_CONFIGURATION_Handle *c)
154{ 155{
155 cfg = c; 156 cfg = c;
156 h = GNUNET_PEERINFO_connect (cfg); 157 h = GNUNET_PEERINFO_standalone_connect (cfg);
157 GNUNET_assert (h != NULL); 158 GNUNET_assert (h != NULL);
158 add_peer (); 159 add_peer ();
159 ic = GNUNET_PEERINFO_iterate (h, 160 ic = GNUNET_PEERINFO_standalone_iterate (h,
160 NULL, 161 &pid,
161 GNUNET_TIME_relative_multiply 162 GNUNET_TIME_relative_multiply
162 (GNUNET_TIME_UNIT_SECONDS, 15), 163 (GNUNET_TIME_UNIT_SECONDS, 15),
163 &process, cls); 164 &process, cls);