gnunet_ats_plugin.h 11 KB

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