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