gnunet_nse_service.h 3.1 KB

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