Interface for connection pooling subroutines. More...
#include "gnunet_ats_service.h"
#include "gnunet_core_service.h"
#include "gnunet_transport_service.h"
Go to the source code of this file.
Typedefs | |
typedef void(* | GST_connection_pool_connection_ready_cb) (void *cls, struct GNUNET_CORE_Handle *ch, struct GNUNET_TRANSPORT_CoreHandle *th, struct GNUNET_ATS_ConnectivityHandle *ac, const struct GNUNET_PeerIdentity *peer_id, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Functions of this type are called when the needed handle is available for usage. More... | |
typedef void(* | GST_connection_pool_peer_connect_notify) (void *cls, const struct GNUNET_PeerIdentity *target) |
Callback to notify when the target peer given to GST_connection_pool_get_handle() is connected. More... | |
Enumerations | |
enum | GST_ConnectionPool_Service { GST_CONNECTIONPOOL_SERVICE_TRANSPORT = 1 , GST_CONNECTIONPOOL_SERVICE_CORE , GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY } |
The type of service. More... | |
Functions | |
void | GST_connection_pool_init (unsigned int size) |
Initialise the connection pool. More... | |
void | GST_connection_pool_destroy (void) |
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... | |
Interface for connection pooling subroutines.
Definition in file gnunet-service-testbed_connectionpool.h.
typedef void(* GST_connection_pool_connection_ready_cb) (void *cls, struct GNUNET_CORE_Handle *ch, struct GNUNET_TRANSPORT_CoreHandle *th, struct GNUNET_ATS_ConnectivityHandle *ac, const struct GNUNET_PeerIdentity *peer_id, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Functions of this type are called when the needed handle is available for usage.
These functions are to be registered with the function GST_connection_pool_get_handle(). The corresponding handles will be set upon success. If they are not set, then it signals an error while opening the handles.
cls | the closure passed to GST_connection_pool_get_handle() |
ch | the handle to CORE. Can be NULL if it is not requested |
th | the handle to TRANSPORT. Can be NULL if it is not requested |
ac | the handle to ATS, can be NULL if it is not requested |
peer_id | the identity of the peer. Will be NULL if ch is NULL. In other cases, its value being NULL means that CORE connection has failed. |
cfg | configuration of the peer |
Definition at line 90 of file gnunet-service-testbed_connectionpool.h.
typedef void(* GST_connection_pool_peer_connect_notify) (void *cls, const struct GNUNET_PeerIdentity *target) |
Callback to notify when the target peer given to GST_connection_pool_get_handle() is connected.
cls | the closure given to GST_connection_pool_get_handle() for this callback |
target | the peer identity of the target peer |
Definition at line 107 of file gnunet-service-testbed_connectionpool.h.
The type of service.
Enumerator | |
---|---|
GST_CONNECTIONPOOL_SERVICE_TRANSPORT | Transport service. |
GST_CONNECTIONPOOL_SERVICE_CORE | Core service. |
GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY | ATS service. |
Definition at line 39 of file gnunet-service-testbed_connectionpool.h.
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().