gnunet-service-ats_addresses.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011-2014 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 ats/gnunet-service-ats_addresses.h
  19. * @brief ats service address management
  20. * @author Matthias Wachs
  21. * @author Christian Grothoff
  22. */
  23. #ifndef GNUNET_SERVICE_ATS_ADDRESSES_H
  24. #define GNUNET_SERVICE_ATS_ADDRESSES_H
  25. #include "gnunet_util_lib.h"
  26. #include "gnunet_ats_service.h"
  27. #include "gnunet-service-ats.h"
  28. /**
  29. * NOTE: Do not change this documentation. This documentation is based on
  30. * gnunet.org:/vcs/fsnsg/ats-paper.git/tech-doku/ats-tech-guide.tex
  31. * use build_txt.sh to generate plaintext output
  32. *
  33. * 1 ATS addresses : ATS address management
  34. *
  35. * This ATS addresses ("addresses") component manages the addresses known to
  36. * ATS service and suggests addresses to transport service when it is
  37. * interested in address suggestion for a peer. ATS addresses also
  38. * instantiates the bandwidth assignment mechanism (solver), notifies it
  39. * about changes to addresses and forwards changes to bandwidth assignments
  40. * to transport, depending if transport is interested in this change.
  41. *
  42. * 1.1 Input data
  43. *
  44. * 1.1.1 Addresses
  45. *
  46. * Addresses are added by specifying peer ID, plugin, address, address length
  47. * and session, if available. ATS information can be specified if available.
  48. *
  49. * 1.1.2 Networks
  50. *
  51. * ATS specifies a fix set of networks an address can belong to. For each
  52. * network an inbound and outbound quota will be specified. The available
  53. * networks and addtional helper varaibles are defined in
  54. * gnunet_ats_service.h. At the moment 5 networks are defined:
  55. * * GNUNET_ATS_NET_UNSPECIFIED
  56. * * GNUNET_ATS_NET_LOOPBACK
  57. * * GNUNET_ATS_NET_LAN
  58. * * GNUNET_ATS_NET_WAN
  59. * * GNUNET_ATS_NET_WLAN
  60. *
  61. * The total number of networks defined is stored in
  62. * GNUNET_ATS_NetworkTypeCount GNUNET_ATS_NetworkType can be used array
  63. * initializer for an int array, while GNUNET_ATS_NetworkType is an
  64. * initializer for a char array containing a string description of all
  65. * networks
  66. *
  67. * 1.1.3 Quotas
  68. *
  69. * An inbound and outbound quota for each of the networks mentioned in 1.1.2
  70. * is loaded from ats configuration during initialization. This quota defines
  71. * to total amount of inbound and outbound traffic allowed for a specific
  72. * network. The configuration values used are in section ats:
  73. * * "NETWORK"_QUOTA_IN = <value>
  74. * * "NETWORK"_QUOTA_IN = <value>
  75. *
  76. * You can specify quotas by setting the <value> to a:
  77. * * unrestricted: unlimited
  78. * * number of bytes: e.g. 10240
  79. * * fancy value: e.g. 64 Kib
  80. *
  81. * unlimited is defined as GNUNET_ATS_MaxBandwidthString and equivalent to
  82. * the value GNUNET_ATS_MaxBandwidth Important predefined values for quotas
  83. * are:
  84. * * GNUNET_ATS_DefaultBandwidth: 65536
  85. * * GNUNET_ATS_MaxBandwidth: UINT32_MAX
  86. * * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT: 1024
  87. *
  88. * Details of loading quotas and default values will be described on
  89. *
  90. * 1.1.4 Preference values
  91. *
  92. * 1.2 Data structures used
  93. *
  94. * Addresse uses struct ATS_Address for each address. The structs are stored
  95. * in a linked list and provides a pointer void *solver_information for the
  96. * solver to store address specific information. It provides the int values
  97. * active which is set to GNUNET_YES if the address is select for transport
  98. * use and used, representing that transport service is actively using this
  99. * address. Address information are stored in peer, addr, addr_len, plugin.
  100. *
  101. * 1.3 Initialization
  102. *
  103. * During initialization a hashmap to store addresses is created. The quotas
  104. * for all networks defined for ATS are loaded from configuration. For each
  105. * network first the logic will check if the string
  106. * GNUNET_ATS_MaxBandwidthString is configured, if not it will try to convert
  107. * the configured value as a fancy size and if this fails it will try to use
  108. * it as a value_number. If no configuration value is found it will assign
  109. * GNUNET_ATS_DefaultBandwidth. The most important step is to load the
  110. * configured solver using configuration "[ats]:MODE". Current solvers are
  111. * MODE_PROPORTIONAL, MODE_MLP. Interaction is done using a solver API
  112. *
  113. * 1.4 Solver API
  114. *
  115. * Solver functions:
  116. * * s_init: init the solver with required information
  117. * * s_add: add a new address
  118. * * s_update: update ATS values or session for an address
  119. * * s_get: get prefered address for a peer
  120. * * s_del: delete an address
  121. * * s_pref: change preference value for a peer
  122. * * s_done: shutdown solver
  123. *
  124. * Callbacks: addresses provides a bandwidth_changed_cb callback to the
  125. * solver which is called when bandwidth assigned to peer has changed
  126. *
  127. * 1.5 Shutdown
  128. *
  129. * During shutdown all addresses are freed and the solver told to shutdown
  130. *
  131. * 1.6 Addresses and sessions
  132. *
  133. * Addresses consist of the address itself and a numerical session. When a
  134. * new address without a session is added it has no session, so it gets
  135. * session 0 assigned. When an address with a session is added and an address
  136. * object with session 0 is found, this object is updated with the session
  137. * otherwise a new address object with this session assigned is created.
  138. *
  139. * 1.6.1 Terminology
  140. *
  141. * Addresses a1,a2 with session s1, s2 are "exact" if:
  142. * (a1 == a2)&&(s1 == s2)
  143. * Addresses a1,a2 with session s1, s2 are "equivalent" if:
  144. * (a1 == a2)&&((s1 == s2)||(s1 == 0)||(s2 == 0)
  145. *
  146. * 1.7 Address management
  147. *
  148. * Transport service notifies ATS about changes to the addresses known to
  149. * him.
  150. *
  151. * 1.7.1 Adding an address
  152. *
  153. * When transport learns a new address it tells ATS and ATS is telling
  154. * addresses about it using GAS_address_add. If not known to addresses it
  155. * creates a new address object and calls solver's s_add. ATS information are
  156. * deserialized and solver is notified about the session and ATS information
  157. * using s_update.
  158. *
  159. * 1.7.2 Updating an address
  160. *
  161. * Addresses does an lookup up for the existing address with the given
  162. * session. If disassembles included ATS information and notifies the solver
  163. * using s_update about the update.
  164. *
  165. * 1.7.3 Deleting an address
  166. *
  167. * Addresses does an lookup for the exact address and session and if removes
  168. * this address. If session != 0 the session is set to 0 and the address is
  169. * kept. If session == 0, the addresses is removed.
  170. *
  171. * 1.7.4 Requesting an address suggestion
  172. *
  173. * The address client issues a request address message to be notified about
  174. * address suggestions for a specific peer. Addresses asks the solver with
  175. * s_get. If no address is available, it will not send a response, otherwise
  176. * it will respond with the choosen address.
  177. *
  178. * 1.7.5 Address suggestions
  179. *
  180. * Addresses will notify the client automatically on any bandwidth_changed_cb
  181. * by the solver if a address suggestion request is pending. If no address is
  182. * available it will not respond at all If the client is not interested
  183. * anymore, it has to cancel the address suggestion request.
  184. *
  185. * 1.7.6 Suggestions blocks and reset
  186. *
  187. * After suggesting an address it is blocked for ATS_BLOCKING_DELTA sec. to
  188. * prevent the client from being thrashed. If the client requires immediately
  189. * it can reset this block using GAS_addresses_handle_backoff_reset.
  190. *
  191. * 1.7.7 Address lifecycle
  192. *
  193. * * (add address)
  194. * * (updated address)
  195. * * (delete address)
  196. *
  197. * 1.8 Bandwidth assignment
  198. *
  199. * The addresses are used to perform resource allocation operations. ATS
  200. * addresses takes care of instantiating the solver configured and notifies
  201. * the respective solver about address changes and receives changes to the
  202. * bandwidth assignment from the solver. The current bandwidth assignment is
  203. * sent to transport. The specific solvers will be described in the specific
  204. * section.
  205. *
  206. * 1.9 Changing peer preferences
  207. *
  208. * The bandwidth assigned to a peer can be influenced by setting a preference
  209. * for a peer. The prefernce will be given to to the solver with s_pref which
  210. * has to take care of the preference value
  211. */
  212. /*
  213. * How long will address suggestions blocked after a suggestion
  214. */
  215. #define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
  216. /**
  217. * Information provided by ATS normalization
  218. */
  219. struct GAS_NormalizationInfo
  220. {
  221. /**
  222. * Next index to use in averaging queue
  223. */
  224. unsigned int avg_queue_index;
  225. /**
  226. * Averaging queue
  227. */
  228. uint64_t atsi_abs[GAS_normalization_queue_length];
  229. /**
  230. * Averaged ATSI values from queue
  231. */
  232. uint64_t avg;
  233. /**
  234. * Normalized values from queue to a range of values [1.0...2.0]
  235. */
  236. double norm;
  237. };
  238. /**
  239. * Address with additional information
  240. */
  241. struct ATS_Address
  242. {
  243. /**
  244. * Peer ID this address is for.
  245. */
  246. struct GNUNET_PeerIdentity peer;
  247. /**
  248. * Address (in plugin-specific binary format).
  249. */
  250. const void *addr;
  251. /**
  252. * Plugin name
  253. */
  254. char *plugin;
  255. /**
  256. * Solver-specific information for this address
  257. */
  258. void *solver_information;
  259. /**
  260. * ATS performance information for this address
  261. */
  262. struct GNUNET_ATS_Properties properties;
  263. /**
  264. * Time when address had last activity (update, in uses)
  265. */
  266. struct GNUNET_TIME_Absolute t_last_activity;
  267. /**
  268. * Time when address was added
  269. */
  270. struct GNUNET_TIME_Absolute t_added;
  271. /**
  272. * Address length, number of bytes in @e addr.
  273. */
  274. size_t addr_len;
  275. /**
  276. * Session ID, can never be 0.
  277. */
  278. uint32_t session_id;
  279. /**
  280. * Field to store local flags.
  281. * FIXME: `enum GNUNET_HELLO_AddressInfo`?
  282. */
  283. uint32_t local_address_info;
  284. /**
  285. * ATS performance information for this address, size of the @e atsi array.
  286. */
  287. uint32_t atsi_count;
  288. /**
  289. * Inbound bandwidth assigned by solver
  290. */
  291. uint32_t assigned_bw_in;
  292. /**
  293. * Outbound bandwidth assigned by solver
  294. */
  295. uint32_t assigned_bw_out;
  296. /**
  297. * Inbound bandwidth assigned by solver in NBO
  298. */
  299. uint32_t last_notified_bw_in;
  300. /**
  301. * Outbound bandwidth assigned by solver in NBO
  302. */
  303. uint32_t last_notified_bw_out;
  304. /**
  305. * Is this the active address for this peer?
  306. */
  307. int active;
  308. /**
  309. * Normalized delay information for this address.
  310. */
  311. struct GAS_NormalizationInfo norm_delay;
  312. /**
  313. * Normalized distance information for this address.
  314. */
  315. struct GAS_NormalizationInfo norm_distance;
  316. /**
  317. * Normalized utilization inbound for this address.
  318. */
  319. struct GAS_NormalizationInfo norm_utilization_in;
  320. /**
  321. * Normalized utilization outbound for this address.
  322. */
  323. struct GAS_NormalizationInfo norm_utilization_out;
  324. };
  325. /**
  326. * A multipeermap mapping peer identities to `struct ATS_Address`.
  327. */
  328. extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
  329. /**
  330. * Initialize address subsystem. The addresses subsystem manages the addresses
  331. * known and current performance information.
  332. *
  333. * @param server handle to our server
  334. */
  335. void
  336. GAS_addresses_init (struct GNUNET_SERVER_Handle *server);
  337. /**
  338. * Shutdown address subsystem.
  339. */
  340. void
  341. GAS_addresses_done (void);
  342. /**
  343. * Add a new address for a peer.
  344. *
  345. * @param peer peer
  346. * @param plugin_name transport plugin name
  347. * @param plugin_addr plugin address
  348. * @param plugin_addr_len length of the @a plugin_addr
  349. * @param local_address_info the local address for the address
  350. * @param session_id session id, can never be 0.
  351. * @param prop performance information for this address
  352. */
  353. void
  354. GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
  355. const char *plugin_name,
  356. const void *plugin_addr,
  357. size_t plugin_addr_len,
  358. uint32_t local_address_info,
  359. uint32_t session_id,
  360. const struct GNUNET_ATS_Properties *prop);
  361. /**
  362. * Update an address with new performance information for a peer.
  363. *
  364. * @param peer peer
  365. * @param session_id session id, can never be 0
  366. * @param prop performance information for this address
  367. */
  368. void
  369. GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
  370. uint32_t session_id,
  371. const struct GNUNET_ATS_Properties *prop);
  372. /**
  373. * Remove an address for a peer.
  374. *
  375. * @param peer peer
  376. * @param session_id session id, can never be 0
  377. */
  378. void
  379. GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
  380. uint32_t session_id);
  381. /**
  382. * Remove all addresses.
  383. */
  384. void
  385. GAS_addresses_destroy_all (void);
  386. /**
  387. * Iterator for #GAS_addresses_get_peer_info()
  388. *
  389. * @param cls closure
  390. * @param id the peer id
  391. * @param plugin_name plugin name
  392. * @param plugin_addr address
  393. * @param plugin_addr_len length of @a plugin_addr
  394. * @param address_active is address actively used
  395. * @param atsi ats performance information
  396. * @param bandwidth_out current outbound bandwidth assigned to address
  397. * @param bandwidth_in current inbound bandwidth assigned to address
  398. */
  399. typedef void
  400. (*GNUNET_ATS_PeerInfo_Iterator) (void *cls,
  401. const struct GNUNET_PeerIdentity *id,
  402. const char *plugin_name,
  403. const void *plugin_addr,
  404. size_t plugin_addr_len,
  405. const int address_active,
  406. const struct GNUNET_ATS_Properties *prop,
  407. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
  408. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
  409. /**
  410. * Return information all peers currently known to ATS
  411. *
  412. * @param peer the respective peer
  413. * @param pi_it the iterator to call for every peer
  414. * @param pi_it_cls the closure for @a pi_it
  415. */
  416. void
  417. GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
  418. GNUNET_ATS_PeerInfo_Iterator pi_it,
  419. void *pi_it_cls);
  420. /**
  421. * Handle 'address list request' messages from clients.
  422. *
  423. * @param cls unused, NULL
  424. * @param client client that sent the request
  425. * @param message the request message
  426. */
  427. void
  428. GAS_handle_request_address_list (void *cls,
  429. struct GNUNET_SERVER_Client *client,
  430. const struct GNUNET_MessageHeader *message);
  431. #endif
  432. /* end of gnunet-service-ats_addresses.h */