GNUnet 0.22.2
nse_api.c File Reference

api to get information from the network size estimation service More...

#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
#include "gnunet_nse_service.h"
#include "nse.h"
Include dependency graph for nse_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_NSE_Handle
 Handle for talking with the NSE service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "nse-api", __VA_ARGS__)
 

Functions

static void reconnect (void *cls)
 Try again to connect to network size estimation service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static void handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg)
 Type of a function to call when we receive a message from the service. More...
 
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

api to get information from the network size estimation service

Author
Nathan Evans

Definition in file nse_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "nse-api", __VA_ARGS__)

Definition at line 34 of file nse_api.c.

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to network size estimation service.

Parameters
clsclosure with the struct GNUNET_NSE_Handle *
clsthe struct GNUNET_NSE_Handle *

Definition at line 131 of file nse_api.c.

132{
133 struct GNUNET_NSE_Handle *h = cls;
135 { GNUNET_MQ_hd_fixed_size (estimate,
138 h),
141 struct GNUNET_MQ_Envelope *env;
142
143 h->reconnect_task = NULL;
145 "Connecting to network size estimation service.\n");
146 GNUNET_assert (NULL == h->mq);
148 if (NULL == h->mq)
149 return;
152}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_NSE_START
client->service message indicating start
#define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE
service->client message indicating
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: nse_api.c:92
#define LOG(kind,...)
Definition: nse_api.c:34
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Message handler for a specific message type.
Header for all communications.
Network size estimate sent from the service to clients.
Definition: nse.h:43
Handle for talking with the NSE service.
Definition: nse_api.c:40

References GNUNET_ARM_Handle::cfg, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, GNUNET_MESSAGE_TYPE_NSE_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), msg, and GNUNET_ARM_Handle::reconnect_task.

Referenced by GNUNET_NSE_connect(), and mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_NSE_Handle *
errorerror code

Definition at line 92 of file nse_api.c.

93{
94 struct GNUNET_NSE_Handle *h = cls;
95
96 (void) error;
98 h->mq = NULL;
100 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
101 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
102}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void reconnect(void *cls)
Try again to connect to network size estimation service.
Definition: nse_api.c:131

References GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, h, GNUNET_ARM_Handle::mq, reconnect(), and GNUNET_ARM_Handle::reconnect_task.

Referenced by reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_estimate()

static void handle_estimate ( void *  cls,
const struct GNUNET_NSE_ClientMessage client_msg 
)
static

Type of a function to call when we receive a message from the service.

Parameters
clsclosure
client_msgmessage received

Definition at line 113 of file nse_api.c.

114{
115 struct GNUNET_NSE_Handle *h = cls;
116
117 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
118 h->recv_cb (h->recv_cb_cls,
120 GNUNET_ntoh_double (client_msg->size_estimate),
121 GNUNET_ntoh_double (client_msg->std_deviation));
122}
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:83
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
double size_estimate
The current estimated network size.
Definition: nse.h:62
struct GNUNET_TIME_AbsoluteNBO timestamp
Timestamp at which the server received the message.
Definition: nse.h:57
double std_deviation
The standard deviation (rounded down to the nearest integer) of size estimations.
Definition: nse.h:69

References GNUNET_ntoh_double(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO, h, GNUNET_NSE_ClientMessage::size_estimate, GNUNET_NSE_ClientMessage::std_deviation, and GNUNET_NSE_ClientMessage::timestamp.

Here is the call graph for this function: