aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_quota_compliance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r--src/core/test_core_quota_compliance.c551
1 files changed, 267 insertions, 284 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 03a7c62eb..5dcc20597 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -77,7 +77,7 @@ struct PeerContext
77{ 77{
78 struct GNUNET_CONFIGURATION_Handle *cfg; 78 struct GNUNET_CONFIGURATION_Handle *cfg;
79 struct GNUNET_CORE_Handle *ch; 79 struct GNUNET_CORE_Handle *ch;
80 struct GNUNET_PeerIdentity id; 80 struct GNUNET_PeerIdentity id;
81 struct GNUNET_TRANSPORT_Handle *th; 81 struct GNUNET_TRANSPORT_Handle *th;
82 struct GNUNET_MessageHeader *hello; 82 struct GNUNET_MessageHeader *hello;
83 struct GNUNET_STATISTICS_Handle *stats; 83 struct GNUNET_STATISTICS_Handle *stats;
@@ -108,13 +108,14 @@ static int running;
108#define OKPP do { ok++; } while (0) 108#define OKPP do { ok++; } while (0)
109#endif 109#endif
110 110
111struct TestMessage 111struct TestMessage
112{ 112{
113 struct GNUNET_MessageHeader header; 113 struct GNUNET_MessageHeader header;
114 uint32_t num; 114 uint32_t num;
115}; 115};
116 116
117static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); 117static void process_hello (void *cls,
118 const struct GNUNET_MessageHeader *message);
118 119
119static void 120static void
120terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 121terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -140,11 +141,11 @@ static void
140terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 141terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
141{ 142{
142 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 143 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n");
144 //GNUNET_break (0); 145 //GNUNET_break (0);
145 146
146 if (measure_task != GNUNET_SCHEDULER_NO_TASK) 147 if (measure_task != GNUNET_SCHEDULER_NO_TASK)
147 GNUNET_SCHEDULER_cancel(measure_task); 148 GNUNET_SCHEDULER_cancel (measure_task);
148 149
149 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); 150 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
150 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); 151 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
@@ -173,21 +174,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 */ 174 */
174static int 175static int
175print_stat (void *cls, 176print_stat (void *cls,
176 const char *subsystem, 177 const char *subsystem,
177 const char *name, 178 const char *name, uint64_t value, int is_persistent)
178 uint64_t value,
179 int is_persistent)
180{ 179{
181 if (cls==&p1) 180 if (cls == &p1)
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
183 "Peer1 %50s = %12llu\n", 182 "Peer1 %50s = %12llu\n", name, (unsigned long long) value);
184 name, 183 if (cls == &p2)
185 (unsigned long long) value); 184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 if (cls==&p2) 185 "Peer2 %50s = %12llu\n", name, (unsigned long long) value);
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "Peer2 %50s = %12llu\n",
189 name,
190 (unsigned long long) value);
191 return GNUNET_OK; 186 return GNUNET_OK;
192} 187}
193 188
@@ -202,7 +197,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
202 unsigned long long int quota_delta; 197 unsigned long long int quota_delta;
203 198
204 measure_task = GNUNET_SCHEDULER_NO_TASK; 199 measure_task = GNUNET_SCHEDULER_NO_TASK;
205 fprintf(stdout,"\n"); 200 fprintf (stdout, "\n");
206 running = GNUNET_NO; 201 running = GNUNET_NO;
207 202
208 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 203 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
@@ -211,96 +206,91 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
211 throughput_in = total_bytes_recv * 1000 / 1024 / delta; 206 throughput_in = total_bytes_recv * 1000 / 1024 / delta;
212 207
213 if (current_quota_p1_in < current_quota_p2_in) 208 if (current_quota_p1_in < current_quota_p2_in)
214 max_quota_in = current_quota_p1_in; 209 max_quota_in = current_quota_p1_in;
215 else 210 else
216 max_quota_in = current_quota_p2_in; 211 max_quota_in = current_quota_p2_in;
217 if (current_quota_p1_out < current_quota_p2_out) 212 if (current_quota_p1_out < current_quota_p2_out)
218 max_quota_out = current_quota_p1_out; 213 max_quota_out = current_quota_p1_out;
219 else 214 else
220 max_quota_out = current_quota_p2_out; 215 max_quota_out = current_quota_p2_out;
221 216
222 if (max_quota_out < max_quota_in) 217 if (max_quota_out < max_quota_in)
223 quota_delta = max_quota_in / 10; 218 quota_delta = max_quota_in / 10;
224 else 219 else
225 quota_delta = max_quota_out / 10; 220 quota_delta = max_quota_out / 10;
226 221
227 if ((throughput_out > (max_quota_out+quota_delta)/1024) || (throughput_in > (max_quota_in+quota_delta)/1024)) 222 if ((throughput_out > (max_quota_out + quota_delta) / 1024) ||
228 ok = 1; 223 (throughput_in > (max_quota_in + quota_delta) / 1024))
224 ok = 1;
229 else 225 else
230 ok = 0; 226 ok = 0;
231 227
232 GNUNET_STATISTICS_get (p1.stats, 228 GNUNET_STATISTICS_get (p1.stats,
233 "core", 229 "core",
234 "# discarded CORE_SEND requests", 230 "# discarded CORE_SEND requests",
235 GNUNET_TIME_UNIT_FOREVER_REL, 231 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
236 NULL,
237 &print_stat, &p1);
238 232
239 GNUNET_STATISTICS_get (p1.stats, 233 GNUNET_STATISTICS_get (p1.stats,
240 "core", 234 "core",
241 "# discarded CORE_SEND request bytes", 235 "# discarded CORE_SEND request bytes",
242 GNUNET_TIME_UNIT_FOREVER_REL, 236 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
243 NULL,
244 &print_stat, &p1);
245 GNUNET_STATISTICS_get (p1.stats, 237 GNUNET_STATISTICS_get (p1.stats,
246 "core", 238 "core",
247 "# discarded lower priority CORE_SEND requests", 239 "# discarded lower priority CORE_SEND requests",
248 GNUNET_TIME_UNIT_FOREVER_REL, 240 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL);
249 NULL,
250 &print_stat, NULL);
251 GNUNET_STATISTICS_get (p1.stats, 241 GNUNET_STATISTICS_get (p1.stats,
252 "core", 242 "core",
253 "# discarded lower priority CORE_SEND request bytes", 243 "# discarded lower priority CORE_SEND request bytes",
254 GNUNET_TIME_UNIT_FOREVER_REL, 244 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
255 NULL,
256 &print_stat, &p1);
257 GNUNET_STATISTICS_get (p2.stats, 245 GNUNET_STATISTICS_get (p2.stats,
258 "core", 246 "core",
259 "# discarded CORE_SEND requests", 247 "# discarded CORE_SEND requests",
260 GNUNET_TIME_UNIT_FOREVER_REL, 248 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
261 NULL,
262 &print_stat, &p2);
263 249
264 GNUNET_STATISTICS_get (p2.stats, 250 GNUNET_STATISTICS_get (p2.stats,
265 "core", 251 "core",
266 "# discarded CORE_SEND request bytes", 252 "# discarded CORE_SEND request bytes",
267 GNUNET_TIME_UNIT_FOREVER_REL, 253 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
268 NULL,
269 &print_stat, &p2);
270 GNUNET_STATISTICS_get (p2.stats, 254 GNUNET_STATISTICS_get (p2.stats,
271 "core", 255 "core",
272 "# discarded lower priority CORE_SEND requests", 256 "# discarded lower priority CORE_SEND requests",
273 GNUNET_TIME_UNIT_FOREVER_REL, 257 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
274 NULL,
275 &print_stat, &p2);
276 GNUNET_STATISTICS_get (p2.stats, 258 GNUNET_STATISTICS_get (p2.stats,
277 "core", 259 "core",
278 "# discarded lower priority CORE_SEND request bytes", 260 "# discarded lower priority CORE_SEND request bytes",
279 GNUNET_TIME_UNIT_FOREVER_REL, 261 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
280 NULL,
281 &print_stat, &p2);
282 262
283 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; 263 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
284 if (ok==1) 264
265 if (ok == 1)
285 { 266 {
286 kind = GNUNET_ERROR_TYPE_ERROR; 267 kind = GNUNET_ERROR_TYPE_ERROR;
287 } 268 }
288 switch (test) 269 switch (test)
289 { 270 {
290 case SYMMETRIC: 271 case SYMMETRIC:
291 GNUNET_log (kind,"Core quota compliance test with symmetric quotas: %s\n", (ok==0)?"PASSED":"FAILED"); 272 GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n",
292 break; 273 (ok == 0) ? "PASSED" : "FAILED");
274 break;
293 case ASYMMETRIC_SEND_LIMITED: 275 case ASYMMETRIC_SEND_LIMITED:
294 GNUNET_log (kind,"Core quota compliance test with limited sender quota: %s\n", (ok==0)?"PASSED":"FAILED"); 276 GNUNET_log (kind,
295 break; 277 "Core quota compliance test with limited sender quota: %s\n",
278 (ok == 0) ? "PASSED" : "FAILED");
279 break;
296 case ASYMMETRIC_RECV_LIMITED: 280 case ASYMMETRIC_RECV_LIMITED:
297 GNUNET_log (kind,"Core quota compliance test with limited receiver quota: %s\n", (ok==0)?"PASSED":"FAILED"); 281 GNUNET_log (kind,
298 break; 282 "Core quota compliance test with limited receiver quota: %s\n",
283 (ok == 0) ? "PASSED" : "FAILED");
284 break;
299 }; 285 };
300 GNUNET_log (kind,"Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000); 286 GNUNET_log (kind, "Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",
301 GNUNET_log (kind,"Peer 1 send quota: %llu kB/s\n",current_quota_p1_out / 1024); 287 throughput_out, total_bytes_sent, delta / 1000);
302 GNUNET_log (kind,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000); 288 GNUNET_log (kind, "Peer 1 send quota: %llu kB/s\n",
303 GNUNET_log (kind,"Peer 2 receive quota: %llu kB/s\n",current_quota_p2_in / 1024); 289 current_quota_p1_out / 1024);
290 GNUNET_log (kind, "Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",
291 throughput_in, total_bytes_recv, delta / 1000);
292 GNUNET_log (kind, "Peer 2 receive quota: %llu kB/s\n",
293 current_quota_p2_in / 1024);
304/* 294/*
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024); 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024);
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024);
@@ -319,49 +309,45 @@ transmit_ready (void *cls, size_t size, void *buf)
319 309
320 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 310 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
321 if (buf == NULL) 311 if (buf == NULL)
322 { 312 {
323 if ( (p1.ch != NULL) && 313 if ((p1.ch != NULL) && (p1.connect_status == 1))
324 (p1.connect_status == 1) ) 314 GNUNET_break (NULL !=
325 GNUNET_break (NULL != 315 GNUNET_CORE_notify_transmit_ready (p1.ch,
326 GNUNET_CORE_notify_transmit_ready (p1.ch, 316 GNUNET_NO,
327 GNUNET_NO, 317 0,
328 0, 318 FAST_TIMEOUT,
329 FAST_TIMEOUT, 319 &p2.id,
330 &p2.id, 320 MESSAGESIZE,
331 MESSAGESIZE, 321 &transmit_ready, &p1));
332 &transmit_ready, &p1)); 322 return 0;
333 return 0; 323 }
334 }
335 GNUNET_assert (tr_n < TOTAL_MSGS); 324 GNUNET_assert (tr_n < TOTAL_MSGS);
336 ret = 0; 325 ret = 0;
337 GNUNET_assert (size >= MESSAGESIZE); 326 GNUNET_assert (size >= MESSAGESIZE);
338 GNUNET_assert (buf != NULL); 327 GNUNET_assert (buf != NULL);
339 cbuf = buf; 328 cbuf = buf;
340 do 329 do
341 { 330 {
342#if DEBUG_TRANSMISSION 331#if DEBUG_TRANSMISSION
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Sending message %u of size %u at offset %u\n", 333 "Sending message %u of size %u at offset %u\n",
345 tr_n, 334 tr_n, MESSAGESIZE, ret);
346 MESSAGESIZE,
347 ret);
348#endif 335#endif
349 hdr.header.size = htons (MESSAGESIZE); 336 hdr.header.size = htons (MESSAGESIZE);
350 hdr.header.type = htons (MTYPE); 337 hdr.header.type = htons (MTYPE);
351 hdr.num = htonl (tr_n); 338 hdr.num = htonl (tr_n);
352 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); 339 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
353 ret += sizeof (struct TestMessage); 340 ret += sizeof (struct TestMessage);
354 memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage)); 341 memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage));
355 ret += MESSAGESIZE - sizeof (struct TestMessage); 342 ret += MESSAGESIZE - sizeof (struct TestMessage);
356 tr_n++; 343 tr_n++;
357 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) 344 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
358 break; /* sometimes pack buffer full, sometimes not */ 345 break; /* sometimes pack buffer full, sometimes not */
359 } 346 }
360 while (size - ret >= MESSAGESIZE); 347 while (size - ret >= MESSAGESIZE);
361 GNUNET_SCHEDULER_cancel (err_task); 348 GNUNET_SCHEDULER_cancel (err_task);
362 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 349 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
363 &terminate_task_error, 350 &terminate_task_error, NULL);
364 NULL);
365 351
366 total_bytes_sent += ret; 352 total_bytes_sent += ret;
367 return ret; 353 return ret;
@@ -376,50 +362,48 @@ connect_notify (void *cls,
376{ 362{
377 struct PeerContext *pc = cls; 363 struct PeerContext *pc = cls;
378 364
379 if (0 == memcmp (&pc->id, 365 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
380 peer,
381 sizeof (struct GNUNET_PeerIdentity)))
382 return; 366 return;
383 GNUNET_assert (pc->connect_status == 0); 367 GNUNET_assert (pc->connect_status == 0);
384 pc->connect_status = 1; 368 pc->connect_status = 1;
385 if (pc == &p1) 369 if (pc == &p1)
386 { 370 {
387#if DEBUG_TRANSMISSION 371#if DEBUG_TRANSMISSION
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Encrypted connection established to peer `%4s'\n", 373 "Encrypted connection established to peer `%4s'\n",
390 GNUNET_i2s (peer)); 374 GNUNET_i2s (peer));
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Asking core (1) for transmission to peer `%4s'\n", 376 "Asking core (1) for transmission to peer `%4s'\n",
393 GNUNET_i2s (&p2.id)); 377 GNUNET_i2s (&p2.id));
394#endif 378#endif
395 if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (err_task); 379 if (err_task != GNUNET_SCHEDULER_NO_TASK)
396 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 380 GNUNET_SCHEDULER_cancel (err_task);
397 &terminate_task_error, 381 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
398 NULL); 382 &terminate_task_error, NULL);
399 start_time = GNUNET_TIME_absolute_get (); 383 start_time = GNUNET_TIME_absolute_get ();
400 running = GNUNET_YES; 384 running = GNUNET_YES;
401 measure_task = GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH, &measurement_stop, NULL); 385 measure_task =
402 386 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
403 GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch, 387 NULL);
404 GNUNET_NO, 388
405 0, 389 GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch,
406 TIMEOUT, 390 GNUNET_NO,
407 &p2.id, 391 0,
408 MESSAGESIZE, 392 TIMEOUT,
409 &transmit_ready, &p1)); 393 &p2.id,
410 } 394 MESSAGESIZE,
395 &transmit_ready,
396 &p1));
397 }
411} 398}
412 399
413 400
414static void 401static void
415disconnect_notify (void *cls, 402disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
416 const struct GNUNET_PeerIdentity *peer)
417{ 403{
418 struct PeerContext *pc = cls; 404 struct PeerContext *pc = cls;
419 405
420 if (0 == memcmp (&pc->id, 406 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
421 peer,
422 sizeof (struct GNUNET_PeerIdentity)))
423 return; 407 return;
424 pc->connect_status = 0; 408 pc->connect_status = 0;
425#if DEBUG_TRANSMISSION 409#if DEBUG_TRANSMISSION
@@ -433,13 +417,14 @@ static int
433inbound_notify (void *cls, 417inbound_notify (void *cls,
434 const struct GNUNET_PeerIdentity *other, 418 const struct GNUNET_PeerIdentity *other,
435 const struct GNUNET_MessageHeader *message, 419 const struct GNUNET_MessageHeader *message,
436 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 420 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
437{ 421{
438#if DEBUG_TRANSMISSION 422#if DEBUG_TRANSMISSION
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Core provides inbound data from `%4s' %llu.\n", GNUNET_i2s (other), ntohs(message->size)); 424 "Core provides inbound data from `%4s' %llu.\n",
425 GNUNET_i2s (other), ntohs (message->size));
441#endif 426#endif
442 total_bytes_recv += ntohs(message->size); 427 total_bytes_recv += ntohs (message->size);
443 return GNUNET_OK; 428 return GNUNET_OK;
444} 429}
445 430
@@ -448,7 +433,7 @@ static int
448outbound_notify (void *cls, 433outbound_notify (void *cls,
449 const struct GNUNET_PeerIdentity *other, 434 const struct GNUNET_PeerIdentity *other,
450 const struct GNUNET_MessageHeader *message, 435 const struct GNUNET_MessageHeader *message,
451 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 436 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
452{ 437{
453#if DEBUG_TRANSMISSION 438#if DEBUG_TRANSMISSION
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -459,48 +444,42 @@ outbound_notify (void *cls,
459} 444}
460 445
461 446
462static size_t 447static size_t transmit_ready (void *cls, size_t size, void *buf);
463transmit_ready (void *cls, size_t size, void *buf);
464 448
465static int 449static int
466process_mtype (void *cls, 450process_mtype (void *cls,
467 const struct GNUNET_PeerIdentity *peer, 451 const struct GNUNET_PeerIdentity *peer,
468 const struct GNUNET_MessageHeader *message, 452 const struct GNUNET_MessageHeader *message,
469 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 453 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
470{ 454{
471 static int n; 455 static int n;
472 const struct TestMessage *hdr; 456 const struct TestMessage *hdr;
473 457
474 hdr = (const struct TestMessage*) message; 458 hdr = (const struct TestMessage *) message;
475 if (MTYPE != ntohs (message->type)) 459 if (MTYPE != ntohs (message->type))
476 return GNUNET_SYSERR; 460 return GNUNET_SYSERR;
477 if (ntohs (message->size) != MESSAGESIZE) 461 if (ntohs (message->size) != MESSAGESIZE)
478 { 462 {
479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
480 "Expected message %u of size %u, got %u bytes of message %u\n", 464 "Expected message %u of size %u, got %u bytes of message %u\n",
481 n, MESSAGESIZE, 465 n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
482 ntohs (message->size), 466 GNUNET_SCHEDULER_cancel (err_task);
483 ntohl (hdr->num)); 467 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
484 GNUNET_SCHEDULER_cancel (err_task); 468 return GNUNET_SYSERR;
485 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); 469 }
486 return GNUNET_SYSERR;
487 }
488 if (ntohl (hdr->num) != n) 470 if (ntohl (hdr->num) != n)
489 { 471 {
490 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 472 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
491 "Expected message %u of size %u, got %u bytes of message %u\n", 473 "Expected message %u of size %u, got %u bytes of message %u\n",
492 n, MESSAGESIZE, 474 n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
493 ntohs (message->size), 475 GNUNET_SCHEDULER_cancel (err_task);
494 ntohl (hdr->num)); 476 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
495 GNUNET_SCHEDULER_cancel (err_task); 477 return GNUNET_SYSERR;
496 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); 478 }
497 return GNUNET_SYSERR;
498 }
499#if DEBUG_TRANSMISSION 479#if DEBUG_TRANSMISSION
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 "Got message %u of size %u\n", 481 "Got message %u of size %u\n",
502 ntohl (hdr->num), 482 ntohl (hdr->num), ntohs (message->size));
503 ntohs (message->size));
504#endif 483#endif
505 n++; 484 n++;
506 if (0 == (n % 10)) 485 if (0 == (n % 10))
@@ -508,14 +487,14 @@ process_mtype (void *cls,
508 487
509 488
510 if (running == GNUNET_YES) 489 if (running == GNUNET_YES)
511 GNUNET_break (NULL != 490 GNUNET_break (NULL !=
512 GNUNET_CORE_notify_transmit_ready (p1.ch, 491 GNUNET_CORE_notify_transmit_ready (p1.ch,
513 GNUNET_NO, 492 GNUNET_NO,
514 0, 493 0,
515 FAST_TIMEOUT, 494 FAST_TIMEOUT,
516 &p2.id, 495 &p2.id,
517 MESSAGESIZE, 496 MESSAGESIZE,
518 &transmit_ready, &p1)); 497 &transmit_ready, &p1));
519 return GNUNET_OK; 498 return GNUNET_OK;
520} 499}
521 500
@@ -542,48 +521,43 @@ init_notify (void *cls,
542 p->id = *my_identity; 521 p->id = *my_identity;
543 p->ch = server; 522 p->ch = server;
544 if (cls == &p1) 523 if (cls == &p1)
545 { 524 {
546 GNUNET_assert (ok == 2); 525 GNUNET_assert (ok == 2);
547 OKPP; 526 OKPP;
548 /* connect p2 */ 527 /* connect p2 */
549 GNUNET_CORE_connect (p2.cfg, 1, 528 GNUNET_CORE_connect (p2.cfg, 1,
550 &p2, 529 &p2,
551 &init_notify, 530 &init_notify,
552 &connect_notify, 531 &connect_notify,
553 &disconnect_notify, 532 &disconnect_notify,
554 NULL, 533 NULL,
555 &inbound_notify, 534 &inbound_notify,
556 GNUNET_YES, 535 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
557 &outbound_notify, GNUNET_YES, handlers); 536 }
558 }
559 else 537 else
560 { 538 {
561 GNUNET_assert (ok == 3); 539 GNUNET_assert (ok == 3);
562 OKPP; 540 OKPP;
563 GNUNET_assert (cls == &p2); 541 GNUNET_assert (cls == &p2);
564#if DEBUG_TRANSMISSION 542#if DEBUG_TRANSMISSION
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Asking core (1) to connect to peer `%4s'\n", 544 "Asking core (1) to connect to peer `%4s'\n",
567 GNUNET_i2s (&p2.id)); 545 GNUNET_i2s (&p2.id));
568#endif 546#endif
569 GNUNET_CORE_peer_request_connect (p1.ch, 547 GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
570 &p2.id, 548 }
571 NULL, NULL);
572 }
573} 549}
574 550
575 551
576static void 552static void
577process_hello (void *cls, 553process_hello (void *cls, const struct GNUNET_MessageHeader *message)
578 const struct GNUNET_MessageHeader *message)
579{ 554{
580 struct PeerContext *p = cls; 555 struct PeerContext *p = cls;
581 556
582 557
583#if DEBUG_TRANSMISSION 558#if DEBUG_TRANSMISSION
584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
585 "Received (my) `%s' from transport service\n", 560 "Received (my) `%s' from transport service\n", "HELLO");
586 "HELLO");
587#endif 561#endif
588 GNUNET_assert (message != NULL); 562 GNUNET_assert (message != NULL);
589 p->hello = GNUNET_malloc (ntohs (message->size)); 563 p->hello = GNUNET_malloc (ntohs (message->size));
@@ -607,15 +581,15 @@ setup_peer (struct PeerContext *p, const char *cfgname)
607 p->cfg = GNUNET_CONFIGURATION_create (); 581 p->cfg = GNUNET_CONFIGURATION_create ();
608#if START_ARM 582#if START_ARM
609 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 583 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
610 "gnunet-service-arm", 584 "gnunet-service-arm",
611#if VERBOSE 585#if VERBOSE
612 "-L", "DEBUG", 586 "-L", "DEBUG",
613#endif 587#endif
614 "-c", cfgname, NULL); 588 "-c", cfgname, NULL);
615#endif 589#endif
616 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 590 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
617 p->stats = GNUNET_STATISTICS_create ("core",p->cfg); 591 p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
618 GNUNET_assert (p->stats!=NULL); 592 GNUNET_assert (p->stats != NULL);
619 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 593 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
620 GNUNET_assert (p->th != NULL); 594 GNUNET_assert (p->th != NULL);
621 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 595 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
@@ -625,47 +599,45 @@ setup_peer (struct PeerContext *p, const char *cfgname)
625static void 599static void
626run (void *cls, 600run (void *cls,
627 char *const *args, 601 char *const *args,
628 const char *cfgfile, 602 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
629 const struct GNUNET_CONFIGURATION_Handle *cfg)
630{ 603{
631 GNUNET_assert (ok == 1); 604 GNUNET_assert (ok == 1);
632 OKPP; 605 OKPP;
633 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 606 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
634 &terminate_task_error, 607 &terminate_task_error, NULL);
635 NULL);
636 if (test == SYMMETRIC) 608 if (test == SYMMETRIC)
637 { 609 {
638 setup_peer (&p1, "test_core_quota_peer1.conf"); 610 setup_peer (&p1, "test_core_quota_peer1.conf");
639 setup_peer (&p2, "test_core_quota_peer2.conf"); 611 setup_peer (&p2, "test_core_quota_peer2.conf");
640 } 612 }
641 else if (test == ASYMMETRIC_SEND_LIMITED) 613 else if (test == ASYMMETRIC_SEND_LIMITED)
642 { 614 {
643 setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf"); 615 setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf");
644 setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf"); 616 setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf");
645 } 617 }
646 else if (test == ASYMMETRIC_RECV_LIMITED) 618 else if (test == ASYMMETRIC_RECV_LIMITED)
647 { 619 {
648 setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); 620 setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf");
649 setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); 621 setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf");
650 } 622 }
651 623
652 GNUNET_assert (test != -1); 624 GNUNET_assert (test != -1);
653 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 625 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
654 "CORE", 626 "CORE",
655 "TOTAL_QUOTA_IN", 627 "TOTAL_QUOTA_IN",
656 &current_quota_p1_in)); 628 &current_quota_p1_in));
657 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 629 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
658 "CORE", 630 "CORE",
659 "TOTAL_QUOTA_IN", 631 "TOTAL_QUOTA_IN",
660 &current_quota_p2_in)); 632 &current_quota_p2_in));
661 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 633 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
662 "CORE", 634 "CORE",
663 "TOTAL_QUOTA_OUT", 635 "TOTAL_QUOTA_OUT",
664 &current_quota_p1_out)); 636 &current_quota_p1_out));
665 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 637 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
666 "CORE", 638 "CORE",
667 "TOTAL_QUOTA_OUT", 639 "TOTAL_QUOTA_OUT",
668 &current_quota_p2_out)); 640 &current_quota_p2_out));
669 641
670 GNUNET_CORE_connect (p1.cfg, 1, 642 GNUNET_CORE_connect (p1.cfg, 1,
671 &p1, 643 &p1,
@@ -684,10 +656,11 @@ stop_arm (struct PeerContext *p)
684#if START_ARM 656#if START_ARM
685 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 657 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
686 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 658 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
687 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 659 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
688 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 660 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 662 "ARM process %u stopped\n",
663 GNUNET_OS_process_get_pid (p->arm_proc));
691 GNUNET_OS_process_close (p->arm_proc); 664 GNUNET_OS_process_close (p->arm_proc);
692 p->arm_proc = NULL; 665 p->arm_proc = NULL;
693#endif 666#endif
@@ -712,7 +685,8 @@ check ()
712 }; 685 };
713 ok = 1; 686 ok = 1;
714 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 687 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
715 argv, "test-core-quota-compliance", "nohelp", options, &run, &ok); 688 argv, "test-core-quota-compliance", "nohelp", options,
689 &run, &ok);
716 stop_arm (&p1); 690 stop_arm (&p1);
717 stop_arm (&p2); 691 stop_arm (&p2);
718 return ok; 692 return ok;
@@ -724,34 +698,38 @@ main (int argc, char *argv[])
724 int ret; 698 int ret;
725 699
726 test = -1; 700 test = -1;
727 if (strstr(argv[0], "_symmetric") != NULL) 701 if (strstr (argv[0], "_symmetric") != NULL)
728 { 702 {
729 test = SYMMETRIC; 703 test = SYMMETRIC;
730 } 704 }
731 else if (strstr(argv[0], "_asymmetric_send") != NULL) 705 else if (strstr (argv[0], "_asymmetric_send") != NULL)
732 { 706 {
733 test = ASYMMETRIC_SEND_LIMITED; 707 test = ASYMMETRIC_SEND_LIMITED;
734 } 708 }
735 else if (strstr(argv[0], "_asymmetric_recv") != NULL) 709 else if (strstr (argv[0], "_asymmetric_recv") != NULL)
736 { 710 {
737 test = ASYMMETRIC_RECV_LIMITED; 711 test = ASYMMETRIC_RECV_LIMITED;
738 } 712 }
739 GNUNET_assert (test != -1); 713 GNUNET_assert (test != -1);
740 if (test == SYMMETRIC) 714 if (test == SYMMETRIC)
741 { 715 {
742 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); 716 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
743 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); 717 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
744 } 718 }
745 else if (test == ASYMMETRIC_SEND_LIMITED) 719 else if (test == ASYMMETRIC_SEND_LIMITED)
746 { 720 {
747 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); 721 GNUNET_DISK_directory_remove
748 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); 722 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
749 } 723 GNUNET_DISK_directory_remove
724 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
725 }
750 else if (test == ASYMMETRIC_RECV_LIMITED) 726 else if (test == ASYMMETRIC_RECV_LIMITED)
751 { 727 {
752 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); 728 GNUNET_DISK_directory_remove
753 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); 729 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
754 } 730 GNUNET_DISK_directory_remove
731 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
732 }
755 733
756 GNUNET_log_setup ("test-core-quota-compliance", 734 GNUNET_log_setup ("test-core-quota-compliance",
757#if VERBOSE 735#if VERBOSE
@@ -762,23 +740,28 @@ main (int argc, char *argv[])
762 NULL); 740 NULL);
763 ret = check (); 741 ret = check ();
764 if (test == SYMMETRIC) 742 if (test == SYMMETRIC)
765 { 743 {
766 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); 744 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
767 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); 745 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
768 } 746 }
769 else if (test == ASYMMETRIC_SEND_LIMITED) 747 else if (test == ASYMMETRIC_SEND_LIMITED)
770 { 748 {
771 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); 749 GNUNET_DISK_directory_remove
772 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); 750 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
773 } 751 GNUNET_DISK_directory_remove
752 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
753 }
774 else if (test == ASYMMETRIC_RECV_LIMITED) 754 else if (test == ASYMMETRIC_RECV_LIMITED)
775 { 755 {
776 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); 756 GNUNET_DISK_directory_remove
777 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); 757 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
778 } 758 GNUNET_DISK_directory_remove
759 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
760 }
779 761
780 762
781 763
782 return ret; 764 return ret;
783} 765}
766
784/* end of test_core_api_reliability.c */ 767/* end of test_core_api_reliability.c */