9400b1f304ae0668ab0f579e94c9b87c929007e6
[oweals/gnunet.git] / src / ats / ats_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010,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  * @file ats/ats_api.c
22  * @brief automatic transport selection API
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  *
26  * TODO:
27  * - write test case
28  * - extend API to get performance data
29  * - implement simplistic strategy based on say 'lowest latency' or strict ordering
30  * - extend API to get peer preferences, implement proportional bandwidth assignment
31  * - re-implement API against a real ATS service (!)
32  */
33 #include "platform.h"
34 #include "gnunet_ats_service.h"
35
36 // NOTE: this implementation is simply supposed
37 // to implement a simplistic strategy in-process;
38 // in the future, we plan to replace it with a real
39 // service implementation
40
41 /**
42  * Allocation record for a peer's address.
43  */
44 struct AllocationRecord
45 {
46
47   /**
48    * Performance information associated with this address (array).
49    */
50   struct GNUNET_TRANSPORT_ATS_Information *ats;
51
52   /**
53    * Name of the plugin
54    */
55   char *plugin_name;
56
57   /**
58    * Address this record represents, allocated at the end of this struct.
59    */
60   const void *plugin_addr;
61
62   /**
63    * Session associated with this record.
64    */
65   struct Session *session;
66
67   /**
68    * Number of bytes in plugin_addr.
69    */
70   size_t plugin_addr_len;            
71
72   /**
73    * Number of entries in 'ats'.
74    */
75   uint32_t ats_count;
76
77   /**
78    * Bandwidth assigned to this address right now, 0 for none.
79    */
80   struct GNUNET_BANDWIDTH_Value32NBO bandwidth;
81
82   /**
83    * Set to GNUNET_YES if this is the connected address of a connected peer.
84    */
85   int connected;
86
87 };
88
89
90 /**
91  * Opaque handle to obtain address suggestions.
92  */
93 struct GNUNET_ATS_SuggestionContext
94 {
95
96   /**
97    * Function to call with our final suggestion.
98    */
99   GNUNET_ATS_AddressSuggestionCallback cb;
100
101   /**
102    * Closure for 'cb'.
103    */
104   void *cb_cls;
105
106   /**
107    * Global ATS handle.
108    */ 
109   struct GNUNET_ATS_Handle *atc;
110
111   /**
112    * Which peer are we monitoring?
113    */   
114   struct GNUNET_PeerIdentity target;
115
116 };
117
118
119 /**
120  * Handle to the ATS subsystem.
121  */
122 struct GNUNET_ATS_Handle
123 {
124   /**
125    * Configuration.
126    */
127   const struct GNUNET_CONFIGURATION_Handle *cfg;
128
129   /**
130    * Function to call when the allocation changes.
131    */
132   GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb;
133
134   /**
135    * Closure for 'alloc_cb'.
136    */
137   void *alloc_cb_cls;
138
139   /**
140    * Information about all connected peers.  Maps peer identities
141    * to one or more 'struct AllocationRecord' values.
142    */
143   struct GNUNET_CONTAINER_MultiHashMap *peers;
144
145   /**
146    * Map of PeerIdentities to 'struct GNUNET_ATS_SuggestionContext's.
147    */
148   struct GNUNET_CONTAINER_MultiHashMap *notify_map;
149
150
151   /**
152    * Task scheduled to update our bandwidth assignment.
153    */
154   GNUNET_SCHEDULER_TaskIdentifier ba_task;
155
156   /**
157    * Total bandwidth per configuration.
158    */
159   unsigned long long total_bps;
160 };
161
162
163 /**
164  * Count number of connected records.
165  *
166  * @param cls pointer to counter
167  * @param key identity of the peer associated with the records
168  * @param value a 'struct AllocationRecord' 
169  * @return GNUNET_YES (continue iteration)
170  */
171 static int
172 count_connections (void *cls,
173                    const GNUNET_HashCode *key,
174                    void *value)
175 {
176   unsigned int *ac = cls;
177   struct AllocationRecord *ar = value;
178   
179   if (GNUNET_YES == ar->connected)
180     (*ac)++;
181   return GNUNET_YES;
182 }
183
184
185 /**
186  * Closure for 'set_bw_connections'.
187  */
188 struct SetBandwidthContext
189 {
190   /**
191    * ATS handle.
192    */
193   struct GNUNET_ATS_Handle *atc;
194
195   /**
196    * Bandwidth to assign.
197    */
198   struct GNUNET_BANDWIDTH_Value32NBO bw;
199 };
200
201
202 /**
203  * Set bandwidth based on record.
204  *
205  * @param cls 'struct SetBandwidthContext'
206  * @param key identity of the peer associated with the records
207  * @param value a 'struct AllocationRecord' 
208  * @return GNUNET_YES (continue iteration)
209  */
210 static int
211 set_bw_connections (void *cls,
212                     const GNUNET_HashCode *key,
213                     void *value)
214 {
215   struct SetBandwidthContext *sbc = cls;
216   struct AllocationRecord *ar = value;
217   
218   if (GNUNET_YES == ar->connected)
219     {
220       ar->bandwidth = sbc->bw;
221       sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
222                           (const struct GNUNET_PeerIdentity*) key,
223                           ar->plugin_name,
224                           ar->session,
225                           ar->plugin_addr,
226                           ar->plugin_addr_len,
227                           ar->bandwidth);
228     }
229   else if (ntohl(ar->bandwidth.value__) > 0)
230     {
231       ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
232       sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
233                           (const struct GNUNET_PeerIdentity*) key,
234                           ar->plugin_name,
235                           ar->session,
236                           ar->plugin_addr,
237                           ar->plugin_addr_len,
238                           ar->bandwidth);
239     }
240   return GNUNET_YES;
241 }
242
243
244 /**
245  * Task run to update bandwidth assignments.
246  *
247  * @param cls the 'struct GNUNET_ATS_Handle'
248  * @param tc scheduler context
249  */ 
250 static void
251 update_bandwidth_task (void *cls,
252                        const struct GNUNET_SCHEDULER_TaskContext *tc)
253 {
254   struct GNUNET_ATS_Handle *atc = cls;
255   unsigned int ac;
256   struct SetBandwidthContext bwc;
257
258   atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
259   /* FIXME: update calculations NICELY; what follows is a naive version */
260   GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
261                                          &count_connections,
262                                          &ac);
263   bwc.atc = atc;
264   bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
265   GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
266                                          &set_bw_connections,
267                                          &bwc);
268 }
269
270
271 /**
272  * Calculate an updated bandwidth assignment and notify.
273  *
274  * @param ats handle
275  * @param change which allocation record changed?
276  */
277 static void
278 update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
279                              struct AllocationRecord *change)
280 {
281   /* FIXME: based on the 'change', update the LP-problem... */
282   if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
283     atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task,
284                                              atc);
285 }
286
287
288 /**
289  * Function called with feasbile addresses we might want to suggest.
290  *
291  * @param cls the 'struct GNUNET_ATS_SuggestionContext'
292  * @param key identity of the peer
293  * @param value a 'struct AllocationRecord' for the peer
294  * @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet
295  */
296 static int
297 suggest_address (void *cls,
298                  const GNUNET_HashCode *key,
299                  void *value)
300 {
301   struct GNUNET_ATS_SuggestionContext *asc = cls;
302   struct AllocationRecord *ar = value;
303   
304   /* trivial strategy: pick first available address... */
305   asc->cb (asc->cb_cls,
306            &asc->target,
307            ar->plugin_name,
308            ar->plugin_addr,
309            ar->plugin_addr_len,
310            GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
311            ar->ats, ar->ats_count);
312   asc->cb = NULL;
313   return GNUNET_NO;
314 }
315
316
317 /**
318  * We would like to establish a new connection with a peer.
319  * ATS should suggest a good address to begin with.
320  *
321  * @param atc handle
322  * @param peer identity of the new peer
323  * @param cb function to call with the address
324  * @param cb_cls closure for cb
325  */
326 struct GNUNET_ATS_SuggestionContext *
327 GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
328                             const struct GNUNET_PeerIdentity *peer,
329                             GNUNET_ATS_AddressSuggestionCallback cb,
330                             void *cb_cls)
331 {
332   struct GNUNET_ATS_SuggestionContext *asc;
333
334   asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
335   asc->cb = cb;
336   asc->cb_cls = cb_cls;
337   asc->atc = atc;
338   asc->target = *peer;
339   GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
340                                               &peer->hashPubKey,
341                                               &suggest_address,
342                                               asc);
343   if (NULL == asc->cb)
344     {
345       GNUNET_free (asc);
346       return NULL;
347     }
348   GNUNET_CONTAINER_multihashmap_put (atc->notify_map,
349                                      &peer->hashPubKey,
350                                      asc,
351                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
352   return asc;
353 }
354
355
356 /**
357  * Cancel suggestion request.
358  *
359  * @param asc handle of the request to cancel
360  */
361 void
362 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
363 {
364   GNUNET_assert (GNUNET_OK ==
365                  GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
366                                                        &asc->target.hashPubKey,
367                                                        asc));
368   GNUNET_free (asc);
369 }
370
371
372 /**
373  * Initialize the ATS subsystem.
374  *
375  * @param cfg configuration to use
376  * @param alloc_cb notification to call whenever the allocation changed
377  * @param alloc_cb_cls closure for 'alloc_cb'
378  * @return ats context
379  */
380 struct GNUNET_ATS_Handle *
381 GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
382                  GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
383                  void *alloc_cb_cls)
384 {
385   struct GNUNET_ATS_Handle *atc;
386
387   atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_Handle));
388   atc->cfg = cfg;
389   atc->alloc_cb = alloc_cb;
390   atc->alloc_cb_cls = alloc_cb_cls;
391   atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
392   GNUNET_CONFIGURATION_get_value_number (cfg,
393                                          "core",
394                                          "TOTAL_QUOTA_OUT",
395                                          &atc->total_bps);
396   return atc;
397 }
398
399
400 /**
401  * Free an allocation record.
402  *
403  * @param cls unused
404  * @param key identity of the peer associated with the record
405  * @param value the 'struct AllocationRecord' to free
406  * @return GNUNET_OK (continue to iterate)
407  */
408 static int
409 destroy_allocation_record (void *cls,
410                            const GNUNET_HashCode *key,
411                            void *value)
412 {
413   struct AllocationRecord *ar = value;
414
415   GNUNET_array_grow (ar->ats, ar->ats_count, 0);
416   GNUNET_free (ar->plugin_name);
417   GNUNET_free (ar);
418   return GNUNET_OK;
419 }
420
421
422 /**
423  * Shutdown the ATS subsystem.
424  *
425  * @param atc handle
426  */
427 void
428 GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
429 {
430   if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
431     {
432       GNUNET_SCHEDULER_cancel (atc->ba_task);
433       atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
434     }
435   GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
436                                          &destroy_allocation_record,
437                                          NULL);
438   GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
439   GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
440   GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
441   atc->notify_map = NULL;
442   GNUNET_free (atc);
443 }
444
445
446 /**
447  * Closure for 'update_session'
448  */
449 struct UpdateSessionContext
450 {
451   /**
452    * Ats handle.
453    */
454   struct GNUNET_ATS_Handle *atc;
455
456   /**
457    * Allocation record with new information.
458    */
459   struct AllocationRecord *arnew;
460 };
461
462
463 /**
464  * Update an allocation record, merging with the new information
465  *
466  * @param cls a new 'struct AllocationRecord'
467  * @param key identity of the peer associated with the records
468  * @param value the old 'struct AllocationRecord' 
469  * @return GNUNET_YES if the records do not match, 
470  *         GNUNET_NO if the record do match and 'old' was updated
471  */
472 static int
473 update_session (void *cls,
474                 const GNUNET_HashCode *key,
475                 void *value)
476 {
477   struct UpdateSessionContext *usc = cls;
478   struct AllocationRecord *arnew = usc->arnew;
479   struct AllocationRecord *arold = value;
480   int change;
481
482   if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
483     return GNUNET_YES;
484   if ( (arnew->session == arold->session) ||
485        ( (arold->session == NULL) &&
486          (arold->plugin_addr_len == arnew->plugin_addr_len) &&
487          (0 == memcmp (arold->plugin_addr,
488                        arnew->plugin_addr,
489                        arnew->plugin_addr_len)) ) )
490     {
491       change = GNUNET_NO;
492       /* records match */
493       if (arnew->session != arold->session) 
494         {
495           arold->session = arnew->session;
496           change = GNUNET_YES;
497         }
498       if ( (arnew->connected == GNUNET_YES) &&
499            (arold->connected == GNUNET_NO) )
500         {
501           arold->connected = GNUNET_YES;
502           change = GNUNET_YES;
503         }
504       // FIXME: merge ats arrays of (arold, arnew);
505       
506       if (GNUNET_YES == change)
507         update_bandwidth_assignment (usc->atc, arold);
508       return GNUNET_NO;      
509     }
510   return GNUNET_YES;
511 }
512
513
514 /**
515  * Create an allocation record with the given properties.
516  *
517  * @param plugin_name name of the currently used transport plugin
518  * @param session session in use (if available)
519  * @param plugin_addr address in use (if available)
520  * @param plugin_addr_len number of bytes in plugin_addr
521  * @param ats performance data for the connection
522  * @param ats_count number of performance records in 'ats'
523  */
524 static struct AllocationRecord *
525 create_allocation_record (const char *plugin_name,
526                           struct Session *session,
527                           const void *plugin_addr,
528                           size_t plugin_addr_len,
529                           const struct GNUNET_TRANSPORT_ATS_Information *ats,
530                           uint32_t ats_count)
531 {
532   struct AllocationRecord *ar;
533
534   ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len);
535   ar->plugin_name = GNUNET_strdup (plugin_name);
536   ar->plugin_addr = &ar[1];
537   memcpy (&ar[1], plugin_addr, plugin_addr_len);
538   ar->session = session;
539   ar->plugin_addr_len = plugin_addr_len;
540   GNUNET_array_grow (ar->ats,
541                      ar->ats_count,
542                      ats_count);
543   memcpy (ar->ats, 
544           ats, 
545           ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
546   return ar;
547 }
548
549
550 /**
551  * Mark all matching allocation records as not connected.
552  *
553  * @param cls 'struct GTS_AtsHandle'
554  * @param key identity of the peer associated with the record
555  * @param value the 'struct AllocationRecord' to clear the 'connected' flag
556  * @return GNUNET_OK (continue to iterate)
557  */
558 static int
559 disconnect_peer (void *cls,
560                  const GNUNET_HashCode *key,
561                  void *value)
562 {
563   struct GNUNET_ATS_Handle *atc = cls;
564   struct AllocationRecord *ar = value;
565
566   if (GNUNET_YES == ar->connected)
567     {
568       ar->connected = GNUNET_NO;     
569       update_bandwidth_assignment (atc, ar);
570     }
571   return GNUNET_OK;
572 }
573
574
575 /**
576  * We established a new connection with a peer (for example, because
577  * core asked for it or because the other peer connected to us).
578  * Calculate bandwidth assignments including the new peer.
579  *
580  * @param atc handle
581  * @param peer identity of the new peer
582  * @param plugin_name name of the currently used transport plugin
583  * @param session session in use (if available)
584  * @param plugin_addr address in use (if available)
585  * @param plugin_addr_len number of bytes in plugin_addr
586  * @param ats performance data for the connection
587  * @param ats_count number of performance records in 'ats'
588  */
589 void
590 GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
591                          const struct GNUNET_PeerIdentity *peer,
592                          const char *plugin_name,
593                          struct Session *session,
594                          const void *plugin_addr,
595                          size_t plugin_addr_len,
596                          const struct GNUNET_TRANSPORT_ATS_Information *ats,
597                          uint32_t ats_count)
598 {
599   struct AllocationRecord *ar;
600   struct UpdateSessionContext usc;
601
602   (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
603                                                 &disconnect_peer,
604                                                 atc);
605   ar = create_allocation_record (plugin_name,
606                                  session,
607                                  plugin_addr,
608                                  plugin_addr_len,
609                                  ats,
610                                  ats_count);
611   ar->connected = GNUNET_YES;
612   usc.atc = atc;
613   usc.arnew = ar;
614   if (GNUNET_SYSERR ==
615       GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
616                                              &update_session,
617                                              &usc))
618     {     
619       destroy_allocation_record (NULL, &peer->hashPubKey, ar);
620       return;
621     }
622   GNUNET_assert (GNUNET_OK ==
623                  GNUNET_CONTAINER_multihashmap_put (atc->peers,
624                                                     &peer->hashPubKey,
625                                                     ar,
626                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));   
627 }
628
629
630 /**
631  * We disconnected from the given peer (for example, because ats, core
632  * or blacklist asked for it or because the other peer disconnected).
633  * Calculate bandwidth assignments without the peer.
634  *
635  * @param atc handle
636  * @param peer identity of the new peer
637  */
638 void
639 GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
640                          const struct GNUNET_PeerIdentity *peer)
641 {
642   (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
643                                                      &peer->hashPubKey,
644                                                      &disconnect_peer,
645                                                      atc);
646 }
647
648
649 /**
650  * Closure for 'destroy_allocation_record'
651  */
652 struct SessionDestroyContext
653 {
654   /**
655    * Ats handle.
656    */
657   struct GNUNET_ATS_Handle *atc;
658
659   /**
660    * Session being destroyed.
661    */
662   const struct Session *session;
663 };
664
665
666 /**
667  * Free an allocation record matching the given session.
668  *
669  * @param cls the 'struct SessionDestroyContext'
670  * @param key identity of the peer associated with the record
671  * @param value the 'struct AllocationRecord' to free
672  * @return GNUNET_OK (continue to iterate)
673  */
674 static int
675 destroy_session (void *cls,
676                  const GNUNET_HashCode *key,
677                  void *value)
678 {
679   struct SessionDestroyContext *sdc = cls;
680   struct AllocationRecord *ar = value;
681
682   if (ar->session != sdc->session)
683     return GNUNET_OK;
684   ar->session = NULL;
685   if (ar->plugin_addr != NULL)
686     return GNUNET_OK;
687   GNUNET_assert (GNUNET_OK ==
688                  GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
689                                                        key,
690                                                        ar));
691   if (GNUNET_YES == ar->connected);
692     {
693       /* FIXME: is this supposed to be allowed? What to do then? */
694       GNUNET_break (0);
695     }
696   destroy_allocation_record (NULL, key, ar);
697   return GNUNET_OK;
698 }
699
700
701 /**
702  * A session got destroyed, stop including it as a valid address.
703  *
704  * @param atc handle
705  * @param peer identity of the peer
706  * @param session session handle that is no longer valid
707  */
708 void
709 GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
710                               const struct GNUNET_PeerIdentity *peer,
711                               const struct Session *session)
712 {
713   struct SessionDestroyContext sdc;
714
715   sdc.atc = atc;
716   sdc.session = session;
717   (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
718                                                 &destroy_session,
719                                                 &sdc);
720 }
721
722
723 /**
724  * Notify validation watcher that an entry is now valid
725  *
726  * @param cls 'struct ValidationEntry' that is now valid
727  * @param key peer identity (unused)
728  * @param value a 'GST_ValidationIteratorContext' to notify
729  * @return GNUNET_YES (continue to iterate)
730  */
731 static int
732 notify_valid (void *cls,
733               const GNUNET_HashCode *key,
734               void *value)
735 {
736   struct AllocationRecord *ar = cls;
737   struct GNUNET_ATS_SuggestionContext *asc = value;
738
739   asc->cb (asc->cb_cls,
740            &asc->target,
741            ar->plugin_name,
742            ar->plugin_addr,
743            ar->plugin_addr_len,
744            GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
745            ar->ats, ar->ats_count);
746   GNUNET_ATS_suggest_address_cancel (asc);
747   return GNUNET_OK;
748 }
749
750
751 /**
752  * We have updated performance statistics for a given address.  Note
753  * that this function can be called for addresses that are currently
754  * in use as well as addresses that are valid but not actively in use.
755  * Furthermore, the peer may not even be connected to us right now (in
756  * which case the call may be ignored or the information may be stored
757  * for later use).  Update bandwidth assignments.
758  *
759  * @param atc handle
760  * @param peer identity of the peer
761  * @param valid_until how long is the address valid?
762  * @param plugin_name name of the transport plugin
763  * @param session session handle (if available)
764  * @param plugin_addr address  (if available)
765  * @param plugin_addr_len number of bytes in plugin_addr
766  * @param ats performance data for the address
767  * @param ats_count number of performance records in 'ats'
768  */
769 void
770 GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
771                            const struct GNUNET_PeerIdentity *peer,
772                            struct GNUNET_TIME_Absolute valid_until,
773                            const char *plugin_name,
774                            struct Session *session,
775                            const void *plugin_addr,
776                            size_t plugin_addr_len,
777                            const struct GNUNET_TRANSPORT_ATS_Information *ats,
778                            uint32_t ats_count)
779 {
780   struct AllocationRecord *ar;
781   struct UpdateSessionContext usc;
782
783   ar = create_allocation_record (plugin_name,                            
784                                  session,
785                                  plugin_addr,
786                                  plugin_addr_len,
787                                  ats,
788                                  ats_count);
789   usc.atc = atc;
790   usc.arnew = ar;    
791   if (GNUNET_SYSERR ==
792       GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
793                                              &update_session,
794                                              &usc))
795     {     
796       destroy_allocation_record (NULL, &peer->hashPubKey, ar);
797       return;
798     }
799   GNUNET_assert (GNUNET_OK ==
800                  GNUNET_CONTAINER_multihashmap_put (atc->peers,
801                                                     &peer->hashPubKey,
802                                                     ar,
803                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 
804   GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
805                                               &peer->hashPubKey,
806                                               &notify_valid,
807                                               ar);
808 }
809
810 /* end of file gnunet-service-transport_ats.c */