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.c901
1 files changed, 453 insertions, 448 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 908d90ac3..9db9ab750 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file core/test_core_quota_compliance.c 21 * @file core/test_core_quota_compliance.c
22 * @brief testcase for core_api.c focusing quota compliance on core level 22 * @brief testcase for core_api.c focusing quota compliance on core level
@@ -46,16 +46,16 @@
46/** 46/**
47 * How long until we give up on transmitting the message? 47 * How long until we give up on transmitting the message?
48 */ 48 */
49#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 49#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
50 50
51/** 51/**
52 * What delay do we request from the core service for transmission? 52 * What delay do we request from the core service for transmission?
53 */ 53 */
54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) 54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150)
55 55
56#define MTYPE 12345 56#define MTYPE 12345
57#define MESSAGESIZE (1024 - 8) 57#define MESSAGESIZE (1024 - 8)
58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
59 59
60static unsigned long long total_bytes_sent; 60static unsigned long long total_bytes_sent;
61static unsigned long long total_bytes_recv; 61static unsigned long long total_bytes_recv;
@@ -67,8 +67,7 @@ static struct GNUNET_SCHEDULER_Task *err_task;
67static struct GNUNET_SCHEDULER_Task *measure_task; 67static struct GNUNET_SCHEDULER_Task *measure_task;
68 68
69 69
70struct PeerContext 70struct PeerContext {
71{
72 struct GNUNET_CONFIGURATION_Handle *cfg; 71 struct GNUNET_CONFIGURATION_Handle *cfg;
73 struct GNUNET_CORE_Handle *ch; 72 struct GNUNET_CORE_Handle *ch;
74 struct GNUNET_MQ_Handle *mq; 73 struct GNUNET_MQ_Handle *mq;
@@ -99,13 +98,12 @@ static int running;
99 98
100 99
101#if VERBOSE 100#if VERBOSE
102#define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 101#define OKPP do { ok++; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
103#else 102#else
104#define OKPP do { ok++; } while (0) 103#define OKPP do { ok++; } while (0)
105#endif 104#endif
106 105
107struct TestMessage 106struct TestMessage {
108{
109 struct GNUNET_MessageHeader header; 107 struct GNUNET_MessageHeader header;
110 uint32_t num GNUNET_PACKED; 108 uint32_t num GNUNET_PACKED;
111 uint8_t pad[MESSAGESIZE]; 109 uint8_t pad[MESSAGESIZE];
@@ -113,71 +111,71 @@ struct TestMessage
113 111
114 112
115static void 113static void
116terminate_peer (struct PeerContext *p) 114terminate_peer(struct PeerContext *p)
117{ 115{
118 if (NULL != p->ch) 116 if (NULL != p->ch)
119 { 117 {
120 GNUNET_CORE_disconnect (p->ch); 118 GNUNET_CORE_disconnect(p->ch);
121 p->ch = NULL; 119 p->ch = NULL;
122 } 120 }
123 if (NULL != p->ghh) 121 if (NULL != p->ghh)
124 { 122 {
125 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 123 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
126 p->ghh = NULL; 124 p->ghh = NULL;
127 } 125 }
128 if (NULL != p->oh) 126 if (NULL != p->oh)
129 { 127 {
130 GNUNET_TRANSPORT_offer_hello_cancel (p->oh); 128 GNUNET_TRANSPORT_offer_hello_cancel(p->oh);
131 p->oh = NULL; 129 p->oh = NULL;
132 } 130 }
133 if (NULL != p->ats_sh) 131 if (NULL != p->ats_sh)
134 { 132 {
135 GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); 133 GNUNET_ATS_connectivity_suggest_cancel(p->ats_sh);
136 p->ats_sh = NULL; 134 p->ats_sh = NULL;
137 } 135 }
138 if (NULL != p->ats) 136 if (NULL != p->ats)
139 { 137 {
140 GNUNET_ATS_connectivity_done (p->ats); 138 GNUNET_ATS_connectivity_done(p->ats);
141 p->ats = NULL; 139 p->ats = NULL;
142 } 140 }
143 if (NULL != p->stats) 141 if (NULL != p->stats)
144 { 142 {
145 GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO); 143 GNUNET_STATISTICS_destroy(p->stats, GNUNET_NO);
146 p->stats = NULL; 144 p->stats = NULL;
147 } 145 }
148 if (NULL != p->hello) 146 if (NULL != p->hello)
149 { 147 {
150 GNUNET_free (p->hello); 148 GNUNET_free(p->hello);
151 p->hello = NULL; 149 p->hello = NULL;
152 } 150 }
153} 151}
154 152
155 153
156static void 154static void
157shutdown_task (void *cls) 155shutdown_task(void *cls)
158{ 156{
159 if (NULL != err_task) 157 if (NULL != err_task)
160 { 158 {
161 GNUNET_SCHEDULER_cancel (err_task); 159 GNUNET_SCHEDULER_cancel(err_task);
162 err_task = NULL; 160 err_task = NULL;
163 } 161 }
164 if (NULL != measure_task) 162 if (NULL != measure_task)
165 { 163 {
166 GNUNET_SCHEDULER_cancel (measure_task); 164 GNUNET_SCHEDULER_cancel(measure_task);
167 measure_task = NULL; 165 measure_task = NULL;
168 } 166 }
169 terminate_peer (&p1); 167 terminate_peer(&p1);
170 terminate_peer (&p2); 168 terminate_peer(&p2);
171} 169}
172 170
173 171
174static void 172static void
175terminate_task_error (void *cls) 173terminate_task_error(void *cls)
176{ 174{
177 err_task = NULL; 175 err_task = NULL;
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 176 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 "Testcase failed (timeout)!\n"); 177 "Testcase failed (timeout)!\n");
180 GNUNET_SCHEDULER_shutdown (); 178 GNUNET_SCHEDULER_shutdown();
181 ok = 42; 179 ok = 42;
182} 180}
183 181
@@ -193,28 +191,28 @@ terminate_task_error (void *cls)
193 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 191 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
194 */ 192 */
195static int 193static int
196print_stat (void *cls, 194print_stat(void *cls,
197 const char *subsystem, 195 const char *subsystem,
198 const char *name, 196 const char *name,
199 uint64_t value, 197 uint64_t value,
200 int is_persistent) 198 int is_persistent)
201{ 199{
202 if (cls == &p1) 200 if (cls == &p1)
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
204 "Peer1 %50s = %12llu\n", 202 "Peer1 %50s = %12llu\n",
205 name, 203 name,
206 (unsigned long long) value); 204 (unsigned long long)value);
207 if (cls == &p2) 205 if (cls == &p2)
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
209 "Peer2 %50s = %12llu\n", 207 "Peer2 %50s = %12llu\n",
210 name, 208 name,
211 (unsigned long long) value); 209 (unsigned long long)value);
212 return GNUNET_OK; 210 return GNUNET_OK;
213} 211}
214 212
215 213
216static void 214static void
217measurement_stop (void *cls) 215measurement_stop(void *cls)
218{ 216{
219 unsigned long long delta; 217 unsigned long long delta;
220 unsigned long long throughput_out; 218 unsigned long long throughput_out;
@@ -225,17 +223,17 @@ measurement_stop (void *cls)
225 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; 223 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
226 224
227 measure_task = NULL; 225 measure_task = NULL;
228 fprintf (stdout, "%s", "\n"); 226 fprintf(stdout, "%s", "\n");
229 running = GNUNET_NO; 227 running = GNUNET_NO;
230 228
231 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 229 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us;
232 if (0 == delta) 230 if (0 == delta)
233 delta = 1; 231 delta = 1;
234 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */ 232 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */
235 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */ 233 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */
236 234
237 max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in); 235 max_quota_in = GNUNET_MIN(current_quota_p1_in, current_quota_p2_in);
238 max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out); 236 max_quota_out = GNUNET_MIN(current_quota_p1_out, current_quota_p2_out);
239 if (max_quota_out < max_quota_in) 237 if (max_quota_out < max_quota_in)
240 quota_delta = max_quota_in / 3; 238 quota_delta = max_quota_in / 3;
241 else 239 else
@@ -246,167 +244,170 @@ measurement_stop (void *cls)
246 ok = 1; /* fail */ 244 ok = 1; /* fail */
247 else 245 else
248 ok = 0; /* pass */ 246 ok = 0; /* pass */
249 GNUNET_STATISTICS_get (p1.stats, 247 GNUNET_STATISTICS_get(p1.stats,
250 "core", 248 "core",
251 "# discarded CORE_SEND requests", 249 "# discarded CORE_SEND requests",
252 NULL, 250 NULL,
253 &print_stat, 251 &print_stat,
254 &p1); 252 &p1);
255 GNUNET_STATISTICS_get (p1.stats, 253 GNUNET_STATISTICS_get(p1.stats,
256 "core", 254 "core",
257 "# discarded CORE_SEND request bytes", 255 "# discarded CORE_SEND request bytes",
258 NULL, 256 NULL,
259 &print_stat, 257 &print_stat,
260 &p1); 258 &p1);
261 GNUNET_STATISTICS_get (p1.stats, 259 GNUNET_STATISTICS_get(p1.stats,
262 "core", 260 "core",
263 "# discarded lower priority CORE_SEND requests", 261 "# discarded lower priority CORE_SEND requests",
264 NULL, 262 NULL,
265 &print_stat, 263 &print_stat,
266 NULL); 264 NULL);
267 GNUNET_STATISTICS_get (p1.stats, 265 GNUNET_STATISTICS_get(p1.stats,
268 "core", 266 "core",
269 "# discarded lower priority CORE_SEND request bytes", 267 "# discarded lower priority CORE_SEND request bytes",
270 NULL, 268 NULL,
271 &print_stat, 269 &print_stat,
272 &p1); 270 &p1);
273 GNUNET_STATISTICS_get (p2.stats, 271 GNUNET_STATISTICS_get(p2.stats,
274 "core", 272 "core",
275 "# discarded CORE_SEND requests", 273 "# discarded CORE_SEND requests",
276 NULL, 274 NULL,
277 &print_stat, 275 &print_stat,
278 &p2); 276 &p2);
279 277
280 GNUNET_STATISTICS_get (p2.stats, 278 GNUNET_STATISTICS_get(p2.stats,
281 "core", 279 "core",
282 "# discarded CORE_SEND request bytes", 280 "# discarded CORE_SEND request bytes",
283 NULL, 281 NULL,
284 &print_stat, 282 &print_stat,
285 &p2); 283 &p2);
286 GNUNET_STATISTICS_get (p2.stats, 284 GNUNET_STATISTICS_get(p2.stats,
287 "core", 285 "core",
288 "# discarded lower priority CORE_SEND requests", 286 "# discarded lower priority CORE_SEND requests",
289 NULL, 287 NULL,
290 &print_stat, 288 &print_stat,
291 &p2); 289 &p2);
292 GNUNET_STATISTICS_get (p2.stats, 290 GNUNET_STATISTICS_get(p2.stats,
293 "core", 291 "core",
294 "# discarded lower priority CORE_SEND request bytes", 292 "# discarded lower priority CORE_SEND request bytes",
295 NULL, 293 NULL,
296 &print_stat, 294 &print_stat,
297 &p2); 295 &p2);
298 296
299 if (ok != 0) 297 if (ok != 0)
300 kind = GNUNET_ERROR_TYPE_ERROR; 298 kind = GNUNET_ERROR_TYPE_ERROR;
301 switch (test) 299 switch (test)
302 { 300 {
303 case SYMMETRIC: 301 case SYMMETRIC:
304 GNUNET_log (kind, 302 GNUNET_log(kind,
305 "Core quota compliance test with symmetric quotas: %s\n", 303 "Core quota compliance test with symmetric quotas: %s\n",
306 (0 == ok) ? "PASSED" : "FAILED"); 304 (0 == ok) ? "PASSED" : "FAILED");
307 break; 305 break;
308 case ASYMMETRIC_SEND_LIMITED: 306
309 GNUNET_log (kind, 307 case ASYMMETRIC_SEND_LIMITED:
310 "Core quota compliance test with limited sender quota: %s\n", 308 GNUNET_log(kind,
311 (0 == ok) ? "PASSED" : "FAILED"); 309 "Core quota compliance test with limited sender quota: %s\n",
312 break; 310 (0 == ok) ? "PASSED" : "FAILED");
313 case ASYMMETRIC_RECV_LIMITED: 311 break;
314 GNUNET_log (kind, 312
315 "Core quota compliance test with limited receiver quota: %s\n", 313 case ASYMMETRIC_RECV_LIMITED:
316 (0 == ok) ? "PASSED" : "FAILED"); 314 GNUNET_log(kind,
317 break; 315 "Core quota compliance test with limited receiver quota: %s\n",
318 }; 316 (0 == ok) ? "PASSED" : "FAILED");
319 GNUNET_log (kind, 317 break;
320 "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", 318 }
321 throughput_out, 319 ;
322 total_bytes_sent, 320 GNUNET_log(kind,
323 delta); 321 "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n",
324 GNUNET_log (kind, 322 throughput_out,
325 "Peer 1 send quota: %llu b/s\n", 323 total_bytes_sent,
326 current_quota_p1_out); 324 delta);
327 GNUNET_log (kind, 325 GNUNET_log(kind,
328 "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", 326 "Peer 1 send quota: %llu b/s\n",
329 throughput_in, 327 current_quota_p1_out);
330 total_bytes_recv, 328 GNUNET_log(kind,
331 delta); 329 "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n",
332 GNUNET_log (kind, 330 throughput_in,
333 "Peer 2 receive quota: %llu b/s\n", 331 total_bytes_recv,
334 current_quota_p2_in); 332 delta);
333 GNUNET_log(kind,
334 "Peer 2 receive quota: %llu b/s\n",
335 current_quota_p2_in);
335/* 336/*
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in );
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
338*/ 339 */
339 GNUNET_SCHEDULER_shutdown (); 340 GNUNET_SCHEDULER_shutdown();
340} 341}
341 342
342 343
343static void 344static void
344do_transmit (void *cls) 345do_transmit(void *cls)
345{ 346{
346 struct TestMessage *hdr; 347 struct TestMessage *hdr;
347 struct GNUNET_MQ_Envelope *env; 348 struct GNUNET_MQ_Envelope *env;
348 349
349 env = GNUNET_MQ_msg (hdr, 350 env = GNUNET_MQ_msg(hdr,
350 MTYPE); 351 MTYPE);
351 hdr->num = htonl (tr_n); 352 hdr->num = htonl(tr_n);
352 memset (&hdr->pad, 353 memset(&hdr->pad,
353 tr_n, 354 tr_n,
354 MESSAGESIZE); 355 MESSAGESIZE);
355 tr_n++; 356 tr_n++;
356 GNUNET_SCHEDULER_cancel (err_task); 357 GNUNET_SCHEDULER_cancel(err_task);
357 err_task = 358 err_task =
358 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 359 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
359 &terminate_task_error, 360 &terminate_task_error,
360 NULL); 361 NULL);
361 total_bytes_sent += sizeof (struct TestMessage); 362 total_bytes_sent += sizeof(struct TestMessage);
362 GNUNET_MQ_send (p1.mq, 363 GNUNET_MQ_send(p1.mq,
363 env); 364 env);
364} 365}
365 366
366 367
367static void * 368static void *
368connect_notify (void *cls, 369connect_notify(void *cls,
369 const struct GNUNET_PeerIdentity *peer, 370 const struct GNUNET_PeerIdentity *peer,
370 struct GNUNET_MQ_Handle *mq) 371 struct GNUNET_MQ_Handle *mq)
371{ 372{
372 struct PeerContext *pc = cls; 373 struct PeerContext *pc = cls;
373 374
374 if (0 == memcmp (&pc->id, 375 if (0 == memcmp(&pc->id,
375 peer, 376 peer,
376 sizeof (struct GNUNET_PeerIdentity))) 377 sizeof(struct GNUNET_PeerIdentity)))
377 return NULL; /* loopback */ 378 return NULL; /* loopback */
378 GNUNET_assert (0 == pc->connect_status); 379 GNUNET_assert(0 == pc->connect_status);
379 pc->connect_status = 1; 380 pc->connect_status = 1;
380 pc->mq = mq; 381 pc->mq = mq;
381 if (pc == &p1) 382 if (pc == &p1)
382 { 383 {
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
384 "Encrypted connection established to peer `%s'\n", 385 "Encrypted connection established to peer `%s'\n",
385 GNUNET_i2s (peer)); 386 GNUNET_i2s(peer));
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
387 "Asking core (1) for transmission to peer `%s'\n", 388 "Asking core (1) for transmission to peer `%s'\n",
388 GNUNET_i2s (&p2.id)); 389 GNUNET_i2s(&p2.id));
389 GNUNET_SCHEDULER_cancel (err_task); 390 GNUNET_SCHEDULER_cancel(err_task);
390 err_task = 391 err_task =
391 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 392 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
392 &terminate_task_error, 393 &terminate_task_error,
393 NULL); 394 NULL);
394 start_time = GNUNET_TIME_absolute_get (); 395 start_time = GNUNET_TIME_absolute_get();
395 running = GNUNET_YES; 396 running = GNUNET_YES;
396 measure_task = 397 measure_task =
397 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, 398 GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH,
398 &measurement_stop, 399 &measurement_stop,
399 NULL); 400 NULL);
400 do_transmit (NULL); 401 do_transmit(NULL);
401 } 402 }
402 return pc; 403 return pc;
403} 404}
404 405
405 406
406static void 407static void
407disconnect_notify (void *cls, 408disconnect_notify(void *cls,
408 const struct GNUNET_PeerIdentity *peer, 409 const struct GNUNET_PeerIdentity *peer,
409 void *internal_cls) 410 void *internal_cls)
410{ 411{
411 struct PeerContext *pc = cls; 412 struct PeerContext *pc = cls;
412 413
@@ -415,99 +416,99 @@ disconnect_notify (void *cls,
415 pc->connect_status = 0; 416 pc->connect_status = 0;
416 pc->mq = NULL; 417 pc->mq = NULL;
417 if (NULL != measure_task) 418 if (NULL != measure_task)
418 { 419 {
419 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 420 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
420 "Measurement aborted due to disconnect!\n"); 421 "Measurement aborted due to disconnect!\n");
421 GNUNET_SCHEDULER_cancel (measure_task); 422 GNUNET_SCHEDULER_cancel(measure_task);
422 measure_task = NULL; 423 measure_task = NULL;
423 } 424 }
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
425 "Encrypted connection to `%s' cut\n", 426 "Encrypted connection to `%s' cut\n",
426 GNUNET_i2s (peer)); 427 GNUNET_i2s(peer));
427} 428}
428 429
429 430
430 431
431static void 432static void
432handle_test (void *cls, 433handle_test(void *cls,
433 const struct TestMessage *hdr) 434 const struct TestMessage *hdr)
434{ 435{
435 static int n; 436 static int n;
436 437
437 total_bytes_recv += sizeof (struct TestMessage); 438 total_bytes_recv += sizeof(struct TestMessage);
438 if (ntohl (hdr->num) != n) 439 if (ntohl(hdr->num) != n)
439 { 440 {
440 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 441 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
441 "Expected message %u, got message %u\n", 442 "Expected message %u, got message %u\n",
442 n, 443 n,
443 ntohl (hdr->num)); 444 ntohl(hdr->num));
444 GNUNET_SCHEDULER_cancel (err_task); 445 GNUNET_SCHEDULER_cancel(err_task);
445 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 446 err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error,
446 NULL); 447 NULL);
447 return; 448 return;
448 } 449 }
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 450 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
450 "Got message %u\n", 451 "Got message %u\n",
451 ntohl (hdr->num)); 452 ntohl(hdr->num));
452 n++; 453 n++;
453 if (0 == (n % 10)) 454 if (0 == (n % 10))
454 fprintf (stderr, "%s", "."); 455 fprintf(stderr, "%s", ".");
455 456
456 if (GNUNET_YES == running) 457 if (GNUNET_YES == running)
457 do_transmit (NULL); 458 do_transmit(NULL);
458} 459}
459 460
460 461
461static void 462static void
462init_notify (void *cls, 463init_notify(void *cls,
463 const struct GNUNET_PeerIdentity *my_identity) 464 const struct GNUNET_PeerIdentity *my_identity)
464{ 465{
465 struct PeerContext *p = cls; 466 struct PeerContext *p = cls;
466 struct GNUNET_MQ_MessageHandler handlers[] = { 467 struct GNUNET_MQ_MessageHandler handlers[] = {
467 GNUNET_MQ_hd_fixed_size (test, 468 GNUNET_MQ_hd_fixed_size(test,
468 MTYPE, 469 MTYPE,
469 struct TestMessage, 470 struct TestMessage,
470 NULL), 471 NULL),
471 GNUNET_MQ_handler_end () 472 GNUNET_MQ_handler_end()
472 }; 473 };
473 474
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
475 "Connection to CORE service of `%s' established\n", 476 "Connection to CORE service of `%s' established\n",
476 GNUNET_i2s (my_identity)); 477 GNUNET_i2s(my_identity));
477 GNUNET_assert (NULL != my_identity); 478 GNUNET_assert(NULL != my_identity);
478 p->id = *my_identity; 479 p->id = *my_identity;
479 if (cls == &p1) 480 if (cls == &p1)
480 { 481 {
481 GNUNET_assert (ok == 2); 482 GNUNET_assert(ok == 2);
482 OKPP; 483 OKPP;
483 /* connect p2 */ 484 /* connect p2 */
484 p2.ch = GNUNET_CORE_connect (p2.cfg, 485 p2.ch = GNUNET_CORE_connect(p2.cfg,
485 &p2, 486 &p2,
486 &init_notify, 487 &init_notify,
487 &connect_notify, 488 &connect_notify,
488 &disconnect_notify, 489 &disconnect_notify,
489 handlers); 490 handlers);
490 } 491 }
491 else 492 else
492 { 493 {
493 GNUNET_assert (ok == 3); 494 GNUNET_assert(ok == 3);
494 OKPP; 495 OKPP;
495 GNUNET_assert (cls == &p2); 496 GNUNET_assert(cls == &p2);
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
497 "Asking core (1) to connect to peer `%s' and vice-versa\n", 498 "Asking core (1) to connect to peer `%s' and vice-versa\n",
498 GNUNET_i2s (&p2.id)); 499 GNUNET_i2s(&p2.id));
499 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, 500 p1.ats_sh = GNUNET_ATS_connectivity_suggest(p1.ats,
500 &p2.id, 501 &p2.id,
501 1); 502 1);
502 p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats, 503 p2.ats_sh = GNUNET_ATS_connectivity_suggest(p2.ats,
503 &p1.id, 504 &p1.id,
504 1); 505 1);
505 } 506 }
506} 507}
507 508
508 509
509static void 510static void
510offer_hello_done (void *cls) 511offer_hello_done(void *cls)
511{ 512{
512 struct PeerContext *p = cls; 513 struct PeerContext *p = cls;
513 514
@@ -516,175 +517,175 @@ offer_hello_done (void *cls)
516 517
517 518
518static void 519static void
519process_hello (void *cls, 520process_hello(void *cls,
520 const struct GNUNET_MessageHeader *message) 521 const struct GNUNET_MessageHeader *message)
521{ 522{
522 struct PeerContext *p = cls; 523 struct PeerContext *p = cls;
523 524
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 525 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
525 "Received (my) HELLO from transport service\n"); 526 "Received (my) HELLO from transport service\n");
526 GNUNET_assert (message != NULL); 527 GNUNET_assert(message != NULL);
527 p->hello = GNUNET_malloc (ntohs (message->size)); 528 p->hello = GNUNET_malloc(ntohs(message->size));
528 GNUNET_memcpy (p->hello, message, ntohs (message->size)); 529 GNUNET_memcpy(p->hello, message, ntohs(message->size));
529 if ( (p == &p1) && 530 if ((p == &p1) &&
530 (NULL == p2.oh) ) 531 (NULL == p2.oh))
531 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 532 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
532 message, 533 message,
533 &offer_hello_done, 534 &offer_hello_done,
534 &p2); 535 &p2);
535 if ( (p == &p2) && 536 if ((p == &p2) &&
536 (NULL == p1.oh) ) 537 (NULL == p1.oh))
537 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, 538 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg, message,
538 &offer_hello_done, 539 &offer_hello_done,
539 &p1); 540 &p1);
540 541
541 if ( (p == &p1) && 542 if ((p == &p1) &&
542 (NULL != p2.hello) && 543 (NULL != p2.hello) &&
543 (NULL == p1.oh) ) 544 (NULL == p1.oh))
544 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 545 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg,
545 p2.hello, 546 p2.hello,
546 &offer_hello_done, 547 &offer_hello_done,
547 &p1); 548 &p1);
548 if ( (p == &p2) && 549 if ((p == &p2) &&
549 (NULL != p1.hello) && 550 (NULL != p1.hello) &&
550 (NULL == p2.oh) ) 551 (NULL == p2.oh))
551 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 552 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
552 p1.hello, 553 p1.hello,
553 &offer_hello_done, 554 &offer_hello_done,
554 &p2); 555 &p2);
555} 556}
556 557
557 558
558static void 559static void
559setup_peer (struct PeerContext *p, 560setup_peer(struct PeerContext *p,
560 const char *cfgname) 561 const char *cfgname)
561{ 562{
562 char *binary; 563 char *binary;
563 564
564 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 565 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
565 p->cfg = GNUNET_CONFIGURATION_create (); 566 p->cfg = GNUNET_CONFIGURATION_create();
566 p->arm_proc = 567 p->arm_proc =
567 GNUNET_OS_start_process (GNUNET_YES, 568 GNUNET_OS_start_process(GNUNET_YES,
568 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 569 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
569 NULL, NULL, NULL, 570 NULL, NULL, NULL,
570 binary, 571 binary,
571 "gnunet-service-arm", 572 "gnunet-service-arm",
572 "-c", 573 "-c",
573 cfgname, 574 cfgname,
574 NULL); 575 NULL);
575 GNUNET_assert (GNUNET_OK == 576 GNUNET_assert(GNUNET_OK ==
576 GNUNET_CONFIGURATION_load (p->cfg, 577 GNUNET_CONFIGURATION_load(p->cfg,
577 cfgname)); 578 cfgname));
578 p->stats = GNUNET_STATISTICS_create ("core", 579 p->stats = GNUNET_STATISTICS_create("core",
579 p->cfg); 580 p->cfg);
580 GNUNET_assert (NULL != p->stats); 581 GNUNET_assert(NULL != p->stats);
581 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 582 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
582 GNUNET_assert (NULL != p->ats); 583 GNUNET_assert(NULL != p->ats);
583 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 584 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
584 GNUNET_TRANSPORT_AC_ANY, 585 GNUNET_TRANSPORT_AC_ANY,
585 &process_hello, 586 &process_hello,
586 p); 587 p);
587 GNUNET_free (binary); 588 GNUNET_free(binary);
588} 589}
589 590
590 591
591static void 592static void
592run (void *cls, 593run(void *cls,
593 char *const *args, 594 char *const *args,
594 const char *cfgfile, 595 const char *cfgfile,
595 const struct GNUNET_CONFIGURATION_Handle *cfg) 596 const struct GNUNET_CONFIGURATION_Handle *cfg)
596{ 597{
597 struct GNUNET_MQ_MessageHandler handlers[] = { 598 struct GNUNET_MQ_MessageHandler handlers[] = {
598 GNUNET_MQ_hd_fixed_size (test, 599 GNUNET_MQ_hd_fixed_size(test,
599 MTYPE, 600 MTYPE,
600 struct TestMessage, 601 struct TestMessage,
601 NULL), 602 NULL),
602 GNUNET_MQ_handler_end () 603 GNUNET_MQ_handler_end()
603 }; 604 };
604 605
605 GNUNET_assert (ok == 1); 606 GNUNET_assert(ok == 1);
606 OKPP; 607 OKPP;
607 err_task = 608 err_task =
608 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 609 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
609 &terminate_task_error, 610 &terminate_task_error,
610 NULL); 611 NULL);
611 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 612 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
612 NULL); 613 NULL);
613 if (test == SYMMETRIC) 614 if (test == SYMMETRIC)
614 { 615 {
615 setup_peer (&p1, 616 setup_peer(&p1,
616 "test_core_quota_peer1.conf"); 617 "test_core_quota_peer1.conf");
617 setup_peer (&p2, 618 setup_peer(&p2,
618 "test_core_quota_peer2.conf"); 619 "test_core_quota_peer2.conf");
619 } 620 }
620 else if (test == ASYMMETRIC_SEND_LIMITED) 621 else if (test == ASYMMETRIC_SEND_LIMITED)
621 { 622 {
622 setup_peer (&p1, 623 setup_peer(&p1,
623 "test_core_quota_asymmetric_send_limit_peer1.conf"); 624 "test_core_quota_asymmetric_send_limit_peer1.conf");
624 setup_peer (&p2, 625 setup_peer(&p2,
625 "test_core_quota_asymmetric_send_limit_peer2.conf"); 626 "test_core_quota_asymmetric_send_limit_peer2.conf");
626 } 627 }
627 else if (test == ASYMMETRIC_RECV_LIMITED) 628 else if (test == ASYMMETRIC_RECV_LIMITED)
628 { 629 {
629 setup_peer (&p1, 630 setup_peer(&p1,
630 "test_core_quota_asymmetric_recv_limited_peer1.conf"); 631 "test_core_quota_asymmetric_recv_limited_peer1.conf");
631 setup_peer (&p2, 632 setup_peer(&p2,
632 "test_core_quota_asymmetric_recv_limited_peer2.conf"); 633 "test_core_quota_asymmetric_recv_limited_peer2.conf");
633 } 634 }
634 635
635 GNUNET_assert (test != -1); 636 GNUNET_assert(test != -1);
636 GNUNET_assert (GNUNET_SYSERR != 637 GNUNET_assert(GNUNET_SYSERR !=
637 GNUNET_CONFIGURATION_get_value_size (p1.cfg, 638 GNUNET_CONFIGURATION_get_value_size(p1.cfg,
638 "ATS", 639 "ATS",
639 "WAN_QUOTA_IN", 640 "WAN_QUOTA_IN",
640 &current_quota_p1_in)); 641 &current_quota_p1_in));
641 GNUNET_assert (GNUNET_SYSERR != 642 GNUNET_assert(GNUNET_SYSERR !=
642 GNUNET_CONFIGURATION_get_value_size (p2.cfg, 643 GNUNET_CONFIGURATION_get_value_size(p2.cfg,
643 "ATS", 644 "ATS",
644 "WAN_QUOTA_IN", 645 "WAN_QUOTA_IN",
645 &current_quota_p2_in)); 646 &current_quota_p2_in));
646 GNUNET_assert (GNUNET_SYSERR != 647 GNUNET_assert(GNUNET_SYSERR !=
647 GNUNET_CONFIGURATION_get_value_size (p1.cfg, 648 GNUNET_CONFIGURATION_get_value_size(p1.cfg,
648 "ATS", 649 "ATS",
649 "WAN_QUOTA_OUT", 650 "WAN_QUOTA_OUT",
650 &current_quota_p1_out)); 651 &current_quota_p1_out));
651 GNUNET_assert (GNUNET_SYSERR != 652 GNUNET_assert(GNUNET_SYSERR !=
652 GNUNET_CONFIGURATION_get_value_size (p2.cfg, 653 GNUNET_CONFIGURATION_get_value_size(p2.cfg,
653 "ATS", 654 "ATS",
654 "WAN_QUOTA_OUT", 655 "WAN_QUOTA_OUT",
655 &current_quota_p2_out)); 656 &current_quota_p2_out));
656 657
657 p1.ch = GNUNET_CORE_connect (p1.cfg, 658 p1.ch = GNUNET_CORE_connect(p1.cfg,
658 &p1, 659 &p1,
659 &init_notify, 660 &init_notify,
660 &connect_notify, 661 &connect_notify,
661 &disconnect_notify, 662 &disconnect_notify,
662 handlers); 663 handlers);
663} 664}
664 665
665 666
666static void 667static void
667stop_arm (struct PeerContext *p) 668stop_arm(struct PeerContext *p)
668{ 669{
669 if (0 != GNUNET_OS_process_kill (p->arm_proc, 670 if (0 != GNUNET_OS_process_kill(p->arm_proc,
670 GNUNET_TERM_SIG)) 671 GNUNET_TERM_SIG))
671 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 672 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
672 "kill"); 673 "kill");
673 if (GNUNET_OK != 674 if (GNUNET_OK !=
674 GNUNET_OS_process_wait (p->arm_proc)) 675 GNUNET_OS_process_wait(p->arm_proc))
675 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 676 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
676 "waitpid"); 677 "waitpid");
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
678 "ARM process %u stopped\n", 679 "ARM process %u stopped\n",
679 GNUNET_OS_process_get_pid (p->arm_proc)); 680 GNUNET_OS_process_get_pid(p->arm_proc));
680 GNUNET_OS_process_destroy (p->arm_proc); 681 GNUNET_OS_process_destroy(p->arm_proc);
681 p->arm_proc = NULL; 682 p->arm_proc = NULL;
682 GNUNET_CONFIGURATION_destroy (p->cfg); 683 GNUNET_CONFIGURATION_destroy(p->cfg);
683} 684}
684 685
685 686
686static int 687static int
687check () 688check()
688{ 689{
689 char *const argv[] = { 690 char *const argv[] = {
690 "test-core-quota-compliance", 691 "test-core-quota-compliance",
@@ -695,73 +696,77 @@ check ()
695 struct GNUNET_GETOPT_CommandLineOption options[] = { 696 struct GNUNET_GETOPT_CommandLineOption options[] = {
696 GNUNET_GETOPT_OPTION_END 697 GNUNET_GETOPT_OPTION_END
697 }; 698 };
699
698 ok = 1; 700 ok = 1;
699 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 701 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
700 argv, 702 argv,
701 "test-core-quota-compliance", 703 "test-core-quota-compliance",
702 "nohelp", 704 "nohelp",
703 options, 705 options,
704 &run, 706 &run,
705 &ok); 707 &ok);
706 stop_arm (&p1); 708 stop_arm(&p1);
707 stop_arm (&p2); 709 stop_arm(&p2);
708 return ok; 710 return ok;
709} 711}
710 712
711 713
712static void 714static void
713cleanup_directory (int test) 715cleanup_directory(int test)
714{ 716{
715 switch (test) { 717 switch (test)
716 case SYMMETRIC: 718 {
717 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); 719 case SYMMETRIC:
718 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); 720 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-quota-sym-peer-1/");
719 break; 721 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-quota-sym-peer-2/");
720 case ASYMMETRIC_SEND_LIMITED: 722 break;
721 GNUNET_DISK_directory_remove 723
724 case ASYMMETRIC_SEND_LIMITED:
725 GNUNET_DISK_directory_remove
722 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); 726 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
723 GNUNET_DISK_directory_remove 727 GNUNET_DISK_directory_remove
724 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); 728 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
725 break; 729 break;
726 case ASYMMETRIC_RECV_LIMITED: 730
727 GNUNET_DISK_directory_remove 731 case ASYMMETRIC_RECV_LIMITED:
732 GNUNET_DISK_directory_remove
728 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); 733 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
729 GNUNET_DISK_directory_remove 734 GNUNET_DISK_directory_remove
730 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); 735 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
731 break; 736 break;
732 } 737 }
733} 738}
734 739
735 740
736int 741int
737main (int argc, 742main(int argc,
738 char *argv[]) 743 char *argv[])
739{ 744{
740 int ret; 745 int ret;
741 746
742 test = -1; 747 test = -1;
743 if (NULL != strstr (argv[0], 748 if (NULL != strstr(argv[0],
744 "_symmetric")) 749 "_symmetric"))
745 { 750 {
746 test = SYMMETRIC; 751 test = SYMMETRIC;
747 } 752 }
748 else if (NULL != strstr (argv[0], 753 else if (NULL != strstr(argv[0],
749 "_asymmetric_send")) 754 "_asymmetric_send"))
750 { 755 {
751 test = ASYMMETRIC_SEND_LIMITED; 756 test = ASYMMETRIC_SEND_LIMITED;
752 } 757 }
753 else if (NULL != strstr (argv[0], 758 else if (NULL != strstr(argv[0],
754 "_asymmetric_recv")) 759 "_asymmetric_recv"))
755 { 760 {
756 test = ASYMMETRIC_RECV_LIMITED; 761 test = ASYMMETRIC_RECV_LIMITED;
757 } 762 }
758 GNUNET_assert (test != -1); 763 GNUNET_assert(test != -1);
759 cleanup_directory (test); 764 cleanup_directory(test);
760 GNUNET_log_setup ("test-core-quota-compliance", 765 GNUNET_log_setup("test-core-quota-compliance",
761 "WARNING", 766 "WARNING",
762 NULL); 767 NULL);
763 ret = check (); 768 ret = check();
764 cleanup_directory (test); 769 cleanup_directory(test);
765 return ret; 770 return ret;
766} 771}
767 772