gnunet_rps_service.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C)
  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., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Julius Bünger
  19. *
  20. * @file
  21. * API to the rps service
  22. *
  23. * @defgroup rps RPS service
  24. * Random Peer Sampling
  25. * @{
  26. */
  27. #ifndef GNUNET_RPS_SERVICE_H
  28. #define GNUNET_RPS_SERVICE_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. /**
  37. * Version of the rps API.
  38. */
  39. #define GNUNET_RPS_VERSION 0x00000000
  40. /**
  41. * Handle for the random peer sampling service
  42. */
  43. struct GNUNET_RPS_Handle;
  44. /**
  45. * Handle for one request to the rps service
  46. */
  47. struct GNUNET_RPS_Request_Handle;
  48. /**
  49. * Callback called when requested random peers are available.
  50. *
  51. * @param cls the closure given with the request
  52. * @param num_peers the number of peers returned
  53. * @param peers array with num_peers PeerIDs
  54. */
  55. typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
  56. uint64_t num_peers,
  57. const struct GNUNET_PeerIdentity *peers);
  58. /**
  59. * Connect to the rps service
  60. *
  61. * @param cfg configuration to use
  62. * @return handle to the rps service
  63. */
  64. struct GNUNET_RPS_Handle *
  65. GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  66. /**
  67. * Request n random peers.
  68. *
  69. * This does exacly the same as GNUNET_RPS_request_peers_single_call
  70. * but needs a GNUNET_RPS_Handle.
  71. * This exists only for other parts of GNUnet that expect having to
  72. * (dis)connect from/to a service.
  73. *
  74. * @param h handle to the rps service
  75. * @param n number of random peers to return
  76. * @param ready_cb the callback to be called when the peers are available
  77. * @param cls a closure that will be given to the callback
  78. * @return handle to this request
  79. */
  80. struct GNUNET_RPS_Request_Handle *
  81. GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
  82. GNUNET_RPS_NotifyReadyCB ready_cb,
  83. void *cls);
  84. /**
  85. * Seed rps service with peerIDs.
  86. *
  87. * @param h handle to the rps service
  88. * @param n number of peers to seed
  89. * @param ids the ids of the peers seeded
  90. */
  91. void
  92. GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
  93. const struct GNUNET_PeerIdentity * ids);
  94. /**
  95. * Cancle an issued request.
  96. *
  97. * @param rh handle of the pending request to be canceled
  98. */
  99. void
  100. GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
  101. #ifdef ENABLE_MALICIOUS
  102. /**
  103. * Turn RPS service to act malicious.
  104. *
  105. * @param h handle to the rps service
  106. * @param type which type of malicious peer to turn to.
  107. * 0 Don't act malicious at all
  108. * 1 Try to maximise representation
  109. * 2 Try to partition the network
  110. * (isolate one peer from the rest)
  111. * @param n number of @a ids
  112. * @param ids the ids of the malicious peers
  113. * if @type is 2 the last id is the id of the
  114. * peer to be isolated from the rest
  115. */
  116. void
  117. GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
  118. uint32_t type,
  119. uint32_t num_peers,
  120. const struct GNUNET_PeerIdentity *ids,
  121. const struct GNUNET_PeerIdentity *target_peer);
  122. #endif /* ENABLE_MALICIOUS */
  123. /**
  124. * Disconnect from the rps service
  125. *
  126. * @param h the handle to the rps service
  127. */
  128. void
  129. GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
  130. #if 0 /* keep Emacsens' auto-indent happy */
  131. {
  132. #endif
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif
  137. /** @} */ /* end of group */