gnunet-service-rps_view.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_view.h
  18. * @brief wrapper around the "local view"
  19. * @author Julius Bünger
  20. */
  21. #include "gnunet_util_lib.h"
  22. #include <inttypes.h>
  23. struct View;
  24. /**
  25. * Create an empty view.
  26. *
  27. * @param len the maximum length for the view
  28. * @return The newly created view
  29. */
  30. struct View *
  31. View_create (unsigned int len);
  32. /**
  33. * Change length of view
  34. *
  35. * If size is decreased, peers with higher indices are removed.
  36. *
  37. * @param view The view that is changed
  38. * @param len the (maximum) length for the view
  39. */
  40. void
  41. View_change_len (struct View *view,
  42. unsigned int len);
  43. /**
  44. * Get the view as an array
  45. *
  46. * @return the view in array representation
  47. */
  48. const struct GNUNET_PeerIdentity *
  49. View_get_as_array (const struct View *view);
  50. /**
  51. * Get the size of the view
  52. *
  53. * @param view The view of which the size should be returned
  54. * @return current number of actually contained peers
  55. */
  56. unsigned int
  57. View_size (const struct View *view);
  58. /**
  59. * Insert peer into the view
  60. *
  61. * @param view The view to put the peer into
  62. * @param peer the peer to insert
  63. *
  64. * @return GNUNET_OK if peer was actually inserted
  65. * GNUNET_NO if peer was not inserted
  66. */
  67. int
  68. View_put (struct View *view,
  69. const struct GNUNET_PeerIdentity *peer);
  70. /**
  71. * Check whether view contains a peer
  72. *
  73. * @param view The which is checked for a peer
  74. * @param peer the peer to check for
  75. *
  76. * @return GNUNET_OK if view contains peer
  77. * GNUNET_NO otherwise
  78. */
  79. int
  80. View_contains_peer (const struct View *view,
  81. const struct GNUNET_PeerIdentity *peer);
  82. /**
  83. * Remove peer from view
  84. *
  85. * @param view The view of which to remove the peer
  86. * @param peer the peer to remove
  87. *
  88. * @return GNUNET_OK if view contained peer and removed it successfully
  89. * GNUNET_NO if view does not contain peer
  90. */
  91. int
  92. View_remove_peer (struct View *view,
  93. const struct GNUNET_PeerIdentity *peer);
  94. /**
  95. * Get a peer by index
  96. *
  97. * @param view the view of which to get the peer
  98. * @param index the index of the peer to get
  99. *
  100. * @return peer to the corresponding index.
  101. * NULL if this index is not known
  102. */
  103. const struct GNUNET_PeerIdentity *
  104. View_get_peer_by_index (const struct View *view,
  105. uint32_t index);
  106. /**
  107. * Clear the view
  108. *
  109. * @param view The view to clear
  110. */
  111. void
  112. View_clear (struct View *view);
  113. /**
  114. * Destroy view.
  115. *
  116. * @param view the view to destroy
  117. */
  118. void
  119. View_destroy (struct View *view);
  120. /* end of gnunet-service-rps_view.h */