removing dead code, improving comments, simplifying iteration logic, making iteration...
[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  * Address handle
64  */
65 static struct GAS_Addresses_Handle *GSA_addresses;
66
67 /**
68  * Head of linked list of all clients to this service.
69  */
70 static struct PerformanceClient *pc_head;
71
72 /**
73  * Tail of linked list of all clients to this service.
74  */
75 static struct PerformanceClient *pc_tail;
76
77 /**
78  * Context for sending messages to performance clients.
79  */
80 static struct GNUNET_SERVER_NotificationContext *nc;
81
82
83 /**
84  * Find the performance client associated with the given handle.
85  *
86  * @param client server handle
87  * @return internal handle
88  */
89 static struct PerformanceClient *
90 find_client (struct GNUNET_SERVER_Client *client)
91 {
92   struct PerformanceClient *pc;
93
94   for (pc = pc_head; pc != NULL; pc = pc->next)
95     if (pc->client == client)
96       return pc;
97   return NULL;
98 }
99
100
101 /**
102  * Unregister a client (which may have been a performance client,
103  * but this is not assured).
104  *
105  * @param client handle of the (now dead) client
106  */
107 void
108 GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
109 {
110   struct PerformanceClient *pc;
111
112   pc = find_client (client);
113   if (NULL == pc)
114     return;
115   GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
116   GAS_addresses_preference_client_disconnect (GSA_addresses, client);
117   GNUNET_free (pc);
118 }
119
120
121 /**
122  * Transmit the given performance information to all performance
123  * clients.
124  *
125  * @param pc performance client to send to
126  * @param peer peer for which this is an address suggestion
127  * @param plugin_name 0-termintated string specifying the transport plugin
128  * @param plugin_addr binary address for the plugin to use
129  * @param plugin_addr_len number of bytes in plugin_addr
130  * @param active #GNUNET_YES if this address is actively used
131  *        to maintain a connection to a peer;
132  *        #GNUNET_NO if the address is not actively used;
133  *        #GNUNET_SYSERR if this address is no longer available for ATS
134  * @param atsi performance data for the address
135  * @param atsi_count number of performance records in @a atsi
136  * @param bandwidth_out assigned outbound bandwidth
137  * @param bandwidth_in assigned inbound bandwidth
138  */
139 void
140 GAS_performance_notify_client (struct PerformanceClient *pc,
141                                const struct GNUNET_PeerIdentity *peer,
142                                const char *plugin_name,
143                                const void *plugin_addr,
144                                size_t plugin_addr_len,
145                                int active,
146                                const struct GNUNET_ATS_Information *atsi,
147                                uint32_t atsi_count,
148                                struct GNUNET_BANDWIDTH_Value32NBO
149                                bandwidth_out,
150                                struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
151 {
152
153   struct PeerInformationMessage *msg;
154   size_t plugin_name_length = strlen (plugin_name) + 1;
155   size_t msize =
156       sizeof (struct PeerInformationMessage) +
157       atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
158       plugin_name_length;
159   char buf[msize] GNUNET_ALIGN;
160   struct GNUNET_ATS_Information *atsp;
161   char *addrp;
162
163   GNUNET_assert (NULL != pc);
164   if (NULL == find_client (pc->client))
165     return; /* Client disconnected */
166
167   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
168   GNUNET_assert (atsi_count <
169                  GNUNET_SERVER_MAX_MESSAGE_SIZE /
170                  sizeof (struct GNUNET_ATS_Information));
171   msg = (struct PeerInformationMessage *) buf;
172   msg->header.size = htons (msize);
173   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
174   msg->id = htonl (0);
175   msg->ats_count = htonl (atsi_count);
176   msg->peer = *peer;
177   msg->address_length = htons (plugin_addr_len);
178   msg->address_active = ntohl ((uint32_t) active);
179   msg->plugin_name_length = htons (plugin_name_length);
180   msg->bandwidth_out = bandwidth_out;
181   msg->bandwidth_in = bandwidth_in;
182   atsp = (struct GNUNET_ATS_Information *) &msg[1];
183   memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
184   addrp = (char *) &atsp[atsi_count];
185   memcpy (addrp, plugin_addr, plugin_addr_len);
186   strcpy (&addrp[plugin_addr_len], plugin_name);
187   GNUNET_SERVER_notification_context_unicast (nc,
188                                               pc->client,
189                                               &msg->header,
190                                               GNUNET_YES);
191 }
192
193
194 /**
195  * Transmit the given performance information to all performance
196  * clients.
197  *
198  * @param peer peer for which this is an address suggestion
199  * @param plugin_name 0-termintated string specifying the transport plugin
200  * @param plugin_addr binary address for the plugin to use
201  * @param plugin_addr_len number of bytes in @a plugin_addr
202  * @param active #GNUNET_YES if this address is actively used
203  *        to maintain a connection to a peer;
204  *        #GNUNET_NO if the address is not actively used;
205  *        #GNUNET_SYSERR if this address is no longer available for ATS
206  * @param atsi performance data for the address
207  * @param atsi_count number of performance records in @a atsi
208  * @param bandwidth_out assigned outbound bandwidth
209  * @param bandwidth_in assigned inbound bandwidth
210  */
211 void
212 GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
213                                     const char *plugin_name,
214                                     const void *plugin_addr,
215                                     size_t plugin_addr_len,
216                                     int active,
217                                     const struct GNUNET_ATS_Information *atsi,
218                                     uint32_t atsi_count,
219                                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
220                                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
221 {
222   struct PerformanceClient *pc;
223
224   for (pc = pc_head; pc != NULL; pc = pc->next)
225     if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
226     {
227         GAS_performance_notify_client (pc,
228                                        peer,
229                                        plugin_name,
230                                        plugin_addr,
231                                        plugin_addr_len,
232                                        active,
233                                        atsi, atsi_count,
234                                        bandwidth_out, bandwidth_in);
235     }
236   GNUNET_STATISTICS_update (GSA_stats,
237                             "# performance updates given to clients", 1,
238                             GNUNET_NO);
239 }
240
241
242
243 /**
244  * Iterator for called from #GAS_addresses_get_peer_info()
245  *
246  * @param cls closure with the `struct PerformanceClient *`
247  * @param id the peer id
248  * @param plugin_name plugin name
249  * @param plugin_addr address
250  * @param plugin_addr_len length of @a plugin_addr
251  * @param active is address actively used
252  * @param atsi ats performance information
253  * @param atsi_count number of ats performance elements in @a atsi
254  * @param bandwidth_out current outbound bandwidth assigned to address
255  * @param bandwidth_in current inbound bandwidth assigned to address
256  */
257 static void
258 peerinfo_it (void *cls,
259              const struct GNUNET_PeerIdentity *id,
260              const char *plugin_name,
261              const void *plugin_addr,
262              size_t plugin_addr_len,
263              int active,
264              const struct GNUNET_ATS_Information *atsi,
265              uint32_t atsi_count,
266              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
267              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
268 {
269   struct PerformanceClient *pc = cls;
270
271   GNUNET_assert (NULL != pc);
272   if (NULL == id)
273     return;
274   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
275               "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
276               GNUNET_i2s (id),
277               plugin_name,
278               (unsigned int) ntohl (bandwidth_out.value__),
279               (unsigned int) ntohl (bandwidth_in.value__));
280   GAS_performance_notify_client (pc,
281                                  id,
282                                  plugin_name,
283                                  plugin_addr,
284                                  plugin_addr_len,
285                                  active,
286                                  atsi, atsi_count,
287                                  bandwidth_out,
288                                  bandwidth_in);
289 }
290
291
292 /**
293  * Register a new performance client.
294  *
295  * @param client handle of the new client
296  * @param flag flag specifying the type of the client
297  */
298 void
299 GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
300                             enum StartFlag flag)
301 {
302   struct PerformanceClient *pc;
303
304   GNUNET_break (NULL == find_client (client));
305   pc = GNUNET_new (struct PerformanceClient);
306   pc->client = client;
307   pc->flag = flag;
308
309   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310               "Adding performance client %s PIC\n",
311               (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without");
312
313   GNUNET_SERVER_notification_context_add (nc,
314                                           client);
315   GNUNET_CONTAINER_DLL_insert (pc_head,
316                                pc_tail,
317                                pc);
318   GAS_addresses_get_peer_info (GSA_addresses,
319                                NULL,
320                                &peerinfo_it,
321                                pc);
322 }
323
324
325 /**
326  * Information we need for the callbacks to return a list of addresses
327  * back to the client.
328  */
329 struct AddressIteration
330 {
331   /**
332    * Actual handle to the client.
333    */
334   struct PerformanceClient *pc;
335
336   /**
337    * Are we sending all addresses, or only those that are active?
338    */
339   int all;
340
341   /**
342    * Which ID should be included in the response?
343    */
344   uint32_t id;
345
346 };
347
348
349 /**
350  * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the
351  * given address details to the client identified in @a ai.
352  *
353  * @param ai our address information context (identifies the client)
354  * @param id the peer id this address is for
355  * @param plugin_name name of the plugin that supports this address
356  * @param plugin_addr address
357  * @param plugin_addr_len length of @a plugin_addr
358  * @param active #GNUNET_YES if this address is actively used
359  * @param atsi ats performance information
360  * @param atsi_count number of ats performance elements in @a atsi
361  * @param bandwidth_out current outbound bandwidth assigned to address
362  * @param bandwidth_in current inbound bandwidth assigned to address
363  */
364 static void
365 transmit_req_addr (struct AddressIteration *ai,
366                    const struct GNUNET_PeerIdentity *id,
367                    const char *plugin_name,
368                    const void *plugin_addr,
369                    size_t plugin_addr_len,
370                    int active,
371                    const struct GNUNET_ATS_Information *atsi,
372                    uint32_t atsi_count,
373                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
374                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
375
376 {
377   struct GNUNET_ATS_Information *atsp;
378   struct PeerInformationMessage *msg;
379   char *addrp;
380   size_t plugin_name_length;
381   size_t msize;
382
383   if (NULL != plugin_name)
384     plugin_name_length = strlen (plugin_name) + 1;
385   else
386     plugin_name_length = 0;
387   msize = sizeof (struct PeerInformationMessage) +
388           atsi_count * sizeof (struct GNUNET_ATS_Information) +
389           plugin_addr_len + plugin_name_length;
390   char buf[msize] GNUNET_ALIGN;
391
392   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
393   GNUNET_assert (atsi_count <
394                  GNUNET_SERVER_MAX_MESSAGE_SIZE /
395                  sizeof (struct GNUNET_ATS_Information));
396   msg = (struct PeerInformationMessage *) buf;
397   msg->header.size = htons (msize);
398   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
399   msg->ats_count = htonl (atsi_count);
400   msg->id = htonl (ai->id);
401   if (NULL != id)
402     msg->peer = *id;
403   else
404     memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
405   msg->address_length = htons (plugin_addr_len);
406   msg->address_active = ntohl (active);
407   msg->plugin_name_length = htons (plugin_name_length);
408   msg->bandwidth_out = bandwidth_out;
409   msg->bandwidth_in = bandwidth_in;
410   atsp = (struct GNUNET_ATS_Information *) &msg[1];
411   memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
412   addrp = (char *) &atsp[atsi_count];
413   if (NULL != plugin_addr)
414     memcpy (addrp, plugin_addr, plugin_addr_len);
415   if (NULL != plugin_name)
416     strcpy (&addrp[plugin_addr_len], plugin_name);
417   GNUNET_SERVER_notification_context_unicast (nc,
418                                               ai->pc->client,
419                                               &msg->header,
420                                               GNUNET_NO);
421 }
422
423
424 /**
425  * Iterator for #GAS_addresses_get_peer_info(), called with peer-specific
426  * information to be passed back to the client.
427  *
428  * @param cls closure with our `struct AddressIteration *`
429  * @param id the peer id
430  * @param plugin_name plugin name
431  * @param plugin_addr address
432  * @param plugin_addr_len length of @a plugin_addr
433  * @param active is address actively used
434  * @param atsi ats performance information
435  * @param atsi_count number of ats performance elements in @a atsi
436  * @param bandwidth_out current outbound bandwidth assigned to address
437  * @param bandwidth_in current inbound bandwidth assigned to address
438  */
439 static void
440 req_addr_peerinfo_it (void *cls,
441                       const struct GNUNET_PeerIdentity *id,
442                       const char *plugin_name,
443                       const void *plugin_addr,
444                       size_t plugin_addr_len,
445                       int active,
446                       const struct GNUNET_ATS_Information *atsi,
447                       uint32_t atsi_count,
448                       struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
449                       struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
450 {
451   struct AddressIteration *ai = cls;
452
453   if ( (NULL == id) &&
454        (NULL == plugin_name) &&
455        (NULL == plugin_addr) )
456   {
457     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
458                 "Address iteration done for one peer\n");
459     return;
460   }
461   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462               "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
463               (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
464               GNUNET_i2s (id),
465               plugin_name,
466               (unsigned int) ntohl (bandwidth_out.value__),
467               (unsigned int) ntohl (bandwidth_in.value__));
468
469   /* Transmit result (either if address is active, or if
470      client wanted all addresses) */
471   if ( (GNUNET_YES == ai->all) ||
472        (GNUNET_YES == active))
473   {
474     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475                 "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
476                 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
477                 GNUNET_i2s (id),
478                 plugin_name,
479                 (unsigned int) ntohl (bandwidth_out.value__),
480                 (unsigned int) ntohl (bandwidth_in.value__));
481     transmit_req_addr (ai,
482                        id,
483                        plugin_name,
484                        plugin_addr, plugin_addr_len,
485                        active,
486                        atsi,
487                        atsi_count,
488                        bandwidth_out,
489                        bandwidth_in);
490   }
491 }
492
493
494 /**
495  * Handle 'address list request' messages from clients.
496  *
497  * @param cls unused, NULL
498  * @param client client that sent the request
499  * @param message the request message
500  */
501 void
502 GAS_handle_request_address_list (void *cls,
503                                  struct GNUNET_SERVER_Client *client,
504                                  const struct GNUNET_MessageHeader *message)
505 {
506   struct PerformanceClient *pc;
507   struct AddressIteration ai;
508   const struct AddressListRequestMessage *alrm;
509   struct GNUNET_PeerIdentity allzeros;
510   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
511
512   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
513               "Received `%s' message\n",
514               "ADDRESSLIST_REQUEST");
515   if (NULL == (pc = find_client(client)))
516   {
517     GNUNET_break (0);
518     return;
519   }
520   alrm = (const struct AddressListRequestMessage *) message;
521   ai.all = ntohl (alrm->all);
522   ai.id = ntohl (alrm->id);
523   ai.pc = pc;
524
525   memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity));
526   bandwidth_zero.value__ = htonl (0);
527   if (0 == memcmp (&alrm->peer,
528                    &allzeros,
529                    sizeof (struct GNUNET_PeerIdentity)))
530   {
531     /* Return addresses for all peers */
532     GAS_addresses_get_peer_info (GSA_addresses,
533                                  NULL,
534                                  &req_addr_peerinfo_it,
535                                  &ai);
536   }
537   else
538   {
539     /* Return addresses for a specific peer */
540     GAS_addresses_get_peer_info (GSA_addresses,
541                                  &alrm->peer,
542                                  &req_addr_peerinfo_it,
543                                  &ai);
544   }
545   transmit_req_addr (&ai,
546                      NULL, NULL, NULL,
547                      0, GNUNET_NO,
548                      NULL, 0,
549                      bandwidth_zero,
550                      bandwidth_zero);
551   GNUNET_SERVER_receive_done (client,
552                               GNUNET_OK);
553 }
554
555
556 /**
557  * Handle 'reservation request' messages from clients.
558  *
559  * @param cls unused, NULL
560  * @param client client that sent the request
561  * @param message the request message
562  */
563 void
564 GAS_handle_reservation_request (void *cls,
565                                 struct GNUNET_SERVER_Client *client,
566                                 const struct GNUNET_MessageHeader *message)
567 {
568   const struct ReservationRequestMessage *msg =
569       (const struct ReservationRequestMessage *) message;
570   struct ReservationResultMessage result;
571   int32_t amount;
572   struct GNUNET_TIME_Relative res_delay;
573
574   if (NULL == find_client (client))
575   {
576     /* missing start message! */
577     GNUNET_break (0);
578     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
579     return;
580   }
581   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582               "Received `%s' message\n",
583               "RESERVATION_REQUEST");
584   amount = (int32_t) ntohl (msg->amount);
585   res_delay = GAS_reservations_reserve (&msg->peer, amount);
586   if (res_delay.rel_value_us > 0)
587     amount = 0;
588   result.header.size = htons (sizeof (struct ReservationResultMessage));
589   result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
590   result.amount = htonl (amount);
591   result.peer = msg->peer;
592   result.res_delay = GNUNET_TIME_relative_hton (res_delay);
593   GNUNET_STATISTICS_update (GSA_stats,
594                             "# 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,
640                             "# preference change requests processed",
641                             1, GNUNET_NO);
642   pi = (const struct PreferenceInformation *) &msg[1];
643   for (i = 0; i < nump; i++)
644     GAS_addresses_preference_change (GSA_addresses,
645                                      client,
646                                      &msg->peer,
647                                      (enum GNUNET_ATS_PreferenceKind)
648                                      ntohl (pi[i].preference_kind),
649                                      pi[i].preference_value);
650   GNUNET_SERVER_receive_done (client, GNUNET_OK);
651 }
652
653
654 /**
655  * Handle 'preference feedback' messages from clients.
656  *
657  * @param cls unused, NULL
658  * @param client client that sent the request
659  * @param message the request message
660  */
661 void
662 GAS_handle_preference_feedback (void *cls,
663                               struct GNUNET_SERVER_Client *client,
664                               const struct GNUNET_MessageHeader *message)
665 {
666   const struct FeedbackPreferenceMessage *msg;
667   const struct PreferenceInformation *pi;
668   uint16_t msize;
669   uint32_t nump;
670   uint32_t i;
671
672   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
673               "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,
693                             "# preference feedbacks requests processed",
694                             1, GNUNET_NO);
695   pi = (const struct PreferenceInformation *) &msg[1];
696   for (i = 0; i < nump; i++)
697     GAS_addresses_preference_feedback (GSA_addresses,
698                                      client,
699                                      &msg->peer,
700                                      GNUNET_TIME_relative_ntoh(msg->scope),
701                                      (enum GNUNET_ATS_PreferenceKind)
702                                      ntohl (pi[i].preference_kind),
703                                      pi[i].preference_value);
704   GNUNET_SERVER_receive_done (client, GNUNET_OK);
705 }
706
707
708
709 /**
710  * Initialize performance subsystem.
711  *
712  * @param server handle to our server
713  * @param addresses the address handle to use
714  */
715 void
716 GAS_performance_init (struct GNUNET_SERVER_Handle *server,
717                       struct GAS_Addresses_Handle *addresses)
718 {
719   GSA_addresses = addresses;
720   nc = GNUNET_SERVER_notification_context_create (server, 128);
721 }
722
723
724 /**
725  * Shutdown performance subsystem.
726  */
727 void
728 GAS_performance_done ()
729 {
730   GNUNET_SERVER_notification_context_destroy (nc);
731   nc = NULL;
732 }
733
734 /* end of gnunet-service-ats_performance.c */