summaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_connectionpool.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-10-23 16:07:00 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-10-23 16:07:00 +0000
commit3c94b32f3ffb68b8660ebbf44b3f195c41d5372e (patch)
treee3d5af25e42fa6f5461644bcf7a8d85568ac6f1b /src/testbed/gnunet-service-testbed_connectionpool.c
parent3379c419925e151d86cad0fa7e9238330e5ae909 (diff)
downloadgnunet-3c94b32f3ffb68b8660ebbf44b3f195c41d5372e.tar.gz
gnunet-3c94b32f3ffb68b8660ebbf44b3f195c41d5372e.zip
- use pooled connections from connection pool module
Diffstat (limited to 'src/testbed/gnunet-service-testbed_connectionpool.c')
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c
index f4eb73778..158c9ec3a 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.c
+++ b/src/testbed/gnunet-service-testbed_connectionpool.c
@@ -214,6 +214,11 @@ struct GST_ConnectionPool_GetHandle
214 * Did we call the pool_connection_ready_cb already? 214 * Did we call the pool_connection_ready_cb already?
215 */ 215 */
216 int connection_ready_called; 216 int connection_ready_called;
217
218 /**
219 * Are we waiting for any peer connect notifications?
220 */
221 int notify_waiting;
217}; 222};
218 223
219 224
@@ -253,6 +258,15 @@ static unsigned int max_size;
253 258
254 259
255/** 260/**
261 * Cancel the expiration task of the give #PooledConnection object
262 *
263 * @param entry the #PooledConnection object
264 */
265static void
266expire_task_cancel (struct PooledConnection *entry);
267
268
269/**
256 * Destroy a #PooledConnection object 270 * Destroy a #PooledConnection object
257 * 271 *
258 * @param entry the #PooledConnection object 272 * @param entry the #PooledConnection object
@@ -264,7 +278,7 @@ destroy_pooled_connection (struct PooledConnection *entry)
264 GNUNET_assert ((NULL == entry->head_waiting) && (NULL == 278 GNUNET_assert ((NULL == entry->head_waiting) && (NULL ==
265 entry->tail_waiting)); 279 entry->tail_waiting));
266 GNUNET_assert (0 == entry->demand); 280 GNUNET_assert (0 == entry->demand);
267 GNUNET_free_non_null (entry->peer_identity); 281 expire_task_cancel (entry);
268 if (entry->in_lru) 282 if (entry->in_lru)
269 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); 283 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
270 if (entry->in_pool) 284 if (entry->in_pool)
@@ -308,6 +322,11 @@ expire (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
308} 322}
309 323
310 324
325/**
326 * Cancel the expiration task of the give #PooledConnection object
327 *
328 * @param entry the #PooledConnection object
329 */
311static void 330static void
312expire_task_cancel (struct PooledConnection *entry) 331expire_task_cancel (struct PooledConnection *entry)
313{ 332{
@@ -399,12 +418,16 @@ connection_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
399 if (NULL != gh->next) 418 if (NULL != gh->next)
400 gh_next = search_waiting (entry, gh->next); 419 gh_next = search_waiting (entry, gh->next);
401 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); 420 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
402 gh->connection_ready_called = GNUNET_YES; 421 gh->connection_ready_called = 1;
403 if (NULL != gh_next) 422 if (NULL != gh_next)
404 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); 423 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
405 if ( (NULL != gh->target) && (NULL != gh->connect_notify_cb) ) 424 if ( (NULL != gh->target) && (NULL != gh->connect_notify_cb) )
406 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, entry->tail_notify, gh); 425 {
407 LOG_DEBUG ("Calling notify for handle type %u\n", gh->service); 426 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, entry->tail_notify,
427 gh);
428 gh->notify_waiting = 1;
429 }
430 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
408 gh->cb (gh->cb_cls, entry->handle_core, entry->handle_transport, 431 gh->cb (gh->cb_cls, entry->handle_core, entry->handle_transport,
409 entry->peer_identity); 432 entry->peer_identity);
410} 433}
@@ -448,6 +471,8 @@ peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
448 cb_cls = gh->connect_notify_cb_cls; 471 cb_cls = gh->connect_notify_cb_cls;
449 gh_next = gh->next; 472 gh_next = gh->next;
450 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); 473 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
474 gh->notify_waiting = 0;
475 LOG_DEBUG ("Peer connected to peer %u at service %u\n", entry->index, gh->service);
451 gh = gh_next; 476 gh = gh_next;
452 cb (cb_cls, peer); 477 cb (cb_cls, peer);
453 } 478 }
@@ -644,10 +669,6 @@ cleanup_iterator (void *cls,
644 struct PooledConnection *entry = value; 669 struct PooledConnection *entry = value;
645 670
646 GNUNET_assert (NULL != entry); 671 GNUNET_assert (NULL != entry);
647 GNUNET_assert (GNUNET_OK ==
648 GNUNET_CONTAINER_multihashmap32_remove (map, key, entry));
649 if (entry->in_lru)
650 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
651 destroy_pooled_connection (entry); 672 destroy_pooled_connection (entry);
652 return GNUNET_YES; 673 return GNUNET_YES;
653} 674}
@@ -693,6 +714,7 @@ GST_connection_pool_destroy ()
693 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); 714 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
694 destroy_pooled_connection (entry); 715 destroy_pooled_connection (entry);
695 } 716 }
717 GNUNET_assert (NULL == head_not_pooled);
696} 718}
697 719
698 720
@@ -744,6 +766,7 @@ GST_connection_pool_get_handle (unsigned int peer_id,
744 uint32_t peer_id32; 766 uint32_t peer_id32;
745 767
746 peer_id32 = (uint32_t) peer_id; 768 peer_id32 = (uint32_t) peer_id;
769 handle = NULL;
747 entry = NULL; 770 entry = NULL;
748 if (NULL != map) 771 if (NULL != map)
749 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32); 772 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
@@ -853,10 +876,16 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
853 struct PooledConnection *entry; 876 struct PooledConnection *entry;
854 877
855 entry = gh->entry; 878 entry = gh->entry;
879 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
880 gh,
881 gh->service, entry->index);
856 if (!gh->connection_ready_called) 882 if (!gh->connection_ready_called)
857 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); 883 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
858 else if ((NULL != gh->next) || (NULL != gh->prev)) 884 if (gh->notify_waiting)
859 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->head_notify, gh); 885 {
886 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
887 gh->notify_waiting = 0;
888 }
860 GNUNET_free (gh); 889 GNUNET_free (gh);
861 gh = NULL; 890 gh = NULL;
862 GNUNET_assert (!entry->in_lru); 891 GNUNET_assert (!entry->in_lru);
@@ -865,10 +894,12 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
865 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map, 894 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map,
866 entry->index)) 895 entry->index))
867 goto unallocate; 896 goto unallocate;
868 if ((GNUNET_CONTAINER_multihashmap32_size (map) == max_size) 897 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
869 && (NULL == head_lru)) 898 {
870 goto unallocate; 899 if (NULL == head_lru)
871 destroy_pooled_connection (head_lru); 900 goto unallocate;
901 destroy_pooled_connection (head_lru);
902 }
872 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry); 903 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
873 GNUNET_assert (GNUNET_OK == 904 GNUNET_assert (GNUNET_OK ==
874 GNUNET_CONTAINER_multihashmap32_put (map, 905 GNUNET_CONTAINER_multihashmap32_put (map,