fixing mantis #18773
[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   if ( (size == 0) || (buf == NULL))
213   {
214     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
215     sh->client = NULL;
216     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
217                                              &reconnect_task, sh);
218     return 0;
219   }
220   ret = 0;
221   cbuf = buf;
222   while ( (NULL != (p = sh->pending_head)) &&
223           (p->size <= size) )
224   {
225     memcpy (&cbuf[ret], &p[1], p->size);    
226     ret += p->size;
227     size -= p->size;
228     GNUNET_CONTAINER_DLL_remove (sh->pending_head,
229                                  sh->pending_tail,
230                                  p);
231     if (GNUNET_YES == p->is_init)
232       GNUNET_CLIENT_receive (sh->client,
233                              &process_ats_message, sh,
234                              GNUNET_TIME_UNIT_FOREVER_REL);
235     GNUNET_free (p);
236   }
237   do_transmit (sh);
238   return ret;
239 }
240
241
242 /**
243  * Transmit messages from the message queue to the service
244  * (if there are any, and if we are not already trying).
245  *
246  * @param sh handle to use
247  */
248 static void
249 do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
250 {
251   struct PendingMessage *p;
252
253   if (NULL != sh->th)
254     return;
255   if (NULL == (p = sh->pending_head))
256     return;
257   if (NULL == sh->client)
258     return; /* currently reconnecting */
259   sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client,
260                                                 p->size,
261                                                 GNUNET_TIME_UNIT_FOREVER_REL,
262                                                 GNUNET_NO,
263                                                 &transmit_message_to_ats, sh);
264 }
265
266
267 /**
268  * Find the session object corresponding to the given session ID.
269  *
270  * @param sh our handle
271  * @param session_id current session ID
272  * @param peer peer the session belongs to
273  * @return the session object (or NULL)
274  */
275 static struct Session*
276 find_session (struct GNUNET_ATS_SchedulingHandle *sh,
277               uint32_t session_id,
278               const struct GNUNET_PeerIdentity *peer)
279 {
280   if (session_id >= sh->session_array_size)
281   {
282     GNUNET_break (0);
283     return NULL;
284   }
285   if (session_id == 0)
286     return NULL;
287   GNUNET_assert (0 == memcmp (peer,
288                               &sh->session_array[session_id].peer,
289                               sizeof (struct GNUNET_PeerIdentity)));
290   return sh->session_array[session_id].session;
291 }
292
293
294 /**
295  * Get the ID for the given session object.  If we do not have an ID for
296  * the given session object, allocate one.
297  *
298  * @param sh our handle
299  * @param session session object
300  * @param peer peer the session belongs to
301  * @return the session id
302  */
303 static uint32_t 
304 get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
305                 struct Session *session,
306                 const struct GNUNET_PeerIdentity *peer)
307 {
308   unsigned int i;
309   unsigned int f;
310   
311   if (NULL == session)
312     return 0;
313   f = 0;
314   for (i=1;i<sh->session_array_size;i++)
315   {
316     if (session == sh->session_array[i].session)
317     {
318       GNUNET_assert (0 == memcmp (peer,
319                                   &sh->session_array[i].peer,
320                                   sizeof (struct GNUNET_PeerIdentity)));
321       return i;
322     }
323     if ( (f == 0) &&
324          (sh->session_array[i].slot_used == GNUNET_NO) )
325       f = i;
326   }
327   if (f == 0)
328   {    
329     f = sh->session_array_size;
330     GNUNET_array_grow (sh->session_array,
331                        sh->session_array_size,
332                        sh->session_array_size * 2);
333   }
334   GNUNET_assert (f > 0);
335   sh->session_array[f].session = session;
336   sh->session_array[f].peer = *peer;
337   sh->session_array[f].slot_used = GNUNET_YES;
338   return f;
339 }
340
341
342 /**
343  * Remove the session of the given session ID from the session
344  * table (it is no longer valid).
345  *
346  * @param sh our handle
347  * @param session_id identifies session that is no longer valid
348  * @param peer peer the session belongs to
349  */
350 static void
351 remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
352                 uint32_t session_id,
353                 const struct GNUNET_PeerIdentity *peer)
354 {
355   if (0 == session_id)
356     return;
357   GNUNET_assert (session_id < sh->session_array_size);
358   GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
359   GNUNET_assert (0 == memcmp (peer,
360                               &sh->session_array[session_id].peer,
361                               sizeof (struct GNUNET_PeerIdentity)));
362   sh->session_array[session_id].session = NULL;
363 }
364
365
366 /**
367  * Release the session slot from the session table (ATS service is
368  * also done using it).
369  *
370  * @param sh our handle
371  * @param session_id identifies session that is no longer valid
372  * @param peer peer the session belongs to
373  */
374 static void
375 release_session (struct GNUNET_ATS_SchedulingHandle *sh,
376                  uint32_t session_id,
377                  const struct GNUNET_PeerIdentity *peer)
378 {
379   GNUNET_assert (session_id < sh->session_array_size);
380   GNUNET_assert (0 == memcmp (peer,
381                               &sh->session_array[session_id].peer,
382                               sizeof (struct GNUNET_PeerIdentity)));
383   sh->session_array[session_id].slot_used = GNUNET_NO;
384   memset (&sh->session_array[session_id].peer,
385           0, 
386           sizeof (struct GNUNET_PeerIdentity));
387 }
388
389
390 static void
391 process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
392                          const struct SessionReleaseMessage *srm)
393 {
394   release_session (sh,
395                    ntohl (srm->session_id),
396                    &srm->peer);
397 }
398
399
400 /**
401  * Type of a function to call when we receive a message
402  * from the service.
403  *
404  * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
405  * @param msg message received, NULL on timeout or fatal error
406  */
407 static void
408 process_ats_message (void *cls,
409                      const struct GNUNET_MessageHeader *msg)
410 {
411   struct GNUNET_ATS_SchedulingHandle *sh = cls;
412   const struct AddressSuggestionMessage *m;
413   const struct GNUNET_ATS_Information *atsi;
414   const char *address;
415   const char *plugin_name;
416   uint16_t address_length;
417   uint16_t plugin_name_length;
418   uint32_t ats_count;
419
420   if (NULL == msg) 
421   {
422     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
423     sh->client = NULL;
424     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
425                                              &reconnect_task, sh);
426     return;
427   }
428   if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
429        (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) )
430   {
431     process_release_message (sh,
432                              (const struct SessionReleaseMessage*) msg);
433     GNUNET_CLIENT_receive (sh->client,
434                            &process_ats_message, sh,
435                            GNUNET_TIME_UNIT_FOREVER_REL);
436     return;
437   }
438   if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
439        (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) )
440   {
441     GNUNET_break (0);
442     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
443     sh->client = NULL;
444     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
445                                              &reconnect_task, sh);
446     return;
447   }
448   m = (const struct AddressSuggestionMessage*) msg;
449   ats_count = ntohl (m->ats_count);
450   address_length = ntohs (m->address_length);
451   atsi = (const struct GNUNET_ATS_Information*) &m[1];
452   address = (const char*) &atsi[ats_count];
453   plugin_name = &address[address_length];
454   plugin_name_length = ntohs (m->plugin_name_length);
455   if ( (address_length +
456         plugin_name_length +
457         ats_count * sizeof (struct GNUNET_ATS_Information) +
458         sizeof (struct AddressSuggestionMessage) != ntohs (msg->size))  ||
459        (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ||
460        (plugin_name[plugin_name_length - 1] != '\0') )
461   {
462     GNUNET_break (0);
463     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
464     sh->client = NULL;
465     sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
466                                              &reconnect_task, sh);
467     return;
468   }
469   sh->suggest_cb (sh->suggest_cb_cls,
470                   &m->peer,
471                   plugin_name,
472                   address, address_length,
473                   find_session (sh, ntohl (m->session_id), &m->peer),
474                   m->bandwidth_out,
475                   m->bandwidth_in,
476                   atsi,
477                   ats_count);
478   GNUNET_CLIENT_receive (sh->client,
479                          &process_ats_message, sh,
480                          GNUNET_TIME_UNIT_FOREVER_REL);
481 }
482
483
484 /**
485  * Re-establish the connection to the ATS service.
486  *
487  * @param sh handle to use to re-connect.
488  */
489 static void
490 reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
491 {
492   struct PendingMessage *p;
493   struct ClientStartMessage *init;
494
495   GNUNET_assert (NULL == sh->client);
496   sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
497   GNUNET_assert (NULL != sh->client);
498   if ( (NULL == (p = sh->pending_head)) ||
499        (GNUNET_YES != p->is_init) )
500   {
501     p = GNUNET_malloc (sizeof (struct PendingMessage) +
502                        sizeof (struct ClientStartMessage));
503     p->size = sizeof (struct ClientStartMessage);
504     p->is_init = GNUNET_YES;
505     init = (struct ClientStartMessage *) &p[1];
506     init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
507     init->header.size = htons (sizeof (struct ClientStartMessage));
508     init->start_flag = htonl (START_FLAG_SCHEDULING);
509     GNUNET_CONTAINER_DLL_insert (sh->pending_head,
510                                  sh->pending_tail,
511                                  p);
512   }
513   do_transmit (sh);
514 }
515
516
517 /**
518  * Initialize the ATS subsystem.
519  *
520  * @param cfg configuration to use
521  * @param suggest_cb notification to call whenever the suggestation changed
522  * @param suggest_cb_cls closure for 'suggest_cb'
523  * @return ats context
524  */
525 struct GNUNET_ATS_SchedulingHandle *
526 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
527                             GNUNET_ATS_AddressSuggestionCallback suggest_cb,
528                             void *suggest_cb_cls)
529 {
530   struct GNUNET_ATS_SchedulingHandle *sh;
531
532   sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SchedulingHandle));
533   sh->cfg = cfg;
534   sh->suggest_cb = suggest_cb;
535   sh->suggest_cb_cls = suggest_cb_cls;
536   GNUNET_array_grow (sh->session_array,
537                      sh->session_array_size,
538                      4);
539   reconnect (sh);
540   return sh;
541 }
542
543
544 /**
545  * Client is done with ATS scheduling, release resources.
546  *
547  * @param sh handle to release
548  */
549 void
550 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
551 {
552   struct PendingMessage *p;
553
554   while (NULL != (p = sh->pending_head))
555   {
556     GNUNET_CONTAINER_DLL_remove (sh->pending_head,
557                                  sh->pending_tail,
558                                  p);
559     GNUNET_free (p);
560   }
561   if (NULL != sh->client)
562   {
563     GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
564     sh->client = NULL;
565   }
566   if (GNUNET_SCHEDULER_NO_TASK != sh->task)
567   {
568     GNUNET_SCHEDULER_cancel (sh->task);
569     sh->task = GNUNET_SCHEDULER_NO_TASK;
570   }
571   GNUNET_array_grow (sh->session_array,
572                      sh->session_array_size,
573                      0);
574   GNUNET_free (sh);
575 }
576
577
578 /**
579  * We would like to establish a new connection with a peer.  ATS
580  * should suggest a good address to begin with.
581  *
582  * @param sh handle
583  * @param peer identity of the peer we need an address for
584  */
585 void
586 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
587                             const struct GNUNET_PeerIdentity *peer)
588 {
589   struct PendingMessage *p;
590   struct RequestAddressMessage *m;
591
592   p = GNUNET_malloc (sizeof (struct PendingMessage) +
593                      sizeof (struct RequestAddressMessage));
594   p->size = sizeof (struct RequestAddressMessage);
595   p->is_init = GNUNET_NO;
596   m = (struct RequestAddressMessage*) &p[1];
597   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
598   m->header.size = htons (sizeof (struct RequestAddressMessage));
599   m->reserved = htonl (0);
600   m->peer = *peer;
601   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
602                                     sh->pending_tail,
603                                     p);
604   do_transmit (sh);
605 }
606
607
608 /**
609  * We have updated performance statistics for a given address.  Note
610  * that this function can be called for addresses that are currently
611  * in use as well as addresses that are valid but not actively in use.
612  * Furthermore, the peer may not even be connected to us right now (in
613  * which case the call may be ignored or the information may be stored
614  * for later use).  Update bandwidth assignments.
615  *
616  * @param sh handle
617  * @param peer identity of the new peer
618  * @param plugin_name name of the transport plugin
619  * @param plugin_addr address  (if available)
620  * @param plugin_addr_len number of bytes in plugin_addr
621  * @param session session handle (if available)
622  * @param ats performance data for the address
623  * @param ats_count number of performance records in 'ats'
624  */
625 void
626 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
627                            const struct GNUNET_PeerIdentity *peer,
628                            const char *plugin_name,
629                            const void *plugin_addr, size_t plugin_addr_len,
630                            struct Session *session,
631                            const struct GNUNET_ATS_Information *ats,
632                            uint32_t ats_count)
633 {
634   struct PendingMessage *p;
635   struct AddressUpdateMessage *m;
636   struct GNUNET_ATS_Information *am;
637   char *pm;
638   size_t namelen;
639   size_t msize;
640
641   namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;                                               
642   msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + 
643     ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
644   if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
645        (plugin_addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
646        (namelen  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
647        (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) )
648   {
649     GNUNET_break (0);
650     return;
651   }
652   p = GNUNET_malloc (sizeof (struct PendingMessage) +  msize);
653   p->size = msize;
654   p->is_init = GNUNET_NO;
655   m = (struct AddressUpdateMessage*) &p[1];
656   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
657   m->header.size = htons (msize);
658   m->ats_count = htonl (ats_count);
659   m->peer = *peer;
660   m->address_length = htons (plugin_addr_len);
661   m->plugin_name_length = htons (namelen);
662   m->session_id = htonl (get_session_id (sh, session, peer));
663   am = (struct GNUNET_ATS_Information*) &m[1];
664   memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
665   pm = (char *) &am[ats_count];
666   memcpy (pm, plugin_addr, plugin_addr_len);
667   memcpy (&pm[plugin_addr_len], plugin_name, namelen);
668   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
669                                     sh->pending_tail,
670                                     p);
671   do_transmit (sh);
672 }
673
674
675 /**
676  * A session got destroyed, stop including it as a valid address.
677  *
678  * @param sh handle
679  * @param peer identity of the peer
680  * @param plugin_name name of the transport plugin
681  * @param plugin_addr address  (if available)
682  * @param plugin_addr_len number of bytes in plugin_addr
683  * @param session session handle that is no longer valid
684  */
685 void
686 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
687                               const struct GNUNET_PeerIdentity *peer,
688                               const char *plugin_name,
689                               const void *plugin_addr, 
690                               size_t plugin_addr_len,
691                               struct Session *session)
692 {
693   struct PendingMessage *p;
694   struct AddressDestroyedMessage *m;
695   char *pm;
696   size_t namelen;
697   size_t msize;
698   uint32_t session_id;
699
700   namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;                                               
701   msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + 
702     namelen;
703   if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
704        (plugin_addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
705        (namelen  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
706   {
707     GNUNET_break (0);
708     return;
709   }
710   p = GNUNET_malloc (sizeof (struct PendingMessage) +  msize);
711   p->size = msize;
712   p->is_init = GNUNET_NO;
713   m = (struct AddressDestroyedMessage*) &p[1];
714   m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
715   m->header.size = htons (msize);
716   m->reserved = htonl (0);
717   m->peer = *peer;
718   m->address_length = htons (plugin_addr_len);
719   m->plugin_name_length = htons (namelen);
720   m->session_id = htonl (session_id = get_session_id (sh, session, peer));
721   pm = (char *) &m[1];
722   memcpy (pm, plugin_addr, plugin_addr_len);
723   memcpy (&pm[plugin_addr_len], plugin_name, namelen);
724   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
725                                     sh->pending_tail,
726                                     p);
727   do_transmit (sh);
728   remove_session (sh, session_id, peer);
729 }
730
731 /* end of ats_api_scheduling.c */