955b21286f435f9227903fc6e435290252d231cc
[oweals/gnunet.git] / src / ats / ats_api_scheduling.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_scheduling.c
22  * @brief automatic transport selection and outbound bandwidth determination
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_ats_service.h"
28 #include "ats.h"
29
30
31 /**
32  * Message in linked list we should send to the ATS service.  The
33  * actual binary message follows this struct.
34  */
35 struct PendingMessage
36 {
37
38   /**
39    * Kept in a DLL.
40    */ 
41   struct PendingMessage *next;
42
43   /**
44    * Kept in a DLL.
45    */ 
46   struct PendingMessage *prev;
47
48   /**
49    * Size of the message.
50    */
51   size_t size;
52
53   /**
54    * Is this the 'ATS_START' message?
55    */ 
56   int is_init;
57 };
58
59
60 /**
61  * Information we track per session.
62  */
63 struct SessionRecord
64 {
65   /**
66    * Identity of the peer (just needed for error checking).
67    */
68   struct GNUNET_PeerIdentity peer;
69
70   /**
71    * Session handle.
72    */
73   struct Session *session;
74
75   /**
76    * Set to GNUNET_YES if the slot is used.
77    */
78   int slot_used;
79 };
80
81
82 /**
83  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
84  */
85 struct GNUNET_ATS_SchedulingHandle
86 {
87   
88   /**
89    * Our configuration.
90    */
91   const struct GNUNET_CONFIGURATION_Handle *cfg;
92
93   /**
94    * Callback to invoke on suggestions.
95    */
96   GNUNET_ATS_AddressSuggestionCallback suggest_cb;
97   
98   /**
99    * Closure for 'suggest_cb'.
100    */
101   void *suggest_cb_cls;
102
103   /**
104    * Connection to ATS service.
105    */
106   struct GNUNET_CLIENT_Connection *client;
107
108   /**
109    * Head of list of messages for the ATS service.
110    */
111   struct PendingMessage *pending_head;
112
113   /**
114    * Tail of list of messages for the ATS service
115    */
116   struct PendingMessage *pending_tail;
117
118   /**
119    * Current request for transmission to ATS.
120    */
121   struct GNUNET_CLIENT_TransmitHandle *th;
122
123   /**
124    * Array of session objects (we need to translate them to numbers and back
125    * for the protocol; the offset in the array is the session number on the
126    * network).  Index 0 is always NULL and reserved to represent the NULL pointer.
127    * Unused entries are also NULL.
128    */
129   struct SessionRecord *session_array;
130
131   /**
132    * Task to trigger reconnect.
133    */ 
134   GNUNET_SCHEDULER_TaskIdentifier task;
135   
136   /**
137    * Size of the session array.
138    */
139   unsigned int session_array_size;
140
141 };
142
143
144 /**
145  * Re-establish the connection to the ATS service.
146  *
147  * @param sh handle to use to re-connect.
148  */
149 static void
150 reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
151
152
153
154 /**
155  * Re-establish the connection to the ATS service.
156  *
157  * @param cls handle to use to re-connect.
158  * @param tc scheduler context
159  */
160 static void
161 reconnect_task (void *cls,
162                 const struct GNUNET_SCHEDULER_TaskContext *tc)
163 {
164   struct GNUNET_ATS_SchedulingHandle *sh = cls;
165
166   sh->task = GNUNET_SCHEDULER_NO_TASK;
167   reconnect (sh);
168 }
169
170
171 /**
172  * Transmit messages from the message queue to the service
173  * (if there are any, and if we are not already trying).
174  *
175  * @param sh handle to use
176  */
177 static void
178 do_transmit (struct GNUNET_ATS_SchedulingHandle *sh);
179
180
181 /**
182  * Type of a function to call when we receive a message
183  * from the service.
184  *
185  * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
186  * @param msg message received, NULL on timeout or fatal error
187  */
188 static void
189 process_ats_message (void *cls,
190                      const struct GNUNET_MessageHeader *msg);
191
192
193 /**
194  * We can now transmit a message to ATS. Do it.
195  *
196  * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
197  * @param size number of bytes we can transmit to ATS
198  * @param buf where to copy the messages
199  * @return number of bytes copied into buf
200  */
201 static size_t
202 transmit_message_to_ats (void *cls,
203                          size_t size,
204                          void *buf)
205 {
206   struct GNUNET_ATS_SchedulingHandle *sh = cls;
207   struct PendingMessage *p;
208   size_t ret;
209   char *cbuf;
210
211   sh->th = NULL;
212   ret = 0;
213   cbuf = buf;
214   while ( (NULL != (p = sh->pending_head)) &&
215           (p->size <= size) )
216   {
217     memcpy (&cbuf[ret], &p[1], p->size);    
218     ret += p->size;
219     size -= p->size;
220     GNUNET_CONTAINER_DLL_remove (sh->pending_head,
221                                  sh->pending_tail,
222                                  p);
223     if (GNUNET_YES == p->is_init)
224       GNUNET_CLIENT_receive (sh->client,
225                              &process_ats_message, sh,
226                              GNUNET_TIME_UNIT_FOREVER_REL);
227     GNUNET_free (p);
228   }
229   do_transmit (sh);
230   return ret;
231 }
232
233
234 /**
235  * Transmit messages from the message queue to the service
236  * (if there are any, and if we are not already trying).
237  *
238  * @param sh handle to use
239  */
240 static void
241 do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
242 {
243   struct PendingMessage *p;
244
245   if (NULL != sh->th)
246     return;
247   if (NULL == (p = sh->pending_head))
248     return;
249   if (NULL == sh->client)
250     return; /* currently reconnecting */
251   sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client,
252                                                 p->size,
253                                                 GNUNET_TIME_UNIT_FOREVER_REL,
254                                                 GNUNET_YES,
255                                                 &transmit_message_to_ats, sh);
256 }
257
258
259 /**
260  * Find the session object corresponding to the given session ID.
261  *
262  * @param sh our handle
263  * @param session_id current session ID
264  * @param peer peer the session belongs to
265  * @return the session object (or NULL)
266  */
267 static struct Session*
268 find_session (struct GNUNET_ATS_SchedulingHandle *sh,
269               uint32_t session_id,
270               const struct GNUNET_PeerIdentity *peer)
271 {
272   if (session_id >= sh->session_array_size)
273   {
274     GNUNET_break (0);
275     return NULL;
276   }
277   if (session_id == 0)
278     return NULL;
279   GNUNET_assert (0 == memcmp (peer,
280                               &sh->session_array[session_id].peer,
281                               sizeof (struct GNUNET_PeerIdentity)));
282   return sh->session_array[session_id].session;
283 }
284
285
286 /**
287  * Get the ID for the given session object.  If we do not have an ID for
288  * the given session object, allocate one.
289  *
290  * @param sh our handle
291  * @param session session object
292  * @param peer peer the session belongs to
293  * @return the session id
294  */
295 static uint32_t 
296 get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
297                 struct Session *session,
298                 const struct GNUNET_PeerIdentity *peer)
299 {
300   unsigned int i;
301   unsigned int f;
302   
303   if (NULL == session)
304     return 0;
305   f = 0;
306   for (i=1;i<sh->session_array_size;i++)
307   {
308     if (session == sh->session_array[i].session)
309     {
310       GNUNET_assert (0 == memcmp (peer,
311                                   &sh->session_array[i].peer,
312                                   sizeof (struct GNUNET_PeerIdentity)));
313       return i;
314     }
315     if ( (f == 0) &&
316          (sh->session_array[i].slot_used == GNUNET_NO) )
317       f = i;
318   }
319   if (f == 0)
320   {    
321     f = sh->session_array_size;
322     GNUNET_array_grow (sh->session_array,
323                        sh->session_array_size,
324                        sh->session_array_size * 2);
325   }
326   GNUNET_assert (f > 0);
327   sh->session_array[f].session = session;
328   sh->session_array[f].peer = *peer;
329   sh->session_array[f].slot_used = GNUNET_YES;
330   return f;
331 }
332
333
334 /**
335  * Remove the session of the given session ID from the session
336  * table (it is no longer valid).
337  *
338  * @param sh our handle
339  * @param session_id identifies session that is no longer valid
340  * @param peer peer the session belongs to
341  */
342 static void
343 remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
344                 uint32_t session_id,
345                 const struct GNUNET_PeerIdentity *peer)
346 {
347   GNUNET_assert (session_id < sh->session_array_size);
348   GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
349   GNUNET_assert (0 == memcmp (peer,
350                               &sh->session_array[session_id].peer,
351                               sizeof (struct GNUNET_PeerIdentity)));
352   sh->session_array[session_id].session = NULL;
353 }
354
355
356 /**
357  * Release the session slot from the session table (ATS service is
358  * also done using it).
359  *
360  * @param sh our handle
361  * @param session_id identifies session that is no longer valid
362  * @param peer peer the session belongs to
363  */
364 static void
365 release_session (struct GNUNET_ATS_SchedulingHandle *sh,
366                  uint32_t session_id,
367                  const struct GNUNET_PeerIdentity *peer)
368 {
369   GNUNET_assert (session_id < sh->session_array_size);
370   GNUNET_assert (0 == memcmp (peer,
371                               &sh->session_array[session_id].peer,
372                               sizeof (struct GNUNET_PeerIdentity)));
373   sh->session_array[session_id].slot_used = GNUNET_NO;
374   memset (&sh->session_array[session_id].peer,
375           0, 
376           sizeof (struct GNUNET_PeerIdentity));
377 }
378
379
380 static void
381 process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
382                          const struct SessionReleaseMessage *srm)
383 {
384   release_session (sh,
385                    ntohl (srm->session_id),
386                    &srm->peer);
387 }
388
389
390 /**
391  * Type of a function to call when we receive a message
392  * from the service.
393  *
394  * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
395  * @param msg message received, NULL on timeout or fatal error
396  */
397 static void
398 process_ats_message (void *cls,
399                      const struct GNUNET_MessageHeader *msg)
400 {
401   struct GNUNET_ATS_SchedulingHandle *sh = cls;
402   const struct AddressSuggestionMessage *m;
403   const struct GNUNET_ATS_Information *atsi;
404   const char *address;
405   const char *plugin_name;
406   uint16_t address_length;
407   uint16_t plugin_name_length;
408   uint32_t ats_count;
409
410   if (NULL == msg) 
411   {
412     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
413     sh->client = NULL;
414     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
415                                              &reconnect_task, sh);
416     return;
417   }
418   if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
419        (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) )
420   {
421     process_release_message (sh,
422                              (const struct SessionReleaseMessage*) msg);
423     GNUNET_CLIENT_receive (sh->client,
424                            &process_ats_message, sh,
425                            GNUNET_TIME_UNIT_FOREVER_REL);
426     return;
427   }
428   if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
429        (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) )
430   {
431     GNUNET_break (0);
432     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
433     sh->client = NULL;
434     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
435                                              &reconnect_task, sh);
436     return;
437   }
438   m = (const struct AddressSuggestionMessage*) msg;
439   ats_count = ntohl (m->ats_count);
440   address_length = ntohs (m->address_length);
441   atsi = (const struct GNUNET_ATS_Information*) &m[1];
442   address = (const char*) &atsi[ats_count];
443   plugin_name = &address[address_length];
444   plugin_name_length = ntohs (m->plugin_name_length);
445   if ( (address_length +
446         plugin_name_length +
447         ats_count * sizeof (struct GNUNET_ATS_Information) +
448         sizeof (struct AddressSuggestionMessage) != ntohs (msg->size))  ||
449        (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ||
450        (plugin_name[plugin_name_length - 1] != '\0') )
451   {
452     GNUNET_break (0);
453     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
454     sh->client = NULL;
455     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
456                                              &reconnect_task, sh);
457     return;
458   }
459   sh->suggest_cb (sh->suggest_cb_cls,
460                   &m->peer,
461                   plugin_name,
462                   address, address_length,
463                   find_session (sh, ntohl (m->session_id), &m->peer),
464                   m->bandwidth_out,
465                   m->bandwidth_in,
466                   atsi,
467                   ats_count);
468   GNUNET_CLIENT_receive (sh->client,
469                          &process_ats_message, sh,
470                          GNUNET_TIME_UNIT_FOREVER_REL);
471 }
472
473
474 /**
475  * Re-establish the connection to the ATS service.
476  *
477  * @param sh handle to use to re-connect.
478  */
479 static void
480 reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
481 {
482   struct PendingMessage *p;
483   struct ClientStartMessage *init;
484
485   GNUNET_assert (NULL == sh->client);
486   sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
487   GNUNET_assert (NULL != sh->client);
488   if ( (NULL == (p = sh->pending_head)) ||
489        (GNUNET_YES != p->is_init) )
490   {
491     p = GNUNET_malloc (sizeof (struct PendingMessage) +
492                        sizeof (struct ClientStartMessage));
493     p->size = sizeof (struct ClientStartMessage);
494     p->is_init = GNUNET_YES;
495     init = (struct ClientStartMessage *) &p[1];
496     init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
497     init->header.size = htons (sizeof (struct ClientStartMessage));
498     init->start_flag = htonl (START_FLAG_SCHEDULING);
499     GNUNET_CONTAINER_DLL_insert (sh->pending_head,
500                                  sh->pending_tail,
501                                  p);
502   }
503   do_transmit (sh);
504 }
505
506
507 /**
508  * Initialize the ATS subsystem.
509  *
510  * @param cfg configuration to use
511  * @param suggest_cb notification to call whenever the suggestation changed
512  * @param suggest_cb_cls closure for 'suggest_cb'
513  * @return ats context
514  */
515 struct GNUNET_ATS_SchedulingHandle *
516 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
517                             GNUNET_ATS_AddressSuggestionCallback suggest_cb,
518                             void *suggest_cb_cls)
519 {
520   struct GNUNET_ATS_SchedulingHandle *sh;
521
522   sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SchedulingHandle));
523   sh->cfg = cfg;
524   sh->suggest_cb = suggest_cb;
525   sh->suggest_cb_cls = suggest_cb_cls;
526   GNUNET_array_grow (sh->session_array,
527                      sh->session_array_size,
528                      4);
529   reconnect (sh);
530   return sh;
531 }
532
533
534 /**
535  * Client is done with ATS scheduling, release resources.
536  *
537  * @param sh handle to release
538  */
539 void
540 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
541 {
542   struct PendingMessage *p;
543
544   while (NULL != (p = sh->pending_head))
545   {
546     GNUNET_CONTAINER_DLL_remove (sh->pending_head,
547                                  sh->pending_tail,
548                                  p);
549     GNUNET_free (p);
550   }
551   if (NULL != sh->client)
552   {
553     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
554     sh->client = NULL;
555   }
556   if (GNUNET_SCHEDULER_NO_TASK != sh->task)
557   {
558     GNUNET_SCHEDULER_cancel (sh->task);
559     sh->task = GNUNET_SCHEDULER_NO_TASK;
560   }
561   GNUNET_array_grow (sh->session_array,
562                      sh->session_array_size,
563                      0);
564   GNUNET_free (sh);
565 }
566
567
568 /**
569  * We would like to establish a new connection with a peer.  ATS
570  * should suggest a good address to begin with.
571  *
572  * @param sh handle
573  * @param peer identity of the peer we need an address for
574  */
575 void
576 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
577                             const struct GNUNET_PeerIdentity *peer)
578 {
579   struct PendingMessage *p;
580   struct RequestAddressMessage *m;
581
582   p = GNUNET_malloc (sizeof (struct PendingMessage) +
583                      sizeof (struct RequestAddressMessage));
584   p->size = sizeof (struct RequestAddressMessage);
585   p->is_init = GNUNET_NO;
586   m = (struct RequestAddressMessage*) &p[1];
587   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
588   m->header.size = htons (sizeof (struct RequestAddressMessage));
589   m->reserved = htonl (0);
590   m->peer = *peer;
591   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
592                                     sh->pending_tail,
593                                     p);
594   do_transmit (sh);
595 }
596
597
598 /**
599  * We have updated performance statistics for a given address.  Note
600  * that this function can be called for addresses that are currently
601  * in use as well as addresses that are valid but not actively in use.
602  * Furthermore, the peer may not even be connected to us right now (in
603  * which case the call may be ignored or the information may be stored
604  * for later use).  Update bandwidth assignments.
605  *
606  * @param sh handle
607  * @param peer identity of the new peer
608  * @param plugin_name name of the transport plugin
609  * @param plugin_addr address  (if available)
610  * @param plugin_addr_len number of bytes in plugin_addr
611  * @param session session handle (if available)
612  * @param ats performance data for the address
613  * @param ats_count number of performance records in 'ats'
614  */
615 void
616 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
617                            const struct GNUNET_PeerIdentity *peer,
618                            const char *plugin_name,
619                            const void *plugin_addr, size_t plugin_addr_len,
620                            struct Session *session,
621                            const struct GNUNET_ATS_Information *ats,
622                            uint32_t ats_count)
623 {
624   struct PendingMessage *p;
625   struct AddressUpdateMessage *m;
626   struct GNUNET_ATS_Information *am;
627   char *pm;
628   size_t namelen;
629   size_t msize;
630
631   namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;                                               
632   msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + 
633     ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
634   if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
635        (plugin_addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
636        (namelen  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
637        (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) )
638   {
639     GNUNET_break (0);
640     return;
641   }
642   p = GNUNET_malloc (sizeof (struct PendingMessage) +  msize);
643   p->size = msize;
644   p->is_init = GNUNET_NO;
645   m = (struct AddressUpdateMessage*) &p[1];
646   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
647   m->header.size = htons (msize);
648   m->ats_count = htonl (ats_count);
649   m->peer = *peer;
650   m->address_length = htons (plugin_addr_len);
651   m->plugin_name_length = htons (namelen);
652   m->session_id = htonl (get_session_id (sh, session, peer));
653   am = (struct GNUNET_ATS_Information*) &m[1];
654   memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
655   pm = (char *) &am[ats_count];
656   memcpy (pm, plugin_addr, plugin_addr_len);
657   memcpy (&pm[plugin_addr_len], plugin_name, namelen);
658   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
659                                     sh->pending_tail,
660                                     p);
661   do_transmit (sh);
662 }
663
664
665 /**
666  * A session got destroyed, stop including it as a valid address.
667  *
668  * @param sh handle
669  * @param peer identity of the peer
670  * @param plugin_name name of the transport plugin
671  * @param plugin_addr address  (if available)
672  * @param plugin_addr_len number of bytes in plugin_addr
673  * @param session session handle that is no longer valid
674  */
675 void
676 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
677                               const struct GNUNET_PeerIdentity *peer,
678                               const char *plugin_name,
679                               const void *plugin_addr, 
680                               size_t plugin_addr_len,
681                               struct Session *session)
682 {
683   struct PendingMessage *p;
684   struct AddressDestroyedMessage *m;
685   char *pm;
686   size_t namelen;
687   size_t msize;
688   uint32_t session_id;
689
690   namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;                                               
691   msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + 
692     namelen;
693   if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
694        (plugin_addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
695        (namelen  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
696   {
697     GNUNET_break (0);
698     return;
699   }
700   p = GNUNET_malloc (sizeof (struct PendingMessage) +  msize);
701   p->size = msize;
702   p->is_init = GNUNET_NO;
703   m = (struct AddressDestroyedMessage*) &p[1];
704   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
705   m->header.size = htons (msize);
706   m->reserved = htonl (0);
707   m->peer = *peer;
708   m->address_length = htons (plugin_addr_len);
709   m->plugin_name_length = htons (namelen);
710   m->session_id = htonl (session_id = get_session_id (sh, session, peer));
711   pm = (char *) &m[1];
712   memcpy (pm, plugin_addr, plugin_addr_len);
713   memcpy (&pm[plugin_addr_len], plugin_name, namelen);
714   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
715                                     sh->pending_tail,
716                                     p);
717   do_transmit (sh);
718   remove_session (sh, session_id, peer);
719 }
720
721 /* end of ats_api_scheduling.c */