use -Wl on -no-undefined as it is a linker option:
[oweals/gnunet.git] / src / ats / gnunet-service-ats_performance.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file ats/gnunet-service-ats_performance.c
23  * @brief ats service, interaction with 'performance' API
24  * @author Matthias Wachs
25  * @author Christian Grothoff
26  */
27 #include "platform.h"
28 #include "gnunet-service-ats.h"
29 #include "gnunet-service-ats_addresses.h"
30 #include "gnunet-service-ats_performance.h"
31 #include "gnunet-service-ats_reservations.h"
32 #include "ats.h"
33
34 /**
35  * We keep clients that are interested in performance in a linked list.
36  */
37 struct PerformanceClient
38 {
39   /**
40    * Next in doubly-linked list.
41    */
42   struct PerformanceClient *next;
43
44   /**
45    * Previous in doubly-linked list.
46    */
47   struct PerformanceClient *prev;
48
49   /**
50    * Actual handle to the client.
51    */
52   struct GNUNET_SERVER_Client *client;
53
54   /**
55    * Options for the client.
56    */
57   enum StartFlag flag;
58
59 };
60
61
62 /**
63  * We keep clients that are interested in performance in a linked list.
64  */
65 struct AddressIteration
66 {
67   /**
68    * Actual handle to the client.
69    */
70   struct PerformanceClient *pc;
71
72   int all;
73
74   uint32_t id;
75
76   unsigned int msg_type;
77 };
78
79 /**
80  * Address handle
81  */
82 static struct GAS_Addresses_Handle *GSA_addresses;
83
84 /**
85  * Head of linked list of all clients to this service.
86  */
87 static struct PerformanceClient *pc_head;
88
89 /**
90  * Tail of linked list of all clients to this service.
91  */
92 static struct PerformanceClient *pc_tail;
93
94 /**
95  * Context for sending messages to performance clients.
96  */
97 static struct GNUNET_SERVER_NotificationContext *nc;
98
99
100 /**
101  * Find the performance client associated with the given handle.
102  *
103  * @param client server handle
104  * @return internal handle
105  */
106 static struct PerformanceClient *
107 find_client (struct GNUNET_SERVER_Client *client)
108 {
109   struct PerformanceClient *pc;
110
111   for (pc = pc_head; pc != NULL; pc = pc->next)
112     if (pc->client == client)
113       return pc;
114   return NULL;
115 }
116
117 /**
118  * Unregister a client (which may have been a performance client,
119  * but this is not assured).
120  *
121  * @param client handle of the (now dead) client
122  */
123 void
124 GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
125 {
126   struct PerformanceClient *pc;
127
128   pc = find_client (client);
129   if (NULL == pc)
130     return;
131   GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
132   GAS_addresses_preference_client_disconnect (GSA_addresses, client);
133   GNUNET_free (pc);
134 }
135
136 /**
137  * Transmit the given performance information to all performance
138  * clients.
139  *
140  * @param pc performance client to send to
141  * @param peer peer for which this is an address suggestion
142  * @param plugin_name 0-termintated string specifying the transport plugin
143  * @param plugin_addr binary address for the plugin to use
144  * @param plugin_addr_len number of bytes in plugin_addr
145  * @param active is this address active
146  * @param atsi performance data for the address
147  * @param atsi_count number of performance records in 'ats'
148  * @param bandwidth_out assigned outbound bandwidth
149  * @param bandwidth_in assigned inbound bandwidth
150  */
151 void
152 GAS_performance_notify_client (struct PerformanceClient *pc,
153                                const struct GNUNET_PeerIdentity *peer,
154                                const char *plugin_name,
155                                const void *plugin_addr, size_t plugin_addr_len,
156                                int active,
157                                const struct GNUNET_ATS_Information *atsi,
158                                uint32_t atsi_count,
159                                struct GNUNET_BANDWIDTH_Value32NBO
160                                bandwidth_out,
161                                struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
162 {
163
164   struct PeerInformationMessage *msg;
165   size_t plugin_name_length = strlen (plugin_name) + 1;
166   size_t msize =
167       sizeof (struct PeerInformationMessage) +
168       atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
169       plugin_name_length;
170   char buf[msize] GNUNET_ALIGN;
171   struct GNUNET_ATS_Information *atsp;
172   char *addrp;
173
174   GNUNET_assert (NULL != pc);
175   if (NULL == find_client (pc->client))
176     return; /* Client disconnected */
177
178   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
179   GNUNET_assert (atsi_count <
180                  GNUNET_SERVER_MAX_MESSAGE_SIZE /
181                  sizeof (struct GNUNET_ATS_Information));
182   msg = (struct PeerInformationMessage *) buf;
183   msg->header.size = htons (msize);
184   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
185   msg->id = htonl (0);
186   msg->ats_count = htonl (atsi_count);
187   msg->peer = *peer;
188   msg->address_length = htons (plugin_addr_len);
189   msg->address_active = ntohl (active);
190   msg->plugin_name_length = htons (plugin_name_length);
191   msg->bandwidth_out = bandwidth_out;
192   msg->bandwidth_in = bandwidth_in;
193   atsp = (struct GNUNET_ATS_Information *) &msg[1];
194   memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
195   addrp = (char *) &atsp[atsi_count];
196   memcpy (addrp, plugin_addr, plugin_addr_len);
197   strcpy (&addrp[plugin_addr_len], plugin_name);
198   GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header,
199                                               GNUNET_YES);
200 }
201
202
203 /**
204  * Transmit the given performance information to all performance
205  * clients.
206  *
207  * @param peer peer for which this is an address suggestion
208  * @param plugin_name 0-termintated string specifying the transport plugin
209  * @param plugin_addr binary address for the plugin to use
210  * @param plugin_addr_len number of bytes in plugin_addr
211  * @param active is this address active
212  * @param atsi performance data for the address
213  * @param atsi_count number of performance records in 'ats'
214  * @param bandwidth_out assigned outbound bandwidth
215  * @param bandwidth_in assigned inbound bandwidth
216  */
217 void
218 GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
219                                     const char *plugin_name,
220                                     const void *plugin_addr, size_t plugin_addr_len,
221                                     int active,
222                                 const struct GNUNET_ATS_Information *atsi,
223                                 uint32_t atsi_count,
224                                 struct GNUNET_BANDWIDTH_Value32NBO
225                                 bandwidth_out,
226                                 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
227 {
228   struct PerformanceClient *pc;
229
230   for (pc = pc_head; pc != NULL; pc = pc->next)
231     if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
232     {
233         GAS_performance_notify_client (pc,
234                                        peer,
235                                        plugin_name, plugin_addr, plugin_addr_len,
236                                        active,
237                                        atsi, atsi_count,
238                                        bandwidth_out, bandwidth_in);
239     }
240   GNUNET_STATISTICS_update (GSA_stats,
241                             "# performance updates given to clients", 1,
242                             GNUNET_NO);
243 }
244
245
246 static void
247 peerinfo_it (void *cls,
248              const struct GNUNET_PeerIdentity *id,
249              const char *plugin_name,
250              const void *plugin_addr, size_t plugin_addr_len,
251              const int active,
252              const struct GNUNET_ATS_Information *atsi,
253              uint32_t atsi_count,
254              struct GNUNET_BANDWIDTH_Value32NBO
255              bandwidth_out,
256              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
257 {
258   struct PerformanceClient *pc = cls;
259   GNUNET_assert (NULL != pc);
260   if (NULL == id)
261     return;
262
263   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264               "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
265               GNUNET_i2s (id),
266               plugin_name,
267               (unsigned int) ntohl (bandwidth_out.value__),
268               (unsigned int) ntohl (bandwidth_in.value__));
269   GAS_performance_notify_client(pc,
270                                 id,
271                                 plugin_name,
272                                 plugin_addr,
273                                 plugin_addr_len,
274                                 active,
275                                 atsi, atsi_count,
276                                 bandwidth_out, bandwidth_in);
277 }
278
279
280 /**
281  * Iterator for GAS_performance_add_client
282  *
283  * @param cls the client requesting information
284  * @param id result
285  */
286 static void
287 peer_it (void *cls,
288          const struct GNUNET_PeerIdentity *id)
289 {
290   struct PerformanceClient *pc = cls;
291   if (NULL != id)
292   {
293     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id));
294     GAS_addresses_get_peer_info (GSA_addresses, id, &peerinfo_it, pc);
295   }
296 }
297
298 /**
299  * Register a new performance client.
300  *
301  * @param client handle of the new client
302  * @param flag flag specifying the type of the client
303  */
304 void
305 GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
306                             enum StartFlag flag)
307 {
308   struct PerformanceClient *pc;
309   GNUNET_break (NULL == find_client (client));
310
311   pc = GNUNET_new (struct PerformanceClient);
312   pc->client = client;
313   pc->flag = flag;
314
315   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding performance client %s PIC\n",
316       (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without");
317
318   GNUNET_SERVER_notification_context_add (nc, client);
319   GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
320
321   /* Send information about clients */
322   GAS_addresses_iterate_peers (GSA_addresses, &peer_it, pc);
323 }
324
325
326 static void transmit_req_addr (struct AddressIteration *ai,
327     const struct GNUNET_PeerIdentity *id,
328     const char *plugin_name,
329     const void *plugin_addr, size_t plugin_addr_len,
330     const int active,
331     const struct GNUNET_ATS_Information *atsi,
332     uint32_t atsi_count,
333     struct GNUNET_BANDWIDTH_Value32NBO
334     bandwidth_out,
335     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
336
337 {
338   struct GNUNET_ATS_Information *atsp;
339   struct PeerInformationMessage *msg;
340   char *addrp;
341   size_t plugin_name_length;
342   size_t msize;
343
344   if (NULL != plugin_name)
345     plugin_name_length = strlen (plugin_name) + 1;
346   else
347     plugin_name_length = 0;
348   msize = sizeof (struct PeerInformationMessage) +
349           atsi_count * sizeof (struct GNUNET_ATS_Information) +
350           plugin_addr_len + plugin_name_length;
351   char buf[msize] GNUNET_ALIGN;
352
353   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
354   GNUNET_assert (atsi_count <
355                  GNUNET_SERVER_MAX_MESSAGE_SIZE /
356                  sizeof (struct GNUNET_ATS_Information));
357   msg = (struct PeerInformationMessage *) buf;
358   msg->header.size = htons (msize);
359   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
360   msg->ats_count = htonl (atsi_count);
361   msg->id = htonl (ai->id);
362   if (NULL != id)
363     msg->peer = *id;
364   else
365     memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
366   msg->address_length = htons (plugin_addr_len);
367   msg->address_active = ntohl (active);
368   msg->plugin_name_length = htons (plugin_name_length);
369   msg->bandwidth_out = bandwidth_out;
370   msg->bandwidth_in = bandwidth_in;
371   atsp = (struct GNUNET_ATS_Information *) &msg[1];
372   memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
373   addrp = (char *) &atsp[atsi_count];
374   if (NULL != plugin_addr)
375     memcpy (addrp, plugin_addr, plugin_addr_len);
376   if (NULL != plugin_name)
377     strcpy (&addrp[plugin_addr_len], plugin_name);
378   GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header,
379                                               GNUNET_NO);
380 }
381
382 static void
383 req_addr_peerinfo_it (void *cls,
384              const struct GNUNET_PeerIdentity *id,
385              const char *plugin_name,
386              const void *plugin_addr, size_t plugin_addr_len,
387              const int active,
388              const struct GNUNET_ATS_Information *atsi,
389              uint32_t atsi_count,
390              struct GNUNET_BANDWIDTH_Value32NBO
391              bandwidth_out,
392              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
393 {
394   struct AddressIteration *ai = cls;
395
396   GNUNET_assert (NULL != ai);
397   GNUNET_assert (NULL != ai->pc);
398   if (NULL == find_client (ai->pc->client))
399     return; /* Client disconnected */
400
401   if ((NULL == id) && (NULL == plugin_name) && (NULL == plugin_addr))
402   {
403       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404                   "Address iteration done\n");
405       return;
406   }
407   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408               "Callback for  %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
409               (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
410               GNUNET_i2s (id),
411               plugin_name,
412               (unsigned int) ntohl (bandwidth_out.value__),
413               (unsigned int) ntohl (bandwidth_in.value__));
414
415   /* Transmit result */
416   if ((GNUNET_YES == ai->all) || (GNUNET_YES == active))
417   {
418       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419                   "Sending result for  %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
420                   (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
421                   GNUNET_i2s (id),
422                   plugin_name,
423                   (unsigned int) ntohl (bandwidth_out.value__),
424                   (unsigned int) ntohl (bandwidth_in.value__));
425     transmit_req_addr (cls,
426                        id,
427                        plugin_name,
428                        plugin_addr, plugin_addr_len,
429                        active,
430                        atsi,
431                        atsi_count,
432                        bandwidth_out, bandwidth_in);
433   }
434 }
435
436
437 /**
438  * Iterator for GAS_handle_request_address_list
439  *
440  * @param cls the client requesting information
441  * @param id result
442  */
443 static void
444 req_addr_peer_it (void *cls,
445          const struct GNUNET_PeerIdentity *id)
446 {
447   struct AddressIteration *ai = cls;
448   if (NULL != id)
449   {
450     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id));
451     GAS_addresses_get_peer_info (GSA_addresses, id, &req_addr_peerinfo_it, ai);
452   }
453   else
454   {
455       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer iteration done\n");
456   }
457 }
458
459
460 /**
461  * Handle 'address list request' messages from clients.
462  *
463  * @param cls unused, NULL
464  * @param client client that sent the request
465  * @param message the request message
466  */
467 void
468 GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client,
469                                  const struct GNUNET_MessageHeader *message)
470 {
471   struct PerformanceClient *pc;
472   struct AddressIteration ai;
473   struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message;
474   struct GNUNET_PeerIdentity allzeros;
475   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
476
477   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
478               "ADDRESSLIST_REQUEST");
479
480   if (NULL == (pc = find_client(client)))
481   {
482       GNUNET_break (0);
483       return;
484   }
485
486   ai.all = ntohl (alrm->all);
487   ai.id = ntohl (alrm->id);
488   ai.pc = pc;
489
490   memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity));
491   bandwidth_zero.value__ = htonl (0);
492   if (0 == memcmp (&alrm->peer, &allzeros, sizeof (struct GNUNET_PeerIdentity)))
493   {
494       /* Return addresses for all peers */
495       GAS_addresses_iterate_peers (GSA_addresses, &req_addr_peer_it, &ai);
496       transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero);
497   }
498   else
499   {
500       /* Return addresses for a specific peer */
501       GAS_addresses_get_peer_info (GSA_addresses, &alrm->peer, &req_addr_peerinfo_it, &ai);
502       transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero);
503   }
504   GNUNET_SERVER_receive_done (client, GNUNET_OK);
505 }
506
507
508 void
509 GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
510     const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len,
511     const int active, struct GNUNET_ATS_Information *ats, uint32_t ats_count,
512     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
513     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
514 {
515   /* Notify here */
516   GAS_performance_notify_all_clients (peer, plugin_name, plugin_addr,
517       plugin_addr_len, active, ats, ats_count, bandwidth_out, bandwidth_in);
518
519 #if 0
520   struct PerformanceClient *cur;
521   struct PerformanceMonitorClient *curm;
522   struct MonitorResponseMessage *mrm;
523   size_t msglen;
524
525   msglen = sizeof (struct MonitorResponseMessage) +
526   ats_count * sizeof (struct GNUNET_ATS_Information);
527   mrm = GNUNET_malloc (msglen);
528
529   mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
530   mrm->header.size = htons (msglen);
531   mrm->ats_count = htonl (ats_count);
532   mrm->peer = *peer;
533   memcpy (&mrm[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));
534
535   for (cur = pc_head; NULL != cur; cur = cur->next)
536   for (curm = cur->pm_head; NULL != curm; curm = curm->next)
537   {
538     /* Notify client about update */
539     mrm->id = htonl (curm->id);
540     GNUNET_SERVER_notification_context_unicast (nc,
541         cur->client,
542         (struct GNUNET_MessageHeader *) mrm,
543         GNUNET_YES);
544   }
545   GNUNET_free (mrm);
546 #endif
547 }
548
549
550 /**
551  * Handle 'reservation request' messages from clients.
552  *
553  * @param cls unused, NULL
554  * @param client client that sent the request
555  * @param message the request message
556  */
557 void
558 GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
559                                 const struct GNUNET_MessageHeader *message)
560 {
561   const struct ReservationRequestMessage *msg =
562       (const struct ReservationRequestMessage *) message;
563   struct ReservationResultMessage result;
564   int32_t amount;
565   struct GNUNET_TIME_Relative res_delay;
566
567   if (NULL == find_client (client))
568   {
569     /* missing start message! */
570     GNUNET_break (0);
571     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
572     return;
573   }
574   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
575               "RESERVATION_REQUEST");
576   amount = (int32_t) ntohl (msg->amount);
577   res_delay = GAS_reservations_reserve (&msg->peer, amount);
578   if (res_delay.rel_value_us > 0)
579     amount = 0;
580   result.header.size = htons (sizeof (struct ReservationResultMessage));
581   result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
582   result.amount = htonl (amount);
583   result.peer = msg->peer;
584   result.res_delay = GNUNET_TIME_relative_hton (res_delay);
585   GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
586                             GNUNET_NO);
587   GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
588                                               GNUNET_NO);
589   GNUNET_SERVER_receive_done (client, GNUNET_OK);
590 }
591
592
593 /**
594  * Handle 'preference change' messages from clients.
595  *
596  * @param cls unused, NULL
597  * @param client client that sent the request
598  * @param message the request message
599  */
600 void
601 GAS_handle_preference_change (void *cls,
602                               struct GNUNET_SERVER_Client *client,
603                               const struct GNUNET_MessageHeader *message)
604 {
605   const struct ChangePreferenceMessage *msg;
606   const struct PreferenceInformation *pi;
607   uint16_t msize;
608   uint32_t nump;
609   uint32_t i;
610
611   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
612               "PREFERENCE_CHANGE");
613   msize = ntohs (message->size);
614   if (msize < sizeof (struct ChangePreferenceMessage))
615   {
616     GNUNET_break (0);
617     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
618     return;
619   }
620   msg = (const struct ChangePreferenceMessage *) message;
621   nump = ntohl (msg->num_preferences);
622   if (msize !=
623       sizeof (struct ChangePreferenceMessage) +
624       nump * sizeof (struct PreferenceInformation))
625   {
626     GNUNET_break (0);
627     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
628     return;
629   }
630   GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
631                             1, GNUNET_NO);
632   pi = (const struct PreferenceInformation *) &msg[1];
633   for (i = 0; i < nump; i++)
634     GAS_addresses_preference_change (GSA_addresses,
635                                      client,
636                                      &msg->peer,
637                                      (enum GNUNET_ATS_PreferenceKind)
638                                      ntohl (pi[i].preference_kind),
639                                      pi[i].preference_value);
640   GNUNET_SERVER_receive_done (client, GNUNET_OK);
641 }
642
643
644 /**
645  * Handle 'preference feedback' messages from clients.
646  *
647  * @param cls unused, NULL
648  * @param client client that sent the request
649  * @param message the request message
650  */
651 void
652 GAS_handle_preference_feedback (void *cls,
653                               struct GNUNET_SERVER_Client *client,
654                               const struct GNUNET_MessageHeader *message)
655 {
656   const struct FeedbackPreferenceMessage *msg;
657   const struct PreferenceInformation *pi;
658   uint16_t msize;
659   uint32_t nump;
660   uint32_t i;
661
662   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
663               "PREFERENCE_FEEDBACK");
664   msize = ntohs (message->size);
665   if (msize < sizeof (struct FeedbackPreferenceMessage))
666   {
667     GNUNET_break (0);
668     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
669     return;
670   }
671   msg = (const struct FeedbackPreferenceMessage *) message;
672   nump = ntohl (msg->num_feedback);
673   if (msize !=
674       sizeof (struct FeedbackPreferenceMessage) +
675       nump * sizeof (struct PreferenceInformation))
676   {
677     GNUNET_break (0);
678     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
679     return;
680   }
681   GNUNET_STATISTICS_update (GSA_stats, "# preference feedbacks requests processed",
682                             1, GNUNET_NO);
683   pi = (const struct PreferenceInformation *) &msg[1];
684   for (i = 0; i < nump; i++)
685     GAS_addresses_preference_feedback (GSA_addresses,
686                                      client,
687                                      &msg->peer,
688                                      GNUNET_TIME_relative_ntoh(msg->scope),
689                                      (enum GNUNET_ATS_PreferenceKind)
690                                      ntohl (pi[i].preference_kind),
691                                      pi[i].preference_value);
692   GNUNET_SERVER_receive_done (client, GNUNET_OK);
693 }
694
695
696
697 /**
698  * Initialize performance subsystem.
699  *
700  * @param server handle to our server
701  * @param addresses the address handle to use
702  */
703 void
704 GAS_performance_init (struct GNUNET_SERVER_Handle *server,
705                       struct GAS_Addresses_Handle *addresses)
706 {
707   GSA_addresses = addresses;
708   nc = GNUNET_SERVER_notification_context_create (server, 128);
709 }
710
711
712 /**
713  * Shutdown performance subsystem.
714  */
715 void
716 GAS_performance_done ()
717 {
718   GNUNET_SERVER_notification_context_destroy (nc);
719   nc = NULL;
720 }
721
722 /* end of gnunet-service-ats_performance.c */