d7e305950f6dcba3c7c142997fbec93616830102
[oweals/gnunet.git] / src / ats / ats_api_scheduling.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file ats/ats_api_scheduling.c
22  * @brief automatic transport selection and outbound bandwidth determination
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  *
26  * TODO:
27  * - we could avoid a linear scan over the
28  *   active addresses in some cases, so if
29  *   there is need, we can still optimize here
30  * - we might want to split off the logic to
31  *   determine LAN vs. WAN, as it has nothing
32  *   to do with accessing the ATS service.
33  */
34 #include "platform.h"
35 #include "gnunet_ats_service.h"
36 #include "ats.h"
37
38 /**
39  * How frequently do we scan the interfaces for changes to the addresses?
40  */
41 #define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
42
43 #define LOG(kind,...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__)
44
45 /**
46  * Session ID we use if there is no session / slot.
47  */
48 #define NOT_FOUND 0
49
50
51 /**
52  * Information we track per address, incoming or outgoing.  It also
53  * doesn't matter if we have a session, any address that ATS is
54  * allowed to suggest right now should be tracked.
55  */
56 struct GNUNET_ATS_AddressRecord
57 {
58
59   /**
60    * Scheduling handle this address record belongs to.
61    */
62   struct GNUNET_ATS_SchedulingHandle *sh;
63
64   /**
65    * Address data.
66    */
67   struct GNUNET_HELLO_Address *address;
68
69   /**
70    * Session handle.  NULL if we have an address but no
71    * active session for this address.
72    */
73   struct GNUNET_ATS_Session *session;
74
75   /**
76    * Performance data about the address.
77    */
78   struct GNUNET_ATS_PropertiesNBO properties;
79
80   /**
81    * Which slot (index) in the session array does
82    * this record correspond to?
83    * FIXME: a linear search on this is really crappy!
84    * Maybe switch to a 64-bit global counter and be
85    * done with it?  Or does that then cause too much
86    * trouble on the ATS-service side?
87    */
88   uint32_t slot;
89
90   /**
91    * We're about to destroy this address record, just ATS does
92    * not know this yet.  Once ATS confirms its destruction,
93    * we can clean up.
94    */
95   int in_destroy;
96 };
97
98
99 /**
100  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
101  */
102 struct GNUNET_ATS_SchedulingHandle
103 {
104
105   /**
106    * Our configuration.
107    */
108   const struct GNUNET_CONFIGURATION_Handle *cfg;
109
110   /**
111    * Callback to invoke on suggestions.
112    */
113   GNUNET_ATS_AddressSuggestionCallback suggest_cb;
114
115   /**
116    * Closure for @e suggest_cb.
117    */
118   void *suggest_cb_cls;
119
120   /**
121    * Message queue for sending requests to the ATS service.
122    */
123   struct GNUNET_MQ_Handle *mq;
124
125   /**
126    * Array of session objects (we need to translate them to numbers and back
127    * for the protocol; the offset in the array is the session number on the
128    * network).  Index 0 is always NULL and reserved to represent the NULL pointer.
129    * Unused entries are also NULL.
130    */
131   struct GNUNET_ATS_AddressRecord **session_array;
132
133   /**
134    * Task to trigger reconnect.
135    */
136   struct GNUNET_SCHEDULER_Task *task;
137
138   /**
139    * Reconnect backoff delay.
140    */
141   struct GNUNET_TIME_Relative backoff;
142
143   /**
144    * Size of the @e session_array.
145    */
146   unsigned int session_array_size;
147
148 };
149
150
151 /**
152  * Re-establish the connection to the ATS service.
153  *
154  * @param sh handle to use to re-connect.
155  */
156 static void
157 reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
158
159
160 /**
161  * Re-establish the connection to the ATS service.
162  *
163  * @param cls handle to use to re-connect.
164  */
165 static void
166 reconnect_task (void *cls)
167 {
168   struct GNUNET_ATS_SchedulingHandle *sh = cls;
169
170   sh->task = NULL;
171   reconnect (sh);
172 }
173
174
175 /**
176  * Disconnect from ATS and then reconnect.
177  *
178  * @param sh our handle
179  */
180 static void
181 force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
182 {
183   if (NULL != sh->mq)
184   {
185     GNUNET_MQ_destroy (sh->mq);
186     sh->mq = NULL;
187   }
188   sh->suggest_cb (sh->suggest_cb_cls,
189                   NULL, NULL, NULL,
190                   GNUNET_BANDWIDTH_ZERO,
191                   GNUNET_BANDWIDTH_ZERO);
192   sh->backoff = GNUNET_TIME_STD_BACKOFF (sh->backoff);
193   sh->task = GNUNET_SCHEDULER_add_delayed (sh->backoff,
194                                            &reconnect_task,
195                                            sh);
196 }
197
198
199 /**
200  * Find the session object corresponding to the given session ID.
201  *
202  * @param sh our handle
203  * @param session_id current session ID
204  * @param peer peer the session belongs to
205  * @return the session object (or NULL)
206  */
207 static struct GNUNET_ATS_AddressRecord *
208 find_session (struct GNUNET_ATS_SchedulingHandle *sh,
209               uint32_t session_id,
210               const struct GNUNET_PeerIdentity *peer)
211 {
212   struct GNUNET_ATS_AddressRecord *ar;
213
214   if (session_id >= sh->session_array_size)
215   {
216     GNUNET_break (0);
217     return NULL;
218   }
219   if (0 == session_id)
220     return NULL;
221   ar = sh->session_array[session_id];
222   if (NULL == ar)
223   {
224     GNUNET_break (0);
225     return NULL;
226   }
227   if (NULL == ar->address)
228   {
229     /* address was destroyed in the meantime, this can happen
230        as we communicate asynchronously with the ATS service. */
231     return NULL;
232   }
233   if (0 != memcmp (peer,
234                    &ar->address->peer,
235                    sizeof (struct GNUNET_PeerIdentity)))
236   {
237     GNUNET_break (0);
238     return NULL;
239   }
240   return ar;
241 }
242
243
244 /**
245  * Get an available session ID.
246  *
247  * @param sh our handle
248  * @return an unused slot, but never NOT_FOUND (0)
249  */
250 static uint32_t
251 find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh)
252 {
253   static uint32_t off;
254   uint32_t i;
255
256   i = 0;
257   while ( ( (NOT_FOUND == off) ||
258             (NULL != sh->session_array[off % sh->session_array_size]) ) &&
259           (i < sh->session_array_size) )
260   {
261     off++;
262     i++;
263   }
264   if ( (NOT_FOUND != off % sh->session_array_size) &&
265        (NULL == sh->session_array[off % sh->session_array_size]) )
266     return off;
267   i = sh->session_array_size;
268   GNUNET_array_grow (sh->session_array,
269                      sh->session_array_size,
270                      sh->session_array_size * 2);
271   return i;
272 }
273
274
275 /**
276  * Get the ID for the given session object.
277  *
278  * @param sh our handle
279  * @param session session object
280  * @param address the address we are looking for
281  * @return the session id or NOT_FOUND for error
282  */
283 static uint32_t
284 find_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
285                  struct GNUNET_ATS_Session *session,
286                  const struct GNUNET_HELLO_Address *address)
287 {
288   uint32_t i;
289
290   if (NULL == address)
291   {
292     GNUNET_break (0);
293     return NOT_FOUND;
294   }
295   for (i = 1; i < sh->session_array_size; i++)
296     if ( (NULL != sh->session_array[i]) &&
297          (GNUNET_NO == sh->session_array[i]->in_destroy) &&
298          ( (session == sh->session_array[i]->session) ||
299            (NULL == sh->session_array[i]->session) ) &&
300          (0 == memcmp (&address->peer,
301                        &sh->session_array[i]->address->peer,
302                        sizeof (struct GNUNET_PeerIdentity))) &&
303          (0 == GNUNET_HELLO_address_cmp (address,
304                                          sh->session_array[i]->address)) )
305       return i;
306   return NOT_FOUND;
307 }
308
309
310 /**
311  * Release the session slot from the session table (ATS service is
312  * also done using it).
313  *
314  * @param sh our handle
315  * @param session_id identifies session that is no longer valid
316  */
317 static void
318 release_session (struct GNUNET_ATS_SchedulingHandle *sh,
319                  uint32_t session_id)
320 {
321   struct GNUNET_ATS_AddressRecord *ar;
322
323   if (NOT_FOUND == session_id)
324     return;
325   if (session_id >= sh->session_array_size)
326   {
327     GNUNET_break (0);
328     force_reconnect (sh);
329     return;
330   }
331   /* this slot should have been removed from remove_session before */
332   ar = sh->session_array[session_id];
333   if (NULL != ar->session)
334   {
335     GNUNET_break (0);
336     force_reconnect (sh);
337     return;
338   }
339   GNUNET_HELLO_address_free (ar->address);
340   GNUNET_free (ar);
341   sh->session_array[session_id] = NULL;
342 }
343
344
345 /**
346  * Type of a function to call when we receive a session release
347  * message from the service.
348  *
349  * @param cls the `struct GNUNET_ATS_SchedulingHandle`
350  * @param srm message received
351  */
352 static void
353 handle_ats_session_release (void *cls,
354                             const struct GNUNET_ATS_SessionReleaseMessage *srm)
355 {
356   struct GNUNET_ATS_SchedulingHandle *sh = cls;
357
358   /* Note: peer field in srm not necessary right now,
359      but might be good to have in the future */
360   release_session (sh,
361                    ntohl (srm->session_id));
362 }
363
364
365 /**
366  * Type of a function to call when we receive a address suggestion
367  * message from the service.
368  *
369  * @param cls the `struct GNUNET_ATS_SchedulingHandle`
370  * @param m message received
371  */
372 static void
373 handle_ats_address_suggestion (void *cls,
374                                const struct AddressSuggestionMessage *m)
375 {
376   struct GNUNET_ATS_SchedulingHandle *sh = cls;
377   struct GNUNET_ATS_AddressRecord *ar;
378   uint32_t session_id;
379
380   session_id = ntohl (m->session_id);
381   if (0 == session_id)
382   {
383     GNUNET_break (0);
384     force_reconnect (sh);
385     return;
386   }
387   ar = find_session (sh,
388                      session_id,
389                      &m->peer);
390   if (NULL == ar)
391   {
392     GNUNET_break (0);
393     force_reconnect (sh);
394     return;
395   }
396   if (NULL == sh->suggest_cb)
397     return;
398   if (GNUNET_YES == ar->in_destroy)
399   {
400     /* ignore suggestion, as this address is dying, unless BW is 0,
401        in that case signal 'disconnect' via BW 0 */
402     if ( (0 == ntohl (m->bandwidth_out.value__)) &&
403          (0 == ntohl (m->bandwidth_in.value__)) )
404     {
405       LOG (GNUNET_ERROR_TYPE_DEBUG,
406            "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
407            GNUNET_i2s (&ar->address->peer),
408            (unsigned int) ntohl (m->bandwidth_out.value__),
409            (unsigned int) ntohl (m->bandwidth_in.value__));
410       sh->suggest_cb (sh->suggest_cb_cls,
411                       &m->peer,
412                       NULL,
413                       NULL,
414                       m->bandwidth_out,
415                       m->bandwidth_in);
416     }
417     return;
418   }
419   if ( (NULL == ar->session) &&
420        (GNUNET_HELLO_address_check_option (ar->address,
421                                            GNUNET_HELLO_ADDRESS_INFO_INBOUND)) )
422   {
423     GNUNET_break (0);
424     return;
425   }
426   sh->backoff = GNUNET_TIME_UNIT_ZERO;
427   LOG (GNUNET_ERROR_TYPE_DEBUG,
428        "ATS suggests address slot %u for peer `%s' using plugin %s\n",
429        ar->slot,
430        GNUNET_i2s (&ar->address->peer),
431        ar->address->transport_name);
432   sh->suggest_cb (sh->suggest_cb_cls,
433                   &m->peer,
434                   ar->address,
435                   ar->session,
436                   m->bandwidth_out,
437                   m->bandwidth_in);
438 }
439
440
441 /**
442  * We encountered an error handling the MQ to the
443  * ATS service.  Reconnect.
444  *
445  * @param cls the `struct GNUNET_ATS_SchedulingHandle`
446  * @param error details about the error
447  */
448 static void
449 error_handler (void *cls,
450                enum GNUNET_MQ_Error error)
451 {
452   struct GNUNET_ATS_SchedulingHandle *sh = cls;
453
454   LOG (GNUNET_ERROR_TYPE_DEBUG,
455        "ATS connection died (code %d), reconnecting\n",
456        (int) error);
457   force_reconnect (sh);
458 }
459
460
461 /**
462  * Generate and transmit the `struct AddressAddMessage` for the given
463  * address record.
464  *
465  * @param sh the scheduling handle to use for transmission
466  * @param ar the address to inform the ATS service about
467  */
468 static void
469 send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
470                           const struct GNUNET_ATS_AddressRecord *ar)
471 {
472   struct GNUNET_MQ_Envelope *ev;
473   struct AddressAddMessage *m;
474   char *pm;
475   size_t namelen;
476   size_t msize;
477
478   if (NULL == sh->mq)
479     return; /* disconnected, skip for now */
480   GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ar->properties.scope);
481   namelen = strlen (ar->address->transport_name) + 1;
482   msize = ar->address->address_length + namelen;
483   ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
484   m->peer = ar->address->peer;
485   m->address_length = htons (ar->address->address_length);
486   m->address_local_info = htonl ((uint32_t) ar->address->local_info);
487   m->plugin_name_length = htons (namelen);
488   m->session_id = htonl (ar->slot);
489   m->properties = ar->properties;
490
491   LOG (GNUNET_ERROR_TYPE_DEBUG,
492        "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
493        GNUNET_i2s (&ar->address->peer),
494        ar->address->transport_name,
495        ar->session,
496        ar->slot);
497   pm = (char *) &m[1];
498   memcpy (pm,
499           ar->address->address,
500           ar->address->address_length);
501   if (NULL != ar->address->transport_name)
502     memcpy (&pm[ar->address->address_length],
503             ar->address->transport_name,
504             namelen);
505   GNUNET_MQ_send (sh->mq, ev);
506 }
507
508
509 /**
510  * Re-establish the connection to the ATS service.
511  *
512  * @param sh handle to use to re-connect.
513  */
514 static void
515 reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
516 {
517   GNUNET_MQ_hd_fixed_size (ats_session_release,
518                            GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
519                            struct GNUNET_ATS_SessionReleaseMessage);
520   GNUNET_MQ_hd_fixed_size (ats_address_suggestion,
521                            GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
522                            struct AddressSuggestionMessage);
523   struct GNUNET_MQ_MessageHandler handlers[] = {
524     make_ats_session_release_handler (sh),
525     make_ats_address_suggestion_handler (sh),
526     GNUNET_MQ_handler_end ()
527   };
528   struct GNUNET_MQ_Envelope *ev;
529   struct ClientStartMessage *init;
530   unsigned int i;
531   struct GNUNET_ATS_AddressRecord *ar;
532   struct GNUNET_CLIENT_Connection *client;
533
534   GNUNET_assert (NULL == sh->mq);
535   client = GNUNET_CLIENT_connect ("ats",
536                                   sh->cfg);
537   if (NULL == client)
538   {
539     GNUNET_break (0);
540     force_reconnect (sh);
541     return;
542   }
543   sh->mq = GNUNET_MQ_queue_for_connection_client (client,
544                                                   handlers,
545                                                   &error_handler,
546                                                   sh);
547   ev = GNUNET_MQ_msg (init,
548                       GNUNET_MESSAGE_TYPE_ATS_START);
549   init->start_flag = htonl (START_FLAG_SCHEDULING);
550   GNUNET_MQ_send (sh->mq, ev);
551   if (NULL == sh->mq)
552     return;
553   for (i=0;i<sh->session_array_size;i++)
554   {
555     ar = sh->session_array[i];
556     if (NULL == ar)
557       continue;
558     send_add_address_message (sh, ar);
559     if (NULL == sh->mq)
560       return;
561   }
562 }
563
564
565 /**
566  * Initialize the ATS subsystem.
567  *
568  * @param cfg configuration to use
569  * @param suggest_cb notification to call whenever the suggestation changed
570  * @param suggest_cb_cls closure for @a suggest_cb
571  * @return ats context
572  */
573 struct GNUNET_ATS_SchedulingHandle *
574 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
575                             GNUNET_ATS_AddressSuggestionCallback suggest_cb,
576                             void *suggest_cb_cls)
577 {
578   struct GNUNET_ATS_SchedulingHandle *sh;
579
580   sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle);
581   sh->cfg = cfg;
582   sh->suggest_cb = suggest_cb;
583   sh->suggest_cb_cls = suggest_cb_cls;
584   GNUNET_array_grow (sh->session_array,
585                      sh->session_array_size,
586                      4);
587   reconnect (sh);
588   return sh;
589 }
590
591
592 /**
593  * Client is done with ATS scheduling, release resources.
594  *
595  * @param sh handle to release
596  */
597 void
598 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
599 {
600   struct GNUNET_ATS_AddressRecord *ar;
601   unsigned int i;
602
603   if (NULL != sh->mq)
604   {
605     GNUNET_MQ_destroy (sh->mq);
606     sh->mq = NULL;
607   }
608   if (NULL != sh->task)
609   {
610     GNUNET_SCHEDULER_cancel (sh->task);
611     sh->task = NULL;
612   }
613   for (i=0;i<sh->session_array_size;i++)
614   {
615     if (NULL != (ar = sh->session_array[i]))
616     {
617       GNUNET_HELLO_address_free (ar->address);
618       GNUNET_free (ar);
619       sh->session_array[i] = NULL;
620     }
621   }
622   GNUNET_array_grow (sh->session_array,
623                      sh->session_array_size,
624                      0);
625   GNUNET_free (sh);
626 }
627
628
629 /**
630  * We have a new address ATS should know. Addresses have to be added
631  * with this function before they can be: updated, set in use and
632  * destroyed.
633  *
634  * @param sh handle
635  * @param address the address
636  * @param session session handle, can be NULL
637  * @param prop performance data for the address
638  * @return handle to the address representation inside ATS, NULL
639  *         on error (i.e. ATS knows this exact address already)
640  */
641 struct GNUNET_ATS_AddressRecord *
642 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
643                         const struct GNUNET_HELLO_Address *address,
644                         struct GNUNET_ATS_Session *session,
645                         const struct GNUNET_ATS_Properties *prop)
646 {
647   struct GNUNET_ATS_AddressRecord *ar;
648   size_t namelen;
649   size_t msize;
650   uint32_t s;
651
652   if (NULL == address)
653   {
654     /* we need a valid address */
655     GNUNET_break (0);
656     return NULL;
657   }
658   GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
659   namelen = strlen (address->transport_name) + 1;
660   msize = address->address_length + namelen;
661   if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
662       (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
663       (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
664   {
665     /* address too large for us, this should not happen */
666     GNUNET_break (0);
667     return NULL;
668   }
669
670   if (NOT_FOUND !=
671       find_session_id (sh,
672                        session,
673                        address))
674   {
675     /* Already existing, nothing todo, but this should not happen */
676     GNUNET_break (0);
677     return NULL;
678   }
679   s = find_empty_session_slot (sh);
680   ar = GNUNET_new (struct GNUNET_ATS_AddressRecord);
681   ar->sh = sh;
682   ar->slot = s;
683   ar->session = session;
684   ar->address = GNUNET_HELLO_address_copy (address);
685   GNUNET_ATS_properties_hton (&ar->properties,
686                               prop);
687   sh->session_array[s] = ar;
688   send_add_address_message (sh, ar);
689   return ar;
690 }
691
692
693 /**
694  * An address was used to initiate a session.
695  *
696  * @param ar address record to update information for
697  * @param session session handle
698  */
699 void
700 GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
701                                 struct GNUNET_ATS_Session *session)
702 {
703   GNUNET_break (NULL == ar->session);
704   ar->session = session;
705 }
706
707
708 /**
709  * A session was destroyed, disassociate it from the
710  * given address record.  If this was an incoming
711  * addess, destroy the address as well.
712  *
713  * @param ar address record to update information for
714  * @param session session handle
715  * @return #GNUNET_YES if the @a ar was destroyed because
716  *                     it was an incoming address,
717  *         #GNUNET_NO if the @ar was kept because we can
718  *                    use it still to establish a new session
719  */
720 int
721 GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
722                                 struct GNUNET_ATS_Session *session)
723 {
724   GNUNET_assert (session == ar->session);
725   ar->session = NULL;
726   if (GNUNET_HELLO_address_check_option (ar->address,
727                                          GNUNET_HELLO_ADDRESS_INFO_INBOUND))
728   {
729     GNUNET_ATS_address_destroy (ar);
730     return GNUNET_YES;
731   }
732   return GNUNET_NO;
733 }
734
735
736 /**
737  * We have updated performance statistics for a given address.  Note
738  * that this function can be called for addresses that are currently
739  * in use as well as addresses that are valid but not actively in use.
740  * Furthermore, the peer may not even be connected to us right now (in
741  * which case the call may be ignored or the information may be stored
742  * for later use).  Update bandwidth assignments.
743  *
744  * @param ar address record to update information for
745  * @param prop performance data for the address
746  */
747 void
748 GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
749                            const struct GNUNET_ATS_Properties *prop)
750 {
751   struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
752   struct GNUNET_MQ_Envelope *ev;
753   struct AddressUpdateMessage *m;
754
755   LOG (GNUNET_ERROR_TYPE_DEBUG,
756        "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
757        GNUNET_i2s (&ar->address->peer),
758        ar->address->transport_name,
759        ar->session,
760        ar->slot);
761   GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
762   GNUNET_ATS_properties_hton (&ar->properties,
763                               prop);
764   if (NULL == sh->mq)
765     return; /* disconnected, skip for now */
766   ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
767   m->session_id = htonl (ar->slot);
768   m->peer = ar->address->peer;
769   m->properties = ar->properties;
770   GNUNET_MQ_send (sh->mq,
771                   ev);
772 }
773
774
775 /**
776  * An address got destroyed, stop using it as a valid address.
777  *
778  * @param ar address to destroy
779  */
780 void
781 GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
782 {
783   struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
784   struct GNUNET_MQ_Envelope *ev;
785   struct AddressDestroyedMessage *m;
786
787   LOG (GNUNET_ERROR_TYPE_DEBUG,
788        "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
789        GNUNET_i2s (&ar->address->peer),
790        ar->address->transport_name,
791        ar->slot,
792        ar->session);
793   GNUNET_break (NULL == ar->session);
794   ar->session = NULL;
795   ar->in_destroy = GNUNET_YES;
796   if (NULL == sh->mq)
797     return;
798   ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
799   m->session_id = htonl (ar->slot);
800   m->peer = ar->address->peer;
801   GNUNET_MQ_send (sh->mq, ev);
802 }
803
804
805 /* end of ats_api_scheduling.c */