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 (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK)
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 (session->client != NULL)
1000 GNUNET_SERVER_receive_done (session->client, GNUNET_SYSERR);
1002 if (session->client != NULL)
1004 GNUNET_SERVER_client_drop (session->client);
1005 session->client = NULL;
1009 GNUNET_free_non_null (session->addr);
1010 GNUNET_assert (NULL == session->transmit_handle);
1011 GNUNET_free (session);
1016 * Function that can be used by the transport service to transmit
1017 * a message using the plugin. Note that in the case of a
1018 * peer disconnecting, the continuation MUST be called
1019 * prior to the disconnect notification itself. This function
1020 * will be called with this peer's HELLO message to initiate
1021 * a fresh connection to another peer.
1023 * @param cls closure
1024 * @param session which session must be used
1025 * @param msgbuf the message to transmit
1026 * @param msgbuf_size number of bytes in 'msgbuf'
1027 * @param priority how important is the message (most plugins will
1028 * ignore message priority and just FIFO)
1029 * @param to how long to wait at most for the transmission (does not
1030 * require plugins to discard the message after the timeout,
1031 * just advisory for the desired delay; most plugins will ignore
1033 * @param cont continuation to call once the message has
1034 * been transmitted (or if the transport is ready
1035 * for the next transmission call; or if the
1036 * peer disconnected...); can be NULL
1037 * @param cont_cls closure for cont
1038 * @return number of bytes used (on the physical network, with overheads);
1039 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1040 * and does NOT mean that the message was not transmitted (DV)
1043 tcp_plugin_send (void *cls,
1044 struct Session *session,
1045 const char *msgbuf, size_t msgbuf_size,
1046 unsigned int priority,
1047 struct GNUNET_TIME_Relative to,
1048 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1050 struct Plugin * plugin = cls;
1051 struct PendingMessage *pm;
1053 GNUNET_assert (plugin != NULL);
1054 GNUNET_assert (session != NULL);
1056 /* create new message entry */
1057 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
1058 pm->msg = (const char *) &pm[1];
1059 memcpy (&pm[1], msgbuf, msgbuf_size);
1060 pm->message_size = msgbuf_size;
1061 pm->timeout = GNUNET_TIME_relative_to_absolute (to);
1062 pm->transmit_cont = cont;
1063 pm->transmit_cont_cls = cont_cls;
1065 LOG (GNUNET_ERROR_TYPE_DEBUG,
1066 "Asked to transmit %u bytes to `%s', added message to list.\n",
1067 msgbuf_size, GNUNET_i2s (&session->target));
1069 reschedule_session_timeout (session);
1071 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessionmap, &session->target.hashPubKey, session))
1073 GNUNET_assert (session->client != NULL);
1075 GNUNET_SERVER_client_set_timeout (session->client,
1076 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1077 GNUNET_STATISTICS_update (plugin->env->stats,
1078 gettext_noop ("# bytes currently in TCP buffers"),
1079 msgbuf_size, GNUNET_NO);
1081 /* append pm to pending_messages list */
1082 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1083 session->pending_messages_tail, pm);
1085 process_pending_messages (session);
1088 else if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->nat_wait_conns, &session->target.hashPubKey, session))
1090 LOG (GNUNET_ERROR_TYPE_DEBUG,
1091 "This NAT WAIT session for peer `%s' is not yet ready!\n",
1092 GNUNET_i2s (&session->target));
1094 GNUNET_STATISTICS_update (plugin->env->stats,
1095 gettext_noop ("# bytes currently in TCP buffers"),
1096 msgbuf_size, GNUNET_NO);
1098 /* append pm to pending_messages list */
1099 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1100 session->pending_messages_tail, pm);
1106 cont (cont_cls, &session->target, GNUNET_SYSERR);
1109 return GNUNET_SYSERR; /* session does not exist here */
1117 struct Session * result;
1121 session_lookup_it (void *cls,
1122 const GNUNET_HashCode * key,
1125 struct SessionItCtx * si_ctx = cls;
1126 struct Session * session = value;
1128 char * a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1129 char * a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1130 LOG (GNUNET_ERROR_TYPE_DEBUG,
1131 "Comparing: %s %u <-> %s %u\n",
1139 if (session->addrlen != si_ctx->addrlen)
1143 if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen))
1148 a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1149 a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1150 LOG (GNUNET_ERROR_TYPE_DEBUG,
1151 "Comparing: %s %u <-> %s %u , OK!\n",
1159 /* Found existing session */
1160 si_ctx->result = session;
1166 * Task cleaning up a NAT connection attempt after timeout
1169 nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1171 struct Session *session = cls;
1173 LOG (GNUNET_ERROR_TYPE_DEBUG,
1174 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
1175 GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen));
1176 disconnect_session (session);
1181 * Create a new session to transmit data to the target
1182 * This session will used to send data to this peer and the plugin will
1183 * notify us by calling the env->session_end function
1185 * @param cls closure
1186 * @param address pointer to the GNUNET_HELLO_Address
1187 * @return the session if the address is valid, NULL otherwise
1189 static struct Session *
1190 tcp_plugin_get_session (void *cls,
1191 const struct GNUNET_HELLO_Address *address)
1193 struct Plugin * plugin = cls;
1194 struct Session * session = NULL;
1198 struct GNUNET_CONNECTION_Handle *sa;
1199 struct sockaddr_in a4;
1200 struct sockaddr_in6 a6;
1201 const struct IPv4TcpAddress *t4;
1202 const struct IPv6TcpAddress *t6;
1203 struct GNUNET_ATS_Information ats;
1204 unsigned int is_natd = GNUNET_NO;
1207 GNUNET_assert (plugin != NULL);
1208 GNUNET_assert (address != NULL);
1209 addrlen = address->address_length;
1210 LOG (GNUNET_ERROR_TYPE_DEBUG,
1211 "Trying to get session for `%s' address of peer `%s'\n",
1212 tcp_address_to_string(NULL, address->address, address->address_length),
1213 GNUNET_i2s (&address->peer));
1215 /* look for existing session */
1217 GNUNET_CONTAINER_multihashmap_contains(plugin->sessionmap, &address->peer.hashPubKey))
1219 struct SessionItCtx si_ctx;
1221 si_ctx.addr = (void *) address->address;
1222 si_ctx.addrlen = address->address_length;
1224 si_ctx.result = NULL;
1226 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessionmap, &address->peer.hashPubKey, &session_lookup_it, &si_ctx);
1227 if (si_ctx.result != NULL)
1229 session = si_ctx.result;
1230 LOG (GNUNET_ERROR_TYPE_DEBUG,
1231 "Found exisiting session for `%s' address `%s' session %p\n",
1232 GNUNET_i2s (&address->peer),
1233 tcp_address_to_string(NULL, address->address, address->address_length),
1237 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Existing sessions did not match address `%s' or peer `%s'\n",
1239 tcp_address_to_string(NULL, address->address, address->address_length),
1240 GNUNET_i2s (&address->peer));
1243 if (addrlen == sizeof (struct IPv6TcpAddress))
1245 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1246 t6 = address->address;
1248 memset (&a6, 0, sizeof (a6));
1249 #if HAVE_SOCKADDR_IN_SIN_LEN
1250 a6.sin6_len = sizeof (a6);
1252 a6.sin6_family = AF_INET6;
1253 a6.sin6_port = t6->t6_port;
1254 if (t6->t6_port == 0)
1255 is_natd = GNUNET_YES;
1256 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1260 else if (addrlen == sizeof (struct IPv4TcpAddress))
1262 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1263 t4 = address->address;
1265 memset (&a4, 0, sizeof (a4));
1266 #if HAVE_SOCKADDR_IN_SIN_LEN
1267 a4.sin_len = sizeof (a4);
1269 a4.sin_family = AF_INET;
1270 a4.sin_port = t4->t4_port;
1271 if (t4->t4_port == 0)
1272 is_natd = GNUNET_YES;
1273 a4.sin_addr.s_addr = t4->ipv4_addr;
1279 LOG (GNUNET_ERROR_TYPE_ERROR,
1280 _("Address of unexpected length: %u\n"), addrlen);
1285 ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs);
1287 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
1289 /* NAT client only works with IPv4 addresses */
1293 if (0 == plugin->max_connections)
1299 if ((is_natd == GNUNET_YES) &&
1301 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1302 &address->peer.hashPubKey)))
1304 /* Only do one NAT punch attempt per peer identity */
1308 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
1310 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1311 &address->peer.hashPubKey)))
1313 LOG (GNUNET_ERROR_TYPE_DEBUG,
1314 "Found valid IPv4 NAT address (creating session)!\n") ;
1315 session = create_session (plugin, &address->peer, NULL, GNUNET_YES);
1316 session->addrlen = 0;
1317 session->addr = NULL;
1318 session->ats_address_network_type = ats.value;
1319 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT,
1320 &nat_connect_timeout,
1322 GNUNET_assert (session != NULL);
1323 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
1324 (plugin->nat_wait_conns, &address->peer.hashPubKey, session,
1325 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
1327 LOG (GNUNET_ERROR_TYPE_DEBUG,
1328 "Created NAT WAIT connection to `%4s' at `%s'\n",
1329 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1331 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4))
1335 LOG (GNUNET_ERROR_TYPE_DEBUG,
1336 "Running NAT client for `%4s' at `%s' failed\n",
1337 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1338 disconnect_session (session);
1343 /* create new outbound session */
1344 GNUNET_assert (0 != plugin->max_connections);
1345 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
1348 LOG (GNUNET_ERROR_TYPE_DEBUG,
1349 "Failed to create connection to `%4s' at `%s'\n",
1350 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1353 plugin->max_connections--;
1355 LOG (GNUNET_ERROR_TYPE_DEBUG,
1356 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1357 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
1359 session = create_session (plugin,
1361 GNUNET_SERVER_connect_socket (plugin->server, sa),
1363 session->addr = GNUNET_malloc (addrlen);
1364 memcpy (session->addr, address->address, addrlen);
1365 session->addrlen = addrlen;
1366 session->ats_address_network_type = ats.value;
1368 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &address->peer.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1369 inc_sessions (plugin, session, __LINE__);
1370 LOG (GNUNET_ERROR_TYPE_DEBUG,
1371 "Creating new session for `%s' address `%s' session %p\n",
1372 GNUNET_i2s (&address->peer),
1373 tcp_address_to_string(NULL, address->address, address->address_length),
1375 /* Send TCP Welcome */
1376 process_pending_messages (session);
1383 session_disconnect_it (void *cls,
1384 const GNUNET_HashCode * key,
1387 struct Session *session = value;
1389 GNUNET_STATISTICS_update (session->plugin->env->stats,
1391 ("# transport-service disconnect requests for TCP"),
1393 disconnect_session (session);
1398 * Function that can be called to force a disconnect from the
1399 * specified neighbour. This should also cancel all previously
1400 * scheduled transmissions. Obviously the transmission may have been
1401 * partially completed already, which is OK. The plugin is supposed
1402 * to close the connection (if applicable) and no longer call the
1403 * transmit continuation(s).
1405 * Finally, plugin MUST NOT call the services's receive function to
1406 * notify the service that the connection to the specified target was
1407 * closed after a getting this call.
1409 * @param cls closure
1410 * @param target peer for which the last transmission is
1414 tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1416 struct Plugin *plugin = cls;
1418 LOG (GNUNET_ERROR_TYPE_DEBUG,
1419 "Disconnecting peer `%4s'\n", GNUNET_i2s (target));
1420 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, &target->hashPubKey, &session_disconnect_it, plugin);
1421 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->nat_wait_conns, &target->hashPubKey, &session_disconnect_it, plugin);
1426 * Context for address to string conversion.
1428 struct PrettyPrinterContext
1431 * Function to call with the result.
1433 GNUNET_TRANSPORT_AddressStringCallback asc;
1436 * Clsoure for 'asc'.
1441 * Port to add after the IP address.
1450 * Append our port and forward the result.
1452 * @param cls the 'struct PrettyPrinterContext*'
1453 * @param hostname hostname part of the address
1456 append_port (void *cls, const char *hostname)
1458 struct PrettyPrinterContext *ppc = cls;
1461 if (hostname == NULL)
1463 ppc->asc (ppc->asc_cls, NULL);
1467 if (GNUNET_YES == ppc->ipv6)
1468 GNUNET_asprintf (&ret, "[%s]:%d", hostname, ppc->port);
1470 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
1471 ppc->asc (ppc->asc_cls, ret);
1477 * Convert the transports address to a nice, human-readable
1480 * @param cls closure
1481 * @param type name of the transport that generated the address
1482 * @param addr one of the addresses of the host, NULL for the last address
1483 * the specific address format depends on the transport
1484 * @param addrlen length of the address
1485 * @param numeric should (IP) addresses be displayed in numeric form?
1486 * @param timeout after how long should we give up?
1487 * @param asc function to call on each string
1488 * @param asc_cls closure for asc
1491 tcp_plugin_address_pretty_printer (void *cls, const char *type,
1492 const void *addr, size_t addrlen,
1494 struct GNUNET_TIME_Relative timeout,
1495 GNUNET_TRANSPORT_AddressStringCallback asc,
1498 struct PrettyPrinterContext *ppc;
1501 struct sockaddr_in a4;
1502 struct sockaddr_in6 a6;
1503 const struct IPv4TcpAddress *t4;
1504 const struct IPv6TcpAddress *t6;
1507 if (addrlen == sizeof (struct IPv6TcpAddress))
1510 memset (&a6, 0, sizeof (a6));
1511 a6.sin6_family = AF_INET6;
1512 a6.sin6_port = t6->t6_port;
1513 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1514 port = ntohs (t6->t6_port);
1518 else if (addrlen == sizeof (struct IPv4TcpAddress))
1521 memset (&a4, 0, sizeof (a4));
1522 a4.sin_family = AF_INET;
1523 a4.sin_port = t4->t4_port;
1524 a4.sin_addr.s_addr = t4->ipv4_addr;
1525 port = ntohs (t4->t4_port);
1529 else if (0 == addrlen)
1531 asc (asc_cls, "<inbound connection>");
1532 asc (asc_cls, NULL);
1537 /* invalid address */
1538 GNUNET_break_op (0);
1539 asc (asc_cls, NULL);
1542 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
1543 if (addrlen == sizeof (struct IPv6TcpAddress))
1544 ppc->ipv6 = GNUNET_YES;
1546 ppc->ipv6 = GNUNET_NO;
1548 ppc->asc_cls = asc_cls;
1550 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1555 * Check if the given port is plausible (must be either our listen
1556 * port or our advertised port), or any port if we are behind NAT
1557 * and do not have a port open. If it is neither, we return
1560 * @param plugin global variables
1561 * @param in_port port number to check
1562 * @return GNUNET_OK if port is either open_port or adv_port
1565 check_port (struct Plugin *plugin, uint16_t in_port)
1567 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port))
1569 return GNUNET_SYSERR;
1574 * Function that will be called to check if a binary address for this
1575 * plugin is well-formed and corresponds to an address for THIS peer
1576 * (as per our configuration). Naturally, if absolutely necessary,
1577 * plugins can be a bit conservative in their answer, but in general
1578 * plugins should make sure that the address does not redirect
1579 * traffic to a 3rd party that might try to man-in-the-middle our
1582 * @param cls closure, our 'struct Plugin*'
1583 * @param addr pointer to the address
1584 * @param addrlen length of addr
1585 * @return GNUNET_OK if this is a plausible address for this peer
1586 * and transport, GNUNET_SYSERR if not
1589 tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1591 struct Plugin *plugin = cls;
1592 struct IPv4TcpAddress *v4;
1593 struct IPv6TcpAddress *v6;
1595 if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
1596 (addrlen != sizeof (struct IPv6TcpAddress)))
1598 GNUNET_break_op (0);
1599 return GNUNET_SYSERR;
1601 if (addrlen == sizeof (struct IPv4TcpAddress))
1603 v4 = (struct IPv4TcpAddress *) addr;
1604 if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port)))
1605 return GNUNET_SYSERR;
1607 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
1608 sizeof (struct in_addr)))
1609 return GNUNET_SYSERR;
1613 v6 = (struct IPv6TcpAddress *) addr;
1614 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1616 GNUNET_break_op (0);
1617 return GNUNET_SYSERR;
1619 if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port)))
1620 return GNUNET_SYSERR;
1622 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
1623 sizeof (struct in6_addr)))
1624 return GNUNET_SYSERR;
1631 * We've received a nat probe from this peer via TCP. Finish
1632 * creating the client session and resume sending of queued
1635 * @param cls closure
1636 * @param client identification of the client
1637 * @param message the actual message
1640 handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1641 const struct GNUNET_MessageHeader *message)
1643 struct Plugin *plugin = cls;
1644 struct Session *session;
1645 const struct TCP_NAT_ProbeMessage *tcp_nat_probe;
1648 struct IPv4TcpAddress *t4;
1649 struct IPv6TcpAddress *t6;
1650 const struct sockaddr_in *s4;
1651 const struct sockaddr_in6 *s6;
1653 LOG (GNUNET_ERROR_TYPE_DEBUG, "received NAT probe\n");
1655 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
1656 * a connection to this peer by running gnunet-nat-client. This peer
1657 * received the punch message and now wants us to use the new connection
1658 * as the default for that peer. Do so and then send a WELCOME message
1659 * so we can really be connected!
1661 if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
1663 GNUNET_break_op (0);
1664 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1668 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
1670 memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity,
1671 sizeof (struct GNUNET_PeerIdentity)))
1673 /* refuse connections from ourselves */
1674 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1679 GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns,
1681 clientIdentity.hashPubKey);
1682 if (session == NULL)
1684 LOG (GNUNET_ERROR_TYPE_DEBUG,
1685 "Did NOT find session for NAT probe!\n");
1686 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1689 LOG (GNUNET_ERROR_TYPE_DEBUG,
1690 "Found session for NAT probe!\n");
1692 if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK)
1694 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout);
1695 session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK;
1698 GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove
1699 (plugin->nat_wait_conns,
1700 &tcp_nat_probe->clientIdentity.hashPubKey,
1701 session) == GNUNET_YES);
1702 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1705 GNUNET_free (session);
1706 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1710 GNUNET_SERVER_client_keep (client);
1711 session->client = client;
1712 session->last_activity = GNUNET_TIME_absolute_get ();
1713 session->inbound = GNUNET_NO;
1714 LOG (GNUNET_ERROR_TYPE_DEBUG,
1715 "Found address `%s' for incoming connection\n",
1716 GNUNET_a2s (vaddr, alen));
1717 switch (((const struct sockaddr *) vaddr)->sa_family)
1721 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1722 t4->t4_port = s4->sin_port;
1723 t4->ipv4_addr = s4->sin_addr.s_addr;
1725 session->addrlen = sizeof (struct IPv4TcpAddress);
1729 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1730 t6->t6_port = s6->sin6_port;
1731 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1733 session->addrlen = sizeof (struct IPv6TcpAddress);
1736 GNUNET_break_op (0);
1737 LOG (GNUNET_ERROR_TYPE_DEBUG,
1738 "Bad address for incoming connection!\n");
1739 GNUNET_free (vaddr);
1741 GNUNET_SERVER_client_drop (client);
1742 GNUNET_free (session);
1743 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1746 GNUNET_free (vaddr);
1748 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &session->target.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1749 inc_sessions (plugin, session, __LINE__);
1750 GNUNET_STATISTICS_update (plugin->env->stats,
1751 gettext_noop ("# TCP sessions active"), 1,
1753 process_pending_messages (session);
1754 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1759 * We've received a welcome from this peer via TCP. Possibly create a
1760 * fresh client record and send back our welcome.
1762 * @param cls closure
1763 * @param client identification of the client
1764 * @param message the actual message
1767 handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1768 const struct GNUNET_MessageHeader *message)
1770 struct Plugin *plugin = cls;
1771 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message;
1772 struct Session *session;
1775 struct IPv4TcpAddress *t4;
1776 struct IPv6TcpAddress *t6;
1777 const struct sockaddr_in *s4;
1778 const struct sockaddr_in6 *s6;
1781 memcmp (&wm->clientIdentity, plugin->env->my_identity,
1782 sizeof (struct GNUNET_PeerIdentity)))
1784 /* refuse connections from ourselves */
1785 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1788 LOG (GNUNET_ERROR_TYPE_DEBUG,
1789 "Received %s message from `%4s'\n", "WELCOME",
1790 GNUNET_i2s (&wm->clientIdentity));
1791 GNUNET_STATISTICS_update (plugin->env->stats,
1792 gettext_noop ("# TCP WELCOME messages received"), 1,
1794 session = lookup_session_by_client (plugin, client);
1795 if (session != NULL)
1797 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1799 LOG (GNUNET_ERROR_TYPE_DEBUG,
1800 "Found existing session %p for peer `%s'\n",
1802 GNUNET_a2s (vaddr, alen));
1803 GNUNET_free (vaddr);
1808 GNUNET_SERVER_client_keep (client);
1809 session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO);
1810 session->inbound = GNUNET_YES;
1811 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1813 if (alen == sizeof (struct sockaddr_in))
1816 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1817 t4->t4_port = s4->sin_port;
1818 t4->ipv4_addr = s4->sin_addr.s_addr;
1820 session->addrlen = sizeof (struct IPv4TcpAddress);
1822 else if (alen == sizeof (struct sockaddr_in6))
1825 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1826 t6->t6_port = s6->sin6_port;
1827 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1829 session->addrlen = sizeof (struct IPv6TcpAddress);
1832 struct GNUNET_ATS_Information ats;
1833 ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen);
1834 session->ats_address_network_type = ats.value;
1836 GNUNET_free (vaddr);
1840 LOG (GNUNET_ERROR_TYPE_DEBUG,
1841 "Did not obtain TCP socket address for incoming connection\n");
1843 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &wm->clientIdentity.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1844 inc_sessions (plugin, session, __LINE__);
1847 if (session->expecting_welcome != GNUNET_YES)
1849 GNUNET_break_op (0);
1850 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1853 session->last_activity = GNUNET_TIME_absolute_get ();
1854 session->expecting_welcome = GNUNET_NO;
1857 process_pending_messages (session);
1859 GNUNET_SERVER_client_set_timeout (client,
1860 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1861 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1866 * Task to signal the server that we can continue
1867 * receiving from the TCP client now.
1869 * @param cls the 'struct Session*'
1870 * @param tc task context (unused)
1873 delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1875 struct Session *session = cls;
1876 struct GNUNET_TIME_Relative delay;
1877 struct GNUNET_ATS_Information ats;
1879 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
1881 session->plugin->env->receive (session->plugin->env->cls,
1882 &session->target, NULL, &ats, 0, session,
1884 reschedule_session_timeout (session);
1886 if (delay.rel_value == 0)
1887 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
1889 session->receive_delay_task =
1890 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
1895 * We've received data for this peer via TCP. Unbox,
1896 * compute latency and forward.
1898 * @param cls closure
1899 * @param client identification of the client
1900 * @param message the actual message
1903 handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1904 const struct GNUNET_MessageHeader *message)
1906 struct Plugin *plugin = cls;
1907 struct Session *session;
1908 struct GNUNET_TIME_Relative delay;
1911 type = ntohs (message->type);
1912 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
1913 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
1915 /* We don't want to propagate WELCOME and NAT Probe messages up! */
1916 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1919 session = lookup_session_by_client (plugin, client);
1920 if (NULL == session)
1922 /* No inbound session found */
1926 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1927 LOG (GNUNET_ERROR_TYPE_ERROR,
1928 "Received unexpected %u bytes of type %u from `%s'\n",
1929 (unsigned int) ntohs (message->size),
1930 (unsigned int) ntohs (message->type),
1931 GNUNET_a2s(vaddr, alen));
1932 GNUNET_break_op (0);
1933 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1934 GNUNET_free_non_null(vaddr);
1937 else if (GNUNET_YES == session->expecting_welcome)
1939 /* Session is expecting WELCOME message */
1943 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1944 LOG (GNUNET_ERROR_TYPE_ERROR,
1945 "Received unexpected %u bytes of type %u from `%s'\n",
1946 (unsigned int) ntohs (message->size),
1947 (unsigned int) ntohs (message->type),
1948 GNUNET_a2s(vaddr, alen));
1949 GNUNET_break_op (0);
1950 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1951 GNUNET_free_non_null(vaddr);
1955 session->last_activity = GNUNET_TIME_absolute_get ();
1956 LOG (GNUNET_ERROR_TYPE_DEBUG,
1957 "Passing %u bytes of type %u from `%4s' to transport service.\n",
1958 (unsigned int) ntohs (message->size),
1959 (unsigned int) ntohs (message->type),
1960 GNUNET_i2s (&session->target));
1962 GNUNET_STATISTICS_update (plugin->env->stats,
1963 gettext_noop ("# bytes received via TCP"),
1964 ntohs (message->size), GNUNET_NO);
1965 struct GNUNET_ATS_Information distance[2];
1967 distance[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1968 distance[0].value = htonl (1);
1969 distance[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1970 distance[1].value = session->ats_address_network_type;
1971 GNUNET_break (ntohl(session->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED);
1973 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains_value (plugin->sessionmap,
1974 &session->target.hashPubKey,
1977 delay = plugin->env->receive (plugin->env->cls,
1980 (const struct GNUNET_ATS_Information *) &distance,
1982 (GNUNET_YES == session->inbound) ? NULL : session->addr,
1983 (GNUNET_YES == session->inbound) ? 0 : session->addrlen);
1985 reschedule_session_timeout (session);
1987 if (delay.rel_value == 0)
1989 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1993 LOG (GNUNET_ERROR_TYPE_DEBUG,
1994 "Throttling receiving from `%s' for %llu ms\n",
1995 GNUNET_i2s (&session->target),
1996 (unsigned long long) delay.rel_value);
1997 GNUNET_SERVER_disable_receive_done_warning (client);
1998 session->receive_delay_task =
1999 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
2005 * Functions with this signature are called whenever a peer
2006 * is disconnected on the network level.
2008 * @param cls closure
2009 * @param client identification of the client
2012 disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
2014 struct Plugin *plugin = cls;
2015 struct Session *session;
2019 plugin->max_connections++;
2020 session = lookup_session_by_client (plugin, client);
2021 if (session == NULL)
2022 return; /* unknown, nothing to do */
2023 LOG (GNUNET_ERROR_TYPE_DEBUG,
2024 "Destroying session of `%4s' with %s due to network-level disconnect.\n",
2025 GNUNET_i2s (&session->target),
2027 NULL) ? tcp_address_to_string (session->plugin,
2031 GNUNET_STATISTICS_update (session->plugin->env->stats,
2033 ("# network-level TCP disconnect events"), 1,
2035 disconnect_session (session);
2040 * We can now send a probe message, copy into buffer to really send.
2042 * @param cls closure, a struct TCPProbeContext
2043 * @param size max size to copy
2044 * @param buf buffer to copy message to
2045 * @return number of bytes copied into buf
2048 notify_send_probe (void *cls, size_t size, void *buf)
2050 struct TCPProbeContext *tcp_probe_ctx = cls;
2051 struct Plugin *plugin = tcp_probe_ctx->plugin;
2054 tcp_probe_ctx->transmit_handle = NULL;
2055 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
2059 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock);
2060 GNUNET_free (tcp_probe_ctx);
2063 GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
2064 memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
2065 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
2066 tcp_probe_ctx->sock);
2067 ret = sizeof (tcp_probe_ctx->message);
2068 GNUNET_free (tcp_probe_ctx);
2074 * Function called by the NAT subsystem suggesting another peer wants
2075 * to connect to us via connection reversal. Try to connect back to the
2078 * @param cls closure
2079 * @param addr address to try
2080 * @param addrlen number of bytes in addr
2083 try_connection_reversal (void *cls, const struct sockaddr *addr,
2086 struct Plugin *plugin = cls;
2087 struct GNUNET_CONNECTION_Handle *sock;
2088 struct TCPProbeContext *tcp_probe_ctx;
2091 * We have received an ICMP response, ostensibly from a peer
2092 * that wants to connect to us! Send a message to establish a connection.
2094 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
2097 /* failed for some odd reason (out of sockets?); ignore attempt */
2101 /* FIXME: do we need to track these probe context objects so that
2102 * we can clean them up on plugin unload? */
2103 tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
2104 tcp_probe_ctx->message.header.size =
2105 htons (sizeof (struct TCP_NAT_ProbeMessage));
2106 tcp_probe_ctx->message.header.type =
2107 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
2108 memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity,
2109 sizeof (struct GNUNET_PeerIdentity));
2110 tcp_probe_ctx->plugin = plugin;
2111 tcp_probe_ctx->sock = sock;
2112 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail,
2114 tcp_probe_ctx->transmit_handle =
2115 GNUNET_CONNECTION_notify_transmit_ready (sock,
2116 ntohs (tcp_probe_ctx->
2117 message.header.size),
2118 GNUNET_TIME_UNIT_FOREVER_REL,
2126 * Session was idle, so disconnect it
2129 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2131 GNUNET_assert (NULL != cls);
2132 struct Session *s = cls;
2134 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %p was idle for %llu, disconnecting\n",
2137 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2139 /* call session destroy function */
2140 disconnect_session(s);
2145 * Start session timeout
2148 start_session_timeout (struct Session *s)
2150 GNUNET_assert (NULL != s);
2151 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
2153 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p set to %llu\n",
2158 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2162 * Increment session timeout due to activity
2165 reschedule_session_timeout (struct Session *s)
2167 GNUNET_assert (NULL != s);
2168 if (GNUNET_SCHEDULER_NO_TASK == s->timeout_task)
2170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout for peer `%s' %s not scheduled\n",
2171 GNUNET_i2s (&s->target), tcp_address_to_string(NULL, s->addr, s->addrlen));
2175 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
2177 GNUNET_SCHEDULER_cancel (s->timeout_task);
2178 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n",
2183 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2190 stop_session_timeout (struct Session *s)
2192 GNUNET_assert (NULL != s);
2194 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
2196 GNUNET_SCHEDULER_cancel (s->timeout_task);
2197 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p canceled\n",
2200 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
2204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p was not active\n",
2211 * Entry point for the plugin.
2213 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
2214 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
2217 libgnunet_plugin_transport_tcp_init (void *cls)
2219 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
2220 {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
2221 sizeof (struct WelcomeMessage)},
2222 {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
2223 sizeof (struct TCP_NAT_ProbeMessage)},
2224 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
2227 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2228 struct GNUNET_TRANSPORT_PluginFunctions *api;
2229 struct Plugin *plugin;
2230 struct GNUNET_SERVICE_Context *service;
2231 unsigned long long aport;
2232 unsigned long long bport;
2233 unsigned long long max_connections;
2235 struct GNUNET_TIME_Relative idle_timeout;
2237 struct sockaddr **addrs;
2238 socklen_t *addrlens;
2240 if (NULL == env->receive)
2242 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2243 initialze the plugin or the API */
2244 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2246 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
2247 api->address_to_string = &tcp_address_to_string;
2248 api->string_to_address = &tcp_string_to_address;
2253 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
2256 max_connections = 128;
2260 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT",
2261 &bport)) || (bport > 65535) ||
2263 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
2264 "ADVERTISED-PORT", &aport)) &&
2267 LOG (GNUNET_ERROR_TYPE_ERROR,
2269 ("Require valid port number for service `%s' in configuration!\n"),
2279 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, GNUNET_SERVICE_OPTION_NONE);
2280 if (service == NULL)
2282 LOG (GNUNET_ERROR_TYPE_WARNING,
2283 _("Failed to start service.\n"));
2290 plugin = GNUNET_malloc (sizeof (struct Plugin));
2291 plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create(max_connections);
2292 plugin->max_connections = max_connections;
2293 plugin->open_port = bport;
2294 plugin->adv_port = aport;
2296 plugin->lsock = NULL;
2297 if ((service != NULL) &&
2300 GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs,
2304 GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret,
2305 (const struct sockaddr **) addrs, addrlens,
2306 &tcp_nat_port_map_callback,
2307 &try_connection_reversal, plugin);
2311 GNUNET_assert (addrs[ret] != NULL);
2312 GNUNET_free (addrs[ret]);
2314 GNUNET_free_non_null (addrs);
2315 GNUNET_free_non_null (addrlens);
2320 GNUNET_NAT_register (env->cfg, GNUNET_YES, 0, 0, NULL, NULL, NULL,
2321 &try_connection_reversal, plugin);
2323 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2325 api->send = &tcp_plugin_send;
2326 api->get_session = &tcp_plugin_get_session;
2328 api->disconnect = &tcp_plugin_disconnect;
2329 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
2330 api->check_address = &tcp_plugin_check_address;
2331 api->address_to_string = &tcp_address_to_string;
2332 api->string_to_address = &tcp_string_to_address;
2333 plugin->service = service;
2334 if (service != NULL)
2336 plugin->server = GNUNET_SERVICE_get_server (service);
2341 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp",
2342 "TIMEOUT", &idle_timeout))
2344 LOG (GNUNET_ERROR_TYPE_ERROR,
2345 _("Failed to find option %s in section %s!\n"),
2346 "TIMEOUT", "transport-tcp");
2347 if (plugin->nat != NULL)
2348 GNUNET_NAT_unregister (plugin->nat);
2349 GNUNET_free (plugin);
2354 GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin,
2355 NULL, idle_timeout, GNUNET_YES);
2357 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
2358 memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
2360 i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler);
2362 plugin->handlers[i].callback_cls = plugin;
2363 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
2364 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
2365 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
2367 LOG (GNUNET_ERROR_TYPE_INFO,
2368 _("TCP transport listening on port %llu\n"), bport);
2370 LOG (GNUNET_ERROR_TYPE_INFO,
2372 ("TCP transport not listening on any port (client only)\n"));
2374 LOG (GNUNET_ERROR_TYPE_INFO,
2376 ("TCP transport advertises itself as being on port %llu\n"),
2378 /* Initially set connections to 0 */
2379 GNUNET_STATISTICS_set(plugin->env->stats,
2380 gettext_noop ("# TCP sessions active"), 0,
2387 * Exit point from the plugin.
2390 libgnunet_plugin_transport_tcp_done (void *cls)
2392 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2393 struct Plugin *plugin = api->cls;
2394 struct TCPProbeContext *tcp_probe;
2401 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
2403 /* Removing leftover sessions */
2404 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL);
2405 /* Removing leftover NAT sessions */
2406 GNUNET_CONTAINER_multihashmap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL);
2408 if (plugin->service != NULL)
2409 GNUNET_SERVICE_stop (plugin->service);
2411 GNUNET_SERVER_destroy (plugin->server);
2412 GNUNET_free (plugin->handlers);
2413 if (plugin->nat != NULL)
2414 GNUNET_NAT_unregister (plugin->nat);
2415 while (NULL != (tcp_probe = plugin->probe_head))
2417 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
2419 GNUNET_CONNECTION_destroy (tcp_probe->sock);
2420 GNUNET_free (tcp_probe);
2422 GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns);
2423 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessionmap);
2424 GNUNET_free (plugin);
2429 /* end of plugin_transport_tcp.c */