rps-sampler_client.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/rps-sampler_client.h
  18. * @brief client sampler implementation
  19. * @author Julius Bünger
  20. */
  21. #ifndef RPS_SAMPLER_CLIENT_H
  22. #define RPS_SAMPLER_CLIENT_H
  23. #include <inttypes.h>
  24. #include "rps-sampler_common.h"
  25. /**
  26. * A sampler sampling a stream of PeerIDs.
  27. */
  28. struct RPS_Sampler;
  29. /**
  30. * A handle to cancel a request.
  31. */
  32. struct RPS_SamplerRequestHandle;
  33. /**
  34. * Closure to _get_rand_peer_info()
  35. */
  36. struct RPS_SamplerRequestHandleSingleInfo;
  37. /**
  38. * Get the size of the sampler.
  39. *
  40. * @param sampler the sampler to return the size of.
  41. * @return the size of the sampler
  42. */
  43. unsigned int
  44. RPS_sampler_get_size (struct RPS_Sampler *sampler);
  45. /**
  46. * Grow or shrink the size of the sampler.
  47. *
  48. * @param sampler the sampler to resize.
  49. * @param new_size the new size of the sampler (not 0)
  50. */
  51. void
  52. RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
  53. /**
  54. * Initialise a modified tuple of sampler elements.
  55. *
  56. * @param init_size the size the sampler is initialised with
  57. * @param max_round_interval maximum time a round takes
  58. * @return a handle to a sampler that consists of sampler elements.
  59. */
  60. struct RPS_Sampler *
  61. RPS_sampler_mod_init (size_t init_size,
  62. struct GNUNET_TIME_Relative max_round_interval);
  63. /**
  64. * Update every sampler element of this sampler with given peer
  65. *
  66. * @param sampler the sampler to update.
  67. * @param id the PeerID that is put in the sampler
  68. */
  69. void
  70. RPS_sampler_update (struct RPS_Sampler *sampler,
  71. const struct GNUNET_PeerIdentity *id);
  72. /**
  73. * Reinitialise all previously initialised sampler elements with the given
  74. * value.
  75. *
  76. * Used to get rid of a PeerID.
  77. *
  78. * @param sampler the sampler to reinitialise a sampler in.
  79. * @param id the id of the samplers to update.
  80. */
  81. void
  82. RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
  83. const struct GNUNET_PeerIdentity *id);
  84. /**
  85. * Get n random peers out of the sampled peers.
  86. *
  87. * We might want to reinitialise this sampler after giving the
  88. * corrsponding peer to the client.
  89. * Random with or without consumption?
  90. *
  91. * @param sampler the sampler to get peers from.
  92. * @param cb callback that will be called once the ids are ready.
  93. * @param cls closure given to @a cb
  94. * @param num_peers the number of peers requested
  95. */
  96. struct RPS_SamplerRequestHandle *
  97. RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
  98. uint32_t num_peers,
  99. RPS_sampler_n_rand_peers_ready_cb cb,
  100. void *cls);
  101. /**
  102. * Cancel a request issued through #RPS_sampler_n_rand_peers_ready_cb.
  103. *
  104. * @param req_handle the handle to the request
  105. */
  106. void
  107. RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
  108. /**
  109. * Counts how many Samplers currently hold a given PeerID.
  110. *
  111. * @param sampler the sampler to count ids in.
  112. * @param id the PeerID to count.
  113. *
  114. * @return the number of occurrences of id.
  115. */
  116. uint32_t
  117. RPS_sampler_count_id (struct RPS_Sampler *sampler,
  118. const struct GNUNET_PeerIdentity *id);
  119. /**
  120. * Cleans the samplers.
  121. *
  122. * @param sampler the sampler to destroy.
  123. */
  124. void
  125. RPS_sampler_destroy (struct RPS_Sampler *sampler);
  126. #endif /* RPS_SAMPLER_CLIENT_H */
  127. /* end of gnunet-service-rps.c */