gnunet_ats_service.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2010,2011 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 include/gnunet_ats_service.h
  19. * @brief automatic transport selection and outbound bandwidth determination
  20. * @author Christian Grothoff
  21. * @author Matthias Wachs
  22. *
  23. * TODO:
  24. * - move GNUNET_TRANSPORT_ATS* in here and rename...
  25. * - extend API to express communication preferences to ATS
  26. * (to be called DIRECTLY from apps, not from transport/core!)
  27. */
  28. #ifndef GNUNET_ATS_SERVICE_H
  29. #define GNUNET_ATS_SERVICE_H
  30. #include "gnunet_constants.h"
  31. #include "gnunet_util_lib.h"
  32. #include "gnunet_transport_service.h"
  33. #include "gnunet_transport_plugin.h"
  34. /**
  35. * Handle to the ATS subsystem.
  36. */
  37. struct GNUNET_ATS_Handle;
  38. /**
  39. * Signature of a function called by ATS to notify the callee that the
  40. * assigned bandwidth or address for a given peer was changed. If the
  41. * callback is called with address/bandwidth assignments of zero, the
  42. * ATS disconnect function will still be called once the disconnect
  43. * actually happened.
  44. *
  45. * @param cls closure
  46. * @param peer identity of the peer
  47. * @param plugin_name name of the transport plugin, NULL to disconnect
  48. * @param session session to use (if available)
  49. * @param plugin_addr address to use (if available)
  50. * @param plugin_addr_len number of bytes in addr
  51. * @param bandwidth assigned outbound bandwidth for the connection
  52. */
  53. typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls,
  54. const struct
  55. GNUNET_PeerIdentity
  56. * peer,
  57. const char
  58. *plugin_name,
  59. struct Session *
  60. session,
  61. const void
  62. *plugin_addr,
  63. size_t
  64. plugin_addr_len,
  65. struct
  66. GNUNET_BANDWIDTH_Value32NBO
  67. bandwidth);
  68. /**
  69. * Initialize the ATS subsystem.
  70. *
  71. * @param cfg configuration to use
  72. * @param alloc_cb notification to call whenever the allocation changed
  73. * @param alloc_cb_cls closure for 'alloc_cb'
  74. * @return ats context
  75. */
  76. struct GNUNET_ATS_Handle *
  77. GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  78. GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
  79. void *alloc_cb_cls);
  80. /**
  81. * Shutdown the ATS subsystem.
  82. *
  83. * @param atc handle
  84. */
  85. void
  86. GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc);
  87. /**
  88. * Signature of a function that takes an address suggestion
  89. *
  90. * @param cls closure
  91. * @param peer identity of the new peer
  92. * @param plugin_name name of the plugin, NULL if we have no suggestion
  93. * @param plugin_addr suggested address, NULL if we have no suggestion
  94. * @param plugin_addr_len number of bytes in plugin_addr
  95. * @param bandwidth assigned outbound bandwidth for the connection
  96. * @param ats performance data for the address (as far as known)
  97. * @param ats_count number of performance records in 'ats'
  98. */
  99. typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
  100. const struct
  101. GNUNET_PeerIdentity *
  102. peer,
  103. const char *plugin_name,
  104. const void *plugin_addr,
  105. size_t plugin_addr_len,
  106. struct
  107. GNUNET_BANDWIDTH_Value32NBO
  108. bandwidth,
  109. const struct
  110. GNUNET_TRANSPORT_ATS_Information
  111. * ats,
  112. uint32_t ats_count);
  113. /**
  114. * Handle to cancel suggestion request.
  115. */
  116. struct GNUNET_ATS_SuggestionContext;
  117. /**
  118. * We would like to establish a new connection with a peer.
  119. * ATS should suggest a good address to begin with.
  120. *
  121. * @param atc handle
  122. * @param peer identity of the new peer
  123. * @param cb function to call with the address
  124. * @param cb_cls closure for cb
  125. */
  126. struct GNUNET_ATS_SuggestionContext *
  127. GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
  128. const struct GNUNET_PeerIdentity *peer,
  129. GNUNET_ATS_AddressSuggestionCallback cb,
  130. void *cb_cls);
  131. /**
  132. * Cancel suggestion request.
  133. *
  134. * @param asc handle of the request to cancel
  135. */
  136. void
  137. GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc);
  138. /**
  139. * We established a new connection with a peer (for example, because
  140. * core asked for it or because the other peer connected to us).
  141. * Calculate bandwidth assignments including the new peer.
  142. *
  143. * @param atc handle
  144. * @param peer identity of the new peer
  145. * @param plugin_name name of the currently used transport plugin
  146. * @param session session in use (if available)
  147. * @param plugin_addr address in use (if available)
  148. * @param plugin_addr_len number of bytes in plugin_addr
  149. * @param ats performance data for the connection
  150. * @param ats_count number of performance records in 'ats'
  151. */
  152. void
  153. GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
  154. const struct GNUNET_PeerIdentity *peer,
  155. const char *plugin_name, struct Session *session,
  156. const void *plugin_addr, size_t plugin_addr_len,
  157. const struct GNUNET_TRANSPORT_ATS_Information *ats,
  158. uint32_t ats_count);
  159. /**
  160. * We disconnected from the given peer (for example, because ats, core
  161. * or blacklist asked for it or because the other peer disconnected).
  162. * Calculate bandwidth assignments without the peer.
  163. *
  164. * @param atc handle
  165. * @param peer identity of the peer
  166. */
  167. void
  168. GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
  169. const struct GNUNET_PeerIdentity *peer);
  170. /**
  171. * A session got destroyed, stop including it as a valid address.
  172. *
  173. * @param atc handle
  174. * @param peer identity of the peer
  175. * @param session session handle that is no longer valid
  176. */
  177. void
  178. GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
  179. const struct GNUNET_PeerIdentity *peer,
  180. const struct Session *session);
  181. /**
  182. * We have updated performance statistics for a given address. Note
  183. * that this function can be called for addresses that are currently
  184. * in use as well as addresses that are valid but not actively in use.
  185. * Furthermore, the peer may not even be connected to us right now (in
  186. * which case the call may be ignored or the information may be stored
  187. * for later use). Update bandwidth assignments.
  188. *
  189. * @param atc handle
  190. * @param peer identity of the new peer
  191. * @param valid_until how long is the address valid?
  192. * @param plugin_name name of the transport plugin
  193. * @param session session handle (if available)
  194. * @param plugin_addr address (if available)
  195. * @param plugin_addr_len number of bytes in plugin_addr
  196. * @param ats performance data for the address
  197. * @param ats_count number of performance records in 'ats'
  198. */
  199. void
  200. GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
  201. const struct GNUNET_PeerIdentity *peer,
  202. struct GNUNET_TIME_Absolute valid_until,
  203. const char *plugin_name, struct Session *session,
  204. const void *plugin_addr, size_t plugin_addr_len,
  205. const struct GNUNET_TRANSPORT_ATS_Information *ats,
  206. uint32_t ats_count);
  207. #endif
  208. /* end of file gnunet-service-transport_ats.h */