GNUnet  0.10.x
gnunet-service-testbed_connectionpool.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2008--2015 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "gnunet-service-testbed.h"
29 #include "testbed_api_operations.h"
31 
35 #ifdef LOG
36 #undef LOG
37 #endif
38 #define LOG(kind, ...) \
39  GNUNET_log_from(kind, "testbed-connectionpool", __VA_ARGS__)
40 
41 
45 #define CACHE_EXPIRY \
46  GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
47 
48 
53 
54 
64 
70 
75 
80 
85 
90 
95 
100 
107 
113 
118 
123 
129 
135 
140 
145 
149  unsigned int demand;
150 
154  int in_lru;
155 
159  int in_pool;
160 
164  uint32_t index;
165 };
166 
167 
179 
184 
189 
194 
198  void *cb_cls;
199 
205 
211 
216 
221 
226 
231 };
232 
233 
238 
243 static struct PooledConnection *head_lru;
244 
248 static struct PooledConnection *tail_lru;
249 
256 
262 
266 static unsigned int max_size;
267 
268 
274 static void
275 expire_task_cancel(struct PooledConnection *entry);
276 
277 
283 static void
285 {
286  GNUNET_assert((NULL == entry->head_notify) && (NULL == entry->tail_notify));
287  GNUNET_assert((NULL == entry->head_waiting) &&
288  (NULL == entry->tail_waiting));
289  GNUNET_assert(0 == entry->demand);
290  expire_task_cancel(entry);
291  if (entry->in_lru)
292  GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry);
293  if (entry->in_pool)
295  GNUNET_OK ==
296  GNUNET_CONTAINER_multihashmap32_remove(map, entry->index, entry));
297  if (NULL != entry->notify_task)
298  {
300  entry->notify_task = NULL;
301  }
302  LOG_DEBUG("Cleaning up handles of a pooled connection\n");
303  if (NULL != entry->handle_transport)
304  GNUNET_assert(NULL != entry->op_transport);
305  if (NULL != entry->op_transport)
306  {
308  entry->op_transport = NULL;
309  }
310  if (NULL != entry->handle_ats_connectivity)
311  GNUNET_assert(NULL != entry->op_ats_connectivity);
312  if (NULL != entry->op_ats_connectivity)
313  {
315  entry->op_ats_connectivity = NULL;
316  }
317  if (NULL != entry->op_core)
318  {
320  entry->op_core = NULL;
321  }
322  GNUNET_assert(NULL == entry->handle_core);
323  GNUNET_assert(NULL == entry->handle_ats_connectivity);
324  GNUNET_assert(NULL == entry->handle_transport);
326  GNUNET_free(entry);
327 }
328 
329 
335 static void
336 expire(void *cls)
337 {
338  struct PooledConnection *entry = cls;
339 
340  entry->expire_task = NULL;
342 }
343 
344 
350 static void
352 {
353  if (NULL != entry->expire_task)
354  {
356  entry->expire_task = NULL;
357  }
358 }
359 
360 
366 static void
368 {
369  GNUNET_assert(0 == entry->demand);
370  GNUNET_assert(!entry->in_lru);
371  GNUNET_CONTAINER_DLL_insert_tail(head_lru, tail_lru, entry);
372  entry->in_lru = GNUNET_YES;
373  GNUNET_assert(NULL == entry->expire_task);
374  entry->expire_task =
376 }
377 
378 
390 static struct GST_ConnectionPool_GetHandle *
393 {
395 
396  for (gh = head; NULL != gh; gh = gh->next)
397  {
398  switch (gh->service)
399  {
401  if (NULL == entry->handle_core)
402  continue;
403  if (NULL == entry->peer_identity)
404  continue; /* CORE connection isn't ready yet */
405  break;
406 
408  if (NULL == entry->handle_transport)
409  continue;
410  break;
411 
413  if (NULL == entry->handle_ats_connectivity)
414  continue;
415  break;
416  }
417  break;
418  }
419  return gh;
420 }
421 
422 
432 static void
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 }
465 
466 
476 static void
478  const struct GNUNET_PeerIdentity *peer,
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 }
514 
515 
525 static void *
527  const struct GNUNET_PeerIdentity *peer,
528  struct GNUNET_MQ_Handle *mq)
529 {
530  struct PooledConnection *entry = cls;
531 
533  return NULL;
534 }
535 
536 
543 static void
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 }
573 
574 
581 static void
583 {
584  struct PooledConnection *entry = cls;
585 
586  if (NULL == entry->handle_transport)
587  return;
589  entry->handle_transport = NULL;
590 }
591 
592 
601 static void *
603  const struct GNUNET_PeerIdentity *peer,
604  struct GNUNET_MQ_Handle *mq)
605 {
606  struct PooledConnection *entry = cls;
607 
609  return (void *)peer;
610 }
611 
612 
625 static void
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);
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 }
648 
649 
656 static void
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 }
671 
672 
679 static void
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 }
691 
692 
699 static void
701 {
702  struct PooledConnection *entry = cls;
703 
705 }
706 
707 
714 static void
716 {
717  struct PooledConnection *entry = cls;
718 
719  if (NULL == entry->handle_ats_connectivity)
720  return;
722  entry->handle_ats_connectivity = NULL;
723 }
724 
725 
736 static int
737 cleanup_iterator(void *cls, uint32_t key, void *value)
738 {
739  struct PooledConnection *entry = value;
740 
741  GNUNET_assert(NULL != entry);
743  return GNUNET_YES;
744 }
745 
746 
754 void
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 }
763 
764 
768 void
770 {
771  struct PooledConnection *entry;
772 
773  if (NULL != map)
774  {
776  GNUNET_SYSERR !=
779  map = NULL;
780  }
781  while (NULL != (entry = head_lru))
782  {
783  GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry);
785  }
786  GNUNET_assert(NULL == head_not_pooled);
787 }
788 
789 
824  unsigned int peer_id,
825  const struct GNUNET_CONFIGURATION_Handle *cfg,
828  void *cb_cls,
829  const struct GNUNET_PeerIdentity *target,
831  void *connect_notify_cb_cls)
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);
850  GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, 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;
860 
862  handle = entry->handle_core;
863  if (NULL != handle)
864  LOG_DEBUG("Found CORE handle for peer %u\n", entry->index);
865  break;
866 
868  handle = entry->handle_ats_connectivity;
869  if (NULL != handle)
870  LOG_DEBUG("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
871  break;
872  }
873  }
874  else
875  {
876  entry = GNUNET_new(struct PooledConnection);
877  entry->index = peer_id32;
878  if ((NULL != map) &&
880  {
883  map,
884  entry->index,
885  entry,
887  entry->in_pool = GNUNET_YES;
888  }
889  else
890  {
891  GNUNET_CONTAINER_DLL_insert_tail(head_not_pooled,
892  tail_not_pooled,
893  entry);
894  }
895  entry->cfg = GNUNET_CONFIGURATION_dup(cfg);
896  }
897  entry->demand++;
899  gh->entry = entry;
900  gh->cb = cb;
901  gh->cb_cls = cb_cls;
902  gh->target = target;
903  gh->connect_notify_cb = connect_notify_cb;
904  gh->connect_notify_cb_cls = connect_notify_cb_cls;
905  gh->service = service;
907  if (NULL != handle)
908  {
909  if (NULL == entry->notify_task)
910  {
911  if (NULL != search_waiting(entry, entry->head_waiting))
912  entry->notify_task =
914  }
915  return gh;
916  }
917  op = NULL;
918  switch (gh->service)
919  {
921  if (NULL != entry->op_transport)
922  return gh; /* Operation pending */
926  entry->op_transport = op;
927  break;
928 
930  if (NULL != entry->op_core)
931  return gh; /* Operation pending */
935  entry->op_core = op;
936  break;
937 
939  if (NULL != entry->op_ats_connectivity)
940  return gh; /* Operation pending */
941  op =
945  entry->op_ats_connectivity = op;
946  break;
947  }
950  return gh;
951 }
952 
953 
966 void
968 {
969  struct PooledConnection *entry;
970 
971  if (NULL == gh)
972  return;
973  entry = gh->entry;
974  LOG_DEBUG("Cleaning up get handle %p for service %u, peer %u\n",
975  gh,
976  gh->service,
977  entry->index);
978  if (!gh->connection_ready_called)
979  {
981  if ((NULL == search_waiting(entry, entry->head_waiting)) &&
982  (NULL != entry->notify_task))
983  {
985  entry->notify_task = NULL;
986  }
987  }
988  if (gh->notify_waiting)
989  {
991  gh->notify_waiting = 0;
992  }
993  GNUNET_free(gh);
994  gh = NULL;
995  GNUNET_assert(!entry->in_lru);
996  if (!entry->in_pool)
997  GNUNET_CONTAINER_DLL_remove(head_not_pooled, tail_not_pooled, entry);
998  if (NULL != map)
999  {
1000  if (GNUNET_YES ==
1002  goto unallocate;
1004  {
1005  if (NULL == head_lru)
1006  goto unallocate;
1007  destroy_pooled_connection(head_lru);
1008  }
1011  map,
1012  entry->index,
1013  entry,
1015  entry->in_pool = GNUNET_YES;
1016  }
1017 
1018 unallocate:
1019  GNUNET_assert(0 < entry->demand);
1020  entry->demand--;
1021  if (0 != entry->demand)
1022  return;
1023  if (entry->in_pool)
1024  {
1025  add_to_lru(entry);
1026  return;
1027  }
1029 }
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 &#39;operations&#39; subsystem
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Context for the core service connection.
Definition: core_api.c:76
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 &#39;operation&#39; 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.
Definition: gnunet-cadet.c:42
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_TESTBED_Operation * op_core
The operation handle for core handle.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#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.
Definition: scheduler.c:1237
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.
, &#39; 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.
Definition: scheduler.c:1264
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...
Definition: testbed_api.c:2037
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
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.
Definition: core_api.c:690
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:728
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.
Definition: mq.c:84
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.
configuration data
Definition: configuration.c:83
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:228
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?
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
Definition: 003.c:5
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
Entry in list of pending tasks.
Definition: scheduler.c:131
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
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.
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.
Definition: scheduler.c:956