gnunet-service-transport.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010,2011 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. * @file transport/gnunet-service-transport.h
  18. * @brief globals
  19. * @author Christian Grothoff
  20. */
  21. #ifndef GNUNET_SERVICE_TRANSPORT_H
  22. #define GNUNET_SERVICE_TRANSPORT_H
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_statistics_service.h"
  25. #include "gnunet_ats_service.h"
  26. #include "gnunet_transport_service.h"
  27. #define VERBOSE_VALIDATION GNUNET_YES
  28. /**
  29. * Statistics handle.
  30. */
  31. extern struct GNUNET_STATISTICS_Handle *GST_stats;
  32. /**
  33. * Configuration handle.
  34. */
  35. extern const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
  36. /**
  37. * Configuration handle.
  38. */
  39. extern struct GNUNET_PeerIdentity GST_my_identity;
  40. /**
  41. * Handle to peerinfo service.
  42. */
  43. extern struct GNUNET_PEERINFO_Handle *GST_peerinfo;
  44. /**
  45. * Our private key.
  46. */
  47. extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
  48. /**
  49. * ATS handle.
  50. */
  51. extern struct GNUNET_ATS_SchedulingHandle *GST_ats;
  52. /**
  53. * ATS connectivity handle.
  54. */
  55. extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
  56. /**
  57. * Interface scanner determines our LAN address range(s).
  58. */
  59. extern struct GNUNET_NT_InterfaceScanner *GST_is;
  60. /**
  61. * Function to call when a peer's address has changed
  62. *
  63. * @param cls closure
  64. * @param peer peer this update is about,
  65. * @param address address, NULL for disconnect notification
  66. */
  67. typedef void
  68. (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls,
  69. const struct GNUNET_PeerIdentity *peer,
  70. const struct GNUNET_HELLO_Address *address,
  71. enum GNUNET_TRANSPORT_PeerState state,
  72. struct GNUNET_TIME_Absolute state_timeout,
  73. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
  74. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
  75. /**
  76. * Continuation called from a blacklist test.
  77. *
  78. * @param cls closure
  79. * @param peer identity of peer that was tested
  80. * @param address address associated with the request
  81. * @param session session associated with the request
  82. * @param result #GNUNET_OK if the connection is allowed,
  83. * #GNUNET_NO if not,
  84. * #GNUNET_SYSERR if operation was aborted
  85. */
  86. typedef void
  87. (*GST_BlacklistTestContinuation) (void *cls,
  88. const struct GNUNET_PeerIdentity *peer,
  89. const struct GNUNET_HELLO_Address *address,
  90. struct GNUNET_ATS_Session *session,
  91. int result);
  92. /**
  93. * Add the given peer to the blacklist (for the given transport).
  94. *
  95. * @param peer peer to blacklist
  96. * @param transport_name transport to blacklist for this peer, NULL for all
  97. */
  98. void
  99. GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
  100. const char *transport_name);
  101. /**
  102. * Handle to an active blacklist check.
  103. */
  104. struct GST_BlacklistCheck;
  105. /**
  106. * Test if a peer/transport combination is blacklisted.
  107. *
  108. * @param peer the identity of the peer to test
  109. * @param transport_name name of the transport to test, never NULL
  110. * @param cont function to call with result
  111. * @param cont_cls closure for @a cont
  112. * @param address address to pass back to @a cont, can be NULL
  113. * @param session session to pass back to @a cont, can be NULL
  114. * @return handle to the blacklist check, NULL if the decision
  115. * was made instantly and @a cont was already called
  116. */
  117. struct GST_BlacklistCheck *
  118. GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
  119. const char *transport_name,
  120. GST_BlacklistTestContinuation cont,
  121. void *cont_cls,
  122. const struct GNUNET_HELLO_Address *address,
  123. struct GNUNET_ATS_Session *session);
  124. /**
  125. * Abort blacklist if @a address and @a session match.
  126. *
  127. * @param address address used to abort matching checks
  128. * @param session session used to abort matching checks
  129. */
  130. void
  131. GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
  132. struct GNUNET_ATS_Session *session);
  133. /**
  134. * Cancel a blacklist check.
  135. *
  136. * @param bc check to cancel
  137. */
  138. void
  139. GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
  140. /**
  141. * Function called by the transport for each received message.
  142. *
  143. * @param cls closure, const char* with the name of the plugin we received the message from
  144. * @param address address and (claimed) identity of the other peer
  145. * @param session identifier used for this session (NULL for plugins
  146. * that do not offer bi-directional communication to the sender
  147. * using the same "connection")
  148. * @param message the message, NULL if we only care about
  149. * learning about the delay until we should receive again
  150. * @return how long the plugin should wait until receiving more data
  151. * (plugins that do not support this, can ignore the return value)
  152. */
  153. struct GNUNET_TIME_Relative
  154. GST_receive_callback (void *cls,
  155. const struct GNUNET_HELLO_Address *address,
  156. struct GNUNET_ATS_Session *session,
  157. const struct GNUNET_MessageHeader *message);
  158. /**
  159. * Broadcast the given message to all of our clients.
  160. *
  161. * @param msg message to broadcast
  162. * @param may_drop #GNUNET_YES if the message can be dropped / is payload
  163. */
  164. void
  165. GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
  166. int may_drop);
  167. /**
  168. * Broadcast the new active address to all clients monitoring the peer.
  169. *
  170. * @param peer peer this update is about (never NULL)
  171. * @param address address, NULL on disconnect
  172. * @param state the current state of the peer
  173. * @param state_timeout the time out for the state
  174. */
  175. void
  176. GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
  177. const struct GNUNET_HELLO_Address *address,
  178. enum GNUNET_TRANSPORT_PeerState state,
  179. struct GNUNET_TIME_Absolute state_timeout);
  180. /**
  181. * Notify all clients about a disconnect, and cancel
  182. * pending SEND_OK messages for this peer.
  183. *
  184. * @param peer peer that disconnected
  185. */
  186. void
  187. GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer);
  188. #endif
  189. /* end of file gnunet-service-transport_plugins.h */