diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-05 14:39:12 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-05 14:39:12 +0000 |
commit | 1c388b347390fbc2e784891dad42a2287e90a584 (patch) | |
tree | abd2fcb3396d1490ed6957709abc467792d027cd | |
parent | 28f8e239844323e564d63fc8a792cbcbed41ec68 (diff) | |
download | gnunet-1c388b347390fbc2e784891dad42a2287e90a584.tar.gz gnunet-1c388b347390fbc2e784891dad42a2287e90a584.zip |
delay sending implemented
-rw-r--r-- | src/transport/test_transport_api_manipulation.c | 107 |
1 files changed, 85 insertions, 22 deletions
diff --git a/src/transport/test_transport_api_manipulation.c b/src/transport/test_transport_api_manipulation.c index 03fdb8dc0..21bed3a65 100644 --- a/src/transport/test_transport_api_manipulation.c +++ b/src/transport/test_transport_api_manipulation.c | |||
@@ -76,6 +76,13 @@ static char *cfg_file_p1; | |||
76 | 76 | ||
77 | static char *cfg_file_p2; | 77 | static char *cfg_file_p2; |
78 | 78 | ||
79 | static int messages_recv; | ||
80 | |||
81 | static struct GNUNET_TIME_Absolute start_normal; | ||
82 | static struct GNUNET_TIME_Relative dur_normal; | ||
83 | |||
84 | static struct GNUNET_TIME_Absolute start_delayed; | ||
85 | static struct GNUNET_TIME_Relative dur_delayed; | ||
79 | 86 | ||
80 | static void | 87 | static void |
81 | end () | 88 | end () |
@@ -150,6 +157,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
150 | 157 | ||
151 | 158 | ||
152 | static void | 159 | static void |
160 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
161 | |||
162 | static void | ||
153 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 163 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
154 | const struct GNUNET_MessageHeader *message, | 164 | const struct GNUNET_MessageHeader *message, |
155 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 165 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
@@ -182,25 +192,65 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
182 | { | 192 | { |
183 | GNUNET_break (0); | 193 | GNUNET_break (0); |
184 | ok = 1; | 194 | ok = 1; |
195 | end (); | ||
196 | return; | ||
185 | } | 197 | } |
186 | 198 | ||
187 | for (c = 0; c < ats_count; c++) | 199 | |
200 | if (0 == messages_recv) | ||
188 | { | 201 | { |
189 | //fprintf (stderr, "%d: %u %u\n", d, ntohl(ats[d].type), ats_count); | 202 | /* Received non-delayed message */ |
190 | if (ntohl (ats[c].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) | 203 | dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); |
191 | { | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
192 | if (ntohl (ats[c].value) == 10) | 205 | "Received non-delayed message after %llu\n", |
193 | { | 206 | (long long unsigned int) dur_normal.rel_value); |
194 | ok += 0; | 207 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
195 | } | ||
196 | else | ||
197 | { | ||
198 | GNUNET_break (0); | ||
199 | ok += 1; | ||
200 | } | ||
201 | } | ||
202 | } | 208 | } |
203 | end (); | 209 | if (1 == messages_recv) |
210 | { | ||
211 | /* Received manipulated message */ | ||
212 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); | ||
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
214 | "Received delayed message after %llu\n", | ||
215 | (long long unsigned int) dur_delayed.rel_value); | ||
216 | if (dur_delayed.rel_value < 1000) | ||
217 | { | ||
218 | GNUNET_break (0); | ||
219 | ok += 1; | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
221 | "Delayed message was not delayed correctly: took only %llu\n", | ||
222 | (long long unsigned int) dur_delayed.rel_value); | ||
223 | } | ||
224 | |||
225 | for (c = 0; c < ats_count; c++) | ||
226 | { | ||
227 | if (ntohl (ats[c].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) | ||
228 | { | ||
229 | if (ntohl (ats[c].value) == 10) | ||
230 | { | ||
231 | ok += 0; | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | GNUNET_break (0); | ||
236 | ok += 1; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
241 | /* shutdown */ | ||
242 | end (); | ||
243 | } | ||
244 | messages_recv ++; | ||
245 | |||
246 | |||
247 | |||
248 | /* | ||
249 | |||
250 | |||
251 | // | ||
252 | * | ||
253 | */ | ||
204 | } | 254 | } |
205 | 255 | ||
206 | 256 | ||
@@ -246,6 +296,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
246 | static void | 296 | static void |
247 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 297 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
248 | { | 298 | { |
299 | struct GNUNET_ATS_Information ats[2]; | ||
249 | send_task = GNUNET_SCHEDULER_NO_TASK; | 300 | send_task = GNUNET_SCHEDULER_NO_TASK; |
250 | 301 | ||
251 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 302 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
@@ -256,6 +307,25 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
256 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 307 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
257 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); | 308 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); |
258 | GNUNET_free (receiver_s); | 309 | GNUNET_free (receiver_s); |
310 | |||
311 | |||
312 | if (0 == messages_recv) | ||
313 | { | ||
314 | start_normal = GNUNET_TIME_absolute_get(); | ||
315 | } | ||
316 | if (1 == messages_recv) | ||
317 | { | ||
318 | ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
319 | ats[0].value = htonl (1000); | ||
320 | ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
321 | ats[1].value = htonl (10); | ||
322 | |||
323 | GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_BOTH, ats, 2); | ||
324 | GNUNET_TRANSPORT_set_traffic_metric (p2->th, &p1->id, TM_BOTH, ats, 2); | ||
325 | |||
326 | start_delayed = GNUNET_TIME_absolute_get(); | ||
327 | } | ||
328 | |||
259 | s_sending = GNUNET_YES; | 329 | s_sending = GNUNET_YES; |
260 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0, | 330 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0, |
261 | TIMEOUT_TRANSMIT, ¬ify_ready, | 331 | TIMEOUT_TRANSMIT, ¬ify_ready, |
@@ -325,8 +395,6 @@ static void | |||
325 | start_cb (struct PeerContext *p, void *cls) | 395 | start_cb (struct PeerContext *p, void *cls) |
326 | { | 396 | { |
327 | static int started; | 397 | static int started; |
328 | struct GNUNET_ATS_Information ats; | ||
329 | |||
330 | started++; | 398 | started++; |
331 | 399 | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | 400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, |
@@ -338,11 +406,6 @@ start_cb (struct PeerContext *p, void *cls) | |||
338 | s_started = GNUNET_YES; | 406 | s_started = GNUNET_YES; |
339 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 407 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
340 | 408 | ||
341 | ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
342 | ats.value = htonl (10); | ||
343 | |||
344 | GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_BOTH, &ats, 1); | ||
345 | |||
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
347 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 410 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
348 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 411 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); |