gnunet_ats_plugin.h 12 KB

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