-fixing #2578
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pr.c
index 2893481f2a28252fa2cc4390c3b159c9ca0f80cf..1df10abd296a3e7eb42bda6e39a3a62503efb5fc 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -530,6 +530,8 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
   else
     prio = 0;
   pr->public_data.priority -= prio;
+  pr->public_data.num_transmissions++;
+  pr->public_data.respect_offered += prio;
   gm->priority = htonl (prio);
   now = GNUNET_TIME_absolute_get ();
   ttl = (int64_t) (pr->public_data.ttl.abs_value - now.abs_value);
@@ -929,8 +931,8 @@ put_migration_continuation (void *cls, int success,
     if (min_expiration.abs_value > 0)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-                 "Asking to stop migration for %llu ms because datastore is full\n",
-                 (unsigned long long) GNUNET_TIME_absolute_get_remaining (min_expiration).rel_value);
+                 "Asking to stop migration for %s because datastore is full\n",
+                 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (min_expiration), GNUNET_YES));
       GSF_block_peer_migration_ (cp, min_expiration);      
     }
     else
@@ -943,8 +945,8 @@ put_migration_continuation (void *cls, int success,
                                                      ppd->migration_delay.rel_value);
       ppd->migration_delay = GNUNET_TIME_relative_multiply (ppd->migration_delay, 2);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-                 "Replicated content already exists locally, asking to stop migration for %llu ms\n",
-                 (unsigned long long) mig_pause.rel_value);
+                 "Replicated content already exists locally, asking to stop migration for %s\n",
+                 GNUNET_STRINGS_relative_time_to_string (mig_pause, GNUNET_YES));
       GSF_block_peer_migration_ (cp, GNUNET_TIME_relative_to_absolute (mig_pause));
     }
   }
@@ -1103,9 +1105,8 @@ warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GSF_PendingRequest *pr = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              _("Datastore lookup already took %llu ms!\n"),
-              (unsigned long long)
-              GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
+              _("Datastore lookup already took %s!\n"),
+              GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pr->qe_start), GNUNET_YES));
   pr->warn_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
                                     pr);
@@ -1124,9 +1125,8 @@ odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GSF_PendingRequest *pr = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              _("On-demand lookup already took %llu ms!\n"),
-              (unsigned long long)
-              GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
+              _("On-demand lookup already took %s!\n"),
+              GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pr->qe_start), GNUNET_YES));
   pr->warn_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
                                     &odc_warn_delay_task, pr);
@@ -1509,10 +1509,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
                             GNUNET_NO);
   /* now, lookup 'query' */
   prq.data = (const void *) &put[1];
-  if (NULL != cp)
-    prq.sender = cp;
-  else
-    prq.sender = NULL;
+  prq.sender = cp;
   prq.size = dsize;
   prq.type = type;
   prq.expiration = expiration;
@@ -1529,6 +1526,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
     GSF_get_peer_performance_data_ (cp)->respect += prq.priority;
   }
   if ((GNUNET_YES == active_to_migration) &&
+      (NULL != cp) &&
       (GNUNET_NO == test_put_load_too_high (prq.priority)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1551,7 +1549,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
       put_migration_continuation (pmc, GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
     }
   }
-  else
+  else if (NULL != cp)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Choosing not to keep content `%s' (%d/%d)\n",
@@ -1559,9 +1557,10 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
                 test_put_load_too_high (prq.priority));
   }
   putl = GNUNET_LOAD_get_load (datastore_put_load);
-  if ((NULL != (cp = prq.sender)) && (GNUNET_NO == prq.request_found) &&
-      ((GNUNET_YES != active_to_migration) ||
-       (putl > 2.5 * (1 + prq.priority))))
+  if ( (NULL != cp) && 
+       (GNUNET_NO == prq.request_found) &&
+       ( (GNUNET_YES != active_to_migration) ||
+        (putl > 2.5 * (1 + prq.priority)) ) )
   {
     if (GNUNET_YES != active_to_migration)
       putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
@@ -1596,19 +1595,15 @@ GSF_pending_request_init_ ()
                                              "MAX_PENDING_REQUESTS",
                                              &max_pending_requests))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _
-                ("Configuration fails to specify `%s', assuming default value."),
-                "MAX_PENDING_REQUESTS");
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
+                              "fs", "MAX_PENDING_REQUESTS");
   }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "ats", "WAN_QUOTA_OUT",
                                            &bps))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _
-                ("Configuration fails to specify `%s', assuming default value."),
-                "WAN_QUOTA_OUT");
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
+                              "ats", "WAN_QUOTA_OUT");
     bps = 65536;
   }
   /* queue size should be #queries we can have pending and satisfy within