tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / rps / gnunet-service-rps.c
index 8c50cf9d5ad95da884313a623bbbd97f8c442a18..c5530a1eb8b02e6ac399845222ccc46b481d6baf 100644 (file)
@@ -345,7 +345,7 @@ struct Sub
   unsigned int sampler_size_est_need;
 
   /**
-   * Time inverval the do_round task runs in.
+   * Time interval the do_round task runs in.
    */
   struct GNUNET_TIME_Relative round_interval;
 
@@ -354,16 +354,20 @@ struct Sub
    */
   struct RPS_Sampler *sampler;
 
+#ifdef TO_FILE_FULL
   /**
    * Name to log view to
    */
   char *file_name_view_log;
+#endif /* TO_FILE_FULL */
 
 #ifdef TO_FILE
+#ifdef TO_FILE_FULL
   /**
    * Name to log number of observed peers to
    */
   char *file_name_observed_log;
+#endif /* TO_FILE_FULL */
 
   /**
    * @brief Count the observed peers
@@ -2157,7 +2161,7 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list,
 
   for ( i = 0 ; i < *list_size ; i++ )
   {
-    if (0 == GNUNET_CRYPTO_cmp_peer_identity (&tmp[i], peer))
+    if (0 == GNUNET_memcmp (&tmp[i], peer))
     {
       if (i < *list_size -1)
       { /* Not at the last entry -- shift peers left */
@@ -2400,9 +2404,11 @@ hist_update (const struct GNUNET_PeerIdentity *ids,
     {
       clients_notify_stream_peer (sub, 1, &ids[i]);
     }
+#ifdef TO_FILE_FULL
     to_file (sub->file_name_view_log,
              "+%s\t(hist)",
              GNUNET_i2s_full (ids));
+#endif /* TO_FILE_FULL */
   }
   clients_notify_view_update (sub);
 }
@@ -2596,6 +2602,13 @@ insert_in_sampler (void *cls,
      * messages to it */
     //indicate_sending_intention (peer);
   }
+  if (sub == msub)
+  {
+    GNUNET_STATISTICS_update (stats,
+                              "# observed peers in gossip",
+                              1,
+                              GNUNET_NO);
+  }
 #ifdef TO_FILE
   sub->num_observed_peers++;
   GNUNET_CONTAINER_multipeermap_put
@@ -2605,11 +2618,17 @@ insert_in_sampler (void *cls,
      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
   uint32_t num_observed_unique_peers =
     GNUNET_CONTAINER_multipeermap_size (sub->observed_unique_peers);
+  GNUNET_STATISTICS_set (stats,
+                         "# unique peers in gossip",
+                         num_observed_unique_peers,
+                         GNUNET_NO);
+#ifdef TO_FILE_FULL
   to_file (sub->file_name_observed_log,
           "%" PRIu32 " %" PRIu32 " %f\n",
           sub->num_observed_peers,
           num_observed_unique_peers,
           1.0*num_observed_unique_peers/sub->num_observed_peers)
+#endif /* TO_FILE_FULL */
 #endif /* TO_FILE */
 }
 
@@ -2734,7 +2753,7 @@ clean_peer (struct Sub *sub,
         "Going to remove send channel to peer %s\n",
         GNUNET_i2s (peer));
     #if ENABLE_MALICIOUS
-    if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer,
+    if (0 != GNUNET_memcmp (&attacked_peer,
                                               peer))
       (void) destroy_sending_channel (get_peer_ctx (sub->peer_map,
                                                     peer));
@@ -2905,10 +2924,14 @@ new_sub (const struct GNUNET_HashCode *hash,
                                   round_interval);
 
   /* Logging of internals */
+#ifdef TO_FILE_FULL
   sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
+#endif /* TO_FILE_FULL */
 #ifdef TO_FILE
+#ifdef TO_FILE_FULL
   sub->file_name_observed_log = store_prefix_file_name (&own_identity,
                                                        "observed");
+#endif /* TO_FILE_FULL */
   sub->num_observed_peers = 0;
   sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1,
                                                                     GNUNET_NO);
@@ -2993,6 +3016,7 @@ destroy_sub (struct Sub *sub)
 
   /* Disconnect from cadet */
   GNUNET_CADET_close_port (sub->cadet_port);
+  sub->cadet_port= NULL;
 
   /* Clean up data structures for peers */
   RPS_sampler_destroy (sub->sampler);
@@ -3006,11 +3030,15 @@ destroy_sub (struct Sub *sub)
   peers_terminate (sub);
 
   /* Free leftover data structures */
+#ifdef TO_FILE_FULL
   GNUNET_free (sub->file_name_view_log);
   sub->file_name_view_log = NULL;
+#endif /* TO_FILE_FULL */
 #ifdef TO_FILE
+#ifdef TO_FILE_FULL
   GNUNET_free (sub->file_name_observed_log);
   sub->file_name_observed_log = NULL;
+#endif /* TO_FILE_FULL */
 
   /* Write push frequencies to disk */
   write_histogram_to_file (sub->push_recv,
@@ -3483,6 +3511,15 @@ handle_peer_push (void *cls,
   if (channel_ctx->peer_ctx->sub == msub)
   {
     GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO);
+    if (NULL != map_single_hop &&
+        GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
+                                                             peer))
+    {
+      GNUNET_STATISTICS_update (stats,
+                                "# push message received (multi-hop peer)",
+                                1,
+                                GNUNET_NO);
+    }
   }
 
   #if ENABLE_MALICIOUS
@@ -3570,7 +3607,7 @@ handle_peer_pull_request (void *cls,
 
   else if (2 == mal_type)
   { /* Try to partition network */
-    if (0 == GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
+    if (0 == GNUNET_memcmp (&attacked_peer, peer))
     {
       send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
     }
@@ -3864,6 +3901,15 @@ send_push (struct PeerContext *peer_ctx)
                               "# push send issued",
                               1,
                               GNUNET_NO);
+    if (NULL != map_single_hop &&
+        GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
+                                                             &peer_ctx->peer_id))
+    {
+      GNUNET_STATISTICS_update (stats,
+                                "# push send issued (multi-hop peer)",
+                                1,
+                                GNUNET_NO);
+    }
   }
 }
 
@@ -4182,18 +4228,20 @@ do_round (void *cls)
     GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO);
   }
   sub->do_round_task = NULL;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Printing view:\n");
+#ifdef TO_FILE_FULL
   to_file (sub->file_name_view_log,
            "___ new round ___");
+#endif /* TO_FILE_FULL */
   view_array = View_get_as_array (sub->view);
   for (i = 0; i < View_size (sub->view); i++)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "\t%s\n", GNUNET_i2s (&view_array[i]));
+#ifdef TO_FILE_FULL
     to_file (sub->file_name_view_log,
              "=%s\t(do round)",
              GNUNET_i2s_full (&view_array[i]));
+#endif /* TO_FILE_FULL */
   }
 
 
@@ -4268,8 +4316,10 @@ do_round (void *cls)
 
     /* Seems like recreating is the easiest way of emptying the peermap */
     View_clear (sub->view);
+#ifdef TO_FILE_FULL
     to_file (sub->file_name_view_log,
              "--- emptied ---");
+#endif /* TO_FILE_FULL */
 
     first_border  = GNUNET_MIN (ceil (alpha * sub->view_size_est_need),
                                 CustomPeerMap_size (sub->push_map));
@@ -4299,9 +4349,11 @@ do_round (void *cls)
             1,
             CustomPeerMap_get_peer_by_index (sub->push_map, permut[i]));
       }
+#ifdef TO_FILE_FULL
       to_file (sub->file_name_view_log,
                "+%s\t(push list)",
                GNUNET_i2s_full (&view_array[i]));
+#endif /* TO_FILE_FULL */
       // TODO change the peer_flags accordingly
     }
     GNUNET_free (permut);
@@ -4323,9 +4375,11 @@ do_round (void *cls)
             CustomPeerMap_get_peer_by_index (sub->pull_map,
                                              permut[i - first_border]));
       }
+#ifdef TO_FILE_FULL
       to_file (sub->file_name_view_log,
                "+%s\t(pull list)",
                GNUNET_i2s_full (&view_array[i]));
+#endif /* TO_FILE_FULL */
       // TODO change the peer_flags accordingly
     }
     GNUNET_free (permut);
@@ -4344,9 +4398,11 @@ do_round (void *cls)
     /* Clean peers that were removed from the view */
     for (i = 0; i < peers_to_clean_size; i++)
     {
+#ifdef TO_FILE_FULL
       to_file (sub->file_name_view_log,
                "-%s",
                GNUNET_i2s_full (&peers_to_clean[i]));
+#endif /* TO_FILE_FULL */
       clean_peer (sub, &peers_to_clean[i]);
     }
 
@@ -4388,7 +4444,7 @@ do_round (void *cls)
          HISTOGRAM_FILE_SLOTS);
   }
   // FIXME check bounds of histogram
-  sub->push_delta[(CustomPeerMap_size (sub->push_map) -
+  sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map) -
                    (alpha * sub->view_size_est_need)) +
                           (HISTOGRAM_FILE_SLOTS/2)]++;
   if (sub == msub)