aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-12-20 17:02:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-12-20 17:02:57 +0000
commit0b691ca20af8d64a330fe7ae73eaaf071d8100fb (patch)
tree00d2f16d1de7935e83af3c5a3d035b6547001a0b /src
parent9d7fab191ee6ded0ea7bad978a66c4a76319d6ad (diff)
downloadgnunet-0b691ca20af8d64a330fe7ae73eaaf071d8100fb.tar.gz
gnunet-0b691ca20af8d64a330fe7ae73eaaf071d8100fb.zip
- preference calc improved but not active for release
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_addresses_simplistic.c123
1 files changed, 100 insertions, 23 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c
index c56d56d0d..16f053bc9 100644
--- a/src/ats/gnunet-service-ats_addresses_simplistic.c
+++ b/src/ats/gnunet-service-ats_addresses_simplistic.c
@@ -97,6 +97,8 @@ struct GAS_SIMPLISTIC_Handle
97 */ 97 */
98 void *bw_changed_cls; 98 void *bw_changed_cls;
99 99
100 struct GNUNET_CONTAINER_MultiHashMap *prefs;
101
100 struct PreferenceClient *pc_head; 102 struct PreferenceClient *pc_head;
101 struct PreferenceClient *pc_tail; 103 struct PreferenceClient *pc_tail;
102}; 104};
@@ -241,6 +243,7 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
241 s->network_entries = GNUNET_malloc (dest_length * sizeof (struct Network)); 243 s->network_entries = GNUNET_malloc (dest_length * sizeof (struct Network));
242 s->active_addresses = 0; 244 s->active_addresses = 0;
243 s->total_addresses = 0; 245 s->total_addresses = 0;
246 s->prefs = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
244 247
245 for (c = 0; c < dest_length; c++) 248 for (c = 0; c < dest_length; c++)
246 { 249 {
@@ -257,6 +260,16 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
257 return s; 260 return s;
258} 261}
259 262
263static int
264free_pref (void *cls,
265 const struct GNUNET_HashCode * key,
266 void *value)
267{
268 float *v = value;
269 GNUNET_free (v);
270 return GNUNET_OK;
271}
272
260/** 273/**
261 * Shutdown the simplistic problem solving component 274 * Shutdown the simplistic problem solving component
262 * 275 *
@@ -337,15 +350,12 @@ GAS_simplistic_done (void *solver)
337 } 350 }
338 GNUNET_free (pc); 351 GNUNET_free (pc);
339 } 352 }
353
354 GNUNET_CONTAINER_multihashmap_iterate (s->prefs, &free_pref, NULL);
355 GNUNET_CONTAINER_multihashmap_destroy (s->prefs);
340 GNUNET_free (s); 356 GNUNET_free (s);
341} 357}
342 358
343static unsigned long long int
344calculate_new_quota (unsigned long long int total,
345 unsigned int addresses)
346{
347 return (total / addresses);
348}
349 359
350/** 360/**
351 * Test if bandwidth is available in this network 361 * Test if bandwidth is available in this network
@@ -400,9 +410,68 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s,
400 410
401 if (net->active_addresses == 0) 411 if (net->active_addresses == 0)
402 return; /* no addresses to update */ 412 return; /* no addresses to update */
413#if 0
414 /* Idea TODO
415 *
416 * Assign every peer in network minimum Bandwidth
417 * Distribute bandwidth left according to preference
418 */
419 unsigned long long remaining_quota_in = 0;
420 unsigned long long quota_out_used = 0;
421
422 unsigned long long remaining_quota_out = 0;
423 unsigned long long quota_in_used = 0;
424 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
425 float total_prefs;
426 float cur_pref;
427 float *t;
428
429 remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw);
430 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw);
431 total_prefs = 0.0;
432 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "Remaining: (in/out): %llu/%llu \n",
434 remaining_quota_in, remaining_quota_out);
435 for (cur = net->head; NULL != cur; cur = cur->next)
436 {
437 t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey);
438 if (NULL == t)
439 total_prefs += 1.0;
440 else
441 total_prefs += (*t);
442 }
443 for (cur = net->head; NULL != cur; cur = cur->next)
444 {
445 t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey);
446 if (NULL == t)
447 cur_pref = 1.0;
448 else
449 cur_pref += (*t);
450 LOG (GNUNET_ERROR_TYPE_ERROR,
451 "Current pref vs total pref: (in/out): %f/%f \n",
452 cur_pref, total_prefs);
453 quota_in = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_in;
454 quota_out = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_out;
455 LOG (GNUNET_ERROR_TYPE_ERROR,
456 "New quota would be: (in/out): %llu /%llu\n",
457 quota_in,
458 quota_out);
459 quota_in_used += quota_in;
460 quota_out_used += quota_out;
403 461
404 quota_in = calculate_new_quota (net->total_quota_in, net->active_addresses); 462 }
405 quota_out = calculate_new_quota (net->total_quota_out, net->active_addresses); 463 LOG (GNUNET_ERROR_TYPE_ERROR,
464 "Total quota would be: (in/out): %llu /%llu\n",
465 quota_in,
466 quota_out);
467 LOG (GNUNET_ERROR_TYPE_ERROR,
468 "New quota would be: (in/out): %llu /%llu\n",
469 quota_in_used,
470 quota_out_used);
471 /* End TODO */
472#endif
473 quota_in = net->total_quota_in / net->active_addresses;
474 quota_out = net->total_quota_out / net->active_addresses;
406 475
407 LOG (GNUNET_ERROR_TYPE_DEBUG, 476 LOG (GNUNET_ERROR_TYPE_DEBUG,
408 "New per address quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", 477 "New per address quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
@@ -519,6 +588,7 @@ GAS_simplistic_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap *
519 struct GAS_SIMPLISTIC_Handle *s = solver; 588 struct GAS_SIMPLISTIC_Handle *s = solver;
520 struct Network *net = NULL; 589 struct Network *net = NULL;
521 struct AddressWrapper *aw = NULL; 590 struct AddressWrapper *aw = NULL;
591
522 GNUNET_assert (NULL != s); 592 GNUNET_assert (NULL != s);
523 int c; 593 int c;
524 for (c = 0; c < s->networks; c++) 594 for (c = 0; c < s->networks; c++)
@@ -980,15 +1050,24 @@ GAS_simplistic_address_change_preference (void *solver,
980 enum GNUNET_ATS_PreferenceKind kind, 1050 enum GNUNET_ATS_PreferenceKind kind,
981 float score) 1051 float score)
982{ 1052{
983 struct GAS_SIMPLISTIC_Handle *s = solver;
984 struct PreferenceClient *cur;
985 struct PreferencePeer *p;
986 int i;
987 1053
988 GNUNET_assert (NULL != solver); 1054 GNUNET_assert (NULL != solver);
989 GNUNET_assert (NULL != client); 1055 GNUNET_assert (NULL != client);
990 GNUNET_assert (NULL != peer); 1056 GNUNET_assert (NULL != peer);
991 1057
1058 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer `%s' %s %f\n",
1059 client,
1060 GNUNET_i2s (peer),
1061 GNUNET_ATS_print_preference_type (kind),
1062 score);
1063
1064 if (kind >= GNUNET_ATS_PreferenceCount)
1065 {
1066 GNUNET_break (0);
1067 return;
1068 }
1069#if 0
1070
992 /** 1071 /**
993 * Idea: 1072 * Idea:
994 * 1073 *
@@ -1018,17 +1097,10 @@ GAS_simplistic_address_change_preference (void *solver,
1018 * 1097 *
1019 **/ 1098 **/
1020 1099
1021 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer `%s' %s %f\n", 1100 struct GAS_SIMPLISTIC_Handle *s = solver;
1022 client, 1101 struct PreferenceClient *cur;
1023 GNUNET_i2s (peer), 1102 struct PreferencePeer *p;
1024 GNUNET_ATS_print_preference_type (kind), 1103 int i;
1025 score);
1026
1027 if (kind >= GNUNET_ATS_PreferenceCount)
1028 {
1029 GNUNET_break (0);
1030 return;
1031 }
1032 1104
1033 for (cur = s->pc_head; NULL != cur; cur = cur->next) 1105 for (cur = s->pc_head; NULL != cur; cur = cur->next)
1034 { 1106 {
@@ -1103,6 +1175,11 @@ GAS_simplistic_address_change_preference (void *solver,
1103 GNUNET_i2s (&p->id), 1175 GNUNET_i2s (&p->id),
1104 p->f_rel_total); 1176 p->f_rel_total);
1105 } 1177 }
1178
1179 /* Update global map */
1180 /* TODO */
1181#endif
1182
1106} 1183}
1107 1184
1108/* end of gnunet-service-ats_addresses_simplistic.c */ 1185/* end of gnunet-service-ats_addresses_simplistic.c */