summaryrefslogtreecommitdiff
path: root/src/ats/ats_api.c
blob: 8a5f23247801d2bada54a1f1abf414f5491f3802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/*
     This file is part of GNUnet.
     (C) 2010,2011 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/
/**
 * @file ats/ats_api.c
 * @brief automatic transport selection API
 * @author Christian Grothoff
 * @author Matthias Wachs
 *
 * TODO:
 * - write test case
 * - extend API to get performance data
 * - implement simplistic strategy based on say 'lowest latency' or strict ordering
 * - extend API to get peer preferences, implement proportional bandwidth assignment
 * - re-implement API against a real ATS service (!)
 */
#include "platform.h"
#include "gnunet_ats_service.h"

// NOTE: this implementation is simply supposed
// to implement a simplistic strategy in-process;
// in the future, we plan to replace it with a real
// service implementation

/**
 * Allocation record for a peer's address.
 */
struct AllocationRecord
{

  /**
   * Performance information associated with this address (array).
   */
  struct GNUNET_TRANSPORT_ATS_Information *ats;

  /**
   * Name of the plugin
   */
  char *plugin_name;

  /**
   * Address this record represents, allocated at the end of this struct.
   */
  const void *plugin_addr;

  /**
   * Session associated with this record.
   */
  struct Session *session;

  /**
   * Number of bytes in plugin_addr.
   */
  size_t plugin_addr_len;

  /**
   * Number of entries in 'ats'.
   */
  uint32_t ats_count;

  /**
   * Bandwidth assigned to this address right now, 0 for none.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bandwidth;

  /**
   * Set to GNUNET_YES if this is the connected address of a connected peer.
   */
  int connected;

};


/**
 * Opaque handle to obtain address suggestions.
 */
struct GNUNET_ATS_SuggestionContext
{

  /**
   * Function to call with our final suggestion.
   */
  GNUNET_ATS_AddressSuggestionCallback cb;

  /**
   * Closure for 'cb'.
   */
  void *cb_cls;

  /**
   * Global ATS handle.
   */
  struct GNUNET_ATS_Handle *atc;

  /**
   * Which peer are we monitoring?
   */
  struct GNUNET_PeerIdentity target;

};


/**
 * Handle to the ATS subsystem.
 */
struct GNUNET_ATS_Handle
{
  /**
   * Configuration.
   */
  const struct GNUNET_CONFIGURATION_Handle *cfg;

  /**
   * Function to call when the allocation changes.
   */
  GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb;

  /**
   * Closure for 'alloc_cb'.
   */
  void *alloc_cb_cls;

  /**
   * Information about all connected peers.  Maps peer identities
   * to one or more 'struct AllocationRecord' values.
   */
  struct GNUNET_CONTAINER_MultiHashMap *peers;

  /**
   * Map of PeerIdentities to 'struct GNUNET_ATS_SuggestionContext's.
   */
  struct GNUNET_CONTAINER_MultiHashMap *notify_map;


  /**
   * Task scheduled to update our bandwidth assignment.
   */
  GNUNET_SCHEDULER_TaskIdentifier ba_task;

  /**
   * Total bandwidth per configuration.
   */
  unsigned long long total_bps;
};


/**
 * Count number of connected records.
 *
 * @param cls pointer to counter
 * @param key identity of the peer associated with the records
 * @param value a 'struct AllocationRecord'
 * @return GNUNET_YES (continue iteration)
 */
static int
count_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
  unsigned int *ac = cls;
  struct AllocationRecord *ar = value;

  if (GNUNET_YES == ar->connected)
    (*ac)++;
  return GNUNET_YES;
}


/**
 * Closure for 'set_bw_connections'.
 */
struct SetBandwidthContext
{
  /**
   * ATS handle.
   */
  struct GNUNET_ATS_Handle *atc;

  /**
   * Bandwidth to assign.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bw;
};


/**
 * Set bandwidth based on record.
 *
 * @param cls 'struct SetBandwidthContext'
 * @param key identity of the peer associated with the records
 * @param value a 'struct AllocationRecord'
 * @return GNUNET_YES (continue iteration)
 */
static int
set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct SetBandwidthContext *sbc = cls;
  struct AllocationRecord *ar = value;

  if (GNUNET_YES == ar->connected)
  {
    ar->bandwidth = sbc->bw;
    sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
                        (const struct GNUNET_PeerIdentity *) key,
                        ar->plugin_name, ar->session, ar->plugin_addr,
                        ar->plugin_addr_len, ar->bandwidth);
  }
  else if (ntohl (ar->bandwidth.value__) > 0)
  {
    ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
    sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
                        (const struct GNUNET_PeerIdentity *) key,
                        ar->plugin_name, ar->session, ar->plugin_addr,
                        ar->plugin_addr_len, ar->bandwidth);
  }
  return GNUNET_YES;
}


/**
 * Task run to update bandwidth assignments.
 *
 * @param cls the 'struct GNUNET_ATS_Handle'
 * @param tc scheduler context
 */
static void
update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_ATS_Handle *atc = cls;
  unsigned int ac;
  struct SetBandwidthContext bwc;

  atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
  /* FIXME: update calculations NICELY; what follows is a naive version */
  GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &count_connections, &ac);
  bwc.atc = atc;
  bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
  GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
}


/**
 * Calculate an updated bandwidth assignment and notify.
 *
 * @param atc handle
 * @param change which allocation record changed?
 */
static void
update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
                             struct AllocationRecord *change)
{
  /* FIXME: based on the 'change', update the LP-problem... */
  if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
    atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, atc);
}


/**
 * Function called with feasbile addresses we might want to suggest.
 *
 * @param cls the 'struct GNUNET_ATS_SuggestionContext'
 * @param key identity of the peer
 * @param value a 'struct AllocationRecord' for the peer
 * @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet
 */
static int
suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct GNUNET_ATS_SuggestionContext *asc = cls;
  struct AllocationRecord *ar = value;

  /* trivial strategy: pick first available address... */
  asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
           ar->plugin_addr_len, ar->session,
           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
           ar->ats_count);
  asc->cb = NULL;
  return GNUNET_NO;
}


/**
 * We would like to establish a new connection with a peer.
 * ATS should suggest a good address to begin with.
 *
 * @param atc handle
 * @param peer identity of the new peer
 * @param cb function to call with the address
 * @param cb_cls closure for cb
 */
struct GNUNET_ATS_SuggestionContext *
GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
                            const struct GNUNET_PeerIdentity *peer,
                            GNUNET_ATS_AddressSuggestionCallback cb,
                            void *cb_cls)
{
  struct GNUNET_ATS_SuggestionContext *asc;

  asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
  asc->cb = cb;
  asc->cb_cls = cb_cls;
  asc->atc = atc;
  asc->target = *peer;
  GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, &peer->hashPubKey,
                                              &suggest_address, asc);
  if (NULL == asc->cb)
  {
    GNUNET_free (asc);
    return NULL;
  }
  GNUNET_CONTAINER_multihashmap_put (atc->notify_map, &peer->hashPubKey, asc,
                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
  return asc;
}


/**
 * Cancel suggestion request.
 *
 * @param asc handle of the request to cancel
 */
void
GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
{
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
                                                       &asc->target.hashPubKey,
                                                       asc));
  GNUNET_free (asc);
}


/**
 * Initialize the ATS subsystem.
 *
 * @param cfg configuration to use
 * @param alloc_cb notification to call whenever the allocation changed
 * @param alloc_cb_cls closure for 'alloc_cb'
 * @return ats context
 */
struct GNUNET_ATS_Handle *
GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
                 GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
                 void *alloc_cb_cls)
{
  struct GNUNET_ATS_Handle *atc;

  atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_Handle));
  atc->cfg = cfg;
  atc->alloc_cb = alloc_cb;
  atc->alloc_cb_cls = alloc_cb_cls;
  atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
  atc->notify_map = GNUNET_CONTAINER_multihashmap_create (256);
  GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
                                         &atc->total_bps);
  return atc;
}


/**
 * Free an allocation record.
 *
 * @param cls unused
 * @param key identity of the peer associated with the record
 * @param value the 'struct AllocationRecord' to free
 * @return GNUNET_OK (continue to iterate)
 */
static int
destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct AllocationRecord *ar = value;

  GNUNET_array_grow (ar->ats, ar->ats_count, 0);
  GNUNET_free (ar->plugin_name);
  GNUNET_free (ar);
  return GNUNET_OK;
}


/**
 * Shutdown the ATS subsystem.
 *
 * @param atc handle
 */
void
GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
{
  if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
  {
    GNUNET_SCHEDULER_cancel (atc->ba_task);
    atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_allocation_record,
                                         NULL);
  GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
  GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
  GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
  atc->notify_map = NULL;
  GNUNET_free (atc);
}


/**
 * Closure for 'update_session'
 */
struct UpdateSessionContext
{
  /**
   * Ats handle.
   */
  struct GNUNET_ATS_Handle *atc;

  /**
   * Allocation record with new information.
   */
  struct AllocationRecord *arnew;
};


/**
 * Update an allocation record, merging with the new information
 *
 * @param cls a new 'struct AllocationRecord'
 * @param key identity of the peer associated with the records
 * @param value the old 'struct AllocationRecord'
 * @return GNUNET_YES if the records do not match,
 *         GNUNET_NO if the record do match and 'old' was updated
 */
static int
update_session (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct UpdateSessionContext *usc = cls;
  struct AllocationRecord *arnew = usc->arnew;
  struct AllocationRecord *arold = value;
  int change;

  if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
    return GNUNET_YES;
  if ((arnew->session == arold->session) ||
      ((arold->session == NULL) &&
       (arold->plugin_addr_len == arnew->plugin_addr_len) &&
       (0 ==
        memcmp (arold->plugin_addr, arnew->plugin_addr,
                arnew->plugin_addr_len))))
  {
    change = GNUNET_NO;
    /* records match */
    if (arnew->session != arold->session)
    {
      arold->session = arnew->session;
      change = GNUNET_YES;
    }
    if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
    {
      arold->connected = GNUNET_YES;
      change = GNUNET_YES;
    }
    // FIXME: merge ats arrays of (arold, arnew);

    if (GNUNET_YES == change)
      update_bandwidth_assignment (usc->atc, arold);
    return GNUNET_NO;
  }
  return GNUNET_YES;
}


/**
 * Create an allocation record with the given properties.
 *
 * @param plugin_name name of the currently used transport plugin
 * @param session session in use (if available)
 * @param plugin_addr address in use (if available)
 * @param plugin_addr_len number of bytes in plugin_addr
 * @param ats performance data for the connection
 * @param ats_count number of performance records in 'ats'
 */
static struct AllocationRecord *
create_allocation_record (const char *plugin_name, struct Session *session,
                          const void *plugin_addr, size_t plugin_addr_len,
                          const struct GNUNET_TRANSPORT_ATS_Information *ats,
                          uint32_t ats_count)
{
  struct AllocationRecord *ar;

  ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len);
  ar->plugin_name = GNUNET_strdup (plugin_name);
  ar->plugin_addr = &ar[1];
  memcpy (&ar[1], plugin_addr, plugin_addr_len);
  ar->session = session;
  ar->plugin_addr_len = plugin_addr_len;
  GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
  memcpy (ar->ats, ats,
          ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
  return ar;
}


/**
 * Mark all matching allocation records as not connected.
 *
 * @param cls 'struct GTS_AtsHandle'
 * @param key identity of the peer associated with the record
 * @param value the 'struct AllocationRecord' to clear the 'connected' flag
 * @return GNUNET_OK (continue to iterate)
 */
static int
disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct GNUNET_ATS_Handle *atc = cls;
  struct AllocationRecord *ar = value;

  if (GNUNET_YES == ar->connected)
  {
    ar->connected = GNUNET_NO;
    update_bandwidth_assignment (atc, ar);
  }
  return GNUNET_OK;
}


/**
 * We established a new connection with a peer (for example, because
 * core asked for it or because the other peer connected to us).
 * Calculate bandwidth assignments including the new peer.
 *
 * @param atc handle
 * @param peer identity of the new peer
 * @param plugin_name name of the currently used transport plugin
 * @param session session in use (if available)
 * @param plugin_addr address in use (if available)
 * @param plugin_addr_len number of bytes in plugin_addr
 * @param ats performance data for the connection
 * @param ats_count number of performance records in 'ats'
 */
void
GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
                         const struct GNUNET_PeerIdentity *peer,
                         const char *plugin_name, struct Session *session,
                         const void *plugin_addr, size_t plugin_addr_len,
                         const struct GNUNET_TRANSPORT_ATS_Information *ats,
                         uint32_t ats_count)
{
  struct AllocationRecord *ar;
  struct UpdateSessionContext usc;

  (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
                                                atc);
  ar = create_allocation_record (plugin_name, session, plugin_addr,
                                 plugin_addr_len, ats, ats_count);
  ar->connected = GNUNET_YES;
  usc.atc = atc;
  usc.arnew = ar;
  if (GNUNET_SYSERR ==
      GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
  {
    destroy_allocation_record (NULL, &peer->hashPubKey, ar);
    return;
  }
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_put (atc->peers,
                                                    &peer->hashPubKey, ar,
                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}


/**
 * We disconnected from the given peer (for example, because ats, core
 * or blacklist asked for it or because the other peer disconnected).
 * Calculate bandwidth assignments without the peer.
 *
 * @param atc handle
 * @param peer identity of the new peer
 */
void
GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
                            const struct GNUNET_PeerIdentity *peer)
{
  (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
                                                     &peer->hashPubKey,
                                                     &disconnect_peer, atc);
}


/**
 * Closure for 'destroy_allocation_record'
 */
struct SessionDestroyContext
{
  /**
   * Ats handle.
   */
  struct GNUNET_ATS_Handle *atc;

  /**
   * Session being destroyed.
   */
  const struct Session *session;
};


/**
 * Free an allocation record matching the given session.
 *
 * @param cls the 'struct SessionDestroyContext'
 * @param key identity of the peer associated with the record
 * @param value the 'struct AllocationRecord' to free
 * @return GNUNET_OK (continue to iterate)
 */
static int
destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct SessionDestroyContext *sdc = cls;
  struct AllocationRecord *ar = value;

  if (ar->session != sdc->session)
    return GNUNET_OK;
  ar->session = NULL;
  if (ar->plugin_addr != NULL)
    return GNUNET_OK;
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, key,
                                                       ar));
  if (GNUNET_YES == ar->connected) ;
  {
    /* FIXME: is this supposed to be allowed? What to do then? */
    GNUNET_break (0);
  }
  destroy_allocation_record (NULL, key, ar);
  return GNUNET_OK;
}


/**
 * A session got destroyed, stop including it as a valid address.
 *
 * @param atc handle
 * @param peer identity of the peer
 * @param session session handle that is no longer valid
 */
void
GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
                              const struct GNUNET_PeerIdentity *peer,
                              const struct Session *session)
{
  struct SessionDestroyContext sdc;

  sdc.atc = atc;
  sdc.session = session;
  (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_session,
                                                &sdc);
}


/**
 * Notify validation watcher that an entry is now valid
 *
 * @param cls 'struct ValidationEntry' that is now valid
 * @param key peer identity (unused)
 * @param value a 'GST_ValidationIteratorContext' to notify
 * @return GNUNET_YES (continue to iterate)
 */
static int
notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
{
  struct AllocationRecord *ar = cls;
  struct GNUNET_ATS_SuggestionContext *asc = value;

  asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
           ar->plugin_addr_len, ar->session,
           GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
           ar->ats_count);
  GNUNET_ATS_suggest_address_cancel (asc);
  return GNUNET_OK;
}


/**
 * We have updated performance statistics for a given address.  Note
 * that this function can be called for addresses that are currently
 * in use as well as addresses that are valid but not actively in use.
 * Furthermore, the peer may not even be connected to us right now (in
 * which case the call may be ignored or the information may be stored
 * for later use).  Update bandwidth assignments.
 *
 * @param atc handle
 * @param peer identity of the peer
 * @param valid_until how long is the address valid?
 * @param plugin_name name of the transport plugin
 * @param session session handle (if available)
 * @param plugin_addr address  (if available)
 * @param plugin_addr_len number of bytes in plugin_addr
 * @param ats performance data for the address
 * @param ats_count number of performance records in 'ats'
 */
void
GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
                           const struct GNUNET_PeerIdentity *peer,
                           struct GNUNET_TIME_Absolute valid_until,
                           const char *plugin_name, struct Session *session,
                           const void *plugin_addr, size_t plugin_addr_len,
                           const struct GNUNET_TRANSPORT_ATS_Information *ats,
                           uint32_t ats_count)
{
  struct AllocationRecord *ar;
  struct UpdateSessionContext usc;

  ar = create_allocation_record (plugin_name, session, plugin_addr,
                                 plugin_addr_len, ats, ats_count);
  usc.atc = atc;
  usc.arnew = ar;
  if (GNUNET_SYSERR ==
      GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
  {
    destroy_allocation_record (NULL, &peer->hashPubKey, ar);
    return;
  }
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_put (atc->peers,
                                                    &peer->hashPubKey, ar,
                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
  GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
                                              &peer->hashPubKey, &notify_valid,
                                              ar);
}

/* end of file gnunet-service-transport_ats.c */