diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-04 16:04:46 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-04 16:04:46 +0000 |
commit | 919ae3f285a0142a00982417d371bfcd7ddf3438 (patch) | |
tree | 261094232ba54ea2b3330f0aabde2190b5a759f1 /src | |
parent | 32c6b50f5c00042069e563ca238080ac4b6f309e (diff) | |
download | gnunet-919ae3f285a0142a00982417d371bfcd7ddf3438.tar.gz gnunet-919ae3f285a0142a00982417d371bfcd7ddf3438.zip |
ats_ril: -some comments removed
Diffstat (limited to 'src')
-rwxr-xr-x | src/ats/gnunet-service-ats-solver_ril.c | 98 |
1 files changed, 81 insertions, 17 deletions
diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c index 5b78d03a0..4cc19092d 100755 --- a/src/ats/gnunet-service-ats-solver_ril.c +++ b/src/ats/gnunet-service-ats-solver_ril.c | |||
@@ -257,7 +257,7 @@ struct RIL_Callbacks | |||
257 | void *bw_changed_cls; | 257 | void *bw_changed_cls; |
258 | 258 | ||
259 | /** | 259 | /** |
260 | * ATS function to get preferences | 260 | * ATS function to get preferences for a peer |
261 | */ | 261 | */ |
262 | GAS_get_preferences get_preferences; | 262 | GAS_get_preferences get_preferences; |
263 | 263 | ||
@@ -267,7 +267,7 @@ struct RIL_Callbacks | |||
267 | void *get_preferences_cls; | 267 | void *get_preferences_cls; |
268 | 268 | ||
269 | /** | 269 | /** |
270 | * ATS function to get properties | 270 | * ATS function to get properties of an address |
271 | */ | 271 | */ |
272 | GAS_get_properties get_properties; | 272 | GAS_get_properties get_properties; |
273 | 273 | ||
@@ -344,7 +344,7 @@ struct GAS_RIL_Handle | |||
344 | struct RIL_Peer_Agent * agents_tail; | 344 | struct RIL_Peer_Agent * agents_tail; |
345 | }; | 345 | }; |
346 | 346 | ||
347 | /** | 347 | /* |
348 | * Private functions | 348 | * Private functions |
349 | * --------------------------- | 349 | * --------------------------- |
350 | */ | 350 | */ |
@@ -389,6 +389,12 @@ if (r < RIL_EXPLORE_RATIO) | |||
389 | return GNUNET_NO; | 389 | return GNUNET_NO; |
390 | } | 390 | } |
391 | 391 | ||
392 | /** | ||
393 | * Get the index of the address in the agent's list. | ||
394 | * @param agent agent handle | ||
395 | * @param address address handle | ||
396 | * @return the index, starting with zero | ||
397 | */ | ||
392 | static int | 398 | static int |
393 | agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 399 | agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
394 | { | 400 | { |
@@ -408,6 +414,12 @@ agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *addre | |||
408 | return i; | 414 | return i; |
409 | } | 415 | } |
410 | 416 | ||
417 | /** | ||
418 | * Gets the wrapped address from the agent's list | ||
419 | * @param agent agent handle | ||
420 | * @param address address handle | ||
421 | * @return wrapped address | ||
422 | */ | ||
411 | static struct RIL_Address_Wrapped * | 423 | static struct RIL_Address_Wrapped * |
412 | agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 424 | agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
413 | { | 425 | { |
@@ -525,6 +537,16 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification | |||
525 | } | 537 | } |
526 | } | 538 | } |
527 | 539 | ||
540 | /** | ||
541 | * Changes the active assignment suggestion of the handler and invokes the bw_changed callback to | ||
542 | * notify ATS of its new decision. | ||
543 | * @param solver solver handle | ||
544 | * @param agent agent handle | ||
545 | * @param new_address the address which is to be used | ||
546 | * @param new_bw_in the new amount of inbound bandwidth set for this address | ||
547 | * @param new_bw_out the new amount of outbound bandwidth set for this address | ||
548 | * @param silent disables invocation of the bw_changed callback, if GNUNET_YES | ||
549 | */ | ||
528 | static void | 550 | static void |
529 | envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | 551 | envi_set_active_suggestion (struct GAS_RIL_Handle *solver, |
530 | struct RIL_Peer_Agent *agent, | 552 | struct RIL_Peer_Agent *agent, |
@@ -653,6 +675,12 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
653 | / (double) UINT32_MAX; | 675 | / (double) UINT32_MAX; |
654 | } | 676 | } |
655 | 677 | ||
678 | /** | ||
679 | * Doubles the bandwidth for the active address | ||
680 | * @param solver solver handle | ||
681 | * @param agent agent handle | ||
682 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth | ||
683 | */ | ||
656 | static void | 684 | static void |
657 | envi_action_bw_double (struct GAS_RIL_Handle *solver, | 685 | envi_action_bw_double (struct GAS_RIL_Handle *solver, |
658 | struct RIL_Peer_Agent *agent, | 686 | struct RIL_Peer_Agent *agent, |
@@ -670,6 +698,14 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver, | |||
670 | } | 698 | } |
671 | } | 699 | } |
672 | 700 | ||
701 | /** | ||
702 | * Cuts the bandwidth for the active address in half. The least amount of bandwidth suggested, is | ||
703 | * the minimum bandwidth for a peer, in order to not invoke a disconnect. | ||
704 | * @param solver solver handle | ||
705 | * @param agent agent handle | ||
706 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound | ||
707 | * bandwidth | ||
708 | */ | ||
673 | static void | 709 | static void |
674 | envi_action_bw_halven (struct GAS_RIL_Handle *solver, | 710 | envi_action_bw_halven (struct GAS_RIL_Handle *solver, |
675 | struct RIL_Peer_Agent *agent, | 711 | struct RIL_Peer_Agent *agent, |
@@ -694,6 +730,13 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver, | |||
694 | } | 730 | } |
695 | } | 731 | } |
696 | 732 | ||
733 | /** | ||
734 | * Increases the bandwidth by 5 times the minimum bandwidth for the active address. | ||
735 | * @param solver solver handle | ||
736 | * @param agent agent handle | ||
737 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound | ||
738 | * bandwidth | ||
739 | */ | ||
697 | static void | 740 | static void |
698 | envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 741 | envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
699 | { | 742 | { |
@@ -711,6 +754,14 @@ envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
711 | } | 754 | } |
712 | } | 755 | } |
713 | 756 | ||
757 | /** | ||
758 | * Decreases the bandwidth by 5 times the minimum bandwidth for the active address. The least amount | ||
759 | * of bandwidth suggested, is the minimum bandwidth for a peer, in order to not invoke a disconnect. | ||
760 | * @param solver solver handle | ||
761 | * @param agent agent handle | ||
762 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise change the outbound | ||
763 | * bandwidth | ||
764 | */ | ||
714 | static void | 765 | static void |
715 | envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 766 | envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
716 | { | 767 | { |
@@ -733,6 +784,12 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
733 | } | 784 | } |
734 | } | 785 | } |
735 | 786 | ||
787 | /** | ||
788 | * Switches to the address given by its index | ||
789 | * @param solver solver handle | ||
790 | * @param agent agent handle | ||
791 | * @param address_index index of the address as it is saved in the agent's list, starting with zero | ||
792 | */ | ||
736 | static void | 793 | static void |
737 | envi_action_address_switch (struct GAS_RIL_Handle *solver, | 794 | envi_action_address_switch (struct GAS_RIL_Handle *solver, |
738 | struct RIL_Peer_Agent *agent, | 795 | struct RIL_Peer_Agent *agent, |
@@ -752,12 +809,12 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver, | |||
752 | i++; | 809 | i++; |
753 | } | 810 | } |
754 | 811 | ||
755 | //no address with address_index exists | 812 | //no address with address_index exists, in this case this action should not be callable |
756 | GNUNET_assert(GNUNET_NO); | 813 | GNUNET_assert(GNUNET_NO); |
757 | } | 814 | } |
758 | 815 | ||
759 | /** | 816 | /** |
760 | * Puts the action into effect | 817 | * Puts the action into effect by calling the according function |
761 | * @param solver solver handle | 818 | * @param solver solver handle |
762 | * @param action action to perform by the solver | 819 | * @param action action to perform by the solver |
763 | */ | 820 | */ |
@@ -795,7 +852,7 @@ envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int | |||
795 | envi_action_bw_dec (solver, agent, GNUNET_NO); | 852 | envi_action_bw_dec (solver, agent, GNUNET_NO); |
796 | break; | 853 | break; |
797 | default: | 854 | default: |
798 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) | 855 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action |
799 | { | 856 | { |
800 | address_index = action - RIL_ACTION_TYPE_NUM; | 857 | address_index = action - RIL_ACTION_TYPE_NUM; |
801 | 858 | ||
@@ -1013,6 +1070,13 @@ ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | |||
1013 | return NULL ; | 1070 | return NULL ; |
1014 | } | 1071 | } |
1015 | 1072 | ||
1073 | /** | ||
1074 | * Determine whether at least the minimum bandwidth is set for the network. Otherwise the network is | ||
1075 | * considered inactive and not used. Addresses in an inactive network are ignored. | ||
1076 | * @param solver solver handle | ||
1077 | * @param network the network type | ||
1078 | * @return | ||
1079 | */ | ||
1016 | static int | 1080 | static int |
1017 | ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network) | 1081 | ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network) |
1018 | { | 1082 | { |
@@ -1025,6 +1089,16 @@ ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Ty | |||
1025 | return GNUNET_YES; | 1089 | return GNUNET_YES; |
1026 | } | 1090 | } |
1027 | 1091 | ||
1092 | /** | ||
1093 | * Cuts a slice out of a vector of elements. This is used to decrease the size of the matrix storing | ||
1094 | * the reward function approximation. It copies the memory, which is not cut, to the new vector, | ||
1095 | * frees the memory of the old vector, and redirects the pointer to the new one. | ||
1096 | * @param old pointer to the pointer to the first element of the vector | ||
1097 | * @param element_size byte size of the vector elements | ||
1098 | * @param hole_start the first element to cut out | ||
1099 | * @param hole_length the number of elements to cut out | ||
1100 | * @param old_length the length of the old vector | ||
1101 | */ | ||
1028 | static void | 1102 | static void |
1029 | ril_cut_from_vector (void **old, | 1103 | ril_cut_from_vector (void **old, |
1030 | size_t element_size, | 1104 | size_t element_size, |
@@ -1055,14 +1129,8 @@ ril_cut_from_vector (void **old, | |||
1055 | } | 1129 | } |
1056 | else | 1130 | else |
1057 | { | 1131 | { |
1058 | // LOG(GNUNET_ERROR_TYPE_DEBUG, "hole_start = %d, hole_length = %d, old_length = %d\n", hole_start, hole_length, old_length); | ||
1059 | // LOG(GNUNET_ERROR_TYPE_DEBUG, "bytes_before = %d, bytes_hole = %d, bytes_after = %d\n", bytes_before, bytes_hole, bytes_after); | ||
1060 | // LOG(GNUNET_ERROR_TYPE_DEBUG, "element_size = %d, bytes_old = %d, bytes_new = %d\n", element_size, old_length * element_size, size); | ||
1061 | |||
1062 | tmpptr = GNUNET_malloc (size); | 1132 | tmpptr = GNUNET_malloc (size); |
1063 | // LOG(GNUNET_ERROR_TYPE_DEBUG, "first\n"); | ||
1064 | memcpy (tmpptr, oldptr, bytes_before); | 1133 | memcpy (tmpptr, oldptr, bytes_before); |
1065 | // LOG(GNUNET_ERROR_TYPE_DEBUG, "second\n"); | ||
1066 | memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); | 1134 | memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); |
1067 | } | 1135 | } |
1068 | if (NULL != *old) | 1136 | if (NULL != *old) |
@@ -1072,7 +1140,7 @@ ril_cut_from_vector (void **old, | |||
1072 | *old = (void *) tmpptr; | 1140 | *old = (void *) tmpptr; |
1073 | } | 1141 | } |
1074 | 1142 | ||
1075 | /** | 1143 | /* |
1076 | * Solver API functions | 1144 | * Solver API functions |
1077 | * --------------------------- | 1145 | * --------------------------- |
1078 | */ | 1146 | */ |
@@ -1390,11 +1458,9 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o | |||
1390 | 1458 | ||
1391 | for (i = 0; i < agent->n; i++) | 1459 | for (i = 0; i < agent->n; i++) |
1392 | { | 1460 | { |
1393 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "first - cut vectors in W\n"); | ||
1394 | ril_cut_from_vector ((void **) &agent->W[i], sizeof(double), | 1461 | ril_cut_from_vector ((void **) &agent->W[i], sizeof(double), |
1395 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); | 1462 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); |
1396 | } | 1463 | } |
1397 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "second - cut action vector out of W\n"); | ||
1398 | GNUNET_free (agent->W[RIL_ACTION_TYPE_NUM + address_index]); | 1464 | GNUNET_free (agent->W[RIL_ACTION_TYPE_NUM + address_index]); |
1399 | ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, | 1465 | ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, |
1400 | 1, agent->n); | 1466 | 1, agent->n); |
@@ -1408,10 +1474,8 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o | |||
1408 | agent->a_old = RIL_ACTION_INVALID; | 1474 | agent->a_old = RIL_ACTION_INVALID; |
1409 | } | 1475 | } |
1410 | //decrease old state vector and eligibility vector | 1476 | //decrease old state vector and eligibility vector |
1411 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "third - cut state vector\n"); | ||
1412 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), | 1477 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), |
1413 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); | 1478 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); |
1414 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "fourth - cut eligibility vector\n"); | ||
1415 | ril_cut_from_vector ((void **) &agent->e, sizeof(double), | 1479 | ril_cut_from_vector ((void **) &agent->e, sizeof(double), |
1416 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); | 1480 | ((s->networks_count * RIL_FEATURES_NETWORK_COUNT) + (address_index * RIL_FEATURES_ADDRESS_COUNT)), RIL_FEATURES_ADDRESS_COUNT, agent->m); |
1417 | agent->m = m_new; | 1481 | agent->m = m_new; |