diff options
author | Jeff Burdges <burdges@gnunet.org> | 2015-07-28 14:50:10 +0000 |
---|---|---|
committer | Jeff Burdges <burdges@gnunet.org> | 2015-07-28 14:50:10 +0000 |
commit | 42762fe40aaaf40bec4c20b821f074e082397351 (patch) | |
tree | cf4ad31cf21ec1e8dfe2fb92e5b40ce926802ba5 /src/util | |
parent | 387ce05fe798b8baa07c04af2750d97b571d2460 (diff) | |
download | gnunet-42762fe40aaaf40bec4c20b821f074e082397351.tar.gz gnunet-42762fe40aaaf40bec4c20b821f074e082397351.zip |
Add support for building connection proxies.
It should not have any effect on existing code, and pass any tests that
would pass normally, but if it does break anyhting then contact me ASAP.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/connection.c | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index b20171616..d6da55784 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -251,6 +251,11 @@ struct GNUNET_CONNECTION_Handle | |||
251 | */ | 251 | */ |
252 | int8_t destroy_later; | 252 | int8_t destroy_later; |
253 | 253 | ||
254 | /** | ||
255 | * Handle to subsequent connection after proxy handshake completes, | ||
256 | */ | ||
257 | struct GNUNET_CONNECTION_Handle *proxy_handshake; | ||
258 | |||
254 | }; | 259 | }; |
255 | 260 | ||
256 | 261 | ||
@@ -571,6 +576,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
571 | GNUNET_break (GNUNET_NO == connection->dns_active); | 576 | GNUNET_break (GNUNET_NO == connection->dns_active); |
572 | GNUNET_break (NULL == connection->sock); | 577 | GNUNET_break (NULL == connection->sock); |
573 | GNUNET_assert (NULL == connection->write_task); | 578 | GNUNET_assert (NULL == connection->write_task); |
579 | GNUNET_assert (NULL == connection->proxy_handshake); | ||
574 | 580 | ||
575 | /* signal errors for jobs that used to wait on the connection */ | 581 | /* signal errors for jobs that used to wait on the connection */ |
576 | connection->destroy_later = 1; | 582 | connection->destroy_later = 1; |
@@ -687,7 +693,9 @@ connect_probe_continuation (void *cls, | |||
687 | { | 693 | { |
688 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); | 694 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); |
689 | GNUNET_free (ap); | 695 | GNUNET_free (ap); |
690 | if ((NULL == connection->ap_head) && (GNUNET_NO == connection->dns_active)) | 696 | if ((NULL == connection->ap_head) && |
697 | (GNUNET_NO == connection->dns_active) && | ||
698 | (NULL == connection->proxy_handshake)) | ||
691 | connect_fail_continuation (connection); | 699 | connect_fail_continuation (connection); |
692 | return; | 700 | return; |
693 | } | 701 | } |
@@ -730,7 +738,9 @@ try_connect_using_address (void *cls, | |||
730 | if (NULL == addr) | 738 | if (NULL == addr) |
731 | { | 739 | { |
732 | connection->dns_active = NULL; | 740 | connection->dns_active = NULL; |
733 | if ((NULL == connection->ap_head) && (NULL == connection->sock)) | 741 | if ((NULL == connection->ap_head) && |
742 | (NULL == connection->sock) && | ||
743 | (NULL == connection->proxy_handshake)) | ||
734 | connect_fail_continuation (connection); | 744 | connect_fail_continuation (connection); |
735 | return; | 745 | return; |
736 | } | 746 | } |
@@ -982,7 +992,9 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
982 | int | 992 | int |
983 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) | 993 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) |
984 | { | 994 | { |
985 | if ((NULL != connection->ap_head) || (NULL != connection->dns_active)) | 995 | if ((NULL != connection->ap_head) || |
996 | (NULL != connection->dns_active) || | ||
997 | (NULL != connection->proxy_handshake)) | ||
986 | return GNUNET_YES; /* still trying to connect */ | 998 | return GNUNET_YES; /* still trying to connect */ |
987 | if ( (0 != connection->destroy_later) || | 999 | if ( (0 != connection->destroy_later) || |
988 | (NULL == connection->sock) ) | 1000 | (NULL == connection->sock) ) |
@@ -1035,6 +1047,12 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1035 | GNUNET_RESOLVER_request_cancel (connection->dns_active); | 1047 | GNUNET_RESOLVER_request_cancel (connection->dns_active); |
1036 | connection->dns_active = NULL; | 1048 | connection->dns_active = NULL; |
1037 | } | 1049 | } |
1050 | if (NULL != connection->proxy_handshake) | ||
1051 | { | ||
1052 | /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ | ||
1053 | connection->proxy_handshake->destroy_later = -1; | ||
1054 | connection->proxy_handshake = NULL; /* Not leaked ??? */ | ||
1055 | } | ||
1038 | while (NULL != (pos = connection->ap_head)) | 1056 | while (NULL != (pos = connection->ap_head)) |
1039 | { | 1057 | { |
1040 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 1058 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
@@ -1182,7 +1200,9 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, | |||
1182 | connection); | 1200 | connection); |
1183 | return; | 1201 | return; |
1184 | } | 1202 | } |
1185 | if ((NULL == connection->dns_active) && (NULL == connection->ap_head)) | 1203 | if ((NULL == connection->dns_active) && |
1204 | (NULL == connection->ap_head) && | ||
1205 | (NULL == connection->proxy_handshake)) | ||
1186 | { | 1206 | { |
1187 | connection->receiver = NULL; | 1207 | connection->receiver = NULL; |
1188 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); | 1208 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); |
@@ -1496,7 +1516,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1496 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1516 | GNUNET_assert (NULL == connection->nth.timeout_task); |
1497 | if ((NULL == connection->sock) && | 1517 | if ((NULL == connection->sock) && |
1498 | (NULL == connection->ap_head) && | 1518 | (NULL == connection->ap_head) && |
1499 | (NULL == connection->dns_active)) | 1519 | (NULL == connection->dns_active) && |
1520 | (NULL == connection->proxy_handshake)) | ||
1500 | { | 1521 | { |
1501 | if (NULL != connection->write_task) | 1522 | if (NULL != connection->write_task) |
1502 | GNUNET_SCHEDULER_cancel (connection->write_task); | 1523 | GNUNET_SCHEDULER_cancel (connection->write_task); |
@@ -1551,4 +1572,40 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi | |||
1551 | } | 1572 | } |
1552 | } | 1573 | } |
1553 | 1574 | ||
1575 | |||
1576 | /** | ||
1577 | * Create a connection to be proxied using a given connection. | ||
1578 | * | ||
1579 | * @param cph connection to proxy server | ||
1580 | * @return connection to be proxied | ||
1581 | */ | ||
1582 | struct GNUNET_CONNECTION_Handle * | ||
1583 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) | ||
1584 | { | ||
1585 | struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL); | ||
1586 | proxied->proxy_handshake = cph; | ||
1587 | return proxied; | ||
1588 | } | ||
1589 | |||
1590 | |||
1591 | /** | ||
1592 | * Activate proxied connection and destroy initial proxy handshake connection. | ||
1593 | * There must not be any pending requests for reading or writing to the | ||
1594 | * proxy hadshake connection at this time. | ||
1595 | * | ||
1596 | * @param proxied connection connection to proxy server | ||
1597 | */ | ||
1598 | void | ||
1599 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) | ||
1600 | { | ||
1601 | struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; | ||
1602 | GNUNET_assert (NULL != cph); | ||
1603 | GNUNET_assert (NULL == proxied->sock); | ||
1604 | GNUNET_assert (NULL != cph->sock); | ||
1605 | proxied->sock=cph->sock; | ||
1606 | cph->sock=NULL; | ||
1607 | GNUNET_CONNECTION_destroy (cph); | ||
1608 | } | ||
1609 | |||
1610 | |||
1554 | /* end of connection.c */ | 1611 | /* end of connection.c */ |