diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-11 20:44:34 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-11 20:44:34 +0000 |
commit | e5d1a97cd8c30a54cadd158a81f72bc1f2166c4f (patch) | |
tree | cd57674f1ac473bef35e23bc53b7c925648483df /src/stream | |
parent | 0851edaa204fa2098e85e0ef5a9cd550ff65fac0 (diff) | |
download | gnunet-e5d1a97cd8c30a54cadd158a81f72bc1f2166c4f.tar.gz gnunet-e5d1a97cd8c30a54cadd158a81f72bc1f2166c4f.zip |
more scaffolding
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/perf_stream_api.c | 118 |
1 files changed, 117 insertions, 1 deletions
diff --git a/src/stream/perf_stream_api.c b/src/stream/perf_stream_api.c index 818bbd1b6..584e60e6a 100644 --- a/src/stream/perf_stream_api.c +++ b/src/stream/perf_stream_api.c | |||
@@ -41,7 +41,10 @@ | |||
41 | #include "platform.h" | 41 | #include "platform.h" |
42 | #include "gnunet_common.h" | 42 | #include "gnunet_common.h" |
43 | #include "gnunet_util_lib.h" | 43 | #include "gnunet_util_lib.h" |
44 | #include "gnunet_testing_lib.h" | ||
44 | #include "gnunet_testbed_service.h" | 45 | #include "gnunet_testbed_service.h" |
46 | #include "gnunet_stream_lib.h" | ||
47 | |||
45 | 48 | ||
46 | 49 | ||
47 | /** | 50 | /** |
@@ -86,11 +89,65 @@ enum TestStep | |||
86 | }; | 89 | }; |
87 | 90 | ||
88 | /** | 91 | /** |
92 | * Structure for holding peer's sockets and IO Handles | ||
93 | */ | ||
94 | struct PeerData | ||
95 | { | ||
96 | /** | ||
97 | * Peer's stream socket | ||
98 | */ | ||
99 | struct GNUNET_STREAM_Socket *socket; | ||
100 | |||
101 | struct GNUNET_PeerIdentity self; | ||
102 | |||
103 | /** | ||
104 | * Peer's io write handle | ||
105 | */ | ||
106 | struct GNUNET_STREAM_IOWriteHandle *io_write_handle; | ||
107 | |||
108 | /** | ||
109 | * Peer's io read handle | ||
110 | */ | ||
111 | struct GNUNET_STREAM_IOReadHandle *io_read_handle; | ||
112 | |||
113 | /** | ||
114 | * Bytes the peer has written | ||
115 | */ | ||
116 | unsigned int bytes_wrote; | ||
117 | |||
118 | /** | ||
119 | * Byte the peer has read | ||
120 | */ | ||
121 | unsigned int bytes_read; | ||
122 | }; | ||
123 | |||
124 | |||
125 | /** | ||
89 | * Maximum size of the data which we will transfer during tests | 126 | * Maximum size of the data which we will transfer during tests |
90 | */ | 127 | */ |
91 | #define DATA_SIZE 65536 /* 64KB */ | 128 | #define DATA_SIZE 65536 /* 64KB */ |
92 | 129 | ||
93 | /** | 130 | /** |
131 | * Listen socket of peer2 | ||
132 | */ | ||
133 | struct GNUNET_STREAM_ListenSocket *peer2_listen_socket; | ||
134 | |||
135 | /** | ||
136 | * Handle to configuration during TEST_STEP_1_HOP | ||
137 | */ | ||
138 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
139 | |||
140 | /** | ||
141 | * Placeholder for peer data | ||
142 | */ | ||
143 | static struct PeerData peer_data[3]; | ||
144 | |||
145 | /** | ||
146 | * Task ID for abort task | ||
147 | */ | ||
148 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
149 | |||
150 | /** | ||
94 | * Random data block. Should generate data first | 151 | * Random data block. Should generate data first |
95 | */ | 152 | */ |
96 | static uint32_t data[DATA_SIZE / 4]; /* 64KB array */ | 153 | static uint32_t data[DATA_SIZE / 4]; /* 64KB array */ |
@@ -220,6 +277,45 @@ free_meter (struct ProgressMeter *meter) | |||
220 | 277 | ||
221 | 278 | ||
222 | /** | 279 | /** |
280 | * Something went wrong and timed out. Kill everything and set error flag | ||
281 | */ | ||
282 | static void | ||
283 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
284 | { | ||
285 | GNUNET_break (0); | ||
286 | } | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Functions of this type are called upon new stream connection from other peers | ||
291 | * | ||
292 | * @param cls the closure from GNUNET_STREAM_listen | ||
293 | * @param socket the socket representing the stream | ||
294 | * @param initiator the identity of the peer who wants to establish a stream | ||
295 | * with us | ||
296 | * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the | ||
297 | * stream (the socket will be invalid after the call) | ||
298 | */ | ||
299 | static int | ||
300 | stream_listen_cb (void *cls, struct GNUNET_STREAM_Socket *socket, | ||
301 | const struct GNUNET_PeerIdentity *initiator) | ||
302 | { | ||
303 | GNUNET_break (0); | ||
304 | return GNUNET_OK; | ||
305 | } | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Listen success callback; connects a peer to stream as client | ||
310 | */ | ||
311 | static void | ||
312 | stream_connect (void) | ||
313 | { | ||
314 | GNUNET_break (0); | ||
315 | } | ||
316 | |||
317 | |||
318 | /** | ||
223 | * Initialize framework and start test | 319 | * Initialize framework and start test |
224 | * | 320 | * |
225 | * @param cls closure | 321 | * @param cls closure |
@@ -231,7 +327,21 @@ run (void *cls, | |||
231 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 327 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
232 | struct GNUNET_TESTING_Peer *peer) | 328 | struct GNUNET_TESTING_Peer *peer) |
233 | { | 329 | { |
234 | GNUNET_break (0); | 330 | struct GNUNET_PeerIdentity self; |
331 | |||
332 | GNUNET_TESTING_peer_get_identity (peer, &self); | ||
333 | config = cfg; | ||
334 | peer2_listen_socket = | ||
335 | GNUNET_STREAM_listen (config, 10, /* App port */ &stream_listen_cb, NULL, | ||
336 | GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, | ||
337 | &stream_connect, GNUNET_STREAM_OPTION_END); | ||
338 | GNUNET_assert (NULL != peer2_listen_socket); | ||
339 | peer_data[1].self = self; | ||
340 | peer_data[2].self = self; | ||
341 | abort_task = | ||
342 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
343 | (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort, | ||
344 | NULL); | ||
235 | } | 345 | } |
236 | 346 | ||
237 | 347 | ||
@@ -240,6 +350,7 @@ run (void *cls, | |||
240 | */ | 350 | */ |
241 | int main (int argc, char **argv) | 351 | int main (int argc, char **argv) |
242 | { | 352 | { |
353 | char *pmsg; | ||
243 | unsigned int count; | 354 | unsigned int count; |
244 | int ret; | 355 | int ret; |
245 | 356 | ||
@@ -257,8 +368,13 @@ int main (int argc, char **argv) | |||
257 | payload_size_index < (sizeof (payload_size) / sizeof (uint16_t)); | 368 | payload_size_index < (sizeof (payload_size) / sizeof (uint16_t)); |
258 | payload_size_index++) | 369 | payload_size_index++) |
259 | { | 370 | { |
371 | GNUNET_asprintf (&pmsg, "Testing over loopback with payload size %hu\n", | ||
372 | payload_size[payload_size_index]); | ||
373 | meter = create_meter ((sizeof (data) / 4), pmsg, GNUNET_YES); | ||
374 | GNUNET_free (pmsg); | ||
260 | ret = GNUNET_TESTING_peer_run ("test_stream_big", "test_stream_local.conf", | 375 | ret = GNUNET_TESTING_peer_run ("test_stream_big", "test_stream_local.conf", |
261 | &run, NULL); | 376 | &run, NULL); |
377 | free_meter (meter); | ||
262 | if (0 != ret) | 378 | if (0 != ret) |
263 | break; | 379 | break; |
264 | } | 380 | } |