diff options
-rw-r--r-- | src/ats/Makefile.am | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 38 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 3 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 3 |
4 files changed, 42 insertions, 4 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 4b4823888..964af06db 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -17,7 +17,7 @@ endif | |||
17 | 17 | ||
18 | if HAVE_LIBGLPK | 18 | if HAVE_LIBGLPK |
19 | GN_LIBGLPK = -lglpk | 19 | GN_LIBGLPK = -lglpk |
20 | GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h | 20 | GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h |
21 | GN_MLP_TEST = test_ats_mlp | 21 | GN_MLP_TEST = test_ats_mlp |
22 | GN_MLP_TEST_UPDATE = test_ats_mlp_update | 22 | GN_MLP_TEST_UPDATE = test_ats_mlp_update |
23 | GN_MLP_TEST_AVG = test_ats_mlp_averaging | 23 | GN_MLP_TEST_AVG = test_ats_mlp_averaging |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 45a6227fb..5f2ff26d9 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet-service-ats_addresses.h" | 29 | #include "gnunet-service-ats_addresses.h" |
30 | #include "gnunet-service-ats_normalization.h" | ||
30 | #include "gnunet-service-ats_addresses_mlp.h" | 31 | #include "gnunet-service-ats_addresses_mlp.h" |
31 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
32 | #include "glpk.h" | 33 | #include "glpk.h" |
@@ -1437,6 +1438,27 @@ mlp_get_preferred_address_it (void *cls, const struct GNUNET_HashCode * key, voi | |||
1437 | } | 1438 | } |
1438 | 1439 | ||
1439 | 1440 | ||
1441 | static double get_peer_pref_value (const struct GNUNET_PeerIdentity *peer) | ||
1442 | { | ||
1443 | double res; | ||
1444 | const double *preferences = NULL; | ||
1445 | int c; | ||
1446 | preferences = GAS_normalization_get_preferences ((struct GNUNET_PeerIdentity *) peer); | ||
1447 | |||
1448 | res = 0.0; | ||
1449 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | ||
1450 | { | ||
1451 | if (c != GNUNET_ATS_PREFERENCE_END) | ||
1452 | { | ||
1453 | //fprintf (stderr, "VALUE[%u] %s %.3f \n", c, GNUNET_i2s (&cur->addr->peer), t[c]); | ||
1454 | res += preferences[c]; | ||
1455 | } | ||
1456 | } | ||
1457 | res /= (GNUNET_ATS_PreferenceCount -1); | ||
1458 | return res; | ||
1459 | } | ||
1460 | |||
1461 | |||
1440 | /** | 1462 | /** |
1441 | * Get the preferred address for a specific peer | 1463 | * Get the preferred address for a specific peer |
1442 | * | 1464 | * |
@@ -1469,7 +1491,7 @@ GAS_mlp_get_preferred_address (void *solver, | |||
1469 | 1491 | ||
1470 | p = GNUNET_malloc (sizeof (struct ATS_Peer)); | 1492 | p = GNUNET_malloc (sizeof (struct ATS_Peer)); |
1471 | p->id = (*peer); | 1493 | p->id = (*peer); |
1472 | p->f = DEFAULT_PEER_PREFERENCE; | 1494 | p->f = get_peer_pref_value (peer);; |
1473 | GNUNET_CONTAINER_multihashmap_put (mlp->peers, &peer->hashPubKey, p, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1495 | GNUNET_CONTAINER_multihashmap_put (mlp->peers, &peer->hashPubKey, p, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1474 | 1496 | ||
1475 | /* Added new peer, we have to rebuild problem before solving */ | 1497 | /* Added new peer, we have to rebuild problem before solving */ |
@@ -1530,15 +1552,27 @@ GAS_mlp_address_change_preference (void *solver, | |||
1530 | double pref_rel) | 1552 | double pref_rel) |
1531 | { | 1553 | { |
1532 | struct GAS_MLP_Handle *mlp = solver; | 1554 | struct GAS_MLP_Handle *mlp = solver; |
1555 | struct ATS_Peer *p = NULL; | ||
1556 | |||
1533 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s'\n", | 1557 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s'\n", |
1534 | GNUNET_i2s(peer)); | 1558 | GNUNET_i2s(peer)); |
1535 | 1559 | ||
1536 | GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); | 1560 | GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); |
1537 | 1561 | ||
1538 | /* Update the constraints with changed preferences */ | 1562 | /* Update the constraints with changed preferences */ |
1563 | |||
1564 | |||
1539 | /* Update quality constraint c7 */ | 1565 | /* Update quality constraint c7 */ |
1540 | 1566 | ||
1541 | /* Update relativity constraint c8 */ | 1567 | /* Update relativity constraint c9 */ |
1568 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, &peer->hashPubKey))) | ||
1569 | { | ||
1570 | LOG (GNUNET_ERROR_TYPE_ERROR, "Updating preference for unknown peer `%s' \n", GNUNET_i2s(peer)); | ||
1571 | return; | ||
1572 | } | ||
1573 | p->f = get_peer_pref_value (peer); | ||
1574 | mlp_create_problem_set_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__); | ||
1575 | |||
1542 | 1576 | ||
1543 | /* Problem size changed: new address for peer with pending request */ | 1577 | /* Problem size changed: new address for peer with pending request */ |
1544 | mlp->mlp_prob_updated = GNUNET_YES; | 1578 | mlp->mlp_prob_updated = GNUNET_YES; |
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 54714aa26..1f812ebda 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -422,6 +422,9 @@ GAS_normalization_change_preference (void *src, | |||
422 | const double * | 422 | const double * |
423 | GAS_normalization_get_preferences (struct GNUNET_PeerIdentity *id) | 423 | GAS_normalization_get_preferences (struct GNUNET_PeerIdentity *id) |
424 | { | 424 | { |
425 | GNUNET_assert (NULL != peers); | ||
426 | GNUNET_assert (NULL != id); | ||
427 | |||
425 | struct PeerRelative *rp; | 428 | struct PeerRelative *rp; |
426 | if (NULL == (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | 429 | if (NULL == (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) |
427 | { | 430 | { |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 21334e414..bd39aed44 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c | |||
@@ -104,6 +104,7 @@ end_now (int res) | |||
104 | GAS_mlp_done (mlp); | 104 | GAS_mlp_done (mlp); |
105 | mlp = NULL; | 105 | mlp = NULL; |
106 | } | 106 | } |
107 | GAS_normalization_stop (); | ||
107 | 108 | ||
108 | ret = res; | 109 | ret = res; |
109 | } | 110 | } |
@@ -191,7 +192,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
191 | end_now (1); | 192 | end_now (1); |
192 | return; | 193 | return; |
193 | } | 194 | } |
194 | 195 | GAS_normalization_start (NULL, NULL); | |
195 | /* Setup address hashmap */ | 196 | /* Setup address hashmap */ |
196 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 197 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
197 | 198 | ||