diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-04-16 08:50:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-04-16 08:50:19 +0000 |
commit | 2cf8e99766e1102658075923a1dfbe691fcdc54e (patch) | |
tree | cc0c754e9b4a1adee14556fecbbdc8175116bee3 /src/ats/ats_api_performance.c | |
parent | aad13d29a78ab43a690e4dcff08a64ba414b0f3f (diff) | |
download | gnunet-2cf8e99766e1102658075923a1dfbe691fcdc54e.tar.gz gnunet-2cf8e99766e1102658075923a1dfbe691fcdc54e.zip |
-doxygen, indentation, new FIXME: disconnect needs to notify clients
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r-- | src/ats/ats_api_performance.c | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 90e061c1d..a1d8dc21a 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -55,6 +55,7 @@ struct PendingMessage | |||
55 | int is_init; | 55 | int is_init; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | |||
58 | /** | 59 | /** |
59 | * Linked list of pending reservations. | 60 | * Linked list of pending reservations. |
60 | */ | 61 | */ |
@@ -87,13 +88,13 @@ struct GNUNET_ATS_ReservationContext | |||
87 | GNUNET_ATS_ReservationCallback rcb; | 88 | GNUNET_ATS_ReservationCallback rcb; |
88 | 89 | ||
89 | /** | 90 | /** |
90 | * Closure for 'rcb' | 91 | * Closure for @e rcb |
91 | */ | 92 | */ |
92 | void *rcb_cls; | 93 | void *rcb_cls; |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * Do we need to undo this reservation if it succeeded? Set to | 96 | * Do we need to undo this reservation if it succeeded? Set to |
96 | * GNUNET_YES if a reservation is cancelled. (at that point, 'info' | 97 | * #GNUNET_YES if a reservation is cancelled. (at that point, 'info' |
97 | * is also set to NULL; however, info will ALSO be NULL for the | 98 | * is also set to NULL; however, info will ALSO be NULL for the |
98 | * reservation context that is created to undo the original request, | 99 | * reservation context that is created to undo the original request, |
99 | * so 'info' being NULL cannot be used to check if undo is | 100 | * so 'info' being NULL cannot be used to check if undo is |
@@ -102,6 +103,7 @@ struct GNUNET_ATS_ReservationContext | |||
102 | int undo; | 103 | int undo; |
103 | }; | 104 | }; |
104 | 105 | ||
106 | |||
105 | /** | 107 | /** |
106 | * Linked list of pending reservations. | 108 | * Linked list of pending reservations. |
107 | */ | 109 | */ |
@@ -154,6 +156,7 @@ struct GNUNET_ATS_AddressListHandle | |||
154 | uint32_t id; | 156 | uint32_t id; |
155 | }; | 157 | }; |
156 | 158 | ||
159 | |||
157 | /** | 160 | /** |
158 | * ATS Handle to obtain and/or modify performance information. | 161 | * ATS Handle to obtain and/or modify performance information. |
159 | */ | 162 | */ |
@@ -171,7 +174,7 @@ struct GNUNET_ATS_PerformanceHandle | |||
171 | GNUNET_ATS_AddressInformationCallback addr_info_cb; | 174 | GNUNET_ATS_AddressInformationCallback addr_info_cb; |
172 | 175 | ||
173 | /** | 176 | /** |
174 | * Closure for 'addr_info_cb'. | 177 | * Closure for @e addr_info_cb. |
175 | */ | 178 | */ |
176 | void *addr_info_cb_cls; | 179 | void *addr_info_cb_cls; |
177 | 180 | ||
@@ -239,6 +242,7 @@ struct GNUNET_ATS_PerformanceHandle | |||
239 | static void | 242 | static void |
240 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | 243 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); |
241 | 244 | ||
245 | |||
242 | /** | 246 | /** |
243 | * Re-establish the connection to the ATS service. | 247 | * Re-establish the connection to the ATS service. |
244 | * | 248 | * |
@@ -246,7 +250,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | |||
246 | * @param tc scheduler context | 250 | * @param tc scheduler context |
247 | */ | 251 | */ |
248 | static void | 252 | static void |
249 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 253 | reconnect_task (void *cls, |
254 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
250 | { | 255 | { |
251 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 256 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
252 | 257 | ||
@@ -254,6 +259,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
254 | reconnect (ph); | 259 | reconnect (ph); |
255 | } | 260 | } |
256 | 261 | ||
262 | |||
257 | /** | 263 | /** |
258 | * Transmit messages from the message queue to the service | 264 | * Transmit messages from the message queue to the service |
259 | * (if there are any, and if we are not already trying). | 265 | * (if there are any, and if we are not already trying). |
@@ -263,15 +269,18 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
263 | static void | 269 | static void |
264 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); | 270 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); |
265 | 271 | ||
272 | |||
266 | /** | 273 | /** |
267 | * Type of a function to call when we receive a message | 274 | * Type of a function to call when we receive a message |
268 | * from the service. | 275 | * from the service. |
269 | * | 276 | * |
270 | * @param cls the 'struct GNUNET_ATS_SchedulingHandle' | 277 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` |
271 | * @param msg message received, NULL on timeout or fatal error | 278 | * @param msg message received, NULL on timeout or fatal error |
272 | */ | 279 | */ |
273 | static void | 280 | static void |
274 | process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg); | 281 | process_ats_message (void *cls, |
282 | const struct GNUNET_MessageHeader *msg); | ||
283 | |||
275 | 284 | ||
276 | /** | 285 | /** |
277 | * We can now transmit a message to ATS. Do it. | 286 | * We can now transmit a message to ATS. Do it. |
@@ -304,6 +313,7 @@ transmit_message_to_ats (void *cls, size_t size, void *buf) | |||
304 | return ret; | 313 | return ret; |
305 | } | 314 | } |
306 | 315 | ||
316 | |||
307 | /** | 317 | /** |
308 | * Transmit messages from the message queue to the service | 318 | * Transmit messages from the message queue to the service |
309 | * (if there are any, and if we are not already trying). | 319 | * (if there are any, and if we are not already trying). |
@@ -325,16 +335,17 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) | |||
325 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph); | 335 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph); |
326 | } | 336 | } |
327 | 337 | ||
338 | |||
328 | /** | 339 | /** |
329 | * We received a peer information message. Validate and process it. | 340 | * We received a peer information message. Validate and process it. |
330 | * | 341 | * |
331 | * @param ph our context with the callback | 342 | * @param ph our context with the callback |
332 | * @param msg the message | 343 | * @param msg the message |
333 | * @return GNUNET_OK if the message was well-formed | 344 | * @return #GNUNET_OK if the message was well-formed |
334 | */ | 345 | */ |
335 | static int | 346 | static int |
336 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | 347 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, |
337 | const struct GNUNET_MessageHeader *msg) | 348 | const struct GNUNET_MessageHeader *msg) |
338 | { | 349 | { |
339 | const struct PeerInformationMessage *pi; | 350 | const struct PeerInformationMessage *pi; |
340 | const struct GNUNET_ATS_Information *atsi; | 351 | const struct GNUNET_ATS_Information *atsi; |
@@ -379,22 +390,27 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
379 | address.address_length = plugin_address_length; | 390 | address.address_length = plugin_address_length; |
380 | address.transport_name = plugin_name; | 391 | address.transport_name = plugin_name; |
381 | 392 | ||
382 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, | 393 | ph->addr_info_cb (ph->addr_info_cb_cls, |
383 | pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count); | 394 | &address, |
395 | addr_active, | ||
396 | pi->bandwidth_out, | ||
397 | pi->bandwidth_in, | ||
398 | atsi, ats_count); | ||
384 | } | 399 | } |
385 | return GNUNET_OK; | 400 | return GNUNET_OK; |
386 | } | 401 | } |
387 | 402 | ||
403 | |||
388 | /** | 404 | /** |
389 | * We received a reservation result message. Validate and process it. | 405 | * We received a reservation result message. Validate and process it. |
390 | * | 406 | * |
391 | * @param ph our context with the callback | 407 | * @param ph our context with the callback |
392 | * @param msg the message | 408 | * @param msg the message |
393 | * @return GNUNET_OK if the message was well-formed | 409 | * @return #GNUNET_OK if the message was well-formed |
394 | */ | 410 | */ |
395 | static int | 411 | static int |
396 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | 412 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, |
397 | const struct GNUNET_MessageHeader *msg) | 413 | const struct GNUNET_MessageHeader *msg) |
398 | { | 414 | { |
399 | const struct ReservationResultMessage *rr; | 415 | const struct ReservationResultMessage *rr; |
400 | struct GNUNET_ATS_ReservationContext *rc; | 416 | struct GNUNET_ATS_ReservationContext *rc; |
@@ -434,16 +450,17 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
434 | return GNUNET_OK; | 450 | return GNUNET_OK; |
435 | } | 451 | } |
436 | 452 | ||
453 | |||
437 | /** | 454 | /** |
438 | * We received a reservation result message. Validate and process it. | 455 | * We received a reservation result message. Validate and process it. |
439 | * | 456 | * |
440 | * @param ph our context with the callback | 457 | * @param ph our context with the callback |
441 | * @param msg the message | 458 | * @param msg the message |
442 | * @return GNUNET_OK if the message was well-formed | 459 | * @return #GNUNET_OK if the message was well-formed |
443 | */ | 460 | */ |
444 | static int | 461 | static int |
445 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | 462 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, |
446 | const struct GNUNET_MessageHeader *msg) | 463 | const struct GNUNET_MessageHeader *msg) |
447 | { | 464 | { |
448 | const struct PeerInformationMessage *pi; | 465 | const struct PeerInformationMessage *pi; |
449 | struct GNUNET_ATS_AddressListHandle *alh; | 466 | struct GNUNET_ATS_AddressListHandle *alh; |
@@ -534,6 +551,7 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
534 | return GNUNET_OK; | 551 | return GNUNET_OK; |
535 | } | 552 | } |
536 | 553 | ||
554 | |||
537 | /** | 555 | /** |
538 | * Type of a function to call when we receive a message | 556 | * Type of a function to call when we receive a message |
539 | * from the service. | 557 | * from the service. |
@@ -569,17 +587,20 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
569 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, | 587 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, |
570 | GNUNET_TIME_UNIT_FOREVER_REL); | 588 | GNUNET_TIME_UNIT_FOREVER_REL); |
571 | return; | 589 | return; |
572 | reconnect: if (NULL != ph->th) | 590 | reconnect: |
591 | if (NULL != ph->th) | ||
573 | { | 592 | { |
574 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); | 593 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); |
575 | ph->th = NULL; | 594 | ph->th = NULL; |
576 | } | 595 | } |
577 | GNUNET_CLIENT_disconnect (ph->client); | 596 | GNUNET_CLIENT_disconnect (ph->client); |
578 | ph->client = NULL; | 597 | ph->client = NULL; |
598 | /* FIXME: need to signal monitor that we were disconnected! */ | ||
579 | ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 599 | ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
580 | &reconnect_task, ph); | 600 | &reconnect_task, ph); |
581 | } | 601 | } |
582 | 602 | ||
603 | |||
583 | /** | 604 | /** |
584 | * Re-establish the connection to the ATS service. | 605 | * Re-establish the connection to the ATS service. |
585 | * | 606 | * |
@@ -613,6 +634,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
613 | do_transmit (ph); | 634 | do_transmit (ph); |
614 | } | 635 | } |
615 | 636 | ||
637 | |||
616 | /** | 638 | /** |
617 | * Get handle to access performance API of the ATS subsystem. | 639 | * Get handle to access performance API of the ATS subsystem. |
618 | * | 640 | * |
@@ -624,7 +646,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
624 | */ | 646 | */ |
625 | struct GNUNET_ATS_PerformanceHandle * | 647 | struct GNUNET_ATS_PerformanceHandle * |
626 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 648 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
627 | GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls) | 649 | GNUNET_ATS_AddressInformationCallback addr_info_cb, |
650 | void *addr_info_cb_cls) | ||
628 | { | 651 | { |
629 | struct GNUNET_ATS_PerformanceHandle *ph; | 652 | struct GNUNET_ATS_PerformanceHandle *ph; |
630 | 653 | ||
@@ -637,6 +660,7 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
637 | return ph; | 660 | return ph; |
638 | } | 661 | } |
639 | 662 | ||
663 | |||
640 | /** | 664 | /** |
641 | * Client is done using the ATS performance subsystem, release resources. | 665 | * Client is done using the ATS performance subsystem, release resources. |
642 | * | 666 | * |
@@ -680,6 +704,7 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
680 | GNUNET_free(ph); | 704 | GNUNET_free(ph); |
681 | } | 705 | } |
682 | 706 | ||
707 | |||
683 | /** | 708 | /** |
684 | * Reserve inbound bandwidth from the given peer. ATS will look at | 709 | * Reserve inbound bandwidth from the given peer. ATS will look at |
685 | * the current amount of traffic we receive from the peer and ensure | 710 | * the current amount of traffic we receive from the peer and ensure |
@@ -696,8 +721,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
696 | */ | 721 | */ |
697 | struct GNUNET_ATS_ReservationContext * | 722 | struct GNUNET_ATS_ReservationContext * |
698 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | 723 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, |
699 | const struct GNUNET_PeerIdentity *peer, int32_t amount, | 724 | const struct GNUNET_PeerIdentity *peer, |
700 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) | 725 | int32_t amount, |
726 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) | ||
701 | { | 727 | { |
702 | struct GNUNET_ATS_ReservationContext *rc; | 728 | struct GNUNET_ATS_ReservationContext *rc; |
703 | struct PendingMessage *p; | 729 | struct PendingMessage *p; |
@@ -726,6 +752,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
726 | return rc; | 752 | return rc; |
727 | } | 753 | } |
728 | 754 | ||
755 | |||
729 | /** | 756 | /** |
730 | * Cancel request for reserving bandwidth. | 757 | * Cancel request for reserving bandwidth. |
731 | * | 758 | * |
@@ -737,6 +764,7 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
737 | rc->rcb = NULL; | 764 | rc->rcb = NULL; |
738 | } | 765 | } |
739 | 766 | ||
767 | |||
740 | /** | 768 | /** |
741 | * Get information about addresses known to the ATS subsystem. | 769 | * Get information about addresses known to the ATS subsystem. |
742 | * | 770 | * |
@@ -750,10 +778,11 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
750 | * @return ats performance context | 778 | * @return ats performance context |
751 | */ | 779 | */ |
752 | struct GNUNET_ATS_AddressListHandle* | 780 | struct GNUNET_ATS_AddressListHandle* |
753 | GNUNET_ATS_performance_list_addresses ( | 781 | GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle, |
754 | struct GNUNET_ATS_PerformanceHandle *handle, | 782 | const struct GNUNET_PeerIdentity *peer, |
755 | const struct GNUNET_PeerIdentity *peer, int all, | 783 | int all, |
756 | GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls) | 784 | GNUNET_ATS_AddressInformationCallback infocb, |
785 | void *infocb_cls) | ||
757 | { | 786 | { |
758 | struct GNUNET_ATS_AddressListHandle *alh; | 787 | struct GNUNET_ATS_AddressListHandle *alh; |
759 | struct PendingMessage *p; | 788 | struct PendingMessage *p; |
@@ -803,14 +832,14 @@ GNUNET_ATS_performance_list_addresses ( | |||
803 | return alh; | 832 | return alh; |
804 | } | 833 | } |
805 | 834 | ||
835 | |||
806 | /** | 836 | /** |
807 | * Cancel a pending address listing operation | 837 | * Cancel a pending address listing operation |
808 | * | 838 | * |
809 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel | 839 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel |
810 | */ | 840 | */ |
811 | void | 841 | void |
812 | GNUNET_ATS_performance_list_addresses_cancel ( | 842 | GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle) |
813 | struct GNUNET_ATS_AddressListHandle *handle) | ||
814 | { | 843 | { |
815 | GNUNET_assert(NULL != handle); | 844 | GNUNET_assert(NULL != handle); |
816 | 845 | ||
@@ -819,6 +848,7 @@ GNUNET_ATS_performance_list_addresses_cancel ( | |||
819 | GNUNET_free(handle); | 848 | GNUNET_free(handle); |
820 | } | 849 | } |
821 | 850 | ||
851 | |||
822 | /** | 852 | /** |
823 | * Convert a GNUNET_ATS_PreferenceType to a string | 853 | * Convert a GNUNET_ATS_PreferenceType to a string |
824 | * | 854 | * |
@@ -834,6 +864,7 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
834 | return NULL ; | 864 | return NULL ; |
835 | } | 865 | } |
836 | 866 | ||
867 | |||
837 | /** | 868 | /** |
838 | * Change preferences for the given peer. Preference changes are forgotten if peers | 869 | * Change preferences for the given peer. Preference changes are forgotten if peers |
839 | * disconnect. | 870 | * disconnect. |
@@ -843,9 +874,8 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
843 | * @param ... 0-terminated specification of the desired changes | 874 | * @param ... 0-terminated specification of the desired changes |
844 | */ | 875 | */ |
845 | void | 876 | void |
846 | GNUNET_ATS_performance_change_preference ( | 877 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, |
847 | struct GNUNET_ATS_PerformanceHandle *ph, | 878 | const struct GNUNET_PeerIdentity *peer, ...) |
848 | const struct GNUNET_PeerIdentity *peer, ...) | ||
849 | { | 879 | { |
850 | struct PendingMessage *p; | 880 | struct PendingMessage *p; |
851 | struct ChangePreferenceMessage *m; | 881 | struct ChangePreferenceMessage *m; |
@@ -915,6 +945,7 @@ GNUNET_ATS_performance_change_preference ( | |||
915 | do_transmit (ph); | 945 | do_transmit (ph); |
916 | } | 946 | } |
917 | 947 | ||
948 | |||
918 | /** | 949 | /** |
919 | * Send feedback to ATS on how good a the requirements for a peer and a | 950 | * Send feedback to ATS on how good a the requirements for a peer and a |
920 | * preference is satisfied by ATS | 951 | * preference is satisfied by ATS |
@@ -926,8 +957,8 @@ GNUNET_ATS_performance_change_preference ( | |||
926 | */ | 957 | */ |
927 | void | 958 | void |
928 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 959 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, |
929 | const struct GNUNET_PeerIdentity *peer, | 960 | const struct GNUNET_PeerIdentity *peer, |
930 | const struct GNUNET_TIME_Relative scope, ...) | 961 | const struct GNUNET_TIME_Relative scope, ...) |
931 | { | 962 | { |
932 | struct PendingMessage *p; | 963 | struct PendingMessage *p; |
933 | struct FeedbackPreferenceMessage *m; | 964 | struct FeedbackPreferenceMessage *m; |