diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-22 23:04:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-22 23:04:40 +0000 |
commit | a57305cef1ec471aea627810955e6f6cec36d847 (patch) | |
tree | 475a79a451277b60033a9919fb2499c197cc77ab /src/ats/gnunet-service-ats_addresses.c | |
parent | 78b8e1c2a54c44992a16b65cdf67fea973e2cad0 (diff) | |
download | gnunet-a57305cef1ec471aea627810955e6f6cec36d847.tar.gz gnunet-a57305cef1ec471aea627810955e6f6cec36d847.zip |
use statics instead of singleton struct, simplify internal APIs
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 584 |
1 files changed, 271 insertions, 313 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 73c19173b..d89c9af0d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -272,77 +272,69 @@ struct GAS_Addresses_Preference_Clients | |||
272 | 272 | ||
273 | 273 | ||
274 | /** | 274 | /** |
275 | * Handle for ATS address component. | 275 | * |
276 | * FIXME: these should probably all be 'static's instead. | ||
277 | */ | 276 | */ |
278 | struct GAS_Addresses_Handle | 277 | static struct GNUNET_STATISTICS_Handle *stats; |
279 | { | ||
280 | /** | ||
281 | * | ||
282 | */ | ||
283 | struct GNUNET_STATISTICS_Handle *stat; | ||
284 | 278 | ||
285 | /** | 279 | /** |
286 | * A multihashmap to store all addresses | 280 | * A multihashmap to store all addresses |
287 | */ | 281 | */ |
288 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; | 282 | static struct GNUNET_CONTAINER_MultiPeerMap *addresses; |
289 | |||
290 | /** | ||
291 | * Is ATS addresses running | ||
292 | */ | ||
293 | int running; | ||
294 | 283 | ||
295 | /** | 284 | /** |
296 | * Preferences clients | 285 | * Is ATS addresses running |
297 | */ | 286 | */ |
298 | int pref_clients; | 287 | static int running; |
299 | 288 | ||
300 | /** | 289 | /** |
301 | * Configured ATS solver | 290 | * Preferences clients |
302 | */ | 291 | */ |
303 | int ats_mode; | 292 | static int pref_clients; |
304 | 293 | ||
305 | /** | 294 | /** |
306 | * Solver handle | 295 | * Configured ATS solver |
307 | */ | 296 | */ |
308 | void *solver; | 297 | static int ats_mode; |
309 | 298 | ||
310 | /** | 299 | /** |
311 | * Address suggestion requests DLL head | 300 | * Solver handle |
312 | */ | 301 | */ |
313 | struct GAS_Addresses_Suggestion_Requests *pending_requests_head; | 302 | static void *solver; |
314 | 303 | ||
315 | /** | 304 | /** |
316 | * Address suggestion requests DLL tail | 305 | * Address suggestion requests DLL head |
317 | */ | 306 | */ |
318 | struct GAS_Addresses_Suggestion_Requests *pending_requests_tail; | 307 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_head; |
319 | 308 | ||
320 | /** | 309 | /** |
321 | * Preference requests DLL head | 310 | * Address suggestion requests DLL tail |
322 | */ | 311 | */ |
323 | struct GAS_Addresses_Preference_Clients *preference_clients_head; | 312 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_tail; |
324 | 313 | ||
325 | /** | 314 | /** |
326 | * Preference requests DLL head | 315 | * Preference requests DLL head |
327 | */ | 316 | */ |
328 | struct GAS_Addresses_Preference_Clients *preference_clients_tail; | 317 | static struct GAS_Addresses_Preference_Clients *preference_clients_head; |
329 | 318 | ||
330 | /** | 319 | /** |
331 | * Solver functions | 320 | * Preference requests DLL head |
332 | */ | 321 | */ |
333 | struct GNUNET_ATS_PluginEnvironment env; | 322 | static struct GAS_Addresses_Preference_Clients *preference_clients_tail; |
334 | 323 | ||
335 | /** | 324 | /** |
336 | * Solver plugin name as string | 325 | * Solver functions |
337 | */ | 326 | */ |
338 | char *plugin; | 327 | static struct GNUNET_ATS_PluginEnvironment env; |
339 | }; | ||
340 | 328 | ||
329 | /** | ||
330 | * Solver plugin name as string | ||
331 | */ | ||
332 | static char *plugin; | ||
341 | 333 | ||
342 | /** | 334 | /** |
343 | * Value we pass for zero bandwidth. | 335 | * Value we pass for zero bandwidth. |
344 | */ | 336 | */ |
345 | const static struct GNUNET_BANDWIDTH_Value32NBO zero_bw; | 337 | static const struct GNUNET_BANDWIDTH_Value32NBO zero_bw; |
346 | 338 | ||
347 | 339 | ||
348 | /** | 340 | /** |
@@ -618,14 +610,12 @@ compare_address_it (void *cls, | |||
618 | * Compares by peer identity and network address OR by session ID | 610 | * Compares by peer identity and network address OR by session ID |
619 | * (one of the two must match). | 611 | * (one of the two must match). |
620 | * | 612 | * |
621 | * @param handle the address handle | ||
622 | * @param peer peer to lookup addresses for | 613 | * @param peer peer to lookup addresses for |
623 | * @param addr existing address record | 614 | * @param addr existing address record |
624 | * @return existing address record, NULL for none | 615 | * @return existing address record, NULL for none |
625 | */ | 616 | */ |
626 | struct ATS_Address * | 617 | struct ATS_Address * |
627 | find_equivalent_address (struct GAS_Addresses_Handle *handle, | 618 | find_equivalent_address (const struct GNUNET_PeerIdentity *peer, |
628 | const struct GNUNET_PeerIdentity *peer, | ||
629 | const struct ATS_Address *addr) | 619 | const struct ATS_Address *addr) |
630 | { | 620 | { |
631 | struct CompareAddressContext cac; | 621 | struct CompareAddressContext cac; |
@@ -633,7 +623,7 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, | |||
633 | cac.exact_address = NULL; | 623 | cac.exact_address = NULL; |
634 | cac.base_address = NULL; | 624 | cac.base_address = NULL; |
635 | cac.search = addr; | 625 | cac.search = addr; |
636 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, | 626 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
637 | peer, | 627 | peer, |
638 | &compare_address_it, &cac); | 628 | &compare_address_it, &cac); |
639 | 629 | ||
@@ -689,21 +679,19 @@ find_address_cb (void *cls, | |||
689 | /** | 679 | /** |
690 | * Find the exact address | 680 | * Find the exact address |
691 | * | 681 | * |
692 | * @param handle the address handle to use | ||
693 | * @param peer peer | 682 | * @param peer peer |
694 | * @param session_id session id, can never be 0 | 683 | * @param session_id session id, can never be 0 |
695 | * @return an ATS_address or NULL | 684 | * @return an ATS_address or NULL |
696 | */ | 685 | */ |
697 | static struct ATS_Address * | 686 | static struct ATS_Address * |
698 | find_exact_address (struct GAS_Addresses_Handle *handle, | 687 | find_exact_address (const struct GNUNET_PeerIdentity *peer, |
699 | const struct GNUNET_PeerIdentity *peer, | ||
700 | uint32_t session_id) | 688 | uint32_t session_id) |
701 | { | 689 | { |
702 | struct FindAddressContext fac; | 690 | struct FindAddressContext fac; |
703 | 691 | ||
704 | fac.exact_address = NULL; | 692 | fac.exact_address = NULL; |
705 | fac.session_id = session_id; | 693 | fac.session_id = session_id; |
706 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, | 694 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
707 | peer, | 695 | peer, |
708 | &find_address_cb, &fac); | 696 | &find_address_cb, &fac); |
709 | return fac.exact_address; | 697 | return fac.exact_address; |
@@ -769,7 +757,6 @@ get_performance_info (struct ATS_Address *address, uint32_t type) | |||
769 | /** | 757 | /** |
770 | * Add a new address for a peer. | 758 | * Add a new address for a peer. |
771 | * | 759 | * |
772 | * @param handle the address handle to use | ||
773 | * @param peer peer | 760 | * @param peer peer |
774 | * @param plugin_name transport plugin name | 761 | * @param plugin_name transport plugin name |
775 | * @param plugin_addr plugin address | 762 | * @param plugin_addr plugin address |
@@ -780,8 +767,7 @@ get_performance_info (struct ATS_Address *address, uint32_t type) | |||
780 | * @param atsi_count number of performance information contained in @a atsi | 767 | * @param atsi_count number of performance information contained in @a atsi |
781 | */ | 768 | */ |
782 | void | 769 | void |
783 | GAS_addresses_add (struct GAS_Addresses_Handle *handle, | 770 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, |
784 | const struct GNUNET_PeerIdentity *peer, | ||
785 | const char *plugin_name, | 771 | const char *plugin_name, |
786 | const void *plugin_addr, | 772 | const void *plugin_addr, |
787 | size_t plugin_addr_len, | 773 | size_t plugin_addr_len, |
@@ -803,10 +789,10 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
803 | "ADDRESS ADD", | 789 | "ADDRESS ADD", |
804 | GNUNET_i2s (peer)); | 790 | GNUNET_i2s (peer)); |
805 | 791 | ||
806 | if (GNUNET_NO == handle->running) | 792 | if (GNUNET_NO == running) |
807 | return; | 793 | return; |
808 | 794 | ||
809 | GNUNET_assert(NULL != handle->addresses); | 795 | GNUNET_assert(NULL != addresses); |
810 | 796 | ||
811 | new_address = create_address (peer, plugin_name, | 797 | new_address = create_address (peer, plugin_name, |
812 | plugin_addr, plugin_addr_len, | 798 | plugin_addr, plugin_addr_len, |
@@ -820,21 +806,21 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
820 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | 806 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; |
821 | 807 | ||
822 | /* Get existing address or address with session == 0 */ | 808 | /* Get existing address or address with session == 0 */ |
823 | existing_address = find_equivalent_address (handle, peer, new_address); | 809 | existing_address = find_equivalent_address (peer, new_address); |
824 | if (NULL == existing_address) | 810 | if (NULL == existing_address) |
825 | { | 811 | { |
826 | /* Add a new address */ | 812 | /* Add a new address */ |
827 | new_address->t_added = GNUNET_TIME_absolute_get(); | 813 | new_address->t_added = GNUNET_TIME_absolute_get(); |
828 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); | 814 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); |
829 | GNUNET_assert(GNUNET_OK == | 815 | GNUNET_assert(GNUNET_OK == |
830 | GNUNET_CONTAINER_multipeermap_put (handle->addresses, | 816 | GNUNET_CONTAINER_multipeermap_put (addresses, |
831 | peer, | 817 | peer, |
832 | new_address, | 818 | new_address, |
833 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 819 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
834 | 820 | ||
835 | GNUNET_STATISTICS_set (handle->stat, | 821 | GNUNET_STATISTICS_set (stats, |
836 | "# addresses", | 822 | "# addresses", |
837 | GNUNET_CONTAINER_multipeermap_size (handle->addresses), | 823 | GNUNET_CONTAINER_multipeermap_size (addresses), |
838 | GNUNET_NO); | 824 | GNUNET_NO); |
839 | 825 | ||
840 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 826 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -846,14 +832,14 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
846 | GNUNET_ATS_print_network_type (addr_net)); | 832 | GNUNET_ATS_print_network_type (addr_net)); |
847 | 833 | ||
848 | /* Tell solver about new address */ | 834 | /* Tell solver about new address */ |
849 | handle->env.sf.s_add (handle->solver, new_address, addr_net); | 835 | env.sf.s_add (solver, new_address, addr_net); |
850 | 836 | ||
851 | handle->env.sf.s_bulk_start (handle->solver); | 837 | env.sf.s_bulk_start (solver); |
852 | GAS_normalization_normalize_property (handle->addresses, | 838 | GAS_normalization_normalize_property (addresses, |
853 | new_address, | 839 | new_address, |
854 | atsi, | 840 | atsi, |
855 | atsi_count); | 841 | atsi_count); |
856 | handle->env.sf.s_bulk_stop (handle->solver); | 842 | env.sf.s_bulk_stop (solver); |
857 | 843 | ||
858 | /* Notify performance clients about new address */ | 844 | /* Notify performance clients about new address */ |
859 | GAS_performance_notify_all_clients (&new_address->peer, new_address->plugin, | 845 | GAS_performance_notify_all_clients (&new_address->peer, new_address->plugin, |
@@ -914,7 +900,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
914 | GNUNET_i2s (peer), existing_address, | 900 | GNUNET_i2s (peer), existing_address, |
915 | GNUNET_ATS_print_network_type (addr_net), | 901 | GNUNET_ATS_print_network_type (addr_net), |
916 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); | 902 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); |
917 | handle->env.sf.s_address_update_network (handle->solver, existing_address, | 903 | env.sf.s_address_update_network (solver, existing_address, |
918 | ntohl (atsi_delta[c1].value), | 904 | ntohl (atsi_delta[c1].value), |
919 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); | 905 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); |
920 | addr_net = get_performance_info (existing_address, | 906 | addr_net = get_performance_info (existing_address, |
@@ -922,10 +908,10 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
922 | } | 908 | } |
923 | } | 909 | } |
924 | /* Notify solver about update with atsi information and session */ | 910 | /* Notify solver about update with atsi information and session */ |
925 | handle->env.sf.s_bulk_start (handle->solver); | 911 | env.sf.s_bulk_start (solver); |
926 | GAS_normalization_normalize_property (handle->addresses, existing_address, | 912 | GAS_normalization_normalize_property (addresses, existing_address, |
927 | atsi, atsi_count); | 913 | atsi, atsi_count); |
928 | handle->env.sf.s_bulk_stop (handle->solver); | 914 | env.sf.s_bulk_stop (solver); |
929 | } | 915 | } |
930 | GNUNET_free_non_null(atsi_delta); | 916 | GNUNET_free_non_null(atsi_delta); |
931 | 917 | ||
@@ -935,7 +921,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
935 | 921 | ||
936 | previous_session = existing_address->session_id; | 922 | previous_session = existing_address->session_id; |
937 | existing_address->session_id = session_id; | 923 | existing_address->session_id = session_id; |
938 | handle->env.sf.s_address_update_session (handle->solver, existing_address, | 924 | env.sf.s_address_update_session (solver, existing_address, |
939 | previous_session, session_id); | 925 | previous_session, session_id); |
940 | 926 | ||
941 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 927 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -948,15 +934,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
948 | /** | 934 | /** |
949 | * Update an address with new performance information for a peer. | 935 | * Update an address with new performance information for a peer. |
950 | * | 936 | * |
951 | * @param handle the address handle to use | ||
952 | * @param peer peer | 937 | * @param peer peer |
953 | * @param session_id session id, never 0 | 938 | * @param session_id session id, never 0 |
954 | * @param atsi performance information for this address | 939 | * @param atsi performance information for this address |
955 | * @param atsi_count number of performance information contained in @a atsi | 940 | * @param atsi_count number of performance information contained in @a atsi |
956 | */ | 941 | */ |
957 | void | 942 | void |
958 | GAS_addresses_update (struct GAS_Addresses_Handle *handle, | 943 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, |
959 | const struct GNUNET_PeerIdentity *peer, | ||
960 | uint32_t session_id, | 944 | uint32_t session_id, |
961 | const struct GNUNET_ATS_Information *atsi, | 945 | const struct GNUNET_ATS_Information *atsi, |
962 | uint32_t atsi_count) | 946 | uint32_t atsi_count) |
@@ -967,13 +951,12 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
967 | uint32_t prev_session; | 951 | uint32_t prev_session; |
968 | int c1; | 952 | int c1; |
969 | 953 | ||
970 | if (GNUNET_NO == handle->running) | 954 | if (GNUNET_NO == running) |
971 | return; | 955 | return; |
972 | GNUNET_assert (NULL != handle->addresses); | 956 | GNUNET_assert (NULL != addresses); |
973 | 957 | ||
974 | /* Get existing address */ | 958 | /* Get existing address */ |
975 | aa = find_exact_address (handle, | 959 | aa = find_exact_address (peer, |
976 | peer, | ||
977 | session_id); | 960 | session_id); |
978 | if (NULL == aa) | 961 | if (NULL == aa) |
979 | { | 962 | { |
@@ -999,10 +982,10 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
999 | /* Session changed */ | 982 | /* Session changed */ |
1000 | prev_session = aa->session_id; | 983 | prev_session = aa->session_id; |
1001 | aa->session_id = session_id; | 984 | aa->session_id = session_id; |
1002 | handle->env.sf.s_address_update_session (handle->solver, | 985 | env.sf.s_address_update_session (solver, |
1003 | aa, | 986 | aa, |
1004 | prev_session, | 987 | prev_session, |
1005 | aa->session_id); | 988 | aa->session_id); |
1006 | } | 989 | } |
1007 | 990 | ||
1008 | atsi_delta = NULL; | 991 | atsi_delta = NULL; |
@@ -1019,7 +1002,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
1019 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) | 1002 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) |
1020 | { | 1003 | { |
1021 | /* Network type changed */ | 1004 | /* Network type changed */ |
1022 | handle->env.sf.s_address_update_network (handle->solver, aa, | 1005 | env.sf.s_address_update_network (solver, aa, |
1023 | ntohl (atsi_delta[c1].value), | 1006 | ntohl (atsi_delta[c1].value), |
1024 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); | 1007 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); |
1025 | } | 1008 | } |
@@ -1031,12 +1014,12 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
1031 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), | 1014 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), |
1032 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); | 1015 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); |
1033 | 1016 | ||
1034 | handle->env.sf.s_bulk_start (handle->solver); | 1017 | env.sf.s_bulk_start (solver); |
1035 | GAS_normalization_normalize_property (handle->addresses, | 1018 | GAS_normalization_normalize_property (addresses, |
1036 | aa, | 1019 | aa, |
1037 | atsi, | 1020 | atsi, |
1038 | atsi_count); | 1021 | atsi_count); |
1039 | handle->env.sf.s_bulk_stop (handle->solver); | 1022 | env.sf.s_bulk_stop (solver); |
1040 | } | 1023 | } |
1041 | GNUNET_free_non_null (atsi_delta); | 1024 | GNUNET_free_non_null (atsi_delta); |
1042 | } | 1025 | } |
@@ -1045,23 +1028,20 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
1045 | /** | 1028 | /** |
1046 | * Remove an address or just a session for a peer. | 1029 | * Remove an address or just a session for a peer. |
1047 | * | 1030 | * |
1048 | * @param handle the address handle to use | ||
1049 | * @param peer peer | 1031 | * @param peer peer |
1050 | * @param session_id session id, can never be 0 | 1032 | * @param session_id session id, can never be 0 |
1051 | */ | 1033 | */ |
1052 | void | 1034 | void |
1053 | GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | 1035 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, |
1054 | const struct GNUNET_PeerIdentity *peer, | ||
1055 | uint32_t session_id) | 1036 | uint32_t session_id) |
1056 | { | 1037 | { |
1057 | struct ATS_Address *ea; | 1038 | struct ATS_Address *ea; |
1058 | 1039 | ||
1059 | if (GNUNET_NO == handle->running) | 1040 | if (GNUNET_NO == running) |
1060 | return; | 1041 | return; |
1061 | 1042 | ||
1062 | /* Get existing address */ | 1043 | /* Get existing address */ |
1063 | ea = find_exact_address (handle, | 1044 | ea = find_exact_address (peer, |
1064 | peer, | ||
1065 | session_id); | 1045 | session_id); |
1066 | if (NULL == ea) | 1046 | if (NULL == ea) |
1067 | { | 1047 | { |
@@ -1079,11 +1059,11 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1079 | GNUNET_i2s (peer), | 1059 | GNUNET_i2s (peer), |
1080 | ea, | 1060 | ea, |
1081 | session_id); | 1061 | session_id); |
1082 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, | 1062 | GNUNET_CONTAINER_multipeermap_remove (addresses, |
1083 | peer, | 1063 | peer, |
1084 | ea); | 1064 | ea); |
1085 | 1065 | ||
1086 | handle->env.sf.s_del (handle->solver, ea, GNUNET_NO); | 1066 | env.sf.s_del (solver, ea, GNUNET_NO); |
1087 | GAS_performance_notify_all_clients (peer, | 1067 | GAS_performance_notify_all_clients (peer, |
1088 | ea->plugin, | 1068 | ea->plugin, |
1089 | ea->addr, | 1069 | ea->addr, |
@@ -1093,9 +1073,9 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1093 | zero_bw, | 1073 | zero_bw, |
1094 | zero_bw); | 1074 | zero_bw); |
1095 | free_address (ea); | 1075 | free_address (ea); |
1096 | GNUNET_STATISTICS_set (handle->stat, | 1076 | GNUNET_STATISTICS_set (stats, |
1097 | "# addresses", | 1077 | "# addresses", |
1098 | GNUNET_CONTAINER_multipeermap_size (handle->addresses), | 1078 | GNUNET_CONTAINER_multipeermap_size (addresses), |
1099 | GNUNET_NO); | 1079 | GNUNET_NO); |
1100 | } | 1080 | } |
1101 | 1081 | ||
@@ -1110,15 +1090,13 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1110 | * Note: can only be called with in_use == #GNUNET_NO if called with #GNUNET_YES | 1090 | * Note: can only be called with in_use == #GNUNET_NO if called with #GNUNET_YES |
1111 | * before | 1091 | * before |
1112 | * | 1092 | * |
1113 | * @param handle the address handle to use | ||
1114 | * @param peer peer | 1093 | * @param peer peer |
1115 | * @param session_id session id, can be 0 | 1094 | * @param session_id session id, can be 0 |
1116 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME | 1095 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME |
1117 | * @return #GNUNET_SYSERR on failure (address unknown ...) | 1096 | * @return #GNUNET_SYSERR on failure (address unknown ...) |
1118 | */ | 1097 | */ |
1119 | int | 1098 | int |
1120 | GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | 1099 | GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, |
1121 | const struct GNUNET_PeerIdentity *peer, | ||
1122 | uint32_t session_id, | 1100 | uint32_t session_id, |
1123 | int in_use) | 1101 | int in_use) |
1124 | { | 1102 | { |
@@ -1128,10 +1106,9 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1128 | "Received `%s' for peer `%s'\n", | 1106 | "Received `%s' for peer `%s'\n", |
1129 | "ADDRESS IN USE", | 1107 | "ADDRESS IN USE", |
1130 | GNUNET_i2s (peer)); | 1108 | GNUNET_i2s (peer)); |
1131 | if (GNUNET_NO == handle->running) | 1109 | if (GNUNET_NO == running) |
1132 | return GNUNET_SYSERR; | 1110 | return GNUNET_SYSERR; |
1133 | ea = find_exact_address (handle, | 1111 | ea = find_exact_address (peer, |
1134 | peer, | ||
1135 | session_id); | 1112 | session_id); |
1136 | if (NULL == ea) | 1113 | if (NULL == ea) |
1137 | { | 1114 | { |
@@ -1156,9 +1133,9 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1156 | /* Tell solver about update */ | 1133 | /* Tell solver about update */ |
1157 | ea->used = in_use; | 1134 | ea->used = in_use; |
1158 | ea->t_last_activity = GNUNET_TIME_absolute_get(); | 1135 | ea->t_last_activity = GNUNET_TIME_absolute_get(); |
1159 | handle->env.sf.s_address_update_inuse (handle->solver, | 1136 | env.sf.s_address_update_inuse (solver, |
1160 | ea, | 1137 | ea, |
1161 | ea->used); | 1138 | ea->used); |
1162 | return GNUNET_OK; | 1139 | return GNUNET_OK; |
1163 | } | 1140 | } |
1164 | 1141 | ||
@@ -1166,14 +1143,12 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1166 | /** | 1143 | /** |
1167 | * Cancel address suggestions for a peer | 1144 | * Cancel address suggestions for a peer |
1168 | * | 1145 | * |
1169 | * @param handle the address handle | ||
1170 | * @param peer the peer id | 1146 | * @param peer the peer id |
1171 | */ | 1147 | */ |
1172 | void | 1148 | void |
1173 | GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | 1149 | GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer) |
1174 | const struct GNUNET_PeerIdentity *peer) | ||
1175 | { | 1150 | { |
1176 | struct GAS_Addresses_Suggestion_Requests *cur = handle->pending_requests_head; | 1151 | struct GAS_Addresses_Suggestion_Requests *cur = pending_requests_head; |
1177 | 1152 | ||
1178 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1179 | "Received request: `%s' for peer %s\n", | 1154 | "Received request: `%s' for peer %s\n", |
@@ -1194,13 +1169,13 @@ GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | |||
1194 | GNUNET_i2s (peer)); | 1169 | GNUNET_i2s (peer)); |
1195 | return; | 1170 | return; |
1196 | } | 1171 | } |
1197 | handle->env.sf.s_get_stop (handle->solver, peer); | 1172 | env.sf.s_get_stop (solver, peer); |
1198 | GAS_addresses_handle_backoff_reset (handle, peer); | 1173 | GAS_addresses_handle_backoff_reset (peer); |
1199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Removed request pending for peer `%s\n", | 1175 | "Removed request pending for peer `%s\n", |
1201 | GNUNET_i2s (peer)); | 1176 | GNUNET_i2s (peer)); |
1202 | GNUNET_CONTAINER_DLL_remove (handle->pending_requests_head, | 1177 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, |
1203 | handle->pending_requests_tail, | 1178 | pending_requests_tail, |
1204 | cur); | 1179 | cur); |
1205 | GNUNET_free(cur); | 1180 | GNUNET_free(cur); |
1206 | } | 1181 | } |
@@ -1209,14 +1184,12 @@ GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | |||
1209 | /** | 1184 | /** |
1210 | * Request address suggestions for a peer | 1185 | * Request address suggestions for a peer |
1211 | * | 1186 | * |
1212 | * @param handle the address handle | ||
1213 | * @param peer the peer id | 1187 | * @param peer the peer id |
1214 | */ | 1188 | */ |
1215 | void | 1189 | void |
1216 | GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | 1190 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) |
1217 | const struct GNUNET_PeerIdentity *peer) | ||
1218 | { | 1191 | { |
1219 | struct GAS_Addresses_Suggestion_Requests *cur = handle->pending_requests_head; | 1192 | struct GAS_Addresses_Suggestion_Requests *cur = pending_requests_head; |
1220 | struct ATS_Address *aa; | 1193 | struct ATS_Address *aa; |
1221 | 1194 | ||
1222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1195 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -1224,7 +1197,7 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | |||
1224 | "REQUEST ADDRESS", | 1197 | "REQUEST ADDRESS", |
1225 | GNUNET_i2s (peer)); | 1198 | GNUNET_i2s (peer)); |
1226 | 1199 | ||
1227 | if (GNUNET_NO == handle->running) | 1200 | if (GNUNET_NO == running) |
1228 | return; | 1201 | return; |
1229 | while (NULL != cur) | 1202 | while (NULL != cur) |
1230 | { | 1203 | { |
@@ -1239,11 +1212,13 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | |||
1239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1212 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1240 | "Adding new address suggestion request for `%s'\n", | 1213 | "Adding new address suggestion request for `%s'\n", |
1241 | GNUNET_i2s (peer)); | 1214 | GNUNET_i2s (peer)); |
1242 | GNUNET_CONTAINER_DLL_insert(handle->pending_requests_head, handle->pending_requests_tail, cur); | 1215 | GNUNET_CONTAINER_DLL_insert (pending_requests_head, |
1216 | pending_requests_tail, | ||
1217 | cur); | ||
1243 | } | 1218 | } |
1244 | 1219 | ||
1245 | /* Get prefered address from solver */ | 1220 | /* Get prefered address from solver */ |
1246 | aa = (struct ATS_Address *) handle->env.sf.s_get (handle->solver, peer); | 1221 | aa = (struct ATS_Address *) env.sf.s_get (solver, peer); |
1247 | if (NULL == aa) | 1222 | if (NULL == aa) |
1248 | { | 1223 | { |
1249 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | 1224 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", |
@@ -1301,20 +1276,21 @@ reset_address_it (void *cls, | |||
1301 | * Suggesting addresses is blocked for ATS_BLOCKING_DELTA. Blocking can be | 1276 | * Suggesting addresses is blocked for ATS_BLOCKING_DELTA. Blocking can be |
1302 | * reset using this function | 1277 | * reset using this function |
1303 | * | 1278 | * |
1304 | * @param handle the address handle | ||
1305 | * @param peer the peer id | 1279 | * @param peer the peer id |
1306 | */ | 1280 | */ |
1307 | void | 1281 | void |
1308 | GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | 1282 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) |
1309 | const struct GNUNET_PeerIdentity *peer) | ||
1310 | { | 1283 | { |
1311 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n", | 1284 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1312 | "RESET BACKOFF", GNUNET_i2s (peer)); | 1285 | "Received `%s' for peer `%s'\n", |
1286 | "RESET BACKOFF", | ||
1287 | GNUNET_i2s (peer)); | ||
1313 | 1288 | ||
1314 | GNUNET_break( | 1289 | GNUNET_break(GNUNET_SYSERR != |
1315 | GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, | 1290 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
1316 | peer, | 1291 | peer, |
1317 | &reset_address_it, NULL)); | 1292 | &reset_address_it, |
1293 | NULL)); | ||
1318 | } | 1294 | } |
1319 | 1295 | ||
1320 | 1296 | ||
@@ -1323,13 +1299,13 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | |||
1323 | * | 1299 | * |
1324 | * @param cls the closure | 1300 | * @param cls the closure |
1325 | * @param op the operation | 1301 | * @param op the operation |
1326 | * @param stat operation status | 1302 | * @param status operation status |
1327 | * @param add additional information | 1303 | * @param add additional information |
1328 | */ | 1304 | */ |
1329 | static void | 1305 | static void |
1330 | solver_info_cb (void *cls, | 1306 | solver_info_cb (void *cls, |
1331 | enum GAS_Solver_Operation op, | 1307 | enum GAS_Solver_Operation op, |
1332 | enum GAS_Solver_Status stat, | 1308 | enum GAS_Solver_Status status, |
1333 | enum GAS_Solver_Additional_Information add) | 1309 | enum GAS_Solver_Additional_Information add) |
1334 | { | 1310 | { |
1335 | char *add_info; | 1311 | char *add_info; |
@@ -1359,56 +1335,56 @@ solver_info_cb (void *cls, | |||
1359 | case GAS_OP_SOLVE_START: | 1335 | case GAS_OP_SOLVE_START: |
1360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1361 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", | 1337 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", |
1362 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 1338 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", add_info); |
1363 | return; | 1339 | return; |
1364 | case GAS_OP_SOLVE_STOP: | 1340 | case GAS_OP_SOLVE_STOP: |
1365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1341 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1366 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP", | 1342 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP", |
1367 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 1343 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", add_info); |
1368 | return; | 1344 | return; |
1369 | 1345 | ||
1370 | case GAS_OP_SOLVE_SETUP_START: | 1346 | case GAS_OP_SOLVE_SETUP_START: |
1371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1347 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1372 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", | 1348 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", |
1373 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1349 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1374 | return; | 1350 | return; |
1375 | 1351 | ||
1376 | case GAS_OP_SOLVE_SETUP_STOP: | 1352 | case GAS_OP_SOLVE_SETUP_STOP: |
1377 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1353 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1378 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", | 1354 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", |
1379 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1355 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1380 | return; | 1356 | return; |
1381 | 1357 | ||
1382 | case GAS_OP_SOLVE_MLP_LP_START: | 1358 | case GAS_OP_SOLVE_MLP_LP_START: |
1383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1359 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1384 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", | 1360 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", |
1385 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1361 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1386 | return; | 1362 | return; |
1387 | case GAS_OP_SOLVE_MLP_LP_STOP: | 1363 | case GAS_OP_SOLVE_MLP_LP_STOP: |
1388 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1364 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1389 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", | 1365 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", |
1390 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1366 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1391 | return; | 1367 | return; |
1392 | 1368 | ||
1393 | case GAS_OP_SOLVE_MLP_MLP_START: | 1369 | case GAS_OP_SOLVE_MLP_MLP_START: |
1394 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1370 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1395 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", | 1371 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", |
1396 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1372 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1397 | return; | 1373 | return; |
1398 | case GAS_OP_SOLVE_MLP_MLP_STOP: | 1374 | case GAS_OP_SOLVE_MLP_MLP_STOP: |
1399 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1375 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1400 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", | 1376 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", |
1401 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1377 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1402 | return; | 1378 | return; |
1403 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: | 1379 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: |
1404 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1380 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1405 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", | 1381 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", |
1406 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1382 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1407 | return; | 1383 | return; |
1408 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: | 1384 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: |
1409 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1385 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1410 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", | 1386 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", |
1411 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 1387 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
1412 | return; | 1388 | return; |
1413 | default: | 1389 | default: |
1414 | break; | 1390 | break; |
@@ -1419,27 +1395,26 @@ solver_info_cb (void *cls, | |||
1419 | /** | 1395 | /** |
1420 | * The preference changed for a peer | 1396 | * The preference changed for a peer |
1421 | * | 1397 | * |
1422 | * @param cls the address handle | 1398 | * @param cls NULL |
1423 | * @param peer the peer | 1399 | * @param peer the peer |
1424 | * @param kind the ATS kind | 1400 | * @param kind the ATS kind |
1425 | * @param pref_rel the new relative preference value | 1401 | * @param pref_rel the new relative preference value |
1426 | */ | 1402 | */ |
1427 | static void | 1403 | static void |
1428 | normalized_preference_changed_cb (void *cls, | 1404 | normalized_preference_changed_cb (void *cls, |
1429 | const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, | 1405 | const struct GNUNET_PeerIdentity *peer, |
1430 | double pref_rel) | 1406 | enum GNUNET_ATS_PreferenceKind kind, |
1407 | double pref_rel) | ||
1431 | { | 1408 | { |
1432 | GNUNET_assert(NULL != cls); | ||
1433 | struct GAS_Addresses_Handle *handle = cls; | ||
1434 | |||
1435 | /* Tell solver about update */ | 1409 | /* Tell solver about update */ |
1436 | handle->env.sf.s_pref (handle->solver, peer, kind, pref_rel); | 1410 | env.sf.s_pref (solver, peer, kind, pref_rel); |
1437 | } | 1411 | } |
1438 | 1412 | ||
1413 | |||
1439 | /** | 1414 | /** |
1440 | * The relative value for a property changed | 1415 | * The relative value for a property changed |
1441 | * | 1416 | * |
1442 | * @param cls the address handle | 1417 | * @param cls NULL |
1443 | * @param address the peer | 1418 | * @param address the peer |
1444 | * @param type the ATS type | 1419 | * @param type the ATS type |
1445 | * @param prop_rel the new relative preference value | 1420 | * @param prop_rel the new relative preference value |
@@ -1447,29 +1422,30 @@ normalized_preference_changed_cb (void *cls, | |||
1447 | static void | 1422 | static void |
1448 | normalized_property_changed_cb (void *cls, | 1423 | normalized_property_changed_cb (void *cls, |
1449 | struct ATS_Address *address, | 1424 | struct ATS_Address *address, |
1450 | uint32_t type, double prop_rel) | 1425 | uint32_t type, |
1426 | double prop_rel) | ||
1451 | { | 1427 | { |
1452 | struct GAS_Addresses_Handle *ah = cls; | ||
1453 | |||
1454 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1455 | "Normalized property %s for peer `%s' changed to %.3f \n", | 1429 | "Normalized property %s for peer `%s' changed to %.3f \n", |
1456 | GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), | 1430 | GNUNET_ATS_print_property_type (type), |
1457 | prop_rel); | 1431 | GNUNET_i2s (&address->peer), |
1458 | 1432 | prop_rel); | |
1459 | ah->env.sf.s_address_update_property (ah->solver, address, type, 0, prop_rel); | 1433 | env.sf.s_address_update_property (solver, |
1434 | address, | ||
1435 | type, | ||
1436 | 0, | ||
1437 | prop_rel); | ||
1460 | } | 1438 | } |
1461 | 1439 | ||
1462 | 1440 | ||
1463 | static struct GAS_Addresses_Preference_Clients * | 1441 | static struct GAS_Addresses_Preference_Clients * |
1464 | find_preference_client (struct GAS_Addresses_Handle *handle, void *client) | 1442 | find_preference_client (void *client) |
1465 | { | 1443 | { |
1466 | struct GAS_Addresses_Preference_Clients *cur; | 1444 | struct GAS_Addresses_Preference_Clients *cur; |
1467 | 1445 | ||
1468 | for (cur = handle->preference_clients_head; NULL != cur; cur = cur->next) | 1446 | for (cur = preference_clients_head; NULL != cur; cur = cur->next) |
1469 | { | ||
1470 | if (cur->client == client) | 1447 | if (cur->client == client) |
1471 | return cur; | 1448 | return cur; |
1472 | } | ||
1473 | return NULL; | 1449 | return NULL; |
1474 | } | 1450 | } |
1475 | 1451 | ||
@@ -1477,25 +1453,24 @@ find_preference_client (struct GAS_Addresses_Handle *handle, void *client) | |||
1477 | /** | 1453 | /** |
1478 | * A performance client disconnected | 1454 | * A performance client disconnected |
1479 | * | 1455 | * |
1480 | * @param handle address handle | ||
1481 | * @param client the client | 1456 | * @param client the client |
1482 | */ | 1457 | */ |
1483 | void | 1458 | void |
1484 | GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle, | 1459 | GAS_addresses_preference_client_disconnect (void *client) |
1485 | void *client) | ||
1486 | { | 1460 | { |
1487 | struct GAS_Addresses_Preference_Clients *pc; | 1461 | struct GAS_Addresses_Preference_Clients *pc; |
1488 | 1462 | ||
1489 | if (NULL != (pc = find_preference_client (handle, client))) | 1463 | if (NULL != (pc = find_preference_client (client))) |
1490 | { | 1464 | { |
1491 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, | 1465 | GNUNET_CONTAINER_DLL_remove (preference_clients_head, |
1492 | handle->preference_clients_tail, pc); | 1466 | preference_clients_tail, |
1467 | pc); | ||
1493 | GNUNET_free (pc); | 1468 | GNUNET_free (pc); |
1494 | GNUNET_assert (handle->pref_clients > 0); | 1469 | GNUNET_assert (pref_clients > 0); |
1495 | handle->pref_clients --; | 1470 | pref_clients --; |
1496 | GNUNET_STATISTICS_set (handle->stat, | 1471 | GNUNET_STATISTICS_set (stats, |
1497 | "# active performance clients", | 1472 | "# active performance clients", |
1498 | handle->pref_clients, | 1473 | pref_clients, |
1499 | GNUNET_NO); | 1474 | GNUNET_NO); |
1500 | } | 1475 | } |
1501 | GAS_normalization_preference_client_disconnect (client); | 1476 | GAS_normalization_preference_client_disconnect (client); |
@@ -1505,16 +1480,16 @@ GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle, | |||
1505 | /** | 1480 | /** |
1506 | * Change the preference for a peer | 1481 | * Change the preference for a peer |
1507 | * | 1482 | * |
1508 | * @param handle the address handle | ||
1509 | * @param client the client sending this request | 1483 | * @param client the client sending this request |
1510 | * @param peer the peer id | 1484 | * @param peer the peer id |
1511 | * @param kind the preference kind to change | 1485 | * @param kind the preference kind to change |
1512 | * @param score_abs the new preference score | 1486 | * @param score_abs the new preference score |
1513 | */ | 1487 | */ |
1514 | void | 1488 | void |
1515 | GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle, | 1489 | GAS_addresses_preference_change (void *client, |
1516 | void *client, const struct GNUNET_PeerIdentity *peer, | 1490 | const struct GNUNET_PeerIdentity *peer, |
1517 | enum GNUNET_ATS_PreferenceKind kind, float score_abs) | 1491 | enum GNUNET_ATS_PreferenceKind kind, |
1492 | float score_abs) | ||
1518 | { | 1493 | { |
1519 | struct GAS_Addresses_Preference_Clients *pc; | 1494 | struct GAS_Addresses_Preference_Clients *pc; |
1520 | 1495 | ||
@@ -1522,11 +1497,11 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle, | |||
1522 | "Received `%s' for peer `%s' for client %p\n", "CHANGE PREFERENCE", | 1497 | "Received `%s' for peer `%s' for client %p\n", "CHANGE PREFERENCE", |
1523 | GNUNET_i2s (peer), client); | 1498 | GNUNET_i2s (peer), client); |
1524 | 1499 | ||
1525 | if (GNUNET_NO == handle->running) | 1500 | if (GNUNET_NO == running) |
1526 | return; | 1501 | return; |
1527 | 1502 | ||
1528 | if (GNUNET_NO == | 1503 | if (GNUNET_NO == |
1529 | GNUNET_CONTAINER_multipeermap_contains (handle->addresses, | 1504 | GNUNET_CONTAINER_multipeermap_contains (addresses, |
1530 | peer)) | 1505 | peer)) |
1531 | { | 1506 | { |
1532 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -1535,30 +1510,30 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle, | |||
1535 | return; | 1510 | return; |
1536 | } | 1511 | } |
1537 | 1512 | ||
1538 | if (NULL == find_preference_client (handle, client)) | 1513 | if (NULL == find_preference_client (client)) |
1539 | { | 1514 | { |
1540 | pc = GNUNET_new (struct GAS_Addresses_Preference_Clients); | 1515 | pc = GNUNET_new (struct GAS_Addresses_Preference_Clients); |
1541 | pc->client = client; | 1516 | pc->client = client; |
1542 | GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head, | 1517 | GNUNET_CONTAINER_DLL_insert (preference_clients_head, |
1543 | handle->preference_clients_tail, pc); | 1518 | preference_clients_tail, |
1544 | handle->pref_clients ++; | 1519 | pc); |
1545 | GNUNET_STATISTICS_set (handle->stat, | 1520 | pref_clients ++; |
1521 | GNUNET_STATISTICS_set (stats, | ||
1546 | "# active performance clients", | 1522 | "# active performance clients", |
1547 | handle->pref_clients, | 1523 | pref_clients, |
1548 | GNUNET_NO); | 1524 | GNUNET_NO); |
1549 | } | 1525 | } |
1550 | 1526 | ||
1551 | handle->env.sf.s_bulk_start (handle->solver); | 1527 | env.sf.s_bulk_start (solver); |
1552 | /* Tell normalization about change, normalization will call callback if preference changed */ | 1528 | /* Tell normalization about change, normalization will call callback if preference changed */ |
1553 | GAS_normalization_normalize_preference (client, peer, kind, score_abs); | 1529 | GAS_normalization_normalize_preference (client, peer, kind, score_abs); |
1554 | handle->env.sf.s_bulk_stop (handle->solver); | 1530 | env.sf.s_bulk_stop (solver); |
1555 | } | 1531 | } |
1556 | 1532 | ||
1557 | 1533 | ||
1558 | /** | 1534 | /** |
1559 | * Change the preference for a peer | 1535 | * Change the preference for a peer |
1560 | * | 1536 | * |
1561 | * @param handle the address handle | ||
1562 | * @param application the client sending this request | 1537 | * @param application the client sending this request |
1563 | * @param peer the peer id | 1538 | * @param peer the peer id |
1564 | * @param scope the time interval for this feedback: [now - scope .. now] | 1539 | * @param scope the time interval for this feedback: [now - scope .. now] |
@@ -1566,8 +1541,7 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle, | |||
1566 | * @param score_abs the new preference score | 1541 | * @param score_abs the new preference score |
1567 | */ | 1542 | */ |
1568 | void | 1543 | void |
1569 | GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | 1544 | GAS_addresses_preference_feedback (void *application, |
1570 | void *application, | ||
1571 | const struct GNUNET_PeerIdentity *peer, | 1545 | const struct GNUNET_PeerIdentity *peer, |
1572 | const struct GNUNET_TIME_Relative scope, | 1546 | const struct GNUNET_TIME_Relative scope, |
1573 | enum GNUNET_ATS_PreferenceKind kind, | 1547 | enum GNUNET_ATS_PreferenceKind kind, |
@@ -1579,11 +1553,11 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | |||
1579 | GNUNET_i2s (peer), | 1553 | GNUNET_i2s (peer), |
1580 | application); | 1554 | application); |
1581 | 1555 | ||
1582 | if (GNUNET_NO == handle->running) | 1556 | if (GNUNET_NO == running) |
1583 | return; | 1557 | return; |
1584 | 1558 | ||
1585 | if (GNUNET_NO == | 1559 | if (GNUNET_NO == |
1586 | GNUNET_CONTAINER_multipeermap_contains (handle->addresses, | 1560 | GNUNET_CONTAINER_multipeermap_contains (addresses, |
1587 | peer)) | 1561 | peer)) |
1588 | { | 1562 | { |
1589 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1563 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -1592,8 +1566,8 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | |||
1592 | return; | 1566 | return; |
1593 | } | 1567 | } |
1594 | 1568 | ||
1595 | handle->env.sf.s_feedback (handle->solver, application, peer, scope, kind, | 1569 | env.sf.s_feedback (solver, application, peer, scope, kind, |
1596 | score_abs); | 1570 | score_abs); |
1597 | } | 1571 | } |
1598 | 1572 | ||
1599 | 1573 | ||
@@ -1739,18 +1713,16 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1739 | /** | 1713 | /** |
1740 | * Callback for solver to notify about assignment changes | 1714 | * Callback for solver to notify about assignment changes |
1741 | * | 1715 | * |
1742 | * @param cls the GAS_Addresses_Handle | 1716 | * @param cls NULL |
1743 | * @param address the address with changes | 1717 | * @param address the address with changes |
1744 | */ | 1718 | */ |
1745 | static void | 1719 | static void |
1746 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) | 1720 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) |
1747 | { | 1721 | { |
1748 | struct GAS_Addresses_Handle *handle = cls; | ||
1749 | struct GAS_Addresses_Suggestion_Requests *cur; | 1722 | struct GAS_Addresses_Suggestion_Requests *cur; |
1750 | uint32_t diff_out; | 1723 | uint32_t diff_out; |
1751 | uint32_t diff_in; | 1724 | uint32_t diff_in; |
1752 | 1725 | ||
1753 | GNUNET_assert(handle != NULL); | ||
1754 | GNUNET_assert(address != NULL); | 1726 | GNUNET_assert(address != NULL); |
1755 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1756 | "Bandwidth assignment changed for peer %s \n", | 1728 | "Bandwidth assignment changed for peer %s \n", |
@@ -1763,13 +1735,9 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1763 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), | 1735 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), |
1764 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 1736 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); |
1765 | 1737 | ||
1766 | cur = handle->pending_requests_head; | 1738 | for (cur = pending_requests_head;NULL != cur; cur = cur->next) |
1767 | while (NULL != cur) | ||
1768 | { | ||
1769 | if (0 == memcmp (&address->peer, &cur->id, sizeof(cur->id))) | 1739 | if (0 == memcmp (&address->peer, &cur->id, sizeof(cur->id))) |
1770 | break; /* we have an address request pending*/ | 1740 | break; /* we have an address request pending*/ |
1771 | cur = cur->next; | ||
1772 | } | ||
1773 | if (NULL == cur) | 1741 | if (NULL == cur) |
1774 | { | 1742 | { |
1775 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1743 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -1823,28 +1791,25 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1823 | * and receives updates when the solver changes the resource allocation. | 1791 | * and receives updates when the solver changes the resource allocation. |
1824 | * | 1792 | * |
1825 | * @param cfg configuration to use | 1793 | * @param cfg configuration to use |
1826 | * @param stats the statistics handle to use | 1794 | * @param stats_ the statistics handle to use |
1827 | * @return an address handle | 1795 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (failed to load |
1796 | * solver plugin) | ||
1828 | */ | 1797 | */ |
1829 | struct GAS_Addresses_Handle * | 1798 | int |
1830 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1799 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1831 | struct GNUNET_STATISTICS_Handle *stats) | 1800 | struct GNUNET_STATISTICS_Handle *stats_) |
1832 | { | 1801 | { |
1833 | struct GAS_Addresses_Handle *ah; | ||
1834 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; | 1802 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; |
1835 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; | 1803 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; |
1836 | char *mode_str; | 1804 | char *mode_str; |
1837 | char *plugin_short; | 1805 | char *plugin_short; |
1838 | int c; | 1806 | int c; |
1839 | 1807 | ||
1840 | ah = GNUNET_new (struct GAS_Addresses_Handle); | 1808 | running = GNUNET_NO; |
1841 | ah->running = GNUNET_NO; | 1809 | stats = stats_; |
1842 | |||
1843 | ah->stat = stats; | ||
1844 | /* Initialize the addresses database */ | 1810 | /* Initialize the addresses database */ |
1845 | ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 1811 | addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); |
1846 | ah->pref_clients = 0; | 1812 | pref_clients = 0; |
1847 | GNUNET_assert(NULL != ah->addresses); | ||
1848 | 1813 | ||
1849 | /* Figure out configured solution method */ | 1814 | /* Figure out configured solution method */ |
1850 | if (GNUNET_SYSERR == | 1815 | if (GNUNET_SYSERR == |
@@ -1852,59 +1817,59 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1852 | { | 1817 | { |
1853 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1818 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1854 | "No resource assignment method configured, using proportional approach\n"); | 1819 | "No resource assignment method configured, using proportional approach\n"); |
1855 | ah->ats_mode = MODE_PROPORTIONAL; | 1820 | ats_mode = MODE_PROPORTIONAL; |
1856 | } | 1821 | } |
1857 | else | 1822 | else |
1858 | { | 1823 | { |
1859 | for (c = 0; c < strlen (mode_str); c++) | 1824 | for (c = 0; c < strlen (mode_str); c++) |
1860 | mode_str[c] = toupper (mode_str[c]); | 1825 | mode_str[c] = toupper (mode_str[c]); |
1861 | if (0 == strcmp (mode_str, "PROPORTIONAL")) | 1826 | if (0 == strcmp (mode_str, "PROPORTIONAL")) |
1862 | ah->ats_mode = MODE_PROPORTIONAL; | 1827 | ats_mode = MODE_PROPORTIONAL; |
1863 | else if (0 == strcmp (mode_str, "MLP")) | 1828 | else if (0 == strcmp (mode_str, "MLP")) |
1864 | { | 1829 | { |
1865 | ah->ats_mode = MODE_MLP; | 1830 | ats_mode = MODE_MLP; |
1866 | #if !HAVE_LIBGLPK | 1831 | #if !HAVE_LIBGLPK |
1867 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1832 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1868 | "Assignment method `%s' configured, but GLPK is not available, please install \n", | 1833 | "Assignment method `%s' configured, but GLPK is not available, please install \n", |
1869 | mode_str); | 1834 | mode_str); |
1870 | ah->ats_mode = MODE_PROPORTIONAL; | 1835 | ats_mode = MODE_PROPORTIONAL; |
1871 | #endif | 1836 | #endif |
1872 | } | 1837 | } |
1873 | else if (0 == strcmp (mode_str, "RIL")) | 1838 | else if (0 == strcmp (mode_str, "RIL")) |
1874 | ah->ats_mode = MODE_RIL; | 1839 | ats_mode = MODE_RIL; |
1875 | else | 1840 | else |
1876 | { | 1841 | { |
1877 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1842 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1878 | "Invalid resource assignment method `%s' configured, using proportional approach\n", | 1843 | "Invalid resource assignment method `%s' configured, using proportional approach\n", |
1879 | mode_str); | 1844 | mode_str); |
1880 | ah->ats_mode = MODE_PROPORTIONAL; | 1845 | ats_mode = MODE_PROPORTIONAL; |
1881 | } | 1846 | } |
1882 | GNUNET_free(mode_str); | 1847 | GNUNET_free(mode_str); |
1883 | } | 1848 | } |
1884 | 1849 | ||
1885 | load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount); | 1850 | load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount); |
1886 | ah->env.info_cb = &solver_info_cb; | 1851 | env.info_cb = &solver_info_cb; |
1887 | ah->env.info_cb_cls = ah; | 1852 | env.info_cb_cls = NULL; |
1888 | ah->env.bandwidth_changed_cb = &bandwidth_changed_cb; | 1853 | env.bandwidth_changed_cb = &bandwidth_changed_cb; |
1889 | ah->env.bw_changed_cb_cls = ah; | 1854 | env.bw_changed_cb_cls = NULL; |
1890 | ah->env.get_preferences = &get_preferences_cb; | 1855 | env.get_preferences = &get_preferences_cb; |
1891 | ah->env.get_preference_cls = ah; | 1856 | env.get_preference_cls = NULL; |
1892 | ah->env.get_property = &get_property_cb; | 1857 | env.get_property = &get_property_cb; |
1893 | ah->env.get_property_cls = ah; | 1858 | env.get_property_cls = NULL; |
1894 | ah->env.cfg = cfg; | 1859 | env.cfg = cfg; |
1895 | ah->env.stats = stats; | 1860 | env.stats = stats; |
1896 | ah->env.addresses = ah->addresses; | 1861 | env.addresses = addresses; |
1897 | 1862 | ||
1898 | ah->env.network_count = GNUNET_ATS_NetworkTypeCount; | 1863 | env.network_count = GNUNET_ATS_NetworkTypeCount; |
1899 | int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | 1864 | int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; |
1900 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 1865 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) |
1901 | { | 1866 | { |
1902 | ah->env.networks[c] = networks[c]; | 1867 | env.networks[c] = networks[c]; |
1903 | ah->env.out_quota[c] = quotas_out[c]; | 1868 | env.out_quota[c] = quotas_out[c]; |
1904 | ah->env.in_quota[c] = quotas_in[c]; | 1869 | env.in_quota[c] = quotas_in[c]; |
1905 | } | 1870 | } |
1906 | 1871 | ||
1907 | switch (ah->ats_mode) { | 1872 | switch (ats_mode) { |
1908 | case MODE_PROPORTIONAL: | 1873 | case MODE_PROPORTIONAL: |
1909 | plugin_short = "proportional"; | 1874 | plugin_short = "proportional"; |
1910 | break; | 1875 | break; |
@@ -1918,54 +1883,53 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1918 | plugin_short = NULL; | 1883 | plugin_short = NULL; |
1919 | break; | 1884 | break; |
1920 | } | 1885 | } |
1921 | GNUNET_asprintf (&ah->plugin, | 1886 | GNUNET_asprintf (&plugin, |
1922 | "libgnunet_plugin_ats_%s", | 1887 | "libgnunet_plugin_ats_%s", |
1923 | plugin_short); | 1888 | plugin_short); |
1924 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1889 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1925 | _("Initializing solver `%s '`%s'\n"), | 1890 | _("Initializing solver `%s '`%s'\n"), |
1926 | plugin_short, | 1891 | plugin_short, |
1927 | ah->plugin); | 1892 | plugin); |
1928 | if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env))) | 1893 | if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) |
1929 | { | 1894 | { |
1930 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1895 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1931 | _("Failed to initialize solver `%s'!\n"), | 1896 | _("Failed to initialize solver `%s'!\n"), |
1932 | ah->plugin); | 1897 | plugin); |
1933 | return NULL; | 1898 | return GNUNET_SYSERR; |
1934 | } | 1899 | } |
1935 | 1900 | ||
1936 | GNUNET_assert (NULL != ah->env.sf.s_add); | 1901 | GNUNET_assert (NULL != env.sf.s_add); |
1937 | GNUNET_assert (NULL != ah->env.sf.s_address_update_inuse); | 1902 | GNUNET_assert (NULL != env.sf.s_address_update_inuse); |
1938 | GNUNET_assert (NULL != ah->env.sf.s_address_update_property); | 1903 | GNUNET_assert (NULL != env.sf.s_address_update_property); |
1939 | GNUNET_assert (NULL != ah->env.sf.s_address_update_session); | 1904 | GNUNET_assert (NULL != env.sf.s_address_update_session); |
1940 | GNUNET_assert (NULL != ah->env.sf.s_address_update_network); | 1905 | GNUNET_assert (NULL != env.sf.s_address_update_network); |
1941 | GNUNET_assert (NULL != ah->env.sf.s_get); | 1906 | GNUNET_assert (NULL != env.sf.s_get); |
1942 | GNUNET_assert (NULL != ah->env.sf.s_get_stop); | 1907 | GNUNET_assert (NULL != env.sf.s_get_stop); |
1943 | GNUNET_assert (NULL != ah->env.sf.s_pref); | 1908 | GNUNET_assert (NULL != env.sf.s_pref); |
1944 | GNUNET_assert (NULL != ah->env.sf.s_feedback); | 1909 | GNUNET_assert (NULL != env.sf.s_feedback); |
1945 | GNUNET_assert (NULL != ah->env.sf.s_del); | 1910 | GNUNET_assert (NULL != env.sf.s_del); |
1946 | GNUNET_assert (NULL != ah->env.sf.s_bulk_start); | 1911 | GNUNET_assert (NULL != env.sf.s_bulk_start); |
1947 | GNUNET_assert (NULL != ah->env.sf.s_bulk_stop); | 1912 | GNUNET_assert (NULL != env.sf.s_bulk_stop); |
1948 | 1913 | ||
1949 | 1914 | ||
1950 | GAS_normalization_start (&normalized_preference_changed_cb, ah, | 1915 | GAS_normalization_start (&normalized_preference_changed_cb, NULL, |
1951 | &normalized_property_changed_cb, ah); | 1916 | &normalized_property_changed_cb, NULL); |
1952 | 1917 | ||
1953 | if (NULL == ah->solver) | 1918 | if (NULL == solver) |
1954 | { | 1919 | { |
1955 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1920 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1956 | _("Failed to initialize solver!\n")); | 1921 | _("Failed to initialize solver!\n")); |
1957 | GNUNET_free(ah); | 1922 | return GNUNET_SYSERR; |
1958 | return NULL ; | ||
1959 | } | 1923 | } |
1960 | /* up and running */ | 1924 | /* up and running */ |
1961 | ah->running = GNUNET_YES; | 1925 | running = GNUNET_YES; |
1962 | 1926 | ||
1963 | GNUNET_STATISTICS_set (ah->stat, | 1927 | GNUNET_STATISTICS_set (stats, |
1964 | "# addresses", | 1928 | "# addresses", |
1965 | GNUNET_CONTAINER_multipeermap_size (ah->addresses), | 1929 | GNUNET_CONTAINER_multipeermap_size (addresses), |
1966 | GNUNET_NO); | 1930 | GNUNET_NO); |
1967 | 1931 | ||
1968 | return ah; | 1932 | return GNUNET_OK; |
1969 | } | 1933 | } |
1970 | 1934 | ||
1971 | 1935 | ||
@@ -1982,14 +1946,15 @@ destroy_all_address_it (void *cls, | |||
1982 | const struct GNUNET_PeerIdentity *key, | 1946 | const struct GNUNET_PeerIdentity *key, |
1983 | void *value) | 1947 | void *value) |
1984 | { | 1948 | { |
1985 | struct GAS_Addresses_Handle *handle = cls; | ||
1986 | struct ATS_Address *aa = value; | 1949 | struct ATS_Address *aa = value; |
1987 | 1950 | ||
1988 | /* Remove */ | 1951 | /* Remove */ |
1989 | GNUNET_assert(GNUNET_YES == | 1952 | GNUNET_assert(GNUNET_YES == |
1990 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, key, value)); | 1953 | GNUNET_CONTAINER_multipeermap_remove (addresses, |
1954 | key, | ||
1955 | value)); | ||
1991 | /* Notify */ | 1956 | /* Notify */ |
1992 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); | 1957 | env.sf.s_del (solver, aa, GNUNET_NO); |
1993 | /* Destroy */ | 1958 | /* Destroy */ |
1994 | GAS_performance_notify_all_clients (&aa->peer, | 1959 | GAS_performance_notify_all_clients (&aa->peer, |
1995 | aa->plugin, | 1960 | aa->plugin, |
@@ -2006,68 +1971,63 @@ destroy_all_address_it (void *cls, | |||
2006 | 1971 | ||
2007 | /** | 1972 | /** |
2008 | * Remove all addresses | 1973 | * Remove all addresses |
2009 | * | ||
2010 | * @param handle the address handle to use | ||
2011 | */ | 1974 | */ |
2012 | void | 1975 | void |
2013 | GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle) | 1976 | GAS_addresses_destroy_all () |
2014 | { | 1977 | { |
2015 | if (GNUNET_NO == handle->running) | 1978 | if (GNUNET_NO == running) |
2016 | return; | 1979 | return; |
2017 | 1980 | ||
2018 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1981 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2019 | "Destroying all addresses\n"); | 1982 | "Destroying all addresses\n"); |
2020 | handle->env.sf.s_bulk_start (handle->solver); | 1983 | env.sf.s_bulk_start (solver); |
2021 | if (NULL != handle->addresses) | 1984 | if (NULL != addresses) |
2022 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, | 1985 | GNUNET_CONTAINER_multipeermap_iterate (addresses, |
2023 | &destroy_all_address_it, | 1986 | &destroy_all_address_it, |
2024 | handle); | 1987 | NULL); |
2025 | handle->env.sf.s_bulk_start (handle->solver); | 1988 | env.sf.s_bulk_start (solver); |
2026 | } | 1989 | } |
2027 | 1990 | ||
2028 | 1991 | ||
2029 | /** | 1992 | /** |
2030 | * Shutdown address subsystem. | 1993 | * Shutdown address subsystem. |
2031 | * | ||
2032 | * @param handle the address handle to shutdown | ||
2033 | */ | 1994 | */ |
2034 | void | 1995 | void |
2035 | GAS_addresses_done (struct GAS_Addresses_Handle *handle) | 1996 | GAS_addresses_done () |
2036 | { | 1997 | { |
2037 | struct GAS_Addresses_Suggestion_Requests *cur; | 1998 | struct GAS_Addresses_Suggestion_Requests *cur; |
2038 | struct GAS_Addresses_Preference_Clients *pcur; | 1999 | struct GAS_Addresses_Preference_Clients *pcur; |
2039 | 2000 | ||
2040 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Shutting down addresses\n"); | 2001 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2041 | GNUNET_assert(NULL != handle); | 2002 | "Shutting down addresses\n"); |
2042 | GAS_addresses_destroy_all (handle); | 2003 | GAS_addresses_destroy_all (); |
2043 | handle->running = GNUNET_NO; | 2004 | running = GNUNET_NO; |
2044 | GNUNET_CONTAINER_multipeermap_destroy (handle->addresses); | 2005 | GNUNET_CONTAINER_multipeermap_destroy (addresses); |
2045 | handle->addresses = NULL; | 2006 | addresses = NULL; |
2046 | while (NULL != (cur = handle->pending_requests_head)) | 2007 | while (NULL != (cur = pending_requests_head)) |
2047 | { | 2008 | { |
2048 | GNUNET_CONTAINER_DLL_remove (handle->pending_requests_head, | 2009 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, |
2049 | handle->pending_requests_tail, | 2010 | pending_requests_tail, |
2050 | cur); | 2011 | cur); |
2051 | GNUNET_free(cur); | 2012 | GNUNET_free(cur); |
2052 | } | 2013 | } |
2053 | 2014 | ||
2054 | while (NULL != (pcur = handle->preference_clients_head)) | 2015 | while (NULL != (pcur = preference_clients_head)) |
2055 | { | 2016 | { |
2056 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, | 2017 | GNUNET_CONTAINER_DLL_remove (preference_clients_head, |
2057 | handle->preference_clients_tail, | 2018 | preference_clients_tail, |
2058 | pcur); | 2019 | pcur); |
2059 | GNUNET_assert (handle->pref_clients > 0); | 2020 | GNUNET_assert (pref_clients > 0); |
2060 | handle->pref_clients --; | 2021 | pref_clients --; |
2061 | GNUNET_STATISTICS_set (handle->stat, | 2022 | GNUNET_STATISTICS_set (stats, |
2062 | "# active performance clients", | 2023 | "# active performance clients", |
2063 | handle->pref_clients, | 2024 | pref_clients, |
2064 | GNUNET_NO); | 2025 | GNUNET_NO); |
2065 | GNUNET_free (pcur); | 2026 | GNUNET_free (pcur); |
2066 | } | 2027 | } |
2067 | GNUNET_PLUGIN_unload (handle->plugin, | 2028 | GNUNET_PLUGIN_unload (plugin, |
2068 | handle->solver); | 2029 | solver); |
2069 | GNUNET_free (handle->plugin); | 2030 | GNUNET_free (plugin); |
2070 | GNUNET_free(handle); | ||
2071 | /* Stop configured solution method */ | 2031 | /* Stop configured solution method */ |
2072 | GAS_normalization_stop (); | 2032 | GAS_normalization_stop (); |
2073 | } | 2033 | } |
@@ -2122,14 +2082,12 @@ peerinfo_it (void *cls, | |||
2122 | /** | 2082 | /** |
2123 | * Return information all peers currently known to ATS | 2083 | * Return information all peers currently known to ATS |
2124 | * | 2084 | * |
2125 | * @param handle the address handle to use | ||
2126 | * @param peer the respective peer, NULL for 'all' peers | 2085 | * @param peer the respective peer, NULL for 'all' peers |
2127 | * @param pi_it the iterator to call for every peer | 2086 | * @param pi_it the iterator to call for every peer |
2128 | * @param pi_it_cls the closure for @a pi_it | 2087 | * @param pi_it_cls the closure for @a pi_it |
2129 | */ | 2088 | */ |
2130 | void | 2089 | void |
2131 | GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | 2090 | GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, |
2132 | const struct GNUNET_PeerIdentity *peer, | ||
2133 | GNUNET_ATS_PeerInfo_Iterator pi_it, | 2091 | GNUNET_ATS_PeerInfo_Iterator pi_it, |
2134 | void *pi_it_cls) | 2092 | void *pi_it_cls) |
2135 | { | 2093 | { |
@@ -2146,15 +2104,15 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | |||
2146 | (NULL == peer) | 2104 | (NULL == peer) |
2147 | ? "all peers" | 2105 | ? "all peers" |
2148 | : GNUNET_i2s (peer), | 2106 | : GNUNET_i2s (peer), |
2149 | (unsigned int) GNUNET_CONTAINER_multipeermap_size (handle->addresses)); | 2107 | (unsigned int) GNUNET_CONTAINER_multipeermap_size (addresses)); |
2150 | pi_ctx.it = pi_it; | 2108 | pi_ctx.it = pi_it; |
2151 | pi_ctx.it_cls = pi_it_cls; | 2109 | pi_ctx.it_cls = pi_it_cls; |
2152 | if (NULL == peer) | 2110 | if (NULL == peer) |
2153 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, | 2111 | GNUNET_CONTAINER_multipeermap_iterate (addresses, |
2154 | &peerinfo_it, | 2112 | &peerinfo_it, |
2155 | &pi_ctx); | 2113 | &pi_ctx); |
2156 | else | 2114 | else |
2157 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, | 2115 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
2158 | peer, | 2116 | peer, |
2159 | &peerinfo_it, &pi_ctx); | 2117 | &peerinfo_it, &pi_ctx); |
2160 | pi_it (pi_it_cls, | 2118 | pi_it (pi_it_cls, |