diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-11-02 20:54:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-11-02 20:54:51 +0000 |
commit | ff2354195a8ed1ea2e9c781d7c4421742b0df4d0 (patch) | |
tree | 2cb08c47004138f88f49850b0af2e9185acb4e82 /src/util/connection.c | |
parent | 75b02f33ec88d5b2db25d31a1b6fffc82290f38c (diff) | |
download | gnunet-ff2354195a8ed1ea2e9c781d7c4421742b0df4d0.tar.gz gnunet-ff2354195a8ed1ea2e9c781d7c4421742b0df4d0.zip |
adding TCP_STEALTH support to TCP plugin
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 55 |
1 files changed, 39 insertions, 16 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 | */ |
791 | struct GNUNET_CONNECTION_Handle * | 791 | struct GNUNET_CONNECTION_Handle * |
792 | GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | 792 | GNUNET_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 | */ |
891 | struct GNUNET_CONNECTION_Handle * | 891 | struct GNUNET_CONNECTION_Handle * |
892 | GNUNET_CONNECTION_create_from_sockaddr (int af_family, | 892 | GNUNET_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 | */ | ||
931 | struct GNUNET_CONNECTION_Handle * | ||
932 | GNUNET_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 | */ |
933 | int | 956 | int |
934 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) | 957 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) |