diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-18 13:13:40 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-18 13:13:40 +0000 |
commit | 3f796fcf771107bd9f0823dcc96ac6dc0db37074 (patch) | |
tree | 6161bb5da082c955423a4b8ce3a8dd6eac24a687 | |
parent | 349c2db632fa4969ee11d4d0bfb2cab78d5051b8 (diff) | |
download | gnunet-3f796fcf771107bd9f0823dcc96ac6dc0db37074.tar.gz gnunet-3f796fcf771107bd9f0823dcc96ac6dc0db37074.zip |
- preference mgmt
-rw-r--r-- | src/ats/ats_api_performance.c | 16 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_simplistic.c | 74 | ||||
-rw-r--r-- | src/ats/test_ats_simplistic_change_preference.c | 48 |
3 files changed, 116 insertions, 22 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 5cb199266..25b492614 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -830,6 +830,22 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl | |||
830 | 830 | ||
831 | 831 | ||
832 | /** | 832 | /** |
833 | * Convert a GNUNET_ATS_PreferenceType to a string | ||
834 | * | ||
835 | * @param type the preference type | ||
836 | * @return a string or NULL if invalid | ||
837 | */ | ||
838 | const char * | ||
839 | GNUNET_ATS_print_preference_type (uint32_t type) | ||
840 | { | ||
841 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | ||
842 | if (type < GNUNET_ATS_PreferenceCount) | ||
843 | return prefs[type]; | ||
844 | return NULL; | ||
845 | } | ||
846 | |||
847 | |||
848 | /** | ||
833 | * Change preferences for the given peer. Preference changes are forgotten if peers | 849 | * Change preferences for the given peer. Preference changes are forgotten if peers |
834 | * disconnect. | 850 | * disconnect. |
835 | * | 851 | * |
diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c index 60c9c380e..b70daf067 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.c +++ b/src/ats/gnunet-service-ats_addresses_simplistic.c | |||
@@ -157,11 +157,23 @@ struct AddressWrapper | |||
157 | struct ATS_Address *addr; | 157 | struct ATS_Address *addr; |
158 | }; | 158 | }; |
159 | 159 | ||
160 | |||
161 | struct PreferencePeer | ||
162 | { | ||
163 | struct GNUNET_PeerIdentity id; | ||
164 | |||
165 | float prefs[GNUNET_ATS_PreferenceCount]; | ||
166 | }; | ||
167 | |||
160 | struct PreferenceClient | 168 | struct PreferenceClient |
161 | { | 169 | { |
162 | struct PreferenceClient *prev; | 170 | struct PreferenceClient *prev; |
163 | struct PreferenceClient *next; | 171 | struct PreferenceClient *next; |
164 | void *client; | 172 | void *client; |
173 | |||
174 | float prefs[GNUNET_ATS_PreferenceCount]; | ||
175 | |||
176 | struct GNUNET_CONTAINER_MultiHashMap *peers; | ||
165 | }; | 177 | }; |
166 | 178 | ||
167 | /** | 179 | /** |
@@ -228,6 +240,18 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
228 | } | 240 | } |
229 | 241 | ||
230 | 242 | ||
243 | static int | ||
244 | delete_peers (void *cls, | ||
245 | const struct GNUNET_HashCode * key, | ||
246 | void *value) | ||
247 | { | ||
248 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; | ||
249 | struct PreferencePeer *p = (struct PreferencePeer *) value; | ||
250 | GNUNET_CONTAINER_multihashmap_remove (m, &p->id.hashPubKey, p); | ||
251 | GNUNET_free (p); | ||
252 | return GNUNET_OK; | ||
253 | } | ||
254 | |||
231 | /** | 255 | /** |
232 | * Shutdown the simplistic problem solving component | 256 | * Shutdown the simplistic problem solving component |
233 | * | 257 | * |
@@ -297,6 +321,8 @@ GAS_simplistic_done (void *solver) | |||
297 | { | 321 | { |
298 | next_pc = pc->next; | 322 | next_pc = pc->next; |
299 | GNUNET_CONTAINER_DLL_remove (s->pc_head, s->pc_tail, pc); | 323 | GNUNET_CONTAINER_DLL_remove (s->pc_head, s->pc_tail, pc); |
324 | GNUNET_CONTAINER_multihashmap_iterate (pc->peers, &delete_peers, pc->peers); | ||
325 | GNUNET_CONTAINER_multihashmap_destroy (pc->peers); | ||
300 | GNUNET_free (pc); | 326 | GNUNET_free (pc); |
301 | } | 327 | } |
302 | GNUNET_free (s); | 328 | GNUNET_free (s); |
@@ -858,6 +884,17 @@ GAS_simplistic_get_preferred_address (void *solver, | |||
858 | } | 884 | } |
859 | 885 | ||
860 | 886 | ||
887 | static double | ||
888 | update_pref_value (struct PreferenceClient *cur, int kind, float score) | ||
889 | { | ||
890 | float res = (cur->prefs[kind] + score) / 2; /* change update algorithm here */; | ||
891 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer type %s from %f to %f\n", | ||
892 | cur->client, | ||
893 | GNUNET_ATS_print_preference_type (kind), | ||
894 | cur->prefs[kind], res); | ||
895 | return res; | ||
896 | } | ||
897 | |||
861 | /** | 898 | /** |
862 | * Changes the preferences for a peer in the problem | 899 | * Changes the preferences for a peer in the problem |
863 | * | 900 | * |
@@ -876,30 +913,61 @@ GAS_simplistic_address_change_preference (void *solver, | |||
876 | { | 913 | { |
877 | struct GAS_SIMPLISTIC_Handle *s = solver; | 914 | struct GAS_SIMPLISTIC_Handle *s = solver; |
878 | struct PreferenceClient *cur; | 915 | struct PreferenceClient *cur; |
916 | struct PreferencePeer *p; | ||
917 | int i; | ||
879 | 918 | ||
880 | GNUNET_assert (NULL != solver); | 919 | GNUNET_assert (NULL != solver); |
881 | GNUNET_assert (NULL != client); | 920 | GNUNET_assert (NULL != client); |
882 | GNUNET_assert (NULL != peer); | 921 | GNUNET_assert (NULL != peer); |
883 | 922 | ||
884 | LOG (GNUNET_ERROR_TYPE_ERROR, "Client %p changes preference for peer `%s' %d\n", | 923 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer `%s' %s %f\n", |
885 | client, | 924 | client, |
886 | GNUNET_i2s (peer), | 925 | GNUNET_i2s (peer), |
926 | GNUNET_ATS_print_preference_type (kind), | ||
887 | score); | 927 | score); |
888 | 928 | ||
929 | if (kind >= GNUNET_ATS_PreferenceCount) | ||
930 | { | ||
931 | GNUNET_break (0); | ||
932 | return; | ||
933 | } | ||
934 | |||
889 | for (cur = s->pc_head; NULL != cur; cur = cur->next) | 935 | for (cur = s->pc_head; NULL != cur; cur = cur->next) |
890 | { | 936 | { |
891 | if (client == cur->client) | 937 | if (client == cur->client) |
892 | break; | 938 | break; |
893 | } | 939 | } |
894 | |||
895 | if (NULL == cur) | 940 | if (NULL == cur) |
896 | { | 941 | { |
897 | cur = GNUNET_malloc (sizeof (struct PreferenceClient)); | 942 | cur = GNUNET_malloc (sizeof (struct PreferenceClient)); |
898 | cur->client = client; | 943 | cur->client = client; |
944 | cur->peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | ||
899 | GNUNET_CONTAINER_DLL_insert (s->pc_head, s->pc_tail, cur); | 945 | GNUNET_CONTAINER_DLL_insert (s->pc_head, s->pc_tail, cur); |
900 | } | 946 | } |
901 | 947 | ||
948 | p = GNUNET_CONTAINER_multihashmap_get (cur->peers, &peer->hashPubKey); | ||
949 | if (NULL == p) | ||
950 | { | ||
951 | p = GNUNET_malloc (sizeof (struct PreferencePeer)); | ||
952 | p->id = (*peer); | ||
953 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | ||
954 | p->prefs[i] = 1; | ||
955 | GNUNET_CONTAINER_multihashmap_put (cur->peers, | ||
956 | &peer->hashPubKey, | ||
957 | p, | ||
958 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
959 | } | ||
902 | 960 | ||
961 | switch (kind) { | ||
962 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | ||
963 | case GNUNET_ATS_PREFERENCE_LATENCY: | ||
964 | p->prefs[kind] = update_pref_value (cur, kind, score); | ||
965 | break; | ||
966 | case GNUNET_ATS_PREFERENCE_END: | ||
967 | break; | ||
968 | default: | ||
969 | break; | ||
970 | } | ||
903 | 971 | ||
904 | } | 972 | } |
905 | 973 | ||
diff --git a/src/ats/test_ats_simplistic_change_preference.c b/src/ats/test_ats_simplistic_change_preference.c index ecde45825..6ded2a93b 100644 --- a/src/ats/test_ats_simplistic_change_preference.c +++ b/src/ats/test_ats_simplistic_change_preference.c | |||
@@ -46,6 +46,12 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Scheduling handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
52 | |||
53 | |||
54 | /** | ||
49 | * Return value | 55 | * Return value |
50 | */ | 56 | */ |
51 | static int ret; | 57 | static int ret; |
@@ -99,6 +105,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
99 | 105 | ||
100 | if (sched_ats != NULL) | 106 | if (sched_ats != NULL) |
101 | GNUNET_ATS_scheduling_done (sched_ats); | 107 | GNUNET_ATS_scheduling_done (sched_ats); |
108 | if (perf_ats != NULL) | ||
109 | GNUNET_ATS_performance_done (perf_ats); | ||
102 | free_test_address (&test_addr[0]); | 110 | free_test_address (&test_addr[0]); |
103 | ret = GNUNET_SYSERR; | 111 | ret = GNUNET_SYSERR; |
104 | } | 112 | } |
@@ -113,6 +121,8 @@ end () | |||
113 | GNUNET_SCHEDULER_cancel (die_task); | 121 | GNUNET_SCHEDULER_cancel (die_task); |
114 | die_task = GNUNET_SCHEDULER_NO_TASK; | 122 | die_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 123 | } |
124 | GNUNET_ATS_performance_done (perf_ats); | ||
125 | perf_ats = NULL; | ||
116 | GNUNET_ATS_scheduling_done (sched_ats); | 126 | GNUNET_ATS_scheduling_done (sched_ats); |
117 | sched_ats = NULL; | 127 | sched_ats = NULL; |
118 | free_test_address (&test_addr[0]); | 128 | free_test_address (&test_addr[0]); |
@@ -177,26 +187,17 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
177 | GNUNET_SCHEDULER_add_now (&end, NULL); | 187 | GNUNET_SCHEDULER_add_now (&end, NULL); |
178 | return; | 188 | return; |
179 | } | 189 | } |
180 | p[0].bw_out_assigned = bw_out; | 190 | |
181 | p[0].bw_in_assigned = bw_in; | ||
182 | stage ++; | 191 | stage ++; |
183 | 192 | ||
184 | /* Add a 2nd address */ | 193 | /* Change preference */ |
185 | /* Prepare ATS Information */ | 194 | GNUNET_ATS_change_preference (perf_ats, |
186 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 195 | &p[0].id, |
187 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | 196 | GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); |
188 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | 197 | |
189 | test_ats_info[1].value = htonl(1); | 198 | /* Request address */ |
190 | test_ats_count = 2; | 199 | GNUNET_ATS_suggest_address (sched_ats, &p[0].id); |
191 | 200 | return; | |
192 | /* Adding address with session */ | ||
193 | test_session[1] = &test_addr[1]; | ||
194 | create_test_address (&test_addr[1], "test1", test_session[1], "test1", strlen ("test1") + 1); | ||
195 | test_hello_address[1].peer = p[1].id; | ||
196 | test_hello_address[1].transport_name = test_addr[1].plugin; | ||
197 | test_hello_address[1].address = test_addr[1].addr; | ||
198 | test_hello_address[1].address_length = test_addr[1].addr_len; | ||
199 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count); | ||
200 | } | 201 | } |
201 | if (1 == stage) | 202 | if (1 == stage) |
202 | { | 203 | { |
@@ -321,6 +322,15 @@ run (void *cls, | |||
321 | return; | 322 | return; |
322 | } | 323 | } |
323 | 324 | ||
325 | perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL); | ||
326 | if (perf_ats == NULL) | ||
327 | { | ||
328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n"); | ||
329 | ret = 1; | ||
330 | end (); | ||
331 | return; | ||
332 | } | ||
333 | |||
324 | /* Set up peer 0 */ | 334 | /* Set up peer 0 */ |
325 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey)) | 335 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey)) |
326 | { | 336 | { |
@@ -372,7 +382,7 @@ run (void *cls, | |||
372 | int | 382 | int |
373 | main (int argc, char *argv[]) | 383 | main (int argc, char *argv[]) |
374 | { | 384 | { |
375 | if (0 != GNUNET_TESTING_peer_run ("test_ats_simplististic", | 385 | if (0 != GNUNET_TESTING_peer_run ("test_ats_simplistic_change_preference", |
376 | "test_ats_api.conf", | 386 | "test_ats_api.conf", |
377 | &run, NULL)) | 387 | &run, NULL)) |
378 | return 1; | 388 | return 1; |