-trying to fix fragmentation / udp performance, not working yet
[oweals/gnunet.git] / src / transport / plugin_transport_unix.c
1 /*
2      This file is part of GNUnet
3      (C) 2010 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 /**
22  * @file transport/plugin_transport_unix.c
23  * @brief Transport plugin using unix domain sockets (!)
24  *        Clearly, can only be used locally on Unix/Linux hosts...
25  *        ONLY INTENDED FOR TESTING!!!
26  * @author Christian Grothoff
27  * @author Nathan Evans
28  */
29
30 #include "platform.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_connection_lib.h"
33 #include "gnunet_container_lib.h"
34 #include "gnunet_os_lib.h"
35 #include "gnunet_peerinfo_service.h"
36 #include "gnunet_protocols.h"
37 #include "gnunet_resolver_service.h"
38 #include "gnunet_server_lib.h"
39 #include "gnunet_signatures.h"
40 #include "gnunet_statistics_service.h"
41 #include "gnunet_transport_service.h"
42 #include "gnunet_transport_plugin.h"
43 #include "transport.h"
44
45 #define MAX_PROBES 20
46
47 #define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__)
48
49 /*
50  * Transport cost to peer, always 1 for UNIX (direct connection)
51  */
52 #define UNIX_DIRECT_DISTANCE 1
53
54 #define DEFAULT_NAT_PORT 0
55
56 /**
57  * How long until we give up on transmitting the welcome message?
58  */
59 #define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
60
61 /**
62  * Starting port for listening and sending, eventually a config value
63  */
64 #define UNIX_NAT_DEFAULT_PORT 22086
65
66 GNUNET_NETWORK_STRUCT_BEGIN
67
68 /**
69  * UNIX Message-Packet header.
70  */
71 struct UNIXMessage
72 {
73   /**
74    * Message header.
75    */
76   struct GNUNET_MessageHeader header;
77
78   /**
79    * What is the identity of the sender (GNUNET_hash of public key)
80    */
81   struct GNUNET_PeerIdentity sender;
82
83 };
84
85 struct Session
86 {
87   struct GNUNET_PeerIdentity target;
88
89   void *addr;
90   size_t addrlen;
91
92   /**
93    * Session timeout task
94    */
95   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
96
97   struct Plugin * plugin;
98 };
99
100 struct UNIXMessageWrapper
101 {
102   struct UNIXMessageWrapper *next;
103   struct UNIXMessageWrapper *prev;
104
105   struct UNIXMessage * msg;
106   size_t msgsize;
107   size_t payload;
108
109   struct GNUNET_TIME_Relative timeout;
110   unsigned int priority;
111
112   struct Session *session;
113   GNUNET_TRANSPORT_TransmitContinuation cont;
114   void *cont_cls;
115 };
116
117 /* Forward definition */
118 struct Plugin;
119
120
121 /**
122  * UNIX NAT "Session"
123  */
124 struct PeerSession
125 {
126
127   /**
128    * Stored in a linked list.
129    */
130   struct PeerSession *next;
131
132   /**
133    * Pointer to the global plugin struct.
134    */
135   struct Plugin *plugin;
136
137   /**
138    * To whom are we talking to (set to our identity
139    * if we are still waiting for the welcome message)
140    */
141   struct GNUNET_PeerIdentity target;
142
143   /**
144    * Address of the other peer (either based on our 'connect'
145    * call or on our 'accept' call).
146    */
147   void *connect_addr;
148
149   /**
150    * Length of connect_addr.
151    */
152   size_t connect_alen;
153
154   /**
155    * Are we still expecting the welcome message? (GNUNET_YES/GNUNET_NO)
156    */
157   int expecting_welcome;
158
159   /**
160    * From which socket do we need to send to this peer?
161    */
162   struct GNUNET_NETWORK_Handle *sock;
163
164   /*
165    * Queue of messages for this peer, in the case that
166    * we have to await a connection...
167    */
168   struct MessageQueue *messages;
169
170 };
171
172 /**
173  * Information we keep for each of our listen sockets.
174  */
175 struct UNIX_Sock_Info
176 {
177   /**
178    * The network handle
179    */
180   struct GNUNET_NETWORK_Handle *desc;
181
182   /**
183    * The port we bound to
184    */
185   uint16_t port;
186 };
187
188
189 /**
190  * Encapsulation of all of the state of the plugin.
191  */
192 struct Plugin
193 {
194   /**
195    * Our environment.
196    */
197   struct GNUNET_TRANSPORT_PluginEnvironment *env;
198
199   /**
200    * Sessions
201    */
202   struct GNUNET_CONTAINER_MultiHashMap *session_map;
203
204   /**
205    * ID of task used to update our addresses when one expires.
206    */
207   GNUNET_SCHEDULER_TaskIdentifier address_update_task;
208
209   /**
210    * ID of select task
211    */
212   GNUNET_SCHEDULER_TaskIdentifier select_task;
213
214   /**
215    * Integer to append to unix domain socket.
216    */
217   uint16_t port;
218
219   /**
220    * FD Read set
221    */
222   struct GNUNET_NETWORK_FDSet *rs;
223
224   /**
225    * FD Write set
226    */
227   struct GNUNET_NETWORK_FDSet *ws;
228
229   int with_ws;
230
231   /**
232    * socket that we transmit all data with
233    */
234   struct UNIX_Sock_Info unix_sock;
235
236   /**
237    * Path of our unix domain socket (/tmp/unix-plugin-PORT)
238    */
239   char *unix_socket_path;
240
241   struct UNIXMessageWrapper *msg_head;
242   struct UNIXMessageWrapper *msg_tail;
243
244   /**
245    * ATS network
246    */
247   struct GNUNET_ATS_Information ats_network;
248
249   unsigned int bytes_in_queue;
250   unsigned int bytes_in_sent;
251   unsigned int bytes_in_recv;
252   unsigned int bytes_discarded;
253 };
254
255 /**
256  * Start session timeout
257  */
258 static void
259 start_session_timeout (struct Session *s);
260
261 /**
262  * Increment session timeout due to activity
263  */
264 static void
265 reschedule_session_timeout (struct Session *s);
266
267 /**
268  * Cancel timeout
269  */
270 static void
271 stop_session_timeout (struct Session *s);
272
273
274 static void
275 unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
276
277
278 static void
279 reschedule_select (struct Plugin * plugin)
280 {
281
282   if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
283   {
284     GNUNET_SCHEDULER_cancel (plugin->select_task);
285     plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
286   }
287
288   if (NULL != plugin->msg_head)
289   {
290     plugin->select_task =
291       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
292                                    GNUNET_TIME_UNIT_FOREVER_REL,
293                                    plugin->rs,
294                                    plugin->ws,
295                                    &unix_plugin_select, plugin);
296     plugin->with_ws = GNUNET_YES;
297   }
298   else
299   {
300     plugin->select_task =
301       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
302                                    GNUNET_TIME_UNIT_FOREVER_REL,
303                                    plugin->rs,
304                                    NULL,
305                                    &unix_plugin_select, plugin);
306     plugin->with_ws = GNUNET_NO;
307   }
308 }
309
310 struct LookupCtx
311 {
312   struct Session *s;
313   const struct sockaddr_un *addr;
314 };
315
316 int lookup_session_it (void *cls,
317                        const struct GNUNET_HashCode * key,
318                        void *value)
319 {
320   struct LookupCtx *lctx = cls;
321   struct Session *t = value;
322
323   if (0 == strcmp (t->addr, lctx->addr->sun_path))
324   {
325     lctx->s = t;
326     return GNUNET_NO;
327   }
328   return GNUNET_YES;
329 }
330
331
332 static struct Session *
333 lookup_session (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, const struct sockaddr_un *addr)
334 {
335   struct LookupCtx lctx;
336
337   GNUNET_assert (NULL != plugin);
338   GNUNET_assert (NULL != sender);
339   GNUNET_assert (NULL != addr);
340
341   lctx.s = NULL;
342   lctx.addr = addr;
343
344   GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, &sender->hashPubKey, &lookup_session_it, &lctx);
345
346   return lctx.s;
347 }
348
349 /**
350  * Functions with this signature are called whenever we need
351  * to close a session due to a disconnect or failure to
352  * establish a connection.
353  *
354  * @param s session to close down
355  */
356 static void
357 disconnect_session (struct Session *s)
358 {
359   struct UNIXMessageWrapper *msgw;
360   struct UNIXMessageWrapper *next;
361   struct Plugin * plugin = s->plugin;
362   int removed;
363   GNUNET_assert (plugin != NULL);
364   GNUNET_assert (s != NULL);
365
366   LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting session for peer `%s' `%s' \n", GNUNET_i2s (&s->target), s->addr);
367   stop_session_timeout (s);
368   plugin->env->session_end (plugin->env->cls, &s->target, s);
369
370   msgw = plugin->msg_head;
371   removed = GNUNET_NO;
372   next = plugin->msg_head;
373   while (NULL != next)
374   {
375     msgw = next;
376     next = msgw->next;
377     if (msgw->session != s)
378       continue;
379     GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
380     if (NULL != msgw->cont)
381       msgw->cont (msgw->cont_cls,  &msgw->session->target, GNUNET_SYSERR,
382                   msgw->payload, 0);
383     GNUNET_free (msgw->msg);
384     GNUNET_free (msgw);
385     removed = GNUNET_YES;    
386   }
387   if ((GNUNET_YES == removed) && (NULL == plugin->msg_head))
388     reschedule_select (plugin);
389
390   GNUNET_assert (GNUNET_YES ==
391                  GNUNET_CONTAINER_multihashmap_remove(plugin->session_map, &s->target.hashPubKey, s));
392
393   GNUNET_STATISTICS_set(plugin->env->stats,
394                         "# UNIX sessions active",
395                         GNUNET_CONTAINER_multihashmap_size(plugin->session_map),
396                         GNUNET_NO);
397
398   GNUNET_free (s);
399 }
400
401 static int
402 get_session_delete_it (void *cls, const struct GNUNET_HashCode * key, void *value)
403 {
404   struct Session *s = value;
405   disconnect_session (s);
406   return GNUNET_YES;
407 }
408
409
410 /**
411  * Disconnect from a remote node.  Clean up session if we have one for this peer
412  *
413  * @param cls closure for this call (should be handle to Plugin)
414  * @param target the peeridentity of the peer to disconnect
415  * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
416  */
417 static void
418 unix_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
419 {
420   struct Plugin *plugin = cls;
421   GNUNET_assert (plugin != NULL);
422
423   GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, &target->hashPubKey, &get_session_delete_it, plugin);
424   return;
425 }
426
427 /**
428  * Shutdown the server process (stop receiving inbound traffic). Maybe
429  * restarted later!
430  *
431  * @param cls Handle to the plugin for this transport
432  *
433  * @return returns the number of sockets successfully closed,
434  *         should equal the number of sockets successfully opened
435  */
436 static int
437 unix_transport_server_stop (void *cls)
438 {
439   struct Plugin *plugin = cls;
440   struct UNIXMessageWrapper * msgw;
441
442   while (NULL != (msgw = plugin->msg_head))
443   {
444     GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
445     if (msgw->cont != NULL)
446       msgw->cont (msgw->cont_cls,  &msgw->session->target, GNUNET_SYSERR,
447                   msgw->payload, 0);
448     GNUNET_free (msgw->msg);
449     GNUNET_free (msgw);
450   }
451
452   if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
453   {
454     GNUNET_SCHEDULER_cancel (plugin->select_task);
455     plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
456   }
457
458   if (NULL != plugin->unix_sock.desc)
459   {
460     GNUNET_break (GNUNET_OK ==
461                   GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
462     plugin->unix_sock.desc = NULL;
463     plugin->with_ws = GNUNET_NO;
464   }
465   return GNUNET_OK;
466 }
467
468
469 /**
470  * Actually send out the message, assume we've got the address and
471  * send_handle squared away!
472  *
473  * @param cls closure
474  * @param send_handle which handle to send message on
475  * @param target who should receive this message (ignored by UNIX)
476  * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
477  * @param msgbuf_size the size of the msgbuf to send
478  * @param priority how important is the message (ignored by UNIX)
479  * @param timeout when should we time out (give up) if we can not transmit?
480  * @param addr the addr to send the message to, needs to be a sockaddr for us
481  * @param addrlen the len of addr
482  * @param payload bytes payload to send
483  * @param cont continuation to call once the message has
484  *        been transmitted (or if the transport is ready
485  *        for the next transmission call; or if the
486  *        peer disconnected...)
487  * @param cont_cls closure for cont
488  *
489  * @return the number of bytes written, -1 on errors
490  */
491 static ssize_t
492 unix_real_send (void *cls,
493                 struct GNUNET_NETWORK_Handle *send_handle,
494                 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
495                 size_t msgbuf_size, unsigned int priority,
496                 struct GNUNET_TIME_Relative timeout,
497                 const void *addr,
498                 size_t addrlen,
499                 size_t payload,
500                 GNUNET_TRANSPORT_TransmitContinuation cont,
501                 void *cont_cls)
502 {
503   struct Plugin *plugin = cls;
504   ssize_t sent;
505   const void *sb;
506   size_t sbs;
507   struct sockaddr_un un;
508   size_t slen;
509
510   GNUNET_assert (NULL != plugin);
511
512   if (send_handle == NULL)
513   {
514     /* We do not have a send handle */
515     GNUNET_break (0);
516     if (cont != NULL)
517       cont (cont_cls, target, GNUNET_SYSERR, payload, 0);
518     return -1;
519   }
520   if ((addr == NULL) || (addrlen == 0))
521   {
522     /* Can never send if we don't have an address */
523     GNUNET_break (0);
524     if (cont != NULL)
525       cont (cont_cls, target, GNUNET_SYSERR, payload, 0);
526     return -1;
527   }
528
529   /* Prepare address */
530   memset (&un, 0, sizeof (un));
531   un.sun_family = AF_UNIX;
532   slen = strlen (addr) + 1;
533   if (slen >= sizeof (un.sun_path))
534     slen = sizeof (un.sun_path) - 1;
535   GNUNET_assert (slen < sizeof (un.sun_path));
536   memcpy (un.sun_path, addr, slen);
537   un.sun_path[slen] = '\0';
538   slen = sizeof (struct sockaddr_un);
539 #if LINUX
540   un.sun_path[0] = '\0';
541 #endif
542 #if HAVE_SOCKADDR_IN_SIN_LEN
543   un.sun_len = (u_char) slen;
544 #endif
545   sb = (struct sockaddr *) &un;
546   sbs = slen;
547
548   /* Send the data */
549   sent = 0;
550   sent = GNUNET_NETWORK_socket_sendto (send_handle, msgbuf, msgbuf_size, sb, sbs);
551
552   if ((GNUNET_SYSERR == sent) && ((errno == EAGAIN) || (errno == ENOBUFS)))
553   {
554     /* We have to retry later: retry */
555     return 0;
556   }
557
558   if ((GNUNET_SYSERR == sent) && (errno == EMSGSIZE))
559   {
560     socklen_t size = 0;
561     socklen_t len = sizeof (size);
562
563     GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
564                                       send_handle, SOL_SOCKET, SO_SNDBUF, &size,
565                                       &len);
566
567     if (size < msgbuf_size)
568     {
569       LOG (GNUNET_ERROR_TYPE_DEBUG,
570                   "Trying to increase socket buffer size from %i to %i for message size %i\n",
571                   size,
572                   ((msgbuf_size / 1000) + 2) * 1000,
573                   msgbuf_size);
574       size = ((msgbuf_size / 1000) + 2) * 1000;
575       if (GNUNET_NETWORK_socket_setsockopt
576           ((struct GNUNET_NETWORK_Handle *) send_handle, SOL_SOCKET, SO_SNDBUF,
577            &size, sizeof (size)) == GNUNET_OK)
578       {
579         /* Increased buffer size, retry sending */
580         return 0;
581       }
582       else
583       {
584         /* Could not increase buffer size: error, no retry */
585         GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
586         return -1;
587       }
588     }
589     else
590     {
591       /* Buffer is bigger than message:  error, no retry
592        * This should never happen!*/
593       GNUNET_break (0);
594       return -1;
595     }
596   }
597
598   LOG (GNUNET_ERROR_TYPE_DEBUG,
599               "UNIX transmit %u-byte message to %s (%d: %s)\n",
600               (unsigned int) msgbuf_size, GNUNET_a2s (sb, sbs), (int) sent,
601               (sent < 0) ? STRERROR (errno) : "ok");
602
603   /* Calling continuation */
604   if (cont != NULL)
605   {
606     if (sent == GNUNET_SYSERR)
607       cont (cont_cls, target, GNUNET_SYSERR, payload, 0);
608     if (sent > 0)
609       cont (cont_cls, target, GNUNET_OK, payload, msgbuf_size);
610   }
611
612   /* return number of bytes successfully sent */
613   if (sent > 0)
614     return sent;
615   if (sent == 0)
616   {
617     /* That should never happen */
618     GNUNET_break (0);
619     return -1;
620   }
621   /* failed and retry: return 0 */
622   if (GNUNET_SYSERR == sent)
623     return 0;
624   /* default */
625   return -1;
626 }
627
628 struct gsi_ctx
629 {
630   char *address;
631   size_t addrlen;
632   struct Session *res;
633 };
634
635
636 static int
637 get_session_it (void *cls, const struct GNUNET_HashCode * key, void *value)
638 {
639   struct gsi_ctx *gsi = cls;
640   struct Session *s = value;
641
642   LOG (GNUNET_ERROR_TYPE_DEBUG, "Comparing session %s %s\n", gsi->address, s->addr);
643   if ((gsi->addrlen == s->addrlen) &&
644       (0 == memcmp (gsi->address, s->addr, s->addrlen)))
645   {
646     gsi->res = s;
647     return GNUNET_NO;
648   }
649   return GNUNET_YES;
650 }
651
652 /**
653  * Creates a new outbound session the transport service will use to send data to the
654  * peer
655  *
656  * @param cls the plugin
657  * @param address the address
658  * @return the session or NULL of max connections exceeded
659  */
660 static struct Session *
661 unix_plugin_get_session (void *cls,
662                   const struct GNUNET_HELLO_Address *address)
663 {
664   struct Session * s = NULL;
665   struct Plugin *plugin = cls;
666   struct gsi_ctx gsi;
667
668   /* Checks */
669   GNUNET_assert (plugin != NULL);
670   GNUNET_assert (address != NULL);
671
672   /* Check if already existing */
673   gsi.address = (char *) address->address;
674   gsi.addrlen = address->address_length;
675   gsi.res = NULL;
676   GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, &address->peer.hashPubKey, &get_session_it, &gsi);
677   if (gsi.res != NULL)
678   {
679     LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session\n");
680     return gsi.res;
681   }
682
683   /* Create a new session */
684   s = GNUNET_malloc (sizeof (struct Session) + address->address_length);
685   s->addr = &s[1];
686   s->addrlen = address->address_length;
687   s->plugin = plugin;
688   memcpy(s->addr, address->address, s->addrlen);
689   memcpy(&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity));
690
691   start_session_timeout (s);
692
693   GNUNET_CONTAINER_multihashmap_put (plugin->session_map,
694       &address->peer.hashPubKey, s,
695       GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
696
697   GNUNET_STATISTICS_set(plugin->env->stats,
698                         "# UNIX sessions active",
699                         GNUNET_CONTAINER_multihashmap_size(plugin->session_map),
700                         GNUNET_NO);
701   LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new session\n");
702   return s;
703 }
704
705 /*
706  * @param cls the plugin handle
707  * @param tc the scheduling context (for rescheduling this function again)
708  *
709  * We have been notified that our writeset has something to read.  We don't
710  * know which socket needs to be read, so we have to check each one
711  * Then reschedule this function to be called again once more is available.
712  *
713  */
714 static void
715 unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
716
717 /**
718  * Function that can be used by the transport service to transmit
719  * a message using the plugin.   Note that in the case of a
720  * peer disconnecting, the continuation MUST be called
721  * prior to the disconnect notification itself.  This function
722  * will be called with this peer's HELLO message to initiate
723  * a fresh connection to another peer.
724  *
725  * @param cls closure
726  * @param session which session must be used
727  * @param msgbuf the message to transmit
728  * @param msgbuf_size number of bytes in 'msgbuf'
729  * @param priority how important is the message (most plugins will
730  *                 ignore message priority and just FIFO)
731  * @param to how long to wait at most for the transmission (does not
732  *                require plugins to discard the message after the timeout,
733  *                just advisory for the desired delay; most plugins will ignore
734  *                this as well)
735  * @param cont continuation to call once the message has
736  *        been transmitted (or if the transport is ready
737  *        for the next transmission call; or if the
738  *        peer disconnected...); can be NULL
739  * @param cont_cls closure for cont
740  * @return number of bytes used (on the physical network, with overheads);
741  *         -1 on hard errors (i.e. address invalid); 0 is a legal value
742  *         and does NOT mean that the message was not transmitted (DV)
743  */
744 static ssize_t
745 unix_plugin_send (void *cls,
746                   struct Session *session,
747                   const char *msgbuf, size_t msgbuf_size,
748                   unsigned int priority,
749                   struct GNUNET_TIME_Relative to,
750                   GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
751 {
752   struct Plugin *plugin = cls;
753   struct UNIXMessageWrapper *wrapper;
754   struct UNIXMessage *message;
755   int ssize;
756   
757   GNUNET_assert (plugin != NULL);
758   GNUNET_assert (session != NULL);
759
760   if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_contains_value(plugin->session_map,
761       &session->target.hashPubKey, session))
762   {
763     LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session for peer `%s' `%s'\n",
764                 GNUNET_i2s (&session->target),
765                 (char *) session->addr);
766     GNUNET_break (0);
767
768     return GNUNET_SYSERR;
769   }
770   LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending %u bytes with session for peer `%s' `%s'\n",
771                 msgbuf_size,
772         GNUNET_i2s (&session->target),
773         (char *) session->addr);
774
775   ssize = sizeof (struct UNIXMessage) + msgbuf_size;
776   message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
777   message->header.size = htons (ssize);
778   message->header.type = htons (0);
779   memcpy (&message->sender, plugin->env->my_identity,
780           sizeof (struct GNUNET_PeerIdentity));
781   memcpy (&message[1], msgbuf, msgbuf_size);
782
783   reschedule_session_timeout (session);
784
785   wrapper = GNUNET_malloc (sizeof (struct UNIXMessageWrapper));
786   wrapper->msg = message;
787   wrapper->msgsize = ssize;
788   wrapper->payload = msgbuf_size;
789   wrapper->priority = priority;
790   wrapper->timeout = to;
791   wrapper->cont = cont;
792   wrapper->cont_cls = cont_cls;
793   wrapper->session = session;
794
795   GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, wrapper);
796
797   plugin->bytes_in_queue += ssize;
798   GNUNET_STATISTICS_set (plugin->env->stats,"# bytes currently in UNIX buffers",
799       plugin->bytes_in_queue, GNUNET_NO);
800
801   LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", ssize,
802               (char *) session->addr);
803   if (plugin->with_ws == GNUNET_NO)
804   {
805     reschedule_select (plugin);
806   }
807
808   return ssize;
809 }
810
811
812 /**
813  * Demultiplexer for UNIX messages
814  *
815  * @param plugin the main plugin for this transport
816  * @param sender from which peer the message was received
817  * @param currhdr pointer to the header of the message
818  * @param un the address from which the message was received
819  * @param fromlen the length of the address
820  */
821 static void
822 unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
823                     const struct GNUNET_MessageHeader *currhdr,
824                     const struct sockaddr_un *un, size_t fromlen)
825 {
826   struct GNUNET_ATS_Information ats[2];
827   struct Session *s = NULL;
828   struct GNUNET_HELLO_Address * addr;
829
830   ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
831   ats[0].value = htonl (UNIX_DIRECT_DISTANCE);
832   ats[1] = plugin->ats_network;
833   GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED);
834
835   GNUNET_assert (fromlen >= sizeof (struct sockaddr_un));
836
837   LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n",
838               un->sun_path);
839
840
841
842   plugin->bytes_in_recv += ntohs(currhdr->size);
843   GNUNET_STATISTICS_set (plugin->env->stats,"# bytes received via UNIX",
844       plugin->bytes_in_recv, GNUNET_NO);
845
846   addr = GNUNET_HELLO_address_allocate(sender, "unix", un->sun_path, strlen (un->sun_path) + 1);
847   s = lookup_session (plugin, sender, un);
848   if (NULL == s)
849     s = unix_plugin_get_session (plugin, addr);
850   reschedule_session_timeout (s);
851
852   plugin->env->receive (plugin->env->cls, sender, currhdr,
853                         (const struct GNUNET_ATS_Information *) &ats, 2,
854                         s, un->sun_path, strlen (un->sun_path) + 1);
855   GNUNET_free (addr);
856 }
857
858
859 static void
860 unix_plugin_select_read (struct Plugin * plugin)
861 {
862   char buf[65536] GNUNET_ALIGN;
863   struct UNIXMessage *msg;
864   struct GNUNET_PeerIdentity sender;
865   struct sockaddr_un un;
866   socklen_t addrlen;
867   ssize_t ret;
868   int offset;
869   int tsize;
870   char *msgbuf;
871   const struct GNUNET_MessageHeader *currhdr;
872   uint16_t csize;
873
874   addrlen = sizeof (un);
875   memset (&un, 0, sizeof (un));
876
877   ret =
878       GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf),
879                                       (struct sockaddr *) &un, &addrlen);
880
881   if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
882     return;
883
884   if (ret == GNUNET_SYSERR)
885   {
886     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
887     return;
888   }
889   else
890   {
891 #if LINUX
892     un.sun_path[0] = '/';
893 #endif
894     LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret,
895                 &un.sun_path[0]);
896   }
897
898   GNUNET_assert (AF_UNIX == (un.sun_family));
899
900   msg = (struct UNIXMessage *) buf;
901   csize = ntohs (msg->header.size);
902   if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
903   {
904     GNUNET_break_op (0);
905     return;
906   }
907   msgbuf = (char *) &msg[1];
908   memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
909   offset = 0;
910   tsize = csize - sizeof (struct UNIXMessage);
911   while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
912   {
913     currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
914     csize = ntohs (currhdr->size);
915     if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
916         (csize > tsize - offset))
917     {
918       GNUNET_break_op (0);
919       break;
920     }
921
922     unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un));
923     offset += csize;
924   }
925 }
926
927
928 static void
929 unix_plugin_select_write (struct Plugin * plugin)
930 {
931   static int retry_counter;
932   int sent = 0;
933   struct UNIXMessageWrapper * msgw = plugin->msg_head;
934
935   sent = unix_real_send (plugin,
936                          plugin->unix_sock.desc,
937                          &msgw->session->target,
938                          (const char *) msgw->msg,
939                          msgw->msgsize,
940                          msgw->priority,
941                          msgw->timeout,
942                          msgw->session->addr,
943                          msgw->session->addrlen,
944                          msgw->payload,
945                          msgw->cont, msgw->cont_cls);
946
947   if (sent == 0)
948   {
949     /* failed and retry */
950     retry_counter++;
951     GNUNET_STATISTICS_set (plugin->env->stats,"# UNIX retry attempt",
952         retry_counter, GNUNET_NO);
953     return;
954   }
955
956   if (retry_counter > 0 )
957   {
958     /* no retry: reset counter */
959     retry_counter = 0;
960     GNUNET_STATISTICS_set (plugin->env->stats,"# UNIX retry attempt",
961         retry_counter, GNUNET_NO);
962   }
963
964   if (sent == -1)
965   {
966     /* failed and no retry */
967     GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
968
969     GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
970     plugin->bytes_in_queue -= msgw->msgsize;
971     GNUNET_STATISTICS_set (plugin->env->stats, "# bytes currently in UNIX buffers",
972         plugin->bytes_in_queue, GNUNET_NO);
973     plugin->bytes_discarded += msgw->msgsize;
974     GNUNET_STATISTICS_set (plugin->env->stats,"# UNIX bytes discarded",
975         plugin->bytes_discarded, GNUNET_NO);
976
977     GNUNET_free (msgw->msg);
978     GNUNET_free (msgw);
979     return;
980   }
981
982   if (sent > 0)
983   {
984     /* successfully sent bytes */
985     GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
986
987     GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
988     plugin->bytes_in_queue -= msgw->msgsize;
989     GNUNET_STATISTICS_set (plugin->env->stats,"# bytes currently in UNIX buffers",
990         plugin->bytes_in_queue, GNUNET_NO);
991     plugin->bytes_in_sent += msgw->msgsize;
992     GNUNET_STATISTICS_set (plugin->env->stats,"# bytes transmitted via UNIX",
993         plugin->bytes_in_sent, GNUNET_NO);
994
995     GNUNET_free (msgw->msg);
996     GNUNET_free (msgw);
997     return;
998   }
999
1000 }
1001
1002
1003 /**
1004  * We have been notified that our writeset has something to read.  We don't
1005  * know which socket needs to be read, so we have to check each one
1006  * Then reschedule this function to be called again once more is available.
1007  *
1008  * @param cls the plugin handle
1009  * @param tc the scheduling context (for rescheduling this function again)
1010  */
1011 static void
1012 unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1013 {
1014   struct Plugin *plugin = cls;
1015
1016   plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
1017   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1018     return;
1019
1020   if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
1021   {
1022     /* Ready to send data */
1023     GNUNET_assert (GNUNET_NETWORK_fdset_isset
1024                    (tc->write_ready, plugin->unix_sock.desc));
1025     if (plugin->msg_head != NULL)
1026       unix_plugin_select_write (plugin);
1027   }
1028
1029   if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
1030   {
1031     /* Ready to receive data */
1032     GNUNET_assert (GNUNET_NETWORK_fdset_isset
1033                    (tc->read_ready, plugin->unix_sock.desc));
1034     unix_plugin_select_read (plugin);
1035   }
1036
1037   reschedule_select (plugin);
1038 }
1039
1040
1041 /**
1042  * Create a slew of UNIX sockets.  If possible, use IPv6 and IPv4.
1043  *
1044  * @param cls closure for server start, should be a struct Plugin *
1045  * @return number of sockets created or GNUNET_SYSERR on error
1046  */
1047 static int
1048 unix_transport_server_start (void *cls)
1049 {
1050   struct Plugin *plugin = cls;
1051   struct sockaddr *serverAddr;
1052   socklen_t addrlen;
1053   struct sockaddr_un un;
1054   size_t slen;
1055
1056   memset (&un, 0, sizeof (un));
1057   un.sun_family = AF_UNIX;
1058   slen = strlen (plugin->unix_socket_path) + 1;
1059   if (slen >= sizeof (un.sun_path))
1060     slen = sizeof (un.sun_path) - 1;
1061
1062   memcpy (un.sun_path, plugin->unix_socket_path, slen);
1063   un.sun_path[slen] = '\0';
1064   slen = sizeof (struct sockaddr_un);
1065 #if HAVE_SOCKADDR_IN_SIN_LEN
1066   un.sun_len = (u_char) slen;
1067 #endif
1068
1069   serverAddr = (struct sockaddr *) &un;
1070   addrlen = slen;
1071 #if LINUX
1072   un.sun_path[0] = '\0';
1073 #endif
1074   plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, serverAddr, addrlen);
1075   plugin->unix_sock.desc =
1076       GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1077   if (NULL == plugin->unix_sock.desc)
1078   {
1079     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1080     return GNUNET_SYSERR;
1081   }
1082   if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)
1083       != GNUNET_OK)
1084   {
1085     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1086     GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1087     plugin->unix_sock.desc = NULL;
1088     return GNUNET_SYSERR;
1089   }
1090   LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1091   plugin->rs = GNUNET_NETWORK_fdset_create ();
1092   plugin->ws = GNUNET_NETWORK_fdset_create ();
1093   GNUNET_NETWORK_fdset_zero (plugin->rs);
1094   GNUNET_NETWORK_fdset_zero (plugin->ws);
1095   GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc);
1096   GNUNET_NETWORK_fdset_set (plugin->ws, plugin->unix_sock.desc);
1097
1098   reschedule_select (plugin);
1099
1100   return 1;
1101 }
1102
1103
1104 /**
1105  * Function that will be called to check if a binary address for this
1106  * plugin is well-formed and corresponds to an address for THIS peer
1107  * (as per our configuration).  Naturally, if absolutely necessary,
1108  * plugins can be a bit conservative in their answer, but in general
1109  * plugins should make sure that the address does not redirect
1110  * traffic to a 3rd party that might try to man-in-the-middle our
1111  * traffic.
1112  *
1113  * @param cls closure, should be our handle to the Plugin
1114  * @param addr pointer to the address
1115  * @param addrlen length of addr
1116  * @return GNUNET_OK if this is a plausible address for this peer
1117  *         and transport, GNUNET_SYSERR if not
1118  *
1119  */
1120 static int
1121 unix_check_address (void *cls, const void *addr, size_t addrlen)
1122 {
1123   LOG (GNUNET_ERROR_TYPE_DEBUG,
1124               "Informing transport service about my address `%s'\n",
1125               (char *) addr);
1126   return GNUNET_OK;
1127 }
1128
1129
1130 /**
1131  * Convert the transports address to a nice, human-readable
1132  * format.
1133  *
1134  * @param cls closure
1135  * @param type name of the transport that generated the address
1136  * @param addr one of the addresses of the host, NULL for the last address
1137  *        the specific address format depends on the transport
1138  * @param addrlen length of the address
1139  * @param numeric should (IP) addresses be displayed in numeric form?
1140  * @param timeout after how long should we give up?
1141  * @param asc function to call on each string
1142  * @param asc_cls closure for asc
1143  */
1144 static void
1145 unix_plugin_address_pretty_printer (void *cls, const char *type,
1146                                     const void *addr, size_t addrlen,
1147                                     int numeric,
1148                                     struct GNUNET_TIME_Relative timeout,
1149                                     GNUNET_TRANSPORT_AddressStringCallback asc,
1150                                     void *asc_cls)
1151 {
1152   if ((NULL != addr) && (addrlen > 0))
1153   {
1154     asc (asc_cls, (const char *) addr);
1155   }
1156   else
1157   {
1158     GNUNET_break (0);
1159     asc (asc_cls, "<invalid UNIX address>");
1160   }
1161   asc (asc_cls, NULL);
1162 }
1163
1164
1165 /**
1166  * Function called to convert a string address to
1167  * a binary address.
1168  *
1169  * @param cls closure ('struct Plugin*')
1170  * @param addr string address
1171  * @param addrlen length of the address (strlen(addr) + '\0')
1172  * @param buf location to store the buffer
1173  *        If the function returns GNUNET_SYSERR, its contents are undefined.
1174  * @param added length of created address
1175  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1176  */
1177 static int
1178 unix_string_to_address (void *cls, const char *addr, uint16_t addrlen,
1179     void **buf, size_t *added)
1180 {
1181   if ((NULL == addr) || (0 == addrlen))
1182   {
1183     GNUNET_break (0);
1184     return GNUNET_SYSERR;
1185   }
1186
1187   if ('\0' != addr[addrlen - 1])
1188   {
1189     GNUNET_break (0);
1190     return GNUNET_SYSERR;
1191   }
1192
1193   if (strlen (addr) != addrlen - 1)
1194   {
1195     GNUNET_break (0);
1196     return GNUNET_SYSERR;
1197   }
1198
1199   (*buf) = strdup (addr);
1200   (*added) = strlen (addr) + 1;
1201   return GNUNET_OK;
1202 }
1203
1204
1205 /**
1206  * Function called for a quick conversion of the binary address to
1207  * a numeric address.  Note that the caller must not free the
1208  * address and that the next call to this function is allowed
1209  * to override the address again.
1210  *
1211  * @param cls closure
1212  * @param addr binary address
1213  * @param addrlen length of the address
1214  * @return string representing the same address
1215  */
1216 static const char *
1217 unix_address_to_string (void *cls, const void *addr, size_t addrlen)
1218 {
1219   if ((addr != NULL) && (addrlen > 0))
1220     return (const char *) addr;
1221   return NULL;
1222 }
1223
1224
1225 /**
1226  * Notify transport service about address
1227  *
1228  * @param cls the plugin
1229  * @param tc unused
1230  */
1231 static void
1232 address_notification (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1233 {
1234   struct Plugin *plugin = cls;
1235
1236   plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
1237                                plugin->unix_socket_path,
1238                                strlen (plugin->unix_socket_path) + 1,
1239                                "unix");
1240 }
1241
1242
1243 /**
1244  * Session was idle, so disconnect it
1245  */
1246 static void
1247 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1248 {
1249   GNUNET_assert (NULL != cls);
1250   struct Session *s = cls;
1251
1252   s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1253   LOG (GNUNET_ERROR_TYPE_DEBUG,
1254               "Session %p was idle for %llu ms, disconnecting\n",
1255               s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1256   /* call session destroy function */
1257   disconnect_session(s);
1258 }
1259
1260
1261 /**
1262  * Start session timeout
1263  */
1264 static void
1265 start_session_timeout (struct Session *s)
1266 {
1267   GNUNET_assert (NULL != s);
1268   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1269   s->timeout_task =  GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1270                                                    &session_timeout,
1271                                                    s);
1272   LOG (GNUNET_ERROR_TYPE_DEBUG,
1273               "Timeout for session %p set to %llu ms\n",
1274               s,  (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1275 }
1276
1277
1278 /**
1279  * Increment session timeout due to activity
1280  */
1281 static void
1282 reschedule_session_timeout (struct Session *s)
1283 {
1284   GNUNET_assert (NULL != s);
1285   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1286
1287   GNUNET_SCHEDULER_cancel (s->timeout_task);
1288   s->timeout_task =  GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1289                                                    &session_timeout,
1290                                                    s);
1291   LOG (GNUNET_ERROR_TYPE_DEBUG,
1292               "Timeout rescheduled for session %p set to %llu ms\n",
1293               s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1294 }
1295
1296
1297 /**
1298  * Cancel timeout
1299  */
1300 static void
1301 stop_session_timeout (struct Session *s)
1302 {
1303   GNUNET_assert (NULL != s);
1304
1305   if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1306   {
1307     GNUNET_SCHEDULER_cancel (s->timeout_task);
1308     s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1309     LOG (GNUNET_ERROR_TYPE_DEBUG,
1310                 "Timeout stopped for session %p canceled\n",
1311                 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1312   }
1313 }
1314
1315 /**
1316  * The exported method. Makes the core api available via a global and
1317  * returns the unix transport API.
1318  */
1319 void *
1320 libgnunet_plugin_transport_unix_init (void *cls)
1321 {
1322   struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1323   unsigned long long port;
1324   struct GNUNET_TRANSPORT_PluginFunctions *api;
1325   struct Plugin *plugin;
1326   int sockets_created;
1327
1328   if (NULL == env->receive)
1329   {
1330     /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1331        initialze the plugin or the API */
1332     api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1333     api->cls = NULL;
1334     api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1335     api->address_to_string = &unix_address_to_string;
1336     api->string_to_address = &unix_string_to_address;
1337     return api;
1338   }
1339   GNUNET_assert( NULL != env->stats);
1340
1341   if (GNUNET_OK !=
1342       GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT",
1343                                              &port))
1344     port = UNIX_NAT_DEFAULT_PORT;
1345   plugin = GNUNET_malloc (sizeof (struct Plugin));
1346   plugin->port = port;
1347   plugin->env = env;
1348   GNUNET_asprintf (&plugin->unix_socket_path, "/tmp/unix-plugin-sock.%d",
1349                    plugin->port);
1350
1351   api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1352   api->cls = plugin;
1353
1354   api->get_session = &unix_plugin_get_session;
1355   api->send = &unix_plugin_send;
1356   api->disconnect = &unix_disconnect;
1357   api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1358   api->address_to_string = &unix_address_to_string;
1359   api->check_address = &unix_check_address;
1360   api->string_to_address = &unix_string_to_address;
1361   sockets_created = unix_transport_server_start (plugin);
1362   if (sockets_created == 0)
1363     LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX sockets\n"));
1364
1365   plugin->session_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1366
1367   GNUNET_SCHEDULER_add_now (address_notification, plugin);
1368   return api;
1369 }
1370
1371 void *
1372 libgnunet_plugin_transport_unix_done (void *cls)
1373 {
1374   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1375   struct Plugin *plugin = api->cls;
1376
1377   if (NULL == plugin)
1378   {
1379     GNUNET_free (api);
1380     return NULL;
1381   }
1382
1383   plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1384                                plugin->unix_socket_path,
1385                                strlen (plugin->unix_socket_path) + 1,
1386                                "unix");
1387
1388   unix_transport_server_stop (plugin);
1389
1390
1391   GNUNET_CONTAINER_multihashmap_iterate (plugin->session_map, &get_session_delete_it, plugin);
1392   GNUNET_CONTAINER_multihashmap_destroy (plugin->session_map);
1393
1394
1395   if (NULL != plugin->rs)
1396     GNUNET_NETWORK_fdset_destroy (plugin->rs);
1397   if (NULL != plugin->ws)
1398     GNUNET_NETWORK_fdset_destroy (plugin->ws);
1399   GNUNET_free (plugin->unix_socket_path);
1400   GNUNET_free (plugin);
1401   GNUNET_free (api);
1402   return NULL;
1403 }
1404
1405 /* end of plugin_transport_unix.c */