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