diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-04 13:45:39 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-04 13:45:39 +0000 |
commit | 08f8e2a63dd400e10f9233fdf31dc8075312803e (patch) | |
tree | 0b04e7e07ce76de128d02a083976125e663ff198 /src | |
parent | c9ff33b9a7421d4f6659722a077c00399c68c2e3 (diff) | |
download | gnunet-08f8e2a63dd400e10f9233fdf31dc8075312803e.tar.gz gnunet-08f8e2a63dd400e10f9233fdf31dc8075312803e.zip |
restructure
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/gnunet-service-ats.c | 5 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 198 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 2 |
3 files changed, 95 insertions, 110 deletions
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index e9a11a8b8..915a18c2a 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -41,6 +41,7 @@ struct GNUNET_STATISTICS_Handle *GSA_stats; | |||
41 | 41 | ||
42 | static struct GNUNET_SERVER_Handle *GSA_server; | 42 | static struct GNUNET_SERVER_Handle *GSA_server; |
43 | 43 | ||
44 | struct GAS_Addresses_Handle *GSA_addresses; | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * We have received a 'ClientStartMessage' from a client. Find out which | 47 | * We have received a 'ClientStartMessage' from a client. Find out which |
@@ -109,7 +110,7 @@ client_disconnect_handler (void *cls, struct GNUNET_SERVER_Client *client) | |||
109 | static void | 110 | static void |
110 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 111 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
111 | { | 112 | { |
112 | GAS_addresses_done (); | 113 | GAS_addresses_done (GSA_addresses); |
113 | GAS_scheduling_done (); | 114 | GAS_scheduling_done (); |
114 | GAS_performance_done (); | 115 | GAS_performance_done (); |
115 | GAS_reservations_done (); | 116 | GAS_reservations_done (); |
@@ -168,7 +169,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
168 | GAS_reservations_init (); | 169 | GAS_reservations_init (); |
169 | GAS_performance_init (server); | 170 | GAS_performance_init (server); |
170 | GAS_scheduling_init (server); | 171 | GAS_scheduling_init (server); |
171 | GAS_addresses_init (cfg, GSA_stats); | 172 | GSA_addresses = GAS_addresses_init (cfg, GSA_stats); |
172 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL); | 173 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL); |
173 | GNUNET_SERVER_add_handlers (server, handlers); | 174 | GNUNET_SERVER_add_handlers (server, handlers); |
174 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, | 175 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 586bed79d..d03d186c8 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -62,22 +62,24 @@ enum ATS_Mode | |||
62 | MODE_MLP | 62 | MODE_MLP |
63 | }; | 63 | }; |
64 | 64 | ||
65 | static struct GNUNET_CONTAINER_MultiHashMap *addresses; | ||
66 | 65 | ||
67 | static unsigned long long wan_quota_in; | ||
68 | 66 | ||
69 | static unsigned long long wan_quota_out; | ||
70 | 67 | ||
71 | static unsigned int active_addr_count; | ||
72 | 68 | ||
73 | static int ats_mode; | ||
74 | |||
75 | static int running; | ||
76 | |||
77 | void *solver; | ||
78 | 69 | ||
79 | struct GAS_Addresses_Handle | 70 | struct GAS_Addresses_Handle |
80 | { | 71 | { |
72 | struct GNUNET_CONTAINER_MultiHashMap *addresses; | ||
73 | |||
74 | unsigned long long wan_quota_in; | ||
75 | |||
76 | unsigned long long wan_quota_out; | ||
77 | |||
78 | unsigned int active_addr_count; | ||
79 | |||
80 | int running; | ||
81 | |||
82 | |||
81 | int ats_mode; | 83 | int ats_mode; |
82 | /* Solver handle */ | 84 | /* Solver handle */ |
83 | void *solver; | 85 | void *solver; |
@@ -89,6 +91,7 @@ struct GAS_Addresses_Handle | |||
89 | GAS_solver_address_change_preference s_pref; | 91 | GAS_solver_address_change_preference s_pref; |
90 | }; | 92 | }; |
91 | 93 | ||
94 | struct GAS_Addresses_Handle *handle; | ||
92 | 95 | ||
93 | static unsigned int | 96 | static unsigned int |
94 | assemble_ats_information (struct ATS_Address *aa, struct GNUNET_ATS_Information **dest) | 97 | assemble_ats_information (struct ATS_Address *aa, struct GNUNET_ATS_Information **dest) |
@@ -156,12 +159,12 @@ update_bw_simple_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
156 | 159 | ||
157 | if (GNUNET_YES != aa->active) | 160 | if (GNUNET_YES != aa->active) |
158 | return GNUNET_OK; | 161 | return GNUNET_OK; |
159 | GNUNET_assert (active_addr_count > 0); | 162 | GNUNET_assert (handle->active_addr_count > 0); |
160 | 163 | ||
161 | 164 | ||
162 | /* Simple method */ | 165 | /* Simple method */ |
163 | aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count); | 166 | aa->assigned_bw_in.value__ = htonl (handle->wan_quota_in / handle->active_addr_count); |
164 | aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count); | 167 | aa->assigned_bw_out.value__ = htonl (handle->wan_quota_out / handle->active_addr_count); |
165 | 168 | ||
166 | send_bw_notification (aa); | 169 | send_bw_notification (aa); |
167 | 170 | ||
@@ -180,10 +183,10 @@ recalculate_assigned_bw () | |||
180 | "Recalculating bandwidth for all active connections\n"); | 183 | "Recalculating bandwidth for all active connections\n"); |
181 | GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed", | 184 | GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed", |
182 | 1, GNUNET_NO); | 185 | 1, GNUNET_NO); |
183 | GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count, | 186 | GNUNET_STATISTICS_set (GSA_stats, "# active addresses", handle->active_addr_count, |
184 | GNUNET_NO); | 187 | GNUNET_NO); |
185 | 188 | ||
186 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL); | 189 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &update_bw_simple_it, NULL); |
187 | } | 190 | } |
188 | 191 | ||
189 | /** | 192 | /** |
@@ -239,18 +242,18 @@ destroy_address (struct ATS_Address *addr) | |||
239 | 242 | ||
240 | ret = GNUNET_NO; | 243 | ret = GNUNET_NO; |
241 | GNUNET_assert (GNUNET_YES == | 244 | GNUNET_assert (GNUNET_YES == |
242 | GNUNET_CONTAINER_multihashmap_remove (addresses, | 245 | GNUNET_CONTAINER_multihashmap_remove (handle->addresses, |
243 | &addr->peer.hashPubKey, | 246 | &addr->peer.hashPubKey, |
244 | addr)); | 247 | addr)); |
245 | 248 | ||
246 | #if HAVE_LIBGLPK | 249 | #if HAVE_LIBGLPK |
247 | if (ats_mode == MODE_MLP) | 250 | if (handle->ats_mode == MODE_MLP) |
248 | GAS_mlp_address_delete (solver, addresses, addr); | 251 | GAS_mlp_address_delete (handle->solver, handle->addresses, addr); |
249 | #endif | 252 | #endif |
250 | 253 | ||
251 | if (GNUNET_YES == addr->active) | 254 | if (GNUNET_YES == addr->active) |
252 | { | 255 | { |
253 | active_addr_count--; | 256 | handle->active_addr_count--; |
254 | addr->active = GNUNET_NO; | 257 | addr->active = GNUNET_NO; |
255 | ret = GNUNET_YES; | 258 | ret = GNUNET_YES; |
256 | } | 259 | } |
@@ -359,7 +362,7 @@ find_address (const struct GNUNET_PeerIdentity *peer, | |||
359 | cac.exact_address = NULL; | 362 | cac.exact_address = NULL; |
360 | cac.base_address = NULL; | 363 | cac.base_address = NULL; |
361 | cac.search = addr; | 364 | cac.search = addr; |
362 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 365 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, |
363 | &compare_address_it, &cac); | 366 | &compare_address_it, &cac); |
364 | 367 | ||
365 | #if 0 | 368 | #if 0 |
@@ -409,7 +412,6 @@ lookup_address (const struct GNUNET_PeerIdentity *peer, | |||
409 | } | 412 | } |
410 | 413 | ||
411 | 414 | ||
412 | #if DEADCODE | ||
413 | static int | 415 | static int |
414 | compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 416 | compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value) |
415 | { | 417 | { |
@@ -420,7 +422,7 @@ compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void | |||
420 | { | 422 | { |
421 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id)) | 423 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id)) |
422 | { | 424 | { |
423 | cac->exact_address = aa; | 425 | cac->exact_address = aa; |
424 | return GNUNET_NO; | 426 | return GNUNET_NO; |
425 | } | 427 | } |
426 | } | 428 | } |
@@ -445,11 +447,10 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer, | |||
445 | 447 | ||
446 | cac.exact_address = NULL; | 448 | cac.exact_address = NULL; |
447 | cac.search = addr; | 449 | cac.search = addr; |
448 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 450 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, |
449 | &compare_address_session_it, &cac); | 451 | &compare_address_session_it, &cac); |
450 | return cac.exact_address; | 452 | return cac.exact_address; |
451 | } | 453 | } |
452 | #endif | ||
453 | 454 | ||
454 | 455 | ||
455 | void | 456 | void |
@@ -462,10 +463,10 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
462 | struct ATS_Address *aa; | 463 | struct ATS_Address *aa; |
463 | struct ATS_Address *old; | 464 | struct ATS_Address *old; |
464 | 465 | ||
465 | if (GNUNET_NO == running) | 466 | if (GNUNET_NO == handle->running) |
466 | return; | 467 | return; |
467 | 468 | ||
468 | GNUNET_assert (NULL != addresses); | 469 | GNUNET_assert (NULL != handle->addresses); |
469 | 470 | ||
470 | aa = create_address (peer, | 471 | aa = create_address (peer, |
471 | plugin_name, | 472 | plugin_name, |
@@ -483,7 +484,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
483 | { | 484 | { |
484 | /* We have a new address */ | 485 | /* We have a new address */ |
485 | GNUNET_assert (GNUNET_OK == | 486 | GNUNET_assert (GNUNET_OK == |
486 | GNUNET_CONTAINER_multihashmap_put (addresses, | 487 | GNUNET_CONTAINER_multihashmap_put (handle->addresses, |
487 | &peer->hashPubKey, aa, | 488 | &peer->hashPubKey, aa, |
488 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 489 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n", | 490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n", |
@@ -526,10 +527,10 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
526 | struct ATS_Address *old; | 527 | struct ATS_Address *old; |
527 | uint32_t i; | 528 | uint32_t i; |
528 | 529 | ||
529 | if (GNUNET_NO == running) | 530 | if (GNUNET_NO == handle->running) |
530 | return; | 531 | return; |
531 | 532 | ||
532 | GNUNET_assert (NULL != addresses); | 533 | GNUNET_assert (NULL != handle->addresses); |
533 | 534 | ||
534 | /* Get existing address */ | 535 | /* Get existing address */ |
535 | old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, | 536 | old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
@@ -578,13 +579,13 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
578 | } | 579 | } |
579 | 580 | ||
580 | /* Tell solver about update */ | 581 | /* Tell solver about update */ |
581 | switch (ats_mode) | 582 | switch (handle->ats_mode) |
582 | { | 583 | { |
583 | case MODE_MLP: | 584 | case MODE_MLP: |
584 | GAS_mlp_address_update (solver, addresses, old); | 585 | GAS_mlp_address_update (handle->solver, handle->addresses, old); |
585 | break; | 586 | break; |
586 | case MODE_SIMPLISTIC: | 587 | case MODE_SIMPLISTIC: |
587 | GAS_simplistic_address_update (solver, addresses, old); | 588 | GAS_simplistic_address_update (handle->solver, handle->addresses, old); |
588 | break; | 589 | break; |
589 | default: | 590 | default: |
590 | GNUNET_break (0); | 591 | GNUNET_break (0); |
@@ -642,7 +643,7 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu | |||
642 | if (GNUNET_YES == aa->active) | 643 | if (GNUNET_YES == aa->active) |
643 | { | 644 | { |
644 | aa->active = GNUNET_NO; | 645 | aa->active = GNUNET_NO; |
645 | active_addr_count--; | 646 | handle->active_addr_count--; |
646 | recalculate_assigned_bw (); | 647 | recalculate_assigned_bw (); |
647 | } | 648 | } |
648 | 649 | ||
@@ -658,8 +659,8 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu | |||
658 | { | 659 | { |
659 | /* session was set to 0, update address */ | 660 | /* session was set to 0, update address */ |
660 | #if HAVE_LIBGLPK | 661 | #if HAVE_LIBGLPK |
661 | if (ats_mode == MODE_MLP) | 662 | if (handle->ats_mode == MODE_MLP) |
662 | GAS_mlp_address_update (solver, addresses, aa); | 663 | GAS_mlp_address_update (handle->solver, handle->addresses, aa); |
663 | #endif | 664 | #endif |
664 | } | 665 | } |
665 | 666 | ||
@@ -675,7 +676,7 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
675 | struct ATS_Address *aa; | 676 | struct ATS_Address *aa; |
676 | struct ATS_Address *old; | 677 | struct ATS_Address *old; |
677 | 678 | ||
678 | if (GNUNET_NO == running) | 679 | if (GNUNET_NO == handle->running) |
679 | return; | 680 | return; |
680 | 681 | ||
681 | /* Get existing address */ | 682 | /* Get existing address */ |
@@ -692,7 +693,7 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
692 | GNUNET_break (0 < strlen (plugin_name)); | 693 | GNUNET_break (0 < strlen (plugin_name)); |
693 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); | 694 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); |
694 | 695 | ||
695 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 696 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, |
696 | &destroy_by_session_id, aa); | 697 | &destroy_by_session_id, aa); |
697 | 698 | ||
698 | free_address (aa); | 699 | free_address (aa); |
@@ -801,7 +802,7 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | |||
801 | 802 | ||
802 | struct ATS_Address *old; | 803 | struct ATS_Address *old; |
803 | 804 | ||
804 | if (GNUNET_NO == running) | 805 | if (GNUNET_NO == handle->running) |
805 | return GNUNET_SYSERR; | 806 | return GNUNET_SYSERR; |
806 | 807 | ||
807 | old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id, NULL, 0); | 808 | old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id, NULL, 0); |
@@ -828,13 +829,13 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | |||
828 | old->used = in_use; | 829 | old->used = in_use; |
829 | 830 | ||
830 | /* Tell solver about update */ | 831 | /* Tell solver about update */ |
831 | switch (ats_mode) | 832 | switch (handle->ats_mode) |
832 | { | 833 | { |
833 | case MODE_MLP: | 834 | case MODE_MLP: |
834 | GAS_mlp_address_update (solver, addresses, old); | 835 | GAS_mlp_address_update (handle->solver, handle->addresses, old); |
835 | break; | 836 | break; |
836 | case MODE_SIMPLISTIC: | 837 | case MODE_SIMPLISTIC: |
837 | GAS_simplistic_address_update (solver, addresses, old); | 838 | GAS_simplistic_address_update (handle->solver, handle->addresses, old); |
838 | break; | 839 | break; |
839 | default: | 840 | default: |
840 | GNUNET_break (0); | 841 | GNUNET_break (0); |
@@ -871,8 +872,7 @@ request_address_mlp (const struct GNUNET_PeerIdentity *peer) | |||
871 | if (aa->active == GNUNET_NO) | 872 | if (aa->active == GNUNET_NO) |
872 | { | 873 | { |
873 | aa->active = GNUNET_YES; | 874 | aa->active = GNUNET_YES; |
874 | active_addr_count++; | 875 | handle->active_addr_count++; |
875 | |||
876 | send_bw_notification (aa); | 876 | send_bw_notification (aa); |
877 | } | 877 | } |
878 | else | 878 | else |
@@ -895,7 +895,7 @@ request_address_simple (const struct GNUNET_PeerIdentity *peer) | |||
895 | aa = NULL; | 895 | aa = NULL; |
896 | 896 | ||
897 | /* Get address with: stick to current address, lower distance, lower latency */ | 897 | /* Get address with: stick to current address, lower distance, lower latency */ |
898 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 898 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, |
899 | &find_address_it, &aa); | 899 | &find_address_it, &aa); |
900 | if (aa == NULL) | 900 | if (aa == NULL) |
901 | { | 901 | { |
@@ -910,8 +910,8 @@ request_address_simple (const struct GNUNET_PeerIdentity *peer) | |||
910 | if (aa->active == GNUNET_NO) | 910 | if (aa->active == GNUNET_NO) |
911 | { | 911 | { |
912 | aa->active = GNUNET_YES; | 912 | aa->active = GNUNET_YES; |
913 | active_addr_count++; | 913 | handle->active_addr_count++; |
914 | if (ats_mode == MODE_SIMPLISTIC) | 914 | if (handle->ats_mode == MODE_SIMPLISTIC) |
915 | { | 915 | { |
916 | recalculate_assigned_bw (); | 916 | recalculate_assigned_bw (); |
917 | } | 917 | } |
@@ -931,14 +931,14 @@ request_address_simple (const struct GNUNET_PeerIdentity *peer) | |||
931 | void | 931 | void |
932 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | 932 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) |
933 | { | 933 | { |
934 | if (GNUNET_NO == running) | 934 | if (GNUNET_NO == handle->running) |
935 | return; | 935 | return; |
936 | 936 | ||
937 | if (ats_mode == MODE_SIMPLISTIC) | 937 | if (handle->ats_mode == MODE_SIMPLISTIC) |
938 | { | 938 | { |
939 | request_address_simple (peer); | 939 | request_address_simple (peer); |
940 | } | 940 | } |
941 | if (ats_mode == MODE_MLP) | 941 | if (handle->ats_mode == MODE_MLP) |
942 | { | 942 | { |
943 | request_address_mlp(peer); | 943 | request_address_mlp(peer); |
944 | } | 944 | } |
@@ -962,7 +962,7 @@ reset_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
962 | void | 962 | void |
963 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) | 963 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) |
964 | { | 964 | { |
965 | GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (addresses, | 965 | GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, |
966 | &peer->hashPubKey, | 966 | &peer->hashPubKey, |
967 | &reset_address_it, | 967 | &reset_address_it, |
968 | NULL)); | 968 | NULL)); |
@@ -977,18 +977,18 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, | |||
977 | enum GNUNET_ATS_PreferenceKind kind, | 977 | enum GNUNET_ATS_PreferenceKind kind, |
978 | float score) | 978 | float score) |
979 | { | 979 | { |
980 | if (GNUNET_NO == running) | 980 | if (GNUNET_NO == handle->running) |
981 | return; | 981 | return; |
982 | 982 | ||
983 | 983 | ||
984 | /* Tell solver about update */ | 984 | /* Tell solver about update */ |
985 | switch (ats_mode) | 985 | switch (handle->ats_mode) |
986 | { | 986 | { |
987 | case MODE_MLP: | 987 | case MODE_MLP: |
988 | GAS_mlp_address_change_preference (solver, peer, kind, score); | 988 | GAS_mlp_address_change_preference (handle->solver, peer, kind, score); |
989 | break; | 989 | break; |
990 | case MODE_SIMPLISTIC: | 990 | case MODE_SIMPLISTIC: |
991 | GAS_simplistic_address_change_preference (solver, peer, kind, score); | 991 | GAS_simplistic_address_change_preference (handle->solver, peer, kind, score); |
992 | break; | 992 | break; |
993 | default: | 993 | default: |
994 | GNUNET_break (0); | 994 | GNUNET_break (0); |
@@ -1009,50 +1009,49 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1009 | const struct GNUNET_STATISTICS_Handle *stats) | 1009 | const struct GNUNET_STATISTICS_Handle *stats) |
1010 | { | 1010 | { |
1011 | struct GAS_Addresses_Handle *ah; | 1011 | struct GAS_Addresses_Handle *ah; |
1012 | int c; | ||
1013 | char *quota_wan_in_str; | 1012 | char *quota_wan_in_str; |
1014 | char *quota_wan_out_str; | 1013 | char *quota_wan_out_str; |
1015 | char *mode_str; | 1014 | char *mode_str; |
1016 | running = GNUNET_NO; | 1015 | int c; |
1016 | |||
1017 | ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle)); | ||
1018 | handle = ah; | ||
1019 | handle->running = GNUNET_NO; | ||
1017 | 1020 | ||
1018 | /* Initialize the system with configuration values */ | 1021 | /* Initialize the system with configuration values */ |
1019 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", "a_wan_in_str)) | 1022 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", "a_wan_in_str)) |
1020 | { | 1023 | { |
1021 | if (0 == strcmp(quota_wan_in_str, "unlimited") || | 1024 | if (0 == strcmp(quota_wan_in_str, "unlimited") || |
1022 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_in_str, &wan_quota_in))) | 1025 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_in_str, &ah->wan_quota_in))) |
1023 | wan_quota_in = (UINT32_MAX) /10; | 1026 | ah->wan_quota_in = (UINT32_MAX) /10; |
1024 | 1027 | ||
1025 | GNUNET_free (quota_wan_in_str); | 1028 | GNUNET_free (quota_wan_in_str); |
1026 | quota_wan_in_str = NULL; | 1029 | quota_wan_in_str = NULL; |
1027 | } | 1030 | } |
1028 | else | 1031 | else |
1029 | { | 1032 | ah->wan_quota_in = (UINT32_MAX) /10; |
1030 | wan_quota_in = (UINT32_MAX) /10; | ||
1031 | } | ||
1032 | 1033 | ||
1033 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_OUT", "a_wan_out_str)) | 1034 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_OUT", "a_wan_out_str)) |
1034 | { | 1035 | { |
1035 | if (0 == strcmp(quota_wan_out_str, "unlimited") || | 1036 | if (0 == strcmp(quota_wan_out_str, "unlimited") || |
1036 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_out_str, &wan_quota_out))) | 1037 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_out_str, &ah->wan_quota_out))) |
1037 | wan_quota_out = (UINT32_MAX) /10; | 1038 | ah->wan_quota_out = (UINT32_MAX) /10; |
1038 | 1039 | ||
1039 | GNUNET_free (quota_wan_out_str); | 1040 | GNUNET_free (quota_wan_out_str); |
1040 | quota_wan_out_str = NULL; | 1041 | quota_wan_out_str = NULL; |
1041 | } | 1042 | } |
1042 | else | 1043 | else |
1043 | { | 1044 | ah->wan_quota_out = (UINT32_MAX) /10; |
1044 | wan_quota_out = (UINT32_MAX) /10; | ||
1045 | } | ||
1046 | 1045 | ||
1047 | /* Initialize the addresses database */ | 1046 | /* Initialize the addresses database */ |
1048 | addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | 1047 | ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); |
1049 | GNUNET_assert (NULL != addresses); | 1048 | GNUNET_assert (NULL != ah->addresses); |
1050 | 1049 | ||
1051 | /* Figure out configured solution method */ | 1050 | /* Figure out configured solution method */ |
1052 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) | 1051 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) |
1053 | { | 1052 | { |
1054 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No ressource assignment method configured, using simplistic approch\n"); | 1053 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No ressource assignment method configured, using simplistic approch\n"); |
1055 | ats_mode = MODE_SIMPLISTIC; | 1054 | ah->ats_mode = MODE_SIMPLISTIC; |
1056 | } | 1055 | } |
1057 | else | 1056 | else |
1058 | { | 1057 | { |
@@ -1060,28 +1059,24 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1060 | mode_str[c] = toupper (mode_str[c]); | 1059 | mode_str[c] = toupper (mode_str[c]); |
1061 | if (0 == strcmp (mode_str, "SIMPLISTIC")) | 1060 | if (0 == strcmp (mode_str, "SIMPLISTIC")) |
1062 | { | 1061 | { |
1063 | ats_mode = MODE_SIMPLISTIC; | 1062 | ah->ats_mode = MODE_SIMPLISTIC; |
1064 | } | 1063 | } |
1065 | else if (0 == strcmp (mode_str, "MLP")) | 1064 | else if (0 == strcmp (mode_str, "MLP")) |
1066 | { | 1065 | { |
1067 | ats_mode = MODE_MLP; | 1066 | ah->ats_mode = MODE_MLP; |
1068 | #if !HAVE_LIBGLPK | 1067 | #if !HAVE_LIBGLPK |
1069 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not availabe, please install \n", mode_str); | 1068 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not availabe, please install \n", mode_str); |
1070 | ats_mode = MODE_SIMPLISTIC; | 1069 | ah->ats_mode = MODE_SIMPLISTIC; |
1071 | #endif | 1070 | #endif |
1072 | } | 1071 | } |
1073 | else | 1072 | else |
1074 | { | 1073 | { |
1075 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid ressource assignment method `%s' configured, using simplistic approch\n", mode_str); | 1074 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid ressource assignment method `%s' configured, using simplistic approch\n", mode_str); |
1076 | ats_mode = MODE_SIMPLISTIC; | 1075 | ah->ats_mode = MODE_SIMPLISTIC; |
1077 | } | 1076 | } |
1078 | } | 1077 | } |
1079 | |||
1080 | |||
1081 | ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle)); | ||
1082 | |||
1083 | /* Start configured solution method */ | 1078 | /* Start configured solution method */ |
1084 | switch (ats_mode) | 1079 | switch (ah->ats_mode) |
1085 | { | 1080 | { |
1086 | case MODE_MLP: | 1081 | case MODE_MLP: |
1087 | /* Init the MLP solver with default values */ | 1082 | /* Init the MLP solver with default values */ |
@@ -1092,7 +1087,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1092 | ah->s_del = &GAS_mlp_address_delete; | 1087 | ah->s_del = &GAS_mlp_address_delete; |
1093 | ah->s_done = &GAS_mlp_done; | 1088 | ah->s_done = &GAS_mlp_done; |
1094 | #else | 1089 | #else |
1095 | GNUNET_freee (ah); | 1090 | GNUNET_free (ah); |
1096 | return NULL; | 1091 | return NULL; |
1097 | #endif | 1092 | #endif |
1098 | break; | 1093 | break; |
@@ -1116,7 +1111,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1116 | GNUNET_assert (NULL != ah->s_done); | 1111 | GNUNET_assert (NULL != ah->s_done); |
1117 | 1112 | ||
1118 | ah->solver = ah->s_init (cfg, stats); | 1113 | ah->solver = ah->s_init (cfg, stats); |
1119 | /* REMOVE */ solver = ah->solver; | ||
1120 | if (NULL == ah->solver) | 1114 | if (NULL == ah->solver) |
1121 | { | 1115 | { |
1122 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n"); | 1116 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n"); |
@@ -1125,7 +1119,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1125 | } | 1119 | } |
1126 | 1120 | ||
1127 | /* up and running */ | 1121 | /* up and running */ |
1128 | running = GNUNET_YES; | 1122 | ah->running = GNUNET_YES; |
1129 | return ah; | 1123 | return ah; |
1130 | } | 1124 | } |
1131 | 1125 | ||
@@ -1151,12 +1145,12 @@ free_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
1151 | void | 1145 | void |
1152 | GAS_addresses_destroy_all () | 1146 | GAS_addresses_destroy_all () |
1153 | { | 1147 | { |
1154 | if (GNUNET_NO == running) | 1148 | if (GNUNET_NO == handle->running) |
1155 | return; | 1149 | return; |
1156 | 1150 | ||
1157 | if (addresses != NULL) | 1151 | if (handle->addresses != NULL) |
1158 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); | 1152 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &free_address_it, NULL); |
1159 | GNUNET_assert (active_addr_count == 0); | 1153 | GNUNET_assert (handle->active_addr_count == 0); |
1160 | } | 1154 | } |
1161 | 1155 | ||
1162 | 1156 | ||
@@ -1164,27 +1158,17 @@ GAS_addresses_destroy_all () | |||
1164 | * Shutdown address subsystem. | 1158 | * Shutdown address subsystem. |
1165 | */ | 1159 | */ |
1166 | void | 1160 | void |
1167 | GAS_addresses_done () | 1161 | GAS_addresses_done (struct GAS_Addresses_Handle *handle) |
1168 | { | 1162 | { |
1169 | GAS_addresses_destroy_all (); | 1163 | GNUNET_assert (NULL != handle); |
1170 | running = GNUNET_NO; | ||
1171 | GNUNET_CONTAINER_multihashmap_destroy (addresses); | ||
1172 | addresses = NULL; | ||
1173 | 1164 | ||
1165 | GAS_addresses_destroy_all (); | ||
1166 | handle->running = GNUNET_NO; | ||
1167 | GNUNET_CONTAINER_multihashmap_destroy (handle->addresses); | ||
1168 | handle->addresses = NULL; | ||
1169 | GNUNET_free (handle); | ||
1174 | /* Stop configured solution method */ | 1170 | /* Stop configured solution method */ |
1175 | switch (ats_mode) | 1171 | |
1176 | { | ||
1177 | case MODE_MLP: | ||
1178 | /* Init the MLP solver with default values */ | ||
1179 | GAS_mlp_done (solver); | ||
1180 | break; | ||
1181 | case MODE_SIMPLISTIC: | ||
1182 | /* Init the simplistic solver with default values */ | ||
1183 | GAS_simplistic_done (solver); | ||
1184 | break; | ||
1185 | default: | ||
1186 | break; | ||
1187 | } | ||
1188 | } | 1172 | } |
1189 | 1173 | ||
1190 | struct PeerIteratorContext | 1174 | struct PeerIteratorContext |
@@ -1227,15 +1211,15 @@ GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls) | |||
1227 | 1211 | ||
1228 | if (NULL == p_it) | 1212 | if (NULL == p_it) |
1229 | return; | 1213 | return; |
1230 | GNUNET_assert (NULL != addresses); | 1214 | GNUNET_assert (NULL != handle->addresses); |
1231 | 1215 | ||
1232 | size = GNUNET_CONTAINER_multihashmap_size(addresses); | 1216 | size = GNUNET_CONTAINER_multihashmap_size(handle->addresses); |
1233 | if (0 != size) | 1217 | if (0 != size) |
1234 | { | 1218 | { |
1235 | ip_ctx.it = p_it; | 1219 | ip_ctx.it = p_it; |
1236 | ip_ctx.it_cls = p_it_cls; | 1220 | ip_ctx.it_cls = p_it_cls; |
1237 | ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO); | 1221 | ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO); |
1238 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &peer_it, &ip_ctx); | 1222 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, &ip_ctx); |
1239 | GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); | 1223 | GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); |
1240 | } | 1224 | } |
1241 | p_it (p_it_cls, NULL); | 1225 | p_it (p_it_cls, NULL); |
@@ -1289,7 +1273,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_ | |||
1289 | struct PeerInfoIteratorContext pi_ctx; | 1273 | struct PeerInfoIteratorContext pi_ctx; |
1290 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; | 1274 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; |
1291 | GNUNET_assert (NULL != peer); | 1275 | GNUNET_assert (NULL != peer); |
1292 | GNUNET_assert (NULL != addresses); | 1276 | GNUNET_assert (NULL != handle->addresses); |
1293 | if (NULL == pi_it) | 1277 | if (NULL == pi_it) |
1294 | return; /* does not make sense without callback */ | 1278 | return; /* does not make sense without callback */ |
1295 | 1279 | ||
@@ -1297,7 +1281,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_ | |||
1297 | pi_ctx.it = pi_it; | 1281 | pi_ctx.it = pi_it; |
1298 | pi_ctx.it_cls = pi_it_cls; | 1282 | pi_ctx.it_cls = pi_it_cls; |
1299 | 1283 | ||
1300 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx); | 1284 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx); |
1301 | 1285 | ||
1302 | if (NULL != pi_it) | 1286 | if (NULL != pi_it) |
1303 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, zero_bw); | 1287 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, zero_bw); |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 54fb7b7cb..b5e28cbf1 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -128,7 +128,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
128 | * Shutdown address subsystem. | 128 | * Shutdown address subsystem. |
129 | */ | 129 | */ |
130 | void | 130 | void |
131 | GAS_addresses_done (void); | 131 | GAS_addresses_done (struct GAS_Addresses_Handle *handle); |
132 | 132 | ||
133 | void | 133 | void |
134 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer); | 134 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer); |