-removing 2nd argument from GNUNET_CLIENT_disconnect as it was virtually always GNUNE...
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index 4fbef310578c376bb22d4ebd8066202a431b4a61..6a7248cb563b31333287e120d16aac30adce15f0 100644 (file)
@@ -59,7 +59,7 @@
  * production).  The associated code should also probably be removed
  * once we're done with experiments.
  */
-#define ENABLE_HISTOGRAM GNUNET_NO
+#define ENABLE_HISTOGRAM GNUNET_YES
 
 /**
  * Over how many values do we calculate the weighted average?
@@ -126,12 +126,6 @@ struct NSEPeerEntry
    */
   int previous_round;
 
-  /**
-   * Where a variable has been modified to cause a bug.
-   * FIXME DELETE AFTER DEBUG
-   */
-  const char *where;
-
 #if ENABLE_HISTOGRAM
 
   /**
@@ -575,14 +569,14 @@ transmit_ready (void *cls, size_t size, void *buf)
   unsigned int idx;
 
   peer_entry->th = NULL;
-  if (buf == NULL)
+  if (NULL == buf)
   {
     /* client disconnected */
     return 0;
   }
   GNUNET_assert (size >= sizeof (struct GNUNET_NSE_FloodMessage));
   idx = estimate_index;
-  if (peer_entry->previous_round == GNUNET_NO)
+  if (GNUNET_NO == peer_entry->previous_round)
   {
     idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
     peer_entry->previous_round = GNUNET_YES;
@@ -603,7 +597,7 @@ transmit_ready (void *cls, size_t size, void *buf)
     GNUNET_STATISTICS_update (stats,
                               "# flood messages not generated (lack of history)",
                               1, GNUNET_NO);
-    return 0; // FIXME necessary?
+    return 0;
   }
 #if DEBUG_NSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -641,6 +635,7 @@ transmit_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct NSEPeerEntry *peer_entry = cls;
 
   peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
+
   GNUNET_assert (NULL == peer_entry->th);
   peer_entry->th =
       GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_NO, NSE_PRIORITY,
@@ -722,14 +717,12 @@ schedule_current_round (void *cls, const GNUNET_HashCode * key, void *value)
   if (NULL != peer_entry->th)
   {
     peer_entry->previous_round = GNUNET_NO;
-    peer_entry->where =  __FUNCTION__;
     return GNUNET_OK;
   }
   if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task)
   {
     GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
     peer_entry->previous_round = GNUNET_NO;
-    peer_entry->where = __FUNCTION__;
   }
 #if ENABLE_HISTOGRAM
   if (peer_entry->received_messages > 1)
@@ -987,8 +980,11 @@ update_flood_times (void *cls, const GNUNET_HashCode * key, void *value)
   {
     /* still stuck in previous round, no point to update, check that
      * we are active here though... */
-    GNUNET_break (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task ||
-                  NULL != peer_entry->th);
+    if (GNUNET_SCHEDULER_NO_TASK == peer_entry->transmit_task &&
+                  NULL == peer_entry->th)
+    {
+        GNUNET_break (0);
+    }
     return GNUNET_OK;
   }
   if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1128,7 +1124,6 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
   {
     if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) {
       peer_entry->previous_round = GNUNET_NO;
-      peer_entry->where = __FUNCTION__ ;
     }
     /* push back our result now, that peer is spreading bad information... */
     if (NULL == peer_entry->th)
@@ -1154,6 +1149,11 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
   /* cancel transmission from us to this peer for this round */
   if (idx == estimate_index)
   {
+      /* Cancel transmission in the other direction, as this peer clearly has
+       up-to-date information already. Even if we didn't talk to this peer in
+       the previous round, we should no longer send it stale information as it
+       told us about the current round! */
+      peer_entry->previous_round = GNUNET_YES;
       /* cancel any activity for current round */
       if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
       {
@@ -1220,7 +1220,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
   peer_entry->transmit_task =
       GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task_cb,
                                     peer_entry);
-  peer_entry->where = "core connect";
   GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
 }
 
@@ -1333,7 +1332,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
   struct GNUNET_TIME_Absolute now;
   struct GNUNET_TIME_Absolute prev_time;
 
-  if (server == NULL)
+  if (NULL == server)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
     GNUNET_SCHEDULER_shutdown ();
@@ -1352,9 +1351,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
   estimate_count = 0;
   if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof))
   {
+    int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
     prev_time.abs_value =
         current_timestamp.abs_value - gnunet_nse_interval.rel_value;
-    setup_flood_message (estimate_index, prev_time);
+    setup_flood_message (idx, prev_time);
+    setup_flood_message (estimate_index, current_timestamp);
     estimate_count++;
   }
   flood_task =