aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c7
-rw-r--r--src/peerinfo/test_peerinfo_api_notify_friend_only.c40
2 files changed, 32 insertions, 15 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index d08f9920c..ce7a38a6d 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -455,9 +455,10 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext *
455 455
456 456
457/** 457/**
458 * Add a host to the list. 458 * Add a host to the list and notify clients about this event
459 * 459 *
460 * @param identity the identity of the host 460 * @param identity the identity of the host
461 * @return the HostEntry
461 */ 462 */
462static struct HostEntry * 463static struct HostEntry *
463add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) 464add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
@@ -469,6 +470,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
469 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); 470 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey);
470 if (NULL == entry) 471 if (NULL == entry)
471 { 472 {
473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity));
472 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, 474 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1,
473 GNUNET_NO); 475 GNUNET_NO);
474 entry = GNUNET_malloc (sizeof (struct HostEntry)); 476 entry = GNUNET_malloc (sizeof (struct HostEntry));
@@ -484,6 +486,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
484 entry->friend_only_hello = r.friend_only_hello; 486 entry->friend_only_hello = r.friend_only_hello;
485 GNUNET_free (fn); 487 GNUNET_free (fn);
486 } 488 }
489 notify_all (entry);
487 } 490 }
488 return entry; 491 return entry;
489} 492}
@@ -624,8 +627,6 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
624 GNUNET_i2s (&id)); 627 GNUNET_i2s (&id));
625 update_hello (&id, r.friend_only_hello); 628 update_hello (&id, r.friend_only_hello);
626 } 629 }
627
628 notify_all (entry);
629 dsc->matched++; 630 dsc->matched++;
630 return GNUNET_OK; 631 return GNUNET_OK;
631} 632}
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
index 3afd50e68..700bac755 100644
--- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -57,6 +57,8 @@ static int res_cb_w_fo;
57 */ 57 */
58static int res_cb_wo_fo; 58static int res_cb_wo_fo;
59 59
60struct GNUNET_PeerIdentity pid;
61
60GNUNET_SCHEDULER_TaskIdentifier timeout_task; 62GNUNET_SCHEDULER_TaskIdentifier timeout_task;
61 63
62 64
@@ -142,6 +144,10 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
142 144
143 if (NULL != peer) 145 if (NULL != peer)
144 { 146 {
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n",
148 GNUNET_i2s (peer),
149 (NULL != hello) ? "with" : "without");
150
145 if (NULL == hello) 151 if (NULL == hello)
146 return; 152 return;
147 153
@@ -151,10 +157,14 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
151 return; 157 return;
152 } 158 }
153 159
154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n", 160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
155 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public"); 161 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
156 res_cb_w_fo = GNUNET_YES; 162 GNUNET_i2s (peer));
157 GNUNET_SCHEDULER_add_now(&done, NULL); 163 if (0 == memcmp (&pid, peer, sizeof (pid)))
164 {
165 res_cb_w_fo = GNUNET_YES;
166 GNUNET_SCHEDULER_add_now(&done, NULL);
167 }
158 return; 168 return;
159 } 169 }
160} 170}
@@ -173,20 +183,27 @@ process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
173 183
174 if (NULL != peer) 184 if (NULL != peer)
175 { 185 {
186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n",
187 GNUNET_i2s (peer),
188 (NULL != hello) ? "with" : "without");
189
176 if (NULL == hello) 190 if (NULL == hello)
177 return; 191 return;
178 192
179 GNUNET_break (0);
180
181 if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) 193 if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))
182 { 194 {
183 GNUNET_break (0); 195 GNUNET_break (0);
184 return; 196 return;
185 } 197 }
186 198
187 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n", 199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
188 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public"); 200 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
189 res_cb_wo_fo = GNUNET_YES; 201 GNUNET_i2s (peer));
202 if (0 == memcmp (&pid, peer, sizeof (pid)))
203 {
204 GNUNET_break (0);
205 res_cb_wo_fo = GNUNET_YES;
206 }
190 } 207 }
191} 208}
192 209
@@ -195,8 +212,6 @@ add_peer_done (void *cls, const char *emsg)
195{ 212{
196 if (NULL == emsg) 213 if (NULL == emsg)
197 { 214 {
198 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
199 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
200 return; 215 return;
201 } 216 }
202 else 217 else
@@ -213,7 +228,6 @@ static void
213add_peer () 228add_peer ()
214{ 229{
215 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey; 230 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
216 struct GNUNET_PeerIdentity pid;
217 struct GNUNET_HELLO_Message *h2; 231 struct GNUNET_HELLO_Message *h2;
218 size_t agc; 232 size_t agc;
219 233
@@ -235,6 +249,8 @@ run (void *cls,
235{ 249{
236 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 250 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
237 mycfg = cfg; 251 mycfg = cfg;
252 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
253 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
238 h = GNUNET_PEERINFO_connect (cfg); 254 h = GNUNET_PEERINFO_connect (cfg);
239 GNUNET_assert (NULL != h); 255 GNUNET_assert (NULL != h);
240 add_peer (); 256 add_peer ();