GNUnet  0.10.x
Macros | Typedefs | Functions
NSE service

Network Size Estimation. More...

Macros

#define GNUNET_NSE_VERSION   0x00000000
 Version of the network size estimation API. More...
 
#define GNUNET_NSE_log_estimate_to_n(loge)   pow(2.0, (loge))
 Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in terms of the number of peers in the network. More...
 

Typedefs

typedef void(* GNUNET_NSE_Callback) (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
 Callback to call when network size estimate is updated. More...
 

Functions

struct GNUNET_NSE_HandleGNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
 Connect to the network size estimation service. More...
 
void GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
 Disconnect from network size estimation service. More...
 

Detailed Description

Network Size Estimation.

Provides an API to retrieve the current network size estimate, also to register for notifications whenever a new network size estimate is calculated.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_NSE_VERSION

#define GNUNET_NSE_VERSION   0x00000000

Version of the network size estimation API.

Definition at line 55 of file gnunet_nse_service.h.

◆ GNUNET_NSE_log_estimate_to_n

#define GNUNET_NSE_log_estimate_to_n (   loge)    pow(2.0, (loge))

Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in terms of the number of peers in the network.

Parameters
logelogarithmic estimate
Returns
absolute number of peers in the network (estimated)

Definition at line 83 of file gnunet_nse_service.h.

Referenced by adapt_sizes(), handle_estimate(), and nse_cb().

Typedef Documentation

◆ GNUNET_NSE_Callback

typedef void(* GNUNET_NSE_Callback) (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)

Callback to call when network size estimate is updated.

Parameters
clsclosure
timestamptime when the estimate was received from the server (or created by the server)
logestimatethe log(Base 2) value of the current network size estimate
std_devstandard deviation for the estimate

Definition at line 71 of file gnunet_nse_service.h.

Function Documentation

◆ GNUNET_NSE_connect()

struct GNUNET_NSE_Handle* GNUNET_NSE_connect ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_NSE_Callback  func,
void *  func_cls 
)

Connect to the network size estimation service.

Parameters
cfgthe configuration to use
funcfuntion to call with network size estimate
func_clsclosure to pass to func
Returns
handle to use in GNUNET_NSE_disconnect to stop NSE from invoking the callbacks
Parameters
cfgthe configuration to use
funcfuntion to call with network size estimate
func_clsclosure to pass to func
Returns
handle to use

Definition at line 164 of file nse_api.c.

References GNUNET_NSE_Handle::cfg, GNUNET_assert, GNUNET_free, GNUNET_new, GNUNET_TIME_UNIT_ZERO, h, GNUNET_NSE_Handle::mq, reconnect(), GNUNET_NSE_Handle::reconnect_delay, GNUNET_NSE_Handle::recv_cb, and GNUNET_NSE_Handle::recv_cb_cls.

Referenced by GDS_NSE_init(), nse_connect_adapter(), reconnect(), and run().

167 {
168  struct GNUNET_NSE_Handle *h;
169 
170  GNUNET_assert(NULL != func);
171  h = GNUNET_new(struct GNUNET_NSE_Handle);
172  h->cfg = cfg;
173  h->recv_cb = func;
174  h->recv_cb_cls = func_cls;
176  reconnect(h);
177  if (NULL == h->mq)
178  {
179  GNUNET_free(h);
180  return NULL;
181  }
182  return h;
183 }
struct GNUNET_MQ_Handle * mq
Message queue (if available).
Definition: nse_api.c:49
void * recv_cb_cls
Closure to pass to recv_cb callback.
Definition: nse_api.c:69
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: nse_api.c:44
GNUNET_NSE_Callback recv_cb
Callback function to call when message is received.
Definition: nse_api.c:64
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
Handle for talking with the NSE service.
Definition: nse_api.c:40
static void reconnect(void *cls)
Try again to connect to network size estimation service.
Definition: nse_api.c:131
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_Relative reconnect_delay
Time for next connect retry.
Definition: nse_api.c:59
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NSE_disconnect()

void GNUNET_NSE_disconnect ( struct GNUNET_NSE_Handle h)

Disconnect from network size estimation service.

Parameters
hhandle to destroy

Definition at line 192 of file nse_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_NSE_Handle::mq, and GNUNET_NSE_Handle::reconnect_task.

Referenced by do_shutdown(), GDS_NSE_done(), GNUNET_RPS_disconnect(), nse_disconnect_adapter(), reconnect(), and shutdown_task().

193 {
194  if (NULL != h->reconnect_task)
195  {
197  h->reconnect_task = NULL;
198  }
199  if (NULL != h->mq)
200  {
201  GNUNET_MQ_destroy(h->mq);
202  h->mq = NULL;
203  }
204  GNUNET_free(h);
205 }
struct GNUNET_MQ_Handle * mq
Message queue (if available).
Definition: nse_api.c:49
struct GNUNET_SCHEDULER_Task * reconnect_task
Task doing exponential back-off trying to reconnect.
Definition: nse_api.c:54
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function: