safety check
[oweals/gnunet.git] / src / transport / test_quota_compliance.c
index e4b728007a0f727a69aafd703ac166954d02f605..4da5ab48d6b79c61f84f081133627cc303880132 100644 (file)
@@ -361,6 +361,7 @@ measurement_end (void *cls,
           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   static int strike_counter;
+  static int failed_measurement_counter = 1;
   unsigned long long  quota_allowed = 0;
   int delta = 0;
 
@@ -390,10 +391,10 @@ measurement_end (void *cls,
          quota_allowed = current_quota_p2;
 
 
-  if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/10))
+  if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/3))
          delta = MEASUREMENT_SOFT_LIMIT;
   else
-         delta = (quota_allowed/10);
+         delta = (quota_allowed/3);
 
   /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
   if ((total_bytes_sent/(duration.rel_value / 1000)) < 100)
@@ -408,7 +409,17 @@ measurement_end (void *cls,
                          (total_bytes_sent/(duration.rel_value / 1000)/1024),
                          total_bytes_sent/(duration.rel_value / 1000));
          ok = 1;
-         end();
+         failed_measurement_counter--;
+         if (failed_measurement_counter < 0)
+         {
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                 "\nQuota measurement failed and no free strike: %i\n",failed_measurement_counter);
+                 end();
+                 return;
+         }
+         else
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                 "\nQuota measurement failed and %i free strikes\n",failed_measurement_counter);
   }
 
   /* Throughput is bigger than allowed quota + some extra*/
@@ -424,8 +435,17 @@ measurement_end (void *cls,
                          (total_bytes_sent/(duration.rel_value / 1000)/1024), 
                          total_bytes_sent/(duration.rel_value / 1000));
          ok = 1;
-         end();
-         return;
+         failed_measurement_counter--;
+         if (failed_measurement_counter < 0)
+         {
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                 "\nQuota measurement failed and no free strike: %i\n",failed_measurement_counter);
+                 end();
+                 return;
+         }
+         else
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                 "\nQuota measurement failed and %i free strikes\n",failed_measurement_counter);
   }
   else
   {
@@ -433,12 +453,15 @@ measurement_end (void *cls,
                          "\nQuota compliance ok: \n"\
                          "Quota allowed: %10llu kB/s\n"\
                          "Throughput   : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes_sent/(duration.rel_value / 1000)/1024));
+         if (failed_measurement_counter < 2)
+                 failed_measurement_counter++;
          ok = 0;
   }
 
   if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
   {
-         strike_counter++;
+         if (failed_measurement_counter < 2)
+                 failed_measurement_counter++;
          if (strike_counter == 2)
          {
                  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -457,7 +480,6 @@ measurement_end (void *cls,
          end();
          return;
   }
-
   if (is_asymmetric_send_constant == GNUNET_YES)
   {
    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
@@ -601,6 +623,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
   GNUNET_assert (p->th != NULL);
 }
 
+static size_t
+notify_ready_connect (void *cls, size_t size, void *buf)
+{
+  return 0;
+}
 
 static void
 exchange_hello_last (void *cls,
@@ -616,6 +643,14 @@ exchange_hello_last (void *cls,
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
                                       message, &me->id));
+
+  GNUNET_assert(NULL != (transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
+                                          &p1.id,
+                                          sizeof (struct GNUNET_MessageHeader), 0,
+                                          TIMEOUT,
+                                          &notify_ready_connect,
+                                          NULL)));
+
   /* both HELLOs exchanged, get ready to test transmission! */
 }
 
@@ -766,7 +801,7 @@ main (int argc, char *argv[])
          else
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","symmetric");
   }
-  if (is_udp == GNUNET_YES)
+  else if (is_udp == GNUNET_YES)
   {
          if (is_asymmetric_recv_constant == GNUNET_YES)
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_recv_constant");
@@ -775,7 +810,7 @@ main (int argc, char *argv[])
          else
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","symmetric");
   }
-  if (is_http == GNUNET_YES)
+  else if (is_http == GNUNET_YES)
   {
          if (is_asymmetric_recv_constant == GNUNET_YES)
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_recv_constant");
@@ -784,7 +819,7 @@ main (int argc, char *argv[])
          else
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","symmetric");
   }
-  if (is_https == GNUNET_YES)
+  else if (is_https == GNUNET_YES)
   {
          if (is_asymmetric_recv_constant == GNUNET_YES)
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_recv_constant");
@@ -793,6 +828,10 @@ main (int argc, char *argv[])
          else
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric");
   }
+  else
+  {
+         GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","noplugin","none");
+  }
 
   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");