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