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