diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 117 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 57 | ||||
-rw-r--r-- | src/transport/transport.h | 31 | ||||
-rw-r--r-- | src/transport/transport_api.c | 215 |
4 files changed, 278 insertions, 142 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 310121268..77374ff19 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -790,8 +790,8 @@ clients_handle_send (void *cls, | |||
790 | stcc->client = client; | 790 | stcc->client = client; |
791 | GNUNET_SERVER_client_keep (client); | 791 | GNUNET_SERVER_client_keep (client); |
792 | GST_manipulation_send (&obm->peer, obmm, msize, | 792 | GST_manipulation_send (&obm->peer, obmm, msize, |
793 | GNUNET_TIME_relative_ntoh (obm->timeout), | 793 | GNUNET_TIME_relative_ntoh (obm->timeout), |
794 | &handle_send_transmit_continuation, stcc); | 794 | &handle_send_transmit_continuation, stcc); |
795 | } | 795 | } |
796 | 796 | ||
797 | 797 | ||
@@ -837,63 +837,71 @@ clients_handle_request_connect (void *cls, | |||
837 | struct GNUNET_SERVER_Client *client, | 837 | struct GNUNET_SERVER_Client *client, |
838 | const struct GNUNET_MessageHeader *message) | 838 | const struct GNUNET_MessageHeader *message) |
839 | { | 839 | { |
840 | const struct TransportRequestConnectMessage *trcm = | 840 | const struct TransportRequestConnectMessage *trcm; |
841 | (const struct TransportRequestConnectMessage *) message; | 841 | |
842 | 842 | trcm = (const struct TransportRequestConnectMessage *) message; | |
843 | if (GNUNET_YES == ntohl (trcm->connect)) | 843 | GNUNET_break (0 == ntohl (trcm->reserved)); |
844 | GNUNET_STATISTICS_update (GST_stats, | ||
845 | gettext_noop | ||
846 | ("# REQUEST CONNECT messages received"), 1, | ||
847 | GNUNET_NO); | ||
848 | if (0 == memcmp (&trcm->peer, | ||
849 | &GST_my_identity, | ||
850 | sizeof (struct GNUNET_PeerIdentity))) | ||
844 | { | 851 | { |
845 | GNUNET_STATISTICS_update (GST_stats, | 852 | GNUNET_break (0); |
846 | gettext_noop | 853 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
847 | ("# REQUEST CONNECT messages received"), 1, | 854 | "Received a request connect message myself `%s'\n", |
848 | GNUNET_NO); | 855 | GNUNET_i2s (&trcm->peer)); |
849 | 856 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | |
850 | if (0 == memcmp (&trcm->peer, &GST_my_identity, | 857 | return; |
851 | sizeof (struct GNUNET_PeerIdentity))) | ||
852 | { | ||
853 | GNUNET_break_op (0); | ||
854 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
855 | "Received a request connect message myself `%s'\n", | ||
856 | GNUNET_i2s (&trcm->peer)); | ||
857 | } | ||
858 | else | ||
859 | { | ||
860 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
861 | _("Received a request connect message for peer `%s'\n"), | ||
862 | GNUNET_i2s (&trcm->peer)); | ||
863 | |||
864 | (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed, | ||
865 | NULL); | ||
866 | } | ||
867 | } | 858 | } |
868 | else if (GNUNET_NO == ntohl (trcm->connect)) | 859 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
869 | { | 860 | _("Received a request connect message for peer `%s'\n"), |
870 | GNUNET_STATISTICS_update (GST_stats, | 861 | GNUNET_i2s (&trcm->peer)); |
871 | gettext_noop | 862 | (void) GST_blacklist_test_allowed (&trcm->peer, |
872 | ("# REQUEST DISCONNECT messages received"), 1, | 863 | NULL, |
873 | GNUNET_NO); | 864 | &try_connect_if_allowed, |
865 | NULL); | ||
866 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
867 | } | ||
874 | 868 | ||
875 | if (0 == memcmp (&trcm->peer, &GST_my_identity, | 869 | |
876 | sizeof (struct GNUNET_PeerIdentity))) | 870 | /** |
877 | { | 871 | * Handle request disconnect message |
878 | GNUNET_break_op (0); | 872 | * |
879 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 873 | * @param cls closure (always NULL) |
880 | "Received a request disconnect message myself `%s'\n", | 874 | * @param client identification of the client |
881 | GNUNET_i2s (&trcm->peer)); | 875 | * @param message the actual message |
882 | } | 876 | */ |
883 | else | 877 | static void |
884 | { | 878 | clients_handle_request_disconnect (void *cls, |
885 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 879 | struct GNUNET_SERVER_Client *client, |
886 | _("Received a request disconnect message for peer `%s'\n"), | 880 | const struct GNUNET_MessageHeader *message) |
887 | GNUNET_i2s (&trcm->peer)); | 881 | { |
888 | (void) GST_neighbours_force_disconnect (&trcm->peer); | 882 | const struct TransportRequestDisconnectMessage *trdm; |
889 | } | 883 | |
890 | } | 884 | trdm = (const struct TransportRequestDisconnectMessage *) message; |
891 | else | 885 | GNUNET_break (0 == ntohl (trdm->reserved)); |
886 | GNUNET_STATISTICS_update (GST_stats, | ||
887 | gettext_noop | ||
888 | ("# REQUEST DISCONNECT messages received"), 1, | ||
889 | GNUNET_NO); | ||
890 | if (0 == memcmp (&trdm->peer, | ||
891 | &GST_my_identity, | ||
892 | sizeof (struct GNUNET_PeerIdentity))) | ||
892 | { | 893 | { |
893 | GNUNET_break_op (0); | 894 | GNUNET_break (0); |
894 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 895 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
896 | "Received a request disconnect message myself `%s'\n", | ||
897 | GNUNET_i2s (&trdm->peer)); | ||
898 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
895 | return; | 899 | return; |
896 | } | 900 | } |
901 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
902 | _("Received a request disconnect message for peer `%s'\n"), | ||
903 | GNUNET_i2s (&trdm->peer)); | ||
904 | (void) GST_neighbours_force_disconnect (&trdm->peer); | ||
897 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 905 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
898 | } | 906 | } |
899 | 907 | ||
@@ -1515,6 +1523,9 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
1515 | {&clients_handle_request_connect, NULL, | 1523 | {&clients_handle_request_connect, NULL, |
1516 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, | 1524 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, |
1517 | sizeof (struct TransportRequestConnectMessage)}, | 1525 | sizeof (struct TransportRequestConnectMessage)}, |
1526 | {&clients_handle_request_disconnect, NULL, | ||
1527 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT, | ||
1528 | sizeof (struct TransportRequestDisconnectMessage)}, | ||
1518 | {&clients_handle_address_to_string, NULL, | 1529 | {&clients_handle_address_to_string, NULL, |
1519 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, | 1530 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, |
1520 | {&clients_handle_monitor_peers, NULL, | 1531 | {&clients_handle_monitor_peers, NULL, |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 7adbf4c32..cd74abde7 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -281,11 +281,16 @@ static struct GNUNET_TRANSPORT_Handle *handle; | |||
281 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 281 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
282 | 282 | ||
283 | /** | 283 | /** |
284 | * Try_connect handle | 284 | * Try connect handle |
285 | */ | 285 | */ |
286 | struct GNUNET_TRANSPORT_TryConnectHandle *tc_handle; | 286 | struct GNUNET_TRANSPORT_TryConnectHandle *tc_handle; |
287 | 287 | ||
288 | /** | 288 | /** |
289 | * Try disconnect handle | ||
290 | */ | ||
291 | struct GNUNET_TRANSPORT_TryDisconnectHandle *td_handle; | ||
292 | |||
293 | /** | ||
289 | * Option -s. | 294 | * Option -s. |
290 | */ | 295 | */ |
291 | static int benchmark_send; | 296 | static int benchmark_send; |
@@ -1772,11 +1777,9 @@ try_connect_cb (void *cls, | |||
1772 | { | 1777 | { |
1773 | static int retries = 0; | 1778 | static int retries = 0; |
1774 | 1779 | ||
1780 | tc_handle = NULL; | ||
1775 | if (GNUNET_OK == result) | 1781 | if (GNUNET_OK == result) |
1776 | { | ||
1777 | tc_handle = NULL; | ||
1778 | return; | 1782 | return; |
1779 | } | ||
1780 | retries++; | 1783 | retries++; |
1781 | if (retries < 10) | 1784 | if (retries < 10) |
1782 | { | 1785 | { |
@@ -1784,18 +1787,15 @@ try_connect_cb (void *cls, | |||
1784 | &pid, | 1787 | &pid, |
1785 | &try_connect_cb, | 1788 | &try_connect_cb, |
1786 | NULL); | 1789 | NULL); |
1787 | } | ||
1788 | else | ||
1789 | { | ||
1790 | FPRINTF (stderr, | ||
1791 | "%s", | ||
1792 | _("Failed to send connect request to transport service\n")); | ||
1793 | if (GNUNET_SCHEDULER_NO_TASK != end) | ||
1794 | GNUNET_SCHEDULER_cancel (end); | ||
1795 | ret = 1; | ||
1796 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
1797 | return; | 1790 | return; |
1798 | } | 1791 | } |
1792 | FPRINTF (stderr, | ||
1793 | "%s", | ||
1794 | _("Failed to send connect request to transport service\n")); | ||
1795 | if (GNUNET_SCHEDULER_NO_TASK != end) | ||
1796 | GNUNET_SCHEDULER_cancel (end); | ||
1797 | ret = 1; | ||
1798 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
1799 | } | 1799 | } |
1800 | 1800 | ||
1801 | 1801 | ||
@@ -1812,27 +1812,25 @@ try_disconnect_cb (void *cls, | |||
1812 | const int result) | 1812 | const int result) |
1813 | { | 1813 | { |
1814 | static int retries = 0; | 1814 | static int retries = 0; |
1815 | |||
1816 | td_handle = NULL; | ||
1815 | if (GNUNET_OK == result) | 1817 | if (GNUNET_OK == result) |
1816 | { | ||
1817 | tc_handle = NULL; | ||
1818 | return; | 1818 | return; |
1819 | } | ||
1820 | retries++; | 1819 | retries++; |
1821 | if (retries < 10) | 1820 | if (retries < 10) |
1822 | tc_handle = GNUNET_TRANSPORT_try_disconnect (handle, | 1821 | { |
1822 | td_handle = GNUNET_TRANSPORT_try_disconnect (handle, | ||
1823 | &pid, | 1823 | &pid, |
1824 | &try_disconnect_cb, | 1824 | &try_disconnect_cb, |
1825 | NULL); | 1825 | NULL); |
1826 | else | ||
1827 | { | ||
1828 | FPRINTF (stderr, "%s", | ||
1829 | _("Failed to send disconnect request to transport service\n")); | ||
1830 | if (GNUNET_SCHEDULER_NO_TASK != end) | ||
1831 | GNUNET_SCHEDULER_cancel (end); | ||
1832 | ret = 1; | ||
1833 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
1834 | return; | 1826 | return; |
1835 | } | 1827 | } |
1828 | FPRINTF (stderr, "%s", | ||
1829 | _("Failed to send disconnect request to transport service\n")); | ||
1830 | if (GNUNET_SCHEDULER_NO_TASK != end) | ||
1831 | GNUNET_SCHEDULER_cancel (end); | ||
1832 | ret = 1; | ||
1833 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
1836 | } | 1834 | } |
1837 | 1835 | ||
1838 | 1836 | ||
@@ -1933,9 +1931,10 @@ testservice_task (void *cls, | |||
1933 | ret = 1; | 1931 | ret = 1; |
1934 | return; | 1932 | return; |
1935 | } | 1933 | } |
1936 | tc_handle = GNUNET_TRANSPORT_try_disconnect (handle, &pid, try_disconnect_cb, | 1934 | td_handle = GNUNET_TRANSPORT_try_disconnect (handle, &pid, |
1937 | NULL); | 1935 | &try_disconnect_cb, |
1938 | if (NULL == tc_handle) | 1936 | NULL); |
1937 | if (NULL == td_handle) | ||
1939 | { | 1938 | { |
1940 | FPRINTF (stderr, "%s", | 1939 | FPRINTF (stderr, "%s", |
1941 | _("Failed to send request to transport service\n")); | 1940 | _("Failed to send request to transport service\n")); |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 01d1b1722..af6e16ece 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -163,6 +163,7 @@ struct DisconnectInfoMessage | |||
163 | 163 | ||
164 | }; | 164 | }; |
165 | 165 | ||
166 | |||
166 | /** | 167 | /** |
167 | * Message type for sending a request connect message | 168 | * Message type for sending a request connect message |
168 | * to the transport service. Must be done before transport | 169 | * to the transport service. Must be done before transport |
@@ -172,14 +173,14 @@ struct DisconnectInfoMessage | |||
172 | struct TransportRequestConnectMessage | 173 | struct TransportRequestConnectMessage |
173 | { | 174 | { |
174 | /** | 175 | /** |
175 | * Message header | 176 | * Message header with type #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT |
176 | */ | 177 | */ |
177 | struct GNUNET_MessageHeader header; | 178 | struct GNUNET_MessageHeader header; |
178 | 179 | ||
179 | /** | 180 | /** |
180 | * Connect (#GNUNET_YES) or connect (#GNUNET_NO). | 181 | * Reserved (0). |
181 | */ | 182 | */ |
182 | uint32_t connect; | 183 | uint32_t reserved GNUNET_PACKED; |
183 | 184 | ||
184 | /** | 185 | /** |
185 | * Identity of the peer we would like to connect to. | 186 | * Identity of the peer we would like to connect to. |
@@ -187,6 +188,30 @@ struct TransportRequestConnectMessage | |||
187 | struct GNUNET_PeerIdentity peer; | 188 | struct GNUNET_PeerIdentity peer; |
188 | }; | 189 | }; |
189 | 190 | ||
191 | |||
192 | /** | ||
193 | * Message type for sending a request connection to | ||
194 | * a peer to be torn down. | ||
195 | */ | ||
196 | struct TransportRequestDisconnectMessage | ||
197 | { | ||
198 | /** | ||
199 | * Message header with type #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT | ||
200 | */ | ||
201 | struct GNUNET_MessageHeader header; | ||
202 | |||
203 | /** | ||
204 | * Reserved (0). | ||
205 | */ | ||
206 | uint32_t reserved GNUNET_PACKED; | ||
207 | |||
208 | /** | ||
209 | * Identity of the peer we would like to connect to. | ||
210 | */ | ||
211 | struct GNUNET_PeerIdentity peer; | ||
212 | }; | ||
213 | |||
214 | |||
190 | /** | 215 | /** |
191 | * Message used to set a particular bandwidth quota. Sent TO the | 216 | * Message used to set a particular bandwidth quota. Sent TO the |
192 | * service to set an incoming quota, sent FROM the service to update | 217 | * service to set an incoming quota, sent FROM the service to update |
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 3c57a83a0..4e8d2c8ea 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -65,13 +65,13 @@ struct GNUNET_TRANSPORT_TransmitHandle | |||
65 | struct Neighbour *neighbour; | 65 | struct Neighbour *neighbour; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Function to call when notify_size bytes are available | 68 | * Function to call when @e notify_size bytes are available |
69 | * for transmission. | 69 | * for transmission. |
70 | */ | 70 | */ |
71 | GNUNET_TRANSPORT_TransmitReadyNotify notify; | 71 | GNUNET_TRANSPORT_TransmitReadyNotify notify; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Closure for notify. | 74 | * Closure for @e notify. |
75 | */ | 75 | */ |
76 | void *notify_cls; | 76 | void *notify_cls; |
77 | 77 | ||
@@ -95,7 +95,7 @@ struct GNUNET_TRANSPORT_TransmitHandle | |||
95 | 95 | ||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Entry in hash table of all of our current neighbours. | 98 | * Entry in hash table of all of our current (connected) neighbours. |
99 | */ | 99 | */ |
100 | struct Neighbour | 100 | struct Neighbour |
101 | { | 101 | { |
@@ -120,11 +120,11 @@ struct Neighbour | |||
120 | struct GNUNET_BANDWIDTH_Tracker out_tracker; | 120 | struct GNUNET_BANDWIDTH_Tracker out_tracker; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Entry in our readyness heap (which is sorted by 'next_ready' | 123 | * Entry in our readyness heap (which is sorted by @e next_ready |
124 | * value). NULL if there is no pending transmission request for | 124 | * value). NULL if there is no pending transmission request for |
125 | * this neighbour or if we're waiting for 'is_ready' to become | 125 | * this neighbour or if we're waiting for @e is_ready to become |
126 | * true AFTER the 'out_tracker' suggested that this peer's quota | 126 | * true AFTER the @e out_tracker suggested that this peer's quota |
127 | * has been satisfied (so once 'is_ready' goes to GNUNET_YES, | 127 | * has been satisfied (so once @e is_ready goes to #GNUNET_YES, |
128 | * we should immediately go back into the heap). | 128 | * we should immediately go back into the heap). |
129 | */ | 129 | */ |
130 | struct GNUNET_CONTAINER_HeapNode *hn; | 130 | struct GNUNET_CONTAINER_HeapNode *hn; |
@@ -180,8 +180,9 @@ struct GNUNET_TRANSPORT_GetHelloHandle | |||
180 | 180 | ||
181 | }; | 181 | }; |
182 | 182 | ||
183 | |||
183 | /** | 184 | /** |
184 | * Linked list for all try-connect requests | 185 | * Entry in linked list for a try-connect request. |
185 | */ | 186 | */ |
186 | struct GNUNET_TRANSPORT_TryConnectHandle | 187 | struct GNUNET_TRANSPORT_TryConnectHandle |
187 | { | 188 | { |
@@ -196,22 +197,22 @@ struct GNUNET_TRANSPORT_TryConnectHandle | |||
196 | struct GNUNET_TRANSPORT_TryConnectHandle *next; | 197 | struct GNUNET_TRANSPORT_TryConnectHandle *next; |
197 | 198 | ||
198 | /** | 199 | /** |
199 | * | 200 | * Peer we should try to connect to. |
200 | */ | 201 | */ |
201 | struct GNUNET_PeerIdentity pid; | 202 | struct GNUNET_PeerIdentity pid; |
202 | 203 | ||
203 | /** | 204 | /** |
204 | * | 205 | * Transport service handle this request is part of. |
205 | */ | 206 | */ |
206 | struct GNUNET_TRANSPORT_Handle *th; | 207 | struct GNUNET_TRANSPORT_Handle *th; |
207 | 208 | ||
208 | /** | 209 | /** |
209 | * | 210 | * Message transmission request to communicate to service. |
210 | */ | 211 | */ |
211 | struct GNUNET_TRANSPORT_TransmitHandle *tth; | 212 | struct GNUNET_TRANSPORT_TransmitHandle *tth; |
212 | 213 | ||
213 | /** | 214 | /** |
214 | * | 215 | * Function to call upon completion (of request transmission). |
215 | */ | 216 | */ |
216 | GNUNET_TRANSPORT_TryConnectCallback cb; | 217 | GNUNET_TRANSPORT_TryConnectCallback cb; |
217 | 218 | ||
@@ -220,16 +221,54 @@ struct GNUNET_TRANSPORT_TryConnectHandle | |||
220 | */ | 221 | */ |
221 | void *cb_cls; | 222 | void *cb_cls; |
222 | 223 | ||
224 | }; | ||
225 | |||
226 | |||
227 | /** | ||
228 | * Entry in linked list for all try-disconnect requests | ||
229 | */ | ||
230 | struct GNUNET_TRANSPORT_TryDisconnectHandle | ||
231 | { | ||
232 | /** | ||
233 | * For the DLL. | ||
234 | */ | ||
235 | struct GNUNET_TRANSPORT_TryDisconnectHandle *prev; | ||
236 | |||
223 | /** | 237 | /** |
224 | * | 238 | * For the DLL. |
239 | */ | ||
240 | struct GNUNET_TRANSPORT_TryDisconnectHandle *next; | ||
241 | |||
242 | /** | ||
243 | * Peer we should try to connect to. | ||
225 | */ | 244 | */ |
226 | int connect; | 245 | struct GNUNET_PeerIdentity pid; |
246 | |||
247 | /** | ||
248 | * Transport service handle this request is part of. | ||
249 | */ | ||
250 | struct GNUNET_TRANSPORT_Handle *th; | ||
251 | |||
252 | /** | ||
253 | * Message transmission request to communicate to service. | ||
254 | */ | ||
255 | struct GNUNET_TRANSPORT_TransmitHandle *tth; | ||
256 | |||
257 | /** | ||
258 | * Function to call upon completion (of request transmission). | ||
259 | */ | ||
260 | GNUNET_TRANSPORT_TryDisconnectCallback cb; | ||
261 | |||
262 | /** | ||
263 | * Closure for @e cb. | ||
264 | */ | ||
265 | void *cb_cls; | ||
227 | 266 | ||
228 | }; | 267 | }; |
229 | 268 | ||
230 | 269 | ||
231 | /** | 270 | /** |
232 | * Linked list for all try-connect requests | 271 | * Entry in linked list for all offer-HELLO requests. |
233 | */ | 272 | */ |
234 | struct GNUNET_TRANSPORT_OfferHelloHandle | 273 | struct GNUNET_TRANSPORT_OfferHelloHandle |
235 | { | 274 | { |
@@ -244,17 +283,17 @@ struct GNUNET_TRANSPORT_OfferHelloHandle | |||
244 | struct GNUNET_TRANSPORT_OfferHelloHandle *next; | 283 | struct GNUNET_TRANSPORT_OfferHelloHandle *next; |
245 | 284 | ||
246 | /** | 285 | /** |
247 | * | 286 | * Transport service handle we use for transmission. |
248 | */ | 287 | */ |
249 | struct GNUNET_TRANSPORT_Handle *th; | 288 | struct GNUNET_TRANSPORT_Handle *th; |
250 | 289 | ||
251 | /** | 290 | /** |
252 | * | 291 | * Transmission handle for this request. |
253 | */ | 292 | */ |
254 | struct GNUNET_TRANSPORT_TransmitHandle *tth; | 293 | struct GNUNET_TRANSPORT_TransmitHandle *tth; |
255 | 294 | ||
256 | /** | 295 | /** |
257 | * | 296 | * Function to call once we are done. |
258 | */ | 297 | */ |
259 | GNUNET_SCHEDULER_Task cont; | 298 | GNUNET_SCHEDULER_Task cont; |
260 | 299 | ||
@@ -264,7 +303,7 @@ struct GNUNET_TRANSPORT_OfferHelloHandle | |||
264 | void *cls; | 303 | void *cls; |
265 | 304 | ||
266 | /** | 305 | /** |
267 | * | 306 | * The HELLO message to be transmitted. |
268 | */ | 307 | */ |
269 | struct GNUNET_MessageHeader *msg; | 308 | struct GNUNET_MessageHeader *msg; |
270 | }; | 309 | }; |
@@ -349,6 +388,16 @@ struct GNUNET_TRANSPORT_Handle | |||
349 | struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail; | 388 | struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail; |
350 | 389 | ||
351 | /** | 390 | /** |
391 | * Linked list of pending try disconnect requests head | ||
392 | */ | ||
393 | struct GNUNET_TRANSPORT_TryDisconnectHandle *td_head; | ||
394 | |||
395 | /** | ||
396 | * Linked list of pending try connect requests tail | ||
397 | */ | ||
398 | struct GNUNET_TRANSPORT_TryDisconnectHandle *td_tail; | ||
399 | |||
400 | /** | ||
352 | * Linked list of pending offer HELLO requests head | 401 | * Linked list of pending offer HELLO requests head |
353 | */ | 402 | */ |
354 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head; | 403 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head; |
@@ -1163,29 +1212,33 @@ cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th, | |||
1163 | 1212 | ||
1164 | 1213 | ||
1165 | /** | 1214 | /** |
1166 | * Send REQUEST_CONNECT message to the service. | 1215 | * Send #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT message to the |
1216 | * service. | ||
1167 | * | 1217 | * |
1168 | * @param cls the `struct GNUNET_PeerIdentity` | 1218 | * @param cls the `struct GNUNET_TRANSPORT_TryConnectHandle` |
1169 | * @param size number of bytes available in @a buf | 1219 | * @param size number of bytes available in @a buf |
1170 | * @param buf where to copy the message | 1220 | * @param buf where to copy the message |
1171 | * @return number of bytes copied to @a buf | 1221 | * @return number of bytes copied to @a buf |
1172 | */ | 1222 | */ |
1173 | static size_t | 1223 | static size_t |
1174 | send_try_connect (void *cls, size_t size, void *buf) | 1224 | send_try_connect (void *cls, |
1225 | size_t size, | ||
1226 | void *buf) | ||
1175 | { | 1227 | { |
1176 | struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls; | 1228 | struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls; |
1177 | struct TransportRequestConnectMessage msg; | 1229 | struct TransportRequestConnectMessage msg; |
1178 | 1230 | ||
1231 | tch->tth = NULL; | ||
1179 | if (NULL == buf) | 1232 | if (NULL == buf) |
1180 | { | 1233 | { |
1181 | if (NULL != tch->cb) | ||
1182 | tch->cb (tch->cb_cls, GNUNET_SYSERR); | ||
1183 | GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch); | ||
1184 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1234 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1185 | "Discarding `%s' request to `%4s' due to error in transport service connection.\n", | 1235 | "Discarding `%s' request to `%4s' due to error in transport service connection.\n", |
1186 | "REQUEST_CONNECT", | 1236 | "REQUEST_CONNECT", |
1187 | GNUNET_i2s (&tch->pid)); | 1237 | GNUNET_i2s (&tch->pid)); |
1188 | GNUNET_free (tch); | 1238 | if (NULL != tch->cb) |
1239 | tch->cb (tch->cb_cls, | ||
1240 | GNUNET_SYSERR); | ||
1241 | GNUNET_TRANSPORT_try_connect_cancel (tch); | ||
1189 | return 0; | 1242 | return 0; |
1190 | } | 1243 | } |
1191 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1244 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1195,13 +1248,12 @@ send_try_connect (void *cls, size_t size, void *buf) | |||
1195 | GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); | 1248 | GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); |
1196 | msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); | 1249 | msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); |
1197 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); | 1250 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); |
1198 | msg.connect = htonl (tch->connect); | 1251 | msg.reserved = htonl (0); |
1199 | msg.peer = tch->pid; | 1252 | msg.peer = tch->pid; |
1200 | memcpy (buf, &msg, sizeof (msg)); | 1253 | memcpy (buf, &msg, sizeof (msg)); |
1201 | if (NULL != tch->cb) | 1254 | if (NULL != tch->cb) |
1202 | tch->cb (tch->cb_cls, GNUNET_OK); | 1255 | tch->cb (tch->cb_cls, GNUNET_OK); |
1203 | GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch); | 1256 | GNUNET_TRANSPORT_try_connect_cancel (tch); |
1204 | GNUNET_free (tch); | ||
1205 | return sizeof (struct TransportRequestConnectMessage); | 1257 | return sizeof (struct TransportRequestConnectMessage); |
1206 | } | 1258 | } |
1207 | 1259 | ||
@@ -1233,7 +1285,6 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, | |||
1233 | tch->pid = *(target); | 1285 | tch->pid = *(target); |
1234 | tch->cb = cb; | 1286 | tch->cb = cb; |
1235 | tch->cb_cls = cb_cls; | 1287 | tch->cb_cls = cb_cls; |
1236 | tch->connect = GNUNET_YES; | ||
1237 | tch->tth = schedule_control_transmit (handle, | 1288 | tch->tth = schedule_control_transmit (handle, |
1238 | sizeof (struct TransportRequestConnectMessage), | 1289 | sizeof (struct TransportRequestConnectMessage), |
1239 | &send_try_connect, tch); | 1290 | &send_try_connect, tch); |
@@ -1254,16 +1305,65 @@ void | |||
1254 | GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) | 1305 | GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) |
1255 | { | 1306 | { |
1256 | struct GNUNET_TRANSPORT_Handle *th; | 1307 | struct GNUNET_TRANSPORT_Handle *th; |
1257 | GNUNET_assert (GNUNET_YES == tch->connect); | ||
1258 | 1308 | ||
1259 | th = tch->th; | 1309 | th = tch->th; |
1260 | cancel_control_transmit (th, tch->tth); | 1310 | if (NULL != tch->tth) |
1261 | GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch); | 1311 | cancel_control_transmit (th, tch->tth); |
1312 | GNUNET_CONTAINER_DLL_remove (th->tc_head, | ||
1313 | th->tc_tail, | ||
1314 | tch); | ||
1262 | GNUNET_free (tch); | 1315 | GNUNET_free (tch); |
1263 | } | 1316 | } |
1264 | 1317 | ||
1265 | 1318 | ||
1266 | /** | 1319 | /** |
1320 | * Send #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT message to the | ||
1321 | * service. | ||
1322 | * | ||
1323 | * @param cls the `struct GNUNET_TRANSPORT_TryDisconnectHandle` | ||
1324 | * @param size number of bytes available in @a buf | ||
1325 | * @param buf where to copy the message | ||
1326 | * @return number of bytes copied to @a buf | ||
1327 | */ | ||
1328 | static size_t | ||
1329 | send_try_disconnect (void *cls, | ||
1330 | size_t size, | ||
1331 | void *buf) | ||
1332 | { | ||
1333 | struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh = cls; | ||
1334 | struct TransportRequestConnectMessage msg; | ||
1335 | |||
1336 | tdh->th = NULL; | ||
1337 | if (NULL == buf) | ||
1338 | { | ||
1339 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1340 | "Discarding `%s' request to `%4s' due to error in transport service connection.\n", | ||
1341 | "REQUEST_DISCONNECT", | ||
1342 | GNUNET_i2s (&tdh->pid)); | ||
1343 | if (NULL != tdh->cb) | ||
1344 | tdh->cb (tdh->cb_cls, | ||
1345 | GNUNET_SYSERR); | ||
1346 | GNUNET_TRANSPORT_try_disconnect_cancel (tdh); | ||
1347 | return 0; | ||
1348 | } | ||
1349 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1350 | "Transmitting `%s' request with respect to `%4s'.\n", | ||
1351 | "REQUEST_DISCONNECT", | ||
1352 | GNUNET_i2s (&tdh->pid)); | ||
1353 | GNUNET_assert (size >= sizeof (struct TransportRequestDisconnectMessage)); | ||
1354 | msg.header.size = htons (sizeof (struct TransportRequestDisconnectMessage)); | ||
1355 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT); | ||
1356 | msg.reserved = htonl (0); | ||
1357 | msg.peer = tdh->pid; | ||
1358 | memcpy (buf, &msg, sizeof (msg)); | ||
1359 | if (NULL != tdh->cb) | ||
1360 | tdh->cb (tdh->cb_cls, GNUNET_OK); | ||
1361 | GNUNET_TRANSPORT_try_disconnect_cancel (tdh); | ||
1362 | return sizeof (struct TransportRequestDisconnectMessage); | ||
1363 | } | ||
1364 | |||
1365 | |||
1366 | /** | ||
1267 | * Ask the transport service to shutdown a connection to | 1367 | * Ask the transport service to shutdown a connection to |
1268 | * the given peer. | 1368 | * the given peer. |
1269 | * | 1369 | * |
@@ -1272,32 +1372,31 @@ GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *t | |||
1272 | * @param cb callback to be called when request was transmitted to transport | 1372 | * @param cb callback to be called when request was transmitted to transport |
1273 | * service | 1373 | * service |
1274 | * @param cb_cls closure for the callback @a cb | 1374 | * @param cb_cls closure for the callback @a cb |
1275 | * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or | 1375 | * @return a `struct GNUNET_TRANSPORT_TryDisconnectHandle` handle or |
1276 | * NULL on failure (cb will not be called) | 1376 | * NULL on failure (cb will not be called) |
1277 | */ | 1377 | */ |
1278 | struct GNUNET_TRANSPORT_TryConnectHandle * | 1378 | struct GNUNET_TRANSPORT_TryDisconnectHandle * |
1279 | GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle, | 1379 | GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle, |
1280 | const struct GNUNET_PeerIdentity *target, | 1380 | const struct GNUNET_PeerIdentity *target, |
1281 | GNUNET_TRANSPORT_TryConnectCallback cb, | 1381 | GNUNET_TRANSPORT_TryDisconnectCallback cb, |
1282 | void *cb_cls) | 1382 | void *cb_cls) |
1283 | { | 1383 | { |
1284 | struct GNUNET_TRANSPORT_TryConnectHandle *tch; | 1384 | struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh; |
1285 | 1385 | ||
1286 | if (NULL == handle->client) | 1386 | if (NULL == handle->client) |
1287 | return NULL; | 1387 | return NULL; |
1288 | tch = GNUNET_new (struct GNUNET_TRANSPORT_TryConnectHandle); | 1388 | tdh = GNUNET_new (struct GNUNET_TRANSPORT_TryDisconnectHandle); |
1289 | tch->th = handle; | 1389 | tdh->th = handle; |
1290 | tch->pid = *(target); | 1390 | tdh->pid = *(target); |
1291 | tch->cb = cb; | 1391 | tdh->cb = cb; |
1292 | tch->cb_cls = cb_cls; | 1392 | tdh->cb_cls = cb_cls; |
1293 | tch->connect = GNUNET_NO; | 1393 | tdh->tth = schedule_control_transmit (handle, |
1294 | tch->tth = schedule_control_transmit (handle, | 1394 | sizeof (struct TransportRequestDisconnectMessage), |
1295 | sizeof (struct TransportRequestConnectMessage), | 1395 | &send_try_disconnect, tdh); |
1296 | &send_try_connect, tch); | 1396 | GNUNET_CONTAINER_DLL_insert (handle->td_head, |
1297 | GNUNET_CONTAINER_DLL_insert (handle->tc_head, | 1397 | handle->td_tail, |
1298 | handle->tc_tail, | 1398 | tdh); |
1299 | tch); | 1399 | return tdh; |
1300 | return tch; | ||
1301 | } | 1400 | } |
1302 | 1401 | ||
1303 | 1402 | ||
@@ -1305,18 +1404,20 @@ GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle, | |||
1305 | * Cancel the request to transport to try a disconnect | 1404 | * Cancel the request to transport to try a disconnect |
1306 | * Callback will not be called | 1405 | * Callback will not be called |
1307 | * | 1406 | * |
1308 | * @param tch the handle to cancel | 1407 | * @param tdh the handle to cancel |
1309 | */ | 1408 | */ |
1310 | void | 1409 | void |
1311 | GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) | 1410 | GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh) |
1312 | { | 1411 | { |
1313 | struct GNUNET_TRANSPORT_Handle *th; | 1412 | struct GNUNET_TRANSPORT_Handle *th; |
1314 | 1413 | ||
1315 | GNUNET_assert (GNUNET_NO == tch->connect); | 1414 | th = tdh->th; |
1316 | th = tch->th; | 1415 | if (NULL != tdh->tth) |
1317 | cancel_control_transmit (th, tch->tth); | 1416 | cancel_control_transmit (th, tdh->tth); |
1318 | GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch); | 1417 | GNUNET_CONTAINER_DLL_remove (th->td_head, |
1319 | GNUNET_free (tch); | 1418 | th->td_tail, |
1419 | tdh); | ||
1420 | GNUNET_free (tdh); | ||
1320 | } | 1421 | } |
1321 | 1422 | ||
1322 | 1423 | ||