diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-21 14:42:54 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-21 14:42:54 +0000 |
commit | 40c8383cbd3decba4d605d6f94b102a1ed18a825 (patch) | |
tree | 11aa480f80b2c6f3630bb4128a0cefed60b173aa /src/stream | |
parent | ed2c4e1a48219c6daae03fd161fd311f22afe05f (diff) | |
download | gnunet-40c8383cbd3decba4d605d6f94b102a1ed18a825.tar.gz gnunet-40c8383cbd3decba4d605d6f94b102a1ed18a825.zip |
-added stream listen success callback
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/stream_api.c | 19 | ||||
-rw-r--r-- | src/stream/test_stream_2peers.c | 22 | ||||
-rw-r--r-- | src/stream/test_stream_2peers_halfclose.c | 20 | ||||
-rw-r--r-- | src/stream/test_stream_big.c | 31 | ||||
-rw-r--r-- | src/stream/test_stream_local.c | 27 | ||||
-rw-r--r-- | src/stream/test_stream_local.conf | 1 | ||||
-rw-r--r-- | src/stream/test_stream_sequence_wraparound.c | 50 |
7 files changed, 88 insertions, 82 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index cd89a1de3..f042ccc93 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -389,6 +389,11 @@ struct GNUNET_STREAM_ListenSocket | |||
389 | struct GNUNET_LOCKMANAGER_LockingRequest *locking_request; | 389 | struct GNUNET_LOCKMANAGER_LockingRequest *locking_request; |
390 | 390 | ||
391 | /** | 391 | /** |
392 | * Callback to call after acquring a lock and listening | ||
393 | */ | ||
394 | GNUNET_STREAM_ListenSuccessCallback listen_ok_cb; | ||
395 | |||
396 | /** | ||
392 | * The callback function which is called after successful opening socket | 397 | * The callback function which is called after successful opening socket |
393 | */ | 398 | */ |
394 | GNUNET_STREAM_ListenCallback listen_cb; | 399 | GNUNET_STREAM_ListenCallback listen_cb; |
@@ -2873,6 +2878,10 @@ lock_status_change_cb (void *cls, const char *domain, uint32_t lock, | |||
2873 | server_message_handlers, | 2878 | server_message_handlers, |
2874 | ports); | 2879 | ports); |
2875 | GNUNET_assert (NULL != lsocket->mesh); | 2880 | GNUNET_assert (NULL != lsocket->mesh); |
2881 | if (NULL != lsocket->listen_ok_cb) | ||
2882 | { | ||
2883 | (void) lsocket->listen_ok_cb (); | ||
2884 | } | ||
2876 | } | 2885 | } |
2877 | } | 2886 | } |
2878 | if (GNUNET_LOCKMANAGER_RELEASE == status) | 2887 | if (GNUNET_LOCKMANAGER_RELEASE == status) |
@@ -2939,6 +2948,9 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2939 | case GNUNET_STREAM_OPTION_LISTEN_TIMEOUT: | 2948 | case GNUNET_STREAM_OPTION_LISTEN_TIMEOUT: |
2940 | GNUNET_break (0); /* Option irrelevant in STREAM_open */ | 2949 | GNUNET_break (0); /* Option irrelevant in STREAM_open */ |
2941 | break; | 2950 | break; |
2951 | case GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS: | ||
2952 | GNUNET_break (0); /* Option irrelevant in STREAM_open */ | ||
2953 | break; | ||
2942 | case GNUNET_STREAM_OPTION_END: | 2954 | case GNUNET_STREAM_OPTION_END: |
2943 | break; | 2955 | break; |
2944 | } | 2956 | } |
@@ -3200,7 +3212,8 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3200 | lsocket->retransmit_timeout = | 3212 | lsocket->retransmit_timeout = |
3201 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout); | 3213 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout); |
3202 | lsocket->testing_active = GNUNET_NO; | 3214 | lsocket->testing_active = GNUNET_NO; |
3203 | listen_timeout = TIME_REL_SECS (60); /* A minute for listen timeout */ | 3215 | lsocket->listen_ok_cb = NULL; |
3216 | listen_timeout = TIME_REL_SECS (60); /* A minute for listen timeout */ | ||
3204 | va_start (vargs, listen_cb_cls); | 3217 | va_start (vargs, listen_cb_cls); |
3205 | do { | 3218 | do { |
3206 | option = va_arg (vargs, enum GNUNET_STREAM_Option); | 3219 | option = va_arg (vargs, enum GNUNET_STREAM_Option); |
@@ -3219,6 +3232,10 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3219 | listen_timeout = GNUNET_TIME_relative_multiply | 3232 | listen_timeout = GNUNET_TIME_relative_multiply |
3220 | (GNUNET_TIME_UNIT_MILLISECONDS, va_arg (vargs, uint32_t)); | 3233 | (GNUNET_TIME_UNIT_MILLISECONDS, va_arg (vargs, uint32_t)); |
3221 | break; | 3234 | break; |
3235 | case GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS: | ||
3236 | lsocket->listen_ok_cb = va_arg (vargs, | ||
3237 | GNUNET_STREAM_ListenSuccessCallback); | ||
3238 | break; | ||
3222 | case GNUNET_STREAM_OPTION_END: | 3239 | case GNUNET_STREAM_OPTION_END: |
3223 | break; | 3240 | break; |
3224 | } | 3241 | } |
diff --git a/src/stream/test_stream_2peers.c b/src/stream/test_stream_2peers.c index ecb4b848c..4313f646b 100644 --- a/src/stream/test_stream_2peers.c +++ b/src/stream/test_stream_2peers.c | |||
@@ -436,15 +436,11 @@ stream_listen_cb (void *cls, | |||
436 | 436 | ||
437 | 437 | ||
438 | /** | 438 | /** |
439 | * Task for connecting the peer to stream as client | 439 | * Listen success callback; connects a peer to stream as client |
440 | * | ||
441 | * @param cls PeerData | ||
442 | * @param tc the TaskContext | ||
443 | */ | 440 | */ |
444 | static void | 441 | static void |
445 | stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 442 | stream_connect (void) |
446 | { | 443 | { |
447 | /* Connect to stream library */ | ||
448 | peer1.socket = GNUNET_STREAM_open (d1->cfg, | 444 | peer1.socket = GNUNET_STREAM_open (d1->cfg, |
449 | &d2->id, /* Null for local peer? */ | 445 | &d2->id, /* Null for local peer? */ |
450 | 10, /* App port */ | 446 | 10, /* App port */ |
@@ -494,13 +490,15 @@ peergroup_ready (void *cls, const char *emsg) | |||
494 | GNUNET_i2s (&peer2.our_id), | 490 | GNUNET_i2s (&peer2.our_id), |
495 | GNUNET_i2s (&d2->id)); | 491 | GNUNET_i2s (&d2->id)); |
496 | 492 | ||
497 | peer2_listen_socket = GNUNET_STREAM_listen (d2->cfg, | 493 | peer2_listen_socket = |
498 | 10, /* App port */ | 494 | GNUNET_STREAM_listen (d2->cfg, |
499 | &stream_listen_cb, | 495 | 10, /* App port */ |
500 | NULL, | 496 | &stream_listen_cb, |
501 | GNUNET_STREAM_OPTION_END); | 497 | NULL, |
498 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
499 | &stream_connect, | ||
500 | GNUNET_STREAM_OPTION_END); | ||
502 | GNUNET_assert (NULL != peer2_listen_socket); | 501 | GNUNET_assert (NULL != peer2_listen_socket); |
503 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, NULL); | ||
504 | } | 502 | } |
505 | 503 | ||
506 | 504 | ||
diff --git a/src/stream/test_stream_2peers_halfclose.c b/src/stream/test_stream_2peers_halfclose.c index 0e78dec20..8de758ea0 100644 --- a/src/stream/test_stream_2peers_halfclose.c +++ b/src/stream/test_stream_2peers_halfclose.c | |||
@@ -662,13 +662,10 @@ stream_listen_cb (void *cls, | |||
662 | 662 | ||
663 | 663 | ||
664 | /** | 664 | /** |
665 | * Task for connecting the peer to stream as client | 665 | * Listen success callback; connects a peer to stream as client |
666 | * | ||
667 | * @param cls PeerData | ||
668 | * @param tc the TaskContext | ||
669 | */ | 666 | */ |
670 | static void | 667 | static void |
671 | stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 668 | stream_connect (void) |
672 | { | 669 | { |
673 | /* Connect to stream library */ | 670 | /* Connect to stream library */ |
674 | peer1.socket = GNUNET_STREAM_open (d1->cfg, | 671 | peer1.socket = GNUNET_STREAM_open (d1->cfg, |
@@ -720,12 +717,15 @@ peergroup_ready (void *cls, const char *emsg) | |||
720 | GNUNET_i2s (&peer2.our_id), | 717 | GNUNET_i2s (&peer2.our_id), |
721 | GNUNET_i2s (&d2->id)); | 718 | GNUNET_i2s (&d2->id)); |
722 | 719 | ||
723 | peer2_listen_socket = GNUNET_STREAM_listen (d2->cfg, | 720 | peer2_listen_socket = |
724 | 10, /* App port */ | 721 | GNUNET_STREAM_listen (d2->cfg, |
725 | &stream_listen_cb, | 722 | 10, /* App port */ |
726 | NULL); | 723 | &stream_listen_cb, |
724 | NULL, | ||
725 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
726 | &stream_connect, | ||
727 | GNUNET_STREAM_OPTION_END); | ||
727 | GNUNET_assert (NULL != peer2_listen_socket); | 728 | GNUNET_assert (NULL != peer2_listen_socket); |
728 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, NULL); | ||
729 | } | 729 | } |
730 | 730 | ||
731 | 731 | ||
diff --git a/src/stream/test_stream_big.c b/src/stream/test_stream_big.c index dff5cc0a6..119028807 100644 --- a/src/stream/test_stream_big.c +++ b/src/stream/test_stream_big.c | |||
@@ -324,15 +324,12 @@ stream_listen_cb (void *cls, | |||
324 | 324 | ||
325 | 325 | ||
326 | /** | 326 | /** |
327 | * Task for connecting the peer to stream as client | 327 | * Listen success callback; connects a peer to stream as client |
328 | * | ||
329 | * @param cls PeerData | ||
330 | * @param tc the TaskContext | ||
331 | */ | 328 | */ |
332 | static void | 329 | static void |
333 | stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 330 | stream_connect (void) |
334 | { | 331 | { |
335 | struct PeerData *peer = cls; | 332 | struct PeerData *peer = &peer1; |
336 | 333 | ||
337 | /* Connect to stream */ | 334 | /* Connect to stream */ |
338 | peer->socket = GNUNET_STREAM_open (config, | 335 | peer->socket = GNUNET_STREAM_open (config, |
@@ -360,20 +357,22 @@ run (void *cls, | |||
360 | struct GNUNET_PeerIdentity self; | 357 | struct GNUNET_PeerIdentity self; |
361 | 358 | ||
362 | GNUNET_TESTING_peer_get_identity (peer, &self); | 359 | GNUNET_TESTING_peer_get_identity (peer, &self); |
363 | config = cfg; | 360 | config = cfg; |
361 | peer2_listen_socket = | ||
362 | GNUNET_STREAM_listen (config, | ||
363 | 10, /* App port */ | ||
364 | &stream_listen_cb, | ||
365 | NULL, | ||
366 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
367 | &stream_connect, | ||
368 | GNUNET_STREAM_OPTION_END); | ||
369 | GNUNET_assert (NULL != peer2_listen_socket); | ||
370 | peer1.self = self; | ||
371 | peer2.self = self; | ||
364 | abort_task = | 372 | abort_task = |
365 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 373 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
366 | (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort, | 374 | (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort, |
367 | NULL); | 375 | NULL); |
368 | peer2_listen_socket = GNUNET_STREAM_listen (config, | ||
369 | 10, /* App port */ | ||
370 | &stream_listen_cb, | ||
371 | NULL, | ||
372 | GNUNET_STREAM_OPTION_END); | ||
373 | GNUNET_assert (NULL != peer2_listen_socket); | ||
374 | peer1.self = self; | ||
375 | peer2.self = self; | ||
376 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1); | ||
377 | } | 376 | } |
378 | 377 | ||
379 | /** | 378 | /** |
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c index e660d77d7..af1b8ff84 100644 --- a/src/stream/test_stream_local.c +++ b/src/stream/test_stream_local.c | |||
@@ -335,19 +335,12 @@ stream_listen_cb (void *cls, | |||
335 | 335 | ||
336 | 336 | ||
337 | /** | 337 | /** |
338 | * Task for connecting the peer to stream as client | 338 | * Listen success callback; connects a peer to stream as client |
339 | * | ||
340 | * @param cls PeerData | ||
341 | * @param tc the TaskContext | ||
342 | */ | 339 | */ |
343 | static void | 340 | static void |
344 | stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 341 | stream_connect (void) |
345 | { | 342 | { |
346 | struct PeerData *peer = cls; | 343 | peer1.socket = GNUNET_STREAM_open (config, |
347 | |||
348 | GNUNET_assert (&peer1 == peer); | ||
349 | /* Connect to stream library */ | ||
350 | peer->socket = GNUNET_STREAM_open (config, | ||
351 | &self_id, | 344 | &self_id, |
352 | 10, /* App port */ | 345 | 10, /* App port */ |
353 | &stream_open_cb, | 346 | &stream_open_cb, |
@@ -368,13 +361,15 @@ run (void *cls, | |||
368 | config = cfg; | 361 | config = cfg; |
369 | self = peer; | 362 | self = peer; |
370 | GNUNET_TESTING_peer_get_identity (peer, &self_id); | 363 | GNUNET_TESTING_peer_get_identity (peer, &self_id); |
371 | peer2_listen_socket = GNUNET_STREAM_listen (config, | 364 | peer2_listen_socket = |
372 | 10, /* App port */ | 365 | GNUNET_STREAM_listen (config, |
373 | &stream_listen_cb, | 366 | 10, /* App port */ |
374 | &peer2, | 367 | &stream_listen_cb, |
375 | GNUNET_STREAM_OPTION_END); | 368 | &peer2, |
369 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
370 | &stream_connect, | ||
371 | GNUNET_STREAM_OPTION_END); | ||
376 | GNUNET_assert (NULL != peer2_listen_socket); | 372 | GNUNET_assert (NULL != peer2_listen_socket); |
377 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1); | ||
378 | abort_task = | 373 | abort_task = |
379 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 374 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
380 | (GNUNET_TIME_UNIT_SECONDS, 30), &do_abort, | 375 | (GNUNET_TIME_UNIT_SECONDS, 30), &do_abort, |
diff --git a/src/stream/test_stream_local.conf b/src/stream/test_stream_local.conf index 90ddf41c6..09929ca27 100644 --- a/src/stream/test_stream_local.conf +++ b/src/stream/test_stream_local.conf | |||
@@ -2,6 +2,7 @@ | |||
2 | AUTOSTART = NO | 2 | AUTOSTART = NO |
3 | ACCEPT_FROM = 127.0.0.1; | 3 | ACCEPT_FROM = 127.0.0.1; |
4 | HOSTNAME = localhost | 4 | HOSTNAME = localhost |
5 | PORT = 12101 | ||
5 | 6 | ||
6 | [fs] | 7 | [fs] |
7 | AUTOSTART = NO | 8 | AUTOSTART = NO |
diff --git a/src/stream/test_stream_sequence_wraparound.c b/src/stream/test_stream_sequence_wraparound.c index ffd2eb5fb..3ea6596bd 100644 --- a/src/stream/test_stream_sequence_wraparound.c +++ b/src/stream/test_stream_sequence_wraparound.c | |||
@@ -313,28 +313,22 @@ stream_listen_cb (void *cls, | |||
313 | 313 | ||
314 | 314 | ||
315 | /** | 315 | /** |
316 | * Task for connecting the peer to stream as client | 316 | * Listen success callback; connects a peer to stream as client |
317 | * | ||
318 | * @param cls PeerData | ||
319 | * @param tc the TaskContext | ||
320 | */ | 317 | */ |
321 | static void | 318 | static void |
322 | stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 319 | stream_connect (void) |
323 | { | 320 | { |
324 | struct PeerData *peer = cls; | 321 | peer1.socket = |
325 | 322 | GNUNET_STREAM_open (config, | |
326 | GNUNET_assert (&peer1 == peer); | 323 | &self_id, /* Null for local peer? */ |
327 | /* Connect to stream */ | 324 | 10, /* App port */ |
328 | peer->socket = GNUNET_STREAM_open (config, | 325 | &stream_open_cb, |
329 | &self_id, /* Null for local peer? */ | 326 | &peer1, |
330 | 10, /* App port */ | 327 | GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER, |
331 | &stream_open_cb, | 328 | UINT32_MAX - GNUNET_CRYPTO_random_u32 |
332 | &peer1, | 329 | (GNUNET_CRYPTO_QUALITY_WEAK, 64), |
333 | GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER, | 330 | GNUNET_STREAM_OPTION_END); |
334 | UINT32_MAX - GNUNET_CRYPTO_random_u32 | 331 | GNUNET_assert (NULL != peer1.socket); |
335 | (GNUNET_CRYPTO_QUALITY_WEAK, 64), | ||
336 | GNUNET_STREAM_OPTION_END); | ||
337 | GNUNET_assert (NULL != peer->socket); | ||
338 | } | 332 | } |
339 | 333 | ||
340 | 334 | ||
@@ -349,15 +343,17 @@ run (void *cls, | |||
349 | config = cfg; | 343 | config = cfg; |
350 | self = peer; | 344 | self = peer; |
351 | (void) GNUNET_TESTING_peer_get_identity (peer, &self_id); | 345 | (void) GNUNET_TESTING_peer_get_identity (peer, &self_id); |
352 | peer2_listen_socket = GNUNET_STREAM_listen (config, | 346 | peer2_listen_socket = |
353 | 10, /* App port */ | 347 | GNUNET_STREAM_listen (config, |
354 | &stream_listen_cb, | 348 | 10, /* App port */ |
355 | NULL, | 349 | &stream_listen_cb, |
356 | GNUNET_STREAM_OPTION_LISTEN_TIMEOUT, | 350 | NULL, |
357 | 30 * 1000, | 351 | GNUNET_STREAM_OPTION_LISTEN_TIMEOUT, |
358 | GNUNET_STREAM_OPTION_END); | 352 | 60 * 1000, |
353 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
354 | &stream_connect, | ||
355 | GNUNET_STREAM_OPTION_END); | ||
359 | GNUNET_assert (NULL != peer2_listen_socket); | 356 | GNUNET_assert (NULL != peer2_listen_socket); |
360 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(10), &stream_connect, &peer1); | ||
361 | abort_task = | 357 | abort_task = |
362 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 358 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
363 | (GNUNET_TIME_UNIT_SECONDS, 100), &do_abort, | 359 | (GNUNET_TIME_UNIT_SECONDS, 100), &do_abort, |