gnunet_nse_service.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2011 GNUnet e.V.
  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. #ifndef GNUNET_NSE_SERVICE_H_
  17. #define GNUNET_NSE_SERVICE_H_
  18. /**
  19. * @author Nathan Evans
  20. *
  21. * @file
  22. * API to retrieve the current network size estimate
  23. *
  24. * @defgroup nse NSE service
  25. * Network Size Estimation
  26. *
  27. * Provides an API to retrieve the current network size estimate,
  28. * also to register for notifications whenever a new
  29. * network size estimate is calculated.
  30. *
  31. * @see [Documentation](https://gnunet.org/gnunet-nse-subsystem)
  32. *
  33. * @{
  34. */
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #if 0 /* keep Emacsens' auto-indent happy */
  39. }
  40. #endif
  41. #endif
  42. #include "gnunet_util_lib.h"
  43. /**
  44. * Version of the network size estimation API.
  45. */
  46. #define GNUNET_NSE_VERSION 0x00000000
  47. /**
  48. * Handle for the network size estimation service.
  49. */
  50. struct GNUNET_NSE_Handle;
  51. /**
  52. * Callback to call when network size estimate is updated.
  53. *
  54. * @param cls closure
  55. * @param timestamp time when the estimate was received from the server (or created by the server)
  56. * @param logestimate the log(Base 2) value of the current network size estimate
  57. * @param std_dev standard deviation for the estimate
  58. *
  59. */
  60. typedef void (*GNUNET_NSE_Callback) (void *cls,
  61. struct GNUNET_TIME_Absolute timestamp,
  62. double logestimate, double std_dev);
  63. /**
  64. * Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback'
  65. * into an absolute estimate in terms of the number of peers in the network.
  66. *
  67. * @param loge logarithmic estimate
  68. * @return absolute number of peers in the network (estimated)
  69. */
  70. #define GNUNET_NSE_log_estimate_to_n(loge) pow(2.0, (loge))
  71. /**
  72. * Connect to the network size estimation service.
  73. *
  74. * @param cfg the configuration to use
  75. * @param func funtion to call with network size estimate
  76. * @param func_cls closure to pass to @a func
  77. * @return handle to use in #GNUNET_NSE_disconnect to stop NSE from invoking the callbacks
  78. */
  79. struct GNUNET_NSE_Handle *
  80. GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  81. GNUNET_NSE_Callback func, void *func_cls);
  82. /**
  83. * Disconnect from network size estimation service
  84. *
  85. * @param h handle to destroy
  86. */
  87. void
  88. GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
  89. #if 0 /* keep Emacsens' auto-indent happy */
  90. {
  91. #endif
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. /** @} */ /* end of group nse */
  96. #endif /* GNUNET_NSE_SERVICE_H_ */