2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/ats_api_performance.c
22 * @brief automatic transport selection and outbound bandwidth determination
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_ats_service.h"
31 * Message in linked list we should send to the ATS service. The
32 * actual binary message follows this struct.
40 struct PendingMessage *next;
45 struct PendingMessage *prev;
48 * Size of the message.
53 * Is this the 'ATS_START' message?
59 * Linked list of pending reservations.
61 struct GNUNET_ATS_ReservationContext
67 struct GNUNET_ATS_ReservationContext *next;
72 struct GNUNET_ATS_ReservationContext *prev;
77 struct GNUNET_PeerIdentity peer;
85 * Function to call on result.
87 GNUNET_ATS_ReservationCallback rcb;
95 * 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 * 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 * so 'info' being NULL cannot be used to check if undo is
106 * Linked list of pending reservations.
108 struct GNUNET_ATS_AddressListHandle
114 struct GNUNET_ATS_AddressListHandle *next;
119 struct GNUNET_ATS_AddressListHandle *prev;
124 struct GNUNET_ATS_PerformanceHandle *ph;
129 GNUNET_ATS_AddressInformationCallback cb;
139 struct GNUNET_PeerIdentity peer;
142 * Return all or specific peer only
147 * Return all or used address only
152 * Request multiplexing
158 * ATS Handle to obtain and/or modify performance information.
160 struct GNUNET_ATS_PerformanceHandle
166 const struct GNUNET_CONFIGURATION_Handle *cfg;
169 * Callback to invoke when an address has performance changes.
171 GNUNET_ATS_AddressInformationCallback addr_info_cb;
174 * Closure for 'addr_info_cb'.
176 void *addr_info_cb_cls;
179 * Connection to ATS service.
181 struct GNUNET_CLIENT_Connection *client;
184 * Head of list of messages for the ATS service.
186 struct PendingMessage *pending_head;
189 * Tail of list of messages for the ATS service
191 struct PendingMessage *pending_tail;
194 * Head of linked list of pending reservation requests.
196 struct GNUNET_ATS_ReservationContext *reservation_head;
199 * Tail of linked list of pending reservation requests.
201 struct GNUNET_ATS_ReservationContext *reservation_tail;
204 * Head of linked list of pending address list requests.
206 struct GNUNET_ATS_AddressListHandle *addresslist_head;
209 * Tail of linked list of pending address list requests.
211 struct GNUNET_ATS_AddressListHandle *addresslist_tail;
214 * Current request for transmission to ATS.
216 struct GNUNET_CLIENT_TransmitHandle *th;
219 * Task to trigger reconnect.
221 GNUNET_SCHEDULER_TaskIdentifier task;
224 * Monitor request multiplexing
229 * Request multiplexing
235 * Re-establish the connection to the ATS service.
237 * @param ph handle to use to re-connect.
240 reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
243 * Re-establish the connection to the ATS service.
245 * @param cls handle to use to re-connect.
246 * @param tc scheduler context
249 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 struct GNUNET_ATS_PerformanceHandle *ph = cls;
253 ph->task = GNUNET_SCHEDULER_NO_TASK;
258 * Transmit messages from the message queue to the service
259 * (if there are any, and if we are not already trying).
261 * @param ph handle to use
264 do_transmit (struct GNUNET_ATS_PerformanceHandle *ph);
267 * Type of a function to call when we receive a message
270 * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
271 * @param msg message received, NULL on timeout or fatal error
274 process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg);
277 * We can now transmit a message to ATS. Do it.
279 * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
280 * @param size number of bytes we can transmit to ATS
281 * @param buf where to copy the messages
282 * @return number of bytes copied into buf
285 transmit_message_to_ats (void *cls, size_t size, void *buf)
287 struct GNUNET_ATS_PerformanceHandle *ph = cls;
288 struct PendingMessage *p;
295 while ((NULL != (p = ph->pending_head)) && (p->size <= size))
297 memcpy (&cbuf[ret], &p[1], p->size);
300 GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p);
308 * Transmit messages from the message queue to the service
309 * (if there are any, and if we are not already trying).
311 * @param ph handle to use
314 do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
316 struct PendingMessage *p;
320 if (NULL == (p = ph->pending_head))
322 if (NULL == ph->client)
323 return; /* currently reconnecting */
324 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
325 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph);
329 * We received a peer information message. Validate and process it.
331 * @param ph our context with the callback
332 * @param msg the message
333 * @return GNUNET_OK if the message was well-formed
336 process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
337 const struct GNUNET_MessageHeader *msg)
339 const struct PeerInformationMessage *pi;
340 const struct GNUNET_ATS_Information *atsi;
341 const char *plugin_address;
342 const char *plugin_name;
343 struct GNUNET_HELLO_Address address;
344 uint16_t plugin_address_length;
345 uint16_t plugin_name_length;
349 if (ntohs (msg->size) < sizeof(struct PeerInformationMessage))
352 return GNUNET_SYSERR;
355 pi = (const struct PeerInformationMessage *) msg;
356 ats_count = ntohl (pi->ats_count);
357 plugin_address_length = ntohs (pi->address_length);
358 plugin_name_length = ntohs (pi->plugin_name_length);
359 addr_active = ntohl (pi->address_active);
360 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
361 plugin_address = (const char *) &atsi[ats_count];
362 plugin_name = &plugin_address[plugin_address_length];
363 if ((plugin_address_length + plugin_name_length
364 + ats_count * sizeof(struct GNUNET_ATS_Information)
365 + sizeof(struct PeerInformationMessage) != ntohs (msg->size))
367 > GNUNET_SERVER_MAX_MESSAGE_SIZE
368 / sizeof(struct GNUNET_ATS_Information))
369 || (plugin_name[plugin_name_length - 1] != '\0'))
372 return GNUNET_SYSERR;
375 if (NULL != ph->addr_info_cb)
377 address.peer = pi->peer;
378 address.address = plugin_address;
379 address.address_length = plugin_address_length;
380 address.transport_name = plugin_name;
382 ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active,
383 pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count);
389 * We received a reservation result message. Validate and process it.
391 * @param ph our context with the callback
392 * @param msg the message
393 * @return GNUNET_OK if the message was well-formed
396 process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
397 const struct GNUNET_MessageHeader *msg)
399 const struct ReservationResultMessage *rr;
400 struct GNUNET_ATS_ReservationContext *rc;
403 if (ntohs (msg->size) < sizeof(struct ReservationResultMessage))
406 return GNUNET_SYSERR;
408 rr = (const struct ReservationResultMessage *) msg;
409 amount = ntohl (rr->amount);
410 rc = ph->reservation_head;
411 if (0 != memcmp (&rr->peer, &rc->peer, sizeof(struct GNUNET_PeerIdentity)))
414 return GNUNET_SYSERR;
416 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc);
417 if ((amount == 0) || (rc->rcb != NULL ))
419 /* tell client if not cancelled */
420 if (rc->rcb != NULL )
421 rc->rcb (rc->rcb_cls, &rr->peer, amount,
422 GNUNET_TIME_relative_ntoh (rr->res_delay));
426 /* amount non-zero, but client cancelled, consider undo! */
427 if (GNUNET_YES != rc->undo)
430 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
433 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL );
438 * We received a reservation result message. Validate and process it.
440 * @param ph our context with the callback
441 * @param msg the message
442 * @return GNUNET_OK if the message was well-formed
445 process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
446 const struct GNUNET_MessageHeader *msg)
448 const struct PeerInformationMessage *pi;
449 struct GNUNET_ATS_AddressListHandle *alh;
450 struct GNUNET_ATS_AddressListHandle *next;
451 const struct GNUNET_ATS_Information *atsi;
452 const char *plugin_address;
453 const char *plugin_name;
454 struct GNUNET_HELLO_Address address;
455 struct GNUNET_PeerIdentity allzeros;
456 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
457 uint16_t plugin_address_length;
458 uint16_t plugin_name_length;
463 if (ntohs (msg->size) < sizeof(struct PeerInformationMessage))
466 return GNUNET_SYSERR;
468 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received %s message\n"),
469 "ATS_ADDRESSLIST_RESPONSE");
471 pi = (const struct PeerInformationMessage *) msg;
473 ats_count = ntohl (pi->ats_count);
474 active = ntohl (pi->address_active);
475 plugin_address_length = ntohs (pi->address_length);
476 plugin_name_length = ntohs (pi->plugin_name_length);
477 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
478 plugin_address = (const char *) &atsi[ats_count];
479 plugin_name = &plugin_address[plugin_address_length];
480 if ((plugin_address_length + plugin_name_length
481 + ats_count * sizeof(struct GNUNET_ATS_Information)
482 + sizeof(struct PeerInformationMessage) != ntohs (msg->size))
484 > GNUNET_SERVER_MAX_MESSAGE_SIZE
485 / sizeof(struct GNUNET_ATS_Information))
486 || (plugin_name[plugin_name_length - 1] != '\0'))
489 return GNUNET_SYSERR;
492 next = ph->addresslist_head;
493 while (NULL != (alh = next))
502 return GNUNET_SYSERR;
505 memset (&allzeros, '\0', sizeof(allzeros));
506 if ((0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros)))
507 && (0 == plugin_name_length) && (0 == plugin_address_length)
511 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received last message for %s \n"),
512 "ATS_ADDRESSLIST_RESPONSE");
513 bandwidth_zero.value__ = htonl (0);
515 alh->cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, bandwidth_zero,
516 bandwidth_zero, NULL, 0);
517 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail,
523 address.peer = pi->peer;
524 address.address = plugin_address;
525 address.address_length = plugin_address_length;
526 address.transport_name = plugin_name;
528 if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active))
531 alh->cb (ph->addr_info_cb_cls, &address, active, pi->bandwidth_out,
532 pi->bandwidth_in, atsi, ats_count);
538 * Type of a function to call when we receive a message
541 * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
542 * @param msg message received, NULL on timeout or fatal error
545 process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
547 struct GNUNET_ATS_PerformanceHandle *ph = cls;
551 switch (ntohs (msg->type))
553 case GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION:
554 if (GNUNET_OK != process_pi_message (ph, msg))
557 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
558 if (GNUNET_OK != process_rr_message (ph, msg))
561 case GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE:
562 if (GNUNET_OK != process_ar_message (ph, msg))
569 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
570 GNUNET_TIME_UNIT_FOREVER_REL);
572 reconnect: if (NULL != ph->th)
574 GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th);
577 GNUNET_CLIENT_disconnect (ph->client);
579 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
580 &reconnect_task, ph);
584 * Re-establish the connection to the ATS service.
586 * @param ph handle to use to re-connect.
589 reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
591 struct PendingMessage *p;
592 struct ClientStartMessage *init;
594 GNUNET_assert(NULL == ph->client);
595 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
596 GNUNET_assert(NULL != ph->client);
597 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
598 GNUNET_TIME_UNIT_FOREVER_REL);
599 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
601 p = GNUNET_malloc (sizeof (struct PendingMessage) +
602 sizeof (struct ClientStartMessage));
603 p->size = sizeof(struct ClientStartMessage);
604 p->is_init = GNUNET_YES;
605 init = (struct ClientStartMessage *) &p[1];
606 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
607 init->header.size = htons (sizeof(struct ClientStartMessage));
608 init->start_flag = htonl (
609 (NULL == ph->addr_info_cb) ?
610 START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC);
611 GNUNET_CONTAINER_DLL_insert(ph->pending_head, ph->pending_tail, p);
617 * Get handle to access performance API of the ATS subsystem.
619 * @param cfg configuration to use
620 * @param addr_info_cb callback called when performance characteristics for
622 * @param addr_info_cb_cls closure for infocb
623 * @return ats performance context
625 struct GNUNET_ATS_PerformanceHandle *
626 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
627 GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls)
629 struct GNUNET_ATS_PerformanceHandle *ph;
631 ph = GNUNET_new (struct GNUNET_ATS_PerformanceHandle);
633 ph->addr_info_cb = addr_info_cb;
634 ph->addr_info_cb_cls = addr_info_cb_cls;
641 * Client is done using the ATS performance subsystem, release resources.
646 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
648 struct PendingMessage *p;
649 struct GNUNET_ATS_ReservationContext *rc;
650 struct GNUNET_ATS_AddressListHandle *alh;
652 while (NULL != (p = ph->pending_head))
654 GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p);
657 while (NULL != (alh = ph->addresslist_head))
659 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail,
663 while (NULL != (rc = ph->reservation_head))
665 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc);
666 GNUNET_break(NULL == rc->rcb);
670 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
672 GNUNET_SCHEDULER_cancel (ph->task);
673 ph->task = GNUNET_SCHEDULER_NO_TASK;
675 if (NULL != ph->client)
677 GNUNET_CLIENT_disconnect (ph->client);
684 * Reserve inbound bandwidth from the given peer. ATS will look at
685 * the current amount of traffic we receive from the peer and ensure
686 * that the peer could add 'amount' of data to its stream.
688 * @param ph performance handle
689 * @param peer identifies the peer
690 * @param amount reserve N bytes for receiving, negative
691 * amounts can be used to undo a (recent) reservation;
692 * @param rcb function to call with the resulting reservation information
693 * @param rcb_cls closure for info
694 * @return NULL on error
695 * @deprecated will be replaced soon
697 struct GNUNET_ATS_ReservationContext *
698 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
699 const struct GNUNET_PeerIdentity *peer, int32_t amount,
700 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
702 struct GNUNET_ATS_ReservationContext *rc;
703 struct PendingMessage *p;
704 struct ReservationRequestMessage *m;
706 rc = GNUNET_new (struct GNUNET_ATS_ReservationContext);
710 rc->rcb_cls = rcb_cls;
711 if ((rcb != NULL )&& (amount > 0))rc->undo = GNUNET_YES;
712 GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, ph->reservation_tail,
715 p = GNUNET_malloc (sizeof (struct PendingMessage) +
716 sizeof (struct ReservationRequestMessage));
717 p->size = sizeof(struct ReservationRequestMessage);
718 p->is_init = GNUNET_NO;
719 m = (struct ReservationRequestMessage *) &p[1];
720 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
721 m->header.size = htons (sizeof(struct ReservationRequestMessage));
722 m->amount = htonl (amount);
724 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p);
730 * Cancel request for reserving bandwidth.
732 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
735 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
741 * Get information about addresses known to the ATS subsystem.
743 * @param handle the performance handle to use
744 * @param peer peer idm can be NULL for all peers
745 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
746 * get only address currently used
747 * @param infocb callback to call with the addresses,
748 * will callback with address == NULL when done
749 * @param infocb_cls closure for infocb
750 * @return ats performance context
752 struct GNUNET_ATS_AddressListHandle*
753 GNUNET_ATS_performance_list_addresses (
754 struct GNUNET_ATS_PerformanceHandle *handle,
755 const struct GNUNET_PeerIdentity *peer, int all,
756 GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls)
758 struct GNUNET_ATS_AddressListHandle *alh;
759 struct PendingMessage *p;
760 struct AddressListRequestMessage *m;
762 GNUNET_assert(NULL != handle);
766 alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle);
767 alh->id = handle->id;
770 alh->cb_cls = infocb_cls;
772 alh->all_addresses = all;
774 alh->all_peers = GNUNET_YES;
777 alh->all_peers = GNUNET_NO;
781 GNUNET_CONTAINER_DLL_insert(handle->addresslist_head,
782 handle->addresslist_tail, alh);
784 p = GNUNET_malloc (sizeof (struct PendingMessage) +
785 sizeof (struct AddressListRequestMessage));
786 p->size = sizeof(struct AddressListRequestMessage);
787 m = (struct AddressListRequestMessage *) &p[1];
788 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST);
789 m->header.size = htons (sizeof(struct AddressListRequestMessage));
790 m->all = htonl (all);
791 m->id = htonl (alh->id);
796 memset (&m->peer, '\0', sizeof(struct GNUNET_PeerIdentity));
798 GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head, handle->pending_tail,
801 do_transmit (handle);
807 * Cancel a pending address listing operation
809 * @param handle the GNUNET_ATS_AddressListHandle handle to cancel
812 GNUNET_ATS_performance_list_addresses_cancel (
813 struct GNUNET_ATS_AddressListHandle *handle)
815 GNUNET_assert(NULL != handle);
817 GNUNET_CONTAINER_DLL_remove(handle->ph->addresslist_head,
818 handle->ph->addresslist_tail, handle);
823 * Convert a GNUNET_ATS_PreferenceType to a string
825 * @param type the preference type
826 * @return a string or NULL if invalid
829 GNUNET_ATS_print_preference_type (uint32_t type)
831 char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
832 if (type < GNUNET_ATS_PreferenceCount)
838 * Change preferences for the given peer. Preference changes are forgotten if peers
841 * @param ph performance handle
842 * @param peer identifies the peer
843 * @param ... 0-terminated specification of the desired changes
846 GNUNET_ATS_performance_change_preference (
847 struct GNUNET_ATS_PerformanceHandle *ph,
848 const struct GNUNET_PeerIdentity *peer, ...)
850 struct PendingMessage *p;
851 struct ChangePreferenceMessage *m;
854 struct PreferenceInformation *pi;
856 enum GNUNET_ATS_PreferenceKind kind;
860 while (GNUNET_ATS_PREFERENCE_END != (kind =
861 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
865 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
867 (void) va_arg (ap, double);
870 case GNUNET_ATS_PREFERENCE_LATENCY:
872 (void) va_arg (ap, double);
880 msize = count * sizeof(struct PreferenceInformation)
881 + sizeof(struct ChangePreferenceMessage);
882 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
884 p->is_init = GNUNET_NO;
885 m = (struct ChangePreferenceMessage *) &p[1];
886 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
887 m->header.size = htons (msize);
888 m->num_preferences = htonl (count);
890 pi = (struct PreferenceInformation *) &m[1];
893 while (GNUNET_ATS_PREFERENCE_END != (kind =
894 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
896 pi[count].preference_kind = htonl (kind);
899 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
900 pi[count].preference_value = (float) va_arg (ap, double);
904 case GNUNET_ATS_PREFERENCE_LATENCY:
905 pi[count].preference_value = (float) va_arg (ap, double);
914 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p);
919 * Send feedback to ATS on how good a the requirements for a peer and a
920 * preference is satisfied by ATS
922 * @param ph performance handle
923 * @param scope the time interval this valid for: [now - scope .. now]
924 * @param peer identifies the peer
925 * @param ... 0-terminated specification of the desired changes
928 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
929 const struct GNUNET_PeerIdentity *peer,
930 const struct GNUNET_TIME_Relative scope, ...)
932 struct PendingMessage *p;
933 struct FeedbackPreferenceMessage *m;
936 struct PreferenceInformation *pi;
938 enum GNUNET_ATS_PreferenceKind kind;
942 while (GNUNET_ATS_PREFERENCE_END != (kind =
943 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
947 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
949 (void) va_arg (ap, double);
952 case GNUNET_ATS_PREFERENCE_LATENCY:
954 (void) va_arg (ap, double);
962 msize = count * sizeof(struct PreferenceInformation)
963 + sizeof(struct FeedbackPreferenceMessage);
964 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
966 p->is_init = GNUNET_NO;
967 m = (struct FeedbackPreferenceMessage *) &p[1];
968 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK);
969 m->header.size = htons (msize);
970 m->scope = GNUNET_TIME_relative_hton (scope);
971 m->num_feedback = htonl (count);
973 pi = (struct PreferenceInformation *) &m[1];
976 while (GNUNET_ATS_PREFERENCE_END != (kind =
977 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
979 pi[count].preference_kind = htonl (kind);
982 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
983 pi[count].preference_value = (float) va_arg (ap, double);
987 case GNUNET_ATS_PREFERENCE_LATENCY:
988 pi[count].preference_value = (float) va_arg (ap, double);
997 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p);
1001 /* end of ats_api_performance.c */