aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-11 11:31:32 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-11 11:31:32 +0000
commit6f79b466c1333431aca6ee3158a29cdf62f1002e (patch)
tree4986a1fca28b94e9354145333016e7eddc84c9f5 /src/ats
parentd7de1366e1aa19c8ce84f70d49e79b75b5b8a3b7 (diff)
downloadgnunet-6f79b466c1333431aca6ee3158a29cdf62f1002e.tar.gz
gnunet-6f79b466c1333431aca6ee3158a29cdf62f1002e.zip
-simplify plugin, remove unnecessary header, make internal plugin functions static, doxygen, indentation, code simplification
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/Makefile.am1
-rw-r--r--src/ats/plugin_ats_proportional.c440
-rw-r--r--src/ats/plugin_ats_proportional.h188
3 files changed, 259 insertions, 370 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 1c3b746d8..cd79d619b 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -518,7 +518,6 @@ test_ats_solver_preferences_ril_LDADD = \
518 518
519EXTRA_DIST = \ 519EXTRA_DIST = \
520 ats.h \ 520 ats.h \
521 plugin_ats_proportional.h \
522 plugin_ats_mlp.h \ 521 plugin_ats_mlp.h \
523 plugin_ats_ril.h \ 522 plugin_ats_ril.h \
524 test_ats_api.conf \ 523 test_ats_api.conf \
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index 901e11c1d..40908e6f8 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -24,7 +24,13 @@
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 */ 26 */
27#include "plugin_ats_proportional.h" 27#include "platform.h"
28#include "gnunet_statistics_service.h"
29#include "gnunet_ats_plugin.h"
30#include "gnunet-service-ats_addresses.h"
31
32#define PROP_STABILITY_FACTOR 1.25
33
28 34
29#define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__)
30 36
@@ -102,12 +108,12 @@
102 * return of payload data transport switches to the real network 108 * return of payload data transport switches to the real network
103 * the address is located in. When an address changes networks it 109 * the address is located in. When an address changes networks it
104 * is first of all removed from the old network using the solver 110 * is first of all removed from the old network using the solver
105 * API function GAS_proportional_address_delete and the network in 111 * API function #GAS_proportional_address_delete() and the network in
106 * the address struct is updated. A lookup for the respective new 112 * the address struct is updated. A lookup for the respective new
107 * proportional network is done and stored in the addresse's 113 * proportional network is done and stored in the addresse's
108 * solver_information field. Next the address is re-added to the 114 * solver_information field. Next the address is re-added to the
109 * solver using the solver API function 115 * solver using the solver API function
110 * GAS_proportional_address_add. If the address was marked as in 116 * #GAS_proportional_address_add(). If the address was marked as in
111 * active, the solver checks if bandwidth is available in the 117 * active, the solver checks if bandwidth is available in the
112 * network and if yes sets the address to active and updates the 118 * network and if yes sets the address to active and updates the
113 * bandwidth distribution in this network. If no bandwidth is 119 * bandwidth distribution in this network. If no bandwidth is
@@ -345,7 +351,14 @@ struct Network
345 */ 351 */
346 char *stat_active; 352 char *stat_active;
347 353
354 /**
355 * FIXME.
356 */
348 struct AddressWrapper *head; 357 struct AddressWrapper *head;
358
359 /**
360 * FIXME.
361 */
349 struct AddressWrapper *tail; 362 struct AddressWrapper *tail;
350}; 363};
351 364
@@ -396,112 +409,12 @@ struct AddressWrapper
396 struct ATS_Address *addr; 409 struct ATS_Address *addr;
397}; 410};
398 411
412
399/** 413/**
400 * Important solver functions 414 * Function used to unload the plugin.
401 * --------------------------- 415 *
416 * @param cls return value from #libgnunet_plugin_ats_proportional_init()
402 */ 417 */
403
404void *
405libgnunet_plugin_ats_proportional_init (void *cls)
406{
407 struct GNUNET_ATS_PluginEnvironment *env = cls;
408 struct GAS_PROPORTIONAL_Handle *s;
409 struct Network * cur;
410 char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
411 float f_tmp;
412 int c;
413
414 GNUNET_assert (NULL != env);
415 GNUNET_assert(NULL != env->cfg);
416 GNUNET_assert(NULL != env->bandwidth_changed_cb);
417 GNUNET_assert(NULL != env->get_preferences);
418 GNUNET_assert(NULL != env->get_property);
419
420 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
421 s->env = env;
422 env->sf.s_add = &GAS_proportional_address_add;
423 env->sf.s_address_update_property = &GAS_proportional_address_property_changed;
424 env->sf.s_address_update_session = &GAS_proportional_address_session_changed;
425 env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed;
426 env->sf.s_address_update_network = &GAS_proportional_address_change_network;
427 env->sf.s_get = &GAS_proportional_get_preferred_address;
428 env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
429 env->sf.s_pref = &GAS_proportional_address_change_preference;
430 env->sf.s_feedback = &GAS_proportional_address_preference_feedback;
431 env->sf.s_del = &GAS_proportional_address_delete;
432 env->sf.s_bulk_start = &GAS_proportional_bulk_start;
433 env->sf.s_bulk_stop = &GAS_proportional_bulk_stop;
434
435 s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
436 s->bw_changed = env->bandwidth_changed_cb;
437 s->bw_changed_cls = env->bw_changed_cb_cls;
438 s->get_preferences = env->get_preferences;
439 s->get_preferences_cls = env->get_preference_cls;
440 s->get_properties = env->get_property;
441 s->get_properties_cls = env->get_property_cls;
442 s->network_count = env->network_count;
443 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
444
445 /* Init */
446 s->active_addresses = 0;
447 s->total_addresses = 0;
448 s->bulk_lock = GNUNET_NO;
449 s->addresses = env->addresses;
450 s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
451
452 s->stability_factor = PROP_STABILITY_FACTOR;
453 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
454 "PROP_STABILITY_FACTOR", &f_tmp))
455 {
456 if ((f_tmp < 1.0) || (f_tmp > 2.0))
457 {
458 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
459 "PROP_STABILITY_FACTOR", f_tmp);
460 }
461 else
462 {
463 s->stability_factor = f_tmp;
464 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
465 "PROP_STABILITY_FACTOR", f_tmp);
466 }
467 }
468
469 s->prop_factor = PROPORTIONALITY_FACTOR;
470 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
471 "PROP_STABILITY_FACTOR", &f_tmp))
472 {
473 if (f_tmp < 1.0)
474 {
475 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
476 "PROP_PROPORTIONALITY_FACTOR", f_tmp);
477 }
478 else
479 {
480 s->prop_factor = f_tmp;
481 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
482 "PROP_PROPORTIONALITY_FACTOR", f_tmp);
483 }
484 }
485
486 for (c = 0; c < env->network_count; c++)
487 {
488 cur = &s->network_entries[c];
489 cur->total_addresses = 0;
490 cur->active_addresses = 0;
491 cur->type = env->networks[c];
492 cur->total_quota_in = env->in_quota[c];
493 cur->total_quota_out = env->out_quota[c];
494 cur->desc = net_str[c];
495 GNUNET_asprintf (&cur->stat_total,
496 "# ATS addresses %s total", cur->desc);
497 GNUNET_asprintf (&cur->stat_active,
498 "# ATS active addresses %s total", cur->desc);
499 LOG (GNUNET_ERROR_TYPE_INFO, "Added network %u `%s' (%llu/%llu)\n",
500 c, cur->desc, cur->total_quota_in, cur->total_quota_out);
501 }
502 return s;
503}
504
505void * 418void *
506libgnunet_plugin_ats_proportional_done (void *cls) 419libgnunet_plugin_ats_proportional_done (void *cls)
507{ 420{
@@ -509,6 +422,7 @@ libgnunet_plugin_ats_proportional_done (void *cls)
509 struct AddressWrapper *cur; 422 struct AddressWrapper *cur;
510 struct AddressWrapper *next; 423 struct AddressWrapper *next;
511 int c; 424 int c;
425
512 GNUNET_assert(s != NULL); 426 GNUNET_assert(s != NULL);
513 for (c = 0; c < s->network_count; c++) 427 for (c = 0; c < s->network_count; c++)
514 { 428 {
@@ -564,7 +478,7 @@ libgnunet_plugin_ats_proportional_done (void *cls)
564 * Test if bandwidth is available in this network to add an additional address 478 * Test if bandwidth is available in this network to add an additional address
565 * 479 *
566 * @param net the network type to update 480 * @param net the network type to update
567 * @return GNUNET_YES or GNUNET_NO 481 * @return #GNUNET_YES or #GNUNET_NO
568 */ 482 */
569static int 483static int
570is_bandwidth_available_in_network (struct Network *net) 484is_bandwidth_available_in_network (struct Network *net)
@@ -587,6 +501,7 @@ is_bandwidth_available_in_network (struct Network *net)
587 return GNUNET_NO; 501 return GNUNET_NO;
588} 502}
589 503
504
590/** 505/**
591 * Update bandwidth assigned to peers in this network 506 * Update bandwidth assigned to peers in this network
592 * 507 *
@@ -749,6 +664,10 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
749 } 664 }
750} 665}
751 666
667
668/**
669 * FIXME.
670 */
752struct FindBestAddressCtx 671struct FindBestAddressCtx
753{ 672{
754 struct GAS_PROPORTIONAL_Handle *s; 673 struct GAS_PROPORTIONAL_Handle *s;
@@ -756,6 +675,9 @@ struct FindBestAddressCtx
756}; 675};
757 676
758 677
678/**
679 * FIXME.
680 */
759static int 681static int
760find_property_index (uint32_t type) 682find_property_index (uint32_t type)
761{ 683{
@@ -915,21 +837,26 @@ end:
915 return GNUNET_OK; 837 return GNUNET_OK;
916} 838}
917 839
840
841/**
842 * FIXME.
843 */
918struct ATS_Address * 844struct ATS_Address *
919get_best_address (struct GAS_PROPORTIONAL_Handle *s, 845get_best_address (struct GAS_PROPORTIONAL_Handle *s,
920 struct GNUNET_CONTAINER_MultiPeerMap *addresses, 846 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
921 const struct GNUNET_PeerIdentity *id) 847 const struct GNUNET_PeerIdentity *id)
922{ 848{
923 struct FindBestAddressCtx fba_ctx; 849 struct FindBestAddressCtx fba_ctx;
850
924 fba_ctx.best = NULL; 851 fba_ctx.best = NULL;
925 fba_ctx.s = s; 852 fba_ctx.s = s;
926
927 GNUNET_CONTAINER_multipeermap_get_multiple (addresses, id, 853 GNUNET_CONTAINER_multipeermap_get_multiple (addresses, id,
928 &find_best_address_it, &fba_ctx); 854 &find_best_address_it, &fba_ctx);
929 855
930 return fba_ctx.best; 856 return fba_ctx.best;
931} 857}
932 858
859
933/** 860/**
934 * Hashmap Iterator to find current active address for peer 861 * Hashmap Iterator to find current active address for peer
935 * 862 *
@@ -952,8 +879,9 @@ get_active_address_it (void *cls,
952 if (NULL != (*dest)) 879 if (NULL != (*dest))
953 { 880 {
954 /* should never happen */ 881 /* should never happen */
955 LOG(GNUNET_ERROR_TYPE_ERROR, "Multiple active addresses for peer `%s'\n", 882 LOG (GNUNET_ERROR_TYPE_ERROR,
956 GNUNET_i2s (&aa->peer)); 883 "Multiple active addresses for peer `%s'\n",
884 GNUNET_i2s (&aa->peer));
957 GNUNET_break(0); 885 GNUNET_break(0);
958 return GNUNET_NO; 886 return GNUNET_NO;
959 } 887 }
@@ -962,6 +890,7 @@ get_active_address_it (void *cls,
962 return GNUNET_OK; 890 return GNUNET_OK;
963} 891}
964 892
893
965/** 894/**
966 * Find current active address for peer 895 * Find current active address for peer
967 * 896 *
@@ -1003,9 +932,14 @@ get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type)
1003} 932}
1004 933
1005 934
935/**
936 * FIXME. Degermanize.
937 */
1006static void 938static void
1007addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, 939addresse_increment (struct GAS_PROPORTIONAL_Handle *s,
1008 int total, int active) 940 struct Network *net,
941 int total,
942 int active)
1009{ 943{
1010 if (GNUNET_YES == total) 944 if (GNUNET_YES == total)
1011 { 945 {
@@ -1026,11 +960,17 @@ addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
1026} 960}
1027 961
1028 962
963/**
964 * FIXME. Degermanize.
965 */
1029static int 966static int
1030addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, 967addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1031 int total, int active) 968 struct Network *net,
969 int total,
970 int active)
1032{ 971{
1033 int res = GNUNET_OK; 972 int res = GNUNET_OK;
973
1034 if (GNUNET_YES == total) 974 if (GNUNET_YES == total)
1035 { 975 {
1036 if (s->total_addresses < 1) 976 if (s->total_addresses < 1)
@@ -1083,6 +1023,10 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
1083 return res; 1023 return res;
1084} 1024}
1085 1025
1026
1027/**
1028 * FIXME.
1029 */
1086static int 1030static int
1087address_eq (struct ATS_Address *a, struct ATS_Address *b) 1031address_eq (struct ATS_Address *a, struct ATS_Address *b)
1088{ 1032{
@@ -1099,13 +1043,13 @@ address_eq (struct ATS_Address *a, struct ATS_Address *b)
1099 return GNUNET_YES; 1043 return GNUNET_YES;
1100} 1044}
1101 1045
1046
1102/** 1047/**
1103 * Helper functions 1048 * FIXME.
1104 * ---------------------------
1105 */ 1049 */
1106static void 1050static void
1107propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, 1051propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1108 struct Network *net) 1052 struct Network *net)
1109{ 1053{
1110 struct AddressWrapper *cur; 1054 struct AddressWrapper *cur;
1111 struct AddressSolverInformation *asi; 1055 struct AddressSolverInformation *asi;
@@ -1139,6 +1083,7 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1139 } 1083 }
1140} 1084}
1141 1085
1086
1142/** 1087/**
1143 * Distribibute bandwidth 1088 * Distribibute bandwidth
1144 * 1089 *
@@ -1148,7 +1093,7 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1148 */ 1093 */
1149static void 1094static void
1150distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, 1095distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1151 struct Network *n) 1096 struct Network *n)
1152{ 1097{
1153 if (GNUNET_YES == s->bulk_lock) 1098 if (GNUNET_YES == s->bulk_lock)
1154 { 1099 {
@@ -1213,17 +1158,22 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1213 } 1158 }
1214} 1159}
1215 1160
1161
1162/**
1163 * FIXME
1164 */
1216static const struct ATS_Address * 1165static const struct ATS_Address *
1217update_active_address (struct GAS_PROPORTIONAL_Handle *s, 1166update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1218 const struct GNUNET_PeerIdentity *peer) 1167 const struct GNUNET_PeerIdentity *peer)
1219{ 1168{
1220 struct ATS_Address *best_address; 1169 struct ATS_Address *best_address;
1221 struct ATS_Address *current_address; 1170 struct ATS_Address *current_address;
1222 struct AddressSolverInformation *asi; 1171 struct AddressSolverInformation *asi;
1223 struct Network *net; 1172 struct Network *net;
1224 1173
1225 LOG (GNUNET_ERROR_TYPE_INFO, "Updating active address for peer `%s'\n", 1174 LOG (GNUNET_ERROR_TYPE_INFO,
1226 GNUNET_i2s (peer)); 1175 "Updating active address for peer `%s'\n",
1176 GNUNET_i2s (peer));
1227 1177
1228 /* Find active address */ 1178 /* Find active address */
1229 current_address = get_active_address (s, s->addresses, peer); 1179 current_address = get_active_address (s, s->addresses, peer);
@@ -1304,10 +1254,6 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1304 return best_address; 1254 return best_address;
1305} 1255}
1306 1256
1307/**
1308 * Solver API functions
1309 * ---------------------------
1310 */
1311 1257
1312/** 1258/**
1313 * Changes the preferences for a peer in the problem 1259 * Changes the preferences for a peer in the problem
@@ -1317,7 +1263,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1317 * @param kind the kind to change the preference 1263 * @param kind the kind to change the preference
1318 * @param pref_rel the normalized preference value for this kind over all clients 1264 * @param pref_rel the normalized preference value for this kind over all clients
1319 */ 1265 */
1320void 1266static void
1321GAS_proportional_address_change_preference (void *solver, 1267GAS_proportional_address_change_preference (void *solver,
1322 const struct GNUNET_PeerIdentity *peer, 1268 const struct GNUNET_PeerIdentity *peer,
1323 enum GNUNET_ATS_PreferenceKind kind, 1269 enum GNUNET_ATS_PreferenceKind kind,
@@ -1328,7 +1274,7 @@ GAS_proportional_address_change_preference (void *solver,
1328 struct ATS_Address *active_address; 1274 struct ATS_Address *active_address;
1329 struct AddressSolverInformation *asi; 1275 struct AddressSolverInformation *asi;
1330 1276
1331 GNUNET_assert(NULL != solver); 1277 GNUNET_assert(NULL != s);
1332 GNUNET_assert(NULL != peer); 1278 GNUNET_assert(NULL != peer);
1333 1279
1334 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) 1280 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
@@ -1360,16 +1306,17 @@ GAS_proportional_address_change_preference (void *solver,
1360 * @param kind the kind to change the preference 1306 * @param kind the kind to change the preference
1361 * @param score the score 1307 * @param score the score
1362 */ 1308 */
1363void 1309static void
1364GAS_proportional_address_preference_feedback (void *solver, void *application, 1310GAS_proportional_address_preference_feedback (void *solver,
1365 const struct GNUNET_PeerIdentity *peer, 1311 void *application,
1366 const struct GNUNET_TIME_Relative scope, 1312 const struct GNUNET_PeerIdentity *peer,
1367 enum GNUNET_ATS_PreferenceKind kind, double score) 1313 const struct GNUNET_TIME_Relative scope,
1314 enum GNUNET_ATS_PreferenceKind kind,
1315 double score)
1368{ 1316{
1369 struct GAS_PROPORTIONAL_Handle *s = solver; 1317 struct GAS_PROPORTIONAL_Handle *s = solver;
1370 GNUNET_assert(NULL != solver);
1371 GNUNET_assert(NULL != peer);
1372 1318
1319 GNUNET_assert(NULL != peer);
1373 GNUNET_assert(NULL != s); 1320 GNUNET_assert(NULL != s);
1374} 1321}
1375 1322
@@ -1377,14 +1324,13 @@ GAS_proportional_address_preference_feedback (void *solver, void *application,
1377/** 1324/**
1378 * Get the preferred address for a specific peer 1325 * Get the preferred address for a specific peer
1379 * 1326 *
1380 *
1381 *
1382 * @param solver the solver handle 1327 * @param solver the solver handle
1383 * @param peer the identity of the peer 1328 * @param peer the identity of the peer
1329 * @return FIXME
1384 */ 1330 */
1385const struct ATS_Address * 1331static const struct ATS_Address *
1386GAS_proportional_get_preferred_address (void *solver, 1332GAS_proportional_get_preferred_address (void *solver,
1387 const struct GNUNET_PeerIdentity *peer) 1333 const struct GNUNET_PeerIdentity *peer)
1388{ 1334{
1389 struct GAS_PROPORTIONAL_Handle *s = solver; 1335 struct GAS_PROPORTIONAL_Handle *s = solver;
1390 const struct ATS_Address *best_address; 1336 const struct ATS_Address *best_address;
@@ -1410,15 +1356,16 @@ GAS_proportional_get_preferred_address (void *solver,
1410 return best_address; 1356 return best_address;
1411} 1357}
1412 1358
1359
1413/** 1360/**
1414 * Stop notifying about address and bandwidth changes for this peer 1361 * Stop notifying about address and bandwidth changes for this peer
1415 * 1362 *
1416 * @param solver the solver handle 1363 * @param solver the solver handle
1417 * @param peer the peer 1364 * @param peer the peer
1418 */ 1365 */
1419void 1366static void
1420GAS_proportional_stop_get_preferred_address (void *solver, 1367GAS_proportional_stop_get_preferred_address (void *solver,
1421 const struct GNUNET_PeerIdentity *peer) 1368 const struct GNUNET_PeerIdentity *peer)
1422{ 1369{
1423 struct GAS_PROPORTIONAL_Handle *s = solver; 1370 struct GAS_PROPORTIONAL_Handle *s = solver;
1424 struct ATS_Address *cur; 1371 struct ATS_Address *cur;
@@ -1453,6 +1400,7 @@ GAS_proportional_stop_get_preferred_address (void *solver,
1453 return; 1400 return;
1454} 1401}
1455 1402
1403
1456/** 1404/**
1457 * Remove an address from the solver 1405 * Remove an address from the solver
1458 * 1406 *
@@ -1460,9 +1408,10 @@ GAS_proportional_stop_get_preferred_address (void *solver,
1460 * @param address the address to remove 1408 * @param address the address to remove
1461 * @param session_only delete only session not whole address 1409 * @param session_only delete only session not whole address
1462 */ 1410 */
1463void 1411static void
1464GAS_proportional_address_delete (void *solver, struct ATS_Address *address, 1412GAS_proportional_address_delete (void *solver,
1465 int session_only) 1413 struct ATS_Address *address,
1414 int session_only)
1466{ 1415{
1467 struct GAS_PROPORTIONAL_Handle *s = solver; 1416 struct GAS_PROPORTIONAL_Handle *s = solver;
1468 struct Network *net; 1417 struct Network *net;
@@ -1554,17 +1503,19 @@ GAS_proportional_address_delete (void *solver, struct ATS_Address *address,
1554 1503
1555} 1504}
1556 1505
1506
1557/** 1507/**
1558 * Start a bulk operation 1508 * Start a bulk operation
1559 * 1509 *
1560 * @param solver the solver 1510 * @param solver the solver
1561 */ 1511 */
1562void 1512static void
1563GAS_proportional_bulk_start (void *solver) 1513GAS_proportional_bulk_start (void *solver)
1564{ 1514{
1565 LOG(GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n"); 1515 struct GAS_PROPORTIONAL_Handle *s = solver;
1566 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver;
1567 1516
1517 LOG (GNUNET_ERROR_TYPE_DEBUG,
1518 "Locking solver for bulk operation ...\n");
1568 GNUNET_assert(NULL != solver); 1519 GNUNET_assert(NULL != solver);
1569 s->bulk_lock++; 1520 s->bulk_lock++;
1570} 1521}
@@ -1573,12 +1524,13 @@ GAS_proportional_bulk_start (void *solver)
1573/** 1524/**
1574 * Bulk operation done 1525 * Bulk operation done
1575 */ 1526 */
1576void 1527static void
1577GAS_proportional_bulk_stop (void *solver) 1528GAS_proportional_bulk_stop (void *solver)
1578{ 1529{
1579 LOG(GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n"); 1530 struct GAS_PROPORTIONAL_Handle *s = solver;
1580 1531
1581 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; 1532 LOG (GNUNET_ERROR_TYPE_DEBUG,
1533 "Unlocking solver from bulk operation ...\n");
1582 GNUNET_assert(NULL != solver); 1534 GNUNET_assert(NULL != solver);
1583 1535
1584 if (s->bulk_lock < 1) 1536 if (s->bulk_lock < 1)
@@ -1603,9 +1555,11 @@ GAS_proportional_bulk_stop (void *solver)
1603 * @param address the address to add 1555 * @param address the address to add
1604 * @param network network type of this address 1556 * @param network network type of this address
1605 */ 1557 */
1606void 1558static void
1607GAS_proportional_address_add (void *solver, struct ATS_Address *address, 1559GAS_proportional_address_add (void *solver,
1608 uint32_t network); 1560 struct ATS_Address *address,
1561 uint32_t network);
1562
1609 1563
1610/** 1564/**
1611 * Transport properties for this address have changed 1565 * Transport properties for this address have changed
@@ -1616,21 +1570,21 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address,
1616 * @param abs_value the absolute value of the property 1570 * @param abs_value the absolute value of the property
1617 * @param rel_value the normalized value 1571 * @param rel_value the normalized value
1618 */ 1572 */
1619void 1573static void
1620GAS_proportional_address_property_changed (void *solver, 1574GAS_proportional_address_property_changed (void *solver,
1621 struct ATS_Address *address, uint32_t type, uint32_t abs_value, 1575 struct ATS_Address *address,
1622 double rel_value) 1576 uint32_t type,
1577 uint32_t abs_value,
1578 double rel_value)
1623{ 1579{
1624 struct GAS_PROPORTIONAL_Handle *s; 1580 struct GAS_PROPORTIONAL_Handle *s = solver;
1625 struct Network *n; 1581 struct Network *n;
1626 struct AddressSolverInformation *asi; 1582 struct AddressSolverInformation *asi;
1627 struct ATS_Address *best_address; 1583 struct ATS_Address *best_address;
1628 struct ATS_Address *active_address; 1584 struct ATS_Address *active_address;
1629 1585
1630 GNUNET_assert(NULL != solver); 1586 GNUNET_assert(NULL != s);
1631 GNUNET_assert(NULL != address); 1587 GNUNET_assert(NULL != address);
1632
1633 s = (struct GAS_PROPORTIONAL_Handle *) solver;
1634 asi = address->solver_information; 1588 asi = address->solver_information;
1635 if (NULL == asi) 1589 if (NULL == asi)
1636 { 1590 {
@@ -1678,20 +1632,23 @@ GAS_proportional_address_property_changed (void *solver,
1678 * @param cur_session the current session 1632 * @param cur_session the current session
1679 * @param new_session the new session 1633 * @param new_session the new session
1680 */ 1634 */
1681void 1635static void
1682GAS_proportional_address_session_changed (void *solver, 1636GAS_proportional_address_session_changed (void *solver,
1683 struct ATS_Address *address, uint32_t cur_session, uint32_t new_session) 1637 struct ATS_Address *address,
1638 uint32_t cur_session,
1639 uint32_t new_session)
1684{ 1640{
1685 struct GAS_PROPORTIONAL_Handle *s = solver; 1641 struct GAS_PROPORTIONAL_Handle *s = solver;
1686 struct ATS_Address *best_address; 1642 struct ATS_Address *best_address;
1687 struct ATS_Address *active_address; 1643 struct ATS_Address *active_address;
1688 struct AddressSolverInformation *asi; 1644 struct AddressSolverInformation *asi;
1689 1645
1690 s = (struct GAS_PROPORTIONAL_Handle *) solver;
1691 if (cur_session != new_session) 1646 if (cur_session != new_session)
1692 { 1647 {
1693 LOG(GNUNET_ERROR_TYPE_DEBUG, "Session changed from %u to %u\n", cur_session, 1648 LOG (GNUNET_ERROR_TYPE_DEBUG,
1694 new_session); 1649 "Session changed from %u to %u\n",
1650 cur_session,
1651 new_session);
1695 } 1652 }
1696 1653
1697 if (NULL == address->solver_information) 1654 if (NULL == address->solver_information)
@@ -1718,6 +1675,7 @@ GAS_proportional_address_session_changed (void *solver,
1718 } 1675 }
1719} 1676}
1720 1677
1678
1721/** 1679/**
1722 * Usage for this address has changed 1680 * Usage for this address has changed
1723 * 1681 *
@@ -1727,20 +1685,19 @@ GAS_proportional_address_session_changed (void *solver,
1727 * @param address the address 1685 * @param address the address
1728 * @param in_use usage state 1686 * @param in_use usage state
1729 */ 1687 */
1730void 1688static void
1731GAS_proportional_address_inuse_changed (void *solver, 1689GAS_proportional_address_inuse_changed (void *solver,
1732 struct ATS_Address *address, int in_use) 1690 struct ATS_Address *address,
1691 int in_use)
1733{ 1692{
1734 struct GAS_PROPORTIONAL_Handle *s; 1693 struct GAS_PROPORTIONAL_Handle *s = solver;
1735 struct Network *n; 1694 struct Network *n;
1736 struct AddressSolverInformation *asi; 1695 struct AddressSolverInformation *asi;
1737 struct ATS_Address *best_address; 1696 struct ATS_Address *best_address;
1738 struct ATS_Address *active_address; 1697 struct ATS_Address *active_address;
1739 1698
1740 GNUNET_assert(NULL != solver); 1699 GNUNET_assert(NULL != s);
1741 GNUNET_assert(NULL != address); 1700 GNUNET_assert(NULL != address);
1742
1743 s = (struct GAS_PROPORTIONAL_Handle *) solver;
1744 asi = address->solver_information; 1701 asi = address->solver_information;
1745 if (NULL == asi) 1702 if (NULL == asi)
1746 { 1703 {
@@ -1788,11 +1745,13 @@ GAS_proportional_address_inuse_changed (void *solver,
1788 * @param current_network the current network 1745 * @param current_network the current network
1789 * @param new_network the new network 1746 * @param new_network the new network
1790 */ 1747 */
1791void 1748static void
1792GAS_proportional_address_change_network (void *solver, 1749GAS_proportional_address_change_network (void *solver,
1793 struct ATS_Address *address, uint32_t current_network, uint32_t new_network) 1750 struct ATS_Address *address,
1751 uint32_t current_network,
1752 uint32_t new_network)
1794{ 1753{
1795 struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; 1754 struct GAS_PROPORTIONAL_Handle *s = solver;
1796 struct AddressSolverInformation *asi; 1755 struct AddressSolverInformation *asi;
1797 int save_active = GNUNET_NO; 1756 int save_active = GNUNET_NO;
1798 1757
@@ -1866,9 +1825,10 @@ GAS_proportional_address_change_network (void *solver,
1866 * @param address the address to add 1825 * @param address the address to add
1867 * @param network network type of this address 1826 * @param network network type of this address
1868 */ 1827 */
1869void 1828static void
1870GAS_proportional_address_add (void *solver, struct ATS_Address *address, 1829GAS_proportional_address_add (void *solver,
1871 uint32_t network) 1830 struct ATS_Address *address,
1831 uint32_t network)
1872{ 1832{
1873 struct GAS_PROPORTIONAL_Handle *s = solver; 1833 struct GAS_PROPORTIONAL_Handle *s = solver;
1874 struct Network *net = NULL; 1834 struct Network *net = NULL;
@@ -1912,4 +1872,122 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address,
1912} 1872}
1913 1873
1914 1874
1875
1876/**
1877 * Function invoked when the plugin is loaded.
1878 *
1879 * @param cls[in,out] the `struct GNUNET_ATS_PluginEnvironment *` to use;
1880 * modified to return the API functions (ugh).
1881 * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure
1882 */
1883void *
1884libgnunet_plugin_ats_proportional_init (void *cls)
1885{
1886 struct GNUNET_ATS_PluginEnvironment *env = cls;
1887 struct GAS_PROPORTIONAL_Handle *s;
1888 struct Network * cur;
1889 char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
1890 float f_tmp;
1891 int c;
1892
1893 GNUNET_assert (NULL != env);
1894 GNUNET_assert (NULL != env->cfg);
1895 GNUNET_assert (NULL != env->bandwidth_changed_cb);
1896 GNUNET_assert (NULL != env->get_preferences);
1897 GNUNET_assert (NULL != env->get_property);
1898
1899 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
1900 s->env = env;
1901 env->sf.s_add = &GAS_proportional_address_add;
1902 env->sf.s_address_update_property = &GAS_proportional_address_property_changed;
1903 env->sf.s_address_update_session = &GAS_proportional_address_session_changed;
1904 env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed;
1905 env->sf.s_address_update_network = &GAS_proportional_address_change_network;
1906 env->sf.s_get = &GAS_proportional_get_preferred_address;
1907 env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
1908 env->sf.s_pref = &GAS_proportional_address_change_preference;
1909 env->sf.s_feedback = &GAS_proportional_address_preference_feedback;
1910 env->sf.s_del = &GAS_proportional_address_delete;
1911 env->sf.s_bulk_start = &GAS_proportional_bulk_start;
1912 env->sf.s_bulk_stop = &GAS_proportional_bulk_stop;
1913
1914 s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
1915 s->bw_changed = env->bandwidth_changed_cb;
1916 s->bw_changed_cls = env->bw_changed_cb_cls;
1917 s->get_preferences = env->get_preferences;
1918 s->get_preferences_cls = env->get_preference_cls;
1919 s->get_properties = env->get_property;
1920 s->get_properties_cls = env->get_property_cls;
1921 s->network_count = env->network_count;
1922 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
1923
1924 /* Init */
1925 s->active_addresses = 0;
1926 s->total_addresses = 0;
1927 s->bulk_lock = GNUNET_NO;
1928 s->addresses = env->addresses;
1929 s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1930
1931 s->stability_factor = PROP_STABILITY_FACTOR;
1932 if (GNUNET_SYSERR !=
1933 GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
1934 "PROP_STABILITY_FACTOR", &f_tmp))
1935 {
1936 if ((f_tmp < 1.0) || (f_tmp > 2.0))
1937 {
1938 LOG (GNUNET_ERROR_TYPE_ERROR,
1939 _("Invalid %s configuration %f \n"),
1940 "PROP_STABILITY_FACTOR",
1941 f_tmp);
1942 }
1943 else
1944 {
1945 s->stability_factor = f_tmp;
1946 LOG (GNUNET_ERROR_TYPE_INFO,
1947 "Using %s of %.3f\n",
1948 "PROP_STABILITY_FACTOR", f_tmp);
1949 }
1950 }
1951
1952 s->prop_factor = PROPORTIONALITY_FACTOR;
1953 if (GNUNET_SYSERR !=
1954 GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
1955 "PROP_STABILITY_FACTOR", &f_tmp))
1956 {
1957 if (f_tmp < 1.0)
1958 {
1959 LOG (GNUNET_ERROR_TYPE_ERROR,
1960 _("Invalid %s configuration %f \n"),
1961 "PROP_PROPORTIONALITY_FACTOR", f_tmp);
1962 }
1963 else
1964 {
1965 s->prop_factor = f_tmp;
1966 LOG (GNUNET_ERROR_TYPE_INFO,
1967 "Using %s of %.3f\n",
1968 "PROP_PROPORTIONALITY_FACTOR", f_tmp);
1969 }
1970 }
1971
1972 for (c = 0; c < env->network_count; c++)
1973 {
1974 cur = &s->network_entries[c];
1975 cur->total_addresses = 0;
1976 cur->active_addresses = 0;
1977 cur->type = env->networks[c];
1978 cur->total_quota_in = env->in_quota[c];
1979 cur->total_quota_out = env->out_quota[c];
1980 cur->desc = net_str[c];
1981 GNUNET_asprintf (&cur->stat_total,
1982 "# ATS addresses %s total", cur->desc);
1983 GNUNET_asprintf (&cur->stat_active,
1984 "# ATS active addresses %s total", cur->desc);
1985 LOG (GNUNET_ERROR_TYPE_INFO,
1986 "Added network %u `%s' (%llu/%llu)\n",
1987 c, cur->desc, cur->total_quota_in, cur->total_quota_out);
1988 }
1989 return s;
1990}
1991
1992
1915/* end of plugin_ats_proportional.c */ 1993/* end of plugin_ats_proportional.c */
diff --git a/src/ats/plugin_ats_proportional.h b/src/ats/plugin_ats_proportional.h
deleted file mode 100644
index 999f42f3f..000000000
--- a/src/ats/plugin_ats_proportional.h
+++ /dev/null
@@ -1,188 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file ats/plugin_ats_proportional.h
23 * @brief ATS proportional solver
24 * @author Matthias Wachs
25 * @author Christian Grothoff
26 */
27#include "platform.h"
28#include "gnunet_statistics_service.h"
29#include "gnunet_ats_plugin.h"
30#include "gnunet-service-ats_addresses.h"
31
32#define PROP_STABILITY_FACTOR 1.25
33
34/**
35 * ATS proportional solver
36 *
37 * General description
38 */
39
40/**
41 * Changes the preferences for a peer in the problem
42 *
43 * @param solver the solver handle
44 * @param peer the peer to change the preference for
45 * @param kind the kind to change the preference
46 * @param pref_rel the normalized preference value for this kind over all clients
47 */
48void
49GAS_proportional_address_change_preference (void *solver,
50 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
51 double pref_rel);
52
53/**
54 * Get application feedback for a peer
55 *
56 * @param solver the solver handle
57 * @param application the application
58 * @param peer the peer to change the preference for
59 * @param scope the time interval for this feedback: [now - scope .. now]
60 * @param kind the kind to change the preference
61 * @param score the score
62 */
63void
64GAS_proportional_address_preference_feedback (void *solver, void *application,
65 const struct GNUNET_PeerIdentity *peer,
66 const struct GNUNET_TIME_Relative scope,
67 enum GNUNET_ATS_PreferenceKind kind, double score);
68
69/**
70 * Shutdown the proportional problem solver
71 *
72 * @param solver the respective handle to shutdown
73 */
74void
75GAS_proportional_done (void * solver);
76
77/**
78 * Add a single address within a network to the solver
79 *
80 * @param solver the solver Handle
81 * @param address the address to add
82 * @param network network type of this address
83 */
84void
85GAS_proportional_address_add (void *solver, struct ATS_Address *address,
86 uint32_t network);
87
88/**
89 * Transport properties for this address have changed
90 *
91 * @param solver solver handle
92 * @param address the address
93 * @param type the ATSI type in HBO
94 * @param abs_value the absolute value of the property
95 * @param rel_value the normalized value
96 */
97void
98GAS_proportional_address_property_changed (void *solver,
99 struct ATS_Address *address, uint32_t type, uint32_t abs_value,
100 double rel_value);
101
102/**
103 * Transport session for this address has changed
104 *
105 * NOTE: values in addresses are already updated
106 *
107 * @param solver solver handle
108 * @param address the address
109 * @param cur_session the current session
110 * @param new_session the new session
111 */
112void
113GAS_proportional_address_session_changed (void *solver,
114 struct ATS_Address *address, uint32_t cur_session, uint32_t new_session);
115
116/**
117 * Usage for this address has changed
118 *
119 * NOTE: values in addresses are already updated
120 *
121 * @param solver solver handle
122 * @param address the address
123 * @param in_use usage state
124 */
125void
126GAS_proportional_address_inuse_changed (void *solver,
127 struct ATS_Address *address, int in_use);
128
129/**
130 * Network scope for this address has changed
131 *
132 * NOTE: values in addresses are already updated
133 *
134 * @param solver solver handle
135 * @param address the address
136 * @param current_network the current network
137 * @param new_network the new network
138 */
139void
140GAS_proportional_address_change_network (void *solver,
141 struct ATS_Address *address, uint32_t current_network, uint32_t new_network);
142
143/**
144 * Remove an address from the solver
145 *
146 * @param solver the solver handle
147 * @param address the address to remove
148 * @param session_only delete only session not whole address
149 */
150void
151GAS_proportional_address_delete (void *solver, struct ATS_Address *address,
152 int session_only);
153
154/**
155 * Start a bulk operation
156 *
157 * @param solver the solver
158 */
159void
160GAS_proportional_bulk_start (void *solver);
161
162/**
163 * Bulk operation done
164 */
165void
166GAS_proportional_bulk_stop (void *solver);
167
168/**
169 * Stop notifying about address and bandwidth changes for this peer
170 *
171 * @param solver the proportional handle
172 * @param peer the peer
173 */
174void
175GAS_proportional_stop_get_preferred_address (void *solver,
176 const struct GNUNET_PeerIdentity *peer);
177
178/**
179 * Get the prefered address for a specific peer
180 *
181 * @param solver the solver handle
182 * @param peer the identity of the peer
183 */
184const struct ATS_Address *
185GAS_proportional_get_preferred_address (void *solver,
186 const struct GNUNET_PeerIdentity *peer);
187
188/* end of plugin_ats_proportional.h */