aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_connectionpool.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/testbed/gnunet-service-testbed_connectionpool.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/testbed/gnunet-service-testbed_connectionpool.c')
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.c656
1 files changed, 329 insertions, 327 deletions
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c
index fdb10f987..7f9c9fd57 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.c
+++ b/src/testbed/gnunet-service-testbed_connectionpool.c
@@ -36,14 +36,14 @@
36#undef LOG 36#undef LOG
37#endif 37#endif
38#define LOG(kind, ...) \ 38#define LOG(kind, ...) \
39 GNUNET_log_from(kind, "testbed-connectionpool", __VA_ARGS__) 39 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__)
40 40
41 41
42/** 42/**
43 * Time to expire a cache entry 43 * Time to expire a cache entry
44 */ 44 */
45#define CACHE_EXPIRY \ 45#define CACHE_EXPIRY \
46 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
47 47
48 48
49/** 49/**
@@ -55,7 +55,8 @@ struct GST_ConnectionPool_GetHandle;
55/** 55/**
56 * A pooled connection 56 * A pooled connection
57 */ 57 */
58struct PooledConnection { 58struct PooledConnection
59{
59 /** 60 /**
60 * Next ptr for placing this object in the DLL of least recently used pooled 61 * Next ptr for placing this object in the DLL of least recently used pooled
61 * connections 62 * connections
@@ -168,7 +169,8 @@ struct PooledConnection {
168/** 169/**
169 * The request handle for obtaining a pooled connection 170 * The request handle for obtaining a pooled connection
170 */ 171 */
171struct GST_ConnectionPool_GetHandle { 172struct GST_ConnectionPool_GetHandle
173{
172 /** 174 /**
173 * The next ptr for inclusion in the notification DLLs. At first the object 175 * The next ptr for inclusion in the notification DLLs. At first the object
174 * is placed in the waiting DLL of the corresponding #PooledConnection 176 * is placed in the waiting DLL of the corresponding #PooledConnection
@@ -272,7 +274,7 @@ static unsigned int max_size;
272 * @param entry the #PooledConnection object 274 * @param entry the #PooledConnection object
273 */ 275 */
274static void 276static void
275expire_task_cancel(struct PooledConnection *entry); 277expire_task_cancel (struct PooledConnection *entry);
276 278
277 279
278/** 280/**
@@ -281,49 +283,49 @@ expire_task_cancel(struct PooledConnection *entry);
281 * @param entry the #PooledConnection object 283 * @param entry the #PooledConnection object
282 */ 284 */
283static void 285static void
284destroy_pooled_connection(struct PooledConnection *entry) 286destroy_pooled_connection (struct PooledConnection *entry)
285{ 287{
286 GNUNET_assert((NULL == entry->head_notify) && (NULL == entry->tail_notify)); 288 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify));
287 GNUNET_assert((NULL == entry->head_waiting) && 289 GNUNET_assert ((NULL == entry->head_waiting) &&
288 (NULL == entry->tail_waiting)); 290 (NULL == entry->tail_waiting));
289 GNUNET_assert(0 == entry->demand); 291 GNUNET_assert (0 == entry->demand);
290 expire_task_cancel(entry); 292 expire_task_cancel (entry);
291 if (entry->in_lru) 293 if (entry->in_lru)
292 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 294 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
293 if (entry->in_pool) 295 if (entry->in_pool)
294 GNUNET_assert( 296 GNUNET_assert (
295 GNUNET_OK == 297 GNUNET_OK ==
296 GNUNET_CONTAINER_multihashmap32_remove(map, entry->index, entry)); 298 GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry));
297 if (NULL != entry->notify_task) 299 if (NULL != entry->notify_task)
298 { 300 {
299 GNUNET_SCHEDULER_cancel(entry->notify_task); 301 GNUNET_SCHEDULER_cancel (entry->notify_task);
300 entry->notify_task = NULL; 302 entry->notify_task = NULL;
301 } 303 }
302 LOG_DEBUG("Cleaning up handles of a pooled connection\n"); 304 LOG_DEBUG ("Cleaning up handles of a pooled connection\n");
303 if (NULL != entry->handle_transport) 305 if (NULL != entry->handle_transport)
304 GNUNET_assert(NULL != entry->op_transport); 306 GNUNET_assert (NULL != entry->op_transport);
305 if (NULL != entry->op_transport) 307 if (NULL != entry->op_transport)
306 { 308 {
307 GNUNET_TESTBED_operation_done(entry->op_transport); 309 GNUNET_TESTBED_operation_done (entry->op_transport);
308 entry->op_transport = NULL; 310 entry->op_transport = NULL;
309 } 311 }
310 if (NULL != entry->handle_ats_connectivity) 312 if (NULL != entry->handle_ats_connectivity)
311 GNUNET_assert(NULL != entry->op_ats_connectivity); 313 GNUNET_assert (NULL != entry->op_ats_connectivity);
312 if (NULL != entry->op_ats_connectivity) 314 if (NULL != entry->op_ats_connectivity)
313 { 315 {
314 GNUNET_TESTBED_operation_done(entry->op_ats_connectivity); 316 GNUNET_TESTBED_operation_done (entry->op_ats_connectivity);
315 entry->op_ats_connectivity = NULL; 317 entry->op_ats_connectivity = NULL;
316 } 318 }
317 if (NULL != entry->op_core) 319 if (NULL != entry->op_core)
318 { 320 {
319 GNUNET_TESTBED_operation_done(entry->op_core); 321 GNUNET_TESTBED_operation_done (entry->op_core);
320 entry->op_core = NULL; 322 entry->op_core = NULL;
321 } 323 }
322 GNUNET_assert(NULL == entry->handle_core); 324 GNUNET_assert (NULL == entry->handle_core);
323 GNUNET_assert(NULL == entry->handle_ats_connectivity); 325 GNUNET_assert (NULL == entry->handle_ats_connectivity);
324 GNUNET_assert(NULL == entry->handle_transport); 326 GNUNET_assert (NULL == entry->handle_transport);
325 GNUNET_CONFIGURATION_destroy(entry->cfg); 327 GNUNET_CONFIGURATION_destroy (entry->cfg);
326 GNUNET_free(entry); 328 GNUNET_free (entry);
327} 329}
328 330
329 331
@@ -333,12 +335,12 @@ destroy_pooled_connection(struct PooledConnection *entry)
333 * @param cls the #PooledConnection object 335 * @param cls the #PooledConnection object
334 */ 336 */
335static void 337static void
336expire(void *cls) 338expire (void *cls)
337{ 339{
338 struct PooledConnection *entry = cls; 340 struct PooledConnection *entry = cls;
339 341
340 entry->expire_task = NULL; 342 entry->expire_task = NULL;
341 destroy_pooled_connection(entry); 343 destroy_pooled_connection (entry);
342} 344}
343 345
344 346
@@ -348,13 +350,13 @@ expire(void *cls)
348 * @param entry the #PooledConnection object 350 * @param entry the #PooledConnection object
349 */ 351 */
350static void 352static void
351expire_task_cancel(struct PooledConnection *entry) 353expire_task_cancel (struct PooledConnection *entry)
352{ 354{
353 if (NULL != entry->expire_task) 355 if (NULL != entry->expire_task)
354 { 356 {
355 GNUNET_SCHEDULER_cancel(entry->expire_task); 357 GNUNET_SCHEDULER_cancel (entry->expire_task);
356 entry->expire_task = NULL; 358 entry->expire_task = NULL;
357 } 359 }
358} 360}
359 361
360 362
@@ -364,15 +366,15 @@ expire_task_cancel(struct PooledConnection *entry)
364 * @param entry the #PooledConnection object 366 * @param entry the #PooledConnection object
365 */ 367 */
366static void 368static void
367add_to_lru(struct PooledConnection *entry) 369add_to_lru (struct PooledConnection *entry)
368{ 370{
369 GNUNET_assert(0 == entry->demand); 371 GNUNET_assert (0 == entry->demand);
370 GNUNET_assert(!entry->in_lru); 372 GNUNET_assert (! entry->in_lru);
371 GNUNET_CONTAINER_DLL_insert_tail(head_lru, tail_lru, entry); 373 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry);
372 entry->in_lru = GNUNET_YES; 374 entry->in_lru = GNUNET_YES;
373 GNUNET_assert(NULL == entry->expire_task); 375 GNUNET_assert (NULL == entry->expire_task);
374 entry->expire_task = 376 entry->expire_task =
375 GNUNET_SCHEDULER_add_delayed(CACHE_EXPIRY, &expire, entry); 377 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry);
376} 378}
377 379
378 380
@@ -388,34 +390,34 @@ add_to_lru(struct PooledConnection *entry)
388 * is found 390 * is found
389 */ 391 */
390static struct GST_ConnectionPool_GetHandle * 392static struct GST_ConnectionPool_GetHandle *
391search_waiting(const struct PooledConnection *entry, 393search_waiting (const struct PooledConnection *entry,
392 struct GST_ConnectionPool_GetHandle *head) 394 struct GST_ConnectionPool_GetHandle *head)
393{ 395{
394 struct GST_ConnectionPool_GetHandle *gh; 396 struct GST_ConnectionPool_GetHandle *gh;
395 397
396 for (gh = head; NULL != gh; gh = gh->next) 398 for (gh = head; NULL != gh; gh = gh->next)
399 {
400 switch (gh->service)
397 { 401 {
398 switch (gh->service) 402 case GST_CONNECTIONPOOL_SERVICE_CORE:
399 { 403 if (NULL == entry->handle_core)
400 case GST_CONNECTIONPOOL_SERVICE_CORE: 404 continue;
401 if (NULL == entry->handle_core) 405 if (NULL == entry->peer_identity)
402 continue; 406 continue; /* CORE connection isn't ready yet */
403 if (NULL == entry->peer_identity) 407 break;
404 continue; /* CORE connection isn't ready yet */ 408
405 break; 409 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
406 410 if (NULL == entry->handle_transport)
407 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 411 continue;
408 if (NULL == entry->handle_transport) 412 break;
409 continue; 413
410 break; 414 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
411 415 if (NULL == entry->handle_ats_connectivity)
412 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 416 continue;
413 if (NULL == entry->handle_ats_connectivity)
414 continue;
415 break;
416 }
417 break; 417 break;
418 } 418 }
419 break;
420 }
419 return gh; 421 return gh;
420} 422}
421 423
@@ -430,37 +432,37 @@ search_waiting(const struct PooledConnection *entry,
430 * @param cls the #PooledConnection object 432 * @param cls the #PooledConnection object
431 */ 433 */
432static void 434static void
433connection_ready(void *cls) 435connection_ready (void *cls)
434{ 436{
435 struct PooledConnection *entry = cls; 437 struct PooledConnection *entry = cls;
436 struct GST_ConnectionPool_GetHandle *gh; 438 struct GST_ConnectionPool_GetHandle *gh;
437 struct GST_ConnectionPool_GetHandle *gh_next; 439 struct GST_ConnectionPool_GetHandle *gh_next;
438 440
439 GNUNET_assert(NULL != entry->notify_task); 441 GNUNET_assert (NULL != entry->notify_task);
440 entry->notify_task = NULL; 442 entry->notify_task = NULL;
441 gh = search_waiting(entry, entry->head_waiting); 443 gh = search_waiting (entry, entry->head_waiting);
442 GNUNET_assert(NULL != gh); 444 GNUNET_assert (NULL != gh);
443 gh_next = NULL; 445 gh_next = NULL;
444 if (NULL != gh->next) 446 if (NULL != gh->next)
445 gh_next = search_waiting(entry, gh->next); 447 gh_next = search_waiting (entry, gh->next);
446 GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); 448 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
447 gh->connection_ready_called = 1; 449 gh->connection_ready_called = 1;
448 if (NULL != gh_next) 450 if (NULL != gh_next)
449 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 451 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
450 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) 452 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb))
451 { 453 {
452 GNUNET_CONTAINER_DLL_insert_tail(entry->head_notify, 454 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify,
453 entry->tail_notify, 455 entry->tail_notify,
454 gh); 456 gh);
455 gh->notify_waiting = 1; 457 gh->notify_waiting = 1;
456 } 458 }
457 LOG_DEBUG("Connection ready for handle type %u\n", gh->service); 459 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
458 gh->cb(gh->cb_cls, 460 gh->cb (gh->cb_cls,
459 entry->handle_core, 461 entry->handle_core,
460 entry->handle_transport, 462 entry->handle_transport,
461 entry->handle_ats_connectivity, 463 entry->handle_ats_connectivity,
462 entry->peer_identity, 464 entry->peer_identity,
463 entry->cfg); 465 entry->cfg);
464} 466}
465 467
466 468
@@ -474,9 +476,9 @@ connection_ready(void *cls)
474 * @param service the service where this notification has originated 476 * @param service the service where this notification has originated
475 */ 477 */
476static void 478static void
477peer_connect_notify_cb(void *cls, 479peer_connect_notify_cb (void *cls,
478 const struct GNUNET_PeerIdentity *peer, 480 const struct GNUNET_PeerIdentity *peer,
479 const enum GST_ConnectionPool_Service service) 481 const enum GST_ConnectionPool_Service service)
480{ 482{
481 struct PooledConnection *entry = cls; 483 struct PooledConnection *entry = cls;
482 struct GST_ConnectionPool_GetHandle *gh; 484 struct GST_ConnectionPool_GetHandle *gh;
@@ -485,31 +487,31 @@ peer_connect_notify_cb(void *cls,
485 void *cb_cls; 487 void *cb_cls;
486 488
487 for (gh = entry->head_notify; NULL != gh;) 489 for (gh = entry->head_notify; NULL != gh;)
490 {
491 GNUNET_assert (NULL != gh->target);
492 GNUNET_assert (NULL != gh->connect_notify_cb);
493 GNUNET_assert (gh->connection_ready_called);
494 if (service != gh->service)
488 { 495 {
489 GNUNET_assert(NULL != gh->target); 496 gh = gh->next;
490 GNUNET_assert(NULL != gh->connect_notify_cb); 497 continue;
491 GNUNET_assert(gh->connection_ready_called);
492 if (service != gh->service)
493 {
494 gh = gh->next;
495 continue;
496 }
497 if (0 != memcmp(gh->target, peer, sizeof(struct GNUNET_PeerIdentity)))
498 {
499 gh = gh->next;
500 continue;
501 }
502 cb = gh->connect_notify_cb;
503 cb_cls = gh->connect_notify_cb_cls;
504 gh_next = gh->next;
505 GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh);
506 gh->notify_waiting = 0;
507 LOG_DEBUG("Peer connected to peer %u at service %u\n",
508 entry->index,
509 gh->service);
510 gh = gh_next;
511 cb(cb_cls, peer);
512 } 498 }
499 if (0 != memcmp (gh->target, peer, sizeof(struct GNUNET_PeerIdentity)))
500 {
501 gh = gh->next;
502 continue;
503 }
504 cb = gh->connect_notify_cb;
505 cb_cls = gh->connect_notify_cb_cls;
506 gh_next = gh->next;
507 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
508 gh->notify_waiting = 0;
509 LOG_DEBUG ("Peer connected to peer %u at service %u\n",
510 entry->index,
511 gh->service);
512 gh = gh_next;
513 cb (cb_cls, peer);
514 }
513} 515}
514 516
515 517
@@ -523,13 +525,13 @@ peer_connect_notify_cb(void *cls,
523 * @return NULL 525 * @return NULL
524 */ 526 */
525static void * 527static void *
526transport_peer_connect_notify_cb(void *cls, 528transport_peer_connect_notify_cb (void *cls,
527 const struct GNUNET_PeerIdentity *peer, 529 const struct GNUNET_PeerIdentity *peer,
528 struct GNUNET_MQ_Handle *mq) 530 struct GNUNET_MQ_Handle *mq)
529{ 531{
530 struct PooledConnection *entry = cls; 532 struct PooledConnection *entry = cls;
531 533
532 peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); 534 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
533 return NULL; 535 return NULL;
534} 536}
535 537
@@ -541,34 +543,34 @@ transport_peer_connect_notify_cb(void *cls,
541 * @param cls the #PooledConnection object 543 * @param cls the #PooledConnection object
542 */ 544 */
543static void 545static void
544opstart_get_handle_transport(void *cls) 546opstart_get_handle_transport (void *cls)
545{ 547{
546 struct PooledConnection *entry = cls; 548 struct PooledConnection *entry = cls;
547 549
548 GNUNET_assert(NULL != entry); 550 GNUNET_assert (NULL != entry);
549 LOG_DEBUG("Opening a transport connection to peer %u\n", entry->index); 551 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index);
550 entry->handle_transport = 552 entry->handle_transport =
551 GNUNET_TRANSPORT_core_connect(entry->cfg, 553 GNUNET_TRANSPORT_core_connect (entry->cfg,
552 NULL, 554 NULL,
553 NULL, 555 NULL,
554 entry, 556 entry,
555 &transport_peer_connect_notify_cb, 557 &transport_peer_connect_notify_cb,
556 NULL, 558 NULL,
557 NULL); 559 NULL);
558 if (NULL == entry->handle_transport) 560 if (NULL == entry->handle_transport)
559 { 561 {
560 GNUNET_break(0); 562 GNUNET_break (0);
561 return; 563 return;
562 } 564 }
563 if (0 == entry->demand) 565 if (0 == entry->demand)
564 return; 566 return;
565 if (NULL != entry->notify_task) 567 if (NULL != entry->notify_task)
566 return; 568 return;
567 if (NULL != search_waiting(entry, entry->head_waiting)) 569 if (NULL != search_waiting (entry, entry->head_waiting))
568 { 570 {
569 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 571 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
570 return; 572 return;
571 } 573 }
572} 574}
573 575
574 576
@@ -579,13 +581,13 @@ opstart_get_handle_transport(void *cls)
579 * @param cls the cache entry 581 * @param cls the cache entry
580 */ 582 */
581static void 583static void
582oprelease_get_handle_transport(void *cls) 584oprelease_get_handle_transport (void *cls)
583{ 585{
584 struct PooledConnection *entry = cls; 586 struct PooledConnection *entry = cls;
585 587
586 if (NULL == entry->handle_transport) 588 if (NULL == entry->handle_transport)
587 return; 589 return;
588 GNUNET_TRANSPORT_core_disconnect(entry->handle_transport); 590 GNUNET_TRANSPORT_core_disconnect (entry->handle_transport);
589 entry->handle_transport = NULL; 591 entry->handle_transport = NULL;
590} 592}
591 593
@@ -599,14 +601,14 @@ oprelease_get_handle_transport(void *cls)
599 * @return peer 601 * @return peer
600 */ 602 */
601static void * 603static void *
602core_peer_connect_cb(void *cls, 604core_peer_connect_cb (void *cls,
603 const struct GNUNET_PeerIdentity *peer, 605 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq) 606 struct GNUNET_MQ_Handle *mq)
605{ 607{
606 struct PooledConnection *entry = cls; 608 struct PooledConnection *entry = cls;
607 609
608 peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); 610 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE);
609 return (void *)peer; 611 return (void *) peer;
610} 612}
611 613
612 614
@@ -623,27 +625,27 @@ core_peer_connect_cb(void *cls,
623 * @param my_identity ID of this peer, NULL if we failed 625 * @param my_identity ID of this peer, NULL if we failed
624 */ 626 */
625static void 627static void
626core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) 628core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
627{ 629{
628 struct PooledConnection *entry = cls; 630 struct PooledConnection *entry = cls;
629 631
630 if (NULL == my_identity) 632 if (NULL == my_identity)
631 { 633 {
632 GNUNET_break(0); 634 GNUNET_break (0);
633 return; 635 return;
634 } 636 }
635 GNUNET_assert(NULL == entry->peer_identity); 637 GNUNET_assert (NULL == entry->peer_identity);
636 entry->peer_identity = GNUNET_new(struct GNUNET_PeerIdentity); 638 entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity);
637 *entry->peer_identity = *my_identity; 639 *entry->peer_identity = *my_identity;
638 if (0 == entry->demand) 640 if (0 == entry->demand)
639 return; 641 return;
640 if (NULL != entry->notify_task) 642 if (NULL != entry->notify_task)
641 return; 643 return;
642 if (NULL != search_waiting(entry, entry->head_waiting)) 644 if (NULL != search_waiting (entry, entry->head_waiting))
643 { 645 {
644 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 646 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
645 return; 647 return;
646 } 648 }
647} 649}
648 650
649 651
@@ -654,19 +656,19 @@ core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
654 * @param cls the #PooledConnection object 656 * @param cls the #PooledConnection object
655 */ 657 */
656static void 658static void
657opstart_get_handle_core(void *cls) 659opstart_get_handle_core (void *cls)
658{ 660{
659 struct PooledConnection *entry = cls; 661 struct PooledConnection *entry = cls;
660 662
661 GNUNET_assert(NULL != entry); 663 GNUNET_assert (NULL != entry);
662 LOG_DEBUG("Opening a CORE connection to peer %u\n", entry->index); 664 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index);
663 entry->handle_core = 665 entry->handle_core =
664 GNUNET_CORE_connect(entry->cfg, 666 GNUNET_CORE_connect (entry->cfg,
665 entry, /* closure */ 667 entry, /* closure */
666 &core_startup_cb, /* core startup notify */ 668 &core_startup_cb, /* core startup notify */
667 &core_peer_connect_cb, /* peer connect notify */ 669 &core_peer_connect_cb, /* peer connect notify */
668 NULL, /* peer disconnect notify */ 670 NULL, /* peer disconnect notify */
669 NULL); 671 NULL);
670} 672}
671 673
672 674
@@ -677,15 +679,15 @@ opstart_get_handle_core(void *cls)
677 * @param cls the #PooledConnection object 679 * @param cls the #PooledConnection object
678 */ 680 */
679static void 681static void
680oprelease_get_handle_core(void *cls) 682oprelease_get_handle_core (void *cls)
681{ 683{
682 struct PooledConnection *entry = cls; 684 struct PooledConnection *entry = cls;
683 685
684 if (NULL == entry->handle_core) 686 if (NULL == entry->handle_core)
685 return; 687 return;
686 GNUNET_CORE_disconnect(entry->handle_core); 688 GNUNET_CORE_disconnect (entry->handle_core);
687 entry->handle_core = NULL; 689 entry->handle_core = NULL;
688 GNUNET_free_non_null(entry->peer_identity); 690 GNUNET_free_non_null (entry->peer_identity);
689 entry->peer_identity = NULL; 691 entry->peer_identity = NULL;
690} 692}
691 693
@@ -697,11 +699,11 @@ oprelease_get_handle_core(void *cls)
697 * @param cls the #PooledConnection object 699 * @param cls the #PooledConnection object
698 */ 700 */
699static void 701static void
700opstart_get_handle_ats_connectivity(void *cls) 702opstart_get_handle_ats_connectivity (void *cls)
701{ 703{
702 struct PooledConnection *entry = cls; 704 struct PooledConnection *entry = cls;
703 705
704 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init(entry->cfg); 706 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg);
705} 707}
706 708
707 709
@@ -712,13 +714,13 @@ opstart_get_handle_ats_connectivity(void *cls)
712 * @param cls the #PooledConnection object 714 * @param cls the #PooledConnection object
713 */ 715 */
714static void 716static void
715oprelease_get_handle_ats_connectivity(void *cls) 717oprelease_get_handle_ats_connectivity (void *cls)
716{ 718{
717 struct PooledConnection *entry = cls; 719 struct PooledConnection *entry = cls;
718 720
719 if (NULL == entry->handle_ats_connectivity) 721 if (NULL == entry->handle_ats_connectivity)
720 return; 722 return;
721 GNUNET_ATS_connectivity_done(entry->handle_ats_connectivity); 723 GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity);
722 entry->handle_ats_connectivity = NULL; 724 entry->handle_ats_connectivity = NULL;
723} 725}
724 726
@@ -734,12 +736,12 @@ oprelease_get_handle_ats_connectivity(void *cls)
734 * #GNUNET_NO if not. 736 * #GNUNET_NO if not.
735 */ 737 */
736static int 738static int
737cleanup_iterator(void *cls, uint32_t key, void *value) 739cleanup_iterator (void *cls, uint32_t key, void *value)
738{ 740{
739 struct PooledConnection *entry = value; 741 struct PooledConnection *entry = value;
740 742
741 GNUNET_assert(NULL != entry); 743 GNUNET_assert (NULL != entry);
742 destroy_pooled_connection(entry); 744 destroy_pooled_connection (entry);
743 return GNUNET_YES; 745 return GNUNET_YES;
744} 746}
745 747
@@ -752,13 +754,13 @@ cleanup_iterator(void *cls, uint32_t key, void *value)
752 * #GST_ConnectionPool_Service 754 * #GST_ConnectionPool_Service
753 */ 755 */
754void 756void
755GST_connection_pool_init(unsigned int size) 757GST_connection_pool_init (unsigned int size)
756{ 758{
757 max_size = size; 759 max_size = size;
758 if (0 == max_size) 760 if (0 == max_size)
759 return; 761 return;
760 GNUNET_assert(NULL == map); 762 GNUNET_assert (NULL == map);
761 map = GNUNET_CONTAINER_multihashmap32_create(((size * 3) / 4) + 1); 763 map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1);
762} 764}
763 765
764 766
@@ -766,24 +768,24 @@ GST_connection_pool_init(unsigned int size)
766 * Cleanup the connection pool 768 * Cleanup the connection pool
767 */ 769 */
768void 770void
769GST_connection_pool_destroy() 771GST_connection_pool_destroy ()
770{ 772{
771 struct PooledConnection *entry; 773 struct PooledConnection *entry;
772 774
773 if (NULL != map) 775 if (NULL != map)
774 { 776 {
775 GNUNET_assert( 777 GNUNET_assert (
776 GNUNET_SYSERR != 778 GNUNET_SYSERR !=
777 GNUNET_CONTAINER_multihashmap32_iterate(map, &cleanup_iterator, NULL)); 779 GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL));
778 GNUNET_CONTAINER_multihashmap32_destroy(map); 780 GNUNET_CONTAINER_multihashmap32_destroy (map);
779 map = NULL; 781 map = NULL;
780 } 782 }
781 while (NULL != (entry = head_lru)) 783 while (NULL != (entry = head_lru))
782 { 784 {
783 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 785 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
784 destroy_pooled_connection(entry); 786 destroy_pooled_connection (entry);
785 } 787 }
786 GNUNET_assert(NULL == head_not_pooled); 788 GNUNET_assert (NULL == head_not_pooled);
787} 789}
788 790
789 791
@@ -820,7 +822,7 @@ GST_connection_pool_destroy()
820 * longer being used 822 * longer being used
821 */ 823 */
822struct GST_ConnectionPool_GetHandle * 824struct GST_ConnectionPool_GetHandle *
823GST_connection_pool_get_handle( 825GST_connection_pool_get_handle (
824 unsigned int peer_id, 826 unsigned int peer_id,
825 const struct GNUNET_CONFIGURATION_Handle *cfg, 827 const struct GNUNET_CONFIGURATION_Handle *cfg,
826 enum GST_ConnectionPool_Service service, 828 enum GST_ConnectionPool_Service service,
@@ -836,66 +838,66 @@ GST_connection_pool_get_handle(
836 void *handle; 838 void *handle;
837 uint32_t peer_id32; 839 uint32_t peer_id32;
838 840
839 peer_id32 = (uint32_t)peer_id; 841 peer_id32 = (uint32_t) peer_id;
840 handle = NULL; 842 handle = NULL;
841 entry = NULL; 843 entry = NULL;
842 if (NULL != map) 844 if (NULL != map)
843 entry = GNUNET_CONTAINER_multihashmap32_get(map, peer_id32); 845 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
844 if (NULL != entry) 846 if (NULL != entry)
847 {
848 if (entry->in_lru)
845 { 849 {
846 if (entry->in_lru) 850 GNUNET_assert (0 == entry->demand);
847 { 851 expire_task_cancel (entry);
848 GNUNET_assert(0 == entry->demand); 852 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
849 expire_task_cancel(entry); 853 entry->in_lru = GNUNET_NO;
850 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 854 }
851 entry->in_lru = GNUNET_NO; 855 switch (service)
852 } 856 {
853 switch (service) 857 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
854 { 858 handle = entry->handle_transport;
855 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 859 if (NULL != handle)
856 handle = entry->handle_transport; 860 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index);
857 if (NULL != handle) 861 break;
858 LOG_DEBUG("Found TRANSPORT handle for peer %u\n", entry->index); 862
859 break; 863 case GST_CONNECTIONPOOL_SERVICE_CORE:
860 864 handle = entry->handle_core;
861 case GST_CONNECTIONPOOL_SERVICE_CORE: 865 if (NULL != handle)
862 handle = entry->handle_core; 866 LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index);
863 if (NULL != handle) 867 break;
864 LOG_DEBUG("Found CORE handle for peer %u\n", entry->index); 868
865 break; 869 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
866 870 handle = entry->handle_ats_connectivity;
867 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 871 if (NULL != handle)
868 handle = entry->handle_ats_connectivity; 872 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
869 if (NULL != handle) 873 break;
870 LOG_DEBUG("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
871 break;
872 }
873 } 874 }
875 }
874 else 876 else
877 {
878 entry = GNUNET_new (struct PooledConnection);
879 entry->index = peer_id32;
880 if ((NULL != map) &&
881 (GNUNET_CONTAINER_multihashmap32_size (map) < max_size))
882 {
883 GNUNET_assert (GNUNET_OK ==
884 GNUNET_CONTAINER_multihashmap32_put (
885 map,
886 entry->index,
887 entry,
888 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
889 entry->in_pool = GNUNET_YES;
890 }
891 else
875 { 892 {
876 entry = GNUNET_new(struct PooledConnection); 893 GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled,
877 entry->index = peer_id32; 894 tail_not_pooled,
878 if ((NULL != map) && 895 entry);
879 (GNUNET_CONTAINER_multihashmap32_size(map) < max_size))
880 {
881 GNUNET_assert(GNUNET_OK ==
882 GNUNET_CONTAINER_multihashmap32_put(
883 map,
884 entry->index,
885 entry,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
887 entry->in_pool = GNUNET_YES;
888 }
889 else
890 {
891 GNUNET_CONTAINER_DLL_insert_tail(head_not_pooled,
892 tail_not_pooled,
893 entry);
894 }
895 entry->cfg = GNUNET_CONFIGURATION_dup(cfg);
896 } 896 }
897 entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
898 }
897 entry->demand++; 899 entry->demand++;
898 gh = GNUNET_new(struct GST_ConnectionPool_GetHandle); 900 gh = GNUNET_new (struct GST_ConnectionPool_GetHandle);
899 gh->entry = entry; 901 gh->entry = entry;
900 gh->cb = cb; 902 gh->cb = cb;
901 gh->cb_cls = cb_cls; 903 gh->cb_cls = cb_cls;
@@ -903,50 +905,50 @@ GST_connection_pool_get_handle(
903 gh->connect_notify_cb = connect_notify_cb; 905 gh->connect_notify_cb = connect_notify_cb;
904 gh->connect_notify_cb_cls = connect_notify_cb_cls; 906 gh->connect_notify_cb_cls = connect_notify_cb_cls;
905 gh->service = service; 907 gh->service = service;
906 GNUNET_CONTAINER_DLL_insert(entry->head_waiting, entry->tail_waiting, gh); 908 GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh);
907 if (NULL != handle) 909 if (NULL != handle)
910 {
911 if (NULL == entry->notify_task)
908 { 912 {
909 if (NULL == entry->notify_task) 913 if (NULL != search_waiting (entry, entry->head_waiting))
910 { 914 entry->notify_task =
911 if (NULL != search_waiting(entry, entry->head_waiting)) 915 GNUNET_SCHEDULER_add_now (&connection_ready, entry);
912 entry->notify_task =
913 GNUNET_SCHEDULER_add_now(&connection_ready, entry);
914 }
915 return gh;
916 } 916 }
917 return gh;
918 }
917 op = NULL; 919 op = NULL;
918 switch (gh->service) 920 switch (gh->service)
919 { 921 {
920 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 922 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
921 if (NULL != entry->op_transport) 923 if (NULL != entry->op_transport)
922 return gh; /* Operation pending */ 924 return gh; /* Operation pending */
923 op = GNUNET_TESTBED_operation_create_(entry, 925 op = GNUNET_TESTBED_operation_create_ (entry,
924 &opstart_get_handle_transport, 926 &opstart_get_handle_transport,
925 &oprelease_get_handle_transport); 927 &oprelease_get_handle_transport);
926 entry->op_transport = op; 928 entry->op_transport = op;
927 break; 929 break;
928 930
929 case GST_CONNECTIONPOOL_SERVICE_CORE: 931 case GST_CONNECTIONPOOL_SERVICE_CORE:
930 if (NULL != entry->op_core) 932 if (NULL != entry->op_core)
931 return gh; /* Operation pending */ 933 return gh; /* Operation pending */
932 op = GNUNET_TESTBED_operation_create_(entry, 934 op = GNUNET_TESTBED_operation_create_ (entry,
933 &opstart_get_handle_core, 935 &opstart_get_handle_core,
934 &oprelease_get_handle_core); 936 &oprelease_get_handle_core);
935 entry->op_core = op; 937 entry->op_core = op;
936 break; 938 break;
937 939
938 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 940 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
939 if (NULL != entry->op_ats_connectivity) 941 if (NULL != entry->op_ats_connectivity)
940 return gh; /* Operation pending */ 942 return gh; /* Operation pending */
941 op = 943 op =
942 GNUNET_TESTBED_operation_create_(entry, 944 GNUNET_TESTBED_operation_create_ (entry,
943 &opstart_get_handle_ats_connectivity, 945 &opstart_get_handle_ats_connectivity,
944 &oprelease_get_handle_ats_connectivity); 946 &oprelease_get_handle_ats_connectivity);
945 entry->op_ats_connectivity = op; 947 entry->op_ats_connectivity = op;
946 break; 948 break;
947 } 949 }
948 GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, op); 950 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
949 GNUNET_TESTBED_operation_begin_wait_(op); 951 GNUNET_TESTBED_operation_begin_wait_ (op);
950 return gh; 952 return gh;
951} 953}
952 954
@@ -964,66 +966,66 @@ GST_connection_pool_get_handle(
964 * @param gh the handle 966 * @param gh the handle
965 */ 967 */
966void 968void
967GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh) 969GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
968{ 970{
969 struct PooledConnection *entry; 971 struct PooledConnection *entry;
970 972
971 if (NULL == gh) 973 if (NULL == gh)
972 return; 974 return;
973 entry = gh->entry; 975 entry = gh->entry;
974 LOG_DEBUG("Cleaning up get handle %p for service %u, peer %u\n", 976 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
975 gh, 977 gh,
976 gh->service, 978 gh->service,
977 entry->index); 979 entry->index);
978 if (!gh->connection_ready_called) 980 if (! gh->connection_ready_called)
981 {
982 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
983 if ((NULL == search_waiting (entry, entry->head_waiting)) &&
984 (NULL != entry->notify_task))
979 { 985 {
980 GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); 986 GNUNET_SCHEDULER_cancel (entry->notify_task);
981 if ((NULL == search_waiting(entry, entry->head_waiting)) && 987 entry->notify_task = NULL;
982 (NULL != entry->notify_task))
983 {
984 GNUNET_SCHEDULER_cancel(entry->notify_task);
985 entry->notify_task = NULL;
986 }
987 } 988 }
989 }
988 if (gh->notify_waiting) 990 if (gh->notify_waiting)
989 { 991 {
990 GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); 992 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
991 gh->notify_waiting = 0; 993 gh->notify_waiting = 0;
992 } 994 }
993 GNUNET_free(gh); 995 GNUNET_free (gh);
994 gh = NULL; 996 gh = NULL;
995 GNUNET_assert(!entry->in_lru); 997 GNUNET_assert (! entry->in_lru);
996 if (!entry->in_pool) 998 if (! entry->in_pool)
997 GNUNET_CONTAINER_DLL_remove(head_not_pooled, tail_not_pooled, entry); 999 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
998 if (NULL != map) 1000 if (NULL != map)
1001 {
1002 if (GNUNET_YES ==
1003 GNUNET_CONTAINER_multihashmap32_contains (map, entry->index))
1004 goto unallocate;
1005 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
999 { 1006 {
1000 if (GNUNET_YES == 1007 if (NULL == head_lru)
1001 GNUNET_CONTAINER_multihashmap32_contains(map, entry->index))
1002 goto unallocate; 1008 goto unallocate;
1003 if (GNUNET_CONTAINER_multihashmap32_size(map) == max_size) 1009 destroy_pooled_connection (head_lru);
1004 {
1005 if (NULL == head_lru)
1006 goto unallocate;
1007 destroy_pooled_connection(head_lru);
1008 }
1009 GNUNET_assert(GNUNET_OK ==
1010 GNUNET_CONTAINER_multihashmap32_put(
1011 map,
1012 entry->index,
1013 entry,
1014 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1015 entry->in_pool = GNUNET_YES;
1016 } 1010 }
1011 GNUNET_assert (GNUNET_OK ==
1012 GNUNET_CONTAINER_multihashmap32_put (
1013 map,
1014 entry->index,
1015 entry,
1016 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1017 entry->in_pool = GNUNET_YES;
1018 }
1017 1019
1018unallocate: 1020unallocate:
1019 GNUNET_assert(0 < entry->demand); 1021 GNUNET_assert (0 < entry->demand);
1020 entry->demand--; 1022 entry->demand--;
1021 if (0 != entry->demand) 1023 if (0 != entry->demand)
1022 return; 1024 return;
1023 if (entry->in_pool) 1025 if (entry->in_pool)
1024 { 1026 {
1025 add_to_lru(entry); 1027 add_to_lru (entry);
1026 return; 1028 return;
1027 } 1029 }
1028 destroy_pooled_connection(entry); 1030 destroy_pooled_connection (entry);
1029} 1031}