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>
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_StreamRequestHandle * | new_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_StreamRequestHandle * | GNUNET_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_Handle * | GNUNET_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_Handle * | GNUNET_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_Info * | GNUNET_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_PeerIdentity * | srh_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... | |
API for rps.
Definition in file rps_api.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "rps-api", __VA_ARGS__) |
|
static |
Create a new handle for a stream request.
rps_handle | The rps handle |
num_peers | The number of desired peers |
ready_cb | The callback to be called, once all peers are ready |
cls | The colsure to provide to the callback |
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, 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().
|
static |
Remove the given stream request from the list of requests and memory.
srh | The 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(), 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().
|
static |
Called once the sampler has collected all requested peers.
Calls the callback provided by the client with the corresponding cls.
peers | The array of num_peers that has been returned. |
num_peers | The number of peers that have been returned |
cls | The GNUNET_RPS_Request_Handle |
Definition at line 355 of file rps_api.c.
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().
|
static |
Called once the sampler has collected the requested peer.
Calls the callback provided by the client with the corresponding cls.
peers | The array of num_peers that has been returned. |
num_peers | The number of peers that have been returned |
cls | The GNUNET_RPS_Request_Handle |
probability | Probability with which all IDs have been observed |
num_observed | Number of observed IDs |
Definition at line 381 of file rps_api.c.
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().
|
static |
Callback to collect the peers from the biased stream and put those into the sampler.
cls | The GNUNET_RPS_Request_Handle |
num_peers | The number of peer that have been returned |
peers | The 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, peers, RPS_sampler_update(), and GNUNET_RPS_Request_Handle::sampler.
Referenced by GNUNET_RPS_request_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
cls | The GNUNET_RPS_Request_Handle |
num_peers | The number of peer that have been returned |
peers | The 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, peers, RPS_sampler_update(), and GNUNET_RPS_Request_Handle_Single_Info::sampler.
Referenced by GNUNET_RPS_request_peer_info().
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, rps_handle, and GNUNET_RPS_Handle::view_update_cb.
Referenced by GNUNET_RPS_disconnect().
|
static |
This function is called, when the service updates the view.
It verifies that msg is well-formed.
cls | the closure |
msg | the message |
Definition at line 531 of file rps_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, num_peers, and GNUNET_MessageHeader::size.
|
static |
This function is called, when the service updated its view.
It calls the callback the caller provided and disconnects afterwards.
msg | the message |
Definition at line 558 of file rps_api.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, h, LOG, msg, and peers.
|
static |
Send message to service that this client does not want to receive further updates from the biased peer stream.
rps_handle | The handle representing the service to the client |
Definition at line 583 of file rps_api.c.
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().
|
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
msg | the message |
Definition at line 620 of file rps_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, num_peers, and GNUNET_MessageHeader::size.
|
static |
Called by the scheduler to call the callbacks of the srh handlers.
cls | Stream request handle |
Definition at line 645 of file rps_api.c.
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().
|
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.
msg | the message |
Definition at line 665 of file rps_api.c.
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().
|
static |
Reconnect to the service.
Definition at line 809 of file rps_api.c.
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().
|
static |
Error handler for mq.
This function is called when mq encounters an error. Until now mq doesn't provide useful error messages.
cls | the closure |
error | error code without specyfied meaning |
Definition at line 724 of file rps_api.c.
References GNUNET_ERROR_TYPE_WARNING, h, LOG, and reconnect().
Referenced by reconnect().
|
static |
Create the hash value from the share value that defines the sub (-group)
share_val | Share value | |
[out] | hash | Pointer to the location in which the hash will be stored. |
Definition at line 751 of file rps_api.c.
References GNUNET_CRYPTO_kdf().
Referenced by GNUNET_RPS_sub_start(), and GNUNET_RPS_sub_stop().
|
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
cls | the rps handle |
timestamp | unused |
logestimate | the estimate |
std_dev | the standard distribution |
Definition at line 776 of file rps_api.c.
References GNUNET_NSE_log_estimate_to_n, h, RPS_sampler_update_with_nw_size(), and timestamp().
Referenced by reconnect().
|
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().
|
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().