gnunet-service-testbed_connectionpool.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2008--2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file testbed/gnunet-service-testbed_connectionpool.h
  19. * @brief Interface for connection pooling subroutines
  20. * @author Sree Harsha Totakura <sreeharsha@totakura.in>
  21. */
  22. /**
  23. * The request handle for obtaining a pooled connection
  24. */
  25. struct GST_ConnectionPool_GetHandle;
  26. /**
  27. * The type of service
  28. */
  29. enum GST_ConnectionPool_Service
  30. {
  31. /**
  32. * Transport service
  33. */
  34. GST_CONNECTIONPOOL_SERVICE_TRANSPORT = 1,
  35. /**
  36. * Core service
  37. */
  38. GST_CONNECTIONPOOL_SERVICE_CORE
  39. };
  40. /**
  41. * Initialise the connection pool.
  42. *
  43. * @param size the size of the connection pool. Each entry in the connection
  44. * pool can handle a connection to each of the services enumerated in
  45. * #GST_ConnectionPool_Service
  46. */
  47. void
  48. GST_connection_pool_init (unsigned int size);
  49. /**
  50. * Cleanup the connection pool
  51. */
  52. void
  53. GST_connection_pool_destroy ();
  54. /**
  55. * Functions of this type are called when the needed handle is available for
  56. * usage. These functions are to be registered with the function
  57. * GST_connection_pool_get_handle(). The corresponding handles will be set upon
  58. * success. If they are not set, then it signals an error while opening the
  59. * handles.
  60. *
  61. * @param cls the closure passed to GST_connection_pool_get_handle()
  62. * @param ch the handle to CORE. Can be NULL if it is not requested
  63. * @param th the handle to TRANSPORT. Can be NULL if it is not requested
  64. * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other
  65. * cases, its value being NULL means that CORE connection has failed.
  66. */
  67. typedef void
  68. (*GST_connection_pool_connection_ready_cb) (void *cls,
  69. struct GNUNET_CORE_Handle * ch,
  70. struct GNUNET_TRANSPORT_Handle * th,
  71. const struct GNUNET_PeerIdentity *
  72. peer_id);
  73. /**
  74. * Callback to notify when the target peer given to
  75. * GST_connection_pool_get_handle() is connected.
  76. *
  77. * @param cls the closure given to GST_connection_pool_get_handle() for this
  78. * callback
  79. * @param target the peer identity of the target peer
  80. */
  81. typedef void
  82. (*GST_connection_pool_peer_connect_notify) (void *cls,
  83. const struct GNUNET_PeerIdentity
  84. *target);
  85. /**
  86. * Get a connection handle to @a service. If the connection is opened before
  87. * and the connection handle is present in the connection pool, it is returned
  88. * through @a cb. @a peer_id is used for the lookup in the connection pool. If
  89. * the connection handle is not present in the connection pool, a new connection
  90. * handle is opened for the @a service using @a cfg. Additionally, @a target,
  91. * @a connect_notify_cb can be specified to get notified when @a target is
  92. * connected at @a service.
  93. *
  94. * @note @a connect_notify_cb will not be called if @a target is
  95. * already connected @a service level. Use
  96. * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
  97. * respective @a service's API to check if the target peer is already connected or
  98. * not. @a connect_notify_cb will be called only once or never (in case @a target
  99. * cannot be connected or is already connected).
  100. *
  101. * @param peer_id the index of the peer
  102. * @param cfg the configuration with which the transport handle has to be
  103. * created if it was not present in the cache
  104. * @param service the service of interest
  105. * @param cb the callback to notify when the transport handle is available
  106. * @param cb_cls the closure for @a cb
  107. * @param target the peer identify of the peer whose connection to our TRANSPORT
  108. * subsystem will be notified through the @a connect_notify_cb. Can be NULL
  109. * @param connect_notify_cb the callback to call when the @a target peer is
  110. * connected. This callback will only be called once or never again (in
  111. * case the target peer cannot be connected). Can be NULL
  112. * @param connect_notify_cb_cls the closure for @a connect_notify_cb
  113. * @return the handle which can be used cancel or mark that the handle is no
  114. * longer being used
  115. */
  116. struct GST_ConnectionPool_GetHandle *
  117. GST_connection_pool_get_handle (unsigned int peer_id,
  118. const struct GNUNET_CONFIGURATION_Handle *cfg,
  119. enum GST_ConnectionPool_Service service,
  120. GST_connection_pool_connection_ready_cb cb,
  121. void *cb_cls,
  122. const struct GNUNET_PeerIdentity *target,
  123. GST_connection_pool_peer_connect_notify connect_notify_cb,
  124. void *connect_notify_cb_cls);
  125. /**
  126. * Relinquish a #GST_ConnectionPool_GetHandle object. If the connection
  127. * associated with the object is currently being used by other
  128. * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If
  129. * no other objects are using the connection and the connection pool is not full
  130. * then it is placed in a LRU queue. If the connection pool is full, then
  131. * connections from the LRU queue are evicted and closed to create place for this
  132. * connection. If the connection pool if full and the LRU queue is empty, then
  133. * the connection is closed.
  134. *
  135. * @param gh the handle
  136. */
  137. void
  138. GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh);
  139. /* End of gnunet-service-testbed_connectionpool.h */