gnunet_transport_core_service.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009-2019 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API of the transport service towards the CORE service (TNG version)
  21. *
  22. * @defgroup transport TRANSPORT service
  23. * Communication with other peers
  24. *
  25. * @see [Documentation](https://gnunet.org/transport-service)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_TRANSPORT_CORE_SERVICE_H
  30. #define GNUNET_TRANSPORT_CORE_SERVICE_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. #include "gnunet_util_lib.h"
  38. /**
  39. * Version number of the transport API.
  40. */
  41. #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
  42. /**
  43. * Opaque handle to the service.
  44. */
  45. struct GNUNET_TRANSPORT_CoreHandle;
  46. /**
  47. * Function called to notify transport users that another
  48. * peer connected to us.
  49. *
  50. * @param cls closure
  51. * @param peer the identity of the peer that connected; this
  52. * pointer will remain valid until the disconnect, hence
  53. * applications do not necessarily have to make a copy
  54. * of the value if they only need it until disconnect
  55. * @param mq message queue to use to transmit to @a peer
  56. * @return closure to use in MQ handlers
  57. */
  58. typedef void *(*GNUNET_TRANSPORT_NotifyConnect) (
  59. void *cls,
  60. const struct GNUNET_PeerIdentity *peer,
  61. struct GNUNET_MQ_Handle *mq);
  62. /**
  63. * Function called to notify transport users that another peer
  64. * disconnected from us. The message queue that was given to the
  65. * connect notification will be destroyed and must not be used
  66. * henceforth.
  67. *
  68. * @param cls closure from #GNUNET_TRANSPORT_core_connect
  69. * @param peer the peer that disconnected
  70. * @param handlers_cls closure of the handlers, was returned from the
  71. * connect notification callback
  72. */
  73. typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (
  74. void *cls,
  75. const struct GNUNET_PeerIdentity *peer,
  76. void *handler_cls);
  77. /**
  78. * Connect to the transport service. Note that the connection may
  79. * complete (or fail) asynchronously.
  80. *
  81. * @param cfg configuration to use
  82. * @param self our own identity (API should check that it matches
  83. * the identity found by transport), or NULL (no check)
  84. * @param handlers array of message handlers; note that the
  85. * closures provided will be ignored and replaced
  86. * with the respective return value from @a nc
  87. * @param handlers array with handlers to call when we receive messages, or NULL
  88. * @param cls closure for the @a nc, @a nd and @a neb callbacks
  89. * @param nc function to call on connect events, or NULL
  90. * @param nd function to call on disconnect events, or NULL
  91. * @param neb function to call if we have excess bandwidth to a peer, or NULL
  92. * @return NULL on error
  93. */
  94. struct GNUNET_TRANSPORT_CoreHandle *
  95. GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  96. const struct GNUNET_PeerIdentity *self,
  97. const struct GNUNET_MQ_MessageHandler *handlers,
  98. void *cls,
  99. GNUNET_TRANSPORT_NotifyConnect nc,
  100. GNUNET_TRANSPORT_NotifyDisconnect nd);
  101. /**
  102. * Disconnect from the transport service.
  103. *
  104. * @param handle handle returned from connect
  105. */
  106. void
  107. GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
  108. /**
  109. * Notification from the CORE service to the TRANSPORT service
  110. * that the CORE service has finished processing a message from
  111. * TRANSPORT (via the @code{handlers} of #GNUNET_TRANSPORT_core_connect())
  112. * and that it is thus now OK for TRANSPORT to send more messages
  113. * for @a pid.
  114. *
  115. * Used to provide flow control, this is our equivalent to
  116. * #GNUNET_SERVICE_client_continue() of an ordinary service.
  117. *
  118. * Note that due to the use of a window, TRANSPORT may send multiple
  119. * messages destined for the same peer even without an intermediate
  120. * call to this function. However, CORE must still call this function
  121. * once per message received, as otherwise eventually the window will
  122. * be full and TRANSPORT will stop providing messages to CORE for @a
  123. * pid.
  124. *
  125. * @param ch core handle
  126. * @param pid which peer was the message from that was fully processed by CORE
  127. */
  128. void
  129. GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
  130. const struct GNUNET_PeerIdentity *pid);
  131. /**
  132. * Checks if a given peer is connected to us and get the message queue.
  133. * Convenience function.
  134. *
  135. * @param handle connection to transport service
  136. * @param peer the peer to check
  137. * @return NULL if disconnected, otherwise message queue for @a peer
  138. */
  139. struct GNUNET_MQ_Handle *
  140. GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
  141. const struct GNUNET_PeerIdentity *peer);
  142. #if 0 /* keep Emacsens' auto-indent happy */
  143. {
  144. #endif
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
  149. #endif
  150. /** @} */ /* end of group */
  151. /* end of gnunet_transport_core_service.h */