2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file transport/plugin_transport_tcp.c
22 * @brief Implementation of the TCP transport service
23 * @author Christian Grothoff
26 #include "gnunet_hello_lib.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_connection_lib.h"
29 #include "gnunet_container_lib.h"
30 #include "gnunet_nat_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_resolver_service.h"
34 #include "gnunet_server_lib.h"
35 #include "gnunet_service_lib.h"
36 #include "gnunet_signatures.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_transport_service.h"
39 #include "gnunet_transport_plugin.h"
40 #include "transport.h"
42 #define LOG(kind,...) GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__)
45 * How long until we give up on establishing an NAT connection?
48 #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
51 GNUNET_NETWORK_STRUCT_BEGIN
54 * Initial handshake message for a session.
59 * Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME.
61 struct GNUNET_MessageHeader header;
64 * Identity of the node connecting (TCP client)
66 struct GNUNET_PeerIdentity clientIdentity;
72 * Basically a WELCOME message, but with the purpose
73 * of giving the waiting peer a client handle to use
75 struct TCP_NAT_ProbeMessage
78 * Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
80 struct GNUNET_MessageHeader header;
83 * Identity of the sender of the message.
85 struct GNUNET_PeerIdentity clientIdentity;
88 GNUNET_NETWORK_STRUCT_END
91 * Context for sending a NAT probe via TCP.
93 struct TCPProbeContext
97 * Active probes are kept in a DLL.
99 struct TCPProbeContext *next;
102 * Active probes are kept in a DLL.
104 struct TCPProbeContext *prev;
109 struct GNUNET_CONNECTION_Handle *sock;
112 * Message to be sent.
114 struct TCP_NAT_ProbeMessage message;
117 * Handle to the transmission.
119 struct GNUNET_CONNECTION_TransmitHandle *transmit_handle;
122 * Transport plugin handle.
124 struct Plugin *plugin;
128 GNUNET_NETWORK_STRUCT_BEGIN
131 * Network format for IPv4 addresses.
133 struct IPv4TcpAddress
136 * IPv4 address, in network byte order.
138 uint32_t ipv4_addr GNUNET_PACKED;
141 * Port number, in network byte order.
143 uint16_t t4_port GNUNET_PACKED;
149 * Network format for IPv6 addresses.
151 struct IPv6TcpAddress
156 struct in6_addr ipv6_addr GNUNET_PACKED;
159 * Port number, in network byte order.
161 uint16_t t6_port GNUNET_PACKED;
164 GNUNET_NETWORK_STRUCT_END
167 * Encapsulation of all of the state of the plugin.
173 * Information kept for each message that is yet to
176 struct PendingMessage
180 * This is a doubly-linked list.
182 struct PendingMessage *next;
185 * This is a doubly-linked list.
187 struct PendingMessage *prev;
190 * The pending message
195 * Continuation function to call once the message
196 * has been sent. Can be NULL if there is no
197 * continuation to call.
199 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
202 * Closure for transmit_cont.
204 void *transmit_cont_cls;
207 * Timeout value for the pending message.
209 struct GNUNET_TIME_Absolute timeout;
212 * So that the gnunet-service-transport can group messages together,
213 * these pending messages need to accept a message buffer and size
214 * instead of just a GNUNET_MessageHeader.
222 * Session handle for TCP connections.
230 struct SessionHeader header;
233 * Pointer to the global plugin struct.
235 struct Plugin *plugin;
238 * The client (used to identify this connection)
240 struct GNUNET_SERVER_Client *client;
243 * Task cleaning up a NAT client connection establishment attempt;
245 GNUNET_SCHEDULER_TaskIdentifier nat_connection_timeout;
248 * Messages currently pending for transmission
249 * to this peer, if any.
251 struct PendingMessage *pending_messages_head;
254 * Messages currently pending for transmission
255 * to this peer, if any.
257 struct PendingMessage *pending_messages_tail;
260 * Handle for pending transmission request.
262 struct GNUNET_SERVER_TransmitHandle *transmit_handle;
265 * To whom are we talking to (set to our identity
266 * if we are still waiting for the welcome message)
268 struct GNUNET_PeerIdentity target;
271 * ID of task used to delay receiving more to throttle sender.
273 GNUNET_SCHEDULER_TaskIdentifier receive_delay_task;
276 * Session timeout task
278 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
281 * Address of the other peer (either based on our 'connect'
282 * call or on our 'accept' call).
284 * struct IPv4TcpAddress or struct IPv6TcpAddress
290 * Length of connect_addr.
295 * Last activity on this connection. Used to select preferred
298 struct GNUNET_TIME_Absolute last_activity;
301 * Are we still expecting the welcome message? (GNUNET_YES/GNUNET_NO)
303 int expecting_welcome;
306 * Was this a connection that was inbound (we accepted)? (GNUNET_YES/GNUNET_NO)
311 * Was this session created using NAT traversal?
316 * ATS network type in NBO
318 uint32_t ats_address_network_type;
323 * Encapsulation of all of the state of the plugin.
330 struct GNUNET_TRANSPORT_PluginEnvironment *env;
335 struct GNUNET_CONNECTION_Handle *lsock;
338 * Our handle to the NAT module.
340 struct GNUNET_NAT_Handle *nat;
342 struct GNUNET_CONTAINER_MultiHashMap * sessionmap;
345 * Handle to the network service.
347 struct GNUNET_SERVICE_Context *service;
350 * Handle to the server for this service.
352 struct GNUNET_SERVER_Handle *server;
355 * Copy of the handler array where the closures are
356 * set to this struct's instance.
358 struct GNUNET_SERVER_MessageHandler *handlers;
361 * Map of peers we have tried to contact behind a NAT
363 struct GNUNET_CONTAINER_MultiHashMap *nat_wait_conns;
366 * List of active TCP probes.
368 struct TCPProbeContext *probe_head;
371 * List of active TCP probes.
373 struct TCPProbeContext *probe_tail;
376 * Handle for (DYN)DNS lookup of our external IP.
378 struct GNUNET_RESOLVER_RequestHandle *ext_dns;
381 * How many more TCP sessions are we allowed to open right now?
383 unsigned long long max_connections;
386 * ID of task used to update our addresses when one expires.
388 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
391 * Port that we are actually listening on.
396 * Port that the user said we would have visible to the
405 * Start session timeout
408 start_session_timeout (struct Session *s);
411 * Increment session timeout due to activity
414 reschedule_session_timeout (struct Session *s);
420 stop_session_timeout (struct Session *s);
425 tcp_address_to_string (void *cls, const void *addr, size_t addrlen);
427 static unsigned int sessions;
429 static void inc_sessions (struct Plugin *plugin, struct Session *session, int line)
432 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap);
433 if (sessions != size)
434 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n",
436 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session increased to %u (session map size: %u): `%s' `%s'\n",
440 GNUNET_i2s (&session->target),
441 tcp_address_to_string (NULL, session->addr, session->addrlen));
444 static void dec_sessions (struct Plugin *plugin, struct Session *session, int line)
446 GNUNET_assert (sessions > 0);
447 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap);
449 if (sessions != size)
450 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n",
452 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session decreased to %u (session map size: %u): `%s' `%s'\n",
456 GNUNET_i2s (&session->target),
457 tcp_address_to_string (NULL, session->addr, session->addrlen));
463 * Function to check if an inbound connection is acceptable.
464 * Mostly used to limit the total number of open connections
467 * @param cls the 'struct Plugin'
468 * @param ucred credentials, if available, otherwise NULL
469 * @param addr address
470 * @param addrlen length of address
471 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
472 * for unknown address family (will be denied).
475 plugin_tcp_access_check (void *cls,
476 const struct GNUNET_CONNECTION_Credentials *ucred,
477 const struct sockaddr *addr, socklen_t addrlen)
479 struct Plugin *plugin = cls;
481 LOG (GNUNET_ERROR_TYPE_DEBUG,
482 "Accepting new incoming TCP connection\n");
483 if (0 == plugin->max_connections)
485 plugin->max_connections--;
491 * Our external IP address/port mapping has changed.
493 * @param cls closure, the 'struct LocalAddrList'
494 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
495 * the previous (now invalid) one
496 * @param addr either the previous or the new public IP address
497 * @param addrlen actual lenght of the address
500 tcp_nat_port_map_callback (void *cls, int add_remove,
501 const struct sockaddr *addr, socklen_t addrlen)
503 struct Plugin *plugin = cls;
504 struct IPv4TcpAddress t4;
505 struct IPv6TcpAddress t6;
509 LOG (GNUNET_ERROR_TYPE_DEBUG,
510 "NPMC called with %d for address `%s'\n", add_remove,
511 GNUNET_a2s (addr, addrlen));
512 /* convert 'addr' to our internal format */
513 switch (addr->sa_family)
516 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
517 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
518 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
523 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
524 memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
525 sizeof (struct in6_addr));
526 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
534 /* modify our published address list */
535 plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
540 * Function called for a quick conversion of the binary address to
541 * a numeric address. Note that the caller must not free the
542 * address and that the next call to this function is allowed
543 * to override the address again.
545 * @param cls closure ('struct Plugin*')
546 * @param addr binary address
547 * @param addrlen length of the address
548 * @return string representing the same address
551 tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
553 static char rbuf[INET6_ADDRSTRLEN + 12];
554 char buf[INET6_ADDRSTRLEN];
558 const struct IPv4TcpAddress *t4;
559 const struct IPv6TcpAddress *t6;
563 if (addrlen == sizeof (struct IPv6TcpAddress))
567 port = ntohs (t6->t6_port);
568 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
571 else if (addrlen == sizeof (struct IPv4TcpAddress))
575 port = ntohs (t4->t4_port);
576 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
581 LOG (GNUNET_ERROR_TYPE_ERROR,
582 _("Unexpected address length: %u bytes\n"),
583 (unsigned int) addrlen);
587 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
589 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
592 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
599 * Function called to convert a string address to
602 * @param cls closure ('struct Plugin*')
603 * @param addr string address
604 * @param addrlen length of the address
605 * @param buf location to store the buffer
606 * @param added location to store the number of bytes in the buffer.
607 * If the function returns GNUNET_SYSERR, its contents are undefined.
608 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
611 tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
612 void **buf, size_t *added)
614 struct sockaddr_storage socket_address;
616 if ((NULL == addr) || (addrlen == 0))
619 return GNUNET_SYSERR;
622 if ('\0' != addr[addrlen - 1])
625 return GNUNET_SYSERR;
628 if (strlen (addr) != addrlen - 1)
631 return GNUNET_SYSERR;
634 int ret = GNUNET_STRINGS_to_address_ip (addr, strlen (addr),
637 if (ret != GNUNET_OK)
640 return GNUNET_SYSERR;
643 if (socket_address.ss_family == AF_INET)
645 struct IPv4TcpAddress *t4;
646 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
647 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
648 t4->ipv4_addr = in4->sin_addr.s_addr;
649 t4->t4_port = in4->sin_port;
651 *added = sizeof (struct IPv4TcpAddress);
654 else if (socket_address.ss_family == AF_INET6)
656 struct IPv6TcpAddress *t6;
657 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
658 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
659 t6->ipv6_addr = in6->sin6_addr;
660 t6->t6_port = in6->sin6_port;
662 *added = sizeof (struct IPv6TcpAddress);
665 return GNUNET_SYSERR;
669 struct SessionClientCtx
671 const struct GNUNET_SERVER_Client *client;
677 session_lookup_by_client_it (void *cls,
678 const GNUNET_HashCode * key,
681 struct SessionClientCtx *sc_ctx = cls;
682 struct Session *s = value;
684 if (s->client == sc_ctx->client)
694 * Find the session handle for the given client.
696 * @param plugin the plugin
697 * @param client which client to find the session handle for
698 * @return NULL if no matching session exists
700 static struct Session *
701 lookup_session_by_client (struct Plugin *plugin,
702 const struct GNUNET_SERVER_Client *client)
704 struct SessionClientCtx sc_ctx;
706 sc_ctx.client = client;
708 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessionmap, &session_lookup_by_client_it, &sc_ctx);
714 * Create a new session. Also queues a welcome message.
716 * @param plugin the plugin
717 * @param target peer to connect to
718 * @param client client to use
719 * @param is_nat this a NAT session, we should wait for a client to
720 * connect to us from an address, then assign that to
722 * @return new session object
724 static struct Session *
725 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
726 struct GNUNET_SERVER_Client *client, int is_nat)
729 struct PendingMessage *pm;
730 struct WelcomeMessage welcome;
732 if (is_nat != GNUNET_YES)
733 GNUNET_assert (client != NULL);
735 GNUNET_assert (client == NULL);
737 LOG (GNUNET_ERROR_TYPE_DEBUG,
738 "Creating new session for peer `%4s'\n",
739 GNUNET_i2s (target));
740 ret = GNUNET_malloc (sizeof (struct Session));
741 ret->last_activity = GNUNET_TIME_absolute_get ();
742 ret->plugin = plugin;
743 ret->is_nat = is_nat;
744 ret->client = client;
745 ret->target = *target;
746 ret->expecting_welcome = GNUNET_YES;
747 ret->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
748 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
749 sizeof (struct WelcomeMessage));
750 pm->msg = (const char *) &pm[1];
751 pm->message_size = sizeof (struct WelcomeMessage);
752 welcome.header.size = htons (sizeof (struct WelcomeMessage));
753 welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
754 welcome.clientIdentity = *plugin->env->my_identity;
755 memcpy (&pm[1], &welcome, sizeof (welcome));
756 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
757 GNUNET_STATISTICS_update (plugin->env->stats,
758 gettext_noop ("# bytes currently in TCP buffers"),
759 pm->message_size, GNUNET_NO);
760 GNUNET_CONTAINER_DLL_insert (ret->pending_messages_head,
761 ret->pending_messages_tail, pm);
762 if (is_nat != GNUNET_YES)
764 GNUNET_STATISTICS_update (plugin->env->stats,
765 gettext_noop ("# TCP sessions active"), 1,
768 start_session_timeout (ret);
775 * If we have pending messages, ask the server to
776 * transmit them (schedule the respective tasks, etc.)
778 * @param session for which session should we do this
781 process_pending_messages (struct Session *session);
785 * Function called to notify a client about the socket
786 * being ready to queue more data. "buf" will be
787 * NULL and "size" zero if the socket was closed for
788 * writing in the meantime.
791 * @param size number of bytes available in buf
792 * @param buf where the callee should write the message
793 * @return number of bytes written to buf
796 do_transmit (void *cls, size_t size, void *buf)
798 struct Session *session = cls;
799 struct GNUNET_PeerIdentity pid;
800 struct Plugin *plugin;
801 struct PendingMessage *pos;
802 struct PendingMessage *hd;
803 struct PendingMessage *tl;
804 struct GNUNET_TIME_Absolute now;
808 GNUNET_assert (session != NULL);
809 session->transmit_handle = NULL;
810 plugin = session->plugin;
813 LOG (GNUNET_ERROR_TYPE_DEBUG,
814 "Timeout trying to transmit to peer `%4s', discarding message queue.\n",
815 GNUNET_i2s (&session->target));
816 /* timeout; cancel all messages that have already expired */
820 now = GNUNET_TIME_absolute_get ();
821 while ((NULL != (pos = session->pending_messages_head)) &&
822 (pos->timeout.abs_value <= now.abs_value))
824 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
825 session->pending_messages_tail, pos);
826 LOG (GNUNET_ERROR_TYPE_DEBUG,
827 "Failed to transmit %u byte message to `%4s'.\n",
828 pos->message_size, GNUNET_i2s (&session->target));
829 ret += pos->message_size;
830 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
832 /* do this call before callbacks (so that if callbacks destroy
833 * session, they have a chance to cancel actions done by this
835 process_pending_messages (session);
836 pid = session->target;
837 /* no do callbacks and do not use session again since
838 * the callbacks may abort the session */
839 while (NULL != (pos = hd))
841 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
842 if (pos->transmit_cont != NULL)
843 pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR);
846 GNUNET_STATISTICS_update (plugin->env->stats,
847 gettext_noop ("# bytes currently in TCP buffers"),
848 -(int64_t) ret, GNUNET_NO);
849 GNUNET_STATISTICS_update (plugin->env->stats,
851 ("# bytes discarded by TCP (timeout)"), ret,
855 /* copy all pending messages that would fit */
860 while (NULL != (pos = session->pending_messages_head))
862 if (ret + pos->message_size > size)
864 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
865 session->pending_messages_tail, pos);
866 GNUNET_assert (size >= pos->message_size);
867 LOG (GNUNET_ERROR_TYPE_DEBUG,
868 "Transmitting message of type %u\n",
869 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type));
870 /* FIXME: this memcpy can be up to 7% of our total runtime */
871 memcpy (cbuf, pos->msg, pos->message_size);
872 cbuf += pos->message_size;
873 ret += pos->message_size;
874 size -= pos->message_size;
875 GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
877 /* schedule 'continuation' before callbacks so that callbacks that
878 * cancel everything don't cause us to use a session that no longer
880 process_pending_messages (session);
881 session->last_activity = GNUNET_TIME_absolute_get ();
882 pid = session->target;
883 /* we'll now call callbacks that may cancel the session; hence
884 * we should not use 'session' after this point */
885 while (NULL != (pos = hd))
887 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
888 if (pos->transmit_cont != NULL)
889 pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK);
892 GNUNET_assert (hd == NULL);
893 GNUNET_assert (tl == NULL);
894 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n",
896 GNUNET_STATISTICS_update (plugin->env->stats,
897 gettext_noop ("# bytes currently in TCP buffers"),
898 -(int64_t) ret, GNUNET_NO);
899 GNUNET_STATISTICS_update (plugin->env->stats,
900 gettext_noop ("# bytes transmitted via TCP"), ret,
907 * If we have pending messages, ask the server to
908 * transmit them (schedule the respective tasks, etc.)
910 * @param session for which session should we do this
913 process_pending_messages (struct Session *session)
915 struct PendingMessage *pm;
917 GNUNET_assert (session->client != NULL);
918 if (session->transmit_handle != NULL)
920 if (NULL == (pm = session->pending_messages_head))
923 session->transmit_handle =
924 GNUNET_SERVER_notify_transmit_ready (session->client, pm->message_size,
925 GNUNET_TIME_absolute_get_remaining
926 (pm->timeout), &do_transmit,
932 * Functions with this signature are called whenever we need
933 * to close a session due to a disconnect or failure to
934 * establish a connection.
936 * @param session session to close down
939 disconnect_session (struct Session *session)
941 struct PendingMessage *pm;
942 struct Plugin * plugin = session->plugin;
944 LOG (GNUNET_ERROR_TYPE_DEBUG,
945 "Disconnecting session of peer `%s' address `%s'\n",
946 GNUNET_i2s (&session->target),
947 tcp_address_to_string (NULL, session->addr, session->addrlen));
949 stop_session_timeout (session);
951 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (plugin->sessionmap, &session->target.hashPubKey, session))
953 GNUNET_STATISTICS_update (session->plugin->env->stats,
954 gettext_noop ("# TCP sessions active"), -1,
956 dec_sessions (plugin, session, __LINE__);
958 else GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns, &session->target.hashPubKey, session));
961 if (session->transmit_handle != NULL)
963 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
964 session->transmit_handle = NULL;
966 session->plugin->env->session_end (session->plugin->env->cls,
967 &session->target, session);
969 if (GNUNET_SCHEDULER_NO_TASK != session->nat_connection_timeout)
971 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout);
972 session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK;
975 while (NULL != (pm = session->pending_messages_head))
977 LOG (GNUNET_ERROR_TYPE_DEBUG,
979 NULL ? "Could not deliver message to `%4s'.\n" :
980 "Could not deliver message to `%4s', notifying.\n",
981 GNUNET_i2s (&session->target));
982 GNUNET_STATISTICS_update (session->plugin->env->stats,
983 gettext_noop ("# bytes currently in TCP buffers"),
984 -(int64_t) pm->message_size, GNUNET_NO);
985 GNUNET_STATISTICS_update (session->plugin->env->stats,
987 ("# bytes discarded by TCP (disconnect)"),
988 pm->message_size, GNUNET_NO);
989 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
990 session->pending_messages_tail, pm);
991 if (NULL != pm->transmit_cont)
992 pm->transmit_cont (pm->transmit_cont_cls, &session->target,
996 if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK)
998 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
999 if (NULL != session->client)
1000 GNUNET_SERVER_receive_done (session->client, GNUNET_SYSERR);
1002 if (NULL != session->client)
1004 GNUNET_SERVER_client_disconnect (session->client);
1005 GNUNET_SERVER_client_drop (session->client);
1006 session->client = NULL;
1008 GNUNET_free_non_null (session->addr);
1009 GNUNET_assert (NULL == session->transmit_handle);
1010 GNUNET_free (session);
1015 * Function that can be used by the transport service to transmit
1016 * a message using the plugin. Note that in the case of a
1017 * peer disconnecting, the continuation MUST be called
1018 * prior to the disconnect notification itself. This function
1019 * will be called with this peer's HELLO message to initiate
1020 * a fresh connection to another peer.
1022 * @param cls closure
1023 * @param session which session must be used
1024 * @param msgbuf the message to transmit
1025 * @param msgbuf_size number of bytes in 'msgbuf'
1026 * @param priority how important is the message (most plugins will
1027 * ignore message priority and just FIFO)
1028 * @param to how long to wait at most for the transmission (does not
1029 * require plugins to discard the message after the timeout,
1030 * just advisory for the desired delay; most plugins will ignore
1032 * @param cont continuation to call once the message has
1033 * been transmitted (or if the transport is ready
1034 * for the next transmission call; or if the
1035 * peer disconnected...); can be NULL
1036 * @param cont_cls closure for cont
1037 * @return number of bytes used (on the physical network, with overheads);
1038 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1039 * and does NOT mean that the message was not transmitted (DV)
1042 tcp_plugin_send (void *cls,
1043 struct Session *session,
1044 const char *msgbuf, size_t msgbuf_size,
1045 unsigned int priority,
1046 struct GNUNET_TIME_Relative to,
1047 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1049 struct Plugin * plugin = cls;
1050 struct PendingMessage *pm;
1052 GNUNET_assert (plugin != NULL);
1053 GNUNET_assert (session != NULL);
1055 /* create new message entry */
1056 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
1057 pm->msg = (const char *) &pm[1];
1058 memcpy (&pm[1], msgbuf, msgbuf_size);
1059 pm->message_size = msgbuf_size;
1060 pm->timeout = GNUNET_TIME_relative_to_absolute (to);
1061 pm->transmit_cont = cont;
1062 pm->transmit_cont_cls = cont_cls;
1064 LOG (GNUNET_ERROR_TYPE_DEBUG,
1065 "Asked to transmit %u bytes to `%s', added message to list.\n",
1066 msgbuf_size, GNUNET_i2s (&session->target));
1068 reschedule_session_timeout (session);
1070 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessionmap, &session->target.hashPubKey, session))
1072 GNUNET_assert (session->client != NULL);
1074 GNUNET_SERVER_client_set_timeout (session->client,
1075 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1076 GNUNET_STATISTICS_update (plugin->env->stats,
1077 gettext_noop ("# bytes currently in TCP buffers"),
1078 msgbuf_size, GNUNET_NO);
1080 /* append pm to pending_messages list */
1081 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1082 session->pending_messages_tail, pm);
1084 process_pending_messages (session);
1087 else if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->nat_wait_conns, &session->target.hashPubKey, session))
1089 LOG (GNUNET_ERROR_TYPE_DEBUG,
1090 "This NAT WAIT session for peer `%s' is not yet ready!\n",
1091 GNUNET_i2s (&session->target));
1093 GNUNET_STATISTICS_update (plugin->env->stats,
1094 gettext_noop ("# bytes currently in TCP buffers"),
1095 msgbuf_size, GNUNET_NO);
1097 /* append pm to pending_messages list */
1098 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1099 session->pending_messages_tail, pm);
1105 cont (cont_cls, &session->target, GNUNET_SYSERR);
1108 return GNUNET_SYSERR; /* session does not exist here */
1116 struct Session * result;
1120 session_lookup_it (void *cls,
1121 const GNUNET_HashCode * key,
1124 struct SessionItCtx * si_ctx = cls;
1125 struct Session * session = value;
1127 char * a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1128 char * a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1129 LOG (GNUNET_ERROR_TYPE_DEBUG,
1130 "Comparing: %s %u <-> %s %u\n",
1138 if (session->addrlen != si_ctx->addrlen)
1142 if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen))
1147 a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1148 a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1149 LOG (GNUNET_ERROR_TYPE_DEBUG,
1150 "Comparing: %s %u <-> %s %u , OK!\n",
1158 /* Found existing session */
1159 si_ctx->result = session;
1165 * Task cleaning up a NAT connection attempt after timeout
1168 nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1170 struct Session *session = cls;
1172 LOG (GNUNET_ERROR_TYPE_DEBUG,
1173 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
1174 GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen));
1175 disconnect_session (session);
1180 * Create a new session to transmit data to the target
1181 * This session will used to send data to this peer and the plugin will
1182 * notify us by calling the env->session_end function
1184 * @param cls closure
1185 * @param address pointer to the GNUNET_HELLO_Address
1186 * @return the session if the address is valid, NULL otherwise
1188 static struct Session *
1189 tcp_plugin_get_session (void *cls,
1190 const struct GNUNET_HELLO_Address *address)
1192 struct Plugin * plugin = cls;
1193 struct Session * session = NULL;
1197 struct GNUNET_CONNECTION_Handle *sa;
1198 struct sockaddr_in a4;
1199 struct sockaddr_in6 a6;
1200 const struct IPv4TcpAddress *t4;
1201 const struct IPv6TcpAddress *t6;
1202 struct GNUNET_ATS_Information ats;
1203 unsigned int is_natd = GNUNET_NO;
1206 GNUNET_assert (plugin != NULL);
1207 GNUNET_assert (address != NULL);
1208 addrlen = address->address_length;
1209 LOG (GNUNET_ERROR_TYPE_DEBUG,
1210 "Trying to get session for `%s' address of peer `%s'\n",
1211 tcp_address_to_string(NULL, address->address, address->address_length),
1212 GNUNET_i2s (&address->peer));
1214 /* look for existing session */
1216 GNUNET_CONTAINER_multihashmap_contains(plugin->sessionmap, &address->peer.hashPubKey))
1218 struct SessionItCtx si_ctx;
1220 si_ctx.addr = (void *) address->address;
1221 si_ctx.addrlen = address->address_length;
1223 si_ctx.result = NULL;
1225 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessionmap, &address->peer.hashPubKey, &session_lookup_it, &si_ctx);
1226 if (si_ctx.result != NULL)
1228 session = si_ctx.result;
1229 LOG (GNUNET_ERROR_TYPE_DEBUG,
1230 "Found exisiting session for `%s' address `%s' session %p\n",
1231 GNUNET_i2s (&address->peer),
1232 tcp_address_to_string(NULL, address->address, address->address_length),
1236 LOG (GNUNET_ERROR_TYPE_DEBUG,
1237 "Existing sessions did not match address `%s' or peer `%s'\n",
1238 tcp_address_to_string(NULL, address->address, address->address_length),
1239 GNUNET_i2s (&address->peer));
1242 if (addrlen == sizeof (struct IPv6TcpAddress))
1244 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1245 t6 = address->address;
1247 memset (&a6, 0, sizeof (a6));
1248 #if HAVE_SOCKADDR_IN_SIN_LEN
1249 a6.sin6_len = sizeof (a6);
1251 a6.sin6_family = AF_INET6;
1252 a6.sin6_port = t6->t6_port;
1253 if (t6->t6_port == 0)
1254 is_natd = GNUNET_YES;
1255 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1259 else if (addrlen == sizeof (struct IPv4TcpAddress))
1261 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1262 t4 = address->address;
1264 memset (&a4, 0, sizeof (a4));
1265 #if HAVE_SOCKADDR_IN_SIN_LEN
1266 a4.sin_len = sizeof (a4);
1268 a4.sin_family = AF_INET;
1269 a4.sin_port = t4->t4_port;
1270 if (t4->t4_port == 0)
1271 is_natd = GNUNET_YES;
1272 a4.sin_addr.s_addr = t4->ipv4_addr;
1278 LOG (GNUNET_ERROR_TYPE_ERROR,
1279 _("Address of unexpected length: %u\n"), addrlen);
1284 ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs);
1286 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
1288 /* NAT client only works with IPv4 addresses */
1292 if (0 == plugin->max_connections)
1298 if ((is_natd == GNUNET_YES) &&
1300 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1301 &address->peer.hashPubKey)))
1303 /* Only do one NAT punch attempt per peer identity */
1307 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
1309 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1310 &address->peer.hashPubKey)))
1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1313 "Found valid IPv4 NAT address (creating session)!\n") ;
1314 session = create_session (plugin, &address->peer, NULL, GNUNET_YES);
1315 session->addrlen = 0;
1316 session->addr = NULL;
1317 session->ats_address_network_type = ats.value;
1318 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT,
1319 &nat_connect_timeout,
1321 GNUNET_assert (session != NULL);
1322 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
1323 (plugin->nat_wait_conns, &address->peer.hashPubKey, session,
1324 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
1326 LOG (GNUNET_ERROR_TYPE_DEBUG,
1327 "Created NAT WAIT connection to `%4s' at `%s'\n",
1328 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1330 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4))
1334 LOG (GNUNET_ERROR_TYPE_DEBUG,
1335 "Running NAT client for `%4s' at `%s' failed\n",
1336 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1337 disconnect_session (session);
1342 /* create new outbound session */
1343 GNUNET_assert (0 != plugin->max_connections);
1344 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
1347 LOG (GNUNET_ERROR_TYPE_DEBUG,
1348 "Failed to create connection to `%4s' at `%s'\n",
1349 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1352 plugin->max_connections--;
1354 LOG (GNUNET_ERROR_TYPE_DEBUG,
1355 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1356 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
1358 session = create_session (plugin,
1360 GNUNET_SERVER_connect_socket (plugin->server, sa),
1362 session->addr = GNUNET_malloc (addrlen);
1363 memcpy (session->addr, address->address, addrlen);
1364 session->addrlen = addrlen;
1365 session->ats_address_network_type = ats.value;
1367 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &address->peer.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1368 inc_sessions (plugin, session, __LINE__);
1369 LOG (GNUNET_ERROR_TYPE_DEBUG,
1370 "Creating new session for `%s' address `%s' session %p\n",
1371 GNUNET_i2s (&address->peer),
1372 tcp_address_to_string(NULL, address->address, address->address_length),
1374 /* Send TCP Welcome */
1375 process_pending_messages (session);
1382 session_disconnect_it (void *cls,
1383 const GNUNET_HashCode * key,
1386 struct Session *session = value;
1388 GNUNET_STATISTICS_update (session->plugin->env->stats,
1390 ("# transport-service disconnect requests for TCP"),
1392 disconnect_session (session);
1397 * Function that can be called to force a disconnect from the
1398 * specified neighbour. This should also cancel all previously
1399 * scheduled transmissions. Obviously the transmission may have been
1400 * partially completed already, which is OK. The plugin is supposed
1401 * to close the connection (if applicable) and no longer call the
1402 * transmit continuation(s).
1404 * Finally, plugin MUST NOT call the services's receive function to
1405 * notify the service that the connection to the specified target was
1406 * closed after a getting this call.
1408 * @param cls closure
1409 * @param target peer for which the last transmission is
1413 tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1415 struct Plugin *plugin = cls;
1417 LOG (GNUNET_ERROR_TYPE_DEBUG,
1418 "Disconnecting peer `%4s'\n", GNUNET_i2s (target));
1419 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, &target->hashPubKey, &session_disconnect_it, plugin);
1420 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->nat_wait_conns, &target->hashPubKey, &session_disconnect_it, plugin);
1425 * Context for address to string conversion.
1427 struct PrettyPrinterContext
1430 * Function to call with the result.
1432 GNUNET_TRANSPORT_AddressStringCallback asc;
1435 * Clsoure for 'asc'.
1440 * Port to add after the IP address.
1449 * Append our port and forward the result.
1451 * @param cls the 'struct PrettyPrinterContext*'
1452 * @param hostname hostname part of the address
1455 append_port (void *cls, const char *hostname)
1457 struct PrettyPrinterContext *ppc = cls;
1460 if (hostname == NULL)
1462 ppc->asc (ppc->asc_cls, NULL);
1466 if (GNUNET_YES == ppc->ipv6)
1467 GNUNET_asprintf (&ret, "[%s]:%d", hostname, ppc->port);
1469 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
1470 ppc->asc (ppc->asc_cls, ret);
1476 * Convert the transports address to a nice, human-readable
1479 * @param cls closure
1480 * @param type name of the transport that generated the address
1481 * @param addr one of the addresses of the host, NULL for the last address
1482 * the specific address format depends on the transport
1483 * @param addrlen length of the address
1484 * @param numeric should (IP) addresses be displayed in numeric form?
1485 * @param timeout after how long should we give up?
1486 * @param asc function to call on each string
1487 * @param asc_cls closure for asc
1490 tcp_plugin_address_pretty_printer (void *cls, const char *type,
1491 const void *addr, size_t addrlen,
1493 struct GNUNET_TIME_Relative timeout,
1494 GNUNET_TRANSPORT_AddressStringCallback asc,
1497 struct PrettyPrinterContext *ppc;
1500 struct sockaddr_in a4;
1501 struct sockaddr_in6 a6;
1502 const struct IPv4TcpAddress *t4;
1503 const struct IPv6TcpAddress *t6;
1506 if (addrlen == sizeof (struct IPv6TcpAddress))
1509 memset (&a6, 0, sizeof (a6));
1510 a6.sin6_family = AF_INET6;
1511 a6.sin6_port = t6->t6_port;
1512 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1513 port = ntohs (t6->t6_port);
1517 else if (addrlen == sizeof (struct IPv4TcpAddress))
1520 memset (&a4, 0, sizeof (a4));
1521 a4.sin_family = AF_INET;
1522 a4.sin_port = t4->t4_port;
1523 a4.sin_addr.s_addr = t4->ipv4_addr;
1524 port = ntohs (t4->t4_port);
1528 else if (0 == addrlen)
1530 asc (asc_cls, "<inbound connection>");
1531 asc (asc_cls, NULL);
1536 /* invalid address */
1537 GNUNET_break_op (0);
1538 asc (asc_cls, NULL);
1541 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
1542 if (addrlen == sizeof (struct IPv6TcpAddress))
1543 ppc->ipv6 = GNUNET_YES;
1545 ppc->ipv6 = GNUNET_NO;
1547 ppc->asc_cls = asc_cls;
1549 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1554 * Check if the given port is plausible (must be either our listen
1555 * port or our advertised port), or any port if we are behind NAT
1556 * and do not have a port open. If it is neither, we return
1559 * @param plugin global variables
1560 * @param in_port port number to check
1561 * @return GNUNET_OK if port is either open_port or adv_port
1564 check_port (struct Plugin *plugin, uint16_t in_port)
1566 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port))
1568 return GNUNET_SYSERR;
1573 * Function that will be called to check if a binary address for this
1574 * plugin is well-formed and corresponds to an address for THIS peer
1575 * (as per our configuration). Naturally, if absolutely necessary,
1576 * plugins can be a bit conservative in their answer, but in general
1577 * plugins should make sure that the address does not redirect
1578 * traffic to a 3rd party that might try to man-in-the-middle our
1581 * @param cls closure, our 'struct Plugin*'
1582 * @param addr pointer to the address
1583 * @param addrlen length of addr
1584 * @return GNUNET_OK if this is a plausible address for this peer
1585 * and transport, GNUNET_SYSERR if not
1588 tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1590 struct Plugin *plugin = cls;
1591 struct IPv4TcpAddress *v4;
1592 struct IPv6TcpAddress *v6;
1594 if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
1595 (addrlen != sizeof (struct IPv6TcpAddress)))
1597 GNUNET_break_op (0);
1598 return GNUNET_SYSERR;
1600 if (addrlen == sizeof (struct IPv4TcpAddress))
1602 v4 = (struct IPv4TcpAddress *) addr;
1603 if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port)))
1604 return GNUNET_SYSERR;
1606 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
1607 sizeof (struct in_addr)))
1608 return GNUNET_SYSERR;
1612 v6 = (struct IPv6TcpAddress *) addr;
1613 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1615 GNUNET_break_op (0);
1616 return GNUNET_SYSERR;
1618 if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port)))
1619 return GNUNET_SYSERR;
1621 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
1622 sizeof (struct in6_addr)))
1623 return GNUNET_SYSERR;
1630 * We've received a nat probe from this peer via TCP. Finish
1631 * creating the client session and resume sending of queued
1634 * @param cls closure
1635 * @param client identification of the client
1636 * @param message the actual message
1639 handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1640 const struct GNUNET_MessageHeader *message)
1642 struct Plugin *plugin = cls;
1643 struct Session *session;
1644 const struct TCP_NAT_ProbeMessage *tcp_nat_probe;
1647 struct IPv4TcpAddress *t4;
1648 struct IPv6TcpAddress *t6;
1649 const struct sockaddr_in *s4;
1650 const struct sockaddr_in6 *s6;
1652 LOG (GNUNET_ERROR_TYPE_DEBUG, "received NAT probe\n");
1654 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
1655 * a connection to this peer by running gnunet-nat-client. This peer
1656 * received the punch message and now wants us to use the new connection
1657 * as the default for that peer. Do so and then send a WELCOME message
1658 * so we can really be connected!
1660 if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
1662 GNUNET_break_op (0);
1663 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1667 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
1669 memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity,
1670 sizeof (struct GNUNET_PeerIdentity)))
1672 /* refuse connections from ourselves */
1673 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1678 GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns,
1680 clientIdentity.hashPubKey);
1681 if (session == NULL)
1683 LOG (GNUNET_ERROR_TYPE_DEBUG,
1684 "Did NOT find session for NAT probe!\n");
1685 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1688 LOG (GNUNET_ERROR_TYPE_DEBUG,
1689 "Found session for NAT probe!\n");
1691 if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK)
1693 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout);
1694 session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK;
1697 GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove
1698 (plugin->nat_wait_conns,
1699 &tcp_nat_probe->clientIdentity.hashPubKey,
1700 session) == GNUNET_YES);
1701 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1704 GNUNET_free (session);
1705 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1709 GNUNET_SERVER_client_keep (client);
1710 session->client = client;
1711 session->last_activity = GNUNET_TIME_absolute_get ();
1712 session->inbound = GNUNET_NO;
1713 LOG (GNUNET_ERROR_TYPE_DEBUG,
1714 "Found address `%s' for incoming connection\n",
1715 GNUNET_a2s (vaddr, alen));
1716 switch (((const struct sockaddr *) vaddr)->sa_family)
1720 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1721 t4->t4_port = s4->sin_port;
1722 t4->ipv4_addr = s4->sin_addr.s_addr;
1724 session->addrlen = sizeof (struct IPv4TcpAddress);
1728 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1729 t6->t6_port = s6->sin6_port;
1730 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1732 session->addrlen = sizeof (struct IPv6TcpAddress);
1735 GNUNET_break_op (0);
1736 LOG (GNUNET_ERROR_TYPE_DEBUG,
1737 "Bad address for incoming connection!\n");
1738 GNUNET_free (vaddr);
1740 GNUNET_SERVER_client_drop (client);
1741 GNUNET_free (session);
1742 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1745 GNUNET_free (vaddr);
1747 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &session->target.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1748 inc_sessions (plugin, session, __LINE__);
1749 GNUNET_STATISTICS_update (plugin->env->stats,
1750 gettext_noop ("# TCP sessions active"), 1,
1752 process_pending_messages (session);
1753 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1758 * We've received a welcome from this peer via TCP. Possibly create a
1759 * fresh client record and send back our welcome.
1761 * @param cls closure
1762 * @param client identification of the client
1763 * @param message the actual message
1766 handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1767 const struct GNUNET_MessageHeader *message)
1769 struct Plugin *plugin = cls;
1770 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message;
1771 struct Session *session;
1774 struct IPv4TcpAddress *t4;
1775 struct IPv6TcpAddress *t6;
1776 const struct sockaddr_in *s4;
1777 const struct sockaddr_in6 *s6;
1780 memcmp (&wm->clientIdentity, plugin->env->my_identity,
1781 sizeof (struct GNUNET_PeerIdentity)))
1783 /* refuse connections from ourselves */
1784 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1787 LOG (GNUNET_ERROR_TYPE_DEBUG,
1788 "Received %s message from `%4s'\n", "WELCOME",
1789 GNUNET_i2s (&wm->clientIdentity));
1790 GNUNET_STATISTICS_update (plugin->env->stats,
1791 gettext_noop ("# TCP WELCOME messages received"), 1,
1793 session = lookup_session_by_client (plugin, client);
1794 if (session != NULL)
1796 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1798 LOG (GNUNET_ERROR_TYPE_DEBUG,
1799 "Found existing session %p for peer `%s'\n",
1801 GNUNET_a2s (vaddr, alen));
1802 GNUNET_free (vaddr);
1807 GNUNET_SERVER_client_keep (client);
1808 session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO);
1809 session->inbound = GNUNET_YES;
1810 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1812 if (alen == sizeof (struct sockaddr_in))
1815 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1816 t4->t4_port = s4->sin_port;
1817 t4->ipv4_addr = s4->sin_addr.s_addr;
1819 session->addrlen = sizeof (struct IPv4TcpAddress);
1821 else if (alen == sizeof (struct sockaddr_in6))
1824 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1825 t6->t6_port = s6->sin6_port;
1826 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1828 session->addrlen = sizeof (struct IPv6TcpAddress);
1831 struct GNUNET_ATS_Information ats;
1832 ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen);
1833 session->ats_address_network_type = ats.value;
1835 GNUNET_free (vaddr);
1839 LOG (GNUNET_ERROR_TYPE_DEBUG,
1840 "Did not obtain TCP socket address for incoming connection\n");
1842 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &wm->clientIdentity.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1843 inc_sessions (plugin, session, __LINE__);
1846 if (session->expecting_welcome != GNUNET_YES)
1848 GNUNET_break_op (0);
1849 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1852 session->last_activity = GNUNET_TIME_absolute_get ();
1853 session->expecting_welcome = GNUNET_NO;
1856 process_pending_messages (session);
1858 GNUNET_SERVER_client_set_timeout (client,
1859 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1860 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1865 * Task to signal the server that we can continue
1866 * receiving from the TCP client now.
1868 * @param cls the 'struct Session*'
1869 * @param tc task context (unused)
1872 delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1874 struct Session *session = cls;
1875 struct GNUNET_TIME_Relative delay;
1876 struct GNUNET_ATS_Information ats;
1878 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
1880 session->plugin->env->receive (session->plugin->env->cls,
1881 &session->target, NULL, &ats, 0, session,
1883 reschedule_session_timeout (session);
1885 if (delay.rel_value == 0)
1886 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
1888 session->receive_delay_task =
1889 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
1894 * We've received data for this peer via TCP. Unbox,
1895 * compute latency and forward.
1897 * @param cls closure
1898 * @param client identification of the client
1899 * @param message the actual message
1902 handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1903 const struct GNUNET_MessageHeader *message)
1905 struct Plugin *plugin = cls;
1906 struct Session *session;
1907 struct GNUNET_TIME_Relative delay;
1910 type = ntohs (message->type);
1911 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
1912 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
1914 /* We don't want to propagate WELCOME and NAT Probe messages up! */
1915 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1918 session = lookup_session_by_client (plugin, client);
1919 if (NULL == session)
1921 /* No inbound session found */
1925 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1926 LOG (GNUNET_ERROR_TYPE_ERROR,
1927 "Received unexpected %u bytes of type %u from `%s'\n",
1928 (unsigned int) ntohs (message->size),
1929 (unsigned int) ntohs (message->type),
1930 GNUNET_a2s(vaddr, alen));
1931 GNUNET_break_op (0);
1932 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1933 GNUNET_free_non_null(vaddr);
1936 else if (GNUNET_YES == session->expecting_welcome)
1938 /* Session is expecting WELCOME message */
1942 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1943 LOG (GNUNET_ERROR_TYPE_ERROR,
1944 "Received unexpected %u bytes of type %u from `%s'\n",
1945 (unsigned int) ntohs (message->size),
1946 (unsigned int) ntohs (message->type),
1947 GNUNET_a2s(vaddr, alen));
1948 GNUNET_break_op (0);
1949 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1950 GNUNET_free_non_null(vaddr);
1954 session->last_activity = GNUNET_TIME_absolute_get ();
1955 LOG (GNUNET_ERROR_TYPE_DEBUG,
1956 "Passing %u bytes of type %u from `%4s' to transport service.\n",
1957 (unsigned int) ntohs (message->size),
1958 (unsigned int) ntohs (message->type),
1959 GNUNET_i2s (&session->target));
1961 GNUNET_STATISTICS_update (plugin->env->stats,
1962 gettext_noop ("# bytes received via TCP"),
1963 ntohs (message->size), GNUNET_NO);
1964 struct GNUNET_ATS_Information distance[2];
1966 distance[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1967 distance[0].value = htonl (1);
1968 distance[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1969 distance[1].value = session->ats_address_network_type;
1970 GNUNET_break (ntohl(session->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED);
1972 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains_value (plugin->sessionmap,
1973 &session->target.hashPubKey,
1976 delay = plugin->env->receive (plugin->env->cls,
1979 (const struct GNUNET_ATS_Information *) &distance,
1981 (GNUNET_YES == session->inbound) ? NULL : session->addr,
1982 (GNUNET_YES == session->inbound) ? 0 : session->addrlen);
1984 reschedule_session_timeout (session);
1986 if (delay.rel_value == 0)
1988 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1992 LOG (GNUNET_ERROR_TYPE_DEBUG,
1993 "Throttling receiving from `%s' for %llu ms\n",
1994 GNUNET_i2s (&session->target),
1995 (unsigned long long) delay.rel_value);
1996 GNUNET_SERVER_disable_receive_done_warning (client);
1997 session->receive_delay_task =
1998 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
2004 * Functions with this signature are called whenever a peer
2005 * is disconnected on the network level.
2007 * @param cls closure
2008 * @param client identification of the client
2011 disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
2013 struct Plugin *plugin = cls;
2014 struct Session *session;
2018 plugin->max_connections++;
2019 session = lookup_session_by_client (plugin, client);
2020 if (session == NULL)
2021 return; /* unknown, nothing to do */
2022 LOG (GNUNET_ERROR_TYPE_DEBUG,
2023 "Destroying session of `%4s' with %s due to network-level disconnect.\n",
2024 GNUNET_i2s (&session->target),
2026 NULL) ? tcp_address_to_string (session->plugin,
2030 GNUNET_STATISTICS_update (session->plugin->env->stats,
2032 ("# network-level TCP disconnect events"), 1,
2034 disconnect_session (session);
2039 * We can now send a probe message, copy into buffer to really send.
2041 * @param cls closure, a struct TCPProbeContext
2042 * @param size max size to copy
2043 * @param buf buffer to copy message to
2044 * @return number of bytes copied into buf
2047 notify_send_probe (void *cls, size_t size, void *buf)
2049 struct TCPProbeContext *tcp_probe_ctx = cls;
2050 struct Plugin *plugin = tcp_probe_ctx->plugin;
2053 tcp_probe_ctx->transmit_handle = NULL;
2054 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
2058 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock);
2059 GNUNET_free (tcp_probe_ctx);
2062 GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
2063 memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
2064 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
2065 tcp_probe_ctx->sock);
2066 ret = sizeof (tcp_probe_ctx->message);
2067 GNUNET_free (tcp_probe_ctx);
2073 * Function called by the NAT subsystem suggesting another peer wants
2074 * to connect to us via connection reversal. Try to connect back to the
2077 * @param cls closure
2078 * @param addr address to try
2079 * @param addrlen number of bytes in addr
2082 try_connection_reversal (void *cls, const struct sockaddr *addr,
2085 struct Plugin *plugin = cls;
2086 struct GNUNET_CONNECTION_Handle *sock;
2087 struct TCPProbeContext *tcp_probe_ctx;
2090 * We have received an ICMP response, ostensibly from a peer
2091 * that wants to connect to us! Send a message to establish a connection.
2093 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
2096 /* failed for some odd reason (out of sockets?); ignore attempt */
2100 /* FIXME: do we need to track these probe context objects so that
2101 * we can clean them up on plugin unload? */
2102 tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
2103 tcp_probe_ctx->message.header.size =
2104 htons (sizeof (struct TCP_NAT_ProbeMessage));
2105 tcp_probe_ctx->message.header.type =
2106 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
2107 memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity,
2108 sizeof (struct GNUNET_PeerIdentity));
2109 tcp_probe_ctx->plugin = plugin;
2110 tcp_probe_ctx->sock = sock;
2111 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail,
2113 tcp_probe_ctx->transmit_handle =
2114 GNUNET_CONNECTION_notify_transmit_ready (sock,
2115 ntohs (tcp_probe_ctx->
2116 message.header.size),
2117 GNUNET_TIME_UNIT_FOREVER_REL,
2125 * Session was idle, so disconnect it
2128 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2130 GNUNET_assert (NULL != cls);
2131 struct Session *s = cls;
2133 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2135 "Session %p was idle for %llu, disconnecting\n",
2136 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2137 /* call session destroy function */
2138 disconnect_session(s);
2143 * Start session timeout
2146 start_session_timeout (struct Session *s)
2148 GNUNET_assert (NULL != s);
2149 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
2150 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2154 "Timeout for session %p set to %llu\n",
2156 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2161 * Increment session timeout due to activity
2164 reschedule_session_timeout (struct Session *s)
2166 GNUNET_assert (NULL != s);
2167 if (GNUNET_SCHEDULER_NO_TASK == s->timeout_task)
2169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2170 "Timeout for peer `%s' %s not scheduled\n",
2171 GNUNET_i2s (&s->target),
2172 tcp_address_to_string(NULL, s->addr, s->addrlen));
2175 GNUNET_SCHEDULER_cancel (s->timeout_task);
2176 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n",
2181 (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2189 stop_session_timeout (struct Session *s)
2191 GNUNET_assert (NULL != s);
2192 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
2194 GNUNET_SCHEDULER_cancel (s->timeout_task);
2195 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2197 "Timeout rescheduled for session %p canceled\n",
2198 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2203 "Timeout for session %p was not active\n",
2210 * Entry point for the plugin.
2212 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
2213 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
2216 libgnunet_plugin_transport_tcp_init (void *cls)
2218 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
2219 {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
2220 sizeof (struct WelcomeMessage)},
2221 {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
2222 sizeof (struct TCP_NAT_ProbeMessage)},
2223 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
2226 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2227 struct GNUNET_TRANSPORT_PluginFunctions *api;
2228 struct Plugin *plugin;
2229 struct GNUNET_SERVICE_Context *service;
2230 unsigned long long aport;
2231 unsigned long long bport;
2232 unsigned long long max_connections;
2234 struct GNUNET_TIME_Relative idle_timeout;
2236 struct sockaddr **addrs;
2237 socklen_t *addrlens;
2239 if (NULL == env->receive)
2241 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2242 initialze the plugin or the API */
2243 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2245 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
2246 api->address_to_string = &tcp_address_to_string;
2247 api->string_to_address = &tcp_string_to_address;
2252 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
2255 max_connections = 128;
2259 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT",
2260 &bport)) || (bport > 65535) ||
2262 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
2263 "ADVERTISED-PORT", &aport)) &&
2266 LOG (GNUNET_ERROR_TYPE_ERROR,
2268 ("Require valid port number for service `%s' in configuration!\n"),
2278 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, GNUNET_SERVICE_OPTION_NONE);
2279 if (service == NULL)
2281 LOG (GNUNET_ERROR_TYPE_WARNING,
2282 _("Failed to start service.\n"));
2289 plugin = GNUNET_malloc (sizeof (struct Plugin));
2290 plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create(max_connections);
2291 plugin->max_connections = max_connections;
2292 plugin->open_port = bport;
2293 plugin->adv_port = aport;
2295 plugin->lsock = NULL;
2296 if ((service != NULL) &&
2299 GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs,
2303 GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret,
2304 (const struct sockaddr **) addrs, addrlens,
2305 &tcp_nat_port_map_callback,
2306 &try_connection_reversal, plugin);
2310 GNUNET_assert (addrs[ret] != NULL);
2311 GNUNET_free (addrs[ret]);
2313 GNUNET_free_non_null (addrs);
2314 GNUNET_free_non_null (addrlens);
2319 GNUNET_NAT_register (env->cfg, GNUNET_YES, 0, 0, NULL, NULL, NULL,
2320 &try_connection_reversal, plugin);
2322 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2324 api->send = &tcp_plugin_send;
2325 api->get_session = &tcp_plugin_get_session;
2327 api->disconnect = &tcp_plugin_disconnect;
2328 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
2329 api->check_address = &tcp_plugin_check_address;
2330 api->address_to_string = &tcp_address_to_string;
2331 api->string_to_address = &tcp_string_to_address;
2332 plugin->service = service;
2333 if (service != NULL)
2335 plugin->server = GNUNET_SERVICE_get_server (service);
2340 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp",
2341 "TIMEOUT", &idle_timeout))
2343 LOG (GNUNET_ERROR_TYPE_ERROR,
2344 _("Failed to find option %s in section %s!\n"),
2345 "TIMEOUT", "transport-tcp");
2346 if (plugin->nat != NULL)
2347 GNUNET_NAT_unregister (plugin->nat);
2348 GNUNET_free (plugin);
2353 GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin,
2354 NULL, idle_timeout, GNUNET_YES);
2356 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
2357 memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
2359 i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler);
2361 plugin->handlers[i].callback_cls = plugin;
2362 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
2363 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
2364 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
2366 LOG (GNUNET_ERROR_TYPE_INFO,
2367 _("TCP transport listening on port %llu\n"), bport);
2369 LOG (GNUNET_ERROR_TYPE_INFO,
2371 ("TCP transport not listening on any port (client only)\n"));
2373 LOG (GNUNET_ERROR_TYPE_INFO,
2375 ("TCP transport advertises itself as being on port %llu\n"),
2377 /* Initially set connections to 0 */
2378 GNUNET_STATISTICS_set(plugin->env->stats,
2379 gettext_noop ("# TCP sessions active"), 0,
2386 * Exit point from the plugin.
2389 libgnunet_plugin_transport_tcp_done (void *cls)
2391 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2392 struct Plugin *plugin = api->cls;
2393 struct TCPProbeContext *tcp_probe;
2400 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
2402 /* Removing leftover sessions */
2403 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL);
2404 /* Removing leftover NAT sessions */
2405 GNUNET_CONTAINER_multihashmap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL);
2407 if (plugin->service != NULL)
2408 GNUNET_SERVICE_stop (plugin->service);
2410 GNUNET_SERVER_destroy (plugin->server);
2411 GNUNET_free (plugin->handlers);
2412 if (plugin->nat != NULL)
2413 GNUNET_NAT_unregister (plugin->nat);
2414 while (NULL != (tcp_probe = plugin->probe_head))
2416 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
2418 GNUNET_CONNECTION_destroy (tcp_probe->sock);
2419 GNUNET_free (tcp_probe);
2421 GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns);
2422 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessionmap);
2423 GNUNET_free (plugin);
2428 /* end of plugin_transport_tcp.c */