diff options
Diffstat (limited to 'src/transport/test_transport_api_manipulation_send_tcp.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_send_tcp.c | 180 |
1 files changed, 43 insertions, 137 deletions
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c index 902cac6c2..7e73f0b9c 100644 --- a/src/transport/test_transport_api_manipulation_send_tcp.c +++ b/src/transport/test_transport_api_manipulation_send_tcp.c | |||
@@ -36,22 +36,11 @@ | |||
36 | */ | 36 | */ |
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
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, 10) | ||
43 | |||
44 | #define TEST_MESSAGE_SIZE 2600 | 39 | #define TEST_MESSAGE_SIZE 2600 |
45 | 40 | ||
46 | #define TEST_MESSAGE_TYPE 12345 | ||
47 | |||
48 | 41 | ||
49 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 42 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
50 | 43 | ||
51 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
52 | |||
53 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
54 | |||
55 | static int messages_recv; | 44 | static int messages_recv; |
56 | 45 | ||
57 | static struct GNUNET_TIME_Absolute start_normal; | 46 | static struct GNUNET_TIME_Absolute start_normal; |
@@ -63,27 +52,50 @@ static struct GNUNET_TIME_Absolute start_delayed; | |||
63 | static struct GNUNET_TIME_Relative dur_delayed; | 52 | static struct GNUNET_TIME_Relative dur_delayed; |
64 | 53 | ||
65 | 54 | ||
55 | static size_t | ||
56 | get_size (unsigned int cnt_down) | ||
57 | { | ||
58 | return TEST_MESSAGE_SIZE; | ||
59 | } | ||
60 | |||
61 | |||
66 | static void | 62 | static void |
67 | custom_shutdown (void *cls) | 63 | sendtask (void *cls) |
68 | { | 64 | { |
69 | if (NULL != th) | 65 | struct GNUNET_TIME_Relative delay; |
66 | struct GNUNET_ATS_Properties prop; | ||
67 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
68 | .num_messages = 1, | ||
69 | .get_size_cb = &get_size, | ||
70 | .ccc = ccc | ||
71 | }; | ||
72 | |||
73 | if (0 == messages_recv) | ||
70 | { | 74 | { |
71 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 75 | start_normal = GNUNET_TIME_absolute_get (); |
72 | th = NULL; | ||
73 | } | 76 | } |
74 | if (NULL != send_task) | 77 | if (1 == messages_recv) |
75 | { | 78 | { |
76 | GNUNET_SCHEDULER_cancel (send_task); | 79 | memset (&prop, 0, sizeof (prop)); |
77 | send_task = NULL; | 80 | delay = GNUNET_TIME_UNIT_SECONDS; |
81 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th, | ||
82 | &ccc->p[0]->id, | ||
83 | &prop, | ||
84 | GNUNET_TIME_UNIT_ZERO, | ||
85 | delay); | ||
86 | prop.distance = 10; | ||
87 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th, | ||
88 | &ccc->p[1]->id, | ||
89 | &prop, | ||
90 | delay, | ||
91 | delay); | ||
92 | start_delayed = GNUNET_TIME_absolute_get(); | ||
78 | } | 93 | } |
94 | GNUNET_TRANSPORT_TESTING_simple_send (&sc); | ||
79 | } | 95 | } |
80 | 96 | ||
81 | 97 | ||
82 | static void | 98 | static void |
83 | sendtask (void *cls); | ||
84 | |||
85 | |||
86 | static void | ||
87 | notify_receive (void *cls, | 99 | notify_receive (void *cls, |
88 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 100 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
89 | const struct GNUNET_PeerIdentity *sender, | 101 | const struct GNUNET_PeerIdentity *sender, |
@@ -102,8 +114,8 @@ notify_receive (void *cls, | |||
102 | GNUNET_free (ps); | 114 | GNUNET_free (ps); |
103 | } | 115 | } |
104 | 116 | ||
105 | if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && | 117 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && |
106 | (TEST_MESSAGE_SIZE == ntohs (message->size))) | 118 | (TEST_MESSAGE_SIZE == ntohs (message->size)) ) |
107 | { | 119 | { |
108 | if (GNUNET_NO == ccc->global_ret) | 120 | if (GNUNET_NO == ccc->global_ret) |
109 | ccc->global_ret = GNUNET_OK; | 121 | ccc->global_ret = GNUNET_OK; |
@@ -125,8 +137,8 @@ notify_receive (void *cls, | |||
125 | messages_recv, | 137 | messages_recv, |
126 | GNUNET_STRINGS_relative_time_to_string (dur_normal, | 138 | GNUNET_STRINGS_relative_time_to_string (dur_normal, |
127 | GNUNET_YES)); | 139 | GNUNET_YES)); |
128 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | 140 | GNUNET_SCHEDULER_add_now (&sendtask, |
129 | NULL); | 141 | NULL); |
130 | } | 142 | } |
131 | if (1 == messages_recv) | 143 | if (1 == messages_recv) |
132 | { | 144 | { |
@@ -152,124 +164,18 @@ notify_receive (void *cls, | |||
152 | } | 164 | } |
153 | 165 | ||
154 | 166 | ||
155 | static size_t | ||
156 | notify_ready (void *cls, size_t size, void *buf) | ||
157 | { | ||
158 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
159 | struct GNUNET_MessageHeader *hdr; | ||
160 | |||
161 | th = NULL; | ||
162 | if (NULL == buf) | ||
163 | { | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
165 | "Timeout occurred while waiting for transmit_ready\n"); | ||
166 | GNUNET_SCHEDULER_shutdown (); | ||
167 | ccc->global_ret = 42; | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
172 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
173 | hdr = buf; | ||
174 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
175 | hdr->type = htons (TEST_MESSAGE_TYPE); | ||
176 | |||
177 | { | ||
178 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
179 | |||
180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
181 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", | ||
182 | ccc->p[1]->no, | ||
183 | ps, | ||
184 | ntohs (hdr->type), | ||
185 | ntohs (hdr->size), | ||
186 | p->no, | ||
187 | GNUNET_i2s (&p->id)); | ||
188 | GNUNET_free (ps); | ||
189 | } | ||
190 | |||
191 | return TEST_MESSAGE_SIZE; | ||
192 | } | ||
193 | |||
194 | |||
195 | static void | ||
196 | sendtask (void *cls) | ||
197 | { | ||
198 | struct GNUNET_TIME_Relative delay; | ||
199 | struct GNUNET_ATS_Properties prop; | ||
200 | |||
201 | if (NULL == send_task) | ||
202 | ccc->global_ret = GNUNET_NO; /* first call! */ | ||
203 | send_task = NULL; | ||
204 | { | ||
205 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
206 | |||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
208 | "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", | ||
209 | ccc->p[1]->no, | ||
210 | GNUNET_i2s (&ccc->p[1]->id), | ||
211 | ccc->p[0]->no, | ||
212 | receiver_s); | ||
213 | GNUNET_free (receiver_s); | ||
214 | } | ||
215 | |||
216 | if (0 == messages_recv) | ||
217 | { | ||
218 | start_normal = GNUNET_TIME_absolute_get (); | ||
219 | } | ||
220 | if (1 == messages_recv) | ||
221 | { | ||
222 | memset (&prop, 0, sizeof (prop)); | ||
223 | delay = GNUNET_TIME_UNIT_SECONDS; | ||
224 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th, | ||
225 | &ccc->p[0]->id, | ||
226 | &prop, | ||
227 | GNUNET_TIME_UNIT_ZERO, | ||
228 | delay); | ||
229 | prop.distance = 10; | ||
230 | GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th, | ||
231 | &ccc->p[1]->id, | ||
232 | &prop, | ||
233 | delay, | ||
234 | delay); | ||
235 | start_delayed = GNUNET_TIME_absolute_get(); | ||
236 | } | ||
237 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
238 | &ccc->p[0]->id, | ||
239 | TEST_MESSAGE_SIZE, | ||
240 | TIMEOUT_TRANSMIT, | ||
241 | ¬ify_ready, | ||
242 | ccc->p[0]); | ||
243 | } | ||
244 | |||
245 | |||
246 | static void | ||
247 | notify_disconnect (void *cls, | ||
248 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
249 | const struct GNUNET_PeerIdentity *other) | ||
250 | { | ||
251 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
252 | me, | ||
253 | other); | ||
254 | if (NULL != th) | ||
255 | { | ||
256 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
257 | th = NULL; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | |||
262 | int | 167 | int |
263 | main (int argc, char *argv[]) | 168 | main (int argc, |
169 | char *argv[]) | ||
264 | { | 170 | { |
265 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 171 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
266 | .connect_continuation = &sendtask, | 172 | .connect_continuation = &sendtask, |
267 | .config_file = "test_transport_api_data.conf", | 173 | .config_file = "test_transport_api_data.conf", |
268 | .rec = ¬ify_receive, | 174 | .rec = ¬ify_receive, |
269 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 175 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
270 | .nd = ¬ify_disconnect, | 176 | .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect, |
271 | .shutdown_task = &custom_shutdown, | 177 | .timeout = TIMEOUT, |
272 | .timeout = TIMEOUT | 178 | .global_ret = GNUNET_NO |
273 | }; | 179 | }; |
274 | 180 | ||
275 | ccc = &my_ccc; | 181 | ccc = &my_ccc; |