GNUnet 0.21.1
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)
 Cancel an issued request. More...
 
void GNUNET_RPS_request_single_info_cancel (struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
 Cancel 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__)

Definition at line 36 of file rps_api.c.

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.

307{
309
311 srh->rps_handle = rps_handle;
312 srh->ready_cb = ready_cb;
313 srh->ready_cb_cls = cls;
316 srh);
317
318 return srh;
319}
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
struct GNUNET_RPS_StreamRequestHandle * stream_requests_tail
Tail of the DLL of stream requests.
Definition: rps_api.c:113
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:42
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
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:51

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

Referenced by GNUNET_RPS_stream_request().

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.

329{
331
332 GNUNET_assert (NULL != srh);
333 if (NULL != srh->callback_task)
334 {
336 srh->callback_task = NULL;
337 }
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.
#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:981
Handler to handle requests from a client.
Definition: rps_api.c:79
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
Definition: rps_api.c:61

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

Referenced by GNUNET_RPS_stream_cancel().

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.

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}
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
static unsigned int num_peers
Number of peers.
void GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
Cancel an issued request.
Definition: rps_api.c:1200
Handler for a single request from a client.
Definition: rps_api.c:160
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

References GNUNET_RPS_request_cancel(), num_peers, peers, 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().

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.

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

References GNUNET_RPS_request_single_info_cancel(), peers, 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().

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.

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 {
418 }
419}
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
@ GNUNET_ERROR_TYPE_DEBUG
#define LOG(kind,...)
Definition: rps_api.c:36
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174

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

Referenced by GNUNET_RPS_request_peers().

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.

436{
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}
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:222

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

Referenced by GNUNET_RPS_request_peer_info().

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.

483{
484 struct GNUNET_MQ_Envelope *ev;
485
487
489
492}
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:304
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:87
#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
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93

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

Referenced by GNUNET_RPS_disconnect().

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.

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

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, num_peers, and GNUNET_MessageHeader::size.

◆ 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 558 of file rps_api.c.

560{
561 struct GNUNET_RPS_Handle *h = cls;
563
564 /* Give the peers back */
566 "New view of %" PRIu32 " peers:\n",
567 ntohl (msg->num_peers));
568
569 peers = (struct GNUNET_PeerIdentity *) &msg[1];
570 GNUNET_assert (NULL != h);
571 GNUNET_assert (NULL != h->view_update_cb);
572 h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
573}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, h, LOG, msg, and peers.

◆ 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 583 of file rps_api.c.

584{
585 struct GNUNET_MQ_Envelope *ev;
586
589}
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased stream.

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

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

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 620 of file rps_api.c.

622{
623 uint16_t msize = ntohs (msg->header.size);
624 uint32_t num_peers = ntohl (msg->num_peers);
625
626 (void) cls;
627
628 msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply);
629 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
630 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
631 {
632 GNUNET_break (0);
633 return GNUNET_SYSERR;
634 }
635 return GNUNET_OK;
636}
Message from service to client containing peer from biased stream.
Definition: rps.h:220

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, num_peers, and GNUNET_MessageHeader::size.

◆ 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 645 of file rps_api.c.

646{
647 struct GNUNET_RPS_StreamRequestHandle *srh = cls;
648
649 srh->callback_task = NULL;
650 srh->ready_cb (srh->ready_cb_cls,
653}
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
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

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

Referenced by handle_stream_input().

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 665 of file rps_api.c.

667{
668 struct GNUNET_RPS_Handle *h = cls;
669 // const struct GNUNET_PeerIdentity *peers;
670 uint64_t num_peers;
671 struct GNUNET_RPS_StreamRequestHandle *srh_iter;
672 struct GNUNET_RPS_StreamRequestHandle *srh_next;
673
674 // peers = (struct GNUNET_PeerIdentity *) &msg[1];
675 num_peers = ntohl (msg->num_peers);
679 struct GNUNET_PeerIdentity);
681 &msg[1],
682 num_peers * sizeof(struct GNUNET_PeerIdentity));
684 "Received %" PRIu64 " peer(s) from stream input.\n",
685 num_peers);
686 for (srh_iter = h->stream_requests_head;
687 NULL != srh_iter;
688 srh_iter = srh_next)
689 {
690 LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
691 /* Store next pointer - srh might be removed/freed in callback */
692 srh_next = srh_iter->next;
693 if (NULL != srh_iter->callback_task)
695 srh_iter->callback_task =
697 srh_iter);
698 }
699
700 if (NULL == h->stream_requests_head)
701 {
703 }
704}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
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:1305
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:583
static void srh_callback_scheduled(void *cls)
Called by the scheduler to call the callbacks of the srh handlers.
Definition: rps_api.c:645
struct GNUNET_RPS_StreamRequestHandle * next
Next element of the DLL.
Definition: rps_api.c:66

References GNUNET_RPS_StreamRequestHandle::callback_task, cancel_stream(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcpy, GNUNET_new_array, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), h, LOG, msg, GNUNET_RPS_StreamRequestHandle::next, num_peers, srh_callback_num_peers, srh_callback_peers, and srh_callback_scheduled().

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 809 of file rps_api.c.

810{
811 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
815 h),
819 h),
821 };
822
823 if (NULL != h->mq)
826 "rps",
827 mq_handlers,
829 h);
830 if (NULL != h->nse)
832 h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h);
833}
static int view_update
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:51
static int stream_input
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:56
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:1057
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:192
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:164
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Error handler for mq.
Definition: rps_api.c:724
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,...
Definition: rps_api.c:776
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
Message handler for a specific message type.

References GNUNET_ARM_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(), h, GNUNET_ARM_Handle::mq, mq_error_handler(), nse_cb(), stream_input, and view_update.

Referenced by GNUNET_RPS_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

Error handler for mq.

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

Parameters
clsthe closure
errorerror code without specyfied meaning

Definition at line 724 of file rps_api.c.

726{
727 struct GNUNET_RPS_Handle *h = cls;
728
729 // TODO LOG
731 "Problem with message queue. error: %i\n\
732 1: READ,\n\
733 2: WRITE,\n\
734 4: TIMEOUT\n",
735 // TODO: write GNUNET_MQ_strerror (error)
736 error);
737 reconnect (h);
738 /* Resend all pending request as the service destroyed its knowledge
739 * about them */
740}
@ GNUNET_ERROR_TYPE_WARNING
static void reconnect(struct GNUNET_RPS_Handle *h)
Reconnect to the service.
Definition: rps_api.c:809

References GNUNET_ERROR_TYPE_WARNING, h, LOG, and reconnect().

Referenced by reconnect().

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
[out]hashPointer to the location in which the hash will be stored.

Definition at line 751 of file rps_api.c.

753{
754 GNUNET_CRYPTO_kdf (hash,
755 sizeof(struct GNUNET_HashCode),
756 "rps",
757 strlen ("rps"),
758 share_val,
759 strlen (share_val),
760 NULL, 0);
761}
enum GNUNET_GenericReturnValue 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:70
A 512-bit hashcode.

References GNUNET_CRYPTO_kdf().

Referenced by GNUNET_RPS_sub_start(), and GNUNET_RPS_sub_stop().

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 776 of file rps_api.c.

780{
781 struct GNUNET_RPS_Handle *h = cls;
782
783 (void) timestamp;
784 (void) std_dev;
785
786 for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
787 NULL != rh_iter && NULL != rh_iter->next;
788 rh_iter = rh_iter->next)
789 {
790 RPS_sampler_update_with_nw_size (rh_iter->sampler,
792 logestimate));
793 }
794 for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
795 NULL != rhs_iter && NULL != rhs_iter->next;
796 rhs_iter = rhs_iter->next)
797 {
798 RPS_sampler_update_with_nw_size (rhs_iter->sampler,
800 logestimate));
801 }
802}
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in ...
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.

References GNUNET_NSE_log_estimate_to_n, h, and RPS_sampler_update_with_nw_size().

Referenced by reconnect().

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.

Referenced by GNUNET_RPS_disconnect(), handle_stream_input(), and srh_callback_scheduled().

◆ 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().