peerinfo API change + changes in code using api
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 4 Apr 2013 12:02:43 +0000 (12:02 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 4 Apr 2013 12:02:43 +0000 (12:02 +0000)
src/dht/gnunet-service-dht_hello.c
src/hostlist/hostlist-server.c
src/include/gnunet_peerinfo_service.h
src/peerinfo-tool/gnunet-peerinfo.c
src/peerinfo/gnunet-service-peerinfo.c
src/peerinfo/peerinfo.h
src/peerinfo/peerinfo_api.c
src/peerinfo/peerinfo_api_notify.c
src/peerinfo/test_peerinfo_api.c
src/topology/gnunet-daemon-topology.c
src/transport/gnunet-service-transport_validation.c

index 19da79e23b81c654ff888183676cc3095fa8c662..32a99203fc5b07d13802900bcce495749fa6b5da 100644 (file)
@@ -98,7 +98,7 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
 void
 GDS_HELLO_init ()
 {
-  pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL);
+  pnc = GNUNET_PEERINFO_notify (GDS_cfg, GNUNET_NO, &process_hello, NULL);
   peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256, GNUNET_NO);
 }
 
index 2e94083f5a4ecbd63b76afc57421e4e630bce58c..081d3dac6faefba9698922346b39646a816dbc33 100644 (file)
@@ -673,7 +673,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
   if (daemon_handle_v6 != NULL)
     hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
 
-  notify = GNUNET_PEERINFO_notify (cfg, &process_notify, NULL);
+  notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL);
 
   return GNUNET_OK;
 }
index 49ba916001ab76c3bfecec34c6120f70a5bb3a1d..6aadba964fb5d4adc74e2f2beafd15fada9d718e 100644 (file)
@@ -145,28 +145,28 @@ struct GNUNET_PEERINFO_IteratorContext;
 
 
 /**
- * Call a method for each known matching host to get its HELLO.
- * The callback method will be invoked once for each matching
- * host and then finally once with a NULL pointer.  After that final
- * invocation, the iterator context must no longer be used.
+ * Call a method for each known matching host.  The callback method
+ * will be invoked once for each matching host and then finally once
+ * with a NULL pointer.  After that final invocation, the iterator
+ * context must no longer be used.
  *
- * Instead of calling this function with 'peer == NULL'
- * it is often better to use 'GNUNET_PEERINFO_notify'.
+ * Instead of calling this function with 'peer == NULL' it is often
+ * better to use 'GNUNET_PEERINFO_notify'.
  *
  * @param h handle to the peerinfo service
+ * @param include_friend_only include HELLO messages for friends only
  * @param peer restrict iteration to this peer only (can be NULL)
  * @param timeout how long to wait until timing out
  * @param callback the method to call for each peer
  * @param callback_cls closure for callback
- * @return NULL on error (in this case, 'callback' is never called!),
- *         otherwise an iterator context
+ * @return iterator context
  */
 struct GNUNET_PEERINFO_IteratorContext *
 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+                                                                                                int include_friend_only,
                          const struct GNUNET_PeerIdentity *peer,
                          struct GNUNET_TIME_Relative timeout,
-                         GNUNET_PEERINFO_Processor callback,
-                         void *callback_cls);
+                         GNUNET_PEERINFO_Processor callback, void *callback_cls);
 
 
 
@@ -189,17 +189,21 @@ struct GNUNET_PEERINFO_NotifyContext;
 /**
  * Call a method whenever our known information about peers
  * changes.  Initially calls the given function for all known
- * peers and then only signals changes.  Note that it is
- * possible (i.e. on disconnects) that the callback is called
- * twice with the same peer information.
+ * peers and then only signals changes.
+ *
+ * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO
+ * messages which are intended for friend to friend mode and which do not
+ * have to be gossiped. Otherwise these messages are skipped.
  *
  * @param cfg configuration to use
+ * @param include_friend_only include HELLO messages for friends only
  * @param callback the method to call for each peer
  * @param callback_cls closure for callback
  * @return NULL on error
  */
 struct GNUNET_PEERINFO_NotifyContext *
 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                                                                               int include_friend_only,
                         GNUNET_PEERINFO_Processor callback, void *callback_cls);
 
 
index 0cb434d8913ff16be8f516ff120fc9d99df2b0e9..39d6060c36d1467cfaad39b5064dce811ab676e2 100644 (file)
@@ -106,6 +106,11 @@ struct PrintContext
    */
   unsigned int off;
 
+  /**
+   * Hello was friend only, GNUNET_YES or GNUNET_NO
+   */
+  int friend_only;
+
 };
 
 
@@ -119,6 +124,11 @@ static int no_resolve;
  */
 static int be_quiet;
 
+/**
+ * Option '-f'
+ */
+static int include_friend_only;
+
 /**
  * Option '-s'
  */
@@ -211,7 +221,8 @@ dump_pc (struct PrintContext *pc)
   unsigned int i;
 
   GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
-  printf (_("Peer `%s'\n"), 
+  printf (_("%sPeer `%s'\n"),
+       (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
          (const char *) &enc);
   for (i = 0; i < pc->num_addresses; i++)
   {
@@ -321,6 +332,7 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
 {
   struct GNUNET_CRYPTO_HashAsciiEncoded enc;
   struct PrintContext *pc;
+  int friend_only;
 
   if (NULL == peer)
   {
@@ -335,10 +347,13 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
       tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
     return;
   }
+  friend_only = GNUNET_HELLO_is_friend_only (hello);
   if ((GNUNET_YES == be_quiet) || (NULL == hello))
   {
     GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
-    printf ("%s\n", (const char *) &enc);
+    printf ("%s%s\n",
+               (GNUNET_YES == friend_only) ? "F2F: " : "",
+               (const char *) &enc);
     return;
   }
   pc = GNUNET_malloc (sizeof (struct PrintContext));
@@ -346,6 +361,7 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
                               pc_tail, 
                               pc);
   pc->peer = *peer;
+  pc->friend_only = friend_only;
   GNUNET_HELLO_iterate_addresses (hello, 
                                  GNUNET_NO, 
                                  &count_address, 
@@ -608,7 +624,7 @@ state_machine (void *cls,
   {
     get_info = GNUNET_NO;
     GPI_plugins_load (cfg);
-    pic = GNUNET_PEERINFO_iterate (peerinfo, NULL,
+    pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, NULL,
                                   TIMEOUT,
                                   &print_peer_info, NULL);
     return;
@@ -627,7 +643,7 @@ state_machine (void *cls,
   if (GNUNET_YES == get_uri)
   {
     GPI_plugins_load (cfg);
-    pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity,
+    pic = GNUNET_PEERINFO_iterate (peerinfo,include_friend_only, &my_peer_identity,
                                   TIMEOUT, &print_my_uri, NULL);
     get_uri = GNUNET_NO;
     return;
@@ -653,6 +669,9 @@ main (int argc, char *const *argv)
     {'q', "quiet", NULL,
      gettext_noop ("output only the identity strings"),
      0, &GNUNET_GETOPT_set_one, &be_quiet},
+    {'f', "friends", NULL,
+     gettext_noop ("include friend-only information"),
+     0, &GNUNET_GETOPT_set_one, &include_friend_only},
     {'s', "self", NULL,
      gettext_noop ("output our own identity only"),
      0, &GNUNET_GETOPT_set_one, &get_self},
index 68024a90a996e9aa593b9717b3d895ccc1c4029b..55d4177cf1e3fed9a31f0ce0e61ab76f987be93c 100644 (file)
@@ -90,6 +90,7 @@ static char *networkIdDirectory;
 static struct GNUNET_STATISTICS_Handle *stats;
 
 
+
 /**
  * Notify all clients in the notify list about the
  * given host entry changing.
@@ -638,9 +639,10 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
 {
   const struct ListPeerMessage *lpm;
   struct GNUNET_SERVER_TransmitContext *tc;
+  int friend_only;
 
   lpm = (const struct ListPeerMessage *) message;
-  GNUNET_break (0 == ntohl (lpm->reserved));
+  friend_only = ntohl (lpm->include_friend_only);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
               "GET", GNUNET_i2s (&lpm->peer));
   tc = GNUNET_SERVER_transmit_context_create (client);
@@ -663,8 +665,12 @@ static void
 handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
                 const struct GNUNET_MessageHeader *message)
 {
+  const struct ListAllPeersMessage *lapm;
   struct GNUNET_SERVER_TransmitContext *tc;
+  int friend_only;
 
+  lapm = (const struct ListAllPeersMessage *) message;
+  friend_only = ntohl (lapm->include_friend_only);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
   tc = GNUNET_SERVER_transmit_context_create (client);
   GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc);
@@ -709,7 +715,11 @@ static void
 handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
                const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
+  struct NotifyMessage *nm = (struct NotifyMessage *) message;
+  int friend_only;
+
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
+       friend_only = ntohl (nm->include_friend_only);
   GNUNET_SERVER_client_mark_monitor (client);
   GNUNET_SERVER_notification_context_add (notify_list, client);
   GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client);
@@ -773,9 +783,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
      sizeof (struct ListPeerMessage)},
     {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
-     sizeof (struct GNUNET_MessageHeader)},
+     sizeof (struct ListAllPeersMessage)},
     {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
-     sizeof (struct GNUNET_MessageHeader)},
+     sizeof (struct NotifyMessage)},
     {NULL, NULL, 0, 0}
   };
   char *peerdir;
index e618487578677c04b2e37140c4c54a2ada0f1ca3..97f819aff86a3d02ea85d20a40194ef86a15b757 100644 (file)
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
- * Message requesting a listing of all known peers,
- * possibly restricted to the specified peer identity.
+ * Message requesting a listing of peers,
+ * restricted to the specified peer identity.
  */
 struct ListPeerMessage
 {
 
   /**
-   * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET or
-   * GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL.
+   * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET
+   * .
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Always zero.
+   * Include friend only HELLOs and peers in callbacks
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t include_friend_only GNUNET_PACKED;
 
   /**
    * Restrict to peers with this identity (optional
@@ -56,6 +56,42 @@ struct ListPeerMessage
 
 };
 
+/**
+ * Message requesting a listing of all peers,
+ * restricted to the specified peer identity.
+ */
+struct ListAllPeersMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Include friend only HELLOs and peers in callbacks
+   */
+  uint32_t include_friend_only GNUNET_PACKED;
+
+};
+
+
+/**
+ * Header for all communications.
+ */
+struct NotifyMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Include friend only HELLOs and peers in callbacks
+   */
+  uint32_t include_friend_only GNUNET_PACKED;
+
+};
+
 
 /**
  * Message used to inform the client about
index 175397c785321799766be174318819477bbb9acb..faa56e908b54e43b03acde434c13bbb6522210e5 100644 (file)
@@ -692,6 +692,7 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * better to use 'GNUNET_PEERINFO_notify'.
  *
  * @param h handle to the peerinfo service
+ * @param include_friend_only include HELLO messages for friends only
  * @param peer restrict iteration to this peer only (can be NULL)
  * @param timeout how long to wait until timing out
  * @param callback the method to call for each peer
@@ -700,11 +701,12 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 struct GNUNET_PEERINFO_IteratorContext *
 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+                                                                                                int include_friend_only,
                          const struct GNUNET_PeerIdentity *peer,
                          struct GNUNET_TIME_Relative timeout,
                          GNUNET_PEERINFO_Processor callback, void *callback_cls)
 {
-  struct GNUNET_MessageHeader *lapm;
+  struct ListAllPeersMessage *lapm;
   struct ListPeerMessage *lpm;
   struct GNUNET_PEERINFO_IteratorContext *ic;
   struct GNUNET_PEERINFO_AddContext *ac;
@@ -716,11 +718,12 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
          "Requesting list of peers from PEERINFO service\n");
     ac =
         GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
-                       sizeof (struct GNUNET_MessageHeader));
-    ac->size = sizeof (struct GNUNET_MessageHeader);
-    lapm = (struct GNUNET_MessageHeader *) &ac[1];
-    lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
-    lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
+                       sizeof (struct ListAllPeersMessage));
+    ac->size = sizeof (struct ListAllPeersMessage);
+    lapm = (struct ListAllPeersMessage *) &ac[1];
+    lapm->header.size = htons (sizeof (struct ListAllPeersMessage));
+    lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
+    lapm->include_friend_only = htonl (include_friend_only);
   }
   else
   {
@@ -734,6 +737,7 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
     lpm = (struct ListPeerMessage *) &ac[1];
     lpm->header.size = htons (sizeof (struct ListPeerMessage));
     lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
+    lpm->include_friend_only = htonl (include_friend_only);
     memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
     ic->have_peer = GNUNET_YES;
     ic->peer = *peer;
index b9e83c9e75344629f771fbc6371a4d977d07da3a..4520decfdcabd32fec6116770a266c974399b287 100644 (file)
@@ -69,6 +69,11 @@ struct GNUNET_PEERINFO_NotifyContext
    */
   GNUNET_SCHEDULER_TaskIdentifier task;
 
+  /**
+   * Include friend only HELLOs in callbacks
+   */
+
+  int include_friend_only;
 };
 
 
@@ -195,7 +200,7 @@ static size_t
 transmit_notify_request (void *cls, size_t size, void *buf)
 {
   struct GNUNET_PEERINFO_NotifyContext *nc = cls;
-  struct GNUNET_MessageHeader hdr;
+  struct NotifyMessage nm;
 
   nc->init = NULL;
   if (buf == NULL)
@@ -205,10 +210,11 @@ transmit_notify_request (void *cls, size_t size, void *buf)
     request_notifications (nc);
     return 0;
   }
-  GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
-  hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
-  hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
-  memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader));
+  GNUNET_assert (size >= sizeof (struct NotifyMessage));
+  nm.header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
+  nm.header.size = htons (sizeof (struct NotifyMessage));
+  nm.include_friend_only = htonl (nc->include_friend_only);
+  memcpy (buf, &nm, sizeof (struct NotifyMessage));
   receive_notifications (nc);
   return sizeof (struct GNUNET_MessageHeader);
 }
@@ -226,7 +232,7 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
   GNUNET_assert (NULL == nc->init);
   nc->init =
       GNUNET_CLIENT_notify_transmit_ready (nc->client,
-                                           sizeof (struct GNUNET_MessageHeader),
+                                           sizeof (struct NotifyMessage),
                                            GNUNET_TIME_UNIT_FOREVER_REL,
                                            GNUNET_YES, &transmit_notify_request,
                                            nc);
@@ -238,13 +244,19 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
  * changes.  Initially calls the given function for all known
  * peers and then only signals changes.
  *
+ * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO
+ * messages which are intended for friend to friend mode and which do not
+ * have to be gossiped. Otherwise these messages are skipped.
+ *
  * @param cfg configuration to use
+ * @param include_friend_only include HELLO messages for friends only
  * @param callback the method to call for each peer
  * @param callback_cls closure for callback
  * @return NULL on error
  */
 struct GNUNET_PEERINFO_NotifyContext *
 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                                                                               int include_friend_only,
                         GNUNET_PEERINFO_Processor callback, void *callback_cls)
 {
   struct GNUNET_PEERINFO_NotifyContext *nc;
@@ -262,6 +274,7 @@ GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
   nc->client = client;
   nc->callback = callback;
   nc->callback_cls = callback_cls;
+  nc->include_friend_only = include_friend_only;
   request_notifications (nc);
   return nc;
 }
index 59ea0ac8a7b2c6cf2b25e15159d05c67f211ab89..d3dcc2fd0ea0c037e88731acebb29eef9dae065e 100644 (file)
@@ -120,7 +120,7 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
       /* try again */
       retries++;
       add_peer ();
-      ic = GNUNET_PEERINFO_iterate (h, NULL,
+      ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
                                     GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 15), &process,
                                     cls);
@@ -152,7 +152,7 @@ run (void *cls,
   h = GNUNET_PEERINFO_connect (cfg);
   GNUNET_assert (NULL != h);
   add_peer ();
-  ic = GNUNET_PEERINFO_iterate (h, NULL,
+  ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
                                 GNUNET_TIME_relative_multiply
                                 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
 }
index c36108823303213a9f12489c7a9db757fd1a5654..61ee308f8273901eb23829fa5ccefd24e6b54638 100644 (file)
@@ -918,7 +918,7 @@ process_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
                 _("Error in communication with PEERINFO service: %s\n"),
                 err_msg);
     GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
-    peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
+    peerinfo_notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
     return;
   }
   GNUNET_assert (peer != NULL);
@@ -991,7 +991,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
   handle = server;
   my_identity = *my_id;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
-  peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
+  peerinfo_notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
 }
 
 
index a6c0b7f9da1aeb106d61a897e592581ec3d55c64..71a96de124248a19305720a2de10a42d4eb5b86d 100644 (file)
@@ -800,7 +800,7 @@ GST_validation_start (unsigned int max_fds)
                        validations_fast_start_threshold, validation_delay.rel_value);
   validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE,
                                                         GNUNET_NO);
-  pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);
+  pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL);
 }