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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file testbed/gnunet-service-testbed_connectionpool.c
23 * @brief connection pooling for connections to peers' services
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
27 #include "gnunet-service-testbed.h"
28 #include "gnunet-service-testbed_connectionpool.h"
29 #include "testbed_api_operations.h"
30 #include "gnunet_transport_service.h"
33 * Redefine LOG with a changed log component string
38 #define LOG(kind, ...) \
39 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__)
43 * Time to expire a cache entry
45 #define CACHE_EXPIRY \
46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
50 * The request handle for obtaining a pooled connection
52 struct GST_ConnectionPool_GetHandle;
58 struct PooledConnection
61 * Next ptr for placing this object in the DLL of least recently used pooled
64 struct PooledConnection *next;
67 * Prev ptr for placing this object in the DLL of the least recently used
70 struct PooledConnection *prev;
73 * The transport handle to the peer corresponding to this entry; can be NULL
75 struct GNUNET_TRANSPORT_CoreHandle *handle_transport;
78 * The core handle to the peer corresponding to this entry; can be NULL
80 struct GNUNET_CORE_Handle *handle_core;
83 * The ATS handle to the peer correspondign to this entry; can be NULL.
85 struct GNUNET_ATS_ConnectivityHandle *handle_ats_connectivity;
88 * The operation handle for transport handle
90 struct GNUNET_TESTBED_Operation *op_transport;
93 * The operation handle for core handle
95 struct GNUNET_TESTBED_Operation *op_core;
98 * The operation handle for ATS handle
100 struct GNUNET_TESTBED_Operation *op_ats_connectivity;
103 * The peer identity of this peer. Will be set upon opening a connection to
104 * the peers CORE service. Will be NULL until then and after the CORE
105 * connection is closed
107 struct GNUNET_PeerIdentity *peer_identity;
110 * The configuration of the peer. Should be not NULL as long as the
111 * core_handle or transport_handle are valid
113 struct GNUNET_CONFIGURATION_Handle *cfg;
116 * DLL head for the queue to serve notifications when a peer is connected
118 struct GST_ConnectionPool_GetHandle *head_notify;
121 * DLL tail for the queue to serve notifications when a peer is connected
123 struct GST_ConnectionPool_GetHandle *tail_notify;
126 * DLL head for the queue of #GST_ConnectionPool_GetHandle requests that are
127 * waiting for this connection to be opened
129 struct GST_ConnectionPool_GetHandle *head_waiting;
132 * DLL tail for the queue of #GST_ConnectionPool_GetHandle requests that are
133 * waiting for this connection to be opened
135 struct GST_ConnectionPool_GetHandle *tail_waiting;
138 * The task to expire this connection from the connection pool
140 struct GNUNET_SCHEDULER_Task *expire_task;
143 * The task to notify a waiting #GST_ConnectionPool_GetHandle object
145 struct GNUNET_SCHEDULER_Task *notify_task;
148 * Number of active requests using this pooled connection
153 * Is this entry in LRU
158 * Is this entry present in the connection pool
163 * The index of this peer
170 * The request handle for obtaining a pooled connection
172 struct GST_ConnectionPool_GetHandle
175 * The next ptr for inclusion in the notification DLLs. At first the object
176 * is placed in the waiting DLL of the corresponding #PooledConnection
177 * object. After the handle is opened it is moved to the notification DLL if
178 * @p connect_notify_cb and @p target are not NULL
180 struct GST_ConnectionPool_GetHandle *next;
183 * The prev ptr for inclusion in the notification DLLs
185 struct GST_ConnectionPool_GetHandle *prev;
188 * The pooled connection object this handle corresponds to
190 struct PooledConnection *entry;
193 * The cache callback to call when a handle is available
195 GST_connection_pool_connection_ready_cb cb;
198 * The closure for the above callback
203 * The peer identity of the target peer. When this target peer is connected,
204 * call the notify callback
206 const struct GNUNET_PeerIdentity *target;
209 * The callback to be called for serving notification that the target peer is
212 GST_connection_pool_peer_connect_notify connect_notify_cb;
215 * The closure for the notify callback
217 void *connect_notify_cb_cls;
220 * The service we want to connect to
222 enum GST_ConnectionPool_Service service;
225 * Did we call the pool_connection_ready_cb already?
227 int connection_ready_called;
230 * Are we waiting for any peer connect notifications?
237 * A hashmap for quickly finding connections in the connection pool
239 static struct GNUNET_CONTAINER_MultiHashMap32 *map;
242 * DLL head for maitaining the least recently used #PooledConnection objects.
243 * The head is the least recently used object.
245 static struct PooledConnection *head_lru;
248 * DLL tail for maitaining the least recently used #PooledConnection objects
250 static struct PooledConnection *tail_lru;
253 * DLL head for maintaining #PooledConnection objects that are not added into
254 * the connection pool as it was full at the time the object's creation
257 static struct PooledConnection *head_not_pooled;
260 * DLL tail for maintaining #PooledConnection objects that are not added into
261 * the connection pool as it was full at the time the object's creation
263 static struct PooledConnection *tail_not_pooled;
266 * The maximum number of entries that can be present in the connection pool
268 static unsigned int max_size;
272 * Cancel the expiration task of the give #PooledConnection object
274 * @param entry the #PooledConnection object
277 expire_task_cancel (struct PooledConnection *entry);
281 * Destroy a #PooledConnection object
283 * @param entry the #PooledConnection object
286 destroy_pooled_connection (struct PooledConnection *entry)
288 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify));
289 GNUNET_assert ((NULL == entry->head_waiting) &&
290 (NULL == entry->tail_waiting));
291 GNUNET_assert (0 == entry->demand);
292 expire_task_cancel (entry);
294 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
298 GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry));
299 if (NULL != entry->notify_task)
301 GNUNET_SCHEDULER_cancel (entry->notify_task);
302 entry->notify_task = NULL;
304 LOG_DEBUG ("Cleaning up handles of a pooled connection\n");
305 if (NULL != entry->handle_transport)
306 GNUNET_assert (NULL != entry->op_transport);
307 if (NULL != entry->op_transport)
309 GNUNET_TESTBED_operation_done (entry->op_transport);
310 entry->op_transport = NULL;
312 if (NULL != entry->handle_ats_connectivity)
313 GNUNET_assert (NULL != entry->op_ats_connectivity);
314 if (NULL != entry->op_ats_connectivity)
316 GNUNET_TESTBED_operation_done (entry->op_ats_connectivity);
317 entry->op_ats_connectivity = NULL;
319 if (NULL != entry->op_core)
321 GNUNET_TESTBED_operation_done (entry->op_core);
322 entry->op_core = NULL;
324 GNUNET_assert (NULL == entry->handle_core);
325 GNUNET_assert (NULL == entry->handle_ats_connectivity);
326 GNUNET_assert (NULL == entry->handle_transport);
327 GNUNET_CONFIGURATION_destroy (entry->cfg);
333 * Expire a #PooledConnection object
335 * @param cls the #PooledConnection object
340 struct PooledConnection *entry = cls;
342 entry->expire_task = NULL;
343 destroy_pooled_connection (entry);
348 * Cancel the expiration task of the give #PooledConnection object
350 * @param entry the #PooledConnection object
353 expire_task_cancel (struct PooledConnection *entry)
355 if (NULL != entry->expire_task)
357 GNUNET_SCHEDULER_cancel (entry->expire_task);
358 entry->expire_task = NULL;
364 * Function to add a #PooledConnection object into LRU and begin the expiry task
366 * @param entry the #PooledConnection object
369 add_to_lru (struct PooledConnection *entry)
371 GNUNET_assert (0 == entry->demand);
372 GNUNET_assert (! entry->in_lru);
373 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry);
374 entry->in_lru = GNUNET_YES;
375 GNUNET_assert (NULL == entry->expire_task);
377 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry);
382 * Function to find a #GST_ConnectionPool_GetHandle which is waiting for one of
383 * the handles in given entry which are now available.
385 * @param entry the pooled connection whose active list has to be searched
386 * @param head the starting list element in the GSTCacheGetHandle where the
387 * search has to be begin
388 * @return a suitable GSTCacheGetHandle whose handle ready notify callback
389 * hasn't been called yet. NULL if no such suitable GSTCacheGetHandle
392 static struct GST_ConnectionPool_GetHandle *
393 search_waiting (const struct PooledConnection *entry,
394 struct GST_ConnectionPool_GetHandle *head)
396 struct GST_ConnectionPool_GetHandle *gh;
398 for (gh = head; NULL != gh; gh = gh->next)
402 case GST_CONNECTIONPOOL_SERVICE_CORE:
403 if (NULL == entry->handle_core)
405 if (NULL == entry->peer_identity)
406 continue; /* CORE connection isn't ready yet */
408 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
409 if (NULL == entry->handle_transport)
412 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
413 if (NULL == entry->handle_ats_connectivity)
424 * A handle in the #PooledConnection object pointed by @a cls is ready and there
425 * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This
426 * function retrieves that object and calls the handle ready callback. It
427 * further schedules itself if there are similar waiting objects which can be
430 * @param cls the #PooledConnection object
433 connection_ready (void *cls)
435 struct PooledConnection *entry = cls;
436 struct GST_ConnectionPool_GetHandle *gh;
437 struct GST_ConnectionPool_GetHandle *gh_next;
439 GNUNET_assert (NULL != entry->notify_task);
440 entry->notify_task = NULL;
441 gh = search_waiting (entry, entry->head_waiting);
442 GNUNET_assert (NULL != gh);
444 if (NULL != gh->next)
445 gh_next = search_waiting (entry, gh->next);
446 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
447 gh->connection_ready_called = 1;
449 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
450 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb))
452 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify,
455 gh->notify_waiting = 1;
457 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
460 entry->handle_transport,
461 entry->handle_ats_connectivity,
462 entry->peer_identity,
468 * Function called from peer connect notify callbacks from CORE and TRANSPORT
469 * connections. This function calls the pending peer connect notify callbacks
470 * which are queued in an entry.
472 * @param cls the #PooledConnection object
473 * @param peer the peer that connected
474 * @param service the service where this notification has originated
477 peer_connect_notify_cb (void *cls,
478 const struct GNUNET_PeerIdentity *peer,
479 const enum GST_ConnectionPool_Service service)
481 struct PooledConnection *entry = cls;
482 struct GST_ConnectionPool_GetHandle *gh;
483 struct GST_ConnectionPool_GetHandle *gh_next;
484 GST_connection_pool_peer_connect_notify cb;
487 for (gh = entry->head_notify; NULL != gh;)
489 GNUNET_assert (NULL != gh->target);
490 GNUNET_assert (NULL != gh->connect_notify_cb);
491 GNUNET_assert (gh->connection_ready_called);
492 if (service != gh->service)
497 if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity)))
502 cb = gh->connect_notify_cb;
503 cb_cls = gh->connect_notify_cb_cls;
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",
517 * Function called to notify transport users that another
518 * peer connected to us.
520 * @param cls the #PooledConnection object
521 * @param peer the peer that connected
522 * @param mq queue for sending data to @a peer
526 transport_peer_connect_notify_cb (void *cls,
527 const struct GNUNET_PeerIdentity *peer,
528 struct GNUNET_MQ_Handle *mq)
530 struct PooledConnection *entry = cls;
532 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
538 * Function called when resources for opening a connection to TRANSPORT are
541 * @param cls the #PooledConnection object
544 opstart_get_handle_transport (void *cls)
546 struct PooledConnection *entry = cls;
548 GNUNET_assert (NULL != entry);
549 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index);
550 entry->handle_transport =
551 GNUNET_TRANSPORT_core_connect (entry->cfg,
555 &transport_peer_connect_notify_cb,
558 if (NULL == entry->handle_transport)
563 if (0 == entry->demand)
565 if (NULL != entry->notify_task)
567 if (NULL != search_waiting (entry, entry->head_waiting))
569 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
576 * Function called when the operation responsible for opening a TRANSPORT
577 * connection is marked as done.
579 * @param cls the cache entry
582 oprelease_get_handle_transport (void *cls)
584 struct PooledConnection *entry = cls;
586 if (NULL == entry->handle_transport)
588 GNUNET_TRANSPORT_core_disconnect (entry->handle_transport);
589 entry->handle_transport = NULL;
594 * Method called whenever a given peer connects at CORE level
596 * @param cls the #PooledConnection object
597 * @param peer peer identity this notification is about
598 * @param mq message queue for talking to @a peer
602 core_peer_connect_cb (void *cls,
603 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq)
606 struct PooledConnection *entry = cls;
608 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE);
609 return (void *) peer;
614 * Function called after #GNUNET_CORE_connect() has succeeded (or failed
615 * for good). Note that the private key of the peer is intentionally
616 * not exposed here; if you need it, your process should try to read
617 * the private key file directly (which should work if you are
618 * authorized...). Implementations of this function must not call
619 * #GNUNET_CORE_disconnect() (other than by scheduling a new task to
622 * @param cls the #PooledConnection object
623 * @param my_identity ID of this peer, NULL if we failed
626 core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
628 struct PooledConnection *entry = cls;
630 if (NULL == my_identity)
635 GNUNET_assert (NULL == entry->peer_identity);
636 entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity);
637 *entry->peer_identity = *my_identity;
638 if (0 == entry->demand)
640 if (NULL != entry->notify_task)
642 if (NULL != search_waiting (entry, entry->head_waiting))
644 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
651 * Function called when resources for opening a connection to CORE are
654 * @param cls the #PooledConnection object
657 opstart_get_handle_core (void *cls)
659 struct PooledConnection *entry = cls;
661 GNUNET_assert (NULL != entry);
662 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index);
664 GNUNET_CORE_connect (entry->cfg,
666 &core_startup_cb, /* core startup notify */
667 &core_peer_connect_cb, /* peer connect notify */
668 NULL, /* peer disconnect notify */
674 * Function called when the operation responsible for opening a CORE
675 * connection is marked as done.
677 * @param cls the #PooledConnection object
680 oprelease_get_handle_core (void *cls)
682 struct PooledConnection *entry = cls;
684 if (NULL == entry->handle_core)
686 GNUNET_CORE_disconnect (entry->handle_core);
687 entry->handle_core = NULL;
688 GNUNET_free_non_null (entry->peer_identity);
689 entry->peer_identity = NULL;
694 * Function called when resources for opening a connection to ATS are
697 * @param cls the #PooledConnection object
700 opstart_get_handle_ats_connectivity (void *cls)
702 struct PooledConnection *entry = cls;
704 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg);
709 * Function called when the operation responsible for opening a ATS
710 * connection is marked as done.
712 * @param cls the #PooledConnection object
715 oprelease_get_handle_ats_connectivity (void *cls)
717 struct PooledConnection *entry = cls;
719 if (NULL == entry->handle_ats_connectivity)
721 GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity);
722 entry->handle_ats_connectivity = NULL;
727 * This function will be called for every #PooledConnection object in @p map
730 * @param key current key code
731 * @param value the #PooledConnection object
732 * @return #GNUNET_YES if we should continue to
737 cleanup_iterator (void *cls, uint32_t key, void *value)
739 struct PooledConnection *entry = value;
741 GNUNET_assert (NULL != entry);
742 destroy_pooled_connection (entry);
748 * Initialise the connection pool.
750 * @param size the size of the connection pool. Each entry in the connection
751 * pool can handle a connection to each of the services enumerated in
752 * #GST_ConnectionPool_Service
755 GST_connection_pool_init (unsigned int size)
760 GNUNET_assert (NULL == map);
761 map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1);
766 * Cleanup the connection pool
769 GST_connection_pool_destroy ()
771 struct PooledConnection *entry;
777 GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL));
778 GNUNET_CONTAINER_multihashmap32_destroy (map);
781 while (NULL != (entry = head_lru))
783 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
784 destroy_pooled_connection (entry);
786 GNUNET_assert (NULL == head_not_pooled);
791 * Get a connection handle to @a service. If the connection is opened before
792 * and the connection handle is present in the connection pool, it is returned
793 * through @a cb. @a peer_id is used for the lookup in the connection pool. If
794 * the connection handle is not present in the connection pool, a new connection
795 * handle is opened for the @a service using @a cfg. Additionally, @a target,
796 * @a connect_notify_cb can be specified to get notified when @a target is
797 * connected at @a service.
799 * @note @a connect_notify_cb will not be called if @a target is
800 * already connected @a service level. Use
801 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
802 * respective @a service's API to check if the target peer is already connected
803 * or not. @a connect_notify_cb will be called only once or never (in case @a
804 * target cannot be connected or is already connected).
806 * @param peer_id the index of the peer
807 * @param cfg the configuration with which the transport handle has to be
808 * created if it was not present in the cache
809 * @param service the service of interest
810 * @param cb the callback to notify when the transport handle is available
811 * @param cb_cls the closure for @a cb
812 * @param target the peer identify of the peer whose connection to our TRANSPORT
813 * subsystem will be notified through the @a connect_notify_cb. Can be
815 * @param connect_notify_cb the callback to call when the @a target peer is
816 * connected. This callback will only be called once or never again (in
817 * case the target peer cannot be connected). Can be NULL
818 * @param connect_notify_cb_cls the closure for @a connect_notify_cb
819 * @return the handle which can be used cancel or mark that the handle is no
822 struct GST_ConnectionPool_GetHandle *
823 GST_connection_pool_get_handle (
824 unsigned int peer_id,
825 const struct GNUNET_CONFIGURATION_Handle *cfg,
826 enum GST_ConnectionPool_Service service,
827 GST_connection_pool_connection_ready_cb cb,
829 const struct GNUNET_PeerIdentity *target,
830 GST_connection_pool_peer_connect_notify connect_notify_cb,
831 void *connect_notify_cb_cls)
833 struct GST_ConnectionPool_GetHandle *gh;
834 struct PooledConnection *entry;
835 struct GNUNET_TESTBED_Operation *op;
839 peer_id32 = (uint32_t) peer_id;
843 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
848 GNUNET_assert (0 == entry->demand);
849 expire_task_cancel (entry);
850 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
851 entry->in_lru = GNUNET_NO;
855 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
856 handle = entry->handle_transport;
858 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index);
860 case GST_CONNECTIONPOOL_SERVICE_CORE:
861 handle = entry->handle_core;
863 LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index);
865 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
866 handle = entry->handle_ats_connectivity;
868 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
874 entry = GNUNET_new (struct PooledConnection);
875 entry->index = peer_id32;
877 (GNUNET_CONTAINER_multihashmap32_size (map) < max_size))
879 GNUNET_assert (GNUNET_OK ==
880 GNUNET_CONTAINER_multihashmap32_put (
884 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
885 entry->in_pool = GNUNET_YES;
889 GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled,
893 entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
896 gh = GNUNET_new (struct GST_ConnectionPool_GetHandle);
901 gh->connect_notify_cb = connect_notify_cb;
902 gh->connect_notify_cb_cls = connect_notify_cb_cls;
903 gh->service = service;
904 GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh);
907 if (NULL == entry->notify_task)
909 if (NULL != search_waiting (entry, entry->head_waiting))
911 GNUNET_SCHEDULER_add_now (&connection_ready, entry);
918 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
919 if (NULL != entry->op_transport)
920 return gh; /* Operation pending */
921 op = GNUNET_TESTBED_operation_create_ (entry,
922 &opstart_get_handle_transport,
923 &oprelease_get_handle_transport);
924 entry->op_transport = op;
926 case GST_CONNECTIONPOOL_SERVICE_CORE:
927 if (NULL != entry->op_core)
928 return gh; /* Operation pending */
929 op = GNUNET_TESTBED_operation_create_ (entry,
930 &opstart_get_handle_core,
931 &oprelease_get_handle_core);
934 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
935 if (NULL != entry->op_ats_connectivity)
936 return gh; /* Operation pending */
938 GNUNET_TESTBED_operation_create_ (entry,
939 &opstart_get_handle_ats_connectivity,
940 &oprelease_get_handle_ats_connectivity);
941 entry->op_ats_connectivity = op;
944 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
945 GNUNET_TESTBED_operation_begin_wait_ (op);
951 * Relinquish a #GST_ConnectionPool_GetHandle object. If the connection
952 * associated with the object is currently being used by other
953 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If
954 * no other objects are using the connection and the connection pool is not full
955 * then it is placed in a LRU queue. If the connection pool is full, then
956 * connections from the LRU queue are evicted and closed to create place for
957 * this connection. If the connection pool if full and the LRU queue is empty,
958 * then the connection is closed.
960 * @param gh the handle
963 GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
965 struct PooledConnection *entry;
970 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
974 if (! gh->connection_ready_called)
976 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
977 if ((NULL == search_waiting (entry, entry->head_waiting)) &&
978 (NULL != entry->notify_task))
980 GNUNET_SCHEDULER_cancel (entry->notify_task);
981 entry->notify_task = NULL;
984 if (gh->notify_waiting)
986 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
987 gh->notify_waiting = 0;
991 GNUNET_assert (! entry->in_lru);
992 if (! entry->in_pool)
993 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
997 GNUNET_CONTAINER_multihashmap32_contains (map, entry->index))
999 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
1001 if (NULL == head_lru)
1003 destroy_pooled_connection (head_lru);
1005 GNUNET_assert (GNUNET_OK ==
1006 GNUNET_CONTAINER_multihashmap32_put (
1010 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1011 entry->in_pool = GNUNET_YES;
1015 GNUNET_assert (0 < entry->demand);
1017 if (0 != entry->demand)
1024 destroy_pooled_connection (entry);