aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-02 20:54:51 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-02 20:54:51 +0000
commitff2354195a8ed1ea2e9c781d7c4421742b0df4d0 (patch)
tree2cb08c47004138f88f49850b0af2e9185acb4e82 /src/util
parent75b02f33ec88d5b2db25d31a1b6fffc82290f38c (diff)
downloadgnunet-ff2354195a8ed1ea2e9c781d7c4421742b0df4d0.tar.gz
gnunet-ff2354195a8ed1ea2e9c781d7c4421742b0df4d0.zip
adding TCP_STEALTH support to TCP plugin
Diffstat (limited to 'src/util')
-rw-r--r--src/util/connection.c55
-rw-r--r--src/util/network.c14
-rw-r--r--src/util/service.c16
3 files changed, 64 insertions, 21 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index 2bb128abc..79d1c2d4c 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -789,8 +789,8 @@ try_connect_using_address (void *cls, const struct sockaddr *addr,
789 * @return the connection handle 789 * @return the connection handle
790 */ 790 */
791struct GNUNET_CONNECTION_Handle * 791struct GNUNET_CONNECTION_Handle *
792GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle 792GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
793 *cfg, const char *hostname, 793 const char *hostname,
794 uint16_t port) 794 uint16_t port)
795{ 795{
796 struct GNUNET_CONNECTION_Handle *connection; 796 struct GNUNET_CONNECTION_Handle *connection;
@@ -883,31 +883,25 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
883 * This function returns immediately, even if the connection has not 883 * This function returns immediately, even if the connection has not
884 * yet been established. This function only creates TCP connections. 884 * yet been established. This function only creates TCP connections.
885 * 885 *
886 * @param af_family address family to use 886 * @param s socket to connect
887 * @param serv_addr server address 887 * @param serv_addr server address
888 * @param addrlen length of server address 888 * @param addrlen length of server address
889 * @return the connection handle 889 * @return the connection handle
890 */ 890 */
891struct GNUNET_CONNECTION_Handle * 891struct GNUNET_CONNECTION_Handle *
892GNUNET_CONNECTION_create_from_sockaddr (int af_family, 892GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
893 const struct sockaddr *serv_addr, 893 const struct sockaddr *serv_addr,
894 socklen_t addrlen) 894 socklen_t addrlen)
895{ 895{
896 struct GNUNET_NETWORK_Handle *s;
897 struct GNUNET_CONNECTION_Handle *connection; 896 struct GNUNET_CONNECTION_Handle *connection;
898 897
899 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
900 if (NULL == s)
901 {
902 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
903 return NULL;
904 }
905 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && 898 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
906 (EINPROGRESS != errno)) 899 (EINPROGRESS != errno))
907 { 900 {
908 /* maybe refused / unsupported address, try next */ 901 /* maybe refused / unsupported address, try next */
909 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); 902 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
910 LOG (GNUNET_ERROR_TYPE_INFO, _("Attempt to connect to `%s' failed\n"), 903 LOG (GNUNET_ERROR_TYPE_INFO,
904 _("Attempt to connect to `%s' failed\n"),
911 GNUNET_a2s (serv_addr, addrlen)); 905 GNUNET_a2s (serv_addr, addrlen));
912 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 906 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
913 return NULL; 907 return NULL;
@@ -916,19 +910,48 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
916 connection->addr = GNUNET_malloc (addrlen); 910 connection->addr = GNUNET_malloc (addrlen);
917 memcpy (connection->addr, serv_addr, addrlen); 911 memcpy (connection->addr, serv_addr, addrlen);
918 connection->addrlen = addrlen; 912 connection->addrlen = addrlen;
919 LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), 913 LOG (GNUNET_ERROR_TYPE_INFO,
914 _("Trying to connect to `%s' (%p)\n"),
920 GNUNET_a2s (serv_addr, addrlen), connection); 915 GNUNET_a2s (serv_addr, addrlen), connection);
921 return connection; 916 return connection;
922} 917}
923 918
924 919
925/** 920/**
921 * Create a connection handle by creating a socket and
922 * (asynchronously) connecting to a host. This function returns
923 * immediately, even if the connection has not yet been established.
924 * This function only creates TCP connections.
925 *
926 * @param af_family address family to use
927 * @param serv_addr server address
928 * @param addrlen length of @a serv_addr
929 * @return the connection handle
930 */
931struct GNUNET_CONNECTION_Handle *
932GNUNET_CONNECTION_create_from_sockaddr (int af_family,
933 const struct sockaddr *serv_addr,
934 socklen_t addrlen)
935{
936 struct GNUNET_NETWORK_Handle *s;
937
938 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
939 if (NULL == s)
940 {
941 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
942 return NULL;
943 }
944 return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
945}
946
947
948/**
926 * Check if connection is valid (no fatal errors have happened so far). 949 * Check if connection is valid (no fatal errors have happened so far).
927 * Note that a connection that is still trying to connect is considered 950 * Note that a connection that is still trying to connect is considered
928 * valid. 951 * valid.
929 * 952 *
930 * @param connection connection to check 953 * @param connection connection to check
931 * @return GNUNET_YES if valid, GNUNET_NO otherwise 954 * @return #GNUNET_YES if valid, #GNUNET_NO otherwise
932 */ 955 */
933int 956int
934GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) 957GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
diff --git a/src/util/network.c b/src/util/network.c
index 46e6fa03b..84b659c28 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -829,17 +829,23 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
829 * @param level protocol level of the option 829 * @param level protocol level of the option
830 * @param option_name option identifier 830 * @param option_name option identifier
831 * @param option_value value to set 831 * @param option_value value to set
832 * @param option_len size of option_value 832 * @param option_len size of @a option_value
833 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 833 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
834 */ 834 */
835int 835int
836GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, 836GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
837 int option_name, const void *option_value, 837 int level,
838 int option_name,
839 const void *option_value,
838 socklen_t option_len) 840 socklen_t option_len)
839{ 841{
840 int ret; 842 int ret;
841 843
842 ret = setsockopt (fd->fd, level, option_name, option_value, option_len); 844 ret = setsockopt (fd->fd,
845 level,
846 option_name,
847 option_value,
848 option_len);
843#ifdef MINGW 849#ifdef MINGW
844 if (SOCKET_ERROR == ret) 850 if (SOCKET_ERROR == ret)
845 SetErrnoFromWinsockError (WSAGetLastError ()); 851 SetErrnoFromWinsockError (WSAGetLastError ());
diff --git a/src/util/service.c b/src/util/service.c
index 4e3c232f9..a97cd434f 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -142,7 +142,7 @@ struct GNUNET_SERVICE_Context
142 GNUNET_SERVICE_Main task; 142 GNUNET_SERVICE_Main task;
143 143
144 /** 144 /**
145 * Closure for task. 145 * Closure for @e task.
146 */ 146 */
147 void *task_cls; 147 void *task_cls;
148 148
@@ -1628,6 +1628,20 @@ GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx)
1628 1628
1629 1629
1630/** 1630/**
1631 * Get the NULL-terminated array of listen sockets for this service.
1632 *
1633 * @param ctx service context to query
1634 * @return NULL if there are no listen sockets, otherwise NULL-terminated
1635 * array of listen sockets.
1636 */
1637struct GNUNET_NETWORK_Handle **
1638GNUNET_SERVICE_get_listen_sockets (struct GNUNET_SERVICE_Context *ctx)
1639{
1640 return ctx->lsocks;
1641}
1642
1643
1644/**
1631 * Stop a service that was started with "GNUNET_SERVICE_start". 1645 * Stop a service that was started with "GNUNET_SERVICE_start".
1632 * 1646 *
1633 * @param sctx the service context returned from the start function 1647 * @param sctx the service context returned from the start function