fix #3284: support lib/MULTIARCH/ paths in installation, use GNUNET_PREFIX=@libdir...
[oweals/gnunet.git] / src / peerinfo / test_peerinfo_api_notify_friend_only.c
index 3afd50e68fa522a694ce740b6f0f9dbc19bd566d..f371078985554b87d2cae0e92c5d560553faf763 100644 (file)
@@ -57,6 +57,8 @@ static int res_cb_w_fo;
  */
 static int res_cb_wo_fo;
 
+struct GNUNET_PeerIdentity pid;
+
 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
 
 
@@ -142,6 +144,10 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
 
   if (NULL != peer)
   {
+               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n",
+                               GNUNET_i2s (peer),
+                               (NULL != hello) ? "with" : "without");
+
                if (NULL == hello)
                                return;
 
@@ -151,10 +157,14 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
                                return;
                }
 
-               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n",
-                               (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public");
-                       res_cb_w_fo = GNUNET_YES;
-                       GNUNET_SCHEDULER_add_now(&done, NULL);
+               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
+                               (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
+                               GNUNET_i2s (peer));
+               if (0 == memcmp (&pid, peer, sizeof (pid)))
+               {
+                               res_cb_w_fo = GNUNET_YES;
+                               GNUNET_SCHEDULER_add_now(&done, NULL);
+               }
                        return;
   }
 }
@@ -173,20 +183,27 @@ process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
 
   if (NULL != peer)
   {
+               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n",
+                               GNUNET_i2s (peer),
+                               (NULL != hello) ? "with" : "without");
+
                if (NULL == hello)
                                return;
 
-               GNUNET_break (0);
-
                if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))
                {
                                GNUNET_break (0);
                                return;
                }
 
-               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n",
-                               (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public");
-               res_cb_wo_fo = GNUNET_YES;
+               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
+                               (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
+                               GNUNET_i2s (peer));
+               if (0 == memcmp (&pid, peer, sizeof (pid)))
+               {
+                               GNUNET_break (0);
+                               res_cb_wo_fo = GNUNET_YES;
+               }
   }
 }
 
@@ -195,8 +212,6 @@ add_peer_done (void *cls, const char *emsg)
 {
        if (NULL == emsg)
        {
-                       pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
-                       pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
                        return;
        }
        else
@@ -212,15 +227,12 @@ add_peer_done (void *cls, const char *emsg)
 static void
 add_peer ()
 {
-  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
-  struct GNUNET_PeerIdentity pid;
   struct GNUNET_HELLO_Message *h2;
   size_t agc;
 
   agc = 2;
-  memset (&pkey, 32, sizeof (pkey));
-  GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
-  h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc, GNUNET_YES);
+  memset (&pid, 32, sizeof (pid));
+  h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_YES);
   GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL);
   GNUNET_free (h2);
 
@@ -229,12 +241,14 @@ add_peer ()
 
 
 static void
-run (void *cls, 
+run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
        timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
        mycfg = cfg;
+       pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
+       pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
   h = GNUNET_PEERINFO_connect (cfg);
   GNUNET_assert (NULL != h);
   add_peer ();