GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
rps_api.c File Reference

API for rps. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "rps.h"
#include "gnunet_rps_service.h"
#include "rps-sampler_client.h"
#include "gnunet_nse_service.h"
#include <inttypes.h>
Include dependency graph for rps_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_RPS_StreamRequestHandle
 Handle for a request to get peers from biased stream of ids. More...
 
struct  GNUNET_RPS_Handle
 Handler to handle requests from a client. More...
 
struct  GNUNET_RPS_Request_Handle
 Handler for a single request from a client. More...
 
struct  GNUNET_RPS_Request_Handle_Single_Info
 Handler for a single request from a client. More...
 
struct  cb_cls_pack
 Struct used to pack the callback, its closure (provided by the caller) and the connection handler to the service to pass it to a callback function. More...
 

Macros

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

Functions

static struct GNUNET_RPS_StreamRequestHandlenew_stream_request (struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadyCB ready_cb, void *cls)
 Create a new handle for a stream request. More...
 
static void remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh)
 Remove the given stream request from the list of requests and memory. More...
 
static void peers_ready_cb (const struct GNUNET_PeerIdentity *peers, uint32_t num_peers, void *cls)
 Called once the sampler has collected all requested peers. More...
 
static void peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers, void *cls, double probability, uint32_t num_observed)
 Called once the sampler has collected the requested peer. More...
 
static void collect_peers_cb (void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
 Callback to collect the peers from the biased stream and put those into the sampler. More...
 
static void collect_peers_info_cb (void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
 Callback to collect the peers from the biased stream and put those into the sampler. More...
 
void GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle, uint32_t num_updates, GNUNET_RPS_NotifyReadyCB view_update_cb, void *cls)
 Request updates of view. More...
 
void GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle)
 
struct GNUNET_RPS_StreamRequestHandleGNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadyCB stream_input_cb, void *cls)
 Request biased stream of peers that are being put into the sampler. More...
 
static int check_view_update (void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
 This function is called, when the service updates the view. More...
 
static void handle_view_update (void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
 This function is called, when the service updated its view. More...
 
static void cancel_stream (struct GNUNET_RPS_Handle *rps_handle)
 Send message to service that this client does not want to receive further updates from the biased peer stream. More...
 
void GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh)
 Cancel a specific request for updates from the biased peer stream. More...
 
static int check_stream_input (void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
 This function is called, when the service sends another peer from the biased stream. More...
 
static void srh_callback_scheduled (void *cls)
 Called by the scheduler to call the callbacks of the srh handlers. More...
 
static void handle_stream_input (void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
 This function is called, when the service sends another peer from the biased stream. More...
 
static void reconnect (struct GNUNET_RPS_Handle *h)
 Reconnect to the service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Error handler for mq. More...
 
static void hash_from_share_val (const char *share_val, struct GNUNET_HashCode *hash)
 Create the hash value from the share value that defines the sub (-group) More...
 
static void nse_cb (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
 Callback for network size estimate - called with new estimates about the network size, updates all samplers with the new estimate. More...
 
struct GNUNET_RPS_HandleGNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the rps service. More...
 
void GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h, const char *shared_value)
 Start a sub with the given shared value. More...
 
void GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h, const char *shared_value)
 Stop a sub with the given shared value. More...
 
struct GNUNET_RPS_Request_HandleGNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, uint32_t num_req_peers, GNUNET_RPS_NotifyReadyCB ready_cb, void *cls)
 Request n random peers. More...
 
struct GNUNET_RPS_Request_Handle_Single_InfoGNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, void *cls)
 Request one random peer, getting additional information. More...
 
void GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n, const struct GNUNET_PeerIdentity *ids)
 Seed rps service with peerIDs. More...
 
void GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
 Cancle an issued request. More...
 
void GNUNET_RPS_request_single_info_cancel (struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
 Cancle an issued single info request. More...
 
void GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
 Disconnect from the rps service. More...
 

Variables

static struct GNUNET_PeerIdentitysrh_callback_peers
 Peers received from the biased stream to be passed to all srh_handlers. More...
 
static uint64_t srh_callback_num_peers
 Number of peers in the biased stream that are to be passed to all srh_handlers. More...
 

Detailed Description

API for rps.

Author
Julius Bünger

Definition in file rps_api.c.

Macro Definition Documentation

◆ LOG

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

Function Documentation

◆ new_stream_request()

static struct GNUNET_RPS_StreamRequestHandle* new_stream_request ( struct GNUNET_RPS_Handle rps_handle,
GNUNET_RPS_NotifyReadyCB  ready_cb,
void *  cls 
)
static

Create a new handle for a stream request.

Parameters
rps_handleThe rps handle
num_peersThe number of desired peers
ready_cbThe callback to be called, once all peers are ready
clsThe colsure to provide to the callback
Returns
The handle to the stream request

Definition at line 304 of file rps_api.c.

References GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_RPS_StreamRequestHandle::ready_cb, GNUNET_RPS_StreamRequestHandle::ready_cb_cls, GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Handle::stream_requests_head, and GNUNET_RPS_Handle::stream_requests_tail.

Referenced by GNUNET_RPS_stream_request().

307 {
308  struct GNUNET_RPS_StreamRequestHandle *srh;
309 
311  srh->rps_handle = rps_handle;
312  srh->ready_cb = ready_cb;
313  srh->ready_cb_cls = cls;
315  rps_handle->stream_requests_tail,
316  srh);
317 
318  return srh;
319 }
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:51
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_tail
Tail of the DLL of stream requests.
Definition: rps_api.c:113
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:56
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
Here is the caller graph for this function:

◆ remove_stream_request()

static void remove_stream_request ( struct GNUNET_RPS_StreamRequestHandle srh)
static

Remove the given stream request from the list of requests and memory.

Parameters
srhThe request to be removed

Definition at line 328 of file rps_api.c.

References GNUNET_RPS_StreamRequestHandle::callback_task, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Handle::stream_requests_head, and GNUNET_RPS_Handle::stream_requests_tail.

Referenced by GNUNET_RPS_stream_cancel().

329 {
330  struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle;
331 
332  GNUNET_assert (NULL != srh);
333  if (NULL != srh->callback_task)
334  {
336  srh->callback_task = NULL;
337  }
339  rps_handle->stream_requests_tail,
340  srh);
341  GNUNET_free (srh);
342 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
Handler to handle requests from a client.
Definition: rps_api.c:78
struct GNUNET_RPS_StreamRequestHandle * stream_requests_tail
Tail of the DLL of stream requests.
Definition: rps_api.c:113
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
Definition: rps_api.c:61
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peers_ready_cb()

static void peers_ready_cb ( const struct GNUNET_PeerIdentity peers,
uint32_t  num_peers,
void *  cls 
)
static

Called once the sampler has collected all requested peers.

Calls the callback provided by the client with the corresponding cls.

Parameters
peersThe array of num_peers that has been returned.
num_peersThe number of peers that have been returned
clsThe GNUNET_RPS_Request_Handle

Definition at line 355 of file rps_api.c.

References GNUNET_RPS_request_cancel(), GNUNET_RPS_Request_Handle::ready_cb, GNUNET_RPS_Request_Handle::ready_cb_cls, and GNUNET_RPS_Request_Handle::sampler_rh.

Referenced by GNUNET_RPS_request_peers().

358 {
359  struct GNUNET_RPS_Request_Handle *rh = cls;
360 
361  rh->sampler_rh = NULL;
362  rh->ready_cb (rh->ready_cb_cls,
363  num_peers,
364  peers);
366 }
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:190
struct RPS_SamplerRequestHandle * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:179
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:195
static unsigned int num_peers
void GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
Cancle an issued request.
Definition: rps_api.c:1187
Handler for a single request from a client.
Definition: rps_api.c:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_info_ready_cb()

static void peer_info_ready_cb ( const struct GNUNET_PeerIdentity peers,
void *  cls,
double  probability,
uint32_t  num_observed 
)
static

Called once the sampler has collected the requested peer.

Calls the callback provided by the client with the corresponding cls.

Parameters
peersThe array of num_peers that has been returned.
num_peersThe number of peers that have been returned
clsThe GNUNET_RPS_Request_Handle
probabilityProbability with which all IDs have been observed
num_observedNumber of observed IDs

Definition at line 381 of file rps_api.c.

References GNUNET_RPS_request_single_info_cancel(), GNUNET_RPS_Request_Handle_Single_Info::ready_cb, GNUNET_RPS_Request_Handle_Single_Info::ready_cb_cls, and GNUNET_RPS_Request_Handle_Single_Info::sampler_rh.

Referenced by GNUNET_RPS_request_peer_info().

385 {
386  struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls;
387 
388  rh->sampler_rh = NULL;
389  rh->ready_cb (rh->ready_cb_cls,
390  peers,
391  probability,
392  num_observed);
394 }
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:243
void GNUNET_RPS_request_single_info_cancel(struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
Cancle an issued single info request.
Definition: rps_api.c:1217
Handler for a single request from a client.
Definition: rps_api.c:212
struct RPS_SamplerRequestHandleSingleInfo * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:227
GNUNET_RPS_NotifyReadySingleInfoCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:238
Here is the call graph for this function:
Here is the caller graph for this function:

◆ collect_peers_cb()

static void collect_peers_cb ( void *  cls,
uint64_t  num_peers,
const struct GNUNET_PeerIdentity peers 
)
static

Callback to collect the peers from the biased stream and put those into the sampler.

Parameters
clsThe GNUNET_RPS_Request_Handle
num_peersThe number of peer that have been returned
peersThe array of num_peers that have been returned

Definition at line 406 of file rps_api.c.

References GNUNET_ERROR_TYPE_DEBUG, LOG, num_peers, RPS_sampler_update(), and GNUNET_RPS_Request_Handle::sampler.

Referenced by GNUNET_RPS_request_peers().

409 {
410  struct GNUNET_RPS_Request_Handle *rh = cls;
411 
413  "Service sent %" PRIu64 " peers from stream\n",
414  num_peers);
415  for (uint64_t i = 0; i < num_peers; i++)
416  {
417  RPS_sampler_update (rh->sampler, &peers[i]);
418  }
419 }
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
static unsigned int num_peers
Handler for a single request from a client.
Definition: rps_api.c:159
#define LOG(kind,...)
Definition: rps_api.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ collect_peers_info_cb()

static void collect_peers_info_cb ( void *  cls,
uint64_t  num_peers,
const struct GNUNET_PeerIdentity peers 
)
static

Callback to collect the peers from the biased stream and put those into the sampler.

This version is for the modified GNUNET_RPS_Request_Handle_Single_Info

Parameters
clsThe GNUNET_RPS_Request_Handle
num_peersThe number of peer that have been returned
peersThe array of num_peers that have been returned

Definition at line 433 of file rps_api.c.

References GNUNET_ERROR_TYPE_DEBUG, LOG, num_peers, RPS_sampler_update(), and GNUNET_RPS_Request_Handle_Single_Info::sampler.

Referenced by GNUNET_RPS_request_peer_info().

436 {
437  struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls;
438 
440  "Service sent %" PRIu64 " peers from stream\n",
441  num_peers);
442  for (uint64_t i = 0; i < num_peers; i++)
443  {
444  RPS_sampler_update (rhs->sampler, &peers[i]);
445  }
446 }
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
Handler for a single request from a client.
Definition: rps_api.c:212
static unsigned int num_peers
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:222
#define LOG(kind,...)
Definition: rps_api.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RPS_view_request_cancel()

void GNUNET_RPS_view_request_cancel ( struct GNUNET_RPS_Handle rps_handle)

Definition at line 482 of file rps_api.c.

References GNUNET_assert, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, GNUNET_MQ_msg_header, GNUNET_MQ_send(), GNUNET_RPS_Handle::mq, and GNUNET_RPS_Handle::view_update_cb.

Referenced by GNUNET_RPS_disconnect().

483 {
484  struct GNUNET_MQ_Envelope *ev;
485 
486  GNUNET_assert (NULL != rps_handle->view_update_cb);
487 
488  rps_handle->view_update_cb = NULL;
489 
491  GNUNET_MQ_send (rps_handle->mq, ev);
492 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL
Cancel getting updates of the view.
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
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:353
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_view_update()

static int check_view_update ( void *  cls,
const struct GNUNET_RPS_CS_DEBUG_ViewReply msg 
)
static

This function is called, when the service updates the view.

It verifies that msg is well-formed.

Parameters
clsthe closure
msgthe message
Returns
GNUNET_OK if msg is well-formed

Definition at line 531 of file rps_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_RPS_CS_DEBUG_ViewReply::header, num_peers, GNUNET_RPS_CS_DEBUG_ViewReply::num_peers, and GNUNET_MessageHeader::size.

533 {
534  uint16_t msize = ntohs (msg->header.size);
535  uint32_t num_peers = ntohl (msg->num_peers);
536  (void) cls;
537 
538  msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply);
539  if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
540  (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
541  {
542  GNUNET_break (0);
543  return GNUNET_SYSERR;
544  }
545  return GNUNET_OK;
546 }
Message from service to client containing current update of view.
Definition: rps.h:186
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int num_peers
struct GNUNET_MessageHeader header
Header including size and type in NBO.
Definition: rps.h:191
The identity of the host (wraps the signing key of the peer).
uint64_t num_peers
Number of peers in the view.
Definition: rps.h:201

◆ handle_view_update()

static void handle_view_update ( void *  cls,
const struct GNUNET_RPS_CS_DEBUG_ViewReply msg 
)
static

This function is called, when the service updated its view.

It calls the callback the caller provided and disconnects afterwards.

Parameters
msgthe message

Definition at line 557 of file rps_api.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, h, LOG, GNUNET_RPS_CS_DEBUG_ViewReply::num_peers, peers, GNUNET_RPS_Handle::view_update_cb, and GNUNET_RPS_Handle::view_update_cls.

559 {
560  struct GNUNET_RPS_Handle *h = cls;
561  struct GNUNET_PeerIdentity *peers;
562 
563  /* Give the peers back */
565  "New view of %" PRIu32 " peers:\n",
566  ntohl (msg->num_peers));
567 
568  peers = (struct GNUNET_PeerIdentity *) &msg[1];
569  GNUNET_assert (NULL != h);
570  GNUNET_assert (NULL != h->view_update_cb);
571  h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
572 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Handler to handle requests from a client.
Definition: rps_api.c:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93
The identity of the host (wraps the signing key of the peer).
static struct CadetPeer * peers
Operation to get peer ids.
void * view_update_cls
Closure to each requested update of the view.
Definition: rps_api.c:98
uint64_t num_peers
Number of peers in the view.
Definition: rps.h:201
#define LOG(kind,...)
Definition: rps_api.c:36

◆ cancel_stream()

static void cancel_stream ( struct GNUNET_RPS_Handle rps_handle)
static

Send message to service that this client does not want to receive further updates from the biased peer stream.

Parameters
rps_handleThe handle representing the service to the client

Definition at line 582 of file rps_api.c.

References GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, GNUNET_MQ_msg_header, GNUNET_MQ_send(), and GNUNET_RPS_Handle::mq.

Referenced by GNUNET_RPS_request_cancel(), GNUNET_RPS_request_single_info_cancel(), GNUNET_RPS_stream_cancel(), and handle_stream_input().

583 {
584  struct GNUNET_MQ_Envelope *ev;
585 
587  GNUNET_MQ_send (rps_handle->mq, ev);
588 }
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased strem.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
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:353
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_stream_input()

static int check_stream_input ( void *  cls,
const struct GNUNET_RPS_CS_DEBUG_StreamReply msg 
)
static

This function is called, when the service sends another peer from the biased stream.

It calls the callback the caller provided and disconnects afterwards.

TODO merge with check_view_update

Parameters
msgthe message

Definition at line 619 of file rps_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_RPS_CS_DEBUG_StreamReply::header, num_peers, GNUNET_RPS_CS_DEBUG_StreamReply::num_peers, and GNUNET_MessageHeader::size.

621 {
622  uint16_t msize = ntohs (msg->header.size);
623  uint32_t num_peers = ntohl (msg->num_peers);
624  (void) cls;
625 
626  msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_StreamReply);
627  if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
628  (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
629  {
630  GNUNET_break (0);
631  return GNUNET_SYSERR;
632  }
633  return GNUNET_OK;
634 }
struct GNUNET_MessageHeader header
Header including size and type in NBO.
Definition: rps.h:225
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint64_t num_peers
Number of peers.
Definition: rps.h:230
Message from service to client containing peer from biased stream.
Definition: rps.h:220
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int num_peers
The identity of the host (wraps the signing key of the peer).

◆ srh_callback_scheduled()

static void srh_callback_scheduled ( void *  cls)
static

Called by the scheduler to call the callbacks of the srh handlers.

Parameters
clsStream request handle

Definition at line 643 of file rps_api.c.

References GNUNET_RPS_StreamRequestHandle::callback_task, GNUNET_RPS_StreamRequestHandle::ready_cb, GNUNET_RPS_StreamRequestHandle::ready_cb_cls, and srh_callback_num_peers.

Referenced by handle_stream_input().

644 {
645  struct GNUNET_RPS_StreamRequestHandle *srh = cls;
646 
647  srh->callback_task = NULL;
648  srh->ready_cb (srh->ready_cb_cls,
651 }
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:51
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
Definition: rps_api.c:61
static struct GNUNET_PeerIdentity * srh_callback_peers
Peers received from the biased stream to be passed to all srh_handlers.
Definition: rps_api.c:284
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:56
static uint64_t srh_callback_num_peers
Number of peers in the biased stream that are to be passed to all srh_handlers.
Definition: rps_api.c:290
Here is the caller graph for this function:

◆ handle_stream_input()

static void handle_stream_input ( void *  cls,
const struct GNUNET_RPS_CS_DEBUG_StreamReply msg 
)
static

This function is called, when the service sends another peer from the biased stream.

It calls the callback the caller provided and disconnects afterwards.

Parameters
msgthe message

Definition at line 663 of file rps_api.c.

References GNUNET_RPS_StreamRequestHandle::callback_task, cancel_stream(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_memcpy, GNUNET_new_array, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), h, LOG, GNUNET_RPS_StreamRequestHandle::next, num_peers, GNUNET_RPS_CS_DEBUG_StreamReply::num_peers, reconnect(), srh_callback_num_peers, srh_callback_scheduled(), and GNUNET_RPS_Handle::stream_requests_head.

665 {
666  struct GNUNET_RPS_Handle *h = cls;
667  //const struct GNUNET_PeerIdentity *peers;
668  uint64_t num_peers;
669  struct GNUNET_RPS_StreamRequestHandle *srh_iter;
670  struct GNUNET_RPS_StreamRequestHandle *srh_next;
671 
672  //peers = (struct GNUNET_PeerIdentity *) &msg[1];
673  num_peers = ntohl (msg->num_peers);
677  struct GNUNET_PeerIdentity);
679  &msg[1],
680  num_peers * sizeof (struct GNUNET_PeerIdentity));
682  "Received %" PRIu64 " peer(s) from stream input.\n",
683  num_peers);
684  for (srh_iter = h->stream_requests_head;
685  NULL != srh_iter;
686  srh_iter = srh_next)
687  {
688  LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
689  /* Store next pointer - srh might be removed/freed in callback */
690  srh_next = srh_iter->next;
691  if (NULL != srh_iter->callback_task)
693  srh_iter->callback_task =
695  srh_iter);
696  }
697 
698  if (NULL == h->stream_requests_head)
699  {
700  cancel_stream (h);
701  }
702 }
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
static void cancel_stream(struct GNUNET_RPS_Handle *rps_handle)
Send message to service that this client does not want to receive further updates from the biased pee...
Definition: rps_api.c:582
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Handler to handle requests from a client.
Definition: rps_api.c:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static void srh_callback_scheduled(void *cls)
Called by the scheduler to call the callbacks of the srh handlers.
Definition: rps_api.c:643
uint64_t num_peers
Number of peers.
Definition: rps.h:230
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
static unsigned int num_peers
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
Definition: rps_api.c:61
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_PeerIdentity * srh_callback_peers
Peers received from the biased stream to be passed to all srh_handlers.
Definition: rps_api.c:284
struct GNUNET_RPS_StreamRequestHandle * next
Next element of the DLL.
Definition: rps_api.c:66
static uint64_t srh_callback_num_peers
Number of peers in the biased stream that are to be passed to all srh_handlers.
Definition: rps_api.c:290
#define LOG(kind,...)
Definition: rps_api.c:36
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:

◆ reconnect()

static void reconnect ( struct GNUNET_RPS_Handle h)
static

Reconnect to the service.

Definition at line 802 of file rps_api.c.

References GNUNET_RPS_Handle::cfg, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NSE_connect(), GNUNET_NSE_disconnect(), GNUNET_RPS_Handle::mq, mq_error_handler(), GNUNET_RPS_Handle::nse, nse_cb(), stream_input, and view_update.

Referenced by GNUNET_RPS_connect(), handle_stream_input(), and mq_error_handler().

803 {
804  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
808  h),
812  h),
814  };
815 
816  if (NULL != h->mq)
817  GNUNET_MQ_destroy (h->mq);
818  h->mq = GNUNET_CLIENT_connect (h->cfg,
819  "rps",
820  mq_handlers,
822  h);
823  if (NULL != h->nse)
825  h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h);
826 }
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
Message from service to client containing current update of view.
Definition: rps.h:186
static void nse_cb(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Callback for network size estimate - called with new estimates about the network size, updates all samplers with the new estimate.
Definition: rps_api.c:772
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:901
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.
Definition: nse_api.c:165
static int stream_input
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:56
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message handler for a specific message type.
static int view_update
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:51
Message from service to client containing peer from biased stream.
Definition: rps.h:220
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:193
const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the client configuration.
Definition: rps_api.c:83
struct GNUNET_NSE_Handle * nse
Handle to nse service.
Definition: rps_api.c:118
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Error handler for mq.
Definition: rps_api.c:722
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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

Error handler for mq.

This function is called whan mq encounters an error. Until now mq doesn't provide useful error messages.

Parameters
clsthe closure
errorerror code without specyfied meaning

Definition at line 722 of file rps_api.c.

References GNUNET_ERROR_TYPE_WARNING, LOG, and reconnect().

Referenced by reconnect().

724 {
725  struct GNUNET_RPS_Handle *h = cls;
726  //TODO LOG
727  LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\
728  1: READ,\n\
729  2: WRITE,\n\
730  4: TIMEOUT\n",
731  // TODO: write GNUNET_MQ_strerror (error)
732  error);
733  reconnect (h);
734  /* Resend all pending request as the service destroyed its knowledge
735  * about them */
736 }
static void reconnect(struct GNUNET_RPS_Handle *h)
Reconnect to the service.
Definition: rps_api.c:802
Handler to handle requests from a client.
Definition: rps_api.c:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
#define LOG(kind,...)
Definition: rps_api.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_from_share_val()

static void hash_from_share_val ( const char *  share_val,
struct GNUNET_HashCode hash 
)
static

Create the hash value from the share value that defines the sub (-group)

Parameters
share_valShare value
hash[out]Pointer to the location in which the hash will be stored.

Definition at line 747 of file rps_api.c.

References GNUNET_CRYPTO_kdf().

Referenced by GNUNET_RPS_sub_start(), and GNUNET_RPS_sub_stop().

749 {
750  GNUNET_CRYPTO_kdf (hash,
751  sizeof (struct GNUNET_HashCode),
752  "rps",
753  strlen ("rps"),
754  share_val,
755  strlen (share_val),
756  NULL, 0);
757 }
A 512-bit hashcode.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nse_cb()

static void nse_cb ( void *  cls,
struct GNUNET_TIME_Absolute  timestamp,
double  logestimate,
double  std_dev 
)
static

Callback for network size estimate - called with new estimates about the network size, updates all samplers with the new estimate.

Implements GNUNET_NSE_Callback

Parameters
clsthe rps handle
timestampunused
logestimatethe estimate
std_devthe standard distribution

Definition at line 772 of file rps_api.c.

References GNUNET_NSE_log_estimate_to_n, GNUNET_RPS_Request_Handle::next, GNUNET_RPS_Request_Handle_Single_Info::next, GNUNET_RPS_Handle::rh_head, GNUNET_RPS_Handle::rhs_head, and RPS_sampler_update_with_nw_size().

Referenced by reconnect().

776 {
777  struct GNUNET_RPS_Handle *h = cls;
778  (void) timestamp;
779  (void) std_dev;
780 
781  for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
782  NULL != rh_iter && NULL != rh_iter->next;
783  rh_iter = rh_iter->next)
784  {
785  RPS_sampler_update_with_nw_size (rh_iter->sampler,
786  GNUNET_NSE_log_estimate_to_n (logestimate));
787  }
788  for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
789  NULL != rhs_iter && NULL != rhs_iter->next;
790  rhs_iter = rhs_iter->next)
791  {
792  RPS_sampler_update_with_nw_size (rhs_iter->sampler,
793  GNUNET_NSE_log_estimate_to_n (logestimate));
794  }
795 }
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_head
Pointer to the head element in DLL of single request handles.
Definition: rps_api.c:133
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
Definition: rps_api.c:123
struct GNUNET_RPS_Request_Handle_Single_Info * next
Pointer to next element in DLL.
Definition: rps_api.c:248
Handler to handle requests from a client.
Definition: rps_api.c:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_RPS_Request_Handle * next
Pointer to next element in DLL.
Definition: rps_api.c:200
void RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, uint32_t num_peers)
Update the current estimate of the network size stored at the sampler.
Handler for a single request from a client.
Definition: rps_api.c:212
Handler for a single request from a client.
Definition: rps_api.c:159
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the &#39;GNUNET_NSE_Callback&#39; into an absolute estimate in ...
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ srh_callback_peers

struct GNUNET_PeerIdentity* srh_callback_peers
static

Peers received from the biased stream to be passed to all srh_handlers.

Definition at line 284 of file rps_api.c.

◆ srh_callback_num_peers

uint64_t srh_callback_num_peers
static

Number of peers in the biased stream that are to be passed to all srh_handlers.

Definition at line 290 of file rps_api.c.

Referenced by handle_stream_input(), and srh_callback_scheduled().