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