summaryrefslogtreecommitdiff
path: root/src/core/test_core_api_reliability.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-11-14 13:37:09 +0000
committerChristian Grothoff <christian@grothoff.org>2010-11-14 13:37:09 +0000
commit65cc198f1c0343322d3d9721d62ee10b5ea6fdb7 (patch)
treeeb9407fbdd34b4d28052ba908a98bf713856b8c9 /src/core/test_core_api_reliability.c
parentd1c3036fd48f2645fab427df4a47d3bc69410d15 (diff)
downloadgnunet-65cc198f1c0343322d3d9721d62ee10b5ea6fdb7.tar.gz
gnunet-65cc198f1c0343322d3d9721d62ee10b5ea6fdb7.zip
fix
Diffstat (limited to 'src/core/test_core_api_reliability.c')
-rw-r--r--src/core/test_core_api_reliability.c180
1 files changed, 96 insertions, 84 deletions
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 14b69b80e..9192c9592 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -65,6 +65,9 @@ static unsigned long long total_bytes;
65 65
66static struct GNUNET_TIME_Absolute start_time; 66static struct GNUNET_TIME_Absolute start_time;
67 67
68static GNUNET_SCHEDULER_TaskIdentifier err_task;
69
70
68struct PeerContext 71struct PeerContext
69{ 72{
70 struct GNUNET_CONFIGURATION_Handle *cfg; 73 struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -84,6 +87,9 @@ static struct PeerContext p2;
84 87
85static int ok; 88static int ok;
86 89
90static int32_t tr_n;
91
92
87#if VERBOSE 93#if VERBOSE
88#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 94#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
89#else 95#else
@@ -145,17 +151,99 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
145} 151}
146 152
147 153
154static size_t
155transmit_ready (void *cls, size_t size, void *buf)
156{
157 char *cbuf = buf;
158 struct TestMessage hdr;
159 unsigned int s;
160 unsigned int ret;
161
162 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
163 if (buf == NULL)
164 {
165 if (p1.ch != NULL)
166 GNUNET_break (NULL !=
167 GNUNET_CORE_notify_transmit_ready (p1.ch,
168 0,
169 FAST_TIMEOUT,
170 &p2.id,
171 get_size(tr_n),
172 &transmit_ready, &p1));
173 return 0;
174 }
175 GNUNET_assert (tr_n < TOTAL_MSGS);
176 ret = 0;
177 s = get_size (tr_n);
178 GNUNET_assert (size >= s);
179 GNUNET_assert (buf != NULL);
180 cbuf = buf;
181 do
182 {
183#if VERBOSE
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 "Sending message %u of size %u at offset %u\n",
186 tr_n,
187 s,
188 ret);
189#endif
190 hdr.header.size = htons (s);
191 hdr.header.type = htons (MTYPE);
192 hdr.num = htonl (tr_n);
193 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
194 ret += sizeof (struct TestMessage);
195 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
196 ret += s - sizeof (struct TestMessage);
197 tr_n++;
198 s = get_size (tr_n);
199 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
200 break; /* sometimes pack buffer full, sometimes not */
201 }
202 while (size - ret >= s);
203 GNUNET_SCHEDULER_cancel (err_task);
204 err_task =
205 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
206 &terminate_task_error,
207 NULL);
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "Returning total message block of size %u\n",
210 ret);
211 total_bytes += ret;
212 return ret;
213}
214
215
216
148static void 217static void
149connect_notify (void *cls, 218connect_notify (void *cls,
150 const struct GNUNET_PeerIdentity *peer, 219 const struct GNUNET_PeerIdentity *peer,
151 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 220 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
152{ 221{
153 struct PeerContext *pc = cls; 222 struct PeerContext *pc = cls;
223
154 GNUNET_assert (pc->connect_status == 0); 224 GNUNET_assert (pc->connect_status == 0);
155 pc->connect_status = 1; 225 pc->connect_status = 1;
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 226 if (pc == &p1)
157 "Encrypted connection established to peer `%4s'\n", 227 {
158 GNUNET_i2s (peer)); 228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
229 "Encrypted connection established to peer `%4s'\n",
230 GNUNET_i2s (peer));
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
232 "Asking core (1) for transmission to peer `%4s'\n",
233 GNUNET_i2s (&p2.id));
234 err_task =
235 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
236 &terminate_task_error,
237 NULL);
238 start_time = GNUNET_TIME_absolute_get ();
239 GNUNET_break (NULL !=
240 GNUNET_CORE_notify_transmit_ready (p1.ch,
241 0,
242 TIMEOUT,
243 &p2.id,
244 get_size (0),
245 &transmit_ready, &p1));
246 }
159} 247}
160 248
161 249
@@ -199,15 +287,9 @@ outbound_notify (void *cls,
199} 287}
200 288
201 289
202static GNUNET_SCHEDULER_TaskIdentifier err_task;
203
204
205static size_t 290static size_t
206transmit_ready (void *cls, size_t size, void *buf); 291transmit_ready (void *cls, size_t size, void *buf);
207 292
208static int tr_n;
209
210
211static int 293static int
212process_mtype (void *cls, 294process_mtype (void *cls,
213 const struct GNUNET_PeerIdentity *peer, 295 const struct GNUNET_PeerIdentity *peer,
@@ -279,68 +361,6 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
279}; 361};
280 362
281 363
282static size_t
283transmit_ready (void *cls, size_t size, void *buf)
284{
285 char *cbuf = buf;
286 struct TestMessage hdr;
287 unsigned int s;
288 unsigned int ret;
289
290 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
291 if (buf == NULL)
292 {
293 if (p1.ch != NULL)
294 GNUNET_break (NULL !=
295 GNUNET_CORE_notify_transmit_ready (p1.ch,
296 0,
297 FAST_TIMEOUT,
298 &p2.id,
299 get_size(tr_n),
300 &transmit_ready, &p1));
301 return 0;
302 }
303 GNUNET_assert (tr_n < TOTAL_MSGS);
304 ret = 0;
305 s = get_size (tr_n);
306 GNUNET_assert (size >= s);
307 GNUNET_assert (buf != NULL);
308 cbuf = buf;
309 do
310 {
311#if VERBOSE
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Sending message %u of size %u at offset %u\n",
314 tr_n,
315 s,
316 ret);
317#endif
318 hdr.header.size = htons (s);
319 hdr.header.type = htons (MTYPE);
320 hdr.num = htonl (tr_n);
321 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
322 ret += sizeof (struct TestMessage);
323 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
324 ret += s - sizeof (struct TestMessage);
325 tr_n++;
326 s = get_size (tr_n);
327 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
328 break; /* sometimes pack buffer full, sometimes not */
329 }
330 while (size - ret >= s);
331 GNUNET_SCHEDULER_cancel (err_task);
332 err_task =
333 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
334 &terminate_task_error,
335 NULL);
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "Returning total message block of size %u\n",
338 ret);
339 total_bytes += ret;
340 return ret;
341}
342
343
344 364
345static void 365static void
346init_notify (void *cls, 366init_notify (void *cls,
@@ -377,20 +397,12 @@ init_notify (void *cls,
377 OKPP; 397 OKPP;
378 GNUNET_assert (cls == &p2); 398 GNUNET_assert (cls == &p2);
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Asking core (1) for transmission to peer `%4s'\n", 400 "Asking core (1) to connect to peer `%4s'\n",
381 GNUNET_i2s (&p2.id)); 401 GNUNET_i2s (&p2.id));
382 err_task = 402 GNUNET_CORE_peer_request_connect (p1.ch,
383 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 403 GNUNET_TIME_UNIT_SECONDS,
384 &terminate_task_error, 404 &p2.id,
385 NULL); 405 NULL, NULL);
386 start_time = GNUNET_TIME_absolute_get ();
387 GNUNET_break (NULL !=
388 GNUNET_CORE_notify_transmit_ready (p1.ch,
389 0,
390 TIMEOUT,
391 &p2.id,
392 get_size (0),
393 &transmit_ready, &p1));
394 } 406 }
395} 407}
396 408