added simulation
[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                                const 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                                 const 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   for (pc = pc_head; pc != NULL; pc = pc->next)
230     if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
231     {
232         GAS_performance_notify_client (pc,
233                                        peer,
234                                        plugin_name, plugin_addr, plugin_addr_len,
235                                        active,
236                                        atsi, atsi_count,
237                                        bandwidth_out, bandwidth_in);
238     }
239   GNUNET_STATISTICS_update (GSA_stats,
240                             "# performance updates given to clients", 1,
241                             GNUNET_NO);
242 }
243
244
245 static void
246 peerinfo_it (void *cls,
247              const struct GNUNET_PeerIdentity *id,
248              const char *plugin_name,
249              const void *plugin_addr, size_t plugin_addr_len,
250              const int active,
251              const struct GNUNET_ATS_Information *atsi,
252              uint32_t atsi_count,
253              struct GNUNET_BANDWIDTH_Value32NBO
254              bandwidth_out,
255              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
256 {
257   struct PerformanceClient *pc = cls;
258   GNUNET_assert (NULL != pc);
259   if (NULL == id)
260     return;
261
262   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263               "Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n",
264               GNUNET_i2s (id),
265               plugin_name,
266               ntohl (bandwidth_out.value__),
267               ntohl (bandwidth_in.value__));
268   GAS_performance_notify_client(pc,
269                                 id,
270                                 plugin_name,
271                                 plugin_addr,
272                                 plugin_addr_len,
273                                 active,
274                                 atsi, atsi_count,
275                                 bandwidth_out, bandwidth_in);
276 }
277
278
279 /**
280  * Iterator for GAS_performance_add_client
281  *
282  * @param cls the client requesting information
283  * @param id result
284  */
285 static void
286 peer_it (void *cls,
287          const struct GNUNET_PeerIdentity *id)
288 {
289   struct PerformanceClient *pc = cls;
290   if (NULL != id)
291   {
292     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id));
293     GAS_addresses_get_peer_info (GSA_addresses, id, &peerinfo_it, pc);
294   }
295 }
296
297 /**
298  * Register a new performance client.
299  *
300  * @param client handle of the new client
301  * @param flag flag specifying the type of the client
302  */
303 void
304 GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
305                             enum StartFlag flag)
306 {
307   struct PerformanceClient *pc;
308   GNUNET_break (NULL == find_client (client));
309
310   pc = GNUNET_malloc (sizeof (struct PerformanceClient));
311   pc->client = client;
312   pc->flag = flag;
313
314   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding performance client %s PIC\n",
315       (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without");
316
317   GNUNET_SERVER_notification_context_add (nc, client);
318   GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
319
320   /* Send information about clients */
321   GAS_addresses_iterate_peers (GSA_addresses, &peer_it, pc);
322 }
323
324
325 static void transmit_req_addr (struct AddressIteration *ai,
326     const struct GNUNET_PeerIdentity *id,
327     const char *plugin_name,
328     const void *plugin_addr, size_t plugin_addr_len,
329     const int active,
330     const struct GNUNET_ATS_Information *atsi,
331     uint32_t atsi_count,
332     struct GNUNET_BANDWIDTH_Value32NBO
333     bandwidth_out,
334     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
335
336 {
337   struct GNUNET_ATS_Information *atsp;
338   struct PeerInformationMessage *msg;
339   char *addrp;
340   size_t plugin_name_length;
341   size_t msize;
342
343   if (NULL != plugin_name)
344     plugin_name_length = strlen (plugin_name) + 1;
345   else
346     plugin_name_length = 0;
347   msize = sizeof (struct PeerInformationMessage) +
348           atsi_count * sizeof (struct GNUNET_ATS_Information) +
349           plugin_addr_len + plugin_name_length;
350   char buf[msize] GNUNET_ALIGN;
351
352   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
353   GNUNET_assert (atsi_count <
354                  GNUNET_SERVER_MAX_MESSAGE_SIZE /
355                  sizeof (struct GNUNET_ATS_Information));
356   msg = (struct PeerInformationMessage *) buf;
357   msg->header.size = htons (msize);
358   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
359   msg->ats_count = htonl (atsi_count);
360   msg->id = htonl (ai->id);
361   if (NULL != id)
362     msg->peer = *id;
363   else
364     memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
365   msg->address_length = htons (plugin_addr_len);
366   msg->address_active = ntohl (active);
367   msg->plugin_name_length = htons (plugin_name_length);
368   msg->bandwidth_out = bandwidth_out;
369   msg->bandwidth_in = bandwidth_in;
370   atsp = (struct GNUNET_ATS_Information *) &msg[1];
371   memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
372   addrp = (char *) &atsp[atsi_count];
373   if (NULL != plugin_addr)
374     memcpy (addrp, plugin_addr, plugin_addr_len);
375   if (NULL != plugin_name)
376     strcpy (&addrp[plugin_addr_len], plugin_name);
377   GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header,
378                                               GNUNET_NO);
379 }
380
381 static void
382 req_addr_peerinfo_it (void *cls,
383              const struct GNUNET_PeerIdentity *id,
384              const char *plugin_name,
385              const void *plugin_addr, size_t plugin_addr_len,
386              const int active,
387              const struct GNUNET_ATS_Information *atsi,
388              uint32_t atsi_count,
389              struct GNUNET_BANDWIDTH_Value32NBO
390              bandwidth_out,
391              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
392 {
393   struct AddressIteration *ai = cls;
394
395   GNUNET_assert (NULL != ai);
396   GNUNET_assert (NULL != ai->pc);
397   if (NULL == find_client (ai->pc->client))
398     return; /* Client disconnected */
399
400   if ((NULL == id) && (NULL == plugin_name) && (NULL == plugin_addr))
401   {
402       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403                   "Address iteration done\n");
404       return;
405   }
406   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407               "Callback for  %s peer `%s' plugin `%s' BW out %u, BW in %u \n",
408               (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
409               GNUNET_i2s (id),
410               plugin_name,
411               (unsigned int) ntohl (bandwidth_out.value__),
412               (unsigned int) ntohl (bandwidth_in.value__));
413
414   /* Transmit result */
415   if ((GNUNET_YES == ai->all) || (GNUNET_YES == active))
416   {
417       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418                   "Sending result for  %s peer `%s' plugin `%s' BW out %u, BW in %u \n",
419                   (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
420                   GNUNET_i2s (id),
421                   plugin_name,
422                   (unsigned int) ntohl (bandwidth_out.value__),
423                   (unsigned int) ntohl (bandwidth_in.value__));
424     transmit_req_addr (cls,
425         id,
426         plugin_name,
427         plugin_addr, plugin_addr_len,
428         active,
429         atsi,
430         atsi_count,
431         bandwidth_out, bandwidth_in);
432   }
433 }
434
435
436 /**
437  * Iterator for GAS_handle_request_address_list
438  *
439  * @param cls the client requesting information
440  * @param id result
441  */
442 static void
443 req_addr_peer_it (void *cls,
444          const struct GNUNET_PeerIdentity *id)
445 {
446   struct AddressIteration *ai = cls;
447   if (NULL != id)
448   {
449     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id));
450     GAS_addresses_get_peer_info (GSA_addresses, id, &req_addr_peerinfo_it, ai);
451   }
452   else
453   {
454       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer iteration done\n");
455   }
456 }
457
458
459 /**
460  * Handle 'address list request' messages from clients.
461  *
462  * @param cls unused, NULL
463  * @param client client that sent the request
464  * @param message the request message
465  */
466 void
467 GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client,
468                                  const struct GNUNET_MessageHeader *message)
469 {
470   struct PerformanceClient *pc;
471   struct AddressIteration ai;
472   struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message;
473   struct GNUNET_PeerIdentity allzeros;
474   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
475
476   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
477               "ADDRESSLIST_REQUEST");
478
479   if (NULL == (pc = find_client(client)))
480   {
481       GNUNET_break (0);
482       return;
483   }
484
485   ai.all = ntohl (alrm->all);
486   ai.id = ntohl (alrm->id);
487   ai.pc = pc;
488
489   memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity));
490   bandwidth_zero.value__ = htonl (0);
491   if (0 == memcmp (&alrm->peer, &allzeros, sizeof (struct GNUNET_PeerIdentity)))
492   {
493       /* Return addresses for all peers */
494       GAS_addresses_iterate_peers (GSA_addresses, &req_addr_peer_it, &ai);
495       transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero);
496   }
497   else
498   {
499       /* Return addresses for a specific peer */
500       GAS_addresses_get_peer_info (GSA_addresses, &alrm->peer, &req_addr_peerinfo_it, &ai);
501       transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero);
502   }
503   GNUNET_SERVER_receive_done (client, GNUNET_OK);
504 }
505
506
507 void
508 GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
509                                                                                                                          const char *plugin_name,
510                                                                                                                          const void *plugin_addr,
511                                                                                                                          size_t plugin_addr_len,
512                                                                                                                          const int active,
513                                                                                                                          struct GNUNET_ATS_Information *ats,
514                                                                                                                          uint32_t ats_count,
515                                                                                                                          struct GNUNET_BANDWIDTH_Value32NBO
516                                                                                                                          bandwidth_out,
517                                                                                                                          struct GNUNET_BANDWIDTH_Value32NBO
518                                                                                                                          bandwidth_in)
519 {
520 /* Notify here */
521         GAS_performance_notify_all_clients (peer,
522                                                                                                                                                         plugin_name,
523                                                                                                                                                         plugin_addr, plugin_addr_len,
524                                                                                                                                                         active,
525                                                                                                                                                         ats, ats_count,
526                                                                                                                                                         bandwidth_out, bandwidth_in);
527
528 #if 0
529         struct PerformanceClient *cur;
530         struct PerformanceMonitorClient *curm;
531         struct MonitorResponseMessage *mrm;
532         size_t msglen;
533
534         msglen = sizeof (struct MonitorResponseMessage) +
535                                          ats_count * sizeof (struct GNUNET_ATS_Information);
536         mrm = GNUNET_malloc (msglen);
537
538         mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
539         mrm->header.size = htons (msglen);
540         mrm->ats_count = htonl (ats_count);
541         mrm->peer = *peer;
542         memcpy (&mrm[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));
543
544         for (cur = pc_head; NULL != cur; cur = cur->next)
545                 for (curm = cur->pm_head; NULL != curm; curm = curm->next)
546                 {
547                                 /* Notify client about update */
548                                 mrm->id = htonl (curm->id);
549                           GNUNET_SERVER_notification_context_unicast (nc,
550                                         cur->client,
551                                         (struct GNUNET_MessageHeader *) mrm,
552                                         GNUNET_YES);
553                 }
554         GNUNET_free (mrm);
555 #endif
556 }
557
558
559 /**
560  * Handle 'reservation request' messages from clients.
561  *
562  * @param cls unused, NULL
563  * @param client client that sent the request
564  * @param message the request message
565  */
566 void
567 GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
568                                 const struct GNUNET_MessageHeader *message)
569 {
570   const struct ReservationRequestMessage *msg =
571       (const struct ReservationRequestMessage *) message;
572   struct ReservationResultMessage result;
573   int32_t amount;
574   struct GNUNET_TIME_Relative res_delay;
575
576   if (NULL == find_client (client))
577   {
578     /* missing start message! */
579     GNUNET_break (0);
580     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
581     return;
582   }
583   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
584               "RESERVATION_REQUEST");
585   amount = (int32_t) ntohl (msg->amount);
586   res_delay = GAS_reservations_reserve (&msg->peer, amount);
587   if (res_delay.rel_value_us > 0)
588     amount = 0;
589   result.header.size = htons (sizeof (struct ReservationResultMessage));
590   result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
591   result.amount = htonl (amount);
592   result.peer = msg->peer;
593   result.res_delay = GNUNET_TIME_relative_hton (res_delay);
594   GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
595                             GNUNET_NO);
596   GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
597                                               GNUNET_NO);
598   GNUNET_SERVER_receive_done (client, GNUNET_OK);
599 }
600
601
602 /**
603  * Handle 'preference change' messages from clients.
604  *
605  * @param cls unused, NULL
606  * @param client client that sent the request
607  * @param message the request message
608  */
609 void
610 GAS_handle_preference_change (void *cls,
611                               struct GNUNET_SERVER_Client *client,
612                               const struct GNUNET_MessageHeader *message)
613 {
614   const struct ChangePreferenceMessage *msg;
615   const struct PreferenceInformation *pi;
616   uint16_t msize;
617   uint32_t nump;
618   uint32_t i;
619
620   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
621               "PREFERENCE_CHANGE");
622   msize = ntohs (message->size);
623   if (msize < sizeof (struct ChangePreferenceMessage))
624   {
625     GNUNET_break (0);
626     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
627     return;
628   }
629   msg = (const struct ChangePreferenceMessage *) message;
630   nump = ntohl (msg->num_preferences);
631   if (msize !=
632       sizeof (struct ChangePreferenceMessage) +
633       nump * sizeof (struct PreferenceInformation))
634   {
635     GNUNET_break (0);
636     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
637     return;
638   }
639   GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
640                             1, GNUNET_NO);
641   pi = (const struct PreferenceInformation *) &msg[1];
642   for (i = 0; i < nump; i++)
643     GAS_addresses_preference_change (GSA_addresses,
644                                      client,
645                                      &msg->peer,
646                                      (enum GNUNET_ATS_PreferenceKind)
647                                      ntohl (pi[i].preference_kind),
648                                      pi[i].preference_value);
649   GNUNET_SERVER_receive_done (client, GNUNET_OK);
650 }
651
652
653 /**
654  * Handle 'preference feedback' messages from clients.
655  *
656  * @param cls unused, NULL
657  * @param client client that sent the request
658  * @param message the request message
659  */
660 void
661 GAS_handle_preference_feedback (void *cls,
662                               struct GNUNET_SERVER_Client *client,
663                               const struct GNUNET_MessageHeader *message)
664 {
665   const struct FeedbackPreferenceMessage *msg;
666   const struct PreferenceInformation *pi;
667   uint16_t msize;
668   uint32_t nump;
669   uint32_t i;
670
671   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
672               "PREFERENCE_FEEDBACK");
673   msize = ntohs (message->size);
674   if (msize < sizeof (struct FeedbackPreferenceMessage))
675   {
676     GNUNET_break (0);
677     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
678     return;
679   }
680   msg = (const struct FeedbackPreferenceMessage *) message;
681   nump = ntohl (msg->num_feedback);
682   if (msize !=
683       sizeof (struct FeedbackPreferenceMessage) +
684       nump * sizeof (struct PreferenceInformation))
685   {
686     GNUNET_break (0);
687     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
688     return;
689   }
690   GNUNET_STATISTICS_update (GSA_stats, "# preference feedbacks requests processed",
691                             1, GNUNET_NO);
692   pi = (const struct PreferenceInformation *) &msg[1];
693   for (i = 0; i < nump; i++)
694     GAS_addresses_preference_feedback (GSA_addresses,
695                                      client,
696                                      &msg->peer,
697                                      GNUNET_TIME_relative_ntoh(msg->scope),
698                                      (enum GNUNET_ATS_PreferenceKind)
699                                      ntohl (pi[i].preference_kind),
700                                      pi[i].preference_value);
701   GNUNET_SERVER_receive_done (client, GNUNET_OK);
702 }
703
704
705
706 /**
707  * Initialize performance subsystem.
708  *
709  * @param server handle to our server
710  * @param addresses the address handle to use
711  */
712 void
713 GAS_performance_init (struct GNUNET_SERVER_Handle *server,
714                       struct GAS_Addresses_Handle *addresses)
715 {
716   GSA_addresses = addresses;
717   nc = GNUNET_SERVER_notification_context_create (server, 128);
718 }
719
720
721 /**
722  * Shutdown performance subsystem.
723  */
724 void
725 GAS_performance_done ()
726 {
727   GNUNET_SERVER_notification_context_destroy (nc);
728   nc = NULL;
729 }
730
731 /* end of gnunet-service-ats_performance.c */