gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26203 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r26203 - gnunet/src/ats
Date: Mon, 25 Feb 2013 16:38:01 +0100

Author: wachs
Date: 2013-02-25 16:38:01 +0100 (Mon, 25 Feb 2013)
New Revision: 26203

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/test_ats_mlp.c
Log:
changes


Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-02-25 14:58:33 UTC 
(rev 26202)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-02-25 15:38:01 UTC 
(rev 26203)
@@ -1026,7 +1026,7 @@
   if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active))
   {
        /* Address switch: Activate address*/
-       LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : enabling address\n", (1 == 
mlp_use) ? "[x]": "[ ]", mlp_bw);
+       LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == 
mlp_use) ? "[x]": "[ ]", mlp_bw);
                address->active = GNUNET_YES;
                address->assigned_bw_in.value__ = htonl (mlp_bw);
                address->assigned_bw_out.value__ = htonl (mlp_bw);
@@ -1035,7 +1035,7 @@
   else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active))
   {
                /* Address switch: Disable address*/
-       LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : disabling address\n", (1 == 
mlp_use) ? "[x]": "[ ]", mlp_bw);
+       LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", (1 == 
mlp_use) ? "[x]": "[ ]", mlp_bw);
                address->active = GNUNET_NO;
                /* Set bandwidth to 0 */
                address->assigned_bw_in.value__ = htonl (0);
@@ -1046,14 +1046,14 @@
                                 (mlp_bw != 
ntohl(address->assigned_bw_in.value__)))
   {
        /* Bandwidth changed */
-               LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : bandwidth changed\n", (1 
== mlp_use) ? "[x]": "[ ]", mlp_bw);
+               LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", 
(1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
                address->assigned_bw_in.value__ = htonl (mlp_bw);
                address->assigned_bw_out.value__ = htonl (mlp_bw);
                mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
   }
   else
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : no change\n", (1 == mlp_use) ? 
"[x]": "[ ]", mlp_bw);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", (1 == mlp_use) ? 
"[x]": "[ ]", mlp_bw);
   }
 
   return GNUNET_OK;
@@ -1430,7 +1430,8 @@
          /* Added new peer, we have to rebuild problem before solving */
          mlp->mlp_prob_changed = GNUNET_YES;
   }
-  GAS_mlp_solve_problem (mlp, addresses);
+  if (GNUNET_YES == mlp->mlp_auto_solve)
+       GAS_mlp_solve_problem (mlp, addresses);
 
   /* Get prefered address */
   GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2013-02-25 14:58:33 UTC (rev 26202)
+++ gnunet/src/ats/test_ats_mlp.c       2013-02-25 15:38:01 UTC (rev 26203)
@@ -121,25 +121,52 @@
 }
 
 static void
-bandwidth_changed_cb (void *cls, struct ATS_Address *address)
+end_correctly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP suggests for peer `%s' address 
`%s':`%s' in %llu out %llu \n",
-               GNUNET_i2s(&address->peer), address->plugin, address->addr,
-               ntohl(address->assigned_bw_in.value__),
-               ntohl(address->assigned_bw_out.value__));
-       //end_now (0);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with success\n"));
+       end_now (0);
 }
 
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
        timeout_task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test failed: timeout\n"));
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with timeout\n"));
        end_now (1);
 }
 
 
 static void
+bandwidth_changed_cb (void *cls, struct ATS_Address *address)
+{
+       static int cb_p0 = GNUNET_NO;
+       static int cb_p1 = GNUNET_NO;
+
+       unsigned long long in = ntohl(address->assigned_bw_in.value__);
+       unsigned long long out = ntohl(address->assigned_bw_out.value__);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP suggests for peer `%s' address 
`%s':`%s' in %llu out %llu \n",
+               GNUNET_i2s(&address->peer),
+               address->plugin,
+               address->addr,
+               in, out);
+
+  if ((in > 0) && (out > 0) &&
+               (0 == memcmp(&p[0], &address->peer, sizeof (address->peer))))
+       cb_p0 ++;
+
+  if ((in > 0) && (out > 0) &&
+               (0 == memcmp(&p[1], &address->peer, sizeof (address->peer))))
+       cb_p1 ++;
+
+  if ((1 == cb_p0) && (1 == cb_p1))
+               GNUNET_SCHEDULER_add_now (&end_correctly, NULL);
+  else if ((1 > cb_p0) || (1 > cb_p1))
+               GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+}
+
+
+static void
 check (void *cls, char *const *args, const char *cfgfile,
        const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
@@ -185,6 +212,7 @@
       end_now (1);
       return;
   }
+  mlp->mlp_auto_solve = GNUNET_NO;
 
   /* Create peer 0 */
   if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, 
&p[0].hashPubKey))
@@ -202,35 +230,46 @@
       return;
   }
 
-  /* Create address 3 */
-  address[2] = create_address (&p[1], "test_plugin2", "test_addr2", 
strlen("test_addr2")+1, 0);
-  if (NULL == address[2])
+  /* Create address 0 */
+  address[0] = create_address (&p[0], "test_plugin0", "test_addr0", 
strlen("test_addr0")+1, 0);
+  if (NULL == address[0])
   {
        GNUNET_break (0);
       end_now (1);
       return;
   }
-  GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2],
+  GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+  /* Adding address 0 */
+  GAS_mlp_address_add (mlp, addresses, address[0]);
 
-
+  /* Create address 1 */
+  address[1] = create_address (&p[0], "test_plugin1", "test_addr1", 
strlen("test_addr1")+1, 0);
+  if (NULL == address[1])
+  {
+       GNUNET_break (0);
+      end_now (1);
+      return;
+  }
+  GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
+               GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
   /* Adding address 1*/
-  GAS_mlp_address_add (mlp, addresses, address[2]);
+  GAS_mlp_address_add (mlp, addresses, address[1]);
 
 
-  /* Create address 0 */
-  address[0] = create_address (&p[0], "test_plugin0", "test_addr0", 
strlen("test_addr0")+1, 0);
-  if (NULL == address[0])
+  /* Create address 3 */
+  address[2] = create_address (&p[1], "test_plugin2", "test_addr2", 
strlen("test_addr2")+1, 0);
+  if (NULL == address[2])
   {
        GNUNET_break (0);
       end_now (1);
       return;
   }
-  GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
+  GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+  /* Adding address 3*/
+  GAS_mlp_address_add (mlp, addresses, address[2]);
 
-  /* Adding address 0 */
-  GAS_mlp_address_add (mlp, addresses, address[0]);
 
   /* Updating address 0*/
   ats.type =  htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -239,32 +278,17 @@
 
   /* Retrieving preferred address for peer and wait for callback */
   GAS_mlp_get_preferred_address (mlp, addresses, &p[0]);
+  GAS_mlp_get_preferred_address (mlp, addresses, &p[1]);
 
-  /* Create address 1 */
-  address[1] = create_address (&p[0], "test_plugin1", "test_addr1", 
strlen("test_addr1")+1, 0);
-  if (NULL == address[1])
-  {
-       GNUNET_break (0);
-      end_now (1);
-      return;
-  }
-  GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
-               GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
 
-
-  /* Adding address 1*/
-  GAS_mlp_address_add (mlp, addresses, address[1]);
-
+#if 0
   /* Updating address 1*/
   ats.type =  htonl (GNUNET_ATS_NETWORK_TYPE);
   ats.value = htonl (GNUNET_ATS_NET_WAN);
   GAS_mlp_address_update (mlp, addresses, address[1], 1, GNUNET_NO, &ats, 1);
-
   GAS_mlp_address_delete (mlp, addresses, address[0], GNUNET_NO);
-
-  end_now (0);
-  //struct GAS_MLP_SolutionContext ctx;
-  //GAS_mlp_solve_problem (mlp, &ctx);
+#endif
+  GAS_mlp_solve_problem (mlp, addresses);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]