gnunet-service-ats_normalization.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2011 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_normalization.h
  19. * @brief ats service address: management of ATS properties and preferences normalization
  20. * @author Matthias Wachs
  21. * @author Christian Grothoff
  22. */
  23. #include "platform.h"
  24. #include "gnunet_ats_service.h"
  25. #define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
  26. #define PREF_AGING_FACTOR 0.95
  27. #define PREF_EPSILON 0.01
  28. #define DEFAULT_REL_PREFERENCE 0.0
  29. #define DEFAULT_ABS_PREFERENCE 0.0
  30. #define DEFAULT_REL_QUALITY 1.0
  31. typedef void
  32. (*GAS_Normalization_preference_changed_cb) (void *cls,
  33. const struct GNUNET_PeerIdentity *peer,
  34. enum GNUNET_ATS_PreferenceKind kind,
  35. double pref_rel);
  36. typedef void
  37. (*GAS_Normalization_property_changed_cb) (void *cls,
  38. struct ATS_Address *peer,
  39. uint32_t type,
  40. double prop_rel);
  41. /**
  42. * Get the normalized preference values for a specific peer
  43. *
  44. * @param id the peer @return pointer to the values, can be indexed
  45. * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist
  46. */
  47. const double *
  48. GAS_normalization_get_preferences_by_peer (const struct GNUNET_PeerIdentity *id);
  49. /**
  50. * Get the normalized properties values for a specific peer or
  51. * the default values if
  52. *
  53. * @param address the address
  54. * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind,
  55. * default preferences if peer does not exist
  56. */
  57. const double *
  58. GAS_normalization_get_properties (struct ATS_Address *address);
  59. /**
  60. * Get the normalized preference values for a specific client and peer
  61. *
  62. * @param client client
  63. * @param peer the peer
  64. * @param pref the preference type
  65. * @return the value
  66. */
  67. double
  68. GAS_normalization_get_preferences_by_client (const void *client,
  69. const struct GNUNET_PeerIdentity *peer,
  70. enum GNUNET_ATS_PreferenceKind pref);
  71. /**
  72. * Normalize an updated preference value
  73. *
  74. * @param client the client with this preference
  75. * @param peer the peer to change the preference for
  76. * @param kind the kind to change the preference
  77. * @param score_abs the normalized score
  78. */
  79. void
  80. GAS_normalization_normalize_preference (void *client,
  81. const struct GNUNET_PeerIdentity *peer,
  82. enum GNUNET_ATS_PreferenceKind kind,
  83. float score_abs);
  84. /**
  85. * Update and normalize a atsi performance information
  86. *
  87. * @param addresses hashmap containing all addresses
  88. * @param address the address to update
  89. * @param atsi the array of performance information
  90. * @param atsi_count the number of atsi information in the array
  91. */
  92. void
  93. GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
  94. struct ATS_Address *address,
  95. const struct GNUNET_ATS_Information *atsi,
  96. uint32_t atsi_count);
  97. /**
  98. * A performance client disconnected
  99. *
  100. * @param client the disconnecting client
  101. */
  102. void
  103. GAS_normalization_preference_client_disconnect (void *client);
  104. /**
  105. * Start the normalization component
  106. *
  107. * @param pref_ch_cb callback to call on relative preference changing
  108. * @param pref_ch_cb_cls cls for the preference callback
  109. * @param property_ch_cb callback to call on relative property changing
  110. * @param property_ch_cb_cls cls for the property callback
  111. */
  112. void
  113. GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
  114. void *pref_ch_cb_cls,
  115. GAS_Normalization_property_changed_cb property_ch_cb,
  116. void *property_ch_cb_cls);
  117. /**
  118. * Stop the normalization component and free all items
  119. */
  120. void
  121. GAS_normalization_stop ();
  122. /* end of gnunet-service-ats_normalization.h */