GNUnet  0.11.x
Macros | Typedefs | Functions
RPS service

Random Peer Sampling. More...

Macros

#define GNUNET_RPS_VERSION   0x00000000
 Version of the rps API. More...
 

Typedefs

typedef void(* GNUNET_RPS_NotifyReadyCB) (void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
 Callback called when requested random peers are available. More...
 
typedef 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. More...
 

Functions

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 *h, uint32_t n, 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_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...
 
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...
 
void GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh)
 Cancel a specific request for updates from the biased peer stream. More...
 
void GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
 Disconnect from the rps service. More...
 

Detailed Description

Random Peer Sampling.

Macro Definition Documentation

◆ GNUNET_RPS_VERSION

#define GNUNET_RPS_VERSION   0x00000000

Version of the rps API.

Definition at line 45 of file gnunet_rps_service.h.

Typedef Documentation

◆ GNUNET_RPS_NotifyReadyCB

typedef void(* GNUNET_RPS_NotifyReadyCB) (void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)

Callback called when requested random peers are available.

Parameters
clsthe closure given with the request
num_peersthe number of peers returned
peersarray with num_peers PeerIDs

Definition at line 64 of file gnunet_rps_service.h.

◆ GNUNET_RPS_NotifyReadySingleInfoCB

typedef 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.

Parameters
clsthe closure given with the request
peerThe Peer ID
probabilityThe probability with which all elements have been observed
num_observedNumber of IDs this sampler has observed

Definition at line 79 of file gnunet_rps_service.h.

Function Documentation

◆ GNUNET_RPS_connect()

struct GNUNET_RPS_Handle* GNUNET_RPS_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Connect to the rps service.

Parameters
cfgconfiguration to use
Returns
handle to the rps service
Parameters
cfgconfiguration to use
Returns
a handle to the service, NULL on error

Definition at line 843 of file rps_api.c.

References cfg, GNUNET_RPS_Handle::cfg, GNUNET_RPS_Handle::deficiency_factor, GNUNET_RPS_Handle::desired_probability, GNUNET_CONFIGURATION_get_value_float(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_new, GNUNET_OK, h, LOG, GNUNET_RPS_Handle::mq, and reconnect().

Referenced by rps_connect_adapter(), and run().

844 {
845  struct GNUNET_RPS_Handle *h;
846 
847  h = GNUNET_new (struct GNUNET_RPS_Handle);
848  h->cfg = cfg;
849  if (GNUNET_OK !=
851  "RPS",
852  "DESIRED_PROBABILITY",
853  &h->desired_probability))
854  {
856  "RPS", "DESIRED_PROBABILITY");
857  GNUNET_free (h);
858  return NULL;
859  }
860  if ((0 > h->desired_probability) ||
861  (1 < h->desired_probability) )
862  {
864  "The desired probability must be in the interval [0;1]\n");
865  GNUNET_free (h);
866  return NULL;
867  }
868  if (GNUNET_OK !=
870  "RPS",
871  "DEFICIENCY_FACTOR",
872  &h->deficiency_factor))
873  {
875  "RPS", "DEFICIENCY_FACTOR");
876  GNUNET_free (h);
877  return NULL;
878  }
879  if ((0 > h->desired_probability) ||
880  (1 < h->desired_probability) )
881  {
883  "The deficiency factor must be in the interval [0;1]\n");
884  GNUNET_free (h);
885  return NULL;
886  }
887  reconnect (h);
888  if (NULL == h->mq)
889  {
890  GNUNET_free (h);
891  return NULL;
892  }
893  return h;
894 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void reconnect(struct GNUNET_RPS_Handle *h)
Reconnect to the service.
Definition: rps_api.c:809
float deficiency_factor
A factor that catches the &#39;bias&#39; of a random stream of peer ids.
Definition: rps_api.c:152
int 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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:99
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the client configuration.
Definition: rps_api.c:83
float desired_probability
The desired probability with which we want to have observed all peers.
Definition: rps_api.c:144
#define GNUNET_free(ptr)
Wrapper around free.
#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_sub_start()

void GNUNET_RPS_sub_start ( struct GNUNET_RPS_Handle h,
const char *  shared_value 
)

Start a sub with the given shared value.

Parameters
hHandle to rps
shared_valueThe shared value that defines the members of the sub (-group)
hHandle to rps
shared_valueThe shared value that defines the members of the sub (-gorup)

Definition at line 904 of file rps_api.c.

References GNUNET_assert, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TIME_relative_hton(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, GNUNET_RPS_CS_SubStartMessage::hash, hash_from_share_val(), GNUNET_RPS_Handle::mq, msg, GNUNET_TIME_RelativeNBO::rel_value_us__, and GNUNET_RPS_CS_SubStartMessage::round_interval.

906 {
908  struct GNUNET_MQ_Envelope *ev;
909 
911  hash_from_share_val (shared_value, &msg->hash);
912  msg->round_interval = GNUNET_TIME_relative_hton ( // TODO read from config!
915 
916  GNUNET_MQ_send (h->mq, ev);
917 }
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START
RPS client-service message to start a sub sampler.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
uint64_t rel_value_us__
The actual value (in network byte order).
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
Message from client to service telling it to start a new sub.
Definition: rps.h:121
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)
Definition: rps_api.c:751
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:625
struct GNUNET_TIME_RelativeNBO round_interval
Mean interval between two rounds.
Definition: rps.h:136
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
struct GNUNET_HashCode hash
Length of the shared value represented as string.
Definition: rps.h:141
Here is the call graph for this function:

◆ GNUNET_RPS_sub_stop()

void GNUNET_RPS_sub_stop ( struct GNUNET_RPS_Handle h,
const char *  shared_value 
)

Stop a sub with the given shared value.

Parameters
hHandle to rps
shared_valueThe shared value that defines the members of the sub (-group)
hHandle to rps
shared_valueThe shared value that defines the members of the sub (-gorup)

Definition at line 927 of file rps_api.c.

References GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_RPS_CS_SubStopMessage::hash, hash_from_share_val(), GNUNET_RPS_Handle::mq, and msg.

929 {
931  struct GNUNET_MQ_Envelope *ev;
932 
934  hash_from_share_val (shared_value, &msg->hash);
935 
936  GNUNET_MQ_send (h->mq, ev);
937 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP
RPS client-service message to stop a sub sampler.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
struct GNUNET_HashCode hash
Length of the shared value represented as string.
Definition: rps.h:158
Message from client to service telling it to stop a new sub.
Definition: rps.h:148
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)
Definition: rps_api.c:751
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:

◆ GNUNET_RPS_request_peers()

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.

This does exacly the same as GNUNET_RPS_request_peers_single_call but needs a GNUNET_RPS_Handle. This exists only for other parts of GNUnet that expect having to (dis)connect from/to a service.

Parameters
hhandle to the rps service
nnumber of random peers to return
ready_cbthe callback to be called when the peers are available
clsa closure that will be given to the callback
Returns
handle to this request
Parameters
rps_handlehandle to the rps service
num_req_peersnumber of peers we want to receive
ready_cbthe callback called when the peers are available
clsclosure given to the callback
Returns
a handle to cancel this request

Definition at line 950 of file rps_api.c.

References collect_peers_cb(), GNUNET_RPS_Handle::deficiency_factor, GNUNET_RPS_Handle::desired_probability, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_new, GNUNET_RPS_stream_request(), GNUNET_TIME_UNIT_SECONDS, LOG, GNUNET_RPS_Request_Handle::num_requests, peers_ready_cb(), GNUNET_RPS_StreamRequestHandle::ready_cb, GNUNET_RPS_Request_Handle::ready_cb, GNUNET_RPS_Request_Handle::ready_cb_cls, GNUNET_RPS_Handle::rh_head, GNUNET_RPS_Handle::rh_tail, GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Request_Handle::rps_handle, RPS_sampler_get_n_rand_peers(), RPS_sampler_mod_init(), RPS_sampler_set_deficiency_factor(), RPS_sampler_set_desired_probability(), GNUNET_RPS_Request_Handle::sampler, GNUNET_RPS_Request_Handle::sampler_rh, and GNUNET_RPS_Request_Handle::srh.

Referenced by run().

954 {
955  struct GNUNET_RPS_Request_Handle *rh;
956 
958  "Client requested %" PRIu32 " peers\n",
959  num_req_peers);
961  rh->rps_handle = rps_handle;
962  rh->num_requests = num_req_peers;
963  rh->sampler = RPS_sampler_mod_init (num_req_peers,
964  GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
966  rps_handle->desired_probability);
968  rps_handle->deficiency_factor);
970  num_req_peers,
972  rh);
973  rh->srh = GNUNET_RPS_stream_request (rps_handle,
975  rh); /* cls */
976  rh->ready_cb = ready_cb;
977  rh->ready_cb_cls = cls;
979  rps_handle->rh_tail,
980  rh);
981 
982  return rh;
983 }
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.
Definition: rps_api.c:406
struct GNUNET_RPS_Request_Handle * rh_tail
Pointer to the tail element in DLL of request handles.
Definition: rps_api.c:128
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:185
#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:190
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
Definition: rps_api.c:123
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...
#define GNUNET_TIME_UNIT_SECONDS
One second.
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
float deficiency_factor
A factor that catches the &#39;bias&#39; of a random stream of peer ids.
Definition: rps_api.c:152
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.
Definition: rps_api.c:355
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:164
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.
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
uint32_t num_requests
The number of requested peers.
Definition: rps_api.c:169
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.
Definition: rps_api.c:503
Handler for a single request from a client.
Definition: rps_api.c:159
float desired_probability
The desired probability with which we want to have observed all peers.
Definition: rps_api.c:144
#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_request_peer_info()

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.

Parameters
rps_handlehandle to the rps service
ready_cbthe callback called when the peers are available
clsclosure given to the callback
Returns
a handle to cancel this request

Definition at line 995 of file rps_api.c.

References collect_peers_info_cb(), GNUNET_RPS_Handle::deficiency_factor, GNUNET_RPS_Handle::desired_probability, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_new, GNUNET_RPS_stream_request(), GNUNET_TIME_UNIT_SECONDS, LOG, peer_info_ready_cb(), GNUNET_RPS_StreamRequestHandle::ready_cb, GNUNET_RPS_Request_Handle_Single_Info::ready_cb, GNUNET_RPS_Request_Handle_Single_Info::ready_cb_cls, GNUNET_RPS_Handle::rhs_head, GNUNET_RPS_Handle::rhs_tail, GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Request_Handle_Single_Info::rps_handle, RPS_sampler_get_rand_peer_info(), RPS_sampler_mod_init(), RPS_sampler_set_deficiency_factor(), RPS_sampler_set_desired_probability(), GNUNET_RPS_Request_Handle_Single_Info::sampler, GNUNET_RPS_Request_Handle_Single_Info::sampler_rh, and GNUNET_RPS_Request_Handle_Single_Info::srh.

Referenced by request_peers().

998 {
1000  uint32_t num_req_peers = 1;
1001 
1003  "Client requested peer with additional info\n");
1005  rhs->rps_handle = rps_handle;
1006  rhs->sampler = RPS_sampler_mod_init (num_req_peers,
1007  GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
1009  rps_handle->desired_probability);
1011  rps_handle->deficiency_factor);
1014  rhs);
1015  rhs->srh = GNUNET_RPS_stream_request (rps_handle,
1017  rhs); /* cls */
1018  rhs->ready_cb = ready_cb;
1019  rhs->ready_cb_cls = cls;
1021  rps_handle->rhs_tail,
1022  rhs);
1023 
1024  return rhs;
1025 }
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
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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...
#define GNUNET_TIME_UNIT_SECONDS
One second.
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
float deficiency_factor
A factor that catches the &#39;bias&#39; of a random stream of peer ids.
Definition: rps_api.c:152
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:243
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.
Definition: rps_api.c:433
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:217
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.
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.
Definition: rps_api.c:381
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.
Handler for a single request from a client.
Definition: rps_api.c:212
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:233
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
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:222
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_tail
Pointer to the tail element in DLL of single request handles.
Definition: rps_api.c:138
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.
Definition: rps_api.c:503
float desired_probability
The desired probability with which we want to have observed all peers.
Definition: rps_api.c:144
#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_seed_ids()

void GNUNET_RPS_seed_ids ( struct GNUNET_RPS_Handle h,
uint32_t  n,
const struct GNUNET_PeerIdentity ids 
)

Seed rps service with peerIDs.

Parameters
hhandle to the rps service
nnumber of peers to seed
idsthe ids of the peers seeded

Definition at line 1036 of file rps_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), ids, LOG, GNUNET_RPS_Handle::mq, msg, num_peers, GNUNET_RPS_CS_SeedMessage::num_peers, peer_ids, target_peer, and type.

Referenced by run(), and seed_peers().

1039 {
1040  size_t size_needed;
1041  uint32_t num_peers_max;
1042  const struct GNUNET_PeerIdentity *tmp_peer_pointer;
1043  struct GNUNET_MQ_Envelope *ev;
1045 
1047  "Client wants to seed %" PRIu32 " peers:\n",
1048  n);
1049  for (unsigned int i = 0; i < n; i++)
1051  "%u. peer: %s\n",
1052  i,
1053  GNUNET_i2s (&ids[i]));
1054 
1055  /* The actual size the message occupies */
1056  size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1057  + n * sizeof(struct GNUNET_PeerIdentity);
1058  /* The number of peers that fits in one message together with
1059  * the respective header */
1060  num_peers_max = (GNUNET_MAX_MESSAGE_SIZE
1061  - sizeof(struct GNUNET_RPS_CS_SeedMessage))
1062  / sizeof(struct GNUNET_PeerIdentity);
1063  tmp_peer_pointer = ids;
1064 
1065  while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
1066  {
1067  ev = GNUNET_MQ_msg_extra (msg,
1068  num_peers_max * sizeof(struct
1071  msg->num_peers = htonl (num_peers_max);
1072  GNUNET_memcpy (&msg[1],
1073  tmp_peer_pointer,
1074  num_peers_max * sizeof(struct GNUNET_PeerIdentity));
1075  GNUNET_MQ_send (h->mq,
1076  ev);
1077  n -= num_peers_max;
1078  size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1079  + n * sizeof(struct GNUNET_PeerIdentity);
1080  /* Set pointer to beginning of next block of num_peers_max peers */
1081  tmp_peer_pointer = &ids[num_peers_max];
1082  }
1083 
1084  ev = GNUNET_MQ_msg_extra (msg,
1085  n * sizeof(struct GNUNET_PeerIdentity),
1087  msg->num_peers = htonl (n);
1088  GNUNET_memcpy (&msg[1],
1089  tmp_peer_pointer,
1090  n * sizeof(struct GNUNET_PeerIdentity));
1091  GNUNET_MQ_send (h->mq,
1092  ev);
1093 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Message from client to service with seed of peers.
Definition: rps.h:66
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED
RPS CS SEED Message for the Client to seed peers into rps.
uint32_t num_peers
Number of peers.
Definition: rps.h:76
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
The identity of the host (wraps the signing key of the peer).
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
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#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_request_cancel()

void GNUNET_RPS_request_cancel ( struct GNUNET_RPS_Request_Handle rh)

Cancle an issued request.

Parameters
rhhandle of the pending request to be canceled
rhrequest handle of request to cancle

Definition at line 1200 of file rps_api.c.

References cancel_stream(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_RPS_stream_cancel(), h, GNUNET_RPS_Handle::rh_head, GNUNET_RPS_Handle::rh_tail, GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Request_Handle::rps_handle, RPS_sampler_destroy(), RPS_sampler_request_cancel(), GNUNET_RPS_Request_Handle::sampler, GNUNET_RPS_Request_Handle::sampler_rh, GNUNET_RPS_Request_Handle::srh, and GNUNET_RPS_Handle::stream_requests_head.

Referenced by do_shutdown(), GNUNET_RPS_disconnect(), and peers_ready_cb().

1201 {
1202  struct GNUNET_RPS_Handle *h;
1203 
1204  h = rh->rps_handle;
1205  GNUNET_assert (NULL != rh);
1206  GNUNET_assert (NULL != rh->srh);
1207  GNUNET_assert (h == rh->srh->rps_handle);
1209  rh->srh = NULL;
1210  if (NULL == h->stream_requests_head)
1211  cancel_stream (h);
1212  if (NULL != rh->sampler_rh)
1213  {
1215  }
1217  rh->sampler = NULL;
1219  h->rh_tail,
1220  rh);
1221  GNUNET_free (rh);
1222 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_RPS_Request_Handle * rh_tail
Pointer to the tail element in DLL of request handles.
Definition: rps_api.c:128
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:185
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
Definition: rps_api.c:123
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
Cancel a specific request for updates from the biased peer stream.
Definition: rps_api.c:598
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
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:99
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:164
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
struct RPS_SamplerRequestHandle * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:179
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RPS_request_single_info_cancel()

void GNUNET_RPS_request_single_info_cancel ( struct GNUNET_RPS_Request_Handle_Single_Info rhs)

Cancle an issued single info request.

Parameters
rhsrequest handle of request to cancle

Definition at line 1231 of file rps_api.c.

References cancel_stream(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_RPS_stream_cancel(), h, GNUNET_RPS_Handle::rhs_head, GNUNET_RPS_Handle::rhs_tail, GNUNET_RPS_StreamRequestHandle::rps_handle, GNUNET_RPS_Request_Handle_Single_Info::rps_handle, RPS_sampler_destroy(), RPS_sampler_request_single_info_cancel(), GNUNET_RPS_Request_Handle_Single_Info::sampler, GNUNET_RPS_Request_Handle_Single_Info::sampler_rh, GNUNET_RPS_Request_Handle_Single_Info::srh, and GNUNET_RPS_Handle::stream_requests_head.

Referenced by cancel_request(), GNUNET_RPS_disconnect(), and peer_info_ready_cb().

1233 {
1234  struct GNUNET_RPS_Handle *h;
1235 
1236  h = rhs->rps_handle;
1237  GNUNET_assert (NULL != rhs);
1238  GNUNET_assert (NULL != rhs->srh);
1239  GNUNET_assert (h == rhs->srh->rps_handle);
1241  rhs->srh = NULL;
1242  if (NULL == h->stream_requests_head)
1243  cancel_stream (h);
1244  if (NULL != rhs->sampler_rh)
1245  {
1247  }
1249  rhs->sampler = NULL;
1251  h->rhs_tail,
1252  rhs);
1253  GNUNET_free (rhs);
1254 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancle a request issued through RPS_sampler_sinlge_info_ready_cb.
void GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
Cancel a specific request for updates from the biased peer stream.
Definition: rps_api.c:598
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
Handler to handle requests from a client.
Definition: rps_api.c:78
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:217
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:233
struct RPS_SamplerRequestHandleSingleInfo * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:227
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:222
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_tail
Pointer to the tail element in DLL of single request handles.
Definition: rps_api.c:138
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RPS_view_request()

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.

Parameters
rps_handlehandle to the rps service
num_req_peersnumber of peers we want to receive (0 for infinite updates)
clsa closure that will be given to the callback
ready_cbthe callback called when the peers are available

Definition at line 461 of file rps_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, GNUNET_MQ_msg, GNUNET_MQ_send(), LOG, GNUNET_RPS_Handle::mq, msg, GNUNET_RPS_CS_DEBUG_ViewRequest::num_updates, GNUNET_RPS_Handle::view_update_cb, view_update_cb(), and GNUNET_RPS_Handle::view_update_cls.

Referenced by pre_profiler(), and run().

465 {
466  struct GNUNET_MQ_Envelope *ev;
468 
470  "Client requests %" PRIu32 " view updates\n",
471  num_updates);
472  rps_handle->view_update_cb = view_update_cb;
473  rps_handle->view_update_cls = cls;
474 
476  msg->num_updates = htonl (num_updates);
477  GNUNET_MQ_send (rps_handle->mq, ev);
478 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t num_updates
Number of updates 0 for sending updates until cancellation.
Definition: rps.h:179
Message from client to service indicating that clients wants to get updates of the view...
Definition: rps.h:168
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST
Request updates of the view.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
void view_update_cb(void *cls, uint64_t view_size, const struct GNUNET_PeerIdentity *peers)
void * view_update_cls
Closure to each requested update of the view.
Definition: rps_api.c:98
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
#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_stream_request()

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.

Parameters
rps_handlehandle to the rps service
clsa closure that will be given to the callback
ready_cbthe callback called when the peers are available

Definition at line 503 of file rps_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, GNUNET_MQ_msg, GNUNET_MQ_send(), LOG, GNUNET_RPS_Handle::mq, msg, and new_stream_request().

Referenced by GNUNET_RPS_request_peer_info(), GNUNET_RPS_request_peers(), and run().

506 {
507  struct GNUNET_RPS_StreamRequestHandle *srh;
508  struct GNUNET_MQ_Envelope *ev;
510 
511  srh = new_stream_request (rps_handle,
512  stream_input_cb,
513  cls);
514  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n");
515 
517  GNUNET_MQ_send (rps_handle->mq, ev);
518  return srh;
519 }
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Message from client to service indicating that clients wants to get stream of biased peers...
Definition: rps.h:208
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
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.
Definition: rps_api.c:304
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST
Request biased input stream.
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
#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_stream_cancel()

void GNUNET_RPS_stream_cancel ( struct GNUNET_RPS_StreamRequestHandle srh)

Cancel a specific request for updates from the biased peer stream.

Parameters
srhThe request handle to cancel

Definition at line 598 of file rps_api.c.

References cancel_stream(), remove_stream_request(), GNUNET_RPS_StreamRequestHandle::rps_handle, and GNUNET_RPS_Handle::stream_requests_head.

Referenced by GNUNET_RPS_disconnect(), GNUNET_RPS_request_cancel(), and GNUNET_RPS_request_single_info_cancel().

599 {
601 
602  rps_handle = srh->rps_handle;
603  remove_stream_request (srh);
604  if (NULL == rps_handle->stream_requests_head)
605  cancel_stream (rps_handle);
606 }
static struct GNUNET_RPS_Handle * rps_handle
RPS handle.
Definition: gnunet-rps.c:36
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 remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh)
Remove the given stream request from the list of requests and memory.
Definition: rps_api.c:328
Handler to handle requests from a client.
Definition: rps_api.c:78
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RPS_disconnect()

void GNUNET_RPS_disconnect ( struct GNUNET_RPS_Handle h)

Disconnect from the rps service.

Parameters
hthe handle to the rps service

Definition at line 1263 of file rps_api.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NSE_disconnect(), GNUNET_RPS_request_cancel(), GNUNET_RPS_request_single_info_cancel(), GNUNET_RPS_stream_cancel(), GNUNET_RPS_view_request_cancel(), LOG, GNUNET_RPS_Handle::mq, GNUNET_RPS_StreamRequestHandle::next, GNUNET_RPS_Handle::nse, GNUNET_RPS_Handle::rh_head, GNUNET_RPS_Handle::rhs_head, GNUNET_RPS_Handle::stream_requests_head, and GNUNET_RPS_Handle::view_update_cb.

Referenced by do_shutdown(), and rps_disconnect_adapter().

1264 {
1265  if (NULL != h->stream_requests_head)
1266  {
1267  struct GNUNET_RPS_StreamRequestHandle *srh_next;
1268 
1270  "Still waiting for replies\n");
1271  for (struct GNUNET_RPS_StreamRequestHandle *srh_iter =
1273  NULL != srh_iter;
1274  srh_iter = srh_next)
1275  {
1276  srh_next = srh_iter->next;
1277  GNUNET_RPS_stream_cancel (srh_iter);
1278  }
1279  }
1280  if (NULL != h->rh_head)
1281  {
1283  "Not all requests were cancelled!\n");
1284  for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
1285  h->rh_head != NULL;
1286  rh_iter = h->rh_head)
1287  {
1288  GNUNET_RPS_request_cancel (rh_iter);
1289  }
1290  }
1291  if (NULL != h->rhs_head)
1292  {
1294  "Not all requests were cancelled!\n");
1295  for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
1296  h->rhs_head != NULL;
1297  rhs_iter = h->rhs_head)
1298  {
1300  }
1301  }
1302  if (NULL != srh_callback_peers)
1303  {
1305  srh_callback_peers = NULL;
1306  }
1307  if (NULL != h->view_update_cb)
1308  {
1310  "Still waiting for view updates\n");
1312  }
1313  if (NULL != h->nse)
1315  GNUNET_MQ_destroy (h->mq);
1316  GNUNET_free (h);
1317 }
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
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
Definition: rps_api.c:123
void GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
Cancel a specific request for updates from the biased peer stream.
Definition: rps_api.c:598
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93
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:1231
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
Handler for a single request from a client.
Definition: rps_api.c:212
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:193
void GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle)
Definition: rps_api.c:482
void GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
Cancle an issued request.
Definition: rps_api.c:1200
struct GNUNET_NSE_Handle * nse
Handle to nse service.
Definition: rps_api.c:118
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
Handler for a single request from a client.
Definition: rps_api.c:159
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
#define LOG(kind,...)
Definition: rps_api.c:36
Here is the call graph for this function:
Here is the caller graph for this function: