gnunet_ats_plugin.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2009-2015 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 for the ATS solvers.
  21. *
  22. * @defgroup ats-plugin ATS service plugin API
  23. * Plugin API for the ATS service.
  24. *
  25. * Specifies the struct that is given to the plugin's entry method and the other
  26. * struct that must be returned. Note that the destructors of ATS plugins will
  27. * be given the value returned by the constructor and is expected to return a
  28. * NULL pointer.
  29. *
  30. * @{
  31. */
  32. #ifndef PLUGIN_ATS_H
  33. #define PLUGIN_ATS_H
  34. #include "gnunet_ats_service.h"
  35. #include "gnunet_statistics_service.h"
  36. /**
  37. * Representation of an address the plugin can choose from.
  38. */
  39. struct ATS_Address;
  40. /**
  41. * Change the preference for a peer
  42. *
  43. * @param handle the solver handle
  44. * @param client the client sending this request
  45. * @param peer the peer id
  46. * @param kind the preference kind to change
  47. * @param score the new preference score
  48. * @param pref_rel the normalized preference value for this kind over all clients
  49. */
  50. typedef void
  51. (*GAS_solver_address_change_preference) (void *solver,
  52. const struct GNUNET_PeerIdentity *peer,
  53. enum GNUNET_ATS_PreferenceKind kind,
  54. double pref_rel);
  55. /**
  56. * Give feedback about the current assignment
  57. *
  58. * @param handle the solver handle
  59. * @param application the application sending this request
  60. * @param peer the peer id
  61. * @param scope the time interval for this feedback: [now - scope .. now]
  62. * @param kind the preference kind for this feedback
  63. * @param score the feedback score
  64. */
  65. typedef void
  66. (*GAS_solver_address_feedback_preference) (void *solver,
  67. struct GNUNET_SERVICE_Client *application,
  68. const struct GNUNET_PeerIdentity *peer,
  69. const struct GNUNET_TIME_Relative scope,
  70. enum GNUNET_ATS_PreferenceKind kind,
  71. double score);
  72. /**
  73. * Notify the solver about a bulk operation changing possibly a lot of values
  74. * Solver will not resolve until all bulk operations are marked as done
  75. *
  76. * @param solver the solver
  77. */
  78. typedef void
  79. (*GAS_solver_bulk_start) (void *solver);
  80. /**
  81. * Mark a bulk operation as done
  82. * Solver will resolve if values have changed
  83. *
  84. * @param solver the solver
  85. */
  86. typedef void
  87. (*GAS_solver_bulk_stop) (void *solver);
  88. /**
  89. * Add a single address within a network to the solver
  90. *
  91. * @param solver the solver Handle
  92. * @param address the address to add
  93. * @param network network type of this address
  94. */
  95. typedef void
  96. (*GAS_solver_address_add) (void *solver,
  97. struct ATS_Address *address,
  98. uint32_t network);
  99. /**
  100. * Delete an address or just the session from the solver
  101. *
  102. * @param solver the solver Handle
  103. * @param address the address to delete
  104. */
  105. typedef void
  106. (*GAS_solver_address_delete) (void *solver,
  107. struct ATS_Address *address);
  108. /**
  109. * Transport properties for this address have changed
  110. *
  111. * @param solver solver handle
  112. * @param address the address
  113. */
  114. typedef void
  115. (*GAS_solver_address_property_changed) (void *solver,
  116. struct ATS_Address *address);
  117. /**
  118. * Get the prefered address for a peer from solver
  119. *
  120. * @param solver the solver to use
  121. * @param peer the peer
  122. */
  123. typedef void
  124. (*GAS_solver_get_preferred_address) (void *solver,
  125. const struct GNUNET_PeerIdentity *peer);
  126. /**
  127. * Stop getting the prefered address for a peer from solver
  128. *
  129. * @param solver the solver to use
  130. * @param peer the peer
  131. */
  132. typedef void
  133. (*GAS_solver_stop_get_preferred_address) (void *solver,
  134. const struct GNUNET_PeerIdentity *peer);
  135. /**
  136. * Solver functions.
  137. *
  138. * Each solver is required to set up and return an instance
  139. * of this struct during initialization.
  140. */
  141. struct GNUNET_ATS_SolverFunctions
  142. {
  143. /**
  144. * Closure to pass to all solver functions in this struct.
  145. */
  146. void *cls;
  147. /**
  148. * Add a new address for a peer to the solver
  149. *
  150. * The address is already contained in the addresses hashmap!
  151. */
  152. GAS_solver_address_add s_add;
  153. /**
  154. * Update the properties of an address in the solver
  155. */
  156. GAS_solver_address_property_changed s_address_update_property;
  157. /**
  158. * Tell solver to notify ATS if the address to use changes for a specific
  159. * peer using the bandwidth changed callback
  160. *
  161. * The solver must only notify about changes for peers with pending address
  162. * requests!
  163. */
  164. GAS_solver_get_preferred_address s_get;
  165. /**
  166. * Tell solver stop notifying ATS about changes for this peers
  167. *
  168. * The solver must only notify about changes for peers with pending address
  169. * requests!
  170. */
  171. GAS_solver_stop_get_preferred_address s_get_stop;
  172. /**
  173. * Delete an address in the solver
  174. *
  175. * The address is not contained in the address hashmap anymore!
  176. */
  177. GAS_solver_address_delete s_del;
  178. /**
  179. * Change relative preference for quality in solver
  180. */
  181. GAS_solver_address_change_preference s_pref;
  182. /**
  183. * Give feedback about the current assignment
  184. */
  185. GAS_solver_address_feedback_preference s_feedback;
  186. /**
  187. * Start a bulk operation
  188. *
  189. * Used if many values have to be updated at the same time.
  190. * When a bulk operation is pending the solver does not have to resolve
  191. * the problem since more updates will follow anyway
  192. *
  193. * For each call to bulk_start, a call to bulk_stop is required!
  194. */
  195. GAS_solver_bulk_start s_bulk_start;
  196. /**
  197. * Bulk operation done
  198. *
  199. * If no more bulk operations are pending, the solver can solve the problem
  200. * with the updated values
  201. */
  202. GAS_solver_bulk_stop s_bulk_stop;
  203. };
  204. /**
  205. * Operation codes for solver information callback
  206. *
  207. * Order of calls is expected to be:
  208. * #GAS_OP_SOLVE_START
  209. * #GAS_OP_SOLVE_STOP
  210. * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
  211. * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
  212. *
  213. */
  214. enum GAS_Solver_Operation
  215. {
  216. /**
  217. * A solution iteration has been started
  218. */
  219. GAS_OP_SOLVE_START,
  220. /**
  221. * A solution iteration has been finished
  222. */
  223. GAS_OP_SOLVE_STOP,
  224. /**
  225. * The setup of the problem as a preparation to solve it was started
  226. */
  227. GAS_OP_SOLVE_SETUP_START,
  228. /**
  229. * The setup of the problem as a preparation to solve is finished
  230. */
  231. GAS_OP_SOLVE_SETUP_STOP,
  232. /**
  233. * Solving of the LP problem was started
  234. * MLP solver only
  235. */
  236. GAS_OP_SOLVE_MLP_LP_START,
  237. /**
  238. * Solving of the LP problem is done
  239. * MLP solver only
  240. */
  241. GAS_OP_SOLVE_MLP_LP_STOP,
  242. /**
  243. * Solving of the MLP problem was started
  244. * MLP solver only
  245. */
  246. GAS_OP_SOLVE_MLP_MLP_START,
  247. /**
  248. * Solving of the MLP problem is done
  249. * MLP solver only
  250. */
  251. GAS_OP_SOLVE_MLP_MLP_STOP,
  252. /**
  253. * After the problem was finished, start notifications about changes
  254. * to addresses
  255. */
  256. GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
  257. /**
  258. * After the problem was finished, notifications about changes to addresses
  259. * are done
  260. */
  261. GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
  262. };
  263. /**
  264. * Status of a GAS_Solver_Operation operation
  265. */
  266. enum GAS_Solver_Status
  267. {
  268. /**
  269. * Success
  270. */
  271. GAS_STAT_SUCCESS,
  272. /**
  273. * Failure
  274. */
  275. GAS_STAT_FAIL
  276. };
  277. /**
  278. * Status of the operation
  279. */
  280. enum GAS_Solver_Additional_Information
  281. {
  282. /**
  283. * No more specific information
  284. */
  285. GAS_INFO_NONE,
  286. /**
  287. * A full solution process is performed
  288. * Quite specific to the MLP solver
  289. */
  290. GAS_INFO_FULL,
  291. /**
  292. * An existing solution was reused
  293. * Quite specific to the MLP solver
  294. */
  295. GAS_INFO_UPDATED,
  296. /**
  297. * The proportional solver had to recalculate for a single network
  298. */
  299. GAS_INFO_PROP_SINGLE,
  300. /**
  301. * The proportional solver had to recalculate for all networks
  302. */
  303. GAS_INFO_PROP_ALL
  304. };
  305. /**
  306. * Callback to call with additional information
  307. * Used for measurement
  308. *
  309. * @param cls the closure
  310. * @param op the operation
  311. */
  312. typedef void
  313. (*GAS_solver_information_callback) (void *cls,
  314. enum GAS_Solver_Operation op,
  315. enum GAS_Solver_Status stat,
  316. enum GAS_Solver_Additional_Information);
  317. /**
  318. * Callback to call from solver when bandwidth for address has changed
  319. *
  320. * @param address the with changed bandwidth assigned
  321. */
  322. typedef void
  323. (*GAS_bandwidth_changed_cb) (void *cls,
  324. struct ATS_Address *address);
  325. /**
  326. * Callback to call from solver to obtain application preference
  327. * values for a peer.
  328. *
  329. * @param cls the cls
  330. * @param id the peer id
  331. * @return carry of double values containing the preferences with
  332. * GNUNET_ATS_PreferenceCount elements
  333. */
  334. typedef const double *
  335. (*GAS_get_preferences) (void *cls,
  336. const struct GNUNET_PeerIdentity *id);
  337. /**
  338. * Callback to call from solver to obtain application connectivity
  339. * preferences for a peer.
  340. *
  341. * @param cls the cls
  342. * @param id the peer id
  343. * @return 0 if connectivity is not desired, non-null if address
  344. * suggestions are requested
  345. */
  346. typedef unsigned int
  347. (*GAS_get_connectivity) (void *cls,
  348. const struct GNUNET_PeerIdentity *id);
  349. /**
  350. * The ATS plugin will pass a pointer to a struct
  351. * of this type as to the initialization function
  352. * of the ATS plugins.
  353. */
  354. struct GNUNET_ATS_PluginEnvironment
  355. {
  356. /**
  357. * Configuration handle to be used by the solver
  358. */
  359. const struct GNUNET_CONFIGURATION_Handle *cfg;
  360. /**
  361. * Statistics handle to be used by the solver
  362. */
  363. struct GNUNET_STATISTICS_Handle *stats;
  364. /**
  365. * Closure to pass to all callbacks in this struct.
  366. */
  367. void *cls;
  368. /**
  369. * Hashmap containing all addresses available
  370. */
  371. struct GNUNET_CONTAINER_MultiPeerMap *addresses;
  372. /**
  373. * ATS addresses callback to be notified about bandwidth assignment changes
  374. */
  375. GAS_bandwidth_changed_cb bandwidth_changed_cb;
  376. /**
  377. * ATS addresses function to obtain preference values
  378. */
  379. GAS_get_preferences get_preferences;
  380. /**
  381. * ATS addresses function to obtain preference values
  382. */
  383. GAS_get_connectivity get_connectivity;
  384. /**
  385. * Callback for solver to call with status information,
  386. * can be NULL
  387. */
  388. GAS_solver_information_callback info_cb;
  389. /**
  390. * Number of networks available, size of the @e out_quota
  391. * and @e in_quota arrays.
  392. */
  393. unsigned int network_count;
  394. /**
  395. * Array of configured outbound quotas
  396. * Order according to networks in network array
  397. */
  398. unsigned long long out_quota[GNUNET_NT_COUNT];
  399. /**
  400. * Array of configured inbound quotas
  401. * Order according to networks in network array
  402. */
  403. unsigned long long in_quota[GNUNET_NT_COUNT];
  404. };
  405. #endif
  406. /** @} */ /* end of group */