2
0

gnunet_ats_transport_service.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2015, 2018 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
  18. * Bandwidth allocation API for the transport service
  19. *
  20. * @author Christian Grothoff
  21. * @author Matthias Wachs
  22. *
  23. * @defgroup ats ATS service
  24. * Bandwidth allocation for transport service
  25. *
  26. * @see [Documentation](https://gnunet.org/ats-subsystem)
  27. *
  28. * @{
  29. */
  30. #ifndef GNUNET_ATS_TRANSPORT_SERVICE_H
  31. #define GNUNET_ATS_TRANSPORT_SERVICE_H
  32. #include "gnunet_constants.h"
  33. #include "gnunet_util_lib.h"
  34. #include "gnunet_nt_lib.h"
  35. #include "gnunet_transport_communication_service.h"
  36. /**
  37. * ATS performance characteristics for a session.
  38. */
  39. struct GNUNET_ATS_Properties
  40. {
  41. /**
  42. * Delay. Time between when the time packet is sent and the packet
  43. * arrives. FOREVER if we did not (successfully) measure yet.
  44. */
  45. struct GNUNET_TIME_Relative delay;
  46. /**
  47. * Confirmed successful payload on this connection from this peer to
  48. * the other peer.
  49. *
  50. * Unit: [bytes/second]
  51. */
  52. uint32_t goodput_out;
  53. /**
  54. * Confirmed useful payload on this connection to this peer from
  55. * the other peer.
  56. *
  57. * Unit: [bytes/second]
  58. */
  59. uint32_t goodput_in;
  60. /**
  61. * Actual traffic on this connection from this peer to the other peer.
  62. * Includes transport overhead.
  63. *
  64. * Unit: [bytes/second]
  65. */
  66. uint32_t utilization_out;
  67. /**
  68. * Actual traffic on this connection from the other peer to this peer.
  69. * Includes transport overhead.
  70. *
  71. * Unit: [bytes/second]
  72. */
  73. uint32_t utilization_in;
  74. /**
  75. * Distance on network layer (required for distance-vector routing)
  76. * in hops. Zero for direct connections (i.e. plain TCP/UDP).
  77. */
  78. uint32_t distance;
  79. /**
  80. * MTU of the network layer, UINT32_MAX for no MTU (stream).
  81. *
  82. * Unit: [bytes]
  83. */
  84. uint32_t mtu;
  85. /**
  86. * Which network scope does the respective address belong to?
  87. */
  88. enum GNUNET_NetworkType nt;
  89. /**
  90. * What characteristics does this communicator have?
  91. */
  92. enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
  93. };
  94. /* ******************************** Transport API ***************************** */
  95. /**
  96. * Handle to the ATS subsystem for bandwidth/transport transport information.
  97. */
  98. struct GNUNET_ATS_TransportHandle;
  99. /**
  100. * Opaque session handle, to be defined by transport. Contents not known to ATS.
  101. */
  102. struct GNUNET_ATS_Session;
  103. /**
  104. * Signature of a function called by ATS with the current bandwidth
  105. * allocation to be used as determined by ATS.
  106. *
  107. * @param cls closure
  108. * @param session session this is about
  109. * @param bandwidth_out assigned outbound bandwidth for the connection,
  110. * 0 to signal disconnect
  111. * @param bandwidth_in assigned inbound bandwidth for the connection,
  112. * 0 to signal disconnect
  113. */
  114. typedef void
  115. (*GNUNET_ATS_AllocationCallback) (void *cls,
  116. struct GNUNET_ATS_Session *session,
  117. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
  118. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
  119. /**
  120. * Signature of a function called by ATS suggesting transport to
  121. * try connecting with a particular address.
  122. *
  123. * @param cls closure
  124. * @param pid target peer
  125. * @param address the address to try
  126. */
  127. typedef void
  128. (*GNUNET_ATS_SuggestionCallback) (void *cls,
  129. const struct GNUNET_PeerIdentity *pid,
  130. const char *address);
  131. /**
  132. * Initialize the ATS transport subsystem.
  133. *
  134. * @param cfg configuration to use
  135. * @param alloc_cb notification to call whenever the allocation changed
  136. * @param alloc_cb_cls closure for @a alloc_cb
  137. * @param suggest_cb notification to call whenever the suggestation is made
  138. * @param suggest_cb_cls closure for @a suggest_cb
  139. * @return ats context
  140. */
  141. struct GNUNET_ATS_TransportHandle *
  142. GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  143. GNUNET_ATS_AllocationCallback alloc_cb,
  144. void *alloc_cb_cls,
  145. GNUNET_ATS_SuggestionCallback suggest_cb,
  146. void *suggest_cb_cls);
  147. /**
  148. * Client is done with ATS transport, release resources.
  149. *
  150. * @param ath handle to release
  151. */
  152. void
  153. GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath);
  154. /**
  155. * Handle used within ATS to track an session.
  156. */
  157. struct GNUNET_ATS_SessionRecord;
  158. /**
  159. * We have a new session ATS should know. Sessiones have to be added with this
  160. * function before they can be: updated, set in use and destroyed
  161. *
  162. * @param ath handle
  163. * @param pid peer we connected to
  164. * @param address the address (human readable version),
  165. * @param session transport-internal handle for the session/queue, NULL if
  166. * the session is inbound-only
  167. * @param prop performance data for the session
  168. * @return handle to the session representation inside ATS, NULL
  169. * on error (i.e. ATS knows this exact session already, or
  170. * session is invalid)
  171. */
  172. struct GNUNET_ATS_SessionRecord *
  173. GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
  174. const struct GNUNET_PeerIdentity *pid,
  175. const char *address,
  176. struct GNUNET_ATS_Session *session,
  177. const struct GNUNET_ATS_Properties *prop);
  178. /**
  179. * We have updated performance statistics for a given session. Based
  180. * on the information provided, ATS may update bandwidth assignments.
  181. *
  182. * @param ar session record to update information for
  183. * @param prop performance data for the session
  184. */
  185. void
  186. GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
  187. const struct GNUNET_ATS_Properties *prop);
  188. /**
  189. * A session was destroyed, ATS should now schedule and
  190. * allocate under the assumption that this @a ar is no
  191. * longer in use.
  192. *
  193. * @param ar session record to drop
  194. */
  195. void
  196. GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar);
  197. #endif
  198. /** @} */ /* end of group */
  199. /* end of file gnunet-service-transport_ats.h */