aboutsummaryrefslogtreecommitdiff
path: root/src/stream
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-20 12:41:35 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-20 12:41:35 +0000
commitbd8ba044e2d6d9878b6a24eceb89b29965d08cf3 (patch)
treeb5152e53173e0f8dceb4fdd725d460b5f2b3e6b6 /src/stream
parent550e15b99d7fbe50f7b2e7d695f87ae3a3d5f57d (diff)
downloadgnunet-bd8ba044e2d6d9878b6a24eceb89b29965d08cf3.tar.gz
gnunet-bd8ba044e2d6d9878b6a24eceb89b29965d08cf3.zip
-working on stream
Diffstat (limited to 'src/stream')
-rw-r--r--src/stream/Makefile.am2
-rw-r--r--src/stream/stream_api.c16
-rw-r--r--src/stream/test_stream_big.c106
3 files changed, 36 insertions, 88 deletions
diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am
index 3a0e6835e..10d87f042 100644
--- a/src/stream/Makefile.am
+++ b/src/stream/Makefile.am
@@ -62,7 +62,7 @@ test_stream_big_SOURCES = \
62test_stream_big_LDADD = \ 62test_stream_big_LDADD = \
63 $(top_builddir)/src/stream/libgnunetstream.la \ 63 $(top_builddir)/src/stream/libgnunetstream.la \
64 $(top_builddir)/src/util/libgnunetutil.la \ 64 $(top_builddir)/src/util/libgnunetutil.la \
65 $(top_builddir)/src/testing_old/libgnunettesting_old.la 65 $(top_builddir)/src/testing/libgnunettesting.la
66 66
67test_stream_sequence_wraparound_SOURCES = \ 67test_stream_sequence_wraparound_SOURCES = \
68 test_stream_sequence_wraparound.c 68 test_stream_sequence_wraparound.c
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index fda1810f6..e27f4df1f 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -702,6 +702,7 @@ send_ack_notify (void *cls, size_t size, void *buf)
702 return size; 702 return size;
703} 703}
704 704
705
705/** 706/**
706 * Writes data using the given socket. The amount of data written is limited by 707 * Writes data using the given socket. The amount of data written is limited by
707 * the receiver_window_size 708 * the receiver_window_size
@@ -711,6 +712,7 @@ send_ack_notify (void *cls, size_t size, void *buf)
711static void 712static void
712write_data (struct GNUNET_STREAM_Socket *socket); 713write_data (struct GNUNET_STREAM_Socket *socket);
713 714
715
714/** 716/**
715 * Task for retransmitting data messages if they aren't ACK before their ack 717 * Task for retransmitting data messages if they aren't ACK before their ack
716 * deadline 718 * deadline
@@ -1294,7 +1296,6 @@ set_state_established (void *cls,
1294 socket->write_offset = 0; 1296 socket->write_offset = 0;
1295 socket->read_offset = 0; 1297 socket->read_offset = 0;
1296 socket->state = STATE_ESTABLISHED; 1298 socket->state = STATE_ESTABLISHED;
1297 /* FIXME: What if listen_cb is NULL */
1298 if (NULL != socket->lsocket) 1299 if (NULL != socket->lsocket)
1299 { 1300 {
1300 LOG (GNUNET_ERROR_TYPE_DEBUG, 1301 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1306,12 +1307,12 @@ set_state_established (void *cls,
1306 &socket->other_peer)) 1307 &socket->other_peer))
1307 { 1308 {
1308 socket->state = STATE_CLOSED; 1309 socket->state = STATE_CLOSED;
1309 /* FIXME: We should close in a decent way */ 1310 /* FIXME: We should close in a decent way (send RST) */
1310 GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */ 1311 GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
1311 GNUNET_free (socket); 1312 GNUNET_free (socket);
1312 } 1313 }
1313 } 1314 }
1314 else if (socket->open_cb) 1315 else if (NULL != socket->open_cb)
1315 socket->open_cb (socket->open_cls, socket); 1316 socket->open_cb (socket->open_cls, socket);
1316} 1317}
1317 1318
@@ -1404,6 +1405,7 @@ set_state_closed (void *cls,
1404 socket->state = STATE_CLOSED; 1405 socket->state = STATE_CLOSED;
1405} 1406}
1406 1407
1408
1407/** 1409/**
1408 * Returns a new HelloAckMessage. Also sets the write sequence number for the 1410 * Returns a new HelloAckMessage. Also sets the write sequence number for the
1409 * socket 1411 * socket
@@ -3068,7 +3070,6 @@ GNUNET_STREAM_shutdown_cancel (struct GNUNET_STREAM_ShutdownHandle *handle)
3068 if (GNUNET_SCHEDULER_NO_TASK != handle->close_msg_retransmission_task_id) 3070 if (GNUNET_SCHEDULER_NO_TASK != handle->close_msg_retransmission_task_id)
3069 GNUNET_SCHEDULER_cancel (handle->close_msg_retransmission_task_id); 3071 GNUNET_SCHEDULER_cancel (handle->close_msg_retransmission_task_id);
3070 GNUNET_free (handle); 3072 GNUNET_free (handle);
3071 return;
3072} 3073}
3073 3074
3074 3075
@@ -3180,6 +3181,7 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
3180 enum GNUNET_STREAM_Option option; 3181 enum GNUNET_STREAM_Option option;
3181 va_list vargs; 3182 va_list vargs;
3182 3183
3184 GNUNET_assert (NULL != listen_cb);
3183 lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket)); 3185 lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket));
3184 lsocket->cfg = GNUNET_CONFIGURATION_dup (cfg); 3186 lsocket->cfg = GNUNET_CONFIGURATION_dup (cfg);
3185 lsocket->lockmanager = GNUNET_LOCKMANAGER_connect (lsocket->cfg); 3187 lsocket->lockmanager = GNUNET_LOCKMANAGER_connect (lsocket->cfg);
@@ -3376,7 +3378,6 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket,
3376} 3378}
3377 3379
3378 3380
3379
3380/** 3381/**
3381 * Tries to read data from the stream. 3382 * Tries to read data from the stream.
3382 * 3383 *
@@ -3479,7 +3480,6 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh)
3479 3480
3480 GNUNET_free (socket->write_handle); 3481 GNUNET_free (socket->write_handle);
3481 socket->write_handle = NULL; 3482 socket->write_handle = NULL;
3482 return;
3483} 3483}
3484 3484
3485 3485
@@ -3491,5 +3491,7 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh)
3491void 3491void
3492GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh) 3492GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh)
3493{ 3493{
3494 return; 3494 // FIXME: do stuff
3495} 3495}
3496
3497/* end of stream_api.c */
diff --git a/src/stream/test_stream_big.c b/src/stream/test_stream_big.c
index 2ddfaff80..03dec7c3d 100644
--- a/src/stream/test_stream_big.c
+++ b/src/stream/test_stream_big.c
@@ -29,7 +29,7 @@
29#include "platform.h" 29#include "platform.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_stream_lib.h" 31#include "gnunet_stream_lib.h"
32#include "gnunet_testing_lib.h" 32#include "gnunet_testing_lib-new.h"
33 33
34#define LOG(kind, ...) \ 34#define LOG(kind, ...) \
35 GNUNET_log (kind, __VA_ARGS__); 35 GNUNET_log (kind, __VA_ARGS__);
@@ -48,6 +48,8 @@ struct PeerData
48 */ 48 */
49 struct GNUNET_STREAM_Socket *socket; 49 struct GNUNET_STREAM_Socket *socket;
50 50
51 struct GNUNET_PeerIdentity self;
52
51 /** 53 /**
52 * Peer's io write handle 54 * Peer's io write handle
53 */ 55 */
@@ -69,11 +71,10 @@ struct PeerData
69 unsigned int bytes_read; 71 unsigned int bytes_read;
70}; 72};
71 73
72static struct GNUNET_OS_Process *arm_pid;
73static struct PeerData peer1; 74static struct PeerData peer1;
74static struct PeerData peer2; 75static struct PeerData peer2;
75static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket; 76static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
76static struct GNUNET_CONFIGURATION_Handle *config; 77static const struct GNUNET_CONFIGURATION_Handle *config;
77 78
78static GNUNET_SCHEDULER_TaskIdentifier abort_task; 79static GNUNET_SCHEDULER_TaskIdentifier abort_task;
79static GNUNET_SCHEDULER_TaskIdentifier test_task; 80static GNUNET_SCHEDULER_TaskIdentifier test_task;
@@ -100,16 +101,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
100 { 101 {
101 GNUNET_SCHEDULER_cancel (abort_task); 102 GNUNET_SCHEDULER_cancel (abort_task);
102 } 103 }
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
104 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
105 {
106 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
107 }
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n"); 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
109 /* Free the duplicated configuration */
110 GNUNET_CONFIGURATION_destroy (config);
111 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
112 GNUNET_OS_process_destroy (arm_pid);
113} 105}
114 106
115 107
@@ -340,14 +332,10 @@ static void
340stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 332stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
341{ 333{
342 struct PeerData *peer = cls; 334 struct PeerData *peer = cls;
343 struct GNUNET_PeerIdentity self;
344 335
345 GNUNET_assert (&peer1 == peer);
346 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
347 &self));
348 /* Connect to stream */ 336 /* Connect to stream */
349 peer->socket = GNUNET_STREAM_open (config, 337 peer->socket = GNUNET_STREAM_open (config,
350 &self, /* Null for local peer? */ 338 &peer2.self, /* Null for local peer? */
351 10, /* App port */ 339 10, /* App port */
352 &stream_open_cb, 340 &stream_open_cb,
353 &peer1, 341 &peer1,
@@ -357,87 +345,45 @@ stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
357 345
358 346
359/** 347/**
360 * Testing function 348 * Initialize framework and start test
361 * 349 *
362 * @param cls NULL 350 * @param cls closure
363 * @param tc the task context 351 * @param cfg configuration of the peer that was started
352 * @param peer identity of the peer that was created
364 */ 353 */
365static void 354static void
366test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 355run (void *cls,
356 const struct GNUNET_CONFIGURATION_Handle *cfg,
357 const struct GNUNET_TESTING_Peer *peer)
367{ 358{
368 struct GNUNET_PeerIdentity self; 359 struct GNUNET_PeerIdentity self;
369 360
370 test_task = GNUNET_SCHEDULER_NO_TASK; 361 GNUNET_TESTING_peer_get_identity (peer, &self);
371 /* Get our identity */ 362 config = cfg;
372 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config, 363 abort_task =
373 &self)); 364 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
374 365 (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
366 NULL);
375 peer2_listen_socket = GNUNET_STREAM_listen (config, 367 peer2_listen_socket = GNUNET_STREAM_listen (config,
376 10, /* App port */ 368 10, /* App port */
377 &stream_listen_cb, 369 &stream_listen_cb,
378 NULL, 370 NULL,
379 GNUNET_STREAM_OPTION_END); 371 GNUNET_STREAM_OPTION_END);
380 GNUNET_assert (NULL != peer2_listen_socket); 372 GNUNET_assert (NULL != peer2_listen_socket);
373 peer1.self = self;
374 peer2.self = self;
381 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1); 375 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1);
382} 376}
383 377
384
385/**
386 * Initialize framework and start test
387 */
388static void
389run (void *cls, char *const *args, const char *cfgfile,
390 const struct GNUNET_CONFIGURATION_Handle *cfg)
391{
392 /* Duplicate the configuration */
393 config = GNUNET_CONFIGURATION_dup (cfg);
394 arm_pid =
395 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
396 "gnunet-service-arm",
397#if VERBOSE_ARM
398 "-L", "DEBUG",
399#endif
400 "-c", "test_stream_local.conf", NULL);
401
402 abort_task =
403 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
404 (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
405 NULL);
406 test_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL);
407}
408
409/** 378/**
410 * Main function 379 * Main function
411 */ 380 */
412int main (int argc, char **argv) 381int main (int argc, char **argv)
413{ 382{
414 int ret; 383 if (0 != GNUNET_TESTING_service_run_restartable ("test-stream-big",
415 384 "arm",
416 char *const argv2[] = { "test-stream-big", 385 "test_stream_local.conf",
417 "-c", "test_stream_local.conf", 386 &run, NULL))
418 "-L", "DEBUG",
419 NULL
420 };
421
422 struct GNUNET_GETOPT_CommandLineOption options[] = {
423 GNUNET_GETOPT_OPTION_END
424 };
425
426 ret =
427 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
428 "test-stream-big", "nohelp", options, &run, NULL);
429
430 if (GNUNET_OK != ret)
431 {
432 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
433 ret);
434 return 1; 387 return 1;
435 } 388 return (GNUNET_SYSERR == result) ? 1 : 0;
436 if (GNUNET_SYSERR == result)
437 {
438 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
439 return 1;
440 }
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");
442 return 0;
443} 389}