2 This file is part of GNUnet.
3 Copyright (C) 2008--2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file testbed/gnunet-service-testbed_connectionpool.c
21 * @brief connection pooling for connections to peers' services
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 #include "gnunet-service-testbed.h"
26 #include "gnunet-service-testbed_connectionpool.h"
27 #include "testbed_api_operations.h"
28 #include "gnunet_transport_core_service.h"
31 * Redefine LOG with a changed log component string
36 #define LOG(kind,...) \
37 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__)
41 * Time to expire a cache entry
43 #define CACHE_EXPIRY \
44 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
48 * The request handle for obtaining a pooled connection
50 struct GST_ConnectionPool_GetHandle;
56 struct PooledConnection
59 * Next ptr for placing this object in the DLL of least recently used pooled
62 struct PooledConnection *next;
65 * Prev ptr for placing this object in the DLL of the least recently used
68 struct PooledConnection *prev;
71 * The transport handle to the peer corresponding to this entry; can be NULL
73 struct GNUNET_TRANSPORT_CoreHandle *handle_transport;
76 * The core handle to the peer corresponding to this entry; can be NULL
78 struct GNUNET_CORE_Handle *handle_core;
81 * The ATS handle to the peer correspondign to this entry; can be NULL.
83 struct GNUNET_ATS_ConnectivityHandle *handle_ats_connectivity;
86 * The operation handle for transport handle
88 struct GNUNET_TESTBED_Operation *op_transport;
91 * The operation handle for core handle
93 struct GNUNET_TESTBED_Operation *op_core;
96 * The operation handle for ATS handle
98 struct GNUNET_TESTBED_Operation *op_ats_connectivity;
101 * The peer identity of this peer. Will be set upon opening a connection to
102 * the peers CORE service. Will be NULL until then and after the CORE
103 * connection is closed
105 struct GNUNET_PeerIdentity *peer_identity;
108 * The configuration of the peer. Should be not NULL as long as the core_handle
109 * or transport_handle are valid
111 struct GNUNET_CONFIGURATION_Handle *cfg;
114 * DLL head for the queue to serve notifications when a peer is connected
116 struct GST_ConnectionPool_GetHandle *head_notify;
119 * DLL tail for the queue to serve notifications when a peer is connected
121 struct GST_ConnectionPool_GetHandle *tail_notify;
124 * DLL head for the queue of #GST_ConnectionPool_GetHandle requests that are
125 * waiting for this connection to be opened
127 struct GST_ConnectionPool_GetHandle *head_waiting;
130 * DLL tail for the queue of #GST_ConnectionPool_GetHandle requests that are
131 * waiting for this connection to be opened
133 struct GST_ConnectionPool_GetHandle *tail_waiting;
136 * The task to expire this connection from the connection pool
138 struct GNUNET_SCHEDULER_Task * expire_task;
141 * The task to notify a waiting #GST_ConnectionPool_GetHandle object
143 struct GNUNET_SCHEDULER_Task * notify_task;
146 * Number of active requests using this pooled connection
151 * Is this entry in LRU
156 * Is this entry present in the connection pool
161 * The index of this peer
168 * The request handle for obtaining a pooled connection
170 struct GST_ConnectionPool_GetHandle
173 * The next ptr for inclusion in the notification DLLs. At first the object
174 * is placed in the waiting DLL of the corresponding #PooledConnection
175 * object. After the handle is opened it is moved to the notification DLL if
176 * @p connect_notify_cb and @p target are not NULL
178 struct GST_ConnectionPool_GetHandle *next;
181 * The prev ptr for inclusion in the notification DLLs
183 struct GST_ConnectionPool_GetHandle *prev;
186 * The pooled connection object this handle corresponds to
188 struct PooledConnection *entry;
191 * The cache callback to call when a handle is available
193 GST_connection_pool_connection_ready_cb cb;
196 * The closure for the above callback
201 * The peer identity of the target peer. When this target peer is connected,
202 * call the notify callback
204 const struct GNUNET_PeerIdentity *target;
207 * The callback to be called for serving notification that the target peer is
210 GST_connection_pool_peer_connect_notify connect_notify_cb;
213 * The closure for the notify callback
215 void *connect_notify_cb_cls;
218 * The service we want to connect to
220 enum GST_ConnectionPool_Service service;
223 * Did we call the pool_connection_ready_cb already?
225 int connection_ready_called;
228 * Are we waiting for any peer connect notifications?
235 * A hashmap for quickly finding connections in the connection pool
237 static struct GNUNET_CONTAINER_MultiHashMap32 *map;
240 * DLL head for maitaining the least recently used #PooledConnection objects.
241 * The head is the least recently used object.
243 static struct PooledConnection *head_lru;
246 * DLL tail for maitaining the least recently used #PooledConnection objects
248 static struct PooledConnection *tail_lru;
251 * DLL head for maintaining #PooledConnection objects that are not added into
252 * the connection pool as it was full at the time the object's creation
255 static struct PooledConnection *head_not_pooled;
258 * DLL tail for maintaining #PooledConnection objects that are not added into
259 * the connection pool as it was full at the time the object's creation
261 static struct PooledConnection *tail_not_pooled;
264 * The maximum number of entries that can be present in the connection pool
266 static unsigned int max_size;
270 * Cancel the expiration task of the give #PooledConnection object
272 * @param entry the #PooledConnection object
275 expire_task_cancel (struct PooledConnection *entry);
279 * Destroy a #PooledConnection object
281 * @param entry the #PooledConnection object
284 destroy_pooled_connection (struct PooledConnection *entry)
286 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify));
287 GNUNET_assert ((NULL == entry->head_waiting) && (NULL ==
288 entry->tail_waiting));
289 GNUNET_assert (0 == entry->demand);
290 expire_task_cancel (entry);
292 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
294 GNUNET_assert (GNUNET_OK ==
295 GNUNET_CONTAINER_multihashmap32_remove (map,
298 if (NULL != entry->notify_task)
300 GNUNET_SCHEDULER_cancel (entry->notify_task);
301 entry->notify_task = NULL;
303 LOG_DEBUG ("Cleaning up handles of a pooled connection\n");
304 if (NULL != entry->handle_transport)
305 GNUNET_assert (NULL != entry->op_transport);
306 if (NULL != entry->op_transport)
308 GNUNET_TESTBED_operation_done (entry->op_transport);
309 entry->op_transport = NULL;
311 if (NULL != entry->handle_ats_connectivity)
312 GNUNET_assert (NULL != entry->op_ats_connectivity);
313 if (NULL != entry->op_ats_connectivity)
315 GNUNET_TESTBED_operation_done (entry->op_ats_connectivity);
316 entry->op_ats_connectivity = NULL;
318 if (NULL != entry->op_core)
320 GNUNET_TESTBED_operation_done (entry->op_core);
321 entry->op_core = NULL;
323 GNUNET_assert (NULL == entry->handle_core);
324 GNUNET_assert (NULL == entry->handle_ats_connectivity);
325 GNUNET_assert (NULL == entry->handle_transport);
326 GNUNET_CONFIGURATION_destroy (entry->cfg);
332 * Expire a #PooledConnection object
334 * @param cls the #PooledConnection object
339 struct PooledConnection *entry = cls;
341 entry->expire_task = NULL;
342 destroy_pooled_connection (entry);
347 * Cancel the expiration task of the give #PooledConnection object
349 * @param entry the #PooledConnection object
352 expire_task_cancel (struct PooledConnection *entry)
354 if (NULL != entry->expire_task)
356 GNUNET_SCHEDULER_cancel (entry->expire_task);
357 entry->expire_task = NULL;
363 * Function to add a #PooledConnection object into LRU and begin the expiry task
365 * @param entry the #PooledConnection object
368 add_to_lru (struct PooledConnection *entry)
370 GNUNET_assert (0 == entry->demand);
371 GNUNET_assert (!entry->in_lru);
372 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry);
373 entry->in_lru = GNUNET_YES;
374 GNUNET_assert (NULL == entry->expire_task);
375 entry->expire_task = GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY,
381 * Function to find a #GST_ConnectionPool_GetHandle which is waiting for one of
382 * the handles in given entry which are now available.
384 * @param entry the pooled connection whose active list has to be searched
385 * @param head the starting list element in the GSTCacheGetHandle where the
386 * search has to be begin
387 * @return a suitable GSTCacheGetHandle whose handle ready notify callback
388 * hasn't been called yet. NULL if no such suitable GSTCacheGetHandle
391 static struct GST_ConnectionPool_GetHandle *
392 search_waiting (const struct PooledConnection *entry,
393 struct GST_ConnectionPool_GetHandle *head)
395 struct GST_ConnectionPool_GetHandle *gh;
397 for (gh = head; NULL != gh; gh = gh->next)
401 case GST_CONNECTIONPOOL_SERVICE_CORE:
402 if (NULL == entry->handle_core)
404 if (NULL == entry->peer_identity)
405 continue; /* CORE connection isn't ready yet */
407 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
408 if (NULL == entry->handle_transport)
411 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
412 if (NULL == entry->handle_ats_connectivity)
423 * A handle in the #PooledConnection object pointed by @a cls is ready and there
424 * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This
425 * function retrieves that object and calls the handle ready callback. It
426 * further schedules itself if there are similar waiting objects which can be notified.
428 * @param cls the #PooledConnection object
431 connection_ready (void *cls)
433 struct PooledConnection *entry = cls;
434 struct GST_ConnectionPool_GetHandle *gh;
435 struct GST_ConnectionPool_GetHandle *gh_next;
437 GNUNET_assert (NULL != entry->notify_task);
438 entry->notify_task = NULL;
439 gh = search_waiting (entry, entry->head_waiting);
440 GNUNET_assert (NULL != gh);
442 if (NULL != gh->next)
443 gh_next = search_waiting (entry, gh->next);
444 GNUNET_CONTAINER_DLL_remove (entry->head_waiting,
447 gh->connection_ready_called = 1;
449 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready,
451 if ( (NULL != gh->target) &&
452 (NULL != gh->connect_notify_cb) )
454 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify,
457 gh->notify_waiting = 1;
459 LOG_DEBUG ("Connection ready for handle type %u\n",
463 entry->handle_transport,
464 entry->handle_ats_connectivity,
465 entry->peer_identity,
471 * Function called from peer connect notify callbacks from CORE and TRANSPORT
472 * connections. This function calls the pending peer connect notify callbacks
473 * which are queued in an entry.
475 * @param cls the #PooledConnection object
476 * @param peer the peer that connected
477 * @param service the service where this notification has originated
480 peer_connect_notify_cb (void *cls,
481 const struct GNUNET_PeerIdentity *peer,
482 const enum GST_ConnectionPool_Service service)
484 struct PooledConnection *entry = cls;
485 struct GST_ConnectionPool_GetHandle *gh;
486 struct GST_ConnectionPool_GetHandle *gh_next;
487 GST_connection_pool_peer_connect_notify cb;
490 for (gh = entry->head_notify; NULL != gh;)
492 GNUNET_assert (NULL != gh->target);
493 GNUNET_assert (NULL != gh->connect_notify_cb);
494 GNUNET_assert (gh->connection_ready_called);
495 if (service != gh->service)
500 if (0 != memcmp (gh->target,
502 sizeof (struct GNUNET_PeerIdentity)))
507 cb = gh->connect_notify_cb;
508 cb_cls = gh->connect_notify_cb_cls;
510 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
511 gh->notify_waiting = 0;
512 LOG_DEBUG ("Peer connected to peer %u at service %u\n",
522 * Function called to notify transport users that another
523 * peer connected to us.
525 * @param cls the #PooledConnection object
526 * @param peer the peer that connected
527 * @param mq queue for sending data to @a peer
531 transport_peer_connect_notify_cb (void *cls,
532 const struct GNUNET_PeerIdentity *peer,
533 struct GNUNET_MQ_Handle *mq)
535 struct PooledConnection *entry = cls;
537 peer_connect_notify_cb (entry,
539 GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
545 * Function called when resources for opening a connection to TRANSPORT are
548 * @param cls the #PooledConnection object
551 opstart_get_handle_transport (void *cls)
553 struct PooledConnection *entry = cls;
555 GNUNET_assert (NULL != entry);
556 LOG_DEBUG ("Opening a transport connection to peer %u\n",
558 entry->handle_transport =
559 GNUNET_TRANSPORT_core_connect (entry->cfg,
563 &transport_peer_connect_notify_cb,
566 if (NULL == entry->handle_transport)
571 if (0 == entry->demand)
573 if (NULL != entry->notify_task)
575 if (NULL != search_waiting (entry, entry->head_waiting))
577 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
584 * Function called when the operation responsible for opening a TRANSPORT
585 * connection is marked as done.
587 * @param cls the cache entry
590 oprelease_get_handle_transport (void *cls)
592 struct PooledConnection *entry = cls;
594 if (NULL == entry->handle_transport)
596 GNUNET_TRANSPORT_core_disconnect (entry->handle_transport);
597 entry->handle_transport = NULL;
602 * Method called whenever a given peer connects at CORE level
604 * @param cls the #PooledConnection object
605 * @param peer peer identity this notification is about
606 * @param mq message queue for talking to @a peer
610 core_peer_connect_cb (void *cls,
611 const struct GNUNET_PeerIdentity *peer,
612 struct GNUNET_MQ_Handle *mq)
614 struct PooledConnection *entry = cls;
616 peer_connect_notify_cb (entry,
618 GST_CONNECTIONPOOL_SERVICE_CORE);
619 return (void *) peer;
624 * Function called after #GNUNET_CORE_connect() has succeeded (or failed
625 * for good). Note that the private key of the peer is intentionally
626 * not exposed here; if you need it, your process should try to read
627 * the private key file directly (which should work if you are
628 * authorized...). Implementations of this function must not call
629 * #GNUNET_CORE_disconnect() (other than by scheduling a new task to
632 * @param cls the #PooledConnection object
633 * @param my_identity ID of this peer, NULL if we failed
636 core_startup_cb (void *cls,
637 const struct GNUNET_PeerIdentity *my_identity)
639 struct PooledConnection *entry = cls;
641 if (NULL == my_identity)
646 GNUNET_assert (NULL == entry->peer_identity);
647 entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity);
648 *entry->peer_identity = *my_identity;
649 if (0 == entry->demand)
651 if (NULL != entry->notify_task)
653 if (NULL != search_waiting (entry, entry->head_waiting))
655 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
662 * Function called when resources for opening a connection to CORE are
665 * @param cls the #PooledConnection object
668 opstart_get_handle_core (void *cls)
670 struct PooledConnection *entry = cls;
672 GNUNET_assert (NULL != entry);
673 LOG_DEBUG ("Opening a CORE connection to peer %u\n",
676 = GNUNET_CORE_connect (entry->cfg,
678 &core_startup_cb, /* core startup notify */
679 &core_peer_connect_cb, /* peer connect notify */
680 NULL, /* peer disconnect notify */
686 * Function called when the operation responsible for opening a CORE
687 * connection is marked as done.
689 * @param cls the #PooledConnection object
692 oprelease_get_handle_core (void *cls)
694 struct PooledConnection *entry = cls;
696 if (NULL == entry->handle_core)
698 GNUNET_CORE_disconnect (entry->handle_core);
699 entry->handle_core = NULL;
700 GNUNET_free_non_null (entry->peer_identity);
701 entry->peer_identity = NULL;
706 * Function called when resources for opening a connection to ATS are
709 * @param cls the #PooledConnection object
712 opstart_get_handle_ats_connectivity (void *cls)
714 struct PooledConnection *entry = cls;
716 entry->handle_ats_connectivity =
717 GNUNET_ATS_connectivity_init (entry->cfg);
722 * Function called when the operation responsible for opening a ATS
723 * connection is marked as done.
725 * @param cls the #PooledConnection object
728 oprelease_get_handle_ats_connectivity (void *cls)
730 struct PooledConnection *entry = cls;
732 if (NULL == entry->handle_ats_connectivity)
734 GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity);
735 entry->handle_ats_connectivity = NULL;
740 * This function will be called for every #PooledConnection object in @p map
743 * @param key current key code
744 * @param value the #PooledConnection object
745 * @return #GNUNET_YES if we should continue to
750 cleanup_iterator (void *cls,
754 struct PooledConnection *entry = value;
756 GNUNET_assert (NULL != entry);
757 destroy_pooled_connection (entry);
763 * Initialise the connection pool.
765 * @param size the size of the connection pool. Each entry in the connection
766 * pool can handle a connection to each of the services enumerated in
767 * #GST_ConnectionPool_Service
770 GST_connection_pool_init (unsigned int size)
775 GNUNET_assert (NULL == map);
776 map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1);
781 * Cleanup the connection pool
784 GST_connection_pool_destroy ()
786 struct PooledConnection *entry;
790 GNUNET_assert (GNUNET_SYSERR !=
791 GNUNET_CONTAINER_multihashmap32_iterate (map,
794 GNUNET_CONTAINER_multihashmap32_destroy (map);
797 while (NULL != (entry = head_lru))
799 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
800 destroy_pooled_connection (entry);
802 GNUNET_assert (NULL == head_not_pooled);
807 * Get a connection handle to @a service. If the connection is opened before
808 * and the connection handle is present in the connection pool, it is returned
809 * through @a cb. @a peer_id is used for the lookup in the connection pool. If
810 * the connection handle is not present in the connection pool, a new connection
811 * handle is opened for the @a service using @a cfg. Additionally, @a target,
812 * @a connect_notify_cb can be specified to get notified when @a target is
813 * connected at @a service.
815 * @note @a connect_notify_cb will not be called if @a target is
816 * already connected @a service level. Use
817 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
818 * respective @a service's API to check if the target peer is already connected or
819 * not. @a connect_notify_cb will be called only once or never (in case @a target
820 * cannot be connected or is already connected).
822 * @param peer_id the index of the peer
823 * @param cfg the configuration with which the transport handle has to be
824 * created if it was not present in the cache
825 * @param service the service of interest
826 * @param cb the callback to notify when the transport handle is available
827 * @param cb_cls the closure for @a cb
828 * @param target the peer identify of the peer whose connection to our TRANSPORT
829 * subsystem will be notified through the @a connect_notify_cb. Can be NULL
830 * @param connect_notify_cb the callback to call when the @a target peer is
831 * connected. This callback will only be called once or never again (in
832 * case the target peer cannot be connected). Can be NULL
833 * @param connect_notify_cb_cls the closure for @a connect_notify_cb
834 * @return the handle which can be used cancel or mark that the handle is no
837 struct GST_ConnectionPool_GetHandle *
838 GST_connection_pool_get_handle (unsigned int peer_id,
839 const struct GNUNET_CONFIGURATION_Handle *cfg,
840 enum GST_ConnectionPool_Service service,
841 GST_connection_pool_connection_ready_cb cb,
843 const struct GNUNET_PeerIdentity *target,
844 GST_connection_pool_peer_connect_notify connect_notify_cb,
845 void *connect_notify_cb_cls)
847 struct GST_ConnectionPool_GetHandle *gh;
848 struct PooledConnection *entry;
849 struct GNUNET_TESTBED_Operation *op;
853 peer_id32 = (uint32_t) peer_id;
857 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
862 GNUNET_assert (0 == entry->demand);
863 expire_task_cancel (entry);
864 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
865 entry->in_lru = GNUNET_NO;
869 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
870 handle = entry->handle_transport;
872 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n",
875 case GST_CONNECTIONPOOL_SERVICE_CORE:
876 handle = entry->handle_core;
878 LOG_DEBUG ("Found CORE handle for peer %u\n",
881 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
882 handle = entry->handle_ats_connectivity;
884 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n",
891 entry = GNUNET_new (struct PooledConnection);
892 entry->index = peer_id32;
894 && (GNUNET_CONTAINER_multihashmap32_size (map) < max_size))
896 GNUNET_assert (GNUNET_OK ==
897 GNUNET_CONTAINER_multihashmap32_put (map,
900 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
901 entry->in_pool = GNUNET_YES;
905 GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled,
909 entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
912 gh = GNUNET_new (struct GST_ConnectionPool_GetHandle);
917 gh->connect_notify_cb = connect_notify_cb;
918 gh->connect_notify_cb_cls = connect_notify_cb_cls;
919 gh->service = service;
920 GNUNET_CONTAINER_DLL_insert (entry->head_waiting,
925 if (NULL == entry->notify_task)
927 if (NULL != search_waiting (entry, entry->head_waiting))
928 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready,
936 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
937 if (NULL != entry->op_transport)
938 return gh; /* Operation pending */
939 op = GNUNET_TESTBED_operation_create_ (entry,
940 &opstart_get_handle_transport,
941 &oprelease_get_handle_transport);
942 entry->op_transport = op;
944 case GST_CONNECTIONPOOL_SERVICE_CORE:
945 if (NULL != entry->op_core)
946 return gh; /* Operation pending */
947 op = GNUNET_TESTBED_operation_create_ (entry,
948 &opstart_get_handle_core,
949 &oprelease_get_handle_core);
952 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
953 if (NULL != entry->op_ats_connectivity)
954 return gh; /* Operation pending */
955 op = GNUNET_TESTBED_operation_create_ (entry,
956 &opstart_get_handle_ats_connectivity,
957 &oprelease_get_handle_ats_connectivity);
958 entry->op_ats_connectivity = op;
961 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds,
963 GNUNET_TESTBED_operation_begin_wait_ (op);
969 * Relinquish a #GST_ConnectionPool_GetHandle object. If the connection
970 * associated with the object is currently being used by other
971 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If
972 * no other objects are using the connection and the connection pool is not full
973 * then it is placed in a LRU queue. If the connection pool is full, then
974 * connections from the LRU queue are evicted and closed to create place for this
975 * connection. If the connection pool if full and the LRU queue is empty, then
976 * the connection is closed.
978 * @param gh the handle
981 GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
983 struct PooledConnection *entry;
988 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
990 gh->service, entry->index);
991 if (! gh->connection_ready_called)
993 GNUNET_CONTAINER_DLL_remove (entry->head_waiting,
996 if ( (NULL == search_waiting (entry, entry->head_waiting)) &&
997 (NULL != entry->notify_task) )
999 GNUNET_SCHEDULER_cancel (entry->notify_task);
1000 entry->notify_task = NULL;
1003 if (gh->notify_waiting)
1005 GNUNET_CONTAINER_DLL_remove (entry->head_notify,
1008 gh->notify_waiting = 0;
1012 GNUNET_assert (! entry->in_lru);
1013 if (! entry->in_pool)
1014 GNUNET_CONTAINER_DLL_remove (head_not_pooled,
1019 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map,
1022 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
1024 if (NULL == head_lru)
1026 destroy_pooled_connection (head_lru);
1028 GNUNET_assert (GNUNET_OK ==
1029 GNUNET_CONTAINER_multihashmap32_put (map,
1032 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1033 entry->in_pool = GNUNET_YES;
1037 GNUNET_assert (0 < entry->demand);
1039 if (0 != entry->demand)
1046 destroy_pooled_connection (entry);