2 This file is part of GNUnet.
3 Copyright (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 #define LOG(kind,...) GNUNET_log_from(kind, "ats-performance-api", __VA_ARGS__)
35 * Message in linked list we should send to the ATS service. The
36 * actual binary message follows this struct.
44 struct PendingMessage *next;
49 struct PendingMessage *prev;
52 * Size of the message.
57 * Is this the 'ATS_START' message?
64 * Linked list of pending reservations.
66 struct GNUNET_ATS_ReservationContext
72 struct GNUNET_ATS_ReservationContext *next;
77 struct GNUNET_ATS_ReservationContext *prev;
82 struct GNUNET_PeerIdentity peer;
90 * Function to call on result.
92 GNUNET_ATS_ReservationCallback rcb;
100 * Do we need to undo this reservation if it succeeded? Set to
101 * #GNUNET_YES if a reservation is cancelled. (at that point, 'info'
102 * is also set to NULL; however, info will ALSO be NULL for the
103 * reservation context that is created to undo the original request,
104 * so 'info' being NULL cannot be used to check if undo is
112 * Linked list of pending reservations.
114 struct GNUNET_ATS_AddressListHandle
120 struct GNUNET_ATS_AddressListHandle *next;
125 struct GNUNET_ATS_AddressListHandle *prev;
130 struct GNUNET_ATS_PerformanceHandle *ph;
135 GNUNET_ATS_AddressInformationCallback cb;
138 * Callback closure for @e cb
145 struct GNUNET_PeerIdentity peer;
148 * Return all or specific peer only
153 * Return all or used address only
158 * Request multiplexing
165 * ATS Handle to obtain and/or modify performance information.
167 struct GNUNET_ATS_PerformanceHandle
173 const struct GNUNET_CONFIGURATION_Handle *cfg;
176 * Callback to invoke when an address has performance changes.
178 GNUNET_ATS_AddressInformationCallback addr_info_cb;
181 * Closure for @e addr_info_cb.
183 void *addr_info_cb_cls;
186 * Connection to ATS service.
188 struct GNUNET_CLIENT_Connection *client;
191 * Head of list of messages for the ATS service.
193 struct PendingMessage *pending_head;
196 * Tail of list of messages for the ATS service
198 struct PendingMessage *pending_tail;
201 * Head of linked list of pending reservation requests.
203 struct GNUNET_ATS_ReservationContext *reservation_head;
206 * Tail of linked list of pending reservation requests.
208 struct GNUNET_ATS_ReservationContext *reservation_tail;
211 * Head of linked list of pending address list requests.
213 struct GNUNET_ATS_AddressListHandle *addresslist_head;
216 * Tail of linked list of pending address list requests.
218 struct GNUNET_ATS_AddressListHandle *addresslist_tail;
221 * Current request for transmission to ATS.
223 struct GNUNET_CLIENT_TransmitHandle *th;
226 * Task to trigger reconnect.
228 struct GNUNET_SCHEDULER_Task *task;
231 * Reconnect backoff delay.
233 struct GNUNET_TIME_Relative backoff;
236 * Monitor request multiplexing
241 * Request multiplexing
247 * Re-establish the connection to the ATS service.
249 * @param ph handle to use to re-connect.
252 reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
256 * Re-establish the connection to the ATS service.
258 * @param cls handle to use to re-connect.
259 * @param tc scheduler context
262 reconnect_task (void *cls,
263 const struct GNUNET_SCHEDULER_TaskContext *tc)
265 struct GNUNET_ATS_PerformanceHandle *ph = cls;
273 * Transmit messages from the message queue to the service
274 * (if there are any, and if we are not already trying).
276 * @param ph handle to use
279 do_transmit (struct GNUNET_ATS_PerformanceHandle *ph);
283 * Type of a function to call when we receive a message
286 * @param cls the `struct GNUNET_ATS_SchedulingHandle`
287 * @param msg message received, NULL on timeout or fatal error
290 process_ats_message (void *cls,
291 const struct GNUNET_MessageHeader *msg);
295 * We can now transmit a message to ATS. Do it.
297 * @param cls the `struct GNUNET_ATS_PerformanceHandle`
298 * @param size number of bytes we can transmit to ATS
299 * @param buf where to copy the messages
300 * @return number of bytes copied into @a buf
303 transmit_message_to_ats (void *cls,
307 struct GNUNET_ATS_PerformanceHandle *ph = cls;
308 struct PendingMessage *p;
315 while ((NULL != (p = ph->pending_head)) && (p->size <= size))
317 memcpy (&cbuf[ret], &p[1], p->size);
320 GNUNET_CONTAINER_DLL_remove (ph->pending_head,
331 * Transmit messages from the message queue to the service
332 * (if there are any, and if we are not already trying).
334 * @param ph handle to use
337 do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
339 struct PendingMessage *p;
343 if (NULL == (p = ph->pending_head))
345 if (NULL == ph->client)
346 return; /* currently reconnecting */
347 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client,
349 GNUNET_TIME_UNIT_FOREVER_REL,
351 &transmit_message_to_ats, ph);
356 * We received a peer information message. Validate and process it.
358 * @param ph our context with the callback
359 * @param msg the message
360 * @return #GNUNET_OK if the message was well-formed
363 process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
364 const struct GNUNET_MessageHeader *msg)
366 const struct PeerInformationMessage *pi;
367 const char *plugin_address;
368 const char *plugin_name;
369 struct GNUNET_HELLO_Address address;
370 uint16_t plugin_address_length;
371 uint16_t plugin_name_length;
373 struct GNUNET_ATS_Properties prop;
375 if (ntohs (msg->size) < sizeof(struct PeerInformationMessage))
378 return GNUNET_SYSERR;
380 pi = (const struct PeerInformationMessage *) msg;
381 plugin_address_length = ntohs (pi->address_length);
382 plugin_name_length = ntohs (pi->plugin_name_length);
383 addr_active = (int) ntohl (pi->address_active);
384 plugin_address = (const char *) &pi[1];
385 plugin_name = &plugin_address[plugin_address_length];
386 if ((plugin_address_length + plugin_name_length
387 + sizeof(struct PeerInformationMessage) != ntohs (msg->size))
388 || (plugin_name[plugin_name_length - 1] != '\0'))
391 return GNUNET_SYSERR;
394 if (NULL != ph->addr_info_cb)
396 GNUNET_ATS_properties_ntoh (&prop,
398 address.peer = pi->peer;
399 address.address = plugin_address;
400 address.address_length = plugin_address_length;
401 address.transport_name = plugin_name;
402 ph->addr_info_cb (ph->addr_info_cb_cls,
414 * We received a reservation result message. Validate and process it.
416 * @param ph our context with the callback
417 * @param msg the message
418 * @return #GNUNET_OK if the message was well-formed
421 process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
422 const struct GNUNET_MessageHeader *msg)
424 const struct ReservationResultMessage *rr;
425 struct GNUNET_ATS_ReservationContext *rc;
428 if (ntohs (msg->size) < sizeof(struct ReservationResultMessage))
431 return GNUNET_SYSERR;
433 rr = (const struct ReservationResultMessage *) msg;
434 amount = ntohl (rr->amount);
435 rc = ph->reservation_head;
436 if (0 != memcmp (&rr->peer, &rc->peer, sizeof(struct GNUNET_PeerIdentity)))
439 return GNUNET_SYSERR;
441 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
442 ph->reservation_tail,
444 if ( (0 == amount) ||
447 /* tell client if not cancelled */
448 if (rc->rcb != NULL )
449 rc->rcb (rc->rcb_cls,
452 GNUNET_TIME_relative_ntoh (rr->res_delay));
456 /* amount non-zero, but client cancelled, consider undo! */
457 if (GNUNET_YES != rc->undo)
460 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
463 (void) GNUNET_ATS_reserve_bandwidth (ph,
472 * We received a reservation result message. Validate and process it.
474 * @param ph our context with the callback
475 * @param msg the message
476 * @return #GNUNET_OK if the message was well-formed
479 process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
480 const struct GNUNET_MessageHeader *msg)
482 const struct PeerInformationMessage *pi;
483 struct GNUNET_ATS_AddressListHandle *alh;
484 struct GNUNET_ATS_AddressListHandle *next;
485 const char *plugin_address;
486 const char *plugin_name;
487 struct GNUNET_HELLO_Address address;
488 struct GNUNET_PeerIdentity allzeros;
489 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
490 struct GNUNET_ATS_Properties prop;
491 uint16_t plugin_address_length;
492 uint16_t plugin_name_length;
496 if (ntohs (msg->size) < sizeof(struct PeerInformationMessage))
499 return GNUNET_SYSERR;
501 pi = (const struct PeerInformationMessage *) msg;
503 active = ntohl (pi->address_active);
504 plugin_address_length = ntohs (pi->address_length);
505 plugin_name_length = ntohs (pi->plugin_name_length);
506 plugin_address = (const char *) &pi[1];
507 plugin_name = &plugin_address[plugin_address_length];
508 if ( (plugin_address_length + plugin_name_length
509 + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
510 (plugin_name[plugin_name_length - 1] != '\0') )
513 return GNUNET_SYSERR;
515 LOG (GNUNET_ERROR_TYPE_DEBUG,
516 "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n",
517 GNUNET_i2s (&pi->peer),
520 next = ph->addresslist_head;
521 while (NULL != (alh = next))
530 return GNUNET_SYSERR;
533 memset (&allzeros, '\0', sizeof (allzeros));
534 if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) &&
535 (0 == plugin_name_length) &&
536 (0 == plugin_address_length) )
539 LOG (GNUNET_ERROR_TYPE_DEBUG,
540 "Received last message for ATS_ADDRESSLIST_RESPONSE\n");
541 bandwidth_zero.value__ = htonl (0);
542 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
543 ph->addresslist_tail,
546 alh->cb (ph->addr_info_cb_cls,
556 address.peer = pi->peer;
557 address.address = plugin_address;
558 address.address_length = plugin_address_length;
559 address.transport_name = plugin_name;
560 if ( ( (GNUNET_YES == alh->all_addresses) ||
561 (GNUNET_YES == active) ) &&
564 GNUNET_ATS_properties_ntoh (&prop,
566 alh->cb (ph->addr_info_cb_cls,
578 * Type of a function to call when we receive a message
581 * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
582 * @param msg message received, NULL on timeout or fatal error
585 process_ats_message (void *cls,
586 const struct GNUNET_MessageHeader *msg)
588 struct GNUNET_ATS_PerformanceHandle *ph = cls;
592 switch (ntohs (msg->type))
594 case GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION:
595 if (GNUNET_OK != process_pi_message (ph, msg))
598 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
599 if (GNUNET_OK != process_rr_message (ph, msg))
602 case GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE:
603 if (GNUNET_OK != process_ar_message (ph, msg))
610 ph->backoff = GNUNET_TIME_UNIT_ZERO;
611 GNUNET_CLIENT_receive (ph->client,
612 &process_ats_message,
614 GNUNET_TIME_UNIT_FOREVER_REL);
618 LOG (GNUNET_ERROR_TYPE_DEBUG,
622 GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th);
625 GNUNET_CLIENT_disconnect (ph->client);
627 if (NULL != ph->addr_info_cb)
629 /* Indicate reconnect */
630 ph->addr_info_cb (ph->addr_info_cb_cls,
633 GNUNET_BANDWIDTH_value_init (0),
634 GNUNET_BANDWIDTH_value_init (0),
637 ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff);
638 ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff,
645 * Re-establish the connection to the ATS service.
647 * @param ph handle to use to re-connect.
650 reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
652 struct PendingMessage *p;
653 struct ClientStartMessage *init;
655 GNUNET_assert (NULL == ph->client);
656 ph->client = GNUNET_CLIENT_connect ("ats",
658 GNUNET_assert (NULL != ph->client);
659 GNUNET_CLIENT_receive (ph->client,
660 &process_ats_message,
662 GNUNET_TIME_UNIT_FOREVER_REL);
663 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
665 p = GNUNET_malloc (sizeof (struct PendingMessage) +
666 sizeof (struct ClientStartMessage));
667 p->size = sizeof(struct ClientStartMessage);
668 p->is_init = GNUNET_YES;
669 init = (struct ClientStartMessage *) &p[1];
670 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
671 init->header.size = htons (sizeof(struct ClientStartMessage));
672 init->start_flag = htonl ( (NULL == ph->addr_info_cb)
673 ? START_FLAG_PERFORMANCE_NO_PIC
674 : START_FLAG_PERFORMANCE_WITH_PIC);
675 GNUNET_CONTAINER_DLL_insert (ph->pending_head,
684 * Get handle to access performance API of the ATS subsystem.
686 * @param cfg configuration to use
687 * @param addr_info_cb callback called when performance characteristics for
689 * @param addr_info_cb_cls closure for @a addr_info_cb
690 * @return ats performance context
692 struct GNUNET_ATS_PerformanceHandle *
693 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
694 GNUNET_ATS_AddressInformationCallback addr_info_cb,
695 void *addr_info_cb_cls)
697 struct GNUNET_ATS_PerformanceHandle *ph;
699 ph = GNUNET_new (struct GNUNET_ATS_PerformanceHandle);
701 ph->addr_info_cb = addr_info_cb;
702 ph->addr_info_cb_cls = addr_info_cb_cls;
710 * Client is done using the ATS performance subsystem, release resources.
715 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
717 struct PendingMessage *p;
718 struct GNUNET_ATS_ReservationContext *rc;
719 struct GNUNET_ATS_AddressListHandle *alh;
721 while (NULL != (p = ph->pending_head))
723 GNUNET_CONTAINER_DLL_remove (ph->pending_head,
728 while (NULL != (alh = ph->addresslist_head))
730 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
731 ph->addresslist_tail,
735 while (NULL != (rc = ph->reservation_head))
737 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
738 ph->reservation_tail,
740 GNUNET_break (NULL == rc->rcb);
744 if (NULL != ph->task)
746 GNUNET_SCHEDULER_cancel (ph->task);
749 if (NULL != ph->client)
751 GNUNET_CLIENT_disconnect (ph->client);
759 * Reserve inbound bandwidth from the given peer. ATS will look at
760 * the current amount of traffic we receive from the peer and ensure
761 * that the peer could add 'amount' of data to its stream.
763 * @param ph performance handle
764 * @param peer identifies the peer
765 * @param amount reserve N bytes for receiving, negative
766 * amounts can be used to undo a (recent) reservation;
767 * @param rcb function to call with the resulting reservation information
768 * @param rcb_cls closure for @a rcb
769 * @return NULL on error
770 * @deprecated will be replaced soon
772 struct GNUNET_ATS_ReservationContext *
773 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
774 const struct GNUNET_PeerIdentity *peer,
776 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
778 struct GNUNET_ATS_ReservationContext *rc;
779 struct PendingMessage *p;
780 struct ReservationRequestMessage *m;
782 rc = GNUNET_new (struct GNUNET_ATS_ReservationContext);
786 rc->rcb_cls = rcb_cls;
787 if ( (NULL != rcb) &&
789 rc->undo = GNUNET_YES;
790 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head,
791 ph->reservation_tail,
794 p = GNUNET_malloc (sizeof (struct PendingMessage) +
795 sizeof (struct ReservationRequestMessage));
796 p->size = sizeof(struct ReservationRequestMessage);
797 p->is_init = GNUNET_NO;
798 m = (struct ReservationRequestMessage *) &p[1];
799 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
800 m->header.size = htons (sizeof(struct ReservationRequestMessage));
801 m->amount = htonl (amount);
803 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
812 * Cancel request for reserving bandwidth.
814 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
817 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
824 * Get information about addresses known to the ATS subsystem.
826 * @param handle the performance handle to use
827 * @param peer peer idm can be NULL for all peers
828 * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO to
829 * get only address currently used
830 * @param infocb callback to call with the addresses,
831 * will callback with address == NULL when done
832 * @param infocb_cls closure for @a infocb
833 * @return ats performance context
835 struct GNUNET_ATS_AddressListHandle*
836 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
837 const struct GNUNET_PeerIdentity *peer,
839 GNUNET_ATS_AddressInformationCallback infocb,
842 struct GNUNET_ATS_AddressListHandle *alh;
843 struct PendingMessage *p;
844 struct AddressListRequestMessage *m;
848 alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle);
849 alh->id = handle->id;
852 alh->cb_cls = infocb_cls;
854 alh->all_addresses = all;
857 alh->all_peers = GNUNET_YES;
861 alh->all_peers = GNUNET_NO;
864 GNUNET_CONTAINER_DLL_insert (handle->addresslist_head,
865 handle->addresslist_tail,
868 p = GNUNET_malloc (sizeof (struct PendingMessage) +
869 sizeof (struct AddressListRequestMessage));
870 p->size = sizeof (struct AddressListRequestMessage);
871 m = (struct AddressListRequestMessage *) &p[1];
872 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST);
873 m->header.size = htons (sizeof(struct AddressListRequestMessage));
874 m->all = htonl (all);
875 m->id = htonl (alh->id);
878 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
879 handle->pending_tail,
881 do_transmit (handle);
888 * Cancel a pending address listing operation
890 * @param handle the handle of the request to cancel
893 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle)
895 GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head,
896 handle->ph->addresslist_tail,
898 GNUNET_free (handle);
903 * Convert a `enum GNUNET_ATS_PreferenceType` to a string
905 * @param type the preference type
906 * @return a string or NULL if invalid
909 GNUNET_ATS_print_preference_type (uint32_t type)
911 const char *prefs[] = GNUNET_ATS_PreferenceTypeString;
913 if (type < GNUNET_ATS_PREFERENCE_END)
920 * Change preferences for the given peer. Preference changes are forgotten if peers
923 * @param ph performance handle
924 * @param peer identifies the peer
925 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
928 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
929 const struct GNUNET_PeerIdentity *peer, ...)
931 struct PendingMessage *p;
932 struct ChangePreferenceMessage *m;
935 struct PreferenceInformation *pi;
937 enum GNUNET_ATS_PreferenceKind kind;
941 while (GNUNET_ATS_PREFERENCE_END !=
942 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
946 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
948 (void) va_arg (ap, double);
950 case GNUNET_ATS_PREFERENCE_LATENCY:
952 (void) va_arg (ap, double);
959 msize = count * sizeof(struct PreferenceInformation)
960 + sizeof(struct ChangePreferenceMessage);
961 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
963 p->is_init = GNUNET_NO;
964 m = (struct ChangePreferenceMessage *) &p[1];
965 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
966 m->header.size = htons (msize);
967 m->num_preferences = htonl (count);
969 pi = (struct PreferenceInformation *) &m[1];
972 while (GNUNET_ATS_PREFERENCE_END != (kind =
973 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
975 pi[count].preference_kind = htonl (kind);
978 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
979 pi[count].preference_value = (float) va_arg (ap, double);
983 case GNUNET_ATS_PREFERENCE_LATENCY:
984 pi[count].preference_value = (float) va_arg (ap, double);
993 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p);
999 * Send feedback to ATS on how good a the requirements for a peer and a
1000 * preference is satisfied by ATS
1002 * @param ph performance handle
1003 * @param scope the time interval this valid for: [now - scope .. now]
1004 * @param peer identifies the peer
1005 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
1008 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
1009 const struct GNUNET_PeerIdentity *peer,
1010 const struct GNUNET_TIME_Relative scope, ...)
1012 struct PendingMessage *p;
1013 struct FeedbackPreferenceMessage *m;
1016 struct PreferenceInformation *pi;
1018 enum GNUNET_ATS_PreferenceKind kind;
1021 va_start(ap, scope);
1022 while (GNUNET_ATS_PREFERENCE_END !=
1023 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
1027 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
1029 (void) va_arg (ap, double);
1031 case GNUNET_ATS_PREFERENCE_LATENCY:
1033 (void) va_arg (ap, double);
1040 msize = count * sizeof(struct PreferenceInformation)
1041 + sizeof(struct FeedbackPreferenceMessage);
1042 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1044 p->is_init = GNUNET_NO;
1045 m = (struct FeedbackPreferenceMessage *) &p[1];
1046 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK);
1047 m->header.size = htons (msize);
1048 m->scope = GNUNET_TIME_relative_hton (scope);
1049 m->num_feedback = htonl (count);
1051 pi = (struct PreferenceInformation *) &m[1];
1053 va_start(ap, scope);
1054 while (GNUNET_ATS_PREFERENCE_END != (kind =
1055 va_arg (ap, enum GNUNET_ATS_PreferenceKind) ))
1057 pi[count].preference_kind = htonl (kind);
1060 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
1061 pi[count].preference_value = (float) va_arg (ap, double);
1065 case GNUNET_ATS_PREFERENCE_LATENCY:
1066 pi[count].preference_value = (float) va_arg (ap, double);
1075 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
1081 /* end of ats_api_performance.c */