aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-06-16 19:27:15 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-06-16 19:27:15 +0000
commit21d40f40cd7307a541a68b0d3b31ef4c2b2cdf7d (patch)
treea0a586b9bb29cc02cdc5f23978c52c1f3aa6df68
parentddefc2b2e4b461cf8beae38ebda30ee8711cd5d2 (diff)
downloadgnunet-21d40f40cd7307a541a68b0d3b31ef4c2b2cdf7d.tar.gz
gnunet-21d40f40cd7307a541a68b0d3b31ef4c2b2cdf7d.zip
-stream testing hooks and options
-rw-r--r--src/include/gnunet_stream_lib.h12
-rw-r--r--src/stream/stream_api.c66
-rw-r--r--src/stream/test_stream_2peers.c3
-rw-r--r--src/stream/test_stream_api.c6
-rw-r--r--src/stream/test_stream_big.c6
-rw-r--r--src/stream/test_stream_local.c3
6 files changed, 86 insertions, 10 deletions
diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h
index e09c264d6..f348780e3 100644
--- a/src/include/gnunet_stream_lib.h
+++ b/src/include/gnunet_stream_lib.h
@@ -103,7 +103,13 @@ enum GNUNET_STREAM_Option
103 * of '0' means to use the round-trip time (plus a tiny grace period); 103 * of '0' means to use the round-trip time (plus a tiny grace period);
104 * this is also the default. 104 * this is also the default.
105 */ 105 */
106 GNUNET_STREAM_OPTION_INITIAL_RETRANSMIT_TIMEOUT 106 GNUNET_STREAM_OPTION_INITIAL_RETRANSMIT_TIMEOUT,
107
108 /**
109 * Option to set the write sequence number. Takes a uint32_t as parameter
110 * to set the value of the write sequence number
111 */
112 GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER
107 }; 113 };
108 114
109 115
@@ -211,13 +217,15 @@ struct GNUNET_STREAM_ListenSocket;
211 * @param listen_cb this function will be called when a peer tries to establish 217 * @param listen_cb this function will be called when a peer tries to establish
212 * a stream with us 218 * a stream with us
213 * @param listen_cb_cls closure for listen_cb 219 * @param listen_cb_cls closure for listen_cb
220 * @param ... options to the stream, terminated by GNUNET_STREAM_OPTION_END
214 * @return listen socket, NULL for any error 221 * @return listen socket, NULL for any error
215 */ 222 */
216struct GNUNET_STREAM_ListenSocket * 223struct GNUNET_STREAM_ListenSocket *
217GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, 224GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
218 GNUNET_MESH_ApplicationType app_port, 225 GNUNET_MESH_ApplicationType app_port,
219 GNUNET_STREAM_ListenCallback listen_cb, 226 GNUNET_STREAM_ListenCallback listen_cb,
220 void *listen_cb_cls); 227 void *listen_cb_cls,
228 ...);
221 229
222 230
223/** 231/**
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index 1dc1ba80e..8c25965f1 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -301,6 +301,16 @@ struct GNUNET_STREAM_Socket
301 GNUNET_MESH_ApplicationType app_port; 301 GNUNET_MESH_ApplicationType app_port;
302 302
303 /** 303 /**
304 * Whether testing mode is active or not
305 */
306 int testing_active;
307
308 /**
309 * The write sequence number to be set incase of testing
310 */
311 uint32_t testing_set_write_sequence_number_value;
312
313 /**
304 * The session id associated with this stream connection 314 * The session id associated with this stream connection
305 * FIXME: Not used currently, may be removed 315 * FIXME: Not used currently, may be removed
306 */ 316 */
@@ -374,6 +384,21 @@ struct GNUNET_STREAM_ListenSocket
374 * FIXME: Remove if not required! 384 * FIXME: Remove if not required!
375 */ 385 */
376 GNUNET_MESH_ApplicationType port; 386 GNUNET_MESH_ApplicationType port;
387
388 /**
389 * The retransmit timeout
390 */
391 struct GNUNET_TIME_Relative retransmit_timeout;
392
393 /**
394 * Whether testing mode is active or not
395 */
396 int testing_active;
397
398 /**
399 * The write sequence number to be set incase of testing
400 */
401 uint32_t testing_set_write_sequence_number_value;
377}; 402};
378 403
379 404
@@ -2666,7 +2691,11 @@ new_tunnel_notify (void *cls,
2666 socket->session_id = 0; /* FIXME */ 2691 socket->session_id = 0; /* FIXME */
2667 socket->state = STATE_INIT; 2692 socket->state = STATE_INIT;
2668 socket->lsocket = lsocket; 2693 socket->lsocket = lsocket;
2669 2694 socket->retransmit_timeout = lsocket->retransmit_timeout;
2695 socket->testing_active = lsocket->testing_active;
2696 socket->testing_set_write_sequence_number_value =
2697 lsocket->testing_set_write_sequence_number_value;
2698
2670 LOG (GNUNET_ERROR_TYPE_DEBUG, 2699 LOG (GNUNET_ERROR_TYPE_DEBUG,
2671 "%s: Peer %s initiated tunnel to us\n", 2700 "%s: Peer %s initiated tunnel to us\n",
2672 GNUNET_i2s (&socket->other_peer), 2701 GNUNET_i2s (&socket->other_peer),
@@ -2777,6 +2806,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
2777 /* Set defaults */ 2806 /* Set defaults */
2778 socket->retransmit_timeout = 2807 socket->retransmit_timeout =
2779 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout); 2808 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout);
2809 socket->testing_active = GNUNET_NO;
2780 va_start (vargs, open_cb_cls); /* Parse variable args */ 2810 va_start (vargs, open_cb_cls); /* Parse variable args */
2781 do { 2811 do {
2782 option = va_arg (vargs, enum GNUNET_STREAM_Option); 2812 option = va_arg (vargs, enum GNUNET_STREAM_Option);
@@ -2787,6 +2817,11 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
2787 socket->retransmit_timeout = va_arg (vargs, 2817 socket->retransmit_timeout = va_arg (vargs,
2788 struct GNUNET_TIME_Relative); 2818 struct GNUNET_TIME_Relative);
2789 break; 2819 break;
2820 case GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER:
2821 socket->testing_active = GNUNET_YES;
2822 socket->testing_set_write_sequence_number_value = va_arg (vargs,
2823 uint32_t);
2824 break;
2790 case GNUNET_STREAM_OPTION_END: 2825 case GNUNET_STREAM_OPTION_END:
2791 break; 2826 break;
2792 } 2827 }
@@ -3018,19 +3053,46 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket)
3018 * @param listen_cb this function will be called when a peer tries to establish 3053 * @param listen_cb this function will be called when a peer tries to establish
3019 * a stream with us 3054 * a stream with us
3020 * @param listen_cb_cls closure for listen_cb 3055 * @param listen_cb_cls closure for listen_cb
3056 * @param ... options to the stream, terminated by GNUNET_STREAM_OPTION_END
3021 * @return listen socket, NULL for any error 3057 * @return listen socket, NULL for any error
3022 */ 3058 */
3023struct GNUNET_STREAM_ListenSocket * 3059struct GNUNET_STREAM_ListenSocket *
3024GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, 3060GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
3025 GNUNET_MESH_ApplicationType app_port, 3061 GNUNET_MESH_ApplicationType app_port,
3026 GNUNET_STREAM_ListenCallback listen_cb, 3062 GNUNET_STREAM_ListenCallback listen_cb,
3027 void *listen_cb_cls) 3063 void *listen_cb_cls,
3064 ...)
3028{ 3065{
3029 /* FIXME: Add variable args for passing configration options? */ 3066 /* FIXME: Add variable args for passing configration options? */
3030 struct GNUNET_STREAM_ListenSocket *lsocket; 3067 struct GNUNET_STREAM_ListenSocket *lsocket;
3031 GNUNET_MESH_ApplicationType ports[] = {app_port, 0}; 3068 GNUNET_MESH_ApplicationType ports[] = {app_port, 0};
3069 enum GNUNET_STREAM_Option option;
3070 va_list vargs;
3032 3071
3033 lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket)); 3072 lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket));
3073 /* Set defaults */
3074 lsocket->retransmit_timeout =
3075 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout);
3076 lsocket->testing_active = GNUNET_NO;
3077 va_start (vargs, listen_cb_cls);
3078 do {
3079 option = va_arg (vargs, enum GNUNET_STREAM_Option);
3080 switch (option)
3081 {
3082 case GNUNET_STREAM_OPTION_INITIAL_RETRANSMIT_TIMEOUT:
3083 lsocket->retransmit_timeout = va_arg (vargs,
3084 struct GNUNET_TIME_Relative);
3085 break;
3086 case GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER:
3087 lsocket->testing_active = GNUNET_YES;
3088 lsocket->testing_set_write_sequence_number_value = va_arg (vargs,
3089 uint32_t);
3090 break;
3091 case GNUNET_STREAM_OPTION_END:
3092 break;
3093 }
3094 } while (GNUNET_STREAM_OPTION_END != option);
3095 va_end (vargs);
3034 lsocket->port = app_port; 3096 lsocket->port = app_port;
3035 lsocket->listen_cb = listen_cb; 3097 lsocket->listen_cb = listen_cb;
3036 lsocket->listen_cb_cls = listen_cb_cls; 3098 lsocket->listen_cb_cls = listen_cb_cls;
diff --git a/src/stream/test_stream_2peers.c b/src/stream/test_stream_2peers.c
index 1fdc0ee19..6a61022e0 100644
--- a/src/stream/test_stream_2peers.c
+++ b/src/stream/test_stream_2peers.c
@@ -474,7 +474,8 @@ peergroup_ready (void *cls, const char *emsg)
474 peer2_listen_socket = GNUNET_STREAM_listen (d2->cfg, 474 peer2_listen_socket = GNUNET_STREAM_listen (d2->cfg,
475 10, /* App port */ 475 10, /* App port */
476 &stream_listen_cb, 476 &stream_listen_cb,
477 NULL); 477 NULL,
478 GNUNET_STREAM_OPTION_END);
478 GNUNET_assert (NULL != peer2_listen_socket); 479 GNUNET_assert (NULL != peer2_listen_socket);
479 480
480 /* Connect to stream library */ 481 /* Connect to stream library */
diff --git a/src/stream/test_stream_api.c b/src/stream/test_stream_api.c
index 84c486763..20581f9b6 100644
--- a/src/stream/test_stream_api.c
+++ b/src/stream/test_stream_api.c
@@ -348,7 +348,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
348 peer2_listen_socket = GNUNET_STREAM_listen (config, 348 peer2_listen_socket = GNUNET_STREAM_listen (config,
349 10, /* App port */ 349 10, /* App port */
350 &stream_listen_cb, 350 &stream_listen_cb,
351 NULL); 351 NULL,
352 GNUNET_STREAM_OPTION_END);
352 GNUNET_assert (NULL != peer2_listen_socket); 353 GNUNET_assert (NULL != peer2_listen_socket);
353 354
354 /* Connect to stream library */ 355 /* Connect to stream library */
@@ -356,7 +357,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
356 &self, /* Null for local peer? */ 357 &self, /* Null for local peer? */
357 10, /* App port */ 358 10, /* App port */
358 &stream_open_cb, 359 &stream_open_cb,
359 (void *) &peer1); 360 (void *) &peer1,
361 GNUNET_STREAM_OPTION_END);
360 GNUNET_assert (NULL != peer1.socket); 362 GNUNET_assert (NULL != peer1.socket);
361} 363}
362 364
diff --git a/src/stream/test_stream_big.c b/src/stream/test_stream_big.c
index d645f66a7..58ad4427c 100644
--- a/src/stream/test_stream_big.c
+++ b/src/stream/test_stream_big.c
@@ -345,7 +345,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
345 peer2_listen_socket = GNUNET_STREAM_listen (config, 345 peer2_listen_socket = GNUNET_STREAM_listen (config,
346 10, /* App port */ 346 10, /* App port */
347 &stream_listen_cb, 347 &stream_listen_cb,
348 NULL); 348 NULL,
349 GNUNET_STREAM_OPTION_END);
349 GNUNET_assert (NULL != peer2_listen_socket); 350 GNUNET_assert (NULL != peer2_listen_socket);
350 351
351 /* Connect to stream library */ 352 /* Connect to stream library */
@@ -353,7 +354,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
353 &self, /* Null for local peer? */ 354 &self, /* Null for local peer? */
354 10, /* App port */ 355 10, /* App port */
355 &stream_open_cb, 356 &stream_open_cb,
356 (void *) &peer1); 357 (void *) &peer1,
358 GNUNET_STREAM_OPTION_END);
357 GNUNET_assert (NULL != peer1.socket); 359 GNUNET_assert (NULL != peer1.socket);
358} 360}
359 361
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c
index c9fab8406..fc2a8f842 100644
--- a/src/stream/test_stream_local.c
+++ b/src/stream/test_stream_local.c
@@ -373,7 +373,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
373 peer2_listen_socket = GNUNET_STREAM_listen (config_peer2, 373 peer2_listen_socket = GNUNET_STREAM_listen (config_peer2,
374 10, /* App port */ 374 10, /* App port */
375 &stream_listen_cb, 375 &stream_listen_cb,
376 &peer2); 376 &peer2,
377 GNUNET_STREAM_OPTION_END);
377 GNUNET_assert (NULL != peer2_listen_socket); 378 GNUNET_assert (NULL != peer2_listen_socket);
378 379
379 /* Connect to stream library */ 380 /* Connect to stream library */