connection pooling for connections to peers' services More...
#include "platform.h"
#include "gnunet-service-testbed.h"
#include "gnunet-service-testbed_connectionpool.h"
#include "testbed_api_operations.h"
#include "gnunet_transport_service.h"
Go to the source code of this file.
Data Structures | |
struct | PooledConnection |
A pooled connection. More... | |
struct | GST_ConnectionPool_GetHandle |
The request handle for obtaining a pooled connection. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) |
Redefine LOG with a changed log component string. More... | |
#define | CACHE_EXPIRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
Time to expire a cache entry. More... | |
Functions | |
static void | expire_task_cancel (struct PooledConnection *entry) |
Cancel the expiration task of the give PooledConnection object. More... | |
static void | destroy_pooled_connection (struct PooledConnection *entry) |
Destroy a PooledConnection object. More... | |
static void | expire (void *cls) |
Expire a PooledConnection object. More... | |
static void | add_to_lru (struct PooledConnection *entry) |
Function to add a PooledConnection object into LRU and begin the expiry task. More... | |
static struct GST_ConnectionPool_GetHandle * | search_waiting (const struct PooledConnection *entry, struct GST_ConnectionPool_GetHandle *head) |
Function to find a GST_ConnectionPool_GetHandle which is waiting for one of the handles in given entry which are now available. More... | |
static void | connection_ready (void *cls) |
A handle in the PooledConnection object pointed by cls is ready and there is a GST_ConnectionPool_GetHandle object waiting in the waiting list. More... | |
static void | peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer, const enum GST_ConnectionPool_Service service) |
Function called from peer connect notify callbacks from CORE and TRANSPORT connections. More... | |
static void * | transport_peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq) |
Function called to notify transport users that another peer connected to us. More... | |
static void | opstart_get_handle_transport (void *cls) |
Function called when resources for opening a connection to TRANSPORT are available. More... | |
static void | oprelease_get_handle_transport (void *cls) |
Function called when the operation responsible for opening a TRANSPORT connection is marked as done. More... | |
static void * | core_peer_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq) |
Method called whenever a given peer connects at CORE level. More... | |
static void | core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
Function called after GNUNET_CORE_connect() has succeeded (or failed for good). More... | |
static void | opstart_get_handle_core (void *cls) |
Function called when resources for opening a connection to CORE are available. More... | |
static void | oprelease_get_handle_core (void *cls) |
Function called when the operation responsible for opening a CORE connection is marked as done. More... | |
static void | opstart_get_handle_ats_connectivity (void *cls) |
Function called when resources for opening a connection to ATS are available. More... | |
static void | oprelease_get_handle_ats_connectivity (void *cls) |
Function called when the operation responsible for opening a ATS connection is marked as done. More... | |
static int | cleanup_iterator (void *cls, uint32_t key, void *value) |
This function will be called for every PooledConnection object in map . More... | |
void | GST_connection_pool_init (unsigned int size) |
Initialise the connection pool. More... | |
void | GST_connection_pool_destroy () |
Cleanup the connection pool. More... | |
struct GST_ConnectionPool_GetHandle * | GST_connection_pool_get_handle (unsigned int peer_id, const struct GNUNET_CONFIGURATION_Handle *cfg, enum GST_ConnectionPool_Service service, GST_connection_pool_connection_ready_cb cb, void *cb_cls, const struct GNUNET_PeerIdentity *target, GST_connection_pool_peer_connect_notify connect_notify_cb, void *connect_notify_cb_cls) |
Get a connection handle to service. More... | |
void | GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) |
Relinquish a GST_ConnectionPool_GetHandle object. More... | |
Variables | |
static struct GNUNET_CONTAINER_MultiHashMap32 * | map |
A hashmap for quickly finding connections in the connection pool. More... | |
static struct PooledConnection * | head_lru |
DLL head for maitaining the least recently used PooledConnection objects. More... | |
static struct PooledConnection * | tail_lru |
DLL tail for maitaining the least recently used PooledConnection objects. More... | |
static struct PooledConnection * | head_not_pooled |
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it was full at the time the object's creation FIXME. More... | |
static struct PooledConnection * | tail_not_pooled |
DLL tail for maintaining PooledConnection objects that are not added into the connection pool as it was full at the time the object's creation. More... | |
static unsigned int | max_size |
The maximum number of entries that can be present in the connection pool. More... | |
connection pooling for connections to peers' services
Definition in file gnunet-service-testbed_connectionpool.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) |
Redefine LOG with a changed log component string.
Definition at line 39 of file gnunet-service-testbed_connectionpool.c.
#define CACHE_EXPIRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
Time to expire a cache entry.
Definition at line 46 of file gnunet-service-testbed_connectionpool.c.
|
static |
Cancel the expiration task of the give PooledConnection object.
entry | the PooledConnection object |
Definition at line 354 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::expire_task, and GNUNET_SCHEDULER_cancel().
Referenced by destroy_pooled_connection(), and GST_connection_pool_get_handle().
|
static |
Destroy a PooledConnection object.
entry | the PooledConnection object |
Definition at line 287 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::cfg, PooledConnection::demand, expire_task_cancel(), GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_TESTBED_operation_done(), PooledConnection::handle_ats_connectivity, PooledConnection::handle_core, PooledConnection::handle_transport, head_lru, PooledConnection::head_notify, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, map, PooledConnection::notify_task, PooledConnection::op_ats_connectivity, PooledConnection::op_core, PooledConnection::op_transport, tail_lru, PooledConnection::tail_notify, and PooledConnection::tail_waiting.
Referenced by cleanup_iterator(), expire(), GST_connection_pool_destroy(), and GST_connection_pool_get_handle_done().
|
static |
Expire a PooledConnection object.
cls | the PooledConnection object |
Definition at line 339 of file gnunet-service-testbed_connectionpool.c.
References destroy_pooled_connection(), and PooledConnection::expire_task.
Referenced by add_to_lru().
|
static |
Function to add a PooledConnection object into LRU and begin the expiry task.
entry | the PooledConnection object |
Definition at line 370 of file gnunet-service-testbed_connectionpool.c.
References CACHE_EXPIRY, PooledConnection::demand, expire(), PooledConnection::expire_task, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, head_lru, PooledConnection::in_lru, and tail_lru.
Referenced by GST_connection_pool_get_handle_done().
|
static |
Function to find a GST_ConnectionPool_GetHandle which is waiting for one of the handles in given entry which are now available.
entry | the pooled connection whose active list has to be searched |
head | the starting list element in the GSTCacheGetHandle where the search has to be begin |
Definition at line 394 of file gnunet-service-testbed_connectionpool.c.
References GST_ConnectionPool_GetHandle::entry, gh, GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, GST_CONNECTIONPOOL_SERVICE_CORE, GST_CONNECTIONPOOL_SERVICE_TRANSPORT, PooledConnection::handle_ats_connectivity, PooledConnection::handle_core, PooledConnection::handle_transport, head, and PooledConnection::peer_identity.
Referenced by connection_ready(), core_startup_cb(), GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), and opstart_get_handle_transport().
|
static |
A handle in the PooledConnection object pointed by cls is ready and there is a GST_ConnectionPool_GetHandle object waiting in the waiting list.
This function retrieves that object and calls the handle ready callback. It further schedules itself if there are similar waiting objects which can be notified.
cls | the PooledConnection object |
Definition at line 436 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::cfg, GST_ConnectionPool_GetHandle::entry, gh, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_SCHEDULER_add_now(), PooledConnection::handle_ats_connectivity, PooledConnection::handle_core, PooledConnection::handle_transport, PooledConnection::head_notify, PooledConnection::head_waiting, PooledConnection::index, LOG_DEBUG, PooledConnection::notify_task, PooledConnection::peer_identity, search_waiting(), PooledConnection::tail_notify, and PooledConnection::tail_waiting.
Referenced by core_startup_cb(), GST_connection_pool_get_handle(), and opstart_get_handle_transport().
|
static |
Function called from peer connect notify callbacks from CORE and TRANSPORT connections.
This function calls the pending peer connect notify callbacks which are queued in an entry.
cls | the PooledConnection object |
peer | the peer that connected |
service | the service where this notification has originated |
Definition at line 485 of file gnunet-service-testbed_connectionpool.c.
References GST_ConnectionPool_GetHandle::cb, GST_ConnectionPool_GetHandle::cb_cls, GST_ConnectionPool_GetHandle::entry, gh, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, PooledConnection::head_notify, PooledConnection::index, LOG_DEBUG, peer, service, and PooledConnection::tail_notify.
Referenced by core_peer_connect_cb(), and transport_peer_connect_notify_cb().
|
static |
Function called to notify transport users that another peer connected to us.
cls | the PooledConnection object |
peer | the peer that connected |
mq | queue for sending data to peer |
Definition at line 534 of file gnunet-service-testbed_connectionpool.c.
References GST_CONNECTIONPOOL_SERVICE_TRANSPORT, peer, and peer_connect_notify_cb().
Referenced by opstart_get_handle_transport().
|
static |
Function called when resources for opening a connection to TRANSPORT are available.
cls | the PooledConnection object |
Definition at line 552 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::cfg, connection_ready(), PooledConnection::demand, GNUNET_assert, GNUNET_break, GNUNET_SCHEDULER_add_now(), GNUNET_TRANSPORT_core_connect(), PooledConnection::handle_transport, PooledConnection::head_waiting, PooledConnection::index, LOG_DEBUG, PooledConnection::notify_task, search_waiting(), and transport_peer_connect_notify_cb().
Referenced by GST_connection_pool_get_handle().
|
static |
Function called when the operation responsible for opening a TRANSPORT connection is marked as done.
cls | the cache entry |
Definition at line 590 of file gnunet-service-testbed_connectionpool.c.
References GNUNET_TRANSPORT_core_disconnect(), and PooledConnection::handle_transport.
Referenced by GST_connection_pool_get_handle().
|
static |
Method called whenever a given peer connects at CORE level.
cls | the PooledConnection object |
peer | peer identity this notification is about |
mq | message queue for talking to peer |
Definition at line 610 of file gnunet-service-testbed_connectionpool.c.
References GST_CONNECTIONPOOL_SERVICE_CORE, peer, and peer_connect_notify_cb().
Referenced by opstart_get_handle_core().
|
static |
Function called after GNUNET_CORE_connect() has succeeded (or failed for good).
Note that the private key of the peer is intentionally not exposed here; if you need it, your process should try to read the private key file directly (which should work if you are authorized...). Implementations of this function must not call GNUNET_CORE_disconnect() (other than by scheduling a new task to do this later).
cls | the PooledConnection object |
my_identity | ID of this peer, NULL if we failed |
Definition at line 634 of file gnunet-service-testbed_connectionpool.c.
References connection_ready(), PooledConnection::demand, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_now(), PooledConnection::head_waiting, PooledConnection::index, my_identity, PooledConnection::notify_task, PooledConnection::peer_identity, and search_waiting().
Referenced by opstart_get_handle_core().
|
static |
Function called when resources for opening a connection to CORE are available.
cls | the PooledConnection object |
Definition at line 670 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::cfg, core_peer_connect_cb(), core_startup_cb(), GNUNET_assert, GNUNET_CORE_connect(), PooledConnection::handle_core, PooledConnection::index, and LOG_DEBUG.
Referenced by GST_connection_pool_get_handle().
|
static |
Function called when the operation responsible for opening a CORE connection is marked as done.
cls | the PooledConnection object |
Definition at line 693 of file gnunet-service-testbed_connectionpool.c.
References GNUNET_CORE_disconnect(), GNUNET_free, PooledConnection::handle_core, and PooledConnection::peer_identity.
Referenced by GST_connection_pool_get_handle().
|
static |
Function called when resources for opening a connection to ATS are available.
cls | the PooledConnection object |
Definition at line 713 of file gnunet-service-testbed_connectionpool.c.
References PooledConnection::cfg, GNUNET_ATS_connectivity_init(), and PooledConnection::handle_ats_connectivity.
Referenced by GST_connection_pool_get_handle().
|
static |
Function called when the operation responsible for opening a ATS connection is marked as done.
cls | the PooledConnection object |
Definition at line 728 of file gnunet-service-testbed_connectionpool.c.
References GNUNET_ATS_connectivity_done(), and PooledConnection::handle_ats_connectivity.
Referenced by GST_connection_pool_get_handle().
|
static |
This function will be called for every PooledConnection object in map
.
cls | NULL |
key | current key code |
value | the PooledConnection object |
Definition at line 750 of file gnunet-service-testbed_connectionpool.c.
References destroy_pooled_connection(), GNUNET_assert, GNUNET_YES, and value.
Referenced by GST_connection_pool_destroy().
void GST_connection_pool_init | ( | unsigned int | size | ) |
Initialise the connection pool.
size | the size of the connection pool. Each entry in the connection pool can handle a connection to each of the services enumerated in GST_ConnectionPool_Service |
Definition at line 768 of file gnunet-service-testbed_connectionpool.c.
References GNUNET_assert, GNUNET_CONTAINER_multihashmap32_create(), map, max_size, and size.
Referenced by testbed_run().
void GST_connection_pool_destroy | ( | void | ) |
Cleanup the connection pool.
Definition at line 782 of file gnunet-service-testbed_connectionpool.c.
References cleanup_iterator(), destroy_pooled_connection(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap32_destroy(), GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_SYSERR, head_lru, head_not_pooled, map, and tail_lru.
Referenced by shutdown_task().
struct GST_ConnectionPool_GetHandle* GST_connection_pool_get_handle | ( | unsigned int | peer_id, |
const struct GNUNET_CONFIGURATION_Handle * | cfg, | ||
enum GST_ConnectionPool_Service | service, | ||
GST_connection_pool_connection_ready_cb | cb, | ||
void * | cb_cls, | ||
const struct GNUNET_PeerIdentity * | target, | ||
GST_connection_pool_peer_connect_notify | connect_notify_cb, | ||
void * | connect_notify_cb_cls | ||
) |
Get a connection handle to service.
If the connection is opened before and the connection handle is present in the connection pool, it is returned through cb. peer_id is used for the lookup in the connection pool. If the connection handle is not present in the connection pool, a new connection handle is opened for the service using cfg. Additionally, target, connect_notify_cb can be specified to get notified when target is connected at service.
peer_id | the index of the peer |
cfg | the configuration with which the transport handle has to be created if it was not present in the cache |
service | the service of interest |
cb | the callback to notify when the transport handle is available |
cb_cls | the closure for cb |
target | the peer identify of the peer whose connection to our TRANSPORT subsystem will be notified through the connect_notify_cb. Can be NULL |
connect_notify_cb | the callback to call when the target peer is connected. This callback will only be called once or never again (in case the target peer cannot be connected). Can be NULL |
connect_notify_cb_cls | the closure for connect_notify_cb |
Definition at line 836 of file gnunet-service-testbed_connectionpool.c.
References GNUNET_TESTBED_Operation::cb_cls, cfg, PooledConnection::cfg, connection_ready(), PooledConnection::demand, expire_task_cancel(), gh, GNUNET_assert, GNUNET_CONFIGURATION_dup(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap32_get(), GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_multihashmap32_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_TESTBED_operation_begin_wait_(), GNUNET_TESTBED_operation_create_(), GNUNET_TESTBED_operation_queue_insert_(), GNUNET_YES, GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, GST_CONNECTIONPOOL_SERVICE_CORE, GST_CONNECTIONPOOL_SERVICE_TRANSPORT, GST_opq_openfds, handle, PooledConnection::handle_ats_connectivity, PooledConnection::handle_core, PooledConnection::handle_transport, head_lru, head_not_pooled, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, map, max_size, PooledConnection::notify_task, op, PooledConnection::op_ats_connectivity, PooledConnection::op_core, PooledConnection::op_transport, oprelease_get_handle_ats_connectivity(), oprelease_get_handle_core(), oprelease_get_handle_transport(), opstart_get_handle_ats_connectivity(), opstart_get_handle_core(), opstart_get_handle_transport(), peer_id, search_waiting(), service, tail_lru, tail_not_pooled, and PooledConnection::tail_waiting.
Referenced by handle_overlay_connect(), handle_remote_overlay_connect(), occ_cache_get_handle_core_cb(), occ_hello_sent_cb(), overlay_connect_get_config(), p2_transport_connect(), and rocc_hello_sent_cb().
void GST_connection_pool_get_handle_done | ( | struct GST_ConnectionPool_GetHandle * | gh | ) |
Relinquish a GST_ConnectionPool_GetHandle object.
If the connection associated with the object is currently being used by other GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If no other objects are using the connection and the connection pool is not full then it is placed in a LRU queue. If the connection pool is full, then connections from the LRU queue are evicted and closed to create place for this connection. If the connection pool if full and the LRU queue is empty, then the connection is closed.
gh | the handle |
Definition at line 983 of file gnunet-service-testbed_connectionpool.c.
References add_to_lru(), PooledConnection::demand, destroy_pooled_connection(), gh, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap32_contains(), GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_multihashmap32_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, head_lru, head_not_pooled, PooledConnection::head_notify, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, map, max_size, PooledConnection::notify_task, search_waiting(), tail_not_pooled, PooledConnection::tail_notify, and PooledConnection::tail_waiting.
Referenced by cleanup_occ(), cleanup_occ_lp2c(), cleanup_rocc(), and hello_update_cb().
|
static |
A hashmap for quickly finding connections in the connection pool.
Definition at line 240 of file gnunet-service-testbed_connectionpool.c.
Referenced by destroy_pooled_connection(), GST_connection_pool_destroy(), GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), and GST_connection_pool_init().
|
static |
DLL head for maitaining the least recently used PooledConnection objects.
The head is the least recently used object.
Definition at line 246 of file gnunet-service-testbed_connectionpool.c.
Referenced by add_to_lru(), destroy_pooled_connection(), GST_connection_pool_destroy(), GST_connection_pool_get_handle(), and GST_connection_pool_get_handle_done().
|
static |
DLL tail for maitaining the least recently used PooledConnection objects.
Definition at line 251 of file gnunet-service-testbed_connectionpool.c.
Referenced by add_to_lru(), destroy_pooled_connection(), GST_connection_pool_destroy(), and GST_connection_pool_get_handle().
|
static |
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it was full at the time the object's creation FIXME.
Definition at line 258 of file gnunet-service-testbed_connectionpool.c.
Referenced by GST_connection_pool_destroy(), GST_connection_pool_get_handle(), and GST_connection_pool_get_handle_done().
|
static |
DLL tail for maintaining PooledConnection objects that are not added into the connection pool as it was full at the time the object's creation.
Definition at line 264 of file gnunet-service-testbed_connectionpool.c.
Referenced by GST_connection_pool_get_handle(), and GST_connection_pool_get_handle_done().
|
static |
The maximum number of entries that can be present in the connection pool.
Definition at line 269 of file gnunet-service-testbed_connectionpool.c.
Referenced by GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), and GST_connection_pool_init().