diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-20 09:57:39 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-20 09:57:39 +0000 |
commit | ddf5b926ada060c2e34500899dc3c4c0942f3c5c (patch) | |
tree | f3aefedf07a2ee67a20ea2013a71ef4741a8603b /src/ats | |
parent | b298fe671bbe804b63e5aedfc7f2bf8d4a3fd2f9 (diff) | |
download | gnunet-ddf5b926ada060c2e34500899dc3c4c0942f3c5c.tar.gz gnunet-ddf5b926ada060c2e34500899dc3c4c0942f3c5c.zip |
- more code
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 89 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 38 |
2 files changed, 119 insertions, 8 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index fa4d3a106..0de6ec3b3 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -148,6 +148,52 @@ mlp_status_to_string (int retcode) | |||
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Translate ATS properties to text | ||
152 | * Just intended for debugging | ||
153 | * | ||
154 | * @param retcode return code | ||
155 | * @return string with result | ||
156 | */ | ||
157 | const char * | ||
158 | mlp_ats_to_string (int ats_index) | ||
159 | { | ||
160 | switch (ats_index) { | ||
161 | case GNUNET_ATS_ARRAY_TERMINATOR: | ||
162 | return "GNUNET_ATS_ARRAY_TERMINATOR"; | ||
163 | break; | ||
164 | case GNUNET_ATS_UTILIZATION_UP: | ||
165 | return "GNUNET_ATS_UTILIZATION_UP"; | ||
166 | break; | ||
167 | case GNUNET_ATS_UTILIZATION_DOWN: | ||
168 | return "GNUNET_ATS_UTILIZATION_DOWN"; | ||
169 | break; | ||
170 | case GNUNET_ATS_COST_LAN: | ||
171 | return "GNUNET_ATS_COST_LAN"; | ||
172 | break; | ||
173 | case GNUNET_ATS_COST_WAN: | ||
174 | return "GNUNET_ATS_COST_LAN"; | ||
175 | break; | ||
176 | case GNUNET_ATS_COST_WLAN: | ||
177 | return "GNUNET_ATS_COST_WLAN"; | ||
178 | break; | ||
179 | case GNUNET_ATS_NETWORK_TYPE: | ||
180 | return "GNUNET_ATS_NETWORK_TYPE"; | ||
181 | break; | ||
182 | case GNUNET_ATS_QUALITY_NET_DELAY: | ||
183 | return "GNUNET_ATS_QUALITY_NET_DELAY"; | ||
184 | break; | ||
185 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | ||
186 | return "GNUNET_ATS_QUALITY_NET_DISTANCE"; | ||
187 | break; | ||
188 | default: | ||
189 | return "unknown"; | ||
190 | break; | ||
191 | } | ||
192 | GNUNET_break (0); | ||
193 | return "unknown error"; | ||
194 | } | ||
195 | |||
196 | /** | ||
151 | * Find a peer in the DLL | 197 | * Find a peer in the DLL |
152 | * @param the peer to find | 198 | * @param the peer to find |
153 | * @return the peer struct | 199 | * @return the peer struct |
@@ -302,6 +348,34 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value) | |||
302 | return GNUNET_OK; | 348 | return GNUNET_OK; |
303 | } | 349 | } |
304 | 350 | ||
351 | /** | ||
352 | * Find the required ATS information for an address | ||
353 | * | ||
354 | * @param addr the address | ||
355 | * @param ats_index the desired ATS index | ||
356 | * | ||
357 | * @return the index on success, otherwise GNUNET_SYSERR | ||
358 | */ | ||
359 | |||
360 | static int | ||
361 | mlp_lookup_ats (struct ATS_Address *addr, int ats_index) | ||
362 | { | ||
363 | struct GNUNET_ATS_Information * ats = addr->ats; | ||
364 | int c; | ||
365 | int found = GNUNET_NO; | ||
366 | for (c = 0; c < addr->ats_count; c++) | ||
367 | { | ||
368 | if (ats[c].type == ats_index) | ||
369 | { | ||
370 | found = GNUNET_YES; | ||
371 | break; | ||
372 | } | ||
373 | } | ||
374 | if (found == GNUNET_YES) | ||
375 | return c; | ||
376 | else | ||
377 | return GNUNET_SYSERR; | ||
378 | } | ||
305 | 379 | ||
306 | /** | 380 | /** |
307 | * Adds the problem constraints for all addresses | 381 | * Adds the problem constraints for all addresses |
@@ -519,6 +593,21 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
519 | 593 | ||
520 | while (addr != NULL) | 594 | while (addr != NULL) |
521 | { | 595 | { |
596 | /* lookup ATS information */ | ||
597 | int index = mlp_lookup_ats(addr, mlp->q[c]); | ||
598 | |||
599 | if (index != GNUNET_SYSERR) | ||
600 | { | ||
601 | value = (double) addr->ats[index].value; | ||
602 | #if DEBUG_ATS | ||
603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property `%s' has index %i in addresses ats information has value %f\n", c, mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value); | ||
604 | #endif | ||
605 | } | ||
606 | #if DEBUG_ATS | ||
607 | else | ||
608 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property `%s' not existing\n", c, mlp_ats_to_string(mlp->q[c]), index); | ||
609 | #endif | ||
610 | |||
522 | mlpi = addr->mlp_information; | 611 | mlpi = addr->mlp_information; |
523 | ia[mlp->ci] = mlp->r_q[c]; | 612 | ia[mlp->ci] = mlp->r_q[c]; |
524 | ja[mlp->ci] = mlpi->c_b; | 613 | ja[mlp->ci] = mlpi->c_b; |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index bf0c6a10a..0ff5bed4b 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_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_statistics_service.h" | 29 | #include "gnunet_statistics_service.h" |
30 | #include "gnunet_ats_service.h" | ||
30 | #include "gnunet-service-ats_addresses_mlp.h" | 31 | #include "gnunet-service-ats_addresses_mlp.h" |
31 | 32 | ||
32 | #define VERBOSE GNUNET_YES | 33 | #define VERBOSE GNUNET_YES |
@@ -45,6 +46,24 @@ struct GNUNET_CONTAINER_MultiHashMap * addresses; | |||
45 | struct GAS_MLP_Handle *mlp; | 46 | struct GAS_MLP_Handle *mlp; |
46 | 47 | ||
47 | static void | 48 | static void |
49 | create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) | ||
50 | { | ||
51 | addr->mlp_information = NULL; | ||
52 | addr->next = NULL; | ||
53 | addr->prev = NULL; | ||
54 | addr->plugin = strdup (plugin); | ||
55 | addr->ats_count = ats_count; | ||
56 | addr->ats = ats; | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) | ||
61 | { | ||
62 | ats->type = type; | ||
63 | ats->value = value; | ||
64 | } | ||
65 | |||
66 | static void | ||
48 | check (void *cls, char *const *args, const char *cfgfile, | 67 | check (void *cls, char *const *args, const char *cfgfile, |
49 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 68 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
50 | { | 69 | { |
@@ -59,17 +78,20 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
59 | 78 | ||
60 | addresses = GNUNET_CONTAINER_multihashmap_create (10); | 79 | addresses = GNUNET_CONTAINER_multihashmap_create (10); |
61 | 80 | ||
81 | /* Creating address 1 */ | ||
62 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey); | 82 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey); |
63 | addr[0].mlp_information = NULL; | 83 | struct GNUNET_ATS_Information a1_ats[3]; |
64 | addr[0].next = NULL; | 84 | set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); |
65 | addr[0].prev = NULL; | 85 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32); |
66 | addr[0].plugin = strdup ("dummy"); | 86 | set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); |
87 | create_address (&addr[0], "dummy", 3, &a1_ats[0]); | ||
67 | 88 | ||
68 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[1].peer.hashPubKey); | 89 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[1].peer.hashPubKey); |
69 | addr[1].mlp_information = NULL; | 90 | struct GNUNET_ATS_Information a2_ats[3]; |
70 | addr[1].next = NULL; | 91 | set_ats (&a2_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32); |
71 | addr[1].prev = NULL; | 92 | set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); |
72 | addr[1].plugin = strdup ("dummy2"); | 93 | set_ats (&a2_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); |
94 | create_address (&addr[1], "dummy2", 3, &a2_ats[0]); | ||
73 | 95 | ||
74 | GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 96 | GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
75 | 97 | ||