diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-25 00:30:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-25 00:30:00 +0000 |
commit | d0701eb6315fc3f5aca74415bbf0ff7418409f87 (patch) | |
tree | fcacb97bbcca542ce9493001c825fd265cb8a801 /src | |
parent | 9bfb8bff3fd253407530c76c7590b33bacf033f1 (diff) | |
download | gnunet-d0701eb6315fc3f5aca74415bbf0ff7418409f87.tar.gz gnunet-d0701eb6315fc3f5aca74415bbf0ff7418409f87.zip |
switching transport tests to new MQ-based transport API
Diffstat (limited to 'src')
29 files changed, 754 insertions, 391 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 0faec4cfc..0ba6f8c74 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -118,6 +118,11 @@ gnunetinclude_HEADERS = \ | |||
118 | gnunet_testing_lib.h \ | 118 | gnunet_testing_lib.h \ |
119 | gnunet_time_lib.h \ | 119 | gnunet_time_lib.h \ |
120 | gnunet_transport_service.h \ | 120 | gnunet_transport_service.h \ |
121 | gnunet_transport_communication_service.h \ | ||
122 | gnunet_transport_core_service.h \ | ||
123 | gnunet_transport_hello_service.h \ | ||
124 | gnunet_transport_manipulation_service.h \ | ||
125 | gnunet_transport_monitor_service.h \ | ||
121 | gnunet_transport_plugin.h \ | 126 | gnunet_transport_plugin.h \ |
122 | gnunet_tun_lib.h \ | 127 | gnunet_tun_lib.h \ |
123 | gnunet_util_lib.h \ | 128 | gnunet_util_lib.h \ |
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h index 6dada4f54..941ef27e4 100644 --- a/src/include/gnunet_transport_core_service.h +++ b/src/include/gnunet_transport_core_service.h | |||
@@ -60,7 +60,10 @@ struct GNUNET_TRANSPORT_CoreHandle; | |||
60 | * peer connected to us. | 60 | * peer connected to us. |
61 | * | 61 | * |
62 | * @param cls closure | 62 | * @param cls closure |
63 | * @param peer the peer that connected | 63 | * @param peer the identity of the peer that connected; this |
64 | * pointer will remain valid until the disconnect, hence | ||
65 | * applications do not necessarily have to make a copy | ||
66 | * of the value if they only need it until disconnect | ||
64 | * @param mq message queue to use to transmit to @a peer | 67 | * @param mq message queue to use to transmit to @a peer |
65 | * @return closure to use in MQ handlers | 68 | * @return closure to use in MQ handlers |
66 | */ | 69 | */ |
diff --git a/src/include/gnunet_transport_manipulation_service.h b/src/include/gnunet_transport_manipulation_service.h new file mode 100644 index 000000000..8c1789636 --- /dev/null +++ b/src/include/gnunet_transport_manipulation_service.h | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2014, 2016 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Christian Grothoff | ||
23 | * | ||
24 | * @file | ||
25 | * Low-level P2P IO | ||
26 | * | ||
27 | * @defgroup transport Transport service | ||
28 | * Low-level P2P IO | ||
29 | * | ||
30 | * @see [Documentation](https://gnunet.org/transport-service) | ||
31 | * | ||
32 | * @{ | ||
33 | */ | ||
34 | |||
35 | #ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H | ||
36 | #define GNUNET_TRANSPORT_MANIPULATION_SERVICE_H | ||
37 | |||
38 | |||
39 | #ifdef __cplusplus | ||
40 | extern "C" | ||
41 | { | ||
42 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
43 | } | ||
44 | #endif | ||
45 | #endif | ||
46 | |||
47 | #include "gnunet_util_lib.h" | ||
48 | #include "gnunet_ats_service.h" | ||
49 | |||
50 | /** | ||
51 | * Version number of the transport API. | ||
52 | */ | ||
53 | #define GNUNET_TRANSPORT_MANIPULATION_VERSION 0x00000003 | ||
54 | |||
55 | /** | ||
56 | * Handle for transport manipulation. | ||
57 | */ | ||
58 | struct GNUNET_TRANSPORT_ManipulationHandle; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Connect to the transport service. Note that the connection may | ||
63 | * complete (or fail) asynchronously. | ||
64 | * | ||
65 | * @param cfg configuration to use | ||
66 | * @return NULL on error | ||
67 | */ | ||
68 | struct GNUNET_TRANSPORT_ManipulationHandle * | ||
69 | GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Disconnect from the transport service. | ||
74 | * | ||
75 | * @param handle handle returned from connect | ||
76 | */ | ||
77 | void | ||
78 | GNUNET_TRANSPORT_manipulation_disconnect (struct GNUNET_TRANSPORT_ManipulationHandle *handle); | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Set transport metrics for a peer and a direction | ||
83 | * | ||
84 | * @param handle transport handle | ||
85 | * @param peer the peer to set the metric for | ||
86 | * @param prop the performance metrics to set | ||
87 | * @param delay_in inbound delay to introduce | ||
88 | * @param delay_out outbound delay to introduce | ||
89 | * | ||
90 | * Note: Delay restrictions in receiving direction will be enforced | ||
91 | * with one message delay. | ||
92 | */ | ||
93 | void | ||
94 | GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *handle, | ||
95 | const struct GNUNET_PeerIdentity *peer, | ||
96 | const struct GNUNET_ATS_Properties *prop, | ||
97 | struct GNUNET_TIME_Relative delay_in, | ||
98 | struct GNUNET_TIME_Relative delay_out); | ||
99 | |||
100 | |||
101 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
102 | { | ||
103 | #endif | ||
104 | #ifdef __cplusplus | ||
105 | } | ||
106 | #endif | ||
107 | |||
108 | /* ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H */ | ||
109 | #endif | ||
110 | |||
111 | /** @} */ /* end of group */ | ||
112 | |||
113 | /* end of gnunet_transport_manipulation_service.h */ | ||
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index b201ab24a..1579602da 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -171,6 +171,7 @@ libgnunettransport_la_SOURCES = \ | |||
171 | transport_api_blacklist.c \ | 171 | transport_api_blacklist.c \ |
172 | transport_api_core.c \ | 172 | transport_api_core.c \ |
173 | transport_api_get_hello.c \ | 173 | transport_api_get_hello.c \ |
174 | transport_api_manipulation.c \ | ||
174 | transport_api_monitor_peers.c \ | 175 | transport_api_monitor_peers.c \ |
175 | transport_api_monitor_plugins.c \ | 176 | transport_api_monitor_plugins.c \ |
176 | transport_api_offer_hello.c | 177 | transport_api_offer_hello.c |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 71c8c0054..02d2428d3 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -1366,18 +1366,24 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, | |||
1366 | int may_drop) | 1366 | int may_drop) |
1367 | { | 1367 | { |
1368 | struct TransportClient *tc; | 1368 | struct TransportClient *tc; |
1369 | int done; | ||
1369 | 1370 | ||
1370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1371 | "Asked to broadcast message of type %u with %u bytes\n", | 1372 | "Asked to broadcast message of type %u with %u bytes\n", |
1372 | (unsigned int) ntohs (msg->type), | 1373 | (unsigned int) ntohs (msg->type), |
1373 | (unsigned int) ntohs (msg->size)); | 1374 | (unsigned int) ntohs (msg->size)); |
1375 | done = GNUNET_NO; | ||
1374 | for (tc = clients_head; NULL != tc; tc = tc->next) | 1376 | for (tc = clients_head; NULL != tc; tc = tc->next) |
1375 | { | 1377 | { |
1376 | if ( (GNUNET_YES == may_drop) && | 1378 | if ( (GNUNET_YES == may_drop) && |
1377 | (GNUNET_YES != tc->send_payload) ) | 1379 | (GNUNET_YES != tc->send_payload) ) |
1378 | continue; /* skip, this client does not care about payload */ | 1380 | continue; /* skip, this client does not care about payload */ |
1379 | unicast (tc, msg, may_drop); | 1381 | unicast (tc, msg, may_drop); |
1382 | done = GNUNET_YES; | ||
1380 | } | 1383 | } |
1384 | if (GNUNET_NO == done) | ||
1385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1386 | "Message not delivered, is CORE service up?\n"); | ||
1381 | } | 1387 | } |
1382 | 1388 | ||
1383 | 1389 | ||
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 76fb1ce5a..376065d24 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -1888,9 +1888,10 @@ handle_helper_message (void *cls, void *client, | |||
1888 | break; | 1888 | break; |
1889 | default: | 1889 | default: |
1890 | GNUNET_break (0); | 1890 | GNUNET_break (0); |
1891 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1891 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1892 | "Unexpected message of type %u (%u bytes)", | 1892 | "Unexpected message of type %u (%u bytes)", |
1893 | ntohs (hdr->type), ntohs (hdr->size)); | 1893 | ntohs (hdr->type), |
1894 | ntohs (hdr->size)); | ||
1894 | break; | 1895 | break; |
1895 | } | 1896 | } |
1896 | return GNUNET_OK; | 1897 | return GNUNET_OK; |
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 5bd3f0237..73b773b88 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -127,14 +127,12 @@ static void | |||
127 | notify_receive (void *cls, | 127 | notify_receive (void *cls, |
128 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 128 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
129 | const struct GNUNET_PeerIdentity *sender, | 129 | const struct GNUNET_PeerIdentity *sender, |
130 | const struct GNUNET_MessageHeader *message) | 130 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) |
131 | { | 131 | { |
132 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr; | ||
133 | 132 | ||
134 | hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message; | 133 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) |
135 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) | ||
136 | return; | 134 | return; |
137 | total_bytes_recv += ntohs (message->size); | 135 | total_bytes_recv += ntohs (hdr->header.size); |
138 | 136 | ||
139 | { | 137 | { |
140 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 138 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
@@ -144,7 +142,7 @@ notify_receive (void *cls, | |||
144 | receiver->no, | 142 | receiver->no, |
145 | ps, | 143 | ps, |
146 | ntohl (hdr->num), | 144 | ntohl (hdr->num), |
147 | ntohs (message->size), | 145 | ntohs (hdr->header.size), |
148 | GNUNET_i2s (sender)); | 146 | GNUNET_i2s (sender)); |
149 | GNUNET_free (ps); | 147 | GNUNET_free (ps); |
150 | } | 148 | } |
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 3998854da..9217d8f90 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -286,12 +286,9 @@ static void | |||
286 | notify_receive (void *cls, | 286 | notify_receive (void *cls, |
287 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 287 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
288 | const struct GNUNET_PeerIdentity *sender, | 288 | const struct GNUNET_PeerIdentity *sender, |
289 | const struct GNUNET_MessageHeader *message) | 289 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) |
290 | { | 290 | { |
291 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr; | 291 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) |
292 | |||
293 | hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message; | ||
294 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) | ||
295 | return; | 292 | return; |
296 | 293 | ||
297 | { | 294 | { |
@@ -302,7 +299,7 @@ notify_receive (void *cls, | |||
302 | receiver->no, | 299 | receiver->no, |
303 | ps, | 300 | ps, |
304 | ntohl (hdr->num), | 301 | ntohl (hdr->num), |
305 | ntohs (message->size), | 302 | ntohs (hdr->header.size), |
306 | GNUNET_i2s (sender)); | 303 | GNUNET_i2s (sender)); |
307 | GNUNET_free (ps); | 304 | GNUNET_free (ps); |
308 | } | 305 | } |
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index d4ae1cf53..2f55631c3 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -43,7 +43,7 @@ static void | |||
43 | notify_receive (void *cls, | 43 | notify_receive (void *cls, |
44 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 44 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
45 | const struct GNUNET_PeerIdentity *sender, | 45 | const struct GNUNET_PeerIdentity *sender, |
46 | const struct GNUNET_MessageHeader *message) | 46 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
47 | { | 47 | { |
48 | { | 48 | { |
49 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 49 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
@@ -52,14 +52,14 @@ notify_receive (void *cls, | |||
52 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", | 52 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
53 | receiver->no, | 53 | receiver->no, |
54 | ps, | 54 | ps, |
55 | ntohs (message->type), | 55 | ntohs (message->header.type), |
56 | ntohs (message->size), | 56 | ntohs (message->header.size), |
57 | GNUNET_i2s (sender)); | 57 | GNUNET_i2s (sender)); |
58 | GNUNET_free (ps); | 58 | GNUNET_free (ps); |
59 | } | 59 | } |
60 | 60 | ||
61 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && | 61 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && |
62 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->size))) | 62 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->header.size))) |
63 | { | 63 | { |
64 | ccc->global_ret = GNUNET_OK; | 64 | ccc->global_ret = GNUNET_OK; |
65 | GNUNET_SCHEDULER_shutdown (); | 65 | GNUNET_SCHEDULER_shutdown (); |
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c index c3675bb9a..76780a48a 100644 --- a/src/transport/test_transport_api_blacklisting.c +++ b/src/transport/test_transport_api_blacklisting.c | |||
@@ -94,7 +94,7 @@ static void | |||
94 | notify_receive (void *cls, | 94 | notify_receive (void *cls, |
95 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 95 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
96 | const struct GNUNET_PeerIdentity *sender, | 96 | const struct GNUNET_PeerIdentity *sender, |
97 | const struct GNUNET_MessageHeader *message) | 97 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
98 | { | 98 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 99 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
100 | "Unexpectedly even received the message despite blacklist\n"); | 100 | "Unexpectedly even received the message despite blacklist\n"); |
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index c8cf89d7e..870d9e4c2 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c | |||
@@ -77,22 +77,22 @@ static void | |||
77 | notify_receive (void *cls, | 77 | notify_receive (void *cls, |
78 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 78 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
79 | const struct GNUNET_PeerIdentity *sender, | 79 | const struct GNUNET_PeerIdentity *sender, |
80 | const struct GNUNET_MessageHeader *message) | 80 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
81 | { | 81 | { |
82 | { | 82 | { |
83 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 83 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
84 | 84 | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n", | 86 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
87 | receiver->no, | 87 | receiver->no, |
88 | ps, | 88 | ps, |
89 | ntohs (message->type), | 89 | ntohs (message->header.type), |
90 | ntohs (message->size), | 90 | ntohs (message->header.size), |
91 | GNUNET_i2s (sender)); | 91 | GNUNET_i2s (sender)); |
92 | GNUNET_free (ps); | 92 | GNUNET_free (ps); |
93 | } | 93 | } |
94 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && | 94 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && |
95 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size))) | 95 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size))) |
96 | { | 96 | { |
97 | GNUNET_SCHEDULER_add_now (&stop_peer, | 97 | GNUNET_SCHEDULER_add_now (&stop_peer, |
98 | NULL); | 98 | NULL); |
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index 1b82ade70..e487748aa 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c | |||
@@ -47,16 +47,16 @@ static void | |||
47 | notify_receive (void *cls, | 47 | notify_receive (void *cls, |
48 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 48 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
49 | const struct GNUNET_PeerIdentity *sender, | 49 | const struct GNUNET_PeerIdentity *sender, |
50 | const struct GNUNET_MessageHeader *message) | 50 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
51 | { | 51 | { |
52 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 52 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
53 | "Received message of type %d from peer %s!\n", | 53 | "Received message of type %d from peer %s!\n", |
54 | ntohs (message->type), | 54 | ntohs (message->header.type), |
55 | GNUNET_i2s (sender)); | 55 | GNUNET_i2s (sender)); |
56 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == | 56 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == |
57 | ntohs (message->type)) && | 57 | ntohs (message->header.type)) && |
58 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == | 58 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == |
59 | ntohs (message->size)) ) | 59 | ntohs (message->header.size)) ) |
60 | { | 60 | { |
61 | ccc->global_ret = GNUNET_OK; | 61 | ccc->global_ret = GNUNET_OK; |
62 | } | 62 | } |
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index 84824ad8b..a2312a872 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.c | |||
@@ -40,7 +40,7 @@ | |||
40 | 40 | ||
41 | #define TEST_MESSAGE_SIZE 2600 | 41 | #define TEST_MESSAGE_SIZE 2600 |
42 | 42 | ||
43 | #define TEST_RESPONSE_MESSAGE_TYPE 12346 | 43 | #define TEST_RESPONSE_MESSAGE_TYPE |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Test delay, in microseconds. | 46 | * Test delay, in microseconds. |
@@ -63,7 +63,7 @@ sendtask_response_task (void *cls) | |||
63 | start_response = GNUNET_TIME_absolute_get(); | 63 | start_response = GNUNET_TIME_absolute_get(); |
64 | ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 64 | ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1], |
65 | ccc->p[0], | 65 | ccc->p[0], |
66 | TEST_RESPONSE_MESSAGE_TYPE, | 66 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, |
67 | TEST_MESSAGE_SIZE, | 67 | TEST_MESSAGE_SIZE, |
68 | 1, | 68 | 1, |
69 | NULL, | 69 | NULL, |
@@ -82,7 +82,7 @@ static void | |||
82 | notify_receive (void *cls, | 82 | notify_receive (void *cls, |
83 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 83 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
84 | const struct GNUNET_PeerIdentity *sender, | 84 | const struct GNUNET_PeerIdentity *sender, |
85 | const struct GNUNET_MessageHeader *message) | 85 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
86 | { | 86 | { |
87 | struct GNUNET_TIME_Relative duration; | 87 | struct GNUNET_TIME_Relative duration; |
88 | 88 | ||
@@ -93,13 +93,13 @@ notify_receive (void *cls, | |||
93 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", | 93 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
94 | receiver->no, | 94 | receiver->no, |
95 | ps, | 95 | ps, |
96 | ntohs (message->type), | 96 | ntohs (message->header.type), |
97 | ntohs (message->size), | 97 | ntohs (message->header.size), |
98 | GNUNET_i2s (sender)); | 98 | GNUNET_i2s (sender)); |
99 | GNUNET_free (ps); | 99 | GNUNET_free (ps); |
100 | } | 100 | } |
101 | 101 | ||
102 | switch (ntohs (message->type)) { | 102 | switch (ntohs (message->header.type)) { |
103 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: | 103 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: |
104 | duration = GNUNET_TIME_absolute_get_difference (start_request, | 104 | duration = GNUNET_TIME_absolute_get_difference (start_request, |
105 | GNUNET_TIME_absolute_get()); | 105 | GNUNET_TIME_absolute_get()); |
@@ -123,7 +123,7 @@ notify_receive (void *cls, | |||
123 | GNUNET_SCHEDULER_add_now (&sendtask_response_task, | 123 | GNUNET_SCHEDULER_add_now (&sendtask_response_task, |
124 | NULL); | 124 | NULL); |
125 | return; | 125 | return; |
126 | case TEST_RESPONSE_MESSAGE_TYPE: | 126 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2: |
127 | duration = GNUNET_TIME_absolute_get_difference(start_response, | 127 | duration = GNUNET_TIME_absolute_get_difference(start_response, |
128 | GNUNET_TIME_absolute_get()); | 128 | GNUNET_TIME_absolute_get()); |
129 | if (duration.rel_value_us >= TEST_DELAY) | 129 | if (duration.rel_value_us >= TEST_DELAY) |
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c index e902aed62..3014715b1 100644 --- a/src/transport/test_transport_api_manipulation_recv_tcp.c +++ b/src/transport/test_transport_api_manipulation_recv_tcp.c | |||
@@ -79,11 +79,11 @@ sendtask (void *cls) | |||
79 | { | 79 | { |
80 | memset (&prop, 0, sizeof (prop)); | 80 | memset (&prop, 0, sizeof (prop)); |
81 | delay = GNUNET_TIME_UNIT_SECONDS; | 81 | delay = GNUNET_TIME_UNIT_SECONDS; |
82 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th, | 82 | GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh, |
83 | &ccc->p[0]->id, | 83 | &ccc->p[0]->id, |
84 | &prop, | 84 | &prop, |
85 | delay, | 85 | delay, |
86 | GNUNET_TIME_UNIT_ZERO); | 86 | GNUNET_TIME_UNIT_ZERO); |
87 | start_delayed = GNUNET_TIME_absolute_get(); | 87 | start_delayed = GNUNET_TIME_absolute_get(); |
88 | } | 88 | } |
89 | GNUNET_TRANSPORT_TESTING_large_send (sc); | 89 | GNUNET_TRANSPORT_TESTING_large_send (sc); |
@@ -94,7 +94,7 @@ static void | |||
94 | notify_receive (void *cls, | 94 | notify_receive (void *cls, |
95 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 95 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
96 | const struct GNUNET_PeerIdentity *sender, | 96 | const struct GNUNET_PeerIdentity *sender, |
97 | const struct GNUNET_MessageHeader *message) | 97 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
98 | { | 98 | { |
99 | { | 99 | { |
100 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 100 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
@@ -103,13 +103,13 @@ notify_receive (void *cls, | |||
103 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", | 103 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
104 | receiver->no, | 104 | receiver->no, |
105 | ps, | 105 | ps, |
106 | ntohs (message->type), | 106 | ntohs (message->header.type), |
107 | ntohs (message->size), | 107 | ntohs (message->header.size), |
108 | GNUNET_i2s (sender)); | 108 | GNUNET_i2s (sender)); |
109 | GNUNET_free (ps); | 109 | GNUNET_free (ps); |
110 | } | 110 | } |
111 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) || | 111 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) || |
112 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->size)) ) | 112 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) ) |
113 | { | 113 | { |
114 | GNUNET_break (0); | 114 | GNUNET_break (0); |
115 | ccc->global_ret = GNUNET_SYSERR; | 115 | ccc->global_ret = GNUNET_SYSERR; |
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c index 95a6b5140..fbb7ccbdb 100644 --- a/src/transport/test_transport_api_manipulation_send_tcp.c +++ b/src/transport/test_transport_api_manipulation_send_tcp.c | |||
@@ -78,11 +78,11 @@ sendtask (void *cls) | |||
78 | { | 78 | { |
79 | memset (&prop, 0, sizeof (prop)); | 79 | memset (&prop, 0, sizeof (prop)); |
80 | delay = GNUNET_TIME_UNIT_SECONDS; | 80 | delay = GNUNET_TIME_UNIT_SECONDS; |
81 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th, | 81 | GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh, |
82 | &ccc->p[1]->id, | 82 | &ccc->p[1]->id, |
83 | &prop, | 83 | &prop, |
84 | GNUNET_TIME_UNIT_ZERO, | 84 | GNUNET_TIME_UNIT_ZERO, |
85 | delay); | 85 | delay); |
86 | start_delayed = GNUNET_TIME_absolute_get(); | 86 | start_delayed = GNUNET_TIME_absolute_get(); |
87 | } | 87 | } |
88 | GNUNET_TRANSPORT_TESTING_large_send (sc); | 88 | GNUNET_TRANSPORT_TESTING_large_send (sc); |
@@ -93,7 +93,7 @@ static void | |||
93 | notify_receive (void *cls, | 93 | notify_receive (void *cls, |
94 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 94 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
95 | const struct GNUNET_PeerIdentity *sender, | 95 | const struct GNUNET_PeerIdentity *sender, |
96 | const struct GNUNET_MessageHeader *message) | 96 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
97 | { | 97 | { |
98 | { | 98 | { |
99 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 99 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
@@ -102,14 +102,14 @@ notify_receive (void *cls, | |||
102 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", | 102 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
103 | receiver->no, | 103 | receiver->no, |
104 | ps, | 104 | ps, |
105 | ntohs (message->type), | 105 | ntohs (message->header.type), |
106 | ntohs (message->size), | 106 | ntohs (message->header.size), |
107 | GNUNET_i2s (sender)); | 107 | GNUNET_i2s (sender)); |
108 | GNUNET_free (ps); | 108 | GNUNET_free (ps); |
109 | } | 109 | } |
110 | 110 | ||
111 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) || | 111 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) || |
112 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->size)) ) | 112 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) ) |
113 | { | 113 | { |
114 | GNUNET_break (0); | 114 | GNUNET_break (0); |
115 | ccc->global_ret = GNUNET_SYSERR; | 115 | ccc->global_ret = GNUNET_SYSERR; |
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c index 1f0eb184c..37f50c4fc 100644 --- a/src/transport/test_transport_api_monitor_peers.c +++ b/src/transport/test_transport_api_monitor_peers.c | |||
@@ -81,7 +81,7 @@ static void | |||
81 | notify_receive (void *cls, | 81 | notify_receive (void *cls, |
82 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 82 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
83 | const struct GNUNET_PeerIdentity *sender, | 83 | const struct GNUNET_PeerIdentity *sender, |
84 | const struct GNUNET_MessageHeader *message) | 84 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
85 | { | 85 | { |
86 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 86 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
87 | 87 | ||
@@ -89,8 +89,8 @@ notify_receive (void *cls, | |||
89 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", | 89 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
90 | receiver->no, | 90 | receiver->no, |
91 | ps, | 91 | ps, |
92 | ntohs (message->type), | 92 | ntohs (message->header.type), |
93 | ntohs (message->size), | 93 | ntohs (message->header.size), |
94 | GNUNET_i2s (sender)); | 94 | GNUNET_i2s (sender)); |
95 | GNUNET_free (ps); | 95 | GNUNET_free (ps); |
96 | } | 96 | } |
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 24ad4b81e..d6702cc25 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -50,6 +50,11 @@ | |||
50 | */ | 50 | */ |
51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) | 51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) |
52 | 52 | ||
53 | /** | ||
54 | * If we are in an "xhdr" test, the factor by which we divide | ||
55 | * #TOTAL_MSGS for a more sane test duration. | ||
56 | */ | ||
57 | static unsigned int xhdr = 1; | ||
53 | 58 | ||
54 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 59 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
55 | 60 | ||
@@ -105,7 +110,7 @@ get_size (unsigned int iter) | |||
105 | static size_t | 110 | static size_t |
106 | get_size_cnt (unsigned int cnt_down) | 111 | get_size_cnt (unsigned int cnt_down) |
107 | { | 112 | { |
108 | size_t ret = get_size (TOTAL_MSGS - 1 - cnt_down); | 113 | size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down); |
109 | 114 | ||
110 | total_bytes += ret; | 115 | total_bytes += ret; |
111 | return ret; | 116 | return ret; |
@@ -189,7 +194,7 @@ custom_shutdown (void *cls) | |||
189 | } | 194 | } |
190 | 195 | ||
191 | ok = 0; | 196 | ok = 0; |
192 | for (unsigned int i = 0; i < TOTAL_MSGS; i++) | 197 | for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) |
193 | { | 198 | { |
194 | if (get_bit (bitmap, i) == 0) | 199 | if (get_bit (bitmap, i) == 0) |
195 | { | 200 | { |
@@ -208,27 +213,24 @@ static void | |||
208 | notify_receive (void *cls, | 213 | notify_receive (void *cls, |
209 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 214 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
210 | const struct GNUNET_PeerIdentity *sender, | 215 | const struct GNUNET_PeerIdentity *sender, |
211 | const struct GNUNET_MessageHeader *message) | 216 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) |
212 | { | 217 | { |
213 | static int n; | 218 | static int n; |
214 | unsigned int s; | 219 | unsigned int s; |
215 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 220 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
216 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr; | ||
217 | |||
218 | hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message; | ||
219 | 221 | ||
220 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) | 222 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) |
221 | return; | 223 | return; |
222 | msg_recv = ntohl (hdr->num); | 224 | msg_recv = ntohl (hdr->num); |
223 | s = get_size (ntohl (hdr->num)); | 225 | s = get_size (ntohl (hdr->num)); |
224 | 226 | ||
225 | if (ntohs (message->size) != s) | 227 | if (ntohs (hdr->header.size) != s) |
226 | { | 228 | { |
227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 229 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
228 | "Expected message %u of size %u, got %u bytes of message %u\n", | 230 | "Expected message %u of size %u, got %u bytes of message %u\n", |
229 | ntohl (hdr->num), | 231 | ntohl (hdr->num), |
230 | s, | 232 | s, |
231 | ntohs (message->size), | 233 | ntohs (hdr->header.size), |
232 | ntohl (hdr->num)); | 234 | ntohl (hdr->num)); |
233 | ccc->global_ret = GNUNET_SYSERR; | 235 | ccc->global_ret = GNUNET_SYSERR; |
234 | GNUNET_SCHEDULER_shutdown (); | 236 | GNUNET_SCHEDULER_shutdown (); |
@@ -257,7 +259,7 @@ notify_receive (void *cls, | |||
257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
258 | "Got message %u of size %u\n", | 260 | "Got message %u of size %u\n", |
259 | ntohl (hdr->num), | 261 | ntohl (hdr->num), |
260 | ntohs (message->size)); | 262 | ntohs (hdr->header.size)); |
261 | } | 263 | } |
262 | #endif | 264 | #endif |
263 | n++; | 265 | n++; |
@@ -266,13 +268,13 @@ notify_receive (void *cls, | |||
266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
267 | "Message id %u is bigger than maxmimum number of messages %u expected\n", | 269 | "Message id %u is bigger than maxmimum number of messages %u expected\n", |
268 | ntohl (hdr->num), | 270 | ntohl (hdr->num), |
269 | TOTAL_MSGS); | 271 | TOTAL_MSGS / xhdr); |
270 | } | 272 | } |
271 | if (0 == (n % (TOTAL_MSGS / 100))) | 273 | if (0 == (n % (TOTAL_MSGS / xhdr / 100))) |
272 | { | 274 | { |
273 | FPRINTF (stderr, "%s", "."); | 275 | FPRINTF (stderr, "%s", "."); |
274 | } | 276 | } |
275 | if (n == TOTAL_MSGS) | 277 | if (n == TOTAL_MSGS / xhdr) |
276 | { | 278 | { |
277 | /* end testcase with success */ | 279 | /* end testcase with success */ |
278 | ccc->global_ret = GNUNET_OK; | 280 | ccc->global_ret = GNUNET_OK; |
@@ -284,8 +286,10 @@ notify_receive (void *cls, | |||
284 | int | 286 | int |
285 | main (int argc, char *argv[]) | 287 | main (int argc, char *argv[]) |
286 | { | 288 | { |
289 | if (0 == strstr (argv[0], "xhdr")) | ||
290 | xhdr = 30; | ||
287 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | 291 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { |
288 | .num_messages = TOTAL_MSGS, | 292 | .num_messages = TOTAL_MSGS / xhdr, |
289 | .get_size_cb = &get_size_cnt | 293 | .get_size_cb = &get_size_cnt |
290 | }; | 294 | }; |
291 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 295 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c index 6fd969918..477b8b54d 100644 --- a/src/transport/test_transport_api_restart_reconnect.c +++ b/src/transport/test_transport_api_restart_reconnect.c | |||
@@ -58,11 +58,11 @@ custom_shutdown (void *cls) | |||
58 | 58 | ||
59 | 59 | ||
60 | static void | 60 | static void |
61 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 61 | restart_cb (void *cls) |
62 | void *cls) | ||
63 | { | 62 | { |
64 | static unsigned int c; | 63 | static unsigned int c; |
65 | 64 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | |
65 | |||
66 | c++; | 66 | c++; |
67 | if ( (2 != c) && | 67 | if ( (2 != c) && |
68 | (NULL != strstr (ccc->test_name, | 68 | (NULL != strstr (ccc->test_name, |
@@ -96,7 +96,7 @@ static void | |||
96 | notify_receive (void *cls, | 96 | notify_receive (void *cls, |
97 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 97 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
98 | const struct GNUNET_PeerIdentity *sender, | 98 | const struct GNUNET_PeerIdentity *sender, |
99 | const struct GNUNET_MessageHeader *message) | 99 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
100 | { | 100 | { |
101 | { | 101 | { |
102 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 102 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
@@ -105,13 +105,13 @@ notify_receive (void *cls, | |||
105 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", | 105 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
106 | receiver->no, | 106 | receiver->no, |
107 | ps, | 107 | ps, |
108 | ntohs (message->type), | 108 | ntohs (message->header.type), |
109 | ntohs (message->size), | 109 | ntohs (message->header.size), |
110 | GNUNET_i2s (sender)); | 110 | GNUNET_i2s (sender)); |
111 | GNUNET_free (ps); | 111 | GNUNET_free (ps); |
112 | } | 112 | } |
113 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && | 113 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && |
114 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size)) ) | 114 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size)) ) |
115 | { | 115 | { |
116 | if (GNUNET_NO == restarted) | 116 | if (GNUNET_NO == restarted) |
117 | { | 117 | { |
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index 05fb01d1d..042cbebed 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c | |||
@@ -79,11 +79,11 @@ static void | |||
79 | notify_receive (void *cls, | 79 | notify_receive (void *cls, |
80 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 80 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
81 | const struct GNUNET_PeerIdentity *sender, | 81 | const struct GNUNET_PeerIdentity *sender, |
82 | const struct GNUNET_MessageHeader *message) | 82 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
83 | { | 83 | { |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
85 | "Received message of type %d from peer %s!\n", | 85 | "Received message of type %d from peer %s!\n", |
86 | ntohs (message->type), | 86 | ntohs (message->header.type), |
87 | GNUNET_i2s (sender)); | 87 | GNUNET_i2s (sender)); |
88 | } | 88 | } |
89 | 89 | ||
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 4d5433713..595177e03 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c | |||
@@ -64,8 +64,7 @@ end_badly () | |||
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 67 | restart_cb (void *cls) |
68 | void *cls) | ||
69 | { | 68 | { |
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
71 | "Peer %u (`%s') successfully restarted\n", | 70 | "Peer %u (`%s') successfully restarted\n", |
@@ -90,8 +89,7 @@ restart_task () | |||
90 | 89 | ||
91 | 90 | ||
92 | static void | 91 | static void |
93 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 92 | start_cb (void *cls) |
94 | void *cls) | ||
95 | { | 93 | { |
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
97 | "Peer %u (`%s') successfully started\n", | 95 | "Peer %u (`%s') successfully started\n", |
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index 0846357e6..6ac0250cc 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -64,8 +64,7 @@ end_badly () | |||
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 67 | start_cb (void *cls) |
68 | void *cls) | ||
69 | { | 68 | { |
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
71 | "Peer %u (`%s') successfully started\n", | 70 | "Peer %u (`%s') successfully started\n", |
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index 79f6a0152..bba37eee8 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c | |||
@@ -145,6 +145,23 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext | |||
145 | 145 | ||
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Information tracked per connected peer. | ||
149 | */ | ||
150 | struct ConnectPairInfo | ||
151 | { | ||
152 | /** | ||
153 | * Peer this is about. | ||
154 | */ | ||
155 | const struct GNUNET_PeerIdentity *sender; | ||
156 | |||
157 | /** | ||
158 | * Information about the receiving peer. | ||
159 | */ | ||
160 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi; | ||
161 | }; | ||
162 | |||
163 | |||
164 | /** | ||
148 | * Function called when we connected two peers. Once we have gotten | 165 | * Function called when we connected two peers. Once we have gotten |
149 | * to the clique, launch test-specific logic. | 166 | * to the clique, launch test-specific logic. |
150 | * | 167 | * |
@@ -207,61 +224,123 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck | |||
207 | * | 224 | * |
208 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | 225 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` |
209 | * @param peer peer we got connected to | 226 | * @param peer peer we got connected to |
227 | * @param mq message queue for transmissions to @a peer | ||
228 | * @return closure for message handlers | ||
210 | */ | 229 | */ |
211 | static void | 230 | static void * |
212 | my_nc (void *cls, | 231 | my_nc (void *cls, |
213 | const struct GNUNET_PeerIdentity *peer) | 232 | const struct GNUNET_PeerIdentity *peer, |
233 | struct GNUNET_MQ_Handle *mq) | ||
214 | { | 234 | { |
215 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 235 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
216 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 236 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
217 | 237 | struct ConnectPairInfo *cpi; | |
238 | |||
218 | if (NULL != ccc->nc) | 239 | if (NULL != ccc->nc) |
219 | ccc->nc (ccc->cls, | 240 | ccc->nc (ccc->cls, |
220 | ccc->p[ipi->off], | 241 | ccc->p[ipi->off], |
221 | peer); | 242 | peer); |
243 | cpi = GNUNET_new (struct ConnectPairInfo); | ||
244 | cpi->ipi = ipi; | ||
245 | cpi->sender = peer; /* valid until disconnect */ | ||
246 | return cpi; | ||
222 | } | 247 | } |
223 | 248 | ||
224 | 249 | ||
225 | |||
226 | /** | 250 | /** |
227 | * Wrapper around peers disconnecting. Calls client's nd function. | 251 | * Wrapper around peers disconnecting. Calls client's nd function. |
228 | * | 252 | * |
229 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | 253 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` |
230 | * @param peer peer we got disconnected from | 254 | * @param peer peer we got disconnected from |
255 | * @param custom_cls return value from @my_nc | ||
231 | */ | 256 | */ |
232 | static void | 257 | static void |
233 | my_nd (void *cls, | 258 | my_nd (void *cls, |
234 | const struct GNUNET_PeerIdentity *peer) | 259 | const struct GNUNET_PeerIdentity *peer, |
260 | void *custom_cls) | ||
235 | { | 261 | { |
236 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 262 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
237 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 263 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
238 | 264 | struct ConnectPairInfo *cpi = custom_cls; | |
265 | |||
239 | if (NULL != ccc->nd) | 266 | if (NULL != ccc->nd) |
240 | ccc->nd (ccc->cls, | 267 | ccc->nd (ccc->cls, |
241 | ccc->p[ipi->off], | 268 | ccc->p[ipi->off], |
242 | peer); | 269 | peer); |
270 | GNUNET_free (cpi); | ||
243 | } | 271 | } |
244 | 272 | ||
245 | 273 | ||
246 | /** | 274 | /** |
247 | * Wrapper around receiving data. Calls client's rec function. | 275 | * Wrapper around receiving data. Calls client's rec function. |
248 | * | 276 | * |
249 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | 277 | * @param cls our `struct ConnectPairInfo *` |
250 | * @param peer peer we got a message from | 278 | * @param message message we received |
279 | * @return #GNUNET_OK (all messages are fine) | ||
280 | */ | ||
281 | static int | ||
282 | check_test (void *cls, | ||
283 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
284 | { | ||
285 | return GNUNET_OK; | ||
286 | } | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Wrapper around receiving data. Calls client's rec function. | ||
291 | * | ||
292 | * @param cls our `struct ConnectPairInfo *` | ||
251 | * @param message message we received | 293 | * @param message message we received |
252 | */ | 294 | */ |
253 | static void | 295 | static void |
254 | my_rec (void *cls, | 296 | handle_test (void *cls, |
255 | const struct GNUNET_PeerIdentity *peer, | 297 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
256 | const struct GNUNET_MessageHeader *message) | ||
257 | { | 298 | { |
258 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 299 | struct ConnectPairInfo *cpi = cls; |
300 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; | ||
301 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | ||
302 | |||
303 | if (NULL != ccc->rec) | ||
304 | ccc->rec (ccc->cls, | ||
305 | ccc->p[ipi->off], | ||
306 | cpi->sender, | ||
307 | message); | ||
308 | } | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Wrapper around receiving data. Calls client's rec function. | ||
313 | * | ||
314 | * @param cls our `struct ConnectPairInfo *` | ||
315 | * @param message message we received | ||
316 | * @return #GNUNET_OK (all messages are fine) | ||
317 | */ | ||
318 | static int | ||
319 | check_test2 (void *cls, | ||
320 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
321 | { | ||
322 | return GNUNET_OK; | ||
323 | } | ||
324 | |||
325 | |||
326 | /** | ||
327 | * Wrapper around receiving data. Calls client's rec function. | ||
328 | * | ||
329 | * @param cls our `struct ConnectPairInfo *` | ||
330 | * @param message message we received | ||
331 | */ | ||
332 | static void | ||
333 | handle_test2 (void *cls, | ||
334 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
335 | { | ||
336 | struct ConnectPairInfo *cpi = cls; | ||
337 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; | ||
259 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 338 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
260 | 339 | ||
261 | if (NULL != ccc->rec) | 340 | if (NULL != ccc->rec) |
262 | ccc->rec (ccc->cls, | 341 | ccc->rec (ccc->cls, |
263 | ccc->p[ipi->off], | 342 | ccc->p[ipi->off], |
264 | peer, | 343 | cpi->sender, |
265 | message); | 344 | message); |
266 | } | 345 | } |
267 | 346 | ||
@@ -315,15 +394,14 @@ do_connect (void *cls) | |||
315 | * Once all peers have been launched, we connect all of them | 394 | * Once all peers have been launched, we connect all of them |
316 | * in a clique. | 395 | * in a clique. |
317 | * | 396 | * |
318 | * @param p peer that was launched (redundant, kill ASAP) | ||
319 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | 397 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` |
320 | */ | 398 | */ |
321 | static void | 399 | static void |
322 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 400 | start_cb (void *cls) |
323 | void *cls) | ||
324 | { | 401 | { |
325 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 402 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
326 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 403 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
404 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; | ||
327 | 405 | ||
328 | ccc->started++; | 406 | ccc->started++; |
329 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 407 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -364,6 +442,12 @@ connect_check_run (void *cls, | |||
364 | const char *cfgfile, | 442 | const char *cfgfile, |
365 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 443 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
366 | { | 444 | { |
445 | GNUNET_MQ_hd_var_size (test, | ||
446 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | ||
447 | struct GNUNET_TRANSPORT_TESTING_TestMessage); | ||
448 | GNUNET_MQ_hd_var_size (test2, | ||
449 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, | ||
450 | struct GNUNET_TRANSPORT_TESTING_TestMessage); | ||
367 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 451 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
368 | int ok; | 452 | int ok; |
369 | 453 | ||
@@ -376,10 +460,15 @@ connect_check_run (void *cls, | |||
376 | ok = GNUNET_OK; | 460 | ok = GNUNET_OK; |
377 | for (unsigned int i=0;i<ccc->num_peers;i++) | 461 | for (unsigned int i=0;i<ccc->num_peers;i++) |
378 | { | 462 | { |
463 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
464 | make_test_handler (NULL), | ||
465 | make_test2_handler (NULL), | ||
466 | GNUNET_MQ_handler_end() | ||
467 | }; | ||
379 | ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, | 468 | ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, |
380 | ccc->cfg_files[i], | 469 | ccc->cfg_files[i], |
381 | i + 1, | 470 | i + 1, |
382 | &my_rec, | 471 | handlers, |
383 | &my_nc, | 472 | &my_nc, |
384 | &my_nd, | 473 | &my_nd, |
385 | &ccc->ip[i], | 474 | &ccc->ip[i], |
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c index 92d5833b0..24858353e 100644 --- a/src/transport/transport-testing-send.c +++ b/src/transport/transport-testing-send.c | |||
@@ -30,63 +30,6 @@ | |||
30 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 30 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
31 | 31 | ||
32 | 32 | ||
33 | static size_t | ||
34 | notify_ready (void *cls, | ||
35 | size_t size, | ||
36 | void *buf) | ||
37 | { | ||
38 | struct TRANSPORT_TESTING_SendJob *sj = cls; | ||
39 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender = sj->sender; | ||
40 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver = sj->receiver; | ||
41 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; | ||
42 | uint16_t msize = sj->msize; | ||
43 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
44 | |||
45 | sj->th = NULL; | ||
46 | GNUNET_CONTAINER_DLL_remove (tth->sj_head, | ||
47 | tth->sj_tail, | ||
48 | sj); | ||
49 | if (NULL == buf) | ||
50 | { | ||
51 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
52 | "Timeout occurred while waiting for transmit_ready\n"); | ||
53 | GNUNET_SCHEDULER_shutdown (); | ||
54 | GNUNET_free (sj); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | GNUNET_assert (size >= msize); | ||
59 | if (NULL != buf) | ||
60 | { | ||
61 | memset (buf, sj->num, msize); | ||
62 | test = buf; | ||
63 | test->header.size = htons (msize); | ||
64 | test->header.type = htons (sj->mtype); | ||
65 | test->num = htonl (sj->num); | ||
66 | } | ||
67 | |||
68 | { | ||
69 | char *ps = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
70 | |||
71 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
72 | "Sending message %u from %u (%s) with type %u and size %u bytes to peer %u (%s)\n", | ||
73 | (unsigned int) sj->num, | ||
74 | sender->no, | ||
75 | ps, | ||
76 | sj->mtype, | ||
77 | msize, | ||
78 | receiver->no, | ||
79 | GNUNET_i2s (&receiver->id)); | ||
80 | GNUNET_free (ps); | ||
81 | } | ||
82 | if (NULL != sj->cont) | ||
83 | GNUNET_SCHEDULER_add_now (sj->cont, | ||
84 | sj->cont_cls); | ||
85 | GNUNET_free (sj); | ||
86 | return msize; | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | 33 | /** |
91 | * Return @a cx in @a cls. | 34 | * Return @a cx in @a cls. |
92 | */ | 35 | */ |
@@ -127,10 +70,10 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
127 | GNUNET_SCHEDULER_TaskCallback cont, | 70 | GNUNET_SCHEDULER_TaskCallback cont, |
128 | void *cont_cls) | 71 | void *cont_cls) |
129 | { | 72 | { |
130 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; | ||
131 | struct TRANSPORT_TESTING_SendJob *sj; | ||
132 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; | 73 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; |
133 | 74 | struct GNUNET_MQ_Envelope *env; | |
75 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
76 | |||
134 | if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)) | 77 | if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)) |
135 | { | 78 | { |
136 | GNUNET_break (0); | 79 | GNUNET_break (0); |
@@ -151,17 +94,11 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
151 | GNUNET_break (0); | 94 | GNUNET_break (0); |
152 | return GNUNET_NO; | 95 | return GNUNET_NO; |
153 | } | 96 | } |
154 | sj = GNUNET_new (struct TRANSPORT_TESTING_SendJob); | 97 | if (NULL == cr->mq) |
155 | sj->num = num; | 98 | { |
156 | sj->sender = sender; | 99 | GNUNET_break (0); |
157 | sj->receiver = receiver; | 100 | return GNUNET_NO; |
158 | sj->cont = cont; | 101 | } |
159 | sj->cont_cls = cont_cls; | ||
160 | sj->mtype = mtype; | ||
161 | sj->msize = msize; | ||
162 | GNUNET_CONTAINER_DLL_insert (tth->sj_head, | ||
163 | tth->sj_tail, | ||
164 | sj); | ||
165 | { | 102 | { |
166 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 103 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
167 | 104 | ||
@@ -173,13 +110,18 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
173 | receiver_s); | 110 | receiver_s); |
174 | GNUNET_free (receiver_s); | 111 | GNUNET_free (receiver_s); |
175 | } | 112 | } |
176 | sj->th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th, | 113 | env = GNUNET_MQ_msg_extra (test, |
177 | &receiver->id, | 114 | msize - sizeof (*test), |
178 | msize, | 115 | mtype); |
179 | TIMEOUT_TRANSMIT, | 116 | test->num = htonl (num); |
180 | ¬ify_ready, | 117 | memset (&test[1], |
181 | sj); | 118 | num, |
182 | GNUNET_assert (NULL != sj->th); | 119 | msize - sizeof (*test)); |
120 | GNUNET_MQ_notify_sent (env, | ||
121 | cont, | ||
122 | cont_cls); | ||
123 | GNUNET_MQ_send (cr->mq, | ||
124 | env); | ||
183 | return GNUNET_OK; | 125 | return GNUNET_OK; |
184 | } | 126 | } |
185 | 127 | ||
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 899ef7851..defafbbc6 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -86,6 +86,16 @@ set_p1c (void *cls, | |||
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | set_mq (void *cls, | ||
90 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | ||
91 | { | ||
92 | struct GNUNET_MQ_Handle *mq = cls; | ||
93 | |||
94 | cx->mq = mq; | ||
95 | } | ||
96 | |||
97 | |||
98 | static void | ||
89 | set_p2c (void *cls, | 99 | set_p2c (void *cls, |
90 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | 100 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) |
91 | { | 101 | { |
@@ -121,9 +131,10 @@ clear_p2c (void *cls, | |||
121 | } | 131 | } |
122 | 132 | ||
123 | 133 | ||
124 | static void | 134 | static void * |
125 | notify_connect (void *cls, | 135 | notify_connect (void *cls, |
126 | const struct GNUNET_PeerIdentity *peer) | 136 | const struct GNUNET_PeerIdentity *peer, |
137 | struct GNUNET_MQ_Handle *mq) | ||
127 | { | 138 | { |
128 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 139 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
129 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; | 140 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; |
@@ -132,12 +143,16 @@ notify_connect (void *cls, | |||
132 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 143 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; |
133 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; | 144 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; |
134 | int found; | 145 | int found; |
146 | void *ret; | ||
135 | 147 | ||
136 | p2 = find_peer_context (p->tth, | 148 | p2 = find_peer_context (p->tth, |
137 | peer); | 149 | peer); |
138 | if (NULL != p->nc) | 150 | if (NULL != p->nc) |
139 | p->nc (p->cb_cls, | 151 | ret = p->nc (p->cb_cls, |
140 | peer); | 152 | peer, |
153 | mq); | ||
154 | else | ||
155 | ret = NULL; | ||
141 | 156 | ||
142 | if (p2 != NULL) | 157 | if (p2 != NULL) |
143 | GNUNET_asprintf (&p2_s, | 158 | GNUNET_asprintf (&p2_s, |
@@ -185,6 +200,10 @@ notify_connect (void *cls, | |||
185 | tth->cc_tail, | 200 | tth->cc_tail, |
186 | cc); | 201 | cc); |
187 | } | 202 | } |
203 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, | ||
204 | p2, | ||
205 | &set_mq, | ||
206 | mq); | ||
188 | /* update set connected flag for all requests */ | 207 | /* update set connected flag for all requests */ |
189 | for (cc = tth->cc_head; NULL != cc; cc = cc->next) | 208 | for (cc = tth->cc_head; NULL != cc; cc = cc->next) |
190 | { | 209 | { |
@@ -223,6 +242,7 @@ notify_connect (void *cls, | |||
223 | cc->cb = NULL; /* only notify once! */ | 242 | cc->cb = NULL; /* only notify once! */ |
224 | } | 243 | } |
225 | } | 244 | } |
245 | return ret; | ||
226 | } | 246 | } |
227 | 247 | ||
228 | 248 | ||
@@ -237,7 +257,8 @@ offer_hello (void *cls); | |||
237 | 257 | ||
238 | static void | 258 | static void |
239 | notify_disconnect (void *cls, | 259 | notify_disconnect (void *cls, |
240 | const struct GNUNET_PeerIdentity *peer) | 260 | const struct GNUNET_PeerIdentity *peer, |
261 | void *handler_cls) | ||
241 | { | 262 | { |
242 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 263 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
243 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; | 264 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; |
@@ -245,8 +266,6 @@ notify_disconnect (void *cls, | |||
245 | /* Find PeerContext */ | 266 | /* Find PeerContext */ |
246 | int no = 0; | 267 | int no = 0; |
247 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; | 268 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; |
248 | struct TRANSPORT_TESTING_SendJob *sj; | ||
249 | struct TRANSPORT_TESTING_SendJob *sjn; | ||
250 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 269 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; |
251 | 270 | ||
252 | p2 = find_peer_context (p->tth, | 271 | p2 = find_peer_context (p->tth, |
@@ -270,25 +289,15 @@ notify_disconnect (void *cls, | |||
270 | /* notify about disconnect */ | 289 | /* notify about disconnect */ |
271 | if (NULL != p->nd) | 290 | if (NULL != p->nd) |
272 | p->nd (p->cb_cls, | 291 | p->nd (p->cb_cls, |
273 | peer); | 292 | peer, |
293 | handler_cls); | ||
274 | if (NULL == p2) | 294 | if (NULL == p2) |
275 | return; | 295 | return; |
276 | /* abort all transmissions this disconnected pair is involved in */ | 296 | /* clear MQ, it is now invalid */ |
277 | for (sj = tth->sj_head; NULL != sj; sj = sjn) | 297 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, |
278 | { | 298 | p2, |
279 | sjn = sj->next; | 299 | &set_mq, |
280 | if ( ( (sj->sender == p2) && | 300 | NULL); |
281 | (sj->receiver == p) ) || | ||
282 | ( (sj->receiver == p2) && | ||
283 | (sj->sender == p) ) ) | ||
284 | { | ||
285 | GNUNET_CONTAINER_DLL_remove (tth->sj_head, | ||
286 | tth->sj_tail, | ||
287 | sj); | ||
288 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (sj->th); | ||
289 | GNUNET_free (sj); | ||
290 | } | ||
291 | } | ||
292 | /* update set connected flags for all requests */ | 301 | /* update set connected flags for all requests */ |
293 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, | 302 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, |
294 | p2, | 303 | p2, |
@@ -322,22 +331,6 @@ notify_disconnect (void *cls, | |||
322 | 331 | ||
323 | 332 | ||
324 | static void | 333 | static void |
325 | notify_receive (void *cls, | ||
326 | const struct GNUNET_PeerIdentity *peer, | ||
327 | const struct GNUNET_MessageHeader *message) | ||
328 | { | ||
329 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
330 | |||
331 | if (NULL == p) | ||
332 | return; | ||
333 | if (NULL != p->rec) | ||
334 | p->rec (p->cb_cls, | ||
335 | peer, | ||
336 | message); | ||
337 | } | ||
338 | |||
339 | |||
340 | static void | ||
341 | get_hello (void *cb_cls, | 334 | get_hello (void *cb_cls, |
342 | const struct GNUNET_MessageHeader *message) | 335 | const struct GNUNET_MessageHeader *message) |
343 | { | 336 | { |
@@ -359,8 +352,7 @@ get_hello (void *cb_cls, | |||
359 | "Peer %u (`%s') successfully started\n", | 352 | "Peer %u (`%s') successfully started\n", |
360 | p->no, | 353 | p->no, |
361 | GNUNET_i2s (&p->id)); | 354 | GNUNET_i2s (&p->id)); |
362 | p->start_cb (p, | 355 | p->start_cb (p->start_cb_cls); |
363 | p->start_cb_cls); | ||
364 | p->start_cb = NULL; | 356 | p->start_cb = NULL; |
365 | } | 357 | } |
366 | } | 358 | } |
@@ -371,7 +363,7 @@ get_hello (void *cb_cls, | |||
371 | * @param tth the testing handle | 363 | * @param tth the testing handle |
372 | * @param cfgname configuration file | 364 | * @param cfgname configuration file |
373 | * @param peer_id a unique number to identify the peer | 365 | * @param peer_id a unique number to identify the peer |
374 | * @param rec receive callback | 366 | * @param handlers functions for receiving messages |
375 | * @param nc connect callback | 367 | * @param nc connect callback |
376 | * @param nd disconnect callback | 368 | * @param nd disconnect callback |
377 | * @param cb_cls closure for callback | 369 | * @param cb_cls closure for callback |
@@ -383,17 +375,18 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext * | |||
383 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, | 375 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, |
384 | const char *cfgname, | 376 | const char *cfgname, |
385 | int peer_id, | 377 | int peer_id, |
386 | GNUNET_TRANSPORT_ReceiveCallback rec, | 378 | const struct GNUNET_MQ_MessageHandler *handlers, |
387 | GNUNET_TRANSPORT_NotifyConnect nc, | 379 | GNUNET_TRANSPORT_NotifyConnecT nc, |
388 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 380 | GNUNET_TRANSPORT_NotifyDisconnecT nd, |
389 | void *cb_cls, | 381 | void *cb_cls, |
390 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, | 382 | GNUNET_SCHEDULER_TaskCallback start_cb, |
391 | void *start_cb_cls) | 383 | void *start_cb_cls) |
392 | { | 384 | { |
393 | char *emsg = NULL; | 385 | char *emsg = NULL; |
394 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 386 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
395 | struct GNUNET_PeerIdentity *dummy; | 387 | struct GNUNET_PeerIdentity *dummy; |
396 | 388 | unsigned int i; | |
389 | |||
397 | if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) | 390 | if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) |
398 | { | 391 | { |
399 | LOG (GNUNET_ERROR_TYPE_ERROR, | 392 | LOG (GNUNET_ERROR_TYPE_ERROR, |
@@ -406,7 +399,15 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
406 | p->tth = tth; | 399 | p->tth = tth; |
407 | p->nc = nc; | 400 | p->nc = nc; |
408 | p->nd = nd; | 401 | p->nd = nd; |
409 | p->rec = rec; | 402 | if (NULL != handlers) |
403 | { | ||
404 | for (i=0;NULL != handlers[i].cb;i++) ; | ||
405 | p->handlers = GNUNET_new_array (i + 1, | ||
406 | struct GNUNET_MQ_MessageHandler); | ||
407 | GNUNET_memcpy (p->handlers, | ||
408 | handlers, | ||
409 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | ||
410 | } | ||
410 | if (NULL != cb_cls) | 411 | if (NULL != cb_cls) |
411 | p->cb_cls = cb_cls; | 412 | p->cb_cls = cb_cls; |
412 | else | 413 | else |
@@ -479,14 +480,16 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
479 | "Peer %u configured with identity `%s'\n", | 480 | "Peer %u configured with identity `%s'\n", |
480 | p->no, | 481 | p->no, |
481 | GNUNET_i2s_full (&p->id)); | 482 | GNUNET_i2s_full (&p->id)); |
482 | 483 | p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg); | |
483 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | 484 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
484 | NULL, | 485 | NULL, |
485 | p, | 486 | handlers, |
486 | ¬ify_receive, | 487 | p, |
487 | ¬ify_connect, | 488 | ¬ify_connect, |
488 | ¬ify_disconnect); | 489 | ¬ify_disconnect, |
489 | if (NULL == p->th) | 490 | NULL); |
491 | if ( (NULL == p->th) || | ||
492 | (NULL == p->tmh) ) | ||
490 | { | 493 | { |
491 | LOG (GNUNET_ERROR_TYPE_ERROR, | 494 | LOG (GNUNET_ERROR_TYPE_ERROR, |
492 | "Failed to connect to transport service for peer `%s': `%s'\n", | 495 | "Failed to connect to transport service for peer `%s': `%s'\n", |
@@ -523,7 +526,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
523 | */ | 526 | */ |
524 | int | 527 | int |
525 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 528 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
526 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, | 529 | GNUNET_SCHEDULER_TaskCallback restart_cb, |
527 | void *restart_cb_cls) | 530 | void *restart_cb_cls) |
528 | { | 531 | { |
529 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 532 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; |
@@ -541,9 +544,14 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte | |||
541 | } | 544 | } |
542 | if (NULL != p->th) | 545 | if (NULL != p->th) |
543 | { | 546 | { |
544 | GNUNET_TRANSPORT_disconnect (p->th); | 547 | GNUNET_TRANSPORT_core_disconnect (p->th); |
545 | p->th = NULL; | 548 | p->th = NULL; |
546 | } | 549 | } |
550 | if (NULL != p->tmh) | ||
551 | { | ||
552 | GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); | ||
553 | p->tmh = NULL; | ||
554 | } | ||
547 | for (cc = p->tth->cc_head; NULL != cc; cc = ccn) | 555 | for (cc = p->tth->cc_head; NULL != cc; cc = ccn) |
548 | { | 556 | { |
549 | ccn = cc->next; | 557 | ccn = cc->next; |
@@ -586,12 +594,13 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte | |||
586 | p->start_cb = restart_cb; | 594 | p->start_cb = restart_cb; |
587 | p->start_cb_cls = restart_cb_cls; | 595 | p->start_cb_cls = restart_cb_cls; |
588 | 596 | ||
589 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | 597 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
590 | NULL, | 598 | NULL, |
591 | p, | 599 | p->handlers, |
592 | ¬ify_receive, | 600 | p, |
593 | ¬ify_connect, | 601 | ¬ify_connect, |
594 | ¬ify_disconnect); | 602 | ¬ify_disconnect, |
603 | NULL); | ||
595 | GNUNET_assert (NULL != p->th); | 604 | GNUNET_assert (NULL != p->th); |
596 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); | 605 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); |
597 | p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, | 606 | p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, |
@@ -626,9 +635,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
626 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | 635 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); |
627 | p->ghh = NULL; | 636 | p->ghh = NULL; |
628 | } | 637 | } |
638 | if (NULL != p->tmh) | ||
639 | { | ||
640 | GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); | ||
641 | p->tmh = NULL; | ||
642 | } | ||
629 | if (NULL != p->th) | 643 | if (NULL != p->th) |
630 | { | 644 | { |
631 | GNUNET_TRANSPORT_disconnect (p->th); | 645 | GNUNET_TRANSPORT_core_disconnect (p->th); |
632 | p->th = NULL; | 646 | p->th = NULL; |
633 | } | 647 | } |
634 | if (NULL != p->peer) | 648 | if (NULL != p->peer) |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index 806b8c5f9..87e647c2f 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -30,6 +30,8 @@ | |||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
33 | #include "gnunet_transport_core_service.h" | ||
34 | #include "gnunet_transport_manipulation_service.h" | ||
33 | #include "gnunet_testing_lib.h" | 35 | #include "gnunet_testing_lib.h" |
34 | 36 | ||
35 | 37 | ||
@@ -47,19 +49,6 @@ struct GNUNET_TRANSPORT_TESTING_Handle; | |||
47 | 49 | ||
48 | 50 | ||
49 | /** | 51 | /** |
50 | * Callback when two peers are connected and both have called the connect callback | ||
51 | * to notify clients about a new peer | ||
52 | * | ||
53 | * @param p FIXME: remove ASAP. | ||
54 | * @param cls closure | ||
55 | */ | ||
56 | typedef void | ||
57 | (*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | ||
58 | void *cls); | ||
59 | |||
60 | |||
61 | |||
62 | /** | ||
63 | * Context for a single peer | 52 | * Context for a single peer |
64 | */ | 53 | */ |
65 | struct GNUNET_TRANSPORT_TESTING_PeerContext | 54 | struct GNUNET_TRANSPORT_TESTING_PeerContext |
@@ -87,7 +76,12 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
87 | /** | 76 | /** |
88 | * Peer's transport service handle | 77 | * Peer's transport service handle |
89 | */ | 78 | */ |
90 | struct GNUNET_TRANSPORT_Handle *th; | 79 | struct GNUNET_TRANSPORT_CoreHandle *th; |
80 | |||
81 | /** | ||
82 | * Peer's transport service manipulation handle | ||
83 | */ | ||
84 | struct GNUNET_TRANSPORT_ManipulationHandle *tmh; | ||
91 | 85 | ||
92 | /** | 86 | /** |
93 | * Peer's ATS handle. | 87 | * Peer's ATS handle. |
@@ -117,22 +111,22 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
117 | /** | 111 | /** |
118 | * Receive callback | 112 | * Receive callback |
119 | */ | 113 | */ |
120 | GNUNET_TRANSPORT_ReceiveCallback rec; | 114 | struct GNUNET_MQ_MessageHandler *handlers; |
121 | 115 | ||
122 | /** | 116 | /** |
123 | * Notify connect callback | 117 | * Notify connect callback |
124 | */ | 118 | */ |
125 | GNUNET_TRANSPORT_NotifyConnect nc; | 119 | GNUNET_TRANSPORT_NotifyConnecT nc; |
126 | 120 | ||
127 | /** | 121 | /** |
128 | * Notify disconnect callback | 122 | * Notify disconnect callback |
129 | */ | 123 | */ |
130 | GNUNET_TRANSPORT_NotifyDisconnect nd; | 124 | GNUNET_TRANSPORT_NotifyDisconnecT nd; |
131 | 125 | ||
132 | /** | 126 | /** |
133 | * Startup completed callback | 127 | * Startup completed callback |
134 | */ | 128 | */ |
135 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb; | 129 | GNUNET_SCHEDULER_TaskCallback start_cb; |
136 | 130 | ||
137 | /** | 131 | /** |
138 | * Peers HELLO Message | 132 | * Peers HELLO Message |
@@ -207,6 +201,11 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest | |||
207 | */ | 201 | */ |
208 | void *cb_cls; | 202 | void *cb_cls; |
209 | 203 | ||
204 | /** | ||
205 | * Message queue for sending from @a p1 to @a p2. | ||
206 | */ | ||
207 | struct GNUNET_MQ_Handle *mq; | ||
208 | |||
210 | /** | 209 | /** |
211 | * Set if peer1 says the connection is up to peer2. | 210 | * Set if peer1 says the connection is up to peer2. |
212 | */ | 211 | */ |
@@ -225,65 +224,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest | |||
225 | 224 | ||
226 | 225 | ||
227 | /** | 226 | /** |
228 | * Information we keep for active transmission jobs. | ||
229 | */ | ||
230 | struct TRANSPORT_TESTING_SendJob | ||
231 | { | ||
232 | |||
233 | /** | ||
234 | * Kept in a DLL. | ||
235 | */ | ||
236 | struct TRANSPORT_TESTING_SendJob *next; | ||
237 | |||
238 | /** | ||
239 | * Kept in a DLL. | ||
240 | */ | ||
241 | struct TRANSPORT_TESTING_SendJob *prev; | ||
242 | |||
243 | /** | ||
244 | * Sender of the message. | ||
245 | */ | ||
246 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender; | ||
247 | |||
248 | /** | ||
249 | * Receiver of the message. | ||
250 | */ | ||
251 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver; | ||
252 | |||
253 | /** | ||
254 | * Operation handle. | ||
255 | */ | ||
256 | struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
257 | |||
258 | /** | ||
259 | * Function to call upon completion. | ||
260 | */ | ||
261 | GNUNET_SCHEDULER_TaskCallback cont; | ||
262 | |||
263 | /** | ||
264 | * Closure for @e cont. | ||
265 | */ | ||
266 | void *cont_cls; | ||
267 | |||
268 | /** | ||
269 | * Number of the message. | ||
270 | */ | ||
271 | uint32_t num; | ||
272 | |||
273 | /** | ||
274 | * Type of message to send. | ||
275 | */ | ||
276 | uint16_t mtype; | ||
277 | |||
278 | /** | ||
279 | * Length of the message. | ||
280 | */ | ||
281 | uint16_t msize; | ||
282 | |||
283 | }; | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Handle for a test run. | 227 | * Handle for a test run. |
288 | */ | 228 | */ |
289 | struct GNUNET_TRANSPORT_TESTING_Handle | 229 | struct GNUNET_TRANSPORT_TESTING_Handle |
@@ -304,16 +244,6 @@ struct GNUNET_TRANSPORT_TESTING_Handle | |||
304 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail; | 244 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail; |
305 | 245 | ||
306 | /** | 246 | /** |
307 | * Kept in a DLL. | ||
308 | */ | ||
309 | struct TRANSPORT_TESTING_SendJob *sj_head; | ||
310 | |||
311 | /** | ||
312 | * Kept in a DLL. | ||
313 | */ | ||
314 | struct TRANSPORT_TESTING_SendJob *sj_tail; | ||
315 | |||
316 | /** | ||
317 | * head DLL of peers | 247 | * head DLL of peers |
318 | */ | 248 | */ |
319 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head; | 249 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head; |
@@ -349,7 +279,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); | |||
349 | * @param tth the testing handle | 279 | * @param tth the testing handle |
350 | * @param cfgname configuration file | 280 | * @param cfgname configuration file |
351 | * @param peer_id the peer_id | 281 | * @param peer_id the peer_id |
352 | * @param rec receive callback | 282 | * @param handlers functions for receiving messages |
353 | * @param nc connect callback | 283 | * @param nc connect callback |
354 | * @param nd disconnect callback | 284 | * @param nd disconnect callback |
355 | * @param cb_cls closure for @a nc and @a nd callback | 285 | * @param cb_cls closure for @a nc and @a nd callback |
@@ -361,11 +291,11 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext * | |||
361 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, | 291 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, |
362 | const char *cfgname, | 292 | const char *cfgname, |
363 | int peer_id, | 293 | int peer_id, |
364 | GNUNET_TRANSPORT_ReceiveCallback rec, | 294 | const struct GNUNET_MQ_MessageHandler *handlers, |
365 | GNUNET_TRANSPORT_NotifyConnect nc, | 295 | GNUNET_TRANSPORT_NotifyConnecT nc, |
366 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 296 | GNUNET_TRANSPORT_NotifyDisconnecT nd, |
367 | void *cb_cls, | 297 | void *cb_cls, |
368 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, | 298 | GNUNET_SCHEDULER_TaskCallback start_cb, |
369 | void *start_cb_cls); | 299 | void *start_cb_cls); |
370 | 300 | ||
371 | 301 | ||
@@ -388,7 +318,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
388 | */ | 318 | */ |
389 | int | 319 | int |
390 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 320 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
391 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, | 321 | GNUNET_SCHEDULER_TaskCallback restart_cb, |
392 | void *restart_cb_cls); | 322 | void *restart_cb_cls); |
393 | 323 | ||
394 | 324 | ||
@@ -476,6 +406,23 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList; | |||
476 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; | 406 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; |
477 | 407 | ||
478 | 408 | ||
409 | GNUNET_NETWORK_STRUCT_BEGIN | ||
410 | struct GNUNET_TRANSPORT_TESTING_TestMessage | ||
411 | { | ||
412 | /** | ||
413 | * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. | ||
414 | */ | ||
415 | struct GNUNET_MessageHeader header; | ||
416 | |||
417 | /** | ||
418 | * Monotonically increasing counter throughout the test. | ||
419 | */ | ||
420 | uint32_t num GNUNET_PACKED; | ||
421 | }; | ||
422 | GNUNET_NETWORK_STRUCT_END | ||
423 | |||
424 | |||
425 | |||
479 | /** | 426 | /** |
480 | * Function called by the transport for each received message. | 427 | * Function called by the transport for each received message. |
481 | * | 428 | * |
@@ -488,7 +435,7 @@ typedef void | |||
488 | (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, | 435 | (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, |
489 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 436 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
490 | const struct GNUNET_PeerIdentity *sender, | 437 | const struct GNUNET_PeerIdentity *sender, |
491 | const struct GNUNET_MessageHeader *message); | 438 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); |
492 | 439 | ||
493 | 440 | ||
494 | /** | 441 | /** |
@@ -800,20 +747,10 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
800 | */ | 747 | */ |
801 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 | 748 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 |
802 | 749 | ||
803 | GNUNET_NETWORK_STRUCT_BEGIN | 750 | /** |
804 | struct GNUNET_TRANSPORT_TESTING_TestMessage | 751 | * Alternative message type for tests. |
805 | { | 752 | */ |
806 | /** | 753 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 |
807 | * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. | ||
808 | */ | ||
809 | struct GNUNET_MessageHeader header; | ||
810 | |||
811 | /** | ||
812 | * Monotonically increasing counter throughout the test. | ||
813 | */ | ||
814 | uint32_t num GNUNET_PACKED; | ||
815 | }; | ||
816 | GNUNET_NETWORK_STRUCT_END | ||
817 | 754 | ||
818 | 755 | ||
819 | /** | 756 | /** |
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c index 499aa96f6..4ca62d797 100644 --- a/src/transport/transport_api_core.c +++ b/src/transport/transport_api_core.c | |||
@@ -266,12 +266,12 @@ neighbour_delete (void *cls, | |||
266 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 266 | GNUNET_SCHEDULER_cancel (n->timeout_task); |
267 | n->timeout_task = NULL; | 267 | n->timeout_task = NULL; |
268 | } | 268 | } |
269 | GNUNET_MQ_destroy (n->mq); | ||
270 | if (NULL != n->env) | 269 | if (NULL != n->env) |
271 | { | 270 | { |
272 | GNUNET_MQ_send_cancel (n->env); | 271 | GNUNET_MQ_send_cancel (n->env); |
273 | n->env = NULL; | 272 | n->env = NULL; |
274 | } | 273 | } |
274 | GNUNET_MQ_destroy (n->mq); | ||
275 | GNUNET_assert (NULL == n->mq); | 275 | GNUNET_assert (NULL == n->mq); |
276 | GNUNET_assert (GNUNET_YES == | 276 | GNUNET_assert (GNUNET_YES == |
277 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, | 277 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, |
@@ -411,7 +411,7 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
411 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | 411 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, |
412 | msg); | 412 | msg); |
413 | obm->reserved = htonl (0); | 413 | obm->reserved = htonl (0); |
414 | obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME: to be removed */ | 414 | obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ |
415 | obm->peer = n->id; | 415 | obm->peer = n->id; |
416 | GNUNET_assert (NULL == n->timeout_task); | 416 | GNUNET_assert (NULL == n->timeout_task); |
417 | n->is_ready = GNUNET_NO; | 417 | n->is_ready = GNUNET_NO; |
@@ -421,6 +421,9 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
421 | n); | 421 | n); |
422 | GNUNET_MQ_send (h->mq, | 422 | GNUNET_MQ_send (h->mq, |
423 | n->env); | 423 | n->env); |
424 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
425 | "Queued message for neighbour `%s'.\n", | ||
426 | GNUNET_i2s (&n->id)); | ||
424 | } | 427 | } |
425 | 428 | ||
426 | 429 | ||
@@ -655,15 +658,14 @@ check_recv (void *cls, | |||
655 | const struct GNUNET_MessageHeader *imm; | 658 | const struct GNUNET_MessageHeader *imm; |
656 | uint16_t size; | 659 | uint16_t size; |
657 | 660 | ||
658 | size = ntohs (im->header.size); | 661 | size = ntohs (im->header.size) - sizeof (*im); |
659 | if (size < | 662 | if (size < sizeof (struct GNUNET_MessageHeader)) |
660 | sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
661 | { | 663 | { |
662 | GNUNET_break (0); | 664 | GNUNET_break (0); |
663 | return GNUNET_SYSERR; | 665 | return GNUNET_SYSERR; |
664 | } | 666 | } |
665 | imm = (const struct GNUNET_MessageHeader *) &im[1]; | 667 | imm = (const struct GNUNET_MessageHeader *) &im[1]; |
666 | if (ntohs (imm->size) + sizeof (struct InboundMessage) != size) | 668 | if (ntohs (imm->size) != size) |
667 | { | 669 | { |
668 | GNUNET_break (0); | 670 | GNUNET_break (0); |
669 | return GNUNET_SYSERR; | 671 | return GNUNET_SYSERR; |
@@ -808,15 +810,15 @@ static void | |||
808 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 810 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
809 | { | 811 | { |
810 | GNUNET_assert (NULL == h->reconnect_task); | 812 | GNUNET_assert (NULL == h->reconnect_task); |
813 | /* Forget about all neighbours that we used to be connected to */ | ||
814 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | ||
815 | &neighbour_delete, | ||
816 | h); | ||
811 | if (NULL != h->mq) | 817 | if (NULL != h->mq) |
812 | { | 818 | { |
813 | GNUNET_MQ_destroy (h->mq); | 819 | GNUNET_MQ_destroy (h->mq); |
814 | h->mq = NULL; | 820 | h->mq = NULL; |
815 | } | 821 | } |
816 | /* Forget about all neighbours that we used to be connected to */ | ||
817 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | ||
818 | &neighbour_delete, | ||
819 | h); | ||
820 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 822 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
821 | "Scheduling task to reconnect to transport service in %s.\n", | 823 | "Scheduling task to reconnect to transport service in %s.\n", |
822 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, | 824 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, |
@@ -865,13 +867,13 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
865 | * @return NULL on error | 867 | * @return NULL on error |
866 | */ | 868 | */ |
867 | struct GNUNET_TRANSPORT_CoreHandle * | 869 | struct GNUNET_TRANSPORT_CoreHandle * |
868 | GNUNET_TRANSPORT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg, | 870 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
869 | const struct GNUNET_PeerIdentity *self, | 871 | const struct GNUNET_PeerIdentity *self, |
870 | const struct GNUNET_MQ_MessageHandler *handlers, | 872 | const struct GNUNET_MQ_MessageHandler *handlers, |
871 | void *cls, | 873 | void *cls, |
872 | GNUNET_TRANSPORT_NotifyConnecT nc, | 874 | GNUNET_TRANSPORT_NotifyConnecT nc, |
873 | GNUNET_TRANSPORT_NotifyDisconnecT nd, | 875 | GNUNET_TRANSPORT_NotifyDisconnecT nd, |
874 | GNUNET_TRANSPORT_NotifyExcessBandwidtH neb) | 876 | GNUNET_TRANSPORT_NotifyExcessBandwidtH neb) |
875 | { | 877 | { |
876 | struct GNUNET_TRANSPORT_CoreHandle *h; | 878 | struct GNUNET_TRANSPORT_CoreHandle *h; |
877 | unsigned int i; | 879 | unsigned int i; |
@@ -888,22 +890,23 @@ GNUNET_TRANSPORT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
888 | h->nd_cb = nd; | 890 | h->nd_cb = nd; |
889 | h->neb_cb = neb; | 891 | h->neb_cb = neb; |
890 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 892 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
891 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
892 | "Connecting to transport service.\n"); | ||
893 | reconnect (h); | ||
894 | if (NULL == h->mq) | ||
895 | { | ||
896 | GNUNET_free (h); | ||
897 | return NULL; | ||
898 | } | ||
899 | if (NULL != handlers) | 893 | if (NULL != handlers) |
900 | { | 894 | { |
901 | for (i=0;NULL != handlers[i].cb; i++) ; | 895 | for (i=0;NULL != handlers[i].cb; i++) ; |
902 | h->handlers = GNUNET_new_array (i + 1, | 896 | h->handlers = GNUNET_new_array (i + 1, |
903 | struct GNUNET_MQ_MessageHandler); | 897 | struct GNUNET_MQ_MessageHandler); |
904 | GNUNET_memcpy (h->handlers, | 898 | GNUNET_memcpy (h->handlers, |
905 | handlers, | 899 | handlers, |
906 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | 900 | i * sizeof (struct GNUNET_MQ_MessageHandler)); |
901 | } | ||
902 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
903 | "Connecting to transport service\n"); | ||
904 | reconnect (h); | ||
905 | if (NULL == h->mq) | ||
906 | { | ||
907 | GNUNET_free_non_null (h->handlers); | ||
908 | GNUNET_free (h); | ||
909 | return NULL; | ||
907 | } | 910 | } |
908 | h->neighbours = | 911 | h->neighbours = |
909 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, | 912 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, |
diff --git a/src/transport/transport_api_get_hello.c b/src/transport/transport_api_get_hello.c index 5a9efcd14..28f6c9d7b 100644 --- a/src/transport/transport_api_get_hello.c +++ b/src/transport/transport_api_get_hello.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/transport_api.c | 22 | * @file transport/transport_api_get_hello.c |
23 | * @brief library to obtain our HELLO from our transport service | 23 | * @brief library to obtain our HELLO from our transport service |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
diff --git a/src/transport/transport_api_manipulation.c b/src/transport/transport_api_manipulation.c new file mode 100644 index 000000000..6325354cb --- /dev/null +++ b/src/transport/transport_api_manipulation.c | |||
@@ -0,0 +1,244 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2013, 2016 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_manipulation.c | ||
23 | * @brief library to access the low-level P2P IO service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_constants.h" | ||
29 | #include "gnunet_arm_service.h" | ||
30 | #include "gnunet_hello_lib.h" | ||
31 | #include "gnunet_protocols.h" | ||
32 | #include "gnunet_transport_service.h" | ||
33 | #include "transport.h" | ||
34 | |||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-api",__VA_ARGS__) | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Handle for the transport service (includes all of the | ||
40 | * state for the transport service). | ||
41 | */ | ||
42 | struct GNUNET_TRANSPORT_ManipulationHandle | ||
43 | { | ||
44 | |||
45 | /** | ||
46 | * My client connection to the transport service. | ||
47 | */ | ||
48 | struct GNUNET_MQ_Handle *mq; | ||
49 | |||
50 | /** | ||
51 | * My configuration. | ||
52 | */ | ||
53 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
54 | |||
55 | /** | ||
56 | * ID of the task trying to reconnect to the service. | ||
57 | */ | ||
58 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
59 | |||
60 | /** | ||
61 | * Delay until we try to reconnect. | ||
62 | */ | ||
63 | struct GNUNET_TIME_Relative reconnect_delay; | ||
64 | |||
65 | /** | ||
66 | * Reconnect in progress | ||
67 | */ | ||
68 | int reconnecting; | ||
69 | }; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Function that will schedule the job that will try | ||
74 | * to connect us again to the client. | ||
75 | * | ||
76 | * @param h transport service to reconnect | ||
77 | */ | ||
78 | static void | ||
79 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h); | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Generic error handler, called with the appropriate | ||
84 | * error code and the same closure specified at the creation of | ||
85 | * the message queue. | ||
86 | * Not every message queue implementation supports an error handler. | ||
87 | * | ||
88 | * @param cls closure with the `struct GNUNET_TRANSPORT_ManipulationHandle *` | ||
89 | * @param error error code | ||
90 | */ | ||
91 | static void | ||
92 | mq_error_handler (void *cls, | ||
93 | enum GNUNET_MQ_Error error) | ||
94 | { | ||
95 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; | ||
96 | |||
97 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
98 | "Error receiving from transport service, disconnecting temporarily.\n"); | ||
99 | h->reconnecting = GNUNET_YES; | ||
100 | disconnect_and_schedule_reconnect (h); | ||
101 | } | ||
102 | |||
103 | |||
104 | /** | ||
105 | * Try again to connect to transport service. | ||
106 | * | ||
107 | * @param cls the handle to the transport service | ||
108 | */ | ||
109 | static void | ||
110 | reconnect (void *cls) | ||
111 | { | ||
112 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; | ||
113 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
114 | GNUNET_MQ_handler_end () | ||
115 | }; | ||
116 | struct GNUNET_MQ_Envelope *env; | ||
117 | struct StartMessage *s; | ||
118 | |||
119 | h->reconnect_task = NULL; | ||
120 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
121 | "Connecting to transport service.\n"); | ||
122 | GNUNET_assert (NULL == h->mq); | ||
123 | h->reconnecting = GNUNET_NO; | ||
124 | h->mq = GNUNET_CLIENT_connecT (h->cfg, | ||
125 | "transport", | ||
126 | handlers, | ||
127 | &mq_error_handler, | ||
128 | h); | ||
129 | if (NULL == h->mq) | ||
130 | return; | ||
131 | env = GNUNET_MQ_msg (s, | ||
132 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); | ||
133 | GNUNET_MQ_send (h->mq, | ||
134 | env); | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Function that will schedule the job that will try | ||
140 | * to connect us again to the client. | ||
141 | * | ||
142 | * @param h transport service to reconnect | ||
143 | */ | ||
144 | static void | ||
145 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h) | ||
146 | { | ||
147 | GNUNET_assert (NULL == h->reconnect_task); | ||
148 | if (NULL != h->mq) | ||
149 | { | ||
150 | GNUNET_MQ_destroy (h->mq); | ||
151 | h->mq = NULL; | ||
152 | } | ||
153 | h->reconnect_task = | ||
154 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | ||
155 | &reconnect, | ||
156 | h); | ||
157 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | ||
158 | } | ||
159 | |||
160 | |||
161 | /** | ||
162 | * Set transport metrics for a peer and a direction. | ||
163 | * | ||
164 | * @param handle transport handle | ||
165 | * @param peer the peer to set the metric for | ||
166 | * @param prop the performance metrics to set | ||
167 | * @param delay_in inbound delay to introduce | ||
168 | * @param delay_out outbound delay to introduce | ||
169 | * | ||
170 | * Note: Delay restrictions in receiving direction will be enforced | ||
171 | * with one message delay. | ||
172 | */ | ||
173 | void | ||
174 | GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *handle, | ||
175 | const struct GNUNET_PeerIdentity *peer, | ||
176 | const struct GNUNET_ATS_Properties *prop, | ||
177 | struct GNUNET_TIME_Relative delay_in, | ||
178 | struct GNUNET_TIME_Relative delay_out) | ||
179 | { | ||
180 | struct GNUNET_MQ_Envelope *env; | ||
181 | struct TrafficMetricMessage *msg; | ||
182 | |||
183 | if (NULL == handle->mq) | ||
184 | return; | ||
185 | env = GNUNET_MQ_msg (msg, | ||
186 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); | ||
187 | msg->reserved = htonl (0); | ||
188 | msg->peer = *peer; | ||
189 | GNUNET_ATS_properties_hton (&msg->properties, | ||
190 | prop); | ||
191 | msg->delay_in = GNUNET_TIME_relative_hton (delay_in); | ||
192 | msg->delay_out = GNUNET_TIME_relative_hton (delay_out); | ||
193 | GNUNET_MQ_send (handle->mq, | ||
194 | env); | ||
195 | } | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Connect to the transport service. Note that the connection may | ||
200 | * complete (or fail) asynchronously. | ||
201 | * | ||
202 | * @param cfg configuration to use | ||
203 | * @return NULL on error | ||
204 | */ | ||
205 | struct GNUNET_TRANSPORT_ManipulationHandle * | ||
206 | GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
207 | { | ||
208 | struct GNUNET_TRANSPORT_ManipulationHandle *h; | ||
209 | |||
210 | h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle); | ||
211 | h->cfg = cfg; | ||
212 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
213 | "Connecting to transport service.\n"); | ||
214 | reconnect (h); | ||
215 | if (NULL == h->mq) | ||
216 | { | ||
217 | GNUNET_free (h); | ||
218 | return NULL; | ||
219 | } | ||
220 | return h; | ||
221 | } | ||
222 | |||
223 | |||
224 | /** | ||
225 | * Disconnect from the transport service. | ||
226 | * | ||
227 | * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() | ||
228 | */ | ||
229 | void | ||
230 | GNUNET_TRANSPORT_manipulation_disconnect (struct GNUNET_TRANSPORT_ManipulationHandle *handle) | ||
231 | { | ||
232 | if (NULL == handle->reconnect_task) | ||
233 | disconnect_and_schedule_reconnect (handle); | ||
234 | /* and now we stop trying to connect again... */ | ||
235 | if (NULL != handle->reconnect_task) | ||
236 | { | ||
237 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | ||
238 | handle->reconnect_task = NULL; | ||
239 | } | ||
240 | GNUNET_free (handle); | ||
241 | } | ||
242 | |||
243 | |||
244 | /* end of transport_api_manipulation.c */ | ||
diff --git a/src/util/mq.c b/src/util/mq.c index 8a46414d2..1638d7e0c 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -807,9 +807,18 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, | |||
807 | { | 807 | { |
808 | struct ClientConnectionState *state = impl_state; | 808 | struct ClientConnectionState *state = impl_state; |
809 | 809 | ||
810 | GNUNET_assert (NULL != state->th); | 810 | if (NULL != state->th) |
811 | GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); | 811 | { |
812 | state->th = NULL; | 812 | GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); |
813 | state->th = NULL; | ||
814 | } | ||
815 | else if (NULL != mq->continue_task) | ||
816 | { | ||
817 | GNUNET_SCHEDULER_cancel (mq->continue_task); | ||
818 | mq->continue_task = NULL; | ||
819 | } | ||
820 | else | ||
821 | GNUNET_assert (0); | ||
813 | } | 822 | } |
814 | 823 | ||
815 | 824 | ||