diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-22 21:35:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-22 21:35:51 +0000 |
commit | 8d0883a3f695261cfd8651ed53734f2f4fb30417 (patch) | |
tree | 389c86b7c6ec9777498ae54e4650c9dbc69b94fc /src/transport/test_transport_api_manipulation_recv_tcp.c | |
parent | b77b2502d587f576baff39120e6f37235c5b5b90 (diff) | |
download | gnunet-8d0883a3f695261cfd8651ed53734f2f4fb30417.tar.gz gnunet-8d0883a3f695261cfd8651ed53734f2f4fb30417.zip |
migrate more tests to new transmission API
Diffstat (limited to 'src/transport/test_transport_api_manipulation_recv_tcp.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_recv_tcp.c | 216 |
1 files changed, 61 insertions, 155 deletions
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c index 023d5a714..e902aed62 100644 --- a/src/transport/test_transport_api_manipulation_recv_tcp.c +++ b/src/transport/test_transport_api_manipulation_recv_tcp.c | |||
@@ -36,22 +36,9 @@ | |||
36 | */ | 36 | */ |
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
38 | 38 | ||
39 | /** | ||
40 | * How long until we give up on transmitting the message? | ||
41 | */ | ||
42 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
43 | |||
44 | #define TEST_MESSAGE_SIZE 2600 | ||
45 | |||
46 | #define TEST_MESSAGE_TYPE 12345 | ||
47 | |||
48 | 39 | ||
49 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 40 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
50 | 41 | ||
51 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
52 | |||
53 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
54 | |||
55 | static int messages_recv; | 42 | static int messages_recv; |
56 | 43 | ||
57 | static struct GNUNET_TIME_Absolute start_normal; | 44 | static struct GNUNET_TIME_Absolute start_normal; |
@@ -64,26 +51,46 @@ static struct GNUNET_TIME_Relative dur_delayed; | |||
64 | 51 | ||
65 | 52 | ||
66 | static void | 53 | static void |
67 | custom_shutdown (void *cls) | 54 | do_free (void *cls) |
68 | { | 55 | { |
69 | if (NULL != th) | 56 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; |
57 | |||
58 | GNUNET_free (sc); | ||
59 | } | ||
60 | |||
61 | |||
62 | static void | ||
63 | sendtask (void *cls) | ||
64 | { | ||
65 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; | ||
66 | struct GNUNET_ATS_Properties prop; | ||
67 | struct GNUNET_TIME_Relative delay; | ||
68 | |||
69 | sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure); | ||
70 | sc->num_messages = 1; | ||
71 | sc->ccc = ccc; | ||
72 | sc->cont = &do_free; | ||
73 | sc->cont_cls = sc; | ||
74 | if (0 == messages_recv) | ||
70 | { | 75 | { |
71 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 76 | start_normal = GNUNET_TIME_absolute_get(); |
72 | th = NULL; | ||
73 | } | 77 | } |
74 | if (NULL != send_task) | 78 | if (0 < messages_recv) |
75 | { | 79 | { |
76 | GNUNET_SCHEDULER_cancel (send_task); | 80 | memset (&prop, 0, sizeof (prop)); |
77 | send_task = NULL; | 81 | delay = GNUNET_TIME_UNIT_SECONDS; |
82 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th, | ||
83 | &ccc->p[0]->id, | ||
84 | &prop, | ||
85 | delay, | ||
86 | GNUNET_TIME_UNIT_ZERO); | ||
87 | start_delayed = GNUNET_TIME_absolute_get(); | ||
78 | } | 88 | } |
89 | GNUNET_TRANSPORT_TESTING_large_send (sc); | ||
79 | } | 90 | } |
80 | 91 | ||
81 | 92 | ||
82 | static void | 93 | static void |
83 | sendtask (void *cls); | ||
84 | |||
85 | |||
86 | static void | ||
87 | notify_receive (void *cls, | 94 | notify_receive (void *cls, |
88 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 95 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
89 | const struct GNUNET_PeerIdentity *sender, | 96 | const struct GNUNET_PeerIdentity *sender, |
@@ -101,13 +108,8 @@ notify_receive (void *cls, | |||
101 | GNUNET_i2s (sender)); | 108 | GNUNET_i2s (sender)); |
102 | GNUNET_free (ps); | 109 | GNUNET_free (ps); |
103 | } | 110 | } |
104 | if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && | 111 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) || |
105 | (TEST_MESSAGE_SIZE == ntohs (message->size))) | 112 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->size)) ) |
106 | { | ||
107 | if (GNUNET_NO == ccc->global_ret) | ||
108 | ccc->global_ret = GNUNET_OK; | ||
109 | } | ||
110 | else | ||
111 | { | 113 | { |
112 | GNUNET_break (0); | 114 | GNUNET_break (0); |
113 | ccc->global_ret = GNUNET_SYSERR; | 115 | ccc->global_ret = GNUNET_SYSERR; |
@@ -118,150 +120,54 @@ notify_receive (void *cls, | |||
118 | if (messages_recv <= 1) | 120 | if (messages_recv <= 1) |
119 | { | 121 | { |
120 | /* Received non-delayed message */ | 122 | /* Received non-delayed message */ |
121 | dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); | 123 | dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); |
122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
123 | "Received non-delayed message %u after %s\n", | 125 | "Received non-delayed message %u after %s\n", |
124 | messages_recv, | 126 | messages_recv, |
125 | GNUNET_STRINGS_relative_time_to_string (dur_normal, | 127 | GNUNET_STRINGS_relative_time_to_string (dur_normal, |
126 | GNUNET_YES)); | 128 | GNUNET_YES)); |
127 | 129 | GNUNET_SCHEDULER_add_now (&sendtask, | |
128 | struct GNUNET_ATS_Properties prop; | 130 | NULL); |
129 | struct GNUNET_TIME_Relative delay; | 131 | messages_recv++; |
130 | 132 | return; | |
131 | delay.rel_value_us = 1000 * 1000LL; | ||
132 | memset (&prop, 0, sizeof (prop)); | ||
133 | prop.distance = 10; | ||
134 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th, | ||
135 | &ccc->p[1]->id, | ||
136 | &prop, | ||
137 | delay, | ||
138 | GNUNET_TIME_UNIT_ZERO); | ||
139 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
140 | } | ||
141 | if (2 == messages_recv) | ||
142 | { | ||
143 | /* Received manipulated message */ | ||
144 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
146 | "Received delayed message %u after %s\n", | ||
147 | messages_recv, | ||
148 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, | ||
149 | GNUNET_YES)); | ||
150 | if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) | ||
151 | { | ||
152 | GNUNET_break (0); | ||
153 | ccc->global_ret = GNUNET_SYSERR; | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
155 | "Delayed message was not delayed correctly: took only %s\n", | ||
156 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, | ||
157 | GNUNET_YES)); | ||
158 | } | ||
159 | /* shutdown */ | ||
160 | GNUNET_SCHEDULER_shutdown (); | ||
161 | } | 133 | } |
162 | messages_recv++; | 134 | /* Received manipulated message */ |
163 | } | 135 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); |
164 | 136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
165 | 137 | "Received delayed message %u after %s\n", | |
166 | static size_t | 138 | messages_recv, |
167 | notify_ready (void *cls, size_t size, void *buf) | 139 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, |
168 | { | 140 | GNUNET_YES)); |
169 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 141 | if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) |
170 | struct GNUNET_MessageHeader *hdr; | ||
171 | |||
172 | th = NULL; | ||
173 | if (NULL == buf) | ||
174 | { | 142 | { |
143 | GNUNET_break (0); | ||
144 | ccc->global_ret = GNUNET_SYSERR; | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
176 | "Timeout occurred while waiting for transmit_ready\n"); | 146 | "Delayed message was not delayed correctly: took only %s\n", |
177 | GNUNET_SCHEDULER_shutdown (); | 147 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, |
178 | ccc->global_ret = 42; | 148 | GNUNET_YES)); |
179 | return 0; | ||
180 | } | ||
181 | |||
182 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
183 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
184 | hdr = buf; | ||
185 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
186 | hdr->type = htons (TEST_MESSAGE_TYPE); | ||
187 | |||
188 | { | ||
189 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
190 | |||
191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
192 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", | ||
193 | ccc->p[1]->no, | ||
194 | ps, | ||
195 | ntohs (hdr->type), | ||
196 | ntohs (hdr->size), | ||
197 | p->no, | ||
198 | GNUNET_i2s (&p->id)); | ||
199 | GNUNET_free (ps); | ||
200 | } | ||
201 | |||
202 | return TEST_MESSAGE_SIZE; | ||
203 | } | ||
204 | |||
205 | |||
206 | static void | ||
207 | sendtask (void *cls) | ||
208 | { | ||
209 | if (NULL == send_task) | ||
210 | ccc->global_ret = GNUNET_NO; /* first call! */ | ||
211 | send_task = NULL; | ||
212 | { | ||
213 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
214 | |||
215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
216 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
217 | ccc->p[1]->no, GNUNET_i2s (&ccc->p[1]->id), ccc->p[0]->no, receiver_s); | ||
218 | GNUNET_free (receiver_s); | ||
219 | } | ||
220 | if (0 == messages_recv) | ||
221 | { | ||
222 | start_normal = GNUNET_TIME_absolute_get(); | ||
223 | } | ||
224 | if (1 == messages_recv) | ||
225 | { | ||
226 | start_delayed = GNUNET_TIME_absolute_get(); | ||
227 | } | 149 | } |
228 | 150 | else | |
229 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | 151 | { |
230 | &ccc->p[0]->id, | 152 | ccc->global_ret = GNUNET_OK; |
231 | TEST_MESSAGE_SIZE, | ||
232 | TIMEOUT_TRANSMIT, | ||
233 | ¬ify_ready, | ||
234 | ccc->p[0]); | ||
235 | } | ||
236 | |||
237 | |||
238 | static void | ||
239 | notify_disconnect (void *cls, | ||
240 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
241 | const struct GNUNET_PeerIdentity *other) | ||
242 | { | ||
243 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
244 | me, | ||
245 | other); | ||
246 | if (NULL != th) | ||
247 | { | ||
248 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
249 | th = NULL; | ||
250 | } | 153 | } |
154 | /* shutdown */ | ||
155 | GNUNET_SCHEDULER_shutdown (); | ||
251 | } | 156 | } |
252 | 157 | ||
253 | 158 | ||
254 | int | 159 | int |
255 | main (int argc, char *argv[]) | 160 | main (int argc, |
161 | char *argv[]) | ||
256 | { | 162 | { |
257 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 163 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
258 | .connect_continuation = &sendtask, | 164 | .connect_continuation = &sendtask, |
259 | .config_file = "test_transport_api_data.conf", | 165 | .config_file = "test_transport_api_data.conf", |
260 | .rec = ¬ify_receive, | 166 | .rec = ¬ify_receive, |
261 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 167 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
262 | .nd = ¬ify_disconnect, | 168 | .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect, |
263 | .shutdown_task = &custom_shutdown, | 169 | .timeout = TIMEOUT, |
264 | .timeout = TIMEOUT | 170 | .global_ret = GNUNET_NO |
265 | }; | 171 | }; |
266 | 172 | ||
267 | ccc = &my_ccc; | 173 | ccc = &my_ccc; |