38 #define LOG(kind, ...) \ 39 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) 45 #define CACHE_EXPIRY \ 46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 304 LOG_DEBUG (
"Cleaning up handles of a pooled connection\n");
398 for (gh = head; NULL !=
gh; gh = gh->
next)
446 if (NULL != gh->
next)
509 LOG_DEBUG (
"Peer connected to peer %u at service %u\n",
551 LOG_DEBUG (
"Opening a transport connection to peer %u\n", entry->
index);
611 return (
void *)
peer;
632 if (NULL == my_identity)
664 LOG_DEBUG (
"Opening a CORE connection to peer %u\n", entry->
index);
783 while (NULL != (entry = head_lru))
841 peer_id32 = (uint32_t) peer_id;
872 LOG_DEBUG (
"Found ATS CONNECTIVITY handle for peer %u\n", entry->
index);
879 entry->
index = peer_id32;
976 LOG_DEBUG (
"Cleaning up get handle %p for service %u, peer %u\n",
1007 if (NULL == head_lru)
static void add_to_lru(struct PooledConnection *entry)
Function to add a PooledConnection object into LRU and begin the expiry task.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void oprelease_get_handle_core(void *cls)
Function called when the operation responsible for opening a CORE connection is marked as done...
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
void * cb_cls
Closure for callbacks.
GST_connection_pool_peer_connect_notify connect_notify_cb
The callback to be called for serving notification that the target peer is connected.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static void destroy_pooled_connection(struct PooledConnection *entry)
Destroy a PooledConnection object.
static int cleanup_iterator(void *cls, uint32_t key, void *value)
This function will be called for every PooledConnection object in map.
internal API to access the 'operations' subsystem
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Context for the core service connection.
int notify_waiting
Are we waiting for any peer connect notifications?
data structures shared amongst components of TESTBED service
GST_ConnectionPool_Service
The type of service.
The request handle for obtaining a pooled connection.
struct GST_ConnectionPool_GetHandle * tail_notify
DLL tail for the queue to serve notifications when a peer is connected.
static struct PooledConnection * tail_lru
DLL tail for maitaining the least recently used PooledConnection objects.
static void expire(void *cls)
Expire a PooledConnection object.
const struct GNUNET_PeerIdentity * target
The peer identity of the target peer.
struct GNUNET_TESTBED_Operation * op_transport
The operation handle for transport handle.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
struct GST_ConnectionPool_GetHandle * tail_waiting
DLL tail for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
static void oprelease_get_handle_transport(void *cls)
Function called when the operation responsible for opening a TRANSPORT connection is marked as done...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void oprelease_get_handle_ats_connectivity(void *cls)
Function called when the operation responsible for opening a ATS connection is marked as done...
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, OperationRelease release)
Create an 'operation' to be performed.
int in_pool
Is this entry present in the connection pool.
void * connect_notify_cb_cls
The closure for the notify callback.
static void opstart_get_handle_transport(void *cls)
Function called when resources for opening a connection to TRANSPORT are available.
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).
static char * peer_id
Option –peer.
struct GNUNET_TESTBED_Operation * op_core
The operation handle for core handle.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GST_ConnectionPool_GetHandle * head_notify
DLL head for the queue to serve notifications when a peer is connected.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
struct GNUNET_SCHEDULER_Task * notify_task
The task to notify a waiting GST_ConnectionPool_GetHandle object.
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.
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.
int GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct OperationQueue * GST_opq_openfds
Operation queue for open file descriptors.
Opaque handle to an abstract operation to be executed by the testing framework.
uint32_t index
The index of this peer.
struct PooledConnection * prev
Prev ptr for placing this object in the DLL of the least recently used pooled connections.
struct GNUNET_CORE_Handle * handle_core
The core handle to the peer corresponding to this entry; can be NULL.
struct GNUNET_PeerIdentity * peer_identity
The peer identity of this peer.
static void connection_ready(void *cls)
A handle in the PooledConnection object pointed by cls is ready and there is a GST_ConnectionPool_Get...
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 entr...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
GST_connection_pool_connection_ready_cb cb
The cache callback to call when a handle is available.
int GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static char * value
Value of the record to add/remove.
unsigned int demand
Number of active requests using this pooled connection.
int GNUNET_CONTAINER_multihashmap32_contains(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Check if the map contains any value under the given key (including values that are NULL)...
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
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...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
unsigned int GNUNET_CONTAINER_multihashmap32_size(const struct GNUNET_CONTAINER_MultiHashMap32 *map)
Get the number of key-value pairs in the map.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
enum GST_ConnectionPool_Service service
The service we want to connect to.
struct GST_ConnectionPool_GetHandle * head_waiting
DLL head for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
Internal representation of the hash map.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
static unsigned int max_size
The maximum number of entries that can be present in the connection pool.
struct PooledConnection * entry
The pooled connection object this handle corresponds to.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
struct GNUNET_TESTBED_Operation * op_ats_connectivity
The operation handle for ATS handle.
Interface for connection pooling subroutines.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
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.
static struct PooledConnection * head_not_pooled
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it w...
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Connect to the core service.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
static void opstart_get_handle_core(void *cls)
Function called when resources for opening a connection to CORE are available.
struct GST_ConnectionPool_GetHandle * prev
The prev ptr for inclusion in the notification DLLs.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void * cb_cls
The closure for the above callback.
#define CACHE_EXPIRY
Time to expire a cache entry.
static struct PooledConnection * tail_not_pooled
DLL tail for maintaining PooledConnection objects that are not added into the connection pool as it w...
struct GST_ConnectionPool_GetHandle * next
The next ptr for inclusion in the notification DLLs.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
Handle to a message queue.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
struct GNUNET_SCHEDULER_Task * expire_task
The task to expire this connection from the connection pool.
The identity of the host (wraps the signing key of the peer).
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
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.
static struct PendingResolutions * head
Head of list of pending resolution requests.
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.
int connection_ready_called
Did we call the pool_connection_ready_cb already?
int in_lru
Is this entry in LRU.
void GST_connection_pool_init(unsigned int size)
Initialise the connection pool.
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.
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
struct GNUNET_MQ_Handle * mq
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
Entry in list of pending tasks.
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
void GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh)
Relinquish a GST_ConnectionPool_GetHandle object.
struct PooledConnection * next
Next ptr for placing this object in the DLL of least recently used pooled connections.
static struct GNUNET_ARM_Operation * op
Current operation.
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
Handle for the transport service (includes all of the state for the transport service).
Handle to the ATS subsystem for connectivity management.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
static void opstart_get_handle_ats_connectivity(void *cls)
Function called when resources for opening a connection to ATS are available.
#define LOG_DEBUG(...)
Debug logging shorthand.
void GST_connection_pool_destroy()
Cleanup the connection pool.
#define GNUNET_free(ptr)
Wrapper around free.
static void expire_task_cancel(struct PooledConnection *entry)
Cancel the expiration task of the give PooledConnection object.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.