gnunet-service-rps_sampler_elem.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C)
  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. * @file rps/gnunet-service-rps_sampler_elem.h
  18. * @brief sampler element implementation
  19. * @author Julius Bünger
  20. */
  21. #ifndef RPS_SAMPLER_ELEM_H
  22. #define RPS_SAMPLER_ELEM_H
  23. #include <inttypes.h>
  24. /***********************************************************************
  25. * WARNING: This section needs to be reviewed regarding the use of
  26. * functions providing (pseudo)randomness!
  27. ***********************************************************************/
  28. /**
  29. * Used to indicate whether a sampler element is empty.
  30. */
  31. enum RPS_SamplerEmpty
  32. {
  33. NOT_EMPTY = 0x0,
  34. EMPTY = 0x1
  35. };
  36. /**
  37. * A sampler element sampling one PeerID at a time.
  38. */
  39. struct RPS_SamplerElement
  40. {
  41. /**
  42. * Min-wise linear permutation used by this sampler.
  43. *
  44. * This is an key later used by a hmac.
  45. */
  46. struct GNUNET_CRYPTO_AuthKey auth_key;
  47. /**
  48. * The PeerID this sampler currently samples.
  49. */
  50. struct GNUNET_PeerIdentity peer_id;
  51. /**
  52. * The according hash value of this PeerID.
  53. */
  54. struct GNUNET_HashCode peer_id_hash;
  55. /**
  56. * Time of last request.
  57. */
  58. struct GNUNET_TIME_Absolute last_client_request;
  59. /**
  60. * Flag that indicates that we are not holding a valid PeerID right now.
  61. */
  62. enum RPS_SamplerEmpty is_empty;
  63. /**
  64. * 'Birth'
  65. */
  66. struct GNUNET_TIME_Absolute birth;
  67. /**
  68. * How many times a PeerID was put in this sampler.
  69. */
  70. uint32_t num_peers;
  71. /**
  72. * How many times this sampler changed the peer_id.
  73. */
  74. uint32_t num_change;
  75. /**
  76. * The file name this sampler element should log to
  77. */
  78. char *file_name;
  79. };
  80. /**
  81. * Reinitialise a previously initialised sampler element.
  82. *
  83. * @param sampler_el The sampler element to (re-) initialise
  84. */
  85. void
  86. RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem);
  87. /**
  88. * Create a sampler element and initialise it.
  89. *
  90. * In this implementation this means choosing an auth_key for later use in
  91. * a hmac at random.
  92. *
  93. * @return a newly created RPS_SamplerElement which currently holds no id.
  94. */
  95. struct RPS_SamplerElement *
  96. RPS_sampler_elem_create (void);
  97. /**
  98. * Destroy a sampler element.
  99. *
  100. * @param sampler_elem the element to destroy
  101. */
  102. void
  103. RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem);
  104. /**
  105. * Update a sampler element with a PeerID
  106. *
  107. * @param sampler_elem The sampler element to update
  108. * @param new_ID The PeerID to update with
  109. */
  110. void
  111. RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem,
  112. const struct GNUNET_PeerIdentity *new_ID);
  113. /**
  114. * Set the min-wise independent function of the given sampler element.
  115. *
  116. * @param sampler_elem the sampler element
  117. * @param auth_key the key to use
  118. */
  119. void
  120. RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem,
  121. struct GNUNET_CRYPTO_AuthKey auth_key);
  122. #endif /* RPS_SAMPLER_ELEM_H */
  123. /* end of gnunet-service-rps.c */