36#define LOG(kind, ...) GNUNET_log_from (kind, "rps-api", __VA_ARGS__)
384 uint32_t num_observed)
413 "Service sent %" PRIu64
" peers from stream\n",
440 "Service sent %" PRIu64
" peers from stream\n",
462 uint32_t num_updates,
470 "Client requests %" PRIu32
" view updates\n",
534 uint16_t msize = ntohs (
msg->header.
size);
566 "New view of %" PRIu32
" peers:\n",
567 ntohl (
msg->num_peers));
572 h->view_update_cb (
h->view_update_cls, ntohl (
msg->num_peers),
peers);
623 uint16_t msize = ntohs (
msg->header.
size);
684 "Received %" PRIu64
" peer(s) from stream input.\n",
686 for (srh_iter =
h->stream_requests_head;
692 srh_next = srh_iter->
next;
700 if (NULL ==
h->stream_requests_head)
731 "Problem with message queue. error: %i\n\
787 NULL != rh_iter && NULL != rh_iter->next;
788 rh_iter = rh_iter->next)
795 NULL != rhs_iter && NULL != rhs_iter->next;
796 rhs_iter = rhs_iter->next)
852 "DESIRED_PROBABILITY",
853 &
h->desired_probability))
856 "RPS",
"DESIRED_PROBABILITY");
860 if ((0 >
h->desired_probability) ||
861 (1 <
h->desired_probability) )
864 "The desired probability must be in the interval [0;1]\n");
872 &
h->deficiency_factor))
875 "RPS",
"DEFICIENCY_FACTOR");
879 if ((0 >
h->desired_probability) ||
880 (1 <
h->desired_probability) )
883 "The deficiency factor must be in the interval [0;1]\n");
905 const char *shared_value)
928 const char *shared_value)
951 uint32_t num_req_peers,
958 "Client requested %" PRIu32
" peers\n",
1000 uint32_t num_req_peers = 1;
1003 "Client requested peer with additional info\n");
1041 uint32_t num_peers_max;
1047 "Client wants to seed %" PRIu32
" peers:\n",
1049 for (
unsigned int i = 0; i < n; i++)
1063 tmp_peer_pointer = ids;
1068 num_peers_max *
sizeof(
struct
1071 msg->num_peers = htonl (num_peers_max);
1081 tmp_peer_pointer = &ids[num_peers_max];
1087 msg->num_peers = htonl (n);
1119 uint32_t num_peers_max;
1122 struct GNUNET_RPS_CS_ActMaliciousMessage *
msg;
1127 "Client turns malicious (type %" PRIu32
") with %" PRIu32
1145 tmp_peer_pointer = peer_ids;
1150 "Too many peers to send at once, sending %" PRIu32
1151 " (all we can so far)\n",
1154 num_peers_max *
sizeof(
struct
1156 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1158 msg->num_peers = htonl (num_peers_max);
1172 tmp_peer_pointer = &peer_ids[num_peers_max];
1177 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1182 msg->attacked_peer = *target_peer;
1210 if (NULL ==
h->stream_requests_head)
1242 if (NULL ==
h->stream_requests_head)
1265 if (NULL !=
h->stream_requests_head)
1270 "Still waiting for replies\n");
1272 h->stream_requests_head;
1274 srh_iter = srh_next)
1276 srh_next = srh_iter->
next;
1280 if (NULL !=
h->rh_head)
1283 "Not all requests were cancelled!\n");
1286 rh_iter =
h->rh_head)
1291 if (NULL !=
h->rhs_head)
1294 "Not all requests were cancelled!\n");
1296 h->rhs_head != NULL;
1297 rhs_iter =
h->rhs_head)
1307 if (NULL !=
h->view_update_cb)
1310 "Still waiting for view updates\n");
struct GNUNET_MessageHeader * msg
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static uint64_t timestamp(void)
Get current timestamp.
static uint32_t type
Type string converted to DNS type value.
static int view_update
Do we want to receive updates of the view? (Option –view)
static int stream_input
Do we want to receive updates of the view? (Option –view)
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
struct RPS_SamplerRequestHandle * RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, uint32_t num_peers, RPS_sampler_n_rand_peers_ready_cb cb, void *cls)
Get n random peers out of the sampled peers.
static unsigned int num_peers
Number of peers.
API to retrieve the current network size estimate.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in ...
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.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START
RPS client-service message to start a sub sampler.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased stream.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP
RPS client-service message to stop a sub sampler.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL
Cancel getting updates of the view.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED
RPS CS SEED Message for the Client to seed peers into rps.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST
Request biased input stream.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST
Request updates of the view.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
void GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, const char *shared_value)
Stop a sub with the given shared value.
void GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, const char *shared_value)
Start a sub with the given shared value.
void GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
Cancel an issued request.
void GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
Cancel a specific request for updates from the biased peer stream.
void(* GNUNET_RPS_NotifyReadySingleInfoCB)(void *cls, const struct GNUNET_PeerIdentity *peer, double probability, uint32_t num_observed)
Callback called when requested random peer with additional information is available.
struct GNUNET_RPS_Handle * GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the rps service.
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.
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.
void GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, uint32_t n, const struct GNUNET_PeerIdentity *ids)
Seed rps service with peerIDs.
void(* GNUNET_RPS_NotifyReadyCB)(void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Callback called when requested random peers are available.
void GNUNET_RPS_disconnect(struct GNUNET_RPS_Handle *h)
Disconnect from the rps service.
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.
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.
void GNUNET_RPS_request_single_info_cancel(struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
Cancel an issued single info request.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
struct RPS_Sampler * RPS_sampler_mod_init(size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
Initialise a modified tuple of sampler elements.
client sampler implementation
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.
struct RPS_SamplerRequestHandleSingleInfo * RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, RPS_sampler_sinlge_info_ready_cb cb, void *cls)
Get one random peer with additional information.
void RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, double deficiency_factor)
Set the deficiency factor.
void RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, double desired_probability)
Set the probability that is needed at least with what a sampler element has to have observed all elem...
void RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancel a request issued through RPS_sampler_sinlge_info_ready_cb.
example IPC messages between RPS API and GNS service
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.
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.
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.
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.
static struct GNUNET_PeerIdentity * srh_callback_peers
Peers received from the biased stream to be passed to all srh_handlers.
static void reconnect(struct GNUNET_RPS_Handle *h)
Reconnect to the service.
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.
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...
static void srh_callback_scheduled(void *cls)
Called by the scheduler to call the callbacks of the srh handlers.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Error handler for mq.
static uint64_t srh_callback_num_peers
Number of peers in the biased stream that are to be passed to all srh_handlers.
void GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle)
static void remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh)
Remove the given stream request from the list of requests and memory.
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.
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.
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.
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,...
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)
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.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Handle to a message queue.
Message handler for a specific message type.
Handle for talking with the NSE service.
The identity of the host (wraps the signing key of the peer).
Message from service to client containing peer from biased stream.
Message from client to service indicating that clients wants to get stream of biased peers.
Message from service to client containing current update of view.
Message from client to service indicating that clients wants to get updates of the view.
uint32_t num_updates
Number of updates 0 for sending updates until cancellation.
Message from client to service with seed of peers.
Message from client to service telling it to start a new sub.
Message from client to service telling it to stop a new sub.
Handler to handle requests from a client.
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_head
Pointer to the head element in DLL of single request handles.
void * view_update_cls
Closure to each requested update of the view.
struct GNUNET_MQ_Handle * mq
The message queue to the client.
const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the client configuration.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
struct GNUNET_RPS_Request_Handle * rh_tail
Pointer to the tail element in DLL of request handles.
float desired_probability
The desired probability with which we want to have observed all peers.
struct GNUNET_NSE_Handle * nse
Handle to nse service.
float deficiency_factor
A factor that catches the 'bias' of a random stream of peer ids.
void * stream_input_cls
Closure to each requested peer from the biased stream.
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_tail
Pointer to the tail element in DLL of single request handles.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_tail
Tail of the DLL of stream requests.
Handler for a single request from a client.
struct RPS_Sampler * sampler
The Sampler for the client request.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
GNUNET_RPS_NotifyReadySingleInfoCB ready_cb
The callback to be called when we receive an answer.
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request.
void * ready_cb_cls
The closure for the callback.
struct RPS_SamplerRequestHandleSingleInfo * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
struct GNUNET_RPS_Request_Handle_Single_Info * next
Pointer to next element in DLL.
struct GNUNET_RPS_Request_Handle_Single_Info * prev
Pointer to previous element in DLL.
Handler for a single request from a client.
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
struct RPS_Sampler * sampler
The Sampler for the client request.
struct RPS_SamplerRequestHandle * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request.
uint32_t num_requests
The number of requested peers.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
struct GNUNET_RPS_Request_Handle * next
Pointer to next element in DLL.
struct GNUNET_RPS_Request_Handle * prev
Pointer to previous element in DLL.
void * ready_cb_cls
The closure for the callback.
Handle for a request to get peers from biased stream of ids.
struct GNUNET_RPS_StreamRequestHandle * prev
Previous element of the DLL.
void * ready_cb_cls
The closure for the callback.
struct GNUNET_RPS_StreamRequestHandle * next
Next element of the DLL.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Closure to _get_rand_peer_info()
Closure to _get_n_rand_peers_ready_cb()
Sampler with its own array of SamplerElements.
Struct used to pack the callback, its closure (provided by the caller) and the connection handler to ...
GNUNET_RPS_NotifyReadyCB cb
Callback provided by the client.
void * cls
Closure provided by the client.
struct GNUNET_CLIENT_Connection * service_conn
Handle to the service connection.