GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-testbed_connectionpool.c File Reference

connection pooling for connections to peers' services More...

#include "gnunet-service-testbed.h"
#include "gnunet-service-testbed_connectionpool.h"
#include "testbed_api_operations.h"
#include "gnunet_transport_service.h"
Include dependency graph for gnunet-service-testbed_connectionpool.c:

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_GetHandlesearch_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_GetHandleGST_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_MultiHashMap32map
 A hashmap for quickly finding connections in the connection pool. More...
 
static struct PooledConnectionhead_lru
 DLL head for maitaining the least recently used PooledConnection objects. More...
 
static struct PooledConnectiontail_lru
 DLL tail for maitaining the least recently used PooledConnection objects. More...
 
static struct PooledConnectionhead_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 PooledConnectiontail_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...
 

Detailed Description

connection pooling for connections to peers' services

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in

Definition in file gnunet-service-testbed_connectionpool.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__)

Redefine LOG with a changed log component string.

Definition at line 38 of file gnunet-service-testbed_connectionpool.c.

◆ CACHE_EXPIRY

Time to expire a cache entry.

Definition at line 45 of file gnunet-service-testbed_connectionpool.c.

Referenced by add_to_lru().

Function Documentation

◆ expire_task_cancel()

static void expire_task_cancel ( struct PooledConnection entry)
static

Cancel the expiration task of the give PooledConnection object.

Parameters
entrythe PooledConnection object

Definition at line 353 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().

354 {
355  if (NULL != entry->expire_task)
356  {
358  entry->expire_task = NULL;
359  }
360 }
struct GNUNET_SCHEDULER_Task * expire_task
The task to expire this connection from the connection pool.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_pooled_connection()

static void destroy_pooled_connection ( struct PooledConnection entry)
static

Destroy a PooledConnection object.

Parameters
entrythe PooledConnection object

Definition at line 286 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, PooledConnection::head_notify, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, PooledConnection::notify_task, PooledConnection::op_ats_connectivity, PooledConnection::op_core, PooledConnection::op_transport, PooledConnection::tail_notify, and PooledConnection::tail_waiting.

Referenced by cleanup_iterator(), expire(), GST_connection_pool_destroy(), and GST_connection_pool_get_handle_done().

287 {
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);
293  if (entry->in_lru)
295  if (entry->in_pool)
296  GNUNET_assert (
297  GNUNET_OK ==
299  if (NULL != entry->notify_task)
300  {
302  entry->notify_task = NULL;
303  }
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)
308  {
310  entry->op_transport = NULL;
311  }
312  if (NULL != entry->handle_ats_connectivity)
313  GNUNET_assert (NULL != entry->op_ats_connectivity);
314  if (NULL != entry->op_ats_connectivity)
315  {
317  entry->op_ats_connectivity = NULL;
318  }
319  if (NULL != entry->op_core)
320  {
322  entry->op_core = NULL;
323  }
324  GNUNET_assert (NULL == entry->handle_core);
325  GNUNET_assert (NULL == entry->handle_ats_connectivity);
326  GNUNET_assert (NULL == entry->handle_transport);
328  GNUNET_free (entry);
329 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
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.
struct GNUNET_TESTBED_Operation * op_transport
The operation handle for transport handle.
struct GST_ConnectionPool_GetHandle * tail_waiting
DLL tail for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
int in_pool
Is this entry present in the connection pool.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_TESTBED_Operation * op_core
The operation handle for core handle.
struct GST_ConnectionPool_GetHandle * head_notify
DLL head for the queue to serve notifications when a peer is connected.
struct GNUNET_SCHEDULER_Task * notify_task
The task to notify a waiting GST_ConnectionPool_GetHandle object.
uint32_t index
The index of this peer.
struct GNUNET_CORE_Handle * handle_core
The core handle to the peer corresponding to this entry; can be NULL.
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.
unsigned int demand
Number of active requests using this pooled connection.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GST_ConnectionPool_GetHandle * head_waiting
DLL head for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
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...
Definition: testbed_api.c:2020
struct GNUNET_TESTBED_Operation * op_ats_connectivity
The operation handle for ATS handle.
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
#define LOG_DEBUG(msg)
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
#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.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expire()

static void expire ( void *  cls)
static

Expire a PooledConnection object.

Parameters
clsthe PooledConnection object

Definition at line 338 of file gnunet-service-testbed_connectionpool.c.

References destroy_pooled_connection(), and PooledConnection::expire_task.

Referenced by add_to_lru(), and GNUNET_GNSRECORD_record_get_expiration_time().

339 {
340  struct PooledConnection *entry = cls;
341 
342  entry->expire_task = NULL;
344 }
static void destroy_pooled_connection(struct PooledConnection *entry)
Destroy a PooledConnection object.
struct GNUNET_SCHEDULER_Task * expire_task
The task to expire this connection from the connection pool.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_lru()

static void add_to_lru ( struct PooledConnection entry)
static

Function to add a PooledConnection object into LRU and begin the expiry task.

Parameters
entrythe PooledConnection object

Definition at line 369 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, and PooledConnection::in_lru.

Referenced by GST_connection_pool_get_handle_done().

370 {
371  GNUNET_assert (0 == entry->demand);
372  GNUNET_assert (! entry->in_lru);
374  entry->in_lru = GNUNET_YES;
375  GNUNET_assert (NULL == entry->expire_task);
376  entry->expire_task =
378 }
static struct PooledConnection * tail_lru
DLL tail for maitaining the least recently used PooledConnection objects.
static void expire(void *cls)
Expire a PooledConnection object.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
Definition: scheduler.c:1246
unsigned int demand
Number of active requests using this pooled connection.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define CACHE_EXPIRY
Time to expire a cache entry.
struct GNUNET_SCHEDULER_Task * expire_task
The task to expire this connection from the connection pool.
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_waiting()

static struct GST_ConnectionPool_GetHandle* search_waiting ( const struct PooledConnection entry,
struct GST_ConnectionPool_GetHandle head 
)
static

Function to find a GST_ConnectionPool_GetHandle which is waiting for one of the handles in given entry which are now available.

Parameters
entrythe pooled connection whose active list has to be searched
headthe starting list element in the GSTCacheGetHandle where the search has to be begin
Returns
a suitable GSTCacheGetHandle whose handle ready notify callback hasn't been called yet. NULL if no such suitable GSTCacheGetHandle is found

Definition at line 393 of file gnunet-service-testbed_connectionpool.c.

References gh, GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, GST_CONNECTIONPOOL_SERVICE_CORE, GST_CONNECTIONPOOL_SERVICE_TRANSPORT, PooledConnection::handle_ats_connectivity, PooledConnection::handle_core, PooledConnection::handle_transport, GST_ConnectionPool_GetHandle::next, PooledConnection::peer_identity, and GST_ConnectionPool_GetHandle::service.

Referenced by connection_ready(), core_startup_cb(), GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), and opstart_get_handle_transport().

395 {
397 
398  for (gh = head; NULL != gh; gh = gh->next)
399  {
400  switch (gh->service)
401  {
403  if (NULL == entry->handle_core)
404  continue;
405  if (NULL == entry->peer_identity)
406  continue; /* CORE connection isn't ready yet */
407  break;
409  if (NULL == entry->handle_transport)
410  continue;
411  break;
413  if (NULL == entry->handle_ats_connectivity)
414  continue;
415  break;
416  }
417  break;
418  }
419  return gh;
420 }
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
The request handle for obtaining a pooled connection.
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.
enum GST_ConnectionPool_Service service
The service we want to connect to.
struct GST_ConnectionPool_GetHandle * next
The next ptr for inclusion in the notification DLLs.
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
Here is the caller graph for this function:

◆ connection_ready()

static void connection_ready ( void *  cls)
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.

Parameters
clsthe PooledConnection object

Definition at line 433 of file gnunet-service-testbed_connectionpool.c.

References GST_ConnectionPool_GetHandle::cb, GST_ConnectionPool_GetHandle::cb_cls, PooledConnection::cfg, GST_ConnectionPool_GetHandle::connect_notify_cb, GST_ConnectionPool_GetHandle::connection_ready_called, 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, LOG_DEBUG, GST_ConnectionPool_GetHandle::next, PooledConnection::notify_task, GST_ConnectionPool_GetHandle::notify_waiting, PooledConnection::peer_identity, search_waiting(), GST_ConnectionPool_GetHandle::service, PooledConnection::tail_notify, PooledConnection::tail_waiting, and GST_ConnectionPool_GetHandle::target.

Referenced by core_startup_cb(), GST_connection_pool_get_handle(), and opstart_get_handle_transport().

434 {
435  struct PooledConnection *entry = cls;
437  struct GST_ConnectionPool_GetHandle *gh_next;
438 
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);
443  gh_next = NULL;
444  if (NULL != gh->next)
445  gh_next = search_waiting (entry, gh->next);
447  gh->connection_ready_called = 1;
448  if (NULL != gh_next)
450  if ((NULL != gh->target) && (NULL != gh->connect_notify_cb))
451  {
453  entry->tail_notify,
454  gh);
455  gh->notify_waiting = 1;
456  }
457  LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
458  gh->cb (gh->cb_cls,
459  entry->handle_core,
460  entry->handle_transport,
462  entry->peer_identity,
463  entry->cfg);
464 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
GST_connection_pool_peer_connect_notify connect_notify_cb
The callback to be called for serving notification that the target peer is connected.
int notify_waiting
Are we waiting for any peer connect notifications?
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.
const struct GNUNET_PeerIdentity * target
The peer identity of the target peer.
struct GST_ConnectionPool_GetHandle * tail_waiting
DLL tail for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
struct GST_ConnectionPool_GetHandle * head_notify
DLL head for the queue to serve notifications when a peer is connected.
struct GNUNET_SCHEDULER_Task * notify_task
The task to notify a waiting GST_ConnectionPool_GetHandle object.
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...
GST_connection_pool_connection_ready_cb cb
The cache callback to call when a handle is available.
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.
Definition: scheduler.c:1273
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 ...
#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.
struct GST_ConnectionPool_GetHandle * next
The next ptr for inclusion in the notification DLLs.
int connection_ready_called
Did we call the pool_connection_ready_cb already?
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
#define LOG_DEBUG(msg)
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_connect_notify_cb()

static void peer_connect_notify_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const enum GST_ConnectionPool_Service  service 
)
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.

Parameters
clsthe PooledConnection object
peerthe peer that connected
servicethe service where this notification has originated

Definition at line 477 of file gnunet-service-testbed_connectionpool.c.

References GST_ConnectionPool_GetHandle::cb, GST_ConnectionPool_GetHandle::cb_cls, GST_ConnectionPool_GetHandle::connect_notify_cb, GST_ConnectionPool_GetHandle::connect_notify_cb_cls, GST_ConnectionPool_GetHandle::connection_ready_called, gh, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, PooledConnection::head_notify, PooledConnection::index, LOG_DEBUG, GST_ConnectionPool_GetHandle::next, GST_ConnectionPool_GetHandle::notify_waiting, GST_ConnectionPool_GetHandle::service, PooledConnection::tail_notify, and GST_ConnectionPool_GetHandle::target.

Referenced by core_peer_connect_cb(), and transport_peer_connect_notify_cb().

480 {
481  struct PooledConnection *entry = cls;
483  struct GST_ConnectionPool_GetHandle *gh_next;
485  void *cb_cls;
486 
487  for (gh = entry->head_notify; NULL != gh;)
488  {
489  GNUNET_assert (NULL != gh->target);
490  GNUNET_assert (NULL != gh->connect_notify_cb);
492  if (service != gh->service)
493  {
494  gh = gh->next;
495  continue;
496  }
497  if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity)))
498  {
499  gh = gh->next;
500  continue;
501  }
502  cb = gh->connect_notify_cb;
503  cb_cls = gh->connect_notify_cb_cls;
504  gh_next = gh->next;
506  gh->notify_waiting = 0;
507  LOG_DEBUG ("Peer connected to peer %u at service %u\n",
508  entry->index,
509  gh->service);
510  gh = gh_next;
511  cb (cb_cls, peer);
512  }
513 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
int notify_waiting
Are we waiting for any peer connect notifications?
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.
const struct GNUNET_PeerIdentity * target
The peer identity of the target peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * connect_notify_cb_cls
The closure for the notify callback.
struct GST_ConnectionPool_GetHandle * head_notify
DLL head for the queue to serve notifications when a peer is connected.
uint32_t index
The index of this peer.
GST_connection_pool_connection_ready_cb cb
The cache callback to call when a handle is available.
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...
enum GST_ConnectionPool_Service service
The service we want to connect to.
void * cb_cls
The closure for the above callback.
struct GST_ConnectionPool_GetHandle * next
The next ptr for inclusion in the notification DLLs.
The identity of the host (wraps the signing key of the peer).
int connection_ready_called
Did we call the pool_connection_ready_cb already?
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
#define LOG_DEBUG(msg)
Here is the caller graph for this function:

◆ transport_peer_connect_notify_cb()

static void* transport_peer_connect_notify_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Function called to notify transport users that another peer connected to us.

Parameters
clsthe PooledConnection object
peerthe peer that connected
mqqueue for sending data to peer
Returns
NULL

Definition at line 526 of file gnunet-service-testbed_connectionpool.c.

References GST_CONNECTIONPOOL_SERVICE_TRANSPORT, and peer_connect_notify_cb().

Referenced by opstart_get_handle_transport().

529 {
530  struct PooledConnection *entry = cls;
531 
533  return NULL;
534 }
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_get_handle_transport()

static void opstart_get_handle_transport ( void *  cls)
static

Function called when resources for opening a connection to TRANSPORT are available.

Parameters
clsthe PooledConnection object

Definition at line 544 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().

545 {
546  struct PooledConnection *entry = cls;
547 
548  GNUNET_assert (NULL != entry);
549  LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index);
550  entry->handle_transport =
552  NULL,
553  NULL,
554  entry,
556  NULL,
557  NULL);
558  if (NULL == entry->handle_transport)
559  {
560  GNUNET_break (0);
561  return;
562  }
563  if (0 == entry->demand)
564  return;
565  if (NULL != entry->notify_task)
566  return;
567  if (NULL != search_waiting (entry, entry->head_waiting))
568  {
570  return;
571  }
572 }
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the 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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t index
The index 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...
unsigned int demand
Number of active requests using this pooled connection.
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.
Definition: scheduler.c:1273
struct GST_ConnectionPool_GetHandle * head_waiting
DLL head for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
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.
#define LOG_DEBUG(msg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_get_handle_transport()

static void oprelease_get_handle_transport ( void *  cls)
static

Function called when the operation responsible for opening a TRANSPORT connection is marked as done.

Parameters
clsthe cache entry

Definition at line 582 of file gnunet-service-testbed_connectionpool.c.

References GNUNET_TRANSPORT_core_disconnect(), and PooledConnection::handle_transport.

Referenced by GST_connection_pool_get_handle().

583 {
584  struct PooledConnection *entry = cls;
585 
586  if (NULL == entry->handle_transport)
587  return;
589  entry->handle_transport = NULL;
590 }
struct GNUNET_TRANSPORT_CoreHandle * handle_transport
The transport handle to the peer corresponding to this entry; can be NULL.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_peer_connect_cb()

static void* core_peer_connect_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Method called whenever a given peer connects at CORE level.

Parameters
clsthe PooledConnection object
peerpeer identity this notification is about
mqmessage queue for talking to peer
Returns
peer

Definition at line 602 of file gnunet-service-testbed_connectionpool.c.

References GST_CONNECTIONPOOL_SERVICE_CORE, peer, and peer_connect_notify_cb().

Referenced by opstart_get_handle_core().

605 {
606  struct PooledConnection *entry = cls;
607 
609  return (void *) peer;
610 }
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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_startup_cb()

static void core_startup_cb ( void *  cls,
const struct GNUNET_PeerIdentity my_identity 
)
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).

Parameters
clsthe PooledConnection object
my_identityID of this peer, NULL if we failed

Definition at line 626 of file gnunet-service-testbed_connectionpool.c.

References connection_ready(), PooledConnection::demand, GNUNET_assert, GNUNET_break, GNUNET_new, GNUNET_SCHEDULER_add_now(), PooledConnection::head_waiting, my_identity, PooledConnection::notify_task, PooledConnection::peer_identity, and search_waiting().

Referenced by opstart_get_handle_core().

627 {
628  struct PooledConnection *entry = cls;
629 
630  if (NULL == my_identity)
631  {
632  GNUNET_break (0);
633  return;
634  }
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)
639  return;
640  if (NULL != entry->notify_task)
641  return;
642  if (NULL != search_waiting (entry, entry->head_waiting))
643  {
645  return;
646  }
647 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_SCHEDULER_Task * notify_task
The task to notify a waiting GST_ConnectionPool_GetHandle object.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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...
unsigned int demand
Number of active requests using this pooled connection.
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.
Definition: scheduler.c:1273
struct GST_ConnectionPool_GetHandle * head_waiting
DLL head for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
The identity of the host (wraps the signing key of the peer).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_get_handle_core()

static void opstart_get_handle_core ( void *  cls)
static

Function called when resources for opening a connection to CORE are available.

Parameters
clsthe PooledConnection object

Definition at line 657 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().

658 {
659  struct PooledConnection *entry = cls;
660 
661  GNUNET_assert (NULL != entry);
662  LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index);
663  entry->handle_core =
664  GNUNET_CORE_connect (entry->cfg,
665  entry, /* closure */
666  &core_startup_cb, /* core startup notify */
667  &core_peer_connect_cb, /* peer connect notify */
668  NULL, /* peer disconnect notify */
669  NULL);
670 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
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).
uint32_t index
The index of this peer.
struct GNUNET_CORE_Handle * handle_core
The core handle to the peer corresponding to this entry; can be NULL.
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.
Definition: core_api.c:694
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.
#define LOG_DEBUG(msg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_get_handle_core()

static void oprelease_get_handle_core ( void *  cls)
static

Function called when the operation responsible for opening a CORE connection is marked as done.

Parameters
clsthe PooledConnection object

Definition at line 680 of file gnunet-service-testbed_connectionpool.c.

References GNUNET_CORE_disconnect(), GNUNET_free_non_null, PooledConnection::handle_core, and PooledConnection::peer_identity.

Referenced by GST_connection_pool_get_handle().

681 {
682  struct PooledConnection *entry = cls;
683 
684  if (NULL == entry->handle_core)
685  return;
687  entry->handle_core = NULL;
689  entry->peer_identity = NULL;
690 }
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:732
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_get_handle_ats_connectivity()

static void opstart_get_handle_ats_connectivity ( void *  cls)
static

Function called when resources for opening a connection to ATS are available.

Parameters
clsthe PooledConnection object

Definition at line 700 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().

701 {
702  struct PooledConnection *entry = cls;
703 
705 }
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_get_handle_ats_connectivity()

static void oprelease_get_handle_ats_connectivity ( void *  cls)
static

Function called when the operation responsible for opening a ATS connection is marked as done.

Parameters
clsthe PooledConnection object

Definition at line 715 of file gnunet-service-testbed_connectionpool.c.

References GNUNET_ATS_connectivity_done(), and PooledConnection::handle_ats_connectivity.

Referenced by GST_connection_pool_get_handle().

716 {
717  struct PooledConnection *entry = cls;
718 
719  if (NULL == entry->handle_ats_connectivity)
720  return;
722  entry->handle_ats_connectivity = NULL;
723 }
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_iterator()

static int cleanup_iterator ( void *  cls,
uint32_t  key,
void *  value 
)
static

This function will be called for every PooledConnection object in map.

Parameters
clsNULL
keycurrent key code
valuethe PooledConnection object
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 737 of file gnunet-service-testbed_connectionpool.c.

References destroy_pooled_connection(), GNUNET_assert, GNUNET_YES, and value.

Referenced by GST_connection_pool_destroy().

738 {
739  struct PooledConnection *entry = value;
740 
741  GNUNET_assert (NULL != entry);
743  return GNUNET_YES;
744 }
static void destroy_pooled_connection(struct PooledConnection *entry)
Destroy a PooledConnection object.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * value
Value of the record to add/remove.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_connection_pool_init()

void GST_connection_pool_init ( unsigned int  size)

Initialise the connection pool.

Parameters
sizethe 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 755 of file gnunet-service-testbed_connectionpool.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap32_create(), max_size, and size.

Referenced by testbed_run().

756 {
757  max_size = size;
758  if (0 == max_size)
759  return;
760  GNUNET_assert (NULL == map);
761  map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1);
762 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int max_size
The maximum number of entries that can be present in the connection pool.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_connection_pool_destroy()

void GST_connection_pool_destroy ( void  )

Cleanup the connection pool.

Definition at line 769 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(), and GNUNET_SYSERR.

Referenced by shutdown_task().

770 {
771  struct PooledConnection *entry;
772 
773  if (NULL != map)
774  {
775  GNUNET_assert (
776  GNUNET_SYSERR !=
779  map = NULL;
780  }
781  while (NULL != (entry = head_lru))
782  {
785  }
786  GNUNET_assert (NULL == head_not_pooled);
787 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
static struct PooledConnection * tail_lru
DLL tail for maitaining the least recently used PooledConnection objects.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct PooledConnection * head_not_pooled
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it w...
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_connection_pool_get_handle()

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.

Note
connect_notify_cb will not be called if target is already connected service level. Use GNUNET_TRANSPORT_check_peer_connected() or a similar function from the respective service's API to check if the target peer is already connected or not. connect_notify_cb will be called only once or never (in case target cannot be connected or is already connected).
Parameters
peer_idthe index of the peer
cfgthe configuration with which the transport handle has to be created if it was not present in the cache
servicethe service of interest
cbthe callback to notify when the transport handle is available
cb_clsthe closure for cb
targetthe peer identify of the peer whose connection to our TRANSPORT subsystem will be notified through the connect_notify_cb. Can be NULL
connect_notify_cbthe 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_clsthe closure for connect_notify_cb
Returns
the handle which can be used cancel or mark that the handle is no longer being used

Definition at line 823 of file gnunet-service-testbed_connectionpool.c.

References GST_ConnectionPool_GetHandle::cb, GST_ConnectionPool_GetHandle::cb_cls, GNUNET_TESTBED_Operation::cb_cls, PooledConnection::cfg, GST_ConnectionPool_GetHandle::connect_notify_cb, GST_ConnectionPool_GetHandle::connect_notify_cb_cls, connection_ready(), PooledConnection::demand, GST_ConnectionPool_GetHandle::entry, 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, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, 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(), search_waiting(), GST_ConnectionPool_GetHandle::service, service, PooledConnection::tail_waiting, and GST_ConnectionPool_GetHandle::target.

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().

832 {
834  struct PooledConnection *entry;
836  void *handle;
837  uint32_t peer_id32;
838 
839  peer_id32 = (uint32_t) peer_id;
840  handle = NULL;
841  entry = NULL;
842  if (NULL != map)
843  entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
844  if (NULL != entry)
845  {
846  if (entry->in_lru)
847  {
848  GNUNET_assert (0 == entry->demand);
849  expire_task_cancel (entry);
851  entry->in_lru = GNUNET_NO;
852  }
853  switch (service)
854  {
856  handle = entry->handle_transport;
857  if (NULL != handle)
858  LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index);
859  break;
861  handle = entry->handle_core;
862  if (NULL != handle)
863  LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index);
864  break;
866  handle = entry->handle_ats_connectivity;
867  if (NULL != handle)
868  LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
869  break;
870  }
871  }
872  else
873  {
874  entry = GNUNET_new (struct PooledConnection);
875  entry->index = peer_id32;
876  if ((NULL != map) &&
878  {
881  map,
882  entry->index,
883  entry,
885  entry->in_pool = GNUNET_YES;
886  }
887  else
888  {
891  entry);
892  }
893  entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
894  }
895  entry->demand++;
897  gh->entry = entry;
898  gh->cb = cb;
899  gh->cb_cls = cb_cls;
900  gh->target = target;
901  gh->connect_notify_cb = connect_notify_cb;
902  gh->connect_notify_cb_cls = connect_notify_cb_cls;
903  gh->service = service;
905  if (NULL != handle)
906  {
907  if (NULL == entry->notify_task)
908  {
909  if (NULL != search_waiting (entry, entry->head_waiting))
910  entry->notify_task =
912  }
913  return gh;
914  }
915  op = NULL;
916  switch (gh->service)
917  {
919  if (NULL != entry->op_transport)
920  return gh; /* Operation pending */
924  entry->op_transport = op;
925  break;
927  if (NULL != entry->op_core)
928  return gh; /* Operation pending */
932  entry->op_core = op;
933  break;
935  if (NULL != entry->op_ats_connectivity)
936  return gh; /* Operation pending */
937  op =
941  entry->op_ats_connectivity = op;
942  break;
943  }
946  return gh;
947 }
#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.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
The request handle for obtaining a pooled connection.
static struct PooledConnection * tail_lru
DLL tail for maitaining the least recently used PooledConnection objects.
const struct GNUNET_PeerIdentity * target
The peer identity of the target peer.
struct GNUNET_TESTBED_Operation * op_transport
The operation handle for transport handle.
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 char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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 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.
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.
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 GNUNET_CORE_Handle * handle_core
The core handle to the peer corresponding to this entry; can be NULL.
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...
GST_connection_pool_connection_ready_cb cb
The cache callback to call when a handle is available.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
unsigned int demand
Number of active requests using this pooled connection.
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.
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.
Definition: scheduler.c:1273
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 ...
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_TESTBED_Operation * op_ats_connectivity
The operation handle for ATS handle.
static struct PooledConnection * head_not_pooled
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it w...
static void opstart_get_handle_core(void *cls)
Function called when resources for opening a connection to CORE are available.
#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.
static struct PooledConnection * tail_not_pooled
DLL tail for maintaining PooledConnection objects that are not added into the connection pool as it w...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
#define LOG_DEBUG(msg)
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct GNUNET_ATS_ConnectivityHandle * handle_ats_connectivity
The ATS handle to the peer correspondign to this entry; can be NULL.
static void opstart_get_handle_ats_connectivity(void *cls)
Function called when resources for opening a connection to ATS are available.
static void expire_task_cancel(struct PooledConnection *entry)
Cancel the expiration task of the give PooledConnection object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_connection_pool_get_handle_done()

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.

Parameters
ghthe handle

Definition at line 963 of file gnunet-service-testbed_connectionpool.c.

References add_to_lru(), GST_ConnectionPool_GetHandle::connection_ready_called, PooledConnection::demand, destroy_pooled_connection(), GST_ConnectionPool_GetHandle::entry, 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, PooledConnection::head_notify, PooledConnection::head_waiting, PooledConnection::in_lru, PooledConnection::in_pool, PooledConnection::index, LOG_DEBUG, max_size, PooledConnection::notify_task, GST_ConnectionPool_GetHandle::notify_waiting, search_waiting(), GST_ConnectionPool_GetHandle::service, PooledConnection::tail_notify, and PooledConnection::tail_waiting.

Referenced by cleanup_occ(), cleanup_occ_lp2c(), cleanup_rocc(), and hello_update_cb().

964 {
965  struct PooledConnection *entry;
966 
967  if (NULL == gh)
968  return;
969  entry = gh->entry;
970  LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
971  gh,
972  gh->service,
973  entry->index);
974  if (! gh->connection_ready_called)
975  {
977  if ((NULL == search_waiting (entry, entry->head_waiting)) &&
978  (NULL != entry->notify_task))
979  {
981  entry->notify_task = NULL;
982  }
983  }
984  if (gh->notify_waiting)
985  {
987  gh->notify_waiting = 0;
988  }
989  GNUNET_free (gh);
990  gh = NULL;
991  GNUNET_assert (! entry->in_lru);
992  if (! entry->in_pool)
994  if (NULL != map)
995  {
996  if (GNUNET_YES ==
998  goto unallocate;
1000  {
1001  if (NULL == head_lru)
1002  goto unallocate;
1004  }
1007  map,
1008  entry->index,
1009  entry,
1011  entry->in_pool = GNUNET_YES;
1012  }
1013 
1014 unallocate:
1015  GNUNET_assert (0 < entry->demand);
1016  entry->demand--;
1017  if (0 != entry->demand)
1018  return;
1019  if (entry->in_pool)
1020  {
1021  add_to_lru (entry);
1022  return;
1023  }
1024  destroy_pooled_connection (entry);
1025 }
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 destroy_pooled_connection(struct PooledConnection *entry)
Destroy a PooledConnection object.
int notify_waiting
Are we waiting for any peer connect notifications?
struct GST_ConnectionPool_GetHandle * tail_notify
DLL tail for the queue to serve notifications when a peer is connected.
struct GST_ConnectionPool_GetHandle * tail_waiting
DLL tail for the queue of GST_ConnectionPool_GetHandle requests that are waiting for this connection ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int in_pool
Is this entry present in the connection pool.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GST_ConnectionPool_GetHandle * head_notify
DLL head for the queue to serve notifications when a peer is connected.
struct GNUNET_SCHEDULER_Task * notify_task
The task to notify a waiting GST_ConnectionPool_GetHandle object.
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.
uint32_t index
The index of this peer.
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...
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)...
unsigned int GNUNET_CONTAINER_multihashmap32_size(const struct GNUNET_CONTAINER_MultiHashMap32 *map)
Get the number of key-value pairs in the map.
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 ...
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.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
static struct PooledConnection * head_not_pooled
DLL head for maintaining PooledConnection objects that are not added into the connection pool as it w...
static struct PooledConnection * tail_not_pooled
DLL tail for maintaining PooledConnection objects that are not added into the connection pool as it w...
int connection_ready_called
Did we call the pool_connection_ready_cb already?
static struct PooledConnection * head_lru
DLL head for maitaining the least recently used PooledConnection objects.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_CONTAINER_MultiHashMap32 * map
A hashmap for quickly finding connections in the connection pool.
#define LOG_DEBUG(msg)
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ map

struct GNUNET_CONTAINER_MultiHashMap32* map
static

A hashmap for quickly finding connections in the connection pool.

Definition at line 239 of file gnunet-service-testbed_connectionpool.c.

◆ head_lru

struct PooledConnection* head_lru
static

DLL head for maitaining the least recently used PooledConnection objects.

The head is the least recently used object.

Definition at line 245 of file gnunet-service-testbed_connectionpool.c.

◆ tail_lru

struct PooledConnection* tail_lru
static

DLL tail for maitaining the least recently used PooledConnection objects.

Definition at line 250 of file gnunet-service-testbed_connectionpool.c.

◆ head_not_pooled

struct PooledConnection* head_not_pooled
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 257 of file gnunet-service-testbed_connectionpool.c.

◆ tail_not_pooled

struct PooledConnection* tail_not_pooled
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 263 of file gnunet-service-testbed_connectionpool.c.

◆ max_size

unsigned int max_size
static

The maximum number of entries that can be present in the connection pool.

Definition at line 268 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().