GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-rps.c File Reference

rps service implementation More...

#include "platform.h"
#include "gnunet_applications.h"
#include "gnunet_util_lib.h"
#include "gnunet_cadet_service.h"
#include "gnunet_core_service.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_nse_service.h"
#include "gnunet_statistics_service.h"
#include "rps.h"
#include "rps-test_util.h"
#include "gnunet-service-rps_sampler.h"
#include "gnunet-service-rps_custommap.h"
#include "gnunet-service-rps_view.h"
#include <math.h>
#include <inttypes.h>
#include <string.h>
Include dependency graph for gnunet-service-rps.c:

Go to the source code of this file.

Data Structures

struct  PeerPendingOp
 Pending operation on peer consisting of callback and closure. More...
 
struct  PendingMessage
 List containing all messages that are yet to be send. More...
 
struct  PeerContext
 Struct used to keep track of other peer's status. More...
 
struct  PeersIteratorCls
 Closure to valid_peer_iterator. More...
 
struct  ChannelCtx
 Context for a channel. More...
 
struct  Sub
 One Sub. More...
 
struct  GetRandPeerIteratorCls
 The closure to get_rand_peer_iterator. More...
 
struct  ReplyCls
 Closure used to pass the client and the id to the callback that replies to a client's request. More...
 
struct  ClientContext
 Struct used to store the context of a connected client. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log(kind, __VA_ARGS__)
 
#define SET_PEER_FLAG(peer_ctx, mask)   ((peer_ctx->peer_flags) |= (mask))
 Set a peer flag of given peer context. More...
 
#define check_peer_flag_set(peer_ctx, mask)   ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
 Get peer flag of given peer context. More...
 
#define UNSET_PEER_FLAG(peer_ctx, mask)   ((peer_ctx->peer_flags) &= ~(mask))
 Unset flag of given peer context. More...
 
#define check_channel_flag_set(channel_flags, mask)   ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
 Get channel flag of given channel context. More...
 
#define unset_channel_flag(channel_flags, mask)   ((*channel_flags) &= ~(mask))
 Unset flag of given channel context. More...
 
#define HISTOGRAM_FILE_SLOTS   32
 This number determines the number of slots for files that represent histograms. More...
 
#define SIZE_DUMP_FILE   (HISTOGRAM_FILE_SLOTS * 5) + 1
 The size (in bytes) a file needs to store the histogram. More...
 

Functions

static void do_round (void *cls)
 Send out PUSHes and PULLs, possibly update #view, samplers. More...
 
static void do_mal_round (void *cls)
 
static struct PeerContextget_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
 Get the PeerContext associated with a peer. More...
 
static int check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
 Check whether we have information about the given peer. More...
 
static struct PeerContextcreate_peer_ctx (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Create a new PeerContext and insert it into the peer map. More...
 
static struct PeerContextcreate_or_get_peer_ctx (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Create or get a PeerContext. More...
 
static int check_connected (struct PeerContext *peer_ctx)
 Check whether we have a connection to this peer. More...
 
static int get_rand_peer_iterator (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Iterator function for get_random_peer_from_peermap. More...
 
static const struct GNUNET_PeerIdentityget_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
 Get a random peer from peer_map. More...
 
static int add_valid_peer (const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
 Add a given peer to valid peers. More...
 
static void remove_pending_message (struct PendingMessage *pending_msg, int cancel)
 Remove a pending message from the respective DLL. More...
 
static void set_peer_online (struct PeerContext *peer_ctx)
 Set the peer flag to living and call the pending operations on this peer. More...
 
static void cleanup_destroyed_channel (void *cls, const struct GNUNET_CADET_Channel *channel)
 This is called when a channel is destroyed. More...
 
static void handle_peer_check (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle a CHECK_LIVE message from another peer. More...
 
static void handle_peer_push (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle a PUSH message from another peer. More...
 
static void handle_peer_pull_request (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle PULL REQUEST request message from another peer. More...
 
static int check_peer_pull_reply (void *cls, const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
 Check whether we sent a corresponding request and whether this reply is the first one. More...
 
static void handle_peer_pull_reply (void *cls, const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
 Handle PULL REPLY message from another peer. More...
 
static struct ChannelCtxadd_channel_ctx (struct PeerContext *peer_ctx)
 Allocate memory for a new channel context and insert it into DLL. More...
 
static void remove_channel_ctx (struct ChannelCtx *channel_ctx)
 Free memory and NULL pointers. More...
 
struct GNUNET_CADET_Channelget_channel (struct PeerContext *peer_ctx)
 Get the channel of a peer. More...
 
static struct GNUNET_MQ_Handleget_mq (struct PeerContext *peer_ctx)
 Get the message queue (GNUNET_MQ_Handle) of a specific peer. More...
 
static struct PendingMessageinsert_pending_message (struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
 Add an envelope to a message passed to mq to list of pending messages. More...
 
static void mq_online_check_successful (void *cls)
 This is called in response to the first message we sent as a online check. More...
 
static void check_peer_online (struct PeerContext *peer_ctx)
 Issue a check whether peer is online. More...
 
static int check_operation_scheduled (const struct PeerContext *peer_ctx, const PeerOp peer_op)
 Check whether function of type PeerOp was already scheduled. More...
 
static void destroy_channel (struct ChannelCtx *channel_ctx)
 Callback for scheduler to destroy a channel. More...
 
static void destroy_channel_cb (void *cls)
 Destroy a cadet channel. More...
 
static void schedule_channel_destruction (struct ChannelCtx *channel_ctx)
 Schedule the destruction of a channel for immediately afterwards. More...
 
static int destroy_peer (struct PeerContext *peer_ctx)
 Remove peer. More...
 
static int peermap_clear_iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
static void mq_notify_sent_cb (void *cls)
 This is called once a message is sent. More...
 
static int store_peer_presistently_iterator (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Iterator function for store_valid_peers. More...
 
static void store_valid_peers (const struct Sub *sub)
 Store the peers currently in #valid_peers to disk. More...
 
static const struct GNUNET_PeerIdentitys2i_full (const char *string_repr)
 Convert string representation of peer id to peer id. More...
 
static void restore_valid_peers (const struct Sub *sub)
 Restore the peers on disk to #valid_peers. More...
 
static void peers_terminate (struct Sub *sub)
 Delete storage of peers that was created with #initialise_peers () More...
 
static int valid_peer_iterator (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Iterator over #valid_peers hash map entries. More...
 
static int get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, PeersIterator iterator, void *it_cls)
 Get all currently known, valid peer ids. More...
 
static int insert_peer (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Add peer to known peers. More...
 
static int check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
 Check whether flags on a peer are set. More...
 
static int issue_peer_online_check (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Try connecting to a peer to see whether it is online. More...
 
static int check_removable (const struct PeerContext *peer_ctx)
 Check if peer is removable. More...
 
static int check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, const struct GNUNET_PeerIdentity *peer)
 Check whether peer is actually a peer. More...
 
static void indicate_sending_intention (struct PeerContext *peer_ctx)
 Indicate that we want to send to the other peer. More...
 
static int check_peer_send_intention (const struct PeerContext *peer_ctx)
 Check whether other peer has the intention to send/opened channel towars us. More...
 
static void * handle_inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
 Handle the channel a peer opens to us. More...
 
static int check_sending_channel_exists (const struct PeerContext *peer_ctx)
 Check whether a sending channel towards the given peer exists. More...
 
static int destroy_sending_channel (struct PeerContext *peer_ctx)
 Destroy the send channel of a peer e.g. More...
 
static void send_message (struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
 Send a message to another peer. More...
 
static int schedule_operation (struct PeerContext *peer_ctx, const PeerOp peer_op, void *cls)
 Schedule a operation on given peer. More...
 
static void print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len)
 Print peerlist to log. More...
 
static void rem_from_list (struct GNUNET_PeerIdentity **peer_list, unsigned int *list_size, const struct GNUNET_PeerIdentity *peer)
 Remove peer from list. More...
 
static void insert_in_view_op (void *cls, const struct GNUNET_PeerIdentity *peer)
 Insert PeerID in #view. More...
 
static int insert_in_view (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Insert PeerID in #view. More...
 
static void send_view (const struct ClientContext *cli_ctx, const struct GNUNET_PeerIdentity *view_array, uint64_t view_size)
 Send view to client. More...
 
static void send_stream_peers (const struct ClientContext *cli_ctx, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
 Send peer from biased stream to client. More...
 
static void clients_notify_view_update (const struct Sub *sub)
 sends updates to clients that are interested More...
 
static void clients_notify_stream_peer (const struct Sub *sub, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
 sends updates to clients that are interested More...
 
static void hist_update (const struct GNUNET_PeerIdentity *ids, uint32_t num_peers, void *cls)
 Put random peer from sampler into the view as history update. More...
 
static void resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
 Wrapper around RPS_sampler_resize() More...
 
static void add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, unsigned int num_peers, struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
 Add all peers in peer_array to peer_map used as set. More...
 
static void send_pull_reply (struct PeerContext *peer_ctx, const struct GNUNET_PeerIdentity *peer_ids, unsigned int num_peer_ids)
 Send a PULL REPLY to peer_id. More...
 
static void insert_in_pull_map (void *cls, const struct GNUNET_PeerIdentity *peer)
 Insert PeerID in #pull_map. More...
 
static void insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
 Update sampler with given PeerID. More...
 
static void got_peer (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 This is called on peers from external sources (cadet, peerinfo, ...) If the peer is not known, online check is issued and it is scheduled to be inserted in sampler and view. More...
 
static int check_sending_channel_needed (const struct PeerContext *peer_ctx)
 Checks if there is a sending channel and if it is needed. More...
 
static void remove_peer (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 remove peer from our knowledge, the view, push and pull maps and samplers. More...
 
static void clean_peer (struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
 Remove data that is not needed anymore. More...
 
struct Subnew_sub (const struct GNUNET_HashCode *hash, uint32_t sampler_size, struct GNUNET_TIME_Relative round_interval)
 Create a new Sub. More...
 
static void write_histogram_to_file (const uint32_t hist_array[], const char *file_name)
 Write all numbers in the given array into the given file. More...
 
static void destroy_sub (struct Sub *sub)
 Destroy Sub. More...
 
void core_init (void *cls, const struct GNUNET_PeerIdentity *my_identity)
 Callback on initialisation of Core. More...
 
void * core_connects (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Callback for core. More...
 
void core_disconnects (void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
 Callback for core. More...
 
static void destroy_cli_ctx (struct ClientContext *cli_ctx)
 Destroy the context for a (connected) client. More...
 
static void adapt_sizes (struct Sub *sub, double logestimate, double std_dev)
 Update sizes in sampler and view on estimate update from nse service. More...
 
static void nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
 Function called by NSE. More...
 
static int check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
 This function is called, when the client seeds peers. More...
 
static void handle_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
 Handle seed from the client. More...
 
static void handle_client_view_request (void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg)
 Handle RPS request from the client. More...
 
static void handle_client_view_cancel (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle the cancellation of the view updates. More...
 
static void handle_client_stream_request (void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg)
 Handle RPS request for biased stream from the client. More...
 
static void handle_client_stream_cancel (void *cls, const struct GNUNET_MessageHeader *msg)
 Handles the cancellation of the stream of biased peer ids. More...
 
static void handle_client_start_sub (void *cls, const struct GNUNET_RPS_CS_SubStartMessage *msg)
 Create and start a Sub. More...
 
static void handle_client_stop_sub (void *cls, const struct GNUNET_RPS_CS_SubStopMessage *msg)
 Destroy the Sub. More...
 
static struct GNUNET_TIME_Relative compute_rand_delay (struct GNUNET_TIME_Relative mean, unsigned int spread)
 Compute a random delay. More...
 
static void send_pull_request (struct PeerContext *peer_ctx)
 Send single pull request. More...
 
static void send_push (struct PeerContext *peer_ctx)
 Send single push. More...
 
void init_peer_cb (void *cls, const struct GNUNET_PeerIdentity *peer, int tunnel, unsigned int n_paths, unsigned int best_path)
 This is called from GNUNET_CADET_get_peers(). More...
 
static int valid_peers_iterator (void *cls, const struct GNUNET_PeerIdentity *peer)
 Iterator function over stored, valid peers. More...
 
void process_peerinfo_peers (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Iterator over peers from peerinfo. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Handle client connecting to the service. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls)
 Callback called when a client disconnected from the service. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Handle random peer sampling clients. More...
 
 GNUNET_SERVICE_MAIN ("rps", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(client_seed, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, struct GNUNET_RPS_CS_SeedMessage, NULL), GNUNET_MQ_hd_fixed_size(client_view_request, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, struct GNUNET_RPS_CS_DEBUG_ViewRequest, NULL), GNUNET_MQ_hd_fixed_size(client_view_cancel, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(client_stream_request, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, struct GNUNET_RPS_CS_DEBUG_StreamRequest, NULL), GNUNET_MQ_hd_fixed_size(client_stream_cancel, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(client_start_sub, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, struct GNUNET_RPS_CS_SubStartMessage, NULL), GNUNET_MQ_hd_fixed_size(client_stop_sub, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, struct GNUNET_RPS_CS_SubStopMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
struct GNUNET_STATISTICS_Handlestats
 Handle to the statistics service. More...
 
struct GNUNET_CADET_Handlecadet_handle
 Handler to CADET. More...
 
struct GNUNET_CORE_Handlecore_handle
 Handle to CORE. More...
 
struct GNUNET_CONTAINER_MultiPeerMapmap_single_hop
 PeerMap to keep track of connected peers. More...
 
static struct GNUNET_PeerIdentity own_identity
 Our own identity. More...
 
static float alpha
 Percentage of total peer number in the view to send random PUSHes to. More...
 
static float beta
 Percentage of total peer number in the view to send random PULLs to. More...
 
static struct GNUNET_NSE_Handlense
 Handler to NSE. More...
 
static struct GNUNET_PEERINFO_Handlepeerinfo_handle
 Handler to PEERINFO. More...
 
static struct GNUNET_PEERINFO_NotifyContextpeerinfo_notify_handle
 Handle for cancellation of iteration over peers. More...
 
static struct Submsub
 Main Sub. More...
 
static const uint32_t num_valid_peers_max = UINT32_MAX
 Maximum number of valid peers to keep. More...
 
struct ClientContextcli_ctx_head
 DLL with all clients currently connected to us. More...
 
struct ClientContextcli_ctx_tail
 

Detailed Description

rps service implementation

Author
Julius B√ľnger

Definition in file gnunet-service-rps.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log(kind, __VA_ARGS__)

◆ SET_PEER_FLAG

#define SET_PEER_FLAG (   peer_ctx,
  mask 
)    ((peer_ctx->peer_flags) |= (mask))

Set a peer flag of given peer context.

Definition at line 63 of file gnunet-service-rps.c.

Referenced by check_connected(), destroy_peer(), send_pull_request(), and set_peer_online().

◆ check_peer_flag_set

#define check_peer_flag_set (   peer_ctx,
  mask 
)    ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO)

Get peer flag of given peer context.

Definition at line 68 of file gnunet-service-rps.c.

Referenced by check_peer_flag(), and check_removable().

◆ UNSET_PEER_FLAG

#define UNSET_PEER_FLAG (   peer_ctx,
  mask 
)    ((peer_ctx->peer_flags) &= ~(mask))

Unset flag of given peer context.

Definition at line 74 of file gnunet-service-rps.c.

Referenced by check_connected(), destroy_peer(), and handle_peer_pull_reply().

◆ check_channel_flag_set

#define check_channel_flag_set (   channel_flags,
  mask 
)    ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO)

Get channel flag of given channel context.

Definition at line 79 of file gnunet-service-rps.c.

◆ unset_channel_flag

#define unset_channel_flag (   channel_flags,
  mask 
)    ((*channel_flags) &= ~(mask))

Unset flag of given channel context.

Definition at line 85 of file gnunet-service-rps.c.

◆ HISTOGRAM_FILE_SLOTS

#define HISTOGRAM_FILE_SLOTS   32

This number determines the number of slots for files that represent histograms.

Definition at line 289 of file gnunet-service-rps.c.

Referenced by do_round(), and write_histogram_to_file().

◆ SIZE_DUMP_FILE

#define SIZE_DUMP_FILE   (HISTOGRAM_FILE_SLOTS * 5) + 1

The size (in bytes) a file needs to store the histogram.

Per slot: 1 newline, up to 4 chars, Additionally: 1 null termination

Definition at line 297 of file gnunet-service-rps.c.

Referenced by write_histogram_to_file().

Function Documentation

◆ do_round()

static void do_round ( void *  cls)
static

Send out PUSHes and PULLs, possibly update #view, samplers.

This is executed regylary.

Parameters
clsClosure - Sub

Definition at line 4209 of file gnunet-service-rps.c.

References alpha, beta, check_peer_flag(), clean_peer(), clients_notify_stream_peer(), clients_notify_view_update(), compute_rand_delay(), CustomPeerMap_clear(), CustomPeerMap_get_peer_by_index(), CustomPeerMap_size(), Sub::do_round_task, get_peer_ctx(), GNUNET_array_grow, GNUNET_CRYPTO_QUALITY_STRONG, GNUNET_CRYPTO_random_permute(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s(), GNUNET_i2s_full(), GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), hist_update(), HISTOGRAM_FILE_SLOTS, insert_in_sampler(), insert_in_view(), LOG, Sub::num_rounds, Sub::peer_map, Peers_PULL_REPLY_PENDING, Sub::pull_map, Sub::push_delta, Sub::push_map, Sub::push_recv, rem_from_list(), Sub::round_interval, RPS_sampler_get_n_rand_peers(), Sub::sampler, send_pull_request(), send_push(), to_file, Sub::view, View_clear(), View_get_as_array(), View_size(), and Sub::view_size_est_need.

Referenced by new_sub(), and send_push().

4210 {
4211  unsigned int i;
4212  const struct GNUNET_PeerIdentity *view_array;
4213  unsigned int *permut;
4214  unsigned int a_peers; /* Number of peers we send pushes to */
4215  unsigned int b_peers; /* Number of peers we send pull requests to */
4216  uint32_t first_border;
4217  uint32_t second_border;
4218  struct GNUNET_PeerIdentity peer;
4219  struct GNUNET_PeerIdentity *update_peer;
4220  struct Sub *sub = cls;
4221 
4222  sub->num_rounds++;
4224  "Going to execute next round.\n");
4225  if (sub == msub)
4226  {
4227  GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO);
4228  }
4229  sub->do_round_task = NULL;
4230 #ifdef TO_FILE_FULL
4231  to_file (sub->file_name_view_log,
4232  "___ new round ___");
4233 #endif /* TO_FILE_FULL */
4234  view_array = View_get_as_array (sub->view);
4235  for (i = 0; i < View_size (sub->view); i++)
4236  {
4238  "\t%s\n", GNUNET_i2s (&view_array[i]));
4239 #ifdef TO_FILE_FULL
4240  to_file (sub->file_name_view_log,
4241  "=%s\t(do round)",
4242  GNUNET_i2s_full (&view_array[i]));
4243 #endif /* TO_FILE_FULL */
4244  }
4245 
4246 
4247  /* Send pushes and pull requests */
4248  if (0 < View_size (sub->view))
4249  {
4251  View_size (sub->view));
4252 
4253  /* Send PUSHes */
4254  a_peers = ceil (alpha * View_size (sub->view));
4255 
4257  "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4258  a_peers, alpha, View_size (sub->view));
4259  for (i = 0; i < a_peers; i++)
4260  {
4261  peer = view_array[permut[i]];
4262  // FIXME if this fails schedule/loop this for later
4263  send_push (get_peer_ctx (sub->peer_map, &peer));
4264  }
4265 
4266  /* Send PULL requests */
4267  b_peers = ceil (beta * View_size (sub->view));
4268  first_border = a_peers;
4269  second_border = a_peers + b_peers;
4270  if (second_border > View_size (sub->view))
4271  {
4272  first_border = View_size (sub->view) - b_peers;
4273  second_border = View_size (sub->view);
4274  }
4276  "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
4277  b_peers, beta, View_size (sub->view));
4278  for (i = first_border; i < second_border; i++)
4279  {
4280  peer = view_array[permut[i]];
4281  if ( GNUNET_NO == check_peer_flag (sub->peer_map,
4282  &peer,
4284  { // FIXME if this fails schedule/loop this for later
4286  }
4287  }
4288 
4289  GNUNET_free (permut);
4290  permut = NULL;
4291  }
4292 
4293 
4294  /* Update view */
4295  /* TODO see how many peers are in push-/pull- list! */
4296 
4297  if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) &&
4298  (0 < CustomPeerMap_size (sub->push_map)) &&
4299  (0 < CustomPeerMap_size (sub->pull_map)))
4300  { /* If conditions for update are fulfilled, update */
4301  LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
4302 
4303  uint32_t final_size;
4304  uint32_t peers_to_clean_size;
4305  struct GNUNET_PeerIdentity *peers_to_clean;
4306 
4307  peers_to_clean = NULL;
4308  peers_to_clean_size = 0;
4309  GNUNET_array_grow (peers_to_clean,
4310  peers_to_clean_size,
4311  View_size (sub->view));
4312  GNUNET_memcpy (peers_to_clean,
4313  view_array,
4314  View_size (sub->view) * sizeof (struct GNUNET_PeerIdentity));
4315 
4316  /* Seems like recreating is the easiest way of emptying the peermap */
4317  View_clear (sub->view);
4318 #ifdef TO_FILE_FULL
4319  to_file (sub->file_name_view_log,
4320  "--- emptied ---");
4321 #endif /* TO_FILE_FULL */
4322 
4323  first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need),
4324  CustomPeerMap_size (sub->push_map));
4325  second_border = first_border +
4326  GNUNET_MIN (floor (beta * sub->view_size_est_need),
4327  CustomPeerMap_size (sub->pull_map));
4328  final_size = second_border +
4329  ceil ((1 - (alpha + beta)) * sub->view_size_est_need);
4331  "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"PRIu32 "\n",
4332  first_border,
4333  second_border,
4334  final_size);
4335 
4336  /* Update view with peers received through PUSHes */
4338  CustomPeerMap_size (sub->push_map));
4339  for (i = 0; i < first_border; i++)
4340  {
4341  int inserted;
4342  inserted = insert_in_view (sub,
4344  permut[i]));
4345  if (GNUNET_OK == inserted)
4346  {
4348  1,
4349  CustomPeerMap_get_peer_by_index (sub->push_map, permut[i]));
4350  }
4351 #ifdef TO_FILE_FULL
4352  to_file (sub->file_name_view_log,
4353  "+%s\t(push list)",
4354  GNUNET_i2s_full (&view_array[i]));
4355 #endif /* TO_FILE_FULL */
4356  // TODO change the peer_flags accordingly
4357  }
4358  GNUNET_free (permut);
4359  permut = NULL;
4360 
4361  /* Update view with peers received through PULLs */
4363  CustomPeerMap_size (sub->pull_map));
4364  for (i = first_border; i < second_border; i++)
4365  {
4366  int inserted;
4367  inserted = insert_in_view (sub,
4369  permut[i - first_border]));
4370  if (GNUNET_OK == inserted)
4371  {
4373  1,
4375  permut[i - first_border]));
4376  }
4377 #ifdef TO_FILE_FULL
4378  to_file (sub->file_name_view_log,
4379  "+%s\t(pull list)",
4380  GNUNET_i2s_full (&view_array[i]));
4381 #endif /* TO_FILE_FULL */
4382  // TODO change the peer_flags accordingly
4383  }
4384  GNUNET_free (permut);
4385  permut = NULL;
4386 
4387  /* Update view with peers from history */
4389  final_size - second_border,
4390  hist_update,
4391  sub);
4392  // TODO change the peer_flags accordingly
4393 
4394  for (i = 0; i < View_size (sub->view); i++)
4395  rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]);
4396 
4397  /* Clean peers that were removed from the view */
4398  for (i = 0; i < peers_to_clean_size; i++)
4399  {
4400 #ifdef TO_FILE_FULL
4401  to_file (sub->file_name_view_log,
4402  "-%s",
4403  GNUNET_i2s_full (&peers_to_clean[i]));
4404 #endif /* TO_FILE_FULL */
4405  clean_peer (sub, &peers_to_clean[i]);
4406  }
4407 
4408  GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0);
4410  } else {
4411  LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
4412  if (sub == msub)
4413  {
4414  GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO);
4415  if (CustomPeerMap_size (sub->push_map) > alpha * sub->view_size_est_need &&
4416  !(0 >= CustomPeerMap_size (sub->pull_map)))
4417  GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO);
4418  if (CustomPeerMap_size (sub->push_map) > alpha * sub->view_size_est_need &&
4419  (0 >= CustomPeerMap_size (sub->pull_map)))
4420  GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO);
4421  if (0 >= CustomPeerMap_size (sub->push_map) &&
4422  !(0 >= CustomPeerMap_size (sub->pull_map)))
4423  GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO);
4424  if (0 >= CustomPeerMap_size (sub->push_map) &&
4425  (0 >= CustomPeerMap_size (sub->pull_map)))
4426  GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO);
4427  if (0 >= CustomPeerMap_size (sub->pull_map) &&
4429  0 >= CustomPeerMap_size (sub->push_map))
4430  GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO);
4431  }
4432  }
4433  // TODO independent of that also get some peers from CADET_get_peers()?
4435  {
4436  sub->push_recv[CustomPeerMap_size (sub->push_map)]++;
4437  }
4438  else
4439  {
4441  "Push map size too big for histogram (%u, %u)\n",
4444  }
4445  // FIXME check bounds of histogram
4446  sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map) -
4447  (alpha * sub->view_size_est_need)) +
4448  (HISTOGRAM_FILE_SLOTS/2)]++;
4449  if (sub == msub)
4450  {
4452  "# peers in push map at end of round",
4454  GNUNET_NO);
4456  "# peers in pull map at end of round",
4458  GNUNET_NO);
4460  "# peers in view at end of round",
4461  View_size (sub->view),
4462  GNUNET_NO);
4464  "# expected pushes",
4465  alpha * sub->view_size_est_need,
4466  GNUNET_NO);
4468  "delta expected - received pushes",
4470  GNUNET_NO);
4471  }
4472 
4474  "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n",
4477  alpha,
4478  View_size (sub->view),
4479  alpha * View_size (sub->view));
4480 
4481  /* Update samplers */
4482  for (i = 0; i < CustomPeerMap_size (sub->push_map); i++)
4483  {
4484  update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i);
4486  "Updating with peer %s from push list\n",
4487  GNUNET_i2s (update_peer));
4488  insert_in_sampler (sub, update_peer);
4489  clean_peer (sub, update_peer); /* This cleans only if it is not in the view */
4490  }
4491 
4492  for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++)
4493  {
4495  "Updating with peer %s from pull list\n",
4498  /* This cleans only if it is not in the view */
4500  }
4501 
4502 
4503  /* Empty push/pull lists */
4506 
4507  if (sub == msub)
4508  {
4510  "view size",
4511  View_size(sub->view),
4512  GNUNET_NO);
4513  }
4514 
4515  struct GNUNET_TIME_Relative time_next_round;
4516 
4517  time_next_round = compute_rand_delay (sub->round_interval, 2);
4518 
4519  /* Schedule next round */
4520  sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4521  &do_round, sub);
4522  LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4523 }
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
static int insert_in_view(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
uint32_t num_rounds
Counts the executed rounds.
static void insert_in_sampler(void *cls, const struct GNUNET_PeerIdentity *peer)
Update sampler with given PeerID.
unsigned int * GNUNET_CRYPTO_random_permute(enum GNUNET_CRYPTO_Quality mode, unsigned int n)
Get an array with a random permutation of the numbers 0...n-1.
#define HISTOGRAM_FILE_SLOTS
This number determines the number of slots for files that represent histograms.
static float alpha
Percentage of total peer number in the view to send random PUSHes to.
struct GNUNET_PeerIdentity * CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, uint32_t index)
Get a peer by index.
#define to_file(file_name,...)
This function is used to facilitate writing important information to disk.
Definition: rps-test_util.h:65
static void send_pull_request(struct PeerContext *peer_ctx)
Send single pull request.
static void hist_update(const struct GNUNET_PeerIdentity *ids, uint32_t num_peers, void *cls)
Put random peer from sampler into the view as history update.
struct RPS_Sampler * sampler
Sampler used for the Brahms protocol itself.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct CustomPeerMap * push_map
List to store peers received through pushes temporary.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
unsigned int view_size_est_need
This is the estimate used as view size.
uint32_t push_delta[32]
Histogram of deltas between the expected and actual number of received pushes.
#define LOG(kind,...)
static void clients_notify_stream_peer(const struct Sub *sub, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
sends updates to clients that are interested
struct GNUNET_TIME_Relative round_interval
Time interval the do_round task runs in.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
If we are waiting for a reply from that peer (sent a pull request).
Definition: rps.h:251
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_memcpy(dst, src, n)
void CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map)
Clear the custom peer map.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
struct CustomPeerMap * pull_map
List to store peers received through pulls temporary.
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 void rem_from_list(struct GNUNET_PeerIdentity **peer_list, unsigned int *list_size, const struct GNUNET_PeerIdentity *peer)
Remove peer from list.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
One Sub.
uint32_t push_recv[32]
This array accumulates the number of received pushes per round.
unsigned int CustomPeerMap_size(const struct CustomPeerMap *c_peer_map)
Get the size of the custom peer map.
static void clean_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Remove data that is not needed anymore.
The identity of the host (wraps the signing key of the peer).
static void send_push(struct PeerContext *peer_ctx)
Send single push.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
unsigned int View_size(const struct View *view)
Get the size of the view.
void View_clear(struct View *view)
Clear the view.
struct GNUNET_SCHEDULER_Task * do_round_task
Identifier for the main task that runs periodically.
static float beta
Percentage of total peer number in the view to send random PULLs to.
struct View * view
The view.
static int check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
Check whether flags on a peer are set.
static struct GNUNET_TIME_Relative compute_rand_delay(struct GNUNET_TIME_Relative mean, unsigned int spread)
Compute a random delay.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void clients_notify_view_update(const struct Sub *sub)
sends updates to clients that are interested
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
High-quality operations are desired.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_mal_round()

static void do_mal_round ( void *  cls)
static

Referenced by send_push().

Here is the caller graph for this function:

◆ get_peer_ctx()

static struct PeerContext* get_peer_ctx ( const struct GNUNET_CONTAINER_MultiPeerMap peer_map,
const struct GNUNET_PeerIdentity peer 
)
static

Get the PeerContext associated with a peer.

Parameters
peer_mapThe peer map containing the context
peerthe peer id
Returns
the PeerContext

Definition at line 613 of file gnunet-service-rps.c.

References ctx, GNUNET_assert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_YES, and ret.

Referenced by check_connected(), check_peer_flag(), clean_peer(), create_or_get_peer_ctx(), do_round(), got_peer(), handle_inbound_channel(), handle_peer_pull_reply(), insert_in_view(), issue_peer_online_check(), peermap_clear_iterator(), remove_peer(), and send_push().

615 {
616  struct PeerContext *ctx;
617  int ret;
618 
619  ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
620  GNUNET_assert (GNUNET_YES == ret);
621  ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
622  GNUNET_assert (NULL != ctx);
623  return ctx;
624 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Struct used to keep track of other peer&#39;s status.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_known()

static int check_peer_known ( const struct GNUNET_CONTAINER_MultiPeerMap peer_map,
const struct GNUNET_PeerIdentity peer 
)
static

Check whether we have information about the given peer.

FIXME probably deprecated. Make this the new _online.

Parameters
peer_mapThe peer map to check for the existence of peer
peerpeer in question
Returns
GNUNET_YES if peer is known GNUNET_NO if peer is not knwon

Definition at line 638 of file gnunet-service-rps.c.

References GNUNET_CONTAINER_multipeermap_contains(), and GNUNET_NO.

Referenced by check_connected(), check_peer_flag(), check_sending_channel_exists(), check_sending_channel_needed(), create_or_get_peer_ctx(), create_peer_ctx(), destroy_sending_channel(), handle_peer_pull_reply(), handle_peer_pull_request(), handle_peer_push(), hist_update(), indicate_sending_intention(), insert_peer(), remove_peer(), schedule_operation(), and send_push().

640 {
641  if (NULL != peer_map)
642  {
643  return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
644  }
645  else
646  {
647  return GNUNET_NO;
648  }
649 }
#define GNUNET_NO
Definition: gnunet_common.h:81
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_peer_ctx()

static struct PeerContext* create_peer_ctx ( struct Sub sub,
const struct GNUNET_PeerIdentity peer 
)
static

Create a new PeerContext and insert it into the peer map.

Parameters
subThe Sub this context belongs to.
peerthe peer to create the PeerContext for
Returns
the PeerContext

Definition at line 661 of file gnunet-service-rps.c.

References check_peer_known(), ctx, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_set(), peer, PeerContext::peer_id, Sub::peer_map, ret, and PeerContext::sub.

Referenced by create_or_get_peer_ctx(), and insert_peer().

663 {
664  struct PeerContext *ctx;
665  int ret;
666 
668 
669  ctx = GNUNET_new (struct PeerContext);
670  ctx->peer_id = *peer;
671  ctx->sub = sub;
672  ret = GNUNET_CONTAINER_multipeermap_put (sub->peer_map, peer, ctx,
674  GNUNET_assert (GNUNET_OK == ret);
675  if (sub == msub)
676  {
678  "# known peers",
680  GNUNET_NO);
681  }
682  return ctx;
683 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct Sub * msub
Main Sub.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
Struct used to keep track of other peer&#39;s status.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct Sub * sub
The Sub this context belongs to.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_or_get_peer_ctx()

static struct PeerContext* create_or_get_peer_ctx ( struct Sub sub,
const struct GNUNET_PeerIdentity peer 
)
static

Create or get a PeerContext.

Parameters
subThe Sub to which the created context belongs to
peerthe peer to get the associated context to
Returns
the context

Definition at line 695 of file gnunet-service-rps.c.

References check_peer_known(), create_peer_ctx(), get_peer_ctx(), GNUNET_NO, and Sub::peer_map.

Referenced by handle_inbound_channel().

697 {
698  if (GNUNET_NO == check_peer_known (sub->peer_map, peer))
699  {
700  return create_peer_ctx (sub, peer);
701  }
702  return get_peer_ctx (sub->peer_map, peer);
703 }
static struct PeerContext * create_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create a new PeerContext and insert it into the peer map.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_connected()

static int check_connected ( struct PeerContext peer_ctx)
static

Check whether we have a connection to this peer.

Also sets the Peers_ONLINE flag accordingly

Parameters
peer_ctxContext of the peer of which connectivity is to be checked
Returns
GNUNET_YES if we are connected GNUNET_NO otherwise

Definition at line 717 of file gnunet-service-rps.c.

References check_peer_known(), get_peer_ctx(), GNUNET_NO, GNUNET_YES, PeerContext::peer_id, Sub::peer_map, Peers_ONLINE, PeerContext::recv_channel_ctx, PeerContext::send_channel_ctx, SET_PEER_FLAG, PeerContext::sub, and UNSET_PEER_FLAG.

Referenced by destroy_sending_channel().

718 {
719  /* If we don't know about this peer we don't know whether it's online */
720  if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
721  &peer_ctx->peer_id))
722  {
723  return GNUNET_NO;
724  }
725  /* Get the context */
726  peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id);
727  /* If we have no channel to this peer we don't know whether it's online */
728  if ( (NULL == peer_ctx->send_channel_ctx) &&
729  (NULL == peer_ctx->recv_channel_ctx) )
730  {
731  UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
732  return GNUNET_NO;
733  }
734  /* Otherwise (if we have a channel, we know that it's online */
735  SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
736  return GNUNET_YES;
737 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define UNSET_PEER_FLAG(peer_ctx, mask)
Unset flag of given peer context.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
#define SET_PEER_FLAG(peer_ctx, mask)
Set a peer flag of given peer context.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
struct ChannelCtx * send_channel_ctx
Channel open to client.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
We set this bit when we know the peer is online.
Definition: rps.h:260
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_rand_peer_iterator()

static int get_rand_peer_iterator ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Iterator function for get_random_peer_from_peermap.

Implements GNUNET_CONTAINER_PeerMapIterator. Decreases the index until the index is null. Then returns the current peer.

Parameters
clsthe GetRandPeerIteratorCls containing index and peer
peercurrent peer
valueunused
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 775 of file gnunet-service-rps.c.

References GNUNET_NO, GNUNET_YES, GetRandPeerIteratorCls::index, peer, and GetRandPeerIteratorCls::peer.

Referenced by get_random_peer_from_peermap().

778 {
779  struct GetRandPeerIteratorCls *iterator_cls = cls;
780  (void) value;
781 
782  if (0 >= iterator_cls->index)
783  {
784  iterator_cls->peer = peer;
785  return GNUNET_NO;
786  }
787  iterator_cls->index--;
788  return GNUNET_YES;
789 }
The closure to get_rand_peer_iterator.
#define GNUNET_NO
Definition: gnunet_common.h:81
static char * value
Value of the record to add/remove.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
uint32_t index
The index of the peer to return.
const struct GNUNET_PeerIdentity * peer
Pointer to peer to return.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ get_random_peer_from_peermap()

static const struct GNUNET_PeerIdentity* get_random_peer_from_peermap ( struct GNUNET_CONTAINER_MultiPeerMap valid_peers)
static

Get a random peer from peer_map.

Parameters
valid_peersPeer map containing valid peers from which to select a random one
Returns
a random peer

Definition at line 801 of file gnunet-service-rps.c.

References get_rand_peer_iterator(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_free, GNUNET_new, GetRandPeerIteratorCls::index, GetRandPeerIteratorCls::peer, and ret.

Referenced by add_valid_peer().

802 {
803  struct GetRandPeerIteratorCls *iterator_cls;
804  const struct GNUNET_PeerIdentity *ret;
805 
806  iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
808  GNUNET_CONTAINER_multipeermap_size (valid_peers));
809  (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
811  iterator_cls);
812  ret = iterator_cls->peer;
813  GNUNET_free (iterator_cls);
814  return ret;
815 }
The closure to get_rand_peer_iterator.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t index
The index of the peer to return.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
const struct GNUNET_PeerIdentity * peer
Pointer to peer to return.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_free(ptr)
Wrapper around free.
static int get_rand_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for get_random_peer_from_peermap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_valid_peer()

static int add_valid_peer ( const struct GNUNET_PeerIdentity peer,
struct GNUNET_CONTAINER_MultiPeerMap valid_peers 
)
static

Add a given peer to valid peers.

If valid peers are already num_valid_peers_max, delete a peer previously.

Parameters
peerThe peer that is added to the valid peers.
valid_peersPeer map of valid peers to which to add the peer
Returns
GNUNET_YES if no other peer had to be removed GNUNET_NO otherwise

Definition at line 830 of file gnunet-service-rps.c.

References get_random_peer_from_peermap(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove_all(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_YES, num_valid_peers_max, remove_pending_message(), ret, and Sub::valid_peers.

Referenced by handle_inbound_channel(), mq_online_check_successful(), and restore_valid_peers().

832 {
833  const struct GNUNET_PeerIdentity *rand_peer;
834  int ret;
835 
836  ret = GNUNET_YES;
837  /* Remove random peers until there is space for a new one */
838  while (num_valid_peers_max <=
840  {
841  rand_peer = get_random_peer_from_peermap (valid_peers);
842  GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
843  ret = GNUNET_NO;
844  }
845  (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
847  if (valid_peers == msub->valid_peers)
848  {
850  "# valid peers",
852  GNUNET_NO);
853  }
854  return ret;
855 }
int GNUNET_CONTAINER_multipeermap_remove_all(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Remove all entries for the given key from the map.
static const struct GNUNET_PeerIdentity * get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Get a random peer from peer_map.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static const uint32_t num_valid_peers_max
Maximum number of valid peers to keep.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_pending_message()

static void remove_pending_message ( struct PendingMessage pending_msg,
int  cancel 
)
static

Remove a pending message from the respective DLL.

Parameters
pending_msgthe pending message to remove
cancelwhether to cancel the pending message, too

Definition at line 1080 of file gnunet-service-rps.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, PendingMessage::peer_ctx, PeerContext::pending_messages_head, and PeerContext::pending_messages_tail.

Referenced by add_valid_peer(), destroy_peer(), mq_notify_sent_cb(), mq_online_check_successful(), and set_peer_online().

1081 {
1082  struct PeerContext *peer_ctx;
1083  (void) cancel;
1084 
1085  peer_ctx = pending_msg->peer_ctx;
1086  GNUNET_assert (NULL != peer_ctx);
1088  peer_ctx->pending_messages_tail,
1089  pending_msg);
1090  // TODO wait for the cadet implementation of message cancellation
1091  //if (GNUNET_YES == cancel)
1092  //{
1093  // GNUNET_MQ_send_cancel (pending_msg->ev);
1094  //}
1095  GNUNET_free (pending_msg);
1096 }
#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.
struct PeerContext * peer_ctx
The corresponding context.
Struct used to keep track of other peer&#39;s status.
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
struct PendingMessage * pending_messages_tail
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ set_peer_online()

static void set_peer_online ( struct PeerContext peer_ctx)
static

Set the peer flag to living and call the pending operations on this peer.

Also adds peer to #valid_peers.

Parameters
peer_ctxthe PeerContext of the peer to set online

Definition at line 869 of file gnunet-service-rps.c.

References check_peer_pull_reply(), cleanup_destroyed_channel(), GNUNET_array_grow, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, handle_peer_check(), handle_peer_pull_reply(), handle_peer_pull_request(), handle_peer_push(), LOG, msg, PeerContext::num_pending_ops, PeerContext::online_check_pending, PeerPendingOp::op, PeerPendingOp::op_cls, peer, PeerContext::peer_id, Peers_ONLINE, PeerContext::pending_ops, remove_pending_message(), and SET_PEER_FLAG.

Referenced by handle_inbound_channel(), and mq_online_check_successful().

870 {
871  struct GNUNET_PeerIdentity *peer;
872  unsigned int i;
873 
874  peer = &peer_ctx->peer_id;
876  "Peer %s is online and valid, calling %i pending operations on it\n",
877  GNUNET_i2s (peer),
878  peer_ctx->num_pending_ops);
879 
880  if (NULL != peer_ctx->online_check_pending)
881  {
883  "Removing pending online check for peer %s\n",
884  GNUNET_i2s (&peer_ctx->peer_id));
885  // TODO wait until cadet sets mq->cancel_impl
886  //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
888  peer_ctx->online_check_pending = NULL;
889  }
890 
891  SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
892 
893  /* Call pending operations */
894  for (i = 0; i < peer_ctx->num_pending_ops; i++)
895  {
896  peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
897  }
898  GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
899 }
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
#define LOG(kind,...)
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define SET_PEER_FLAG(peer_ctx, mask)
Set a peer flag of given peer context.
PeerOp op
Callback.
unsigned int num_pending_ops
Number of pending operations.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
The identity of the host (wraps the signing key of the peer).
void * op_cls
Closure.
#define GNUNET_YES
Definition: gnunet_common.h:80
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
We set this bit when we know the peer is online.
Definition: rps.h:260
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_destroyed_channel()

static void cleanup_destroyed_channel ( void *  cls,
const struct GNUNET_CADET_Channel channel 
)
static

This is called when a channel is destroyed.

Removes peer completely from our knowledge if the send_channel was destroyed Otherwise simply delete the recv_channel Also check if the knowledge about this peer is still needed. If not, remove this peer from our knowledge.

Parameters
clsThe closure - Context to the channel
channelThe channel being closed

Definition at line 2803 of file gnunet-service-rps.c.

References ChannelCtx::channel, check_sending_channel_needed(), GNUNET_YES, ChannelCtx::peer_ctx, PeerContext::peer_id, remove_channel_ctx(), remove_peer(), PeerContext::send_channel_ctx, and PeerContext::sub.

Referenced by get_channel(), new_sub(), and set_peer_online().

2805 {
2806  struct ChannelCtx *channel_ctx = cls;
2807  struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2808  (void) channel;
2809 
2810  channel_ctx->channel = NULL;
2811  remove_channel_ctx (channel_ctx);
2812  if (NULL != peer_ctx &&
2813  peer_ctx->send_channel_ctx == channel_ctx &&
2815  {
2816  remove_peer (peer_ctx->sub, &peer_ctx->peer_id);
2817  }
2818 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
struct PeerContext * peer_ctx
The peer context associated with the channel.
Context for a channel.
struct GNUNET_CADET_Channel * channel
The channel itself.
Struct used to keep track of other peer&#39;s status.
static void remove_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
remove peer from our knowledge, the view, push and pull maps and samplers.
struct ChannelCtx * send_channel_ctx
Channel open to client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
static void remove_channel_ctx(struct ChannelCtx *channel_ctx)
Free memory and NULL pointers.
static int check_sending_channel_needed(const struct PeerContext *peer_ctx)
Checks if there is a sending channel and if it is needed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_peer_check()

static void handle_peer_check ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle a CHECK_LIVE message from another peer.

This does nothing. But without calling GNUNET_CADET_receive_done() the channel is blocked for all other communication.

Parameters
clsClosure - Context of channel
msgMessage - unused

Definition at line 3467 of file gnunet-service-rps.c.

References ChannelCtx::channel, GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_NO, GNUNET_STATISTICS_update(), LOG, ChannelCtx::peer_ctx, PeerContext::peer_id, and PeerContext::sub.

Referenced by set_peer_online().

3469 {
3470  const struct ChannelCtx *channel_ctx = cls;
3471  const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3472  (void) msg;
3473 
3475  "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3476  if (channel_ctx->peer_ctx->sub == msub)
3477  {
3479  "# pending online checks",
3480  -1,
3481  GNUNET_NO);
3482  }
3483 
3484  GNUNET_CADET_receive_done (channel_ctx->channel);
3485 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
struct PeerContext * peer_ctx
The peer context associated with the channel.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define LOG(kind,...)
Context for a channel.
struct GNUNET_CADET_Channel * channel
The channel itself.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct Sub * sub
The Sub this context belongs to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_peer_push()

static void handle_peer_push ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle a PUSH message from another peer.

Check the proof of work and store the PeerID in the temporary list for pushed PeerIDs.

Parameters
clsClosure - Context of channel
msgMessage - unused

Definition at line 3498 of file gnunet-service-rps.c.

References add_peer_array_to_set(), ChannelCtx::channel, check_peer_known(), CustomPeerMap_put(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, mal_type, peer, ChannelCtx::peer_ctx, PeerContext::peer_id, Sub::peer_map, Sub::push_map, and PeerContext::sub.

Referenced by set_peer_online().

3500 {
3501  const struct ChannelCtx *channel_ctx = cls;
3502  const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3503  (void) msg;
3504 
3505  // (check the proof of work (?))
3506 
3508  "Received PUSH (%s)\n",
3509  GNUNET_i2s (peer));
3510  if (channel_ctx->peer_ctx->sub == msub)
3511  {
3512  GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO);
3513  if (NULL != map_single_hop &&
3515  peer))
3516  {
3518  "# push message received (multi-hop peer)",
3519  1,
3520  GNUNET_NO);
3521  }
3522  }
3523 
3524  #if ENABLE_MALICIOUS
3525  struct AttackedPeer *tmp_att_peer;
3526 
3527  if ( (1 == mal_type) ||
3528  (3 == mal_type) )
3529  { /* Try to maximise representation */
3530  tmp_att_peer = GNUNET_new (struct AttackedPeer);
3531  tmp_att_peer->peer_id = *peer;
3532  if (NULL == att_peer_set)
3533  att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
3535  peer))
3536  {
3537  GNUNET_CONTAINER_DLL_insert (att_peers_head,
3538  att_peers_tail,
3539  tmp_att_peer);
3540  add_peer_array_to_set (peer, 1, att_peer_set);
3541  }
3542  else
3543  {
3544  GNUNET_free (tmp_att_peer);
3545  }
3546  }
3547 
3548 
3549  else if (2 == mal_type)
3550  {
3551  /* We attack one single well-known peer - simply ignore */
3552  }
3553  #endif /* ENABLE_MALICIOUS */
3554 
3555  /* Add the sending peer to the push_map */
3556  CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer);
3557 
3559  &channel_ctx->peer_ctx->peer_id));
3560  GNUNET_CADET_receive_done (channel_ctx->channel);
3561 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
struct PeerContext * peer_ctx
The peer context associated with the channel.
static unsigned int mal_type
Type of malicious peer to test.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct CustomPeerMap * push_map
List to store peers received through pushes temporary.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define LOG(kind,...)
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
static void add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, unsigned int num_peers, struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
Add all peers in peer_array to peer_map used as set.
int CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Insert peer into the custom peer map.
Context for a channel.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CADET_Channel * channel
The channel itself.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_CONTAINER_MultiPeerMap * map_single_hop
PeerMap to keep track of connected peers.
struct Sub * sub
The Sub this context belongs to.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_peer_pull_request()

static void handle_peer_pull_request ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle PULL REQUEST request message from another peer.

Reply with the view of PeerIDs.

Parameters
clsClosure - Context of channel
msgMessage - unused

Definition at line 3573 of file gnunet-service-rps.c.

References ChannelCtx::channel, check_peer_known(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_multipeermap_contains(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, mal_type, ChannelCtx::peer_ctx, PeerContext::peer_id, Sub::peer_map, send_pull_reply(), PeerContext::sub, Sub::view, View_get_as_array(), and View_size().

Referenced by set_peer_online().

3575 {
3576  const struct ChannelCtx *channel_ctx = cls;
3577  struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
3578  const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id;
3579  const struct GNUNET_PeerIdentity *view_array;
3580  (void) msg;
3581 
3582  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer));
3583  if (peer_ctx->sub == msub)
3584  {
3586  "# pull request message received",
3587  1,
3588  GNUNET_NO);
3589  if (NULL != map_single_hop &&
3591  &peer_ctx->peer_id))
3592  {
3594  "# pull request message received (multi-hop peer)",
3595  1,
3596  GNUNET_NO);
3597  }
3598  }
3599 
3600  #if ENABLE_MALICIOUS
3601  if (1 == mal_type
3602  || 3 == mal_type)
3603  { /* Try to maximise representation */
3604  send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3605  }
3606 
3607  else if (2 == mal_type)
3608  { /* Try to partition network */
3609  if (0 == GNUNET_memcmp (&attacked_peer, peer))
3610  {
3611  send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3612  }
3613  }
3614  #endif /* ENABLE_MALICIOUS */
3615 
3617  &channel_ctx->peer_ctx->peer_id));
3618  GNUNET_CADET_receive_done (channel_ctx->channel);
3619  view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view);
3620  send_pull_reply (peer_ctx,
3621  view_array,
3622  View_size (channel_ctx->peer_ctx->sub->view));
3623 }
static void send_pull_reply(struct PeerContext *peer_ctx, const struct GNUNET_PeerIdentity *peer_ids, unsigned int num_peer_ids)
Send a PULL REPLY to peer_id.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
struct PeerContext * peer_ctx
The peer context associated with the channel.
static unsigned int mal_type
Type of malicious peer to test.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
#define LOG(kind,...)
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
Context for a channel.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CADET_Channel * channel
The channel itself.
Struct used to keep track of other peer&#39;s status.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
unsigned int View_size(const struct View *view)
Get the size of the view.
struct GNUNET_CONTAINER_MultiPeerMap * map_single_hop
PeerMap to keep track of connected peers.
struct Sub * sub
The Sub this context belongs to.
struct View * view
The view.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_pull_reply()

static int check_peer_pull_reply ( void *  cls,
const struct GNUNET_RPS_P2P_PullReplyMessage msg 
)
static

Check whether we sent a corresponding request and whether this reply is the first one.

Parameters
clsClosure - Context of channel
msgMessage containing the replied peers

Definition at line 3634 of file gnunet-service-rps.c.

References check_peer_flag(), GNUNET_break_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, GNUNET_RPS_P2P_PullReplyMessage::header, LOG, GNUNET_RPS_P2P_PullReplyMessage::num_peers, ChannelCtx::peer_ctx, PeerContext::peer_id, Sub::peer_map, Peers_PULL_REPLY_PENDING, GNUNET_MessageHeader::size, and PeerContext::sub.

Referenced by set_peer_online().

3636 {
3637  struct ChannelCtx *channel_ctx = cls;
3638  struct PeerContext *sender_ctx = channel_ctx->peer_ctx;
3639 
3640  if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size))
3641  {
3642  GNUNET_break_op (0);
3643  return GNUNET_SYSERR;
3644  }
3645 
3646  if ((ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
3647  sizeof (struct GNUNET_PeerIdentity) != ntohl (msg->num_peers))
3648  {
3650  "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3651  ntohl (msg->num_peers),
3652  (ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
3653  sizeof (struct GNUNET_PeerIdentity));
3654  GNUNET_break_op (0);
3655  return GNUNET_SYSERR;
3656  }
3657 
3658  if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map,
3659  &sender_ctx->peer_id,
3661  {
3663  "Received a pull reply from a peer (%s) we didn't request one from!\n",
3664  GNUNET_i2s (&sender_ctx->peer_id));
3665  if (sender_ctx->sub == msub)
3666  {
3668  "# unrequested pull replies",
3669  1,
3670  GNUNET_NO);
3671  }
3672  }
3673  return GNUNET_OK;
3674 }
struct GNUNET_MessageHeader header
Header including size and type in NBO.
Definition: rps.h:48
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
P2P Message to send PeerIDs to other peer.
Definition: rps.h:43
uint32_t num_peers
Number of PeerIDs sent.
Definition: rps.h:53
struct PeerContext * peer_ctx
The peer context associated with the channel.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define LOG(kind,...)
If we are waiting for a reply from that peer (sent a pull request).
Definition: rps.h:251
Context for a channel.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Struct used to keep track of other peer&#39;s status.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
The identity of the host (wraps the signing key of the peer).
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
static int check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
Check whether flags on a peer are set.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_peer_pull_reply()

static void handle_peer_pull_reply ( void *  cls,
const struct GNUNET_RPS_P2P_PullReplyMessage msg 
)
static

Handle PULL REPLY message from another peer.

Parameters
clsClosure
msgThe message header

Definition at line 3684 of file gnunet-service-rps.c.

References add_peer_array_to_set(), ChannelCtx::channel, check_peer_known(), check_peer_valid(), clean_peer(), CustomPeerMap_put(), get_peer_ctx(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, insert_in_pull_map(), insert_peer(), issue_peer_online_check(), LOG, mal_type, GNUNET_RPS_P2P_PullReplyMessage::num_peers, Sub::num_rounds, ChannelCtx::peer_ctx, PeerContext::peer_id, Sub::peer_map, peers, Peers_PULL_REPLY_PENDING, Sub::pull_delays, Sub::pull_map, PeerContext::round_pull_req, schedule_operation(), PeerContext::sub, UNSET_PEER_FLAG, and Sub::valid_peers.

Referenced by set_peer_online().

3686 {
3687  const struct ChannelCtx *channel_ctx = cls;
3688  const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
3689  const struct GNUNET_PeerIdentity *peers;
3690  struct Sub *sub = channel_ctx->peer_ctx->sub;
3691  uint32_t i;
3692 #if ENABLE_MALICIOUS
3693  struct AttackedPeer *tmp_att_peer;
3694 #endif /* ENABLE_MALICIOUS */
3695 
3696  sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++;
3697  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender));
3698  if (channel_ctx->peer_ctx->sub == msub)
3699  {
3701  "# pull reply messages received",
3702  1,
3703  GNUNET_NO);
3704  if (NULL != map_single_hop &&
3706  &channel_ctx->peer_ctx->peer_id))
3707  {
3709  "# pull reply messages received (multi-hop peer)",
3710  1,
3711  GNUNET_NO);
3712  }
3713  }
3714 
3715  #if ENABLE_MALICIOUS
3716  // We shouldn't even receive pull replies as we're not sending
3717  if (2 == mal_type)
3718  {
3719  }
3720  #endif /* ENABLE_MALICIOUS */
3721 
3722  /* Do actual logic */
3723  peers = (const struct GNUNET_PeerIdentity *) &msg[1];
3724 
3726  "PULL REPLY received, got following %u peers:\n",
3727  ntohl (msg->num_peers));
3728 
3729  for (i = 0; i < ntohl (msg->num_peers); i++)
3730  {
3732  "%u. %s\n",
3733  i,
3734  GNUNET_i2s (&peers[i]));
3735 
3736  #if ENABLE_MALICIOUS
3737  if ((NULL != att_peer_set) &&
3738  (1 == mal_type || 3 == mal_type))
3739  { /* Add attacked peer to local list */
3740  // TODO check if we sent a request and this was the first reply
3742  &peers[i])
3744  &peers[i]))
3745  {
3746  tmp_att_peer = GNUNET_new (struct AttackedPeer);
3747  tmp_att_peer->peer_id = peers[i];
3748  GNUNET_CONTAINER_DLL_insert (att_peers_head,
3749  att_peers_tail,
3750  tmp_att_peer);
3751  add_peer_array_to_set (&peers[i], 1, att_peer_set);
3752  }
3753  continue;
3754  }
3755  #endif /* ENABLE_MALICIOUS */
3756  /* Make sure we 'know' about this peer */
3757  (void) insert_peer (channel_ctx->peer_ctx->sub,
3758  &peers[i]);
3759 
3760  if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers,
3761  &peers[i]))
3762  {
3763  CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map,
3764  &peers[i]);
3765  }
3766  else
3767  {
3768  schedule_operation (channel_ctx->peer_ctx,
3770  channel_ctx->peer_ctx->sub); /* cls */
3771  (void) issue_peer_online_check (channel_ctx->peer_ctx->sub,
3772  &peers[i]);
3773  }
3774  }
3775 
3777  sender),
3779  clean_peer (channel_ctx->peer_ctx->sub,
3780  sender);
3781 
3783  sender));
3784  GNUNET_CADET_receive_done (channel_ctx->channel);
3785 }
static int schedule_operation(struct PeerContext *peer_ctx, const PeerOp peer_op, void *cls)
Schedule a operation on given peer.
uint32_t num_rounds
Counts the executed rounds.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
uint32_t num_peers
Number of PeerIDs sent.
Definition: rps.h:53
struct PeerContext * peer_ctx
The peer context associated with the channel.
#define UNSET_PEER_FLAG(peer_ctx, mask)
Unset flag of given peer context.
static unsigned int mal_type
Type of malicious peer to test.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
#define LOG(kind,...)
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
If we are waiting for a reply from that peer (sent a pull request).
Definition: rps.h:251
static void add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, unsigned int num_peers, struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
Add all peers in peer_array to peer_map used as set.
int CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Insert peer into the custom peer map.
Context for a channel.
static void insert_in_pull_map(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #pull_map.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
struct GNUNET_CADET_Channel * channel
The channel itself.
uint32_t round_pull_req
This is pobably followed by &#39;statistical&#39; data (when we first saw it, how did we get its ID...
struct CustomPeerMap * pull_map
List to store peers received through pulls temporary.
static int issue_peer_online_check(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Try connecting to a peer to see whether it is online.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
One Sub.
static int check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, const struct GNUNET_PeerIdentity *peer)
Check whether peer is actually a peer.
static void clean_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Remove data that is not needed anymore.
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
static struct CadetPeer * peers
Operation to get peer ids.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
uint32_t pull_delays[32]
Number of pull replies with this delay measured in rounds.
struct GNUNET_CONTAINER_MultiPeerMap * map_single_hop
PeerMap to keep track of connected peers.
static int insert_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Add peer to known peers.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_channel_ctx()

static struct ChannelCtx* add_channel_ctx ( struct PeerContext peer_ctx)
static

Allocate memory for a new channel context and insert it into DLL.

Parameters
peer_ctxcontext of the according peer
Returns
The channel context

Definition at line 936 of file gnunet-service-rps.c.

References GNUNET_new, and ChannelCtx::peer_ctx.

Referenced by get_channel(), and handle_inbound_channel().

937 {
938  struct ChannelCtx *channel_ctx;
939  channel_ctx = GNUNET_new (struct ChannelCtx);
940  channel_ctx->peer_ctx = peer_ctx;
941  return channel_ctx;
942 }
struct PeerContext * peer_ctx
The peer context associated with the channel.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for a channel.
Here is the caller graph for this function:

◆ remove_channel_ctx()

static void remove_channel_ctx ( struct ChannelCtx channel_ctx)
static

Free memory and NULL pointers.

Parameters
channel_ctxThe channel context.

Definition at line 951 of file gnunet-service-rps.c.

References ChannelCtx::destruction_task, GNUNET_free, GNUNET_SCHEDULER_cancel(), PeerContext::mq, ChannelCtx::peer_ctx, PeerContext::recv_channel_ctx, and PeerContext::send_channel_ctx.

Referenced by cleanup_destroyed_channel(), and destroy_channel().

952 {
953  struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
954 
955  if (NULL != channel_ctx->destruction_task)
956  {
958  channel_ctx->destruction_task = NULL;
959  }
960 
961  GNUNET_free (channel_ctx);
962 
963  if (NULL == peer_ctx) return;
964  if (channel_ctx == peer_ctx->send_channel_ctx)
965  {
966  peer_ctx->send_channel_ctx = NULL;
967  peer_ctx->mq = NULL;
968  }
969  else if (channel_ctx == peer_ctx->recv_channel_ctx)
970  {
971  peer_ctx->recv_channel_ctx = NULL;
972  }
973 }
struct PeerContext * peer_ctx
The peer context associated with the channel.
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
Struct used to keep track of other peer&#39;s status.
struct GNUNET_MQ_Handle * mq
Message queue open to client.
struct ChannelCtx * send_channel_ctx
Channel open to client.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#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:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_channel()

struct GNUNET_CADET_Channel* get_channel ( struct PeerContext peer_ctx)

Get the channel of a peer.

If not existing, create.

Parameters
peer_ctxContext of the peer of which to get the channel
Returns
the GNUNET_CADET_Channel used to send data to peer_ctx

Definition at line 983 of file gnunet-service-rps.c.

References add_channel_ctx(), ChannelCtx::channel, cleanup_destroyed_channel(), GNUNET_assert, GNUNET_CADET_channel_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, Sub::hash, LOG, PeerContext::peer_id, PeerContext::send_channel_ctx, and PeerContext::sub.

Referenced by get_mq(), and indicate_sending_intention().

984 {
985  /* There exists a copy-paste-clone in run() */
986  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
987  GNUNET_MQ_hd_fixed_size (peer_check,
989  struct GNUNET_MessageHeader,
990  NULL),
991  GNUNET_MQ_hd_fixed_size (peer_push,
993  struct GNUNET_MessageHeader,
994  NULL),
995  GNUNET_MQ_hd_fixed_size (peer_pull_request,
997  struct GNUNET_MessageHeader,
998  NULL),
999  GNUNET_MQ_hd_var_size (peer_pull_reply,
1002  NULL),
1004  };
1005 
1006 
1007  if (NULL == peer_ctx->send_channel_ctx)
1008  {
1010  "Trying to establish channel to peer %s\n",
1011  GNUNET_i2s (&peer_ctx->peer_id));
1012  peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
1013  peer_ctx->send_channel_ctx->channel =
1015  peer_ctx->send_channel_ctx, /* context */
1016  &peer_ctx->peer_id,
1017  &peer_ctx->sub->hash,
1018  NULL, /* WindowSize handler */
1019  &cleanup_destroyed_channel, /* Disconnect handler */
1020  cadet_handlers);
1021  }
1022  GNUNET_assert (NULL != peer_ctx->send_channel_ctx);
1023  GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel);
1024  return peer_ctx->send_channel_ctx->channel;
1025 }
struct GNUNET_HashCode hash
Hash of the shared value that defines Subs.
static void cleanup_destroyed_channel(void *cls, const struct GNUNET_CADET_Channel *channel)
This is called when a channel is destroyed.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
P2P Message to send PeerIDs to other peer.
Definition: rps.h:43
#define GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE
RPS check liveliness message to check liveliness of other peer.
struct GNUNET_CADET_Handle * cadet_handle
Handler to CADET.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PUSH
RPS PUSH message to push own ID to another peer.
static struct ChannelCtx * add_channel_ctx(struct PeerContext *peer_ctx)
Allocate memory for a new channel context and insert it into DLL.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define LOG(kind,...)
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_CADET_Channel * channel
The channel itself.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST
RPS PULL REQUEST message to request the local view of another peer.
Message handler for a specific message type.
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
Definition: cadet_api.c:1070
struct ChannelCtx * send_channel_ctx
Channel open to client.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY
RPS PULL REPLY message which contains the view of the other peer.
Header for all communications.
struct Sub * sub
The Sub this context belongs to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_mq()

static struct GNUNET_MQ_Handle* get_mq ( struct PeerContext peer_ctx)
static

Get the message queue (GNUNET_MQ_Handle) of a specific peer.

If we already have a message queue open to this client, simply return it, otherways create one.

Parameters
peer_ctxContext of the peer of whicht to get the mq
Returns
the GNUNET_MQ_Handle

Definition at line 1038 of file gnunet-service-rps.c.

References get_channel(), GNUNET_CADET_get_mq(), and PeerContext::mq.

Referenced by check_peer_online(), and send_message().

1039 {
1040  if (NULL == peer_ctx->mq)
1041  {
1042  peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx));
1043  }
1044  return peer_ctx->mq;
1045 }
struct GNUNET_CADET_Channel * get_channel(struct PeerContext *peer_ctx)
Get the channel of a peer.
struct GNUNET_MQ_Handle * mq
Message queue open to client.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1121
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_pending_message()

static struct PendingMessage* insert_pending_message ( struct PeerContext peer_ctx,
struct GNUNET_MQ_Envelope ev,
const char *  type 
)
static

Add an envelope to a message passed to mq to list of pending messages.

Parameters
peer_ctxContext of the peer for which to insert the envelope
evenvelope to the message
typetype of the message to be sent
Returns
pointer to pending message

Definition at line 1056 of file gnunet-service-rps.c.

References PendingMessage::ev, GNUNET_CONTAINER_DLL_insert, GNUNET_new, PendingMessage::peer_ctx, PeerContext::pending_messages_head, PeerContext::pending_messages_tail, type, and PendingMessage::type.

Referenced by check_peer_online(), and send_message().

1059 {
1060  struct PendingMessage *pending_msg;
1061 
1062  pending_msg = GNUNET_new (struct PendingMessage);
1063  pending_msg->ev = ev;
1064  pending_msg->peer_ctx = peer_ctx;
1065  pending_msg->type = type;
1067  peer_ctx->pending_messages_tail,
1068  pending_msg);
1069  return pending_msg;
1070 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct PeerContext * peer_ctx
The corresponding context.
struct GNUNET_MQ_Envelope * ev
The envelope to the corresponding message.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * type
The message type.
List containing all messages that are yet to be send.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
struct PendingMessage * pending_messages_tail
Here is the caller graph for this function:

◆ mq_online_check_successful()

static void mq_online_check_successful ( void *  cls)
static

This is called in response to the first message we sent as a online check.

Parameters
clsPeerContext of peer with pending online check

Definition at line 1106 of file gnunet-service-rps.c.

References add_valid_peer(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, LOG, PeerContext::online_check_pending, PeerContext::peer_id, remove_pending_message(), set_peer_online(), PeerContext::sub, and Sub::valid_peers.

Referenced by check_peer_online().

1107 {
1108  struct PeerContext *peer_ctx = cls;
1109 
1110  if (NULL != peer_ctx->online_check_pending)
1111  {
1113  "Online check for peer %s was successfull\n",
1114  GNUNET_i2s (&peer_ctx->peer_id));
1116  peer_ctx->online_check_pending = NULL;
1117  set_peer_online (peer_ctx);
1118  (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1119  }
1120 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
#define LOG(kind,...)
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
Struct used to keep track of other peer&#39;s status.
static int add_valid_peer(const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Add a given peer to valid peers.
static void set_peer_online(struct PeerContext *peer_ctx)
Set the peer flag to living and call the pending operations on this peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_online()

static void check_peer_online ( struct PeerContext peer_ctx)
static

Issue a check whether peer is online.

Parameters
peer_ctxthe context of the peer

Definition at line 1128 of file gnunet-service-rps.c.

References get_mq(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, GNUNET_MQ_msg_header, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), insert_pending_message(), LOG, mq, mq_online_check_successful(), PeerContext::online_check_pending, PeerContext::peer_id, and PeerContext::sub.

Referenced by issue_peer_online_check().

1129 {
1131  "Get informed about peer %s getting online\n",
1132  GNUNET_i2s (&peer_ctx->peer_id));
1133 
1134  struct GNUNET_MQ_Handle *mq;
1135  struct GNUNET_MQ_Envelope *ev;
1136 
1138  peer_ctx->online_check_pending =
1139  insert_pending_message (peer_ctx, ev, "Check online");
1140  mq = get_mq (peer_ctx);
1143  peer_ctx);
1144  GNUNET_MQ_send (mq, ev);
1145  if (peer_ctx->sub == msub)
1146  {
1148  "# pending online checks",
1149  1,
1150  GNUNET_NO);
1151  }
1152 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE
RPS check liveliness message to check liveliness of other peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void mq_online_check_successful(void *cls)
This is called in response to the first message we sent as a online check.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
static struct PendingMessage * insert_pending_message(struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
Add an envelope to a message passed to mq to list of pending messages.
#define LOG(kind,...)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
static struct GNUNET_MQ_Handle * get_mq(struct PeerContext *peer_ctx)
Get the message queue (GNUNET_MQ_Handle) of a specific peer.
Handle to a message queue.
Definition: mq.c:85
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct Sub * sub
The Sub this context belongs to.
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_operation_scheduled()

static int check_operation_scheduled ( const struct PeerContext peer_ctx,
const PeerOp  peer_op 
)
static

Check whether function of type PeerOp was already scheduled.

The array with pending operations will probably never grow really big, so iterating over it should be ok.

Parameters
peer_ctxContext of the peer to check for the operation
peer_opthe operation (PeerOp) on the peer
Returns
GNUNET_YES if this operation is scheduled on that peer GNUNET_NO otherwise

Definition at line 1168 of file gnunet-service-rps.c.

References GNUNET_NO, GNUNET_YES, PeerContext::num_pending_ops, PeerPendingOp::op, and PeerContext::pending_ops.

Referenced by schedule_operation().

1170 {
1171  unsigned int i;
1172 
1173  for (i = 0; i < peer_ctx->num_pending_ops; i++)
1174  if (peer_op == peer_ctx->pending_ops[i].op)
1175  return GNUNET_YES;
1176  return GNUNET_NO;
1177 }
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
PeerOp op
Callback.
unsigned int num_pending_ops
Number of pending operations.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ destroy_channel()

static void destroy_channel ( struct ChannelCtx channel_ctx)
static

Callback for scheduler to destroy a channel.

Parameters
clsContext of the channel

Definition at line 1186 of file gnunet-service-rps.c.

References ChannelCtx::channel, ChannelCtx::destruction_task, GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_SCHEDULER_cancel(), and remove_channel_ctx().

Referenced by destroy_channel_cb(), destroy_sending_channel(), and handle_inbound_channel().

1187 {
1188  struct GNUNET_CADET_Channel *channel;
1189 
1190  if (NULL != channel_ctx->destruction_task)
1191  {
1193  channel_ctx->destruction_task = NULL;
1194  }
1195  GNUNET_assert (channel_ctx->channel != NULL);
1196  channel = channel_ctx->channel;
1197  channel_ctx->channel = NULL;
1198  GNUNET_CADET_channel_destroy (channel);
1199  remove_channel_ctx (channel_ctx);
1200 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Opaque handle to a channel.
Definition: cadet_api.c:80
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
struct GNUNET_CADET_Channel * channel
The channel itself.
static void remove_channel_ctx(struct ChannelCtx *channel_ctx)
Free memory and NULL pointers.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:905
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_channel_cb()

static void destroy_channel_cb ( void *  cls)
static

Destroy a cadet channel.

This satisfies the function signature of GNUNET_SCHEDULER_TaskCallback.

Parameters
cls

Definition at line 1211 of file gnunet-service-rps.c.

References destroy_channel(), and ChannelCtx::destruction_task.

Referenced by schedule_channel_destruction().

1212 {
1213  struct ChannelCtx *channel_ctx = cls;
1214 
1215  channel_ctx->destruction_task = NULL;
1216  destroy_channel (channel_ctx);
1217 }
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
Context for a channel.
static void destroy_channel(struct ChannelCtx *channel_ctx)
Callback for scheduler to destroy a channel.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_channel_destruction()

static void schedule_channel_destruction ( struct ChannelCtx channel_ctx)
static

Schedule the destruction of a channel for immediately afterwards.

In case a channel is to be destroyed from within the callback to the destruction of another channel (send channel), we cannot call GNUNET_CADET_channel_destroy directly, but need to use this scheduling construction.

Parameters
channel_ctxchannel to be destroyed.

Definition at line 1231 of file gnunet-service-rps.c.

References ChannelCtx::channel, destroy_channel_cb(), ChannelCtx::destruction_task, GNUNET_assert, and GNUNET_SCHEDULER_add_now().

Referenced by destroy_peer().

1232 {
1233  GNUNET_assert (NULL ==
1234  channel_ctx->destruction_task);
1235  GNUNET_assert (NULL !=
1236  channel_ctx->channel);
1237  channel_ctx->destruction_task =
1239  channel_ctx);
1240 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
static void destroy_channel_cb(void *cls)
Destroy a cadet channel.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct GNUNET_CADET_Channel * channel
The channel itself.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_peer()

static int destroy_peer ( struct PeerContext peer_ctx)
static

Remove peer.

  • Empties the list with pending operations
  • Empties the list with pending messages
  • Cancels potentially existing online check
  • Schedules closing of send and recv channels
  • Removes peer from peer map
Parameters
peer_ctxContext of the peer to be destroyed
Returns
GNUNET_YES if peer was removed GNUNET_NO otherwise

Definition at line 1257 of file gnunet-service-rps.c.

References GNUNET_array_grow, GNUNET_assert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_remove_all(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_YES, LOG, PeerContext::mq, PeerContext::num_pending_ops, PeerContext::online_check_pending, ChannelCtx::peer_ctx, PeerContext::peer_id, Sub::peer_map, Peers_ONLINE, Peers_TO_DESTROY, PeerContext::pending_messages_head, PeerContext::pending_ops, PeerContext::recv_channel_ctx, remove_pending_message(), schedule_channel_destruction(), PeerContext::send_channel_ctx, SET_PEER_FLAG, PeerContext::sub, PendingMessage::type, and UNSET_PEER_FLAG.

Referenced by peermap_clear_iterator(), and remove_peer().

1258 {
1259  GNUNET_assert (NULL != peer_ctx);
1260  GNUNET_assert (NULL != peer_ctx->sub->peer_map);
1261  if (GNUNET_NO ==
1263  &peer_ctx->peer_id))
1264  {
1265  return GNUNET_NO;
1266  }
1267  SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY);
1269  "Going to remove peer %s\n",
1270  GNUNET_i2s (&peer_ctx->peer_id));
1271  UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
1272 
1273  /* Clear list of pending operations */
1274  // TODO this probably leaks memory
1275  // ('only' the cls to the function. Not sure what to do with it)
1276  GNUNET_array_grow (peer_ctx->pending_ops,
1277  peer_ctx->num_pending_ops,
1278  0);
1279  /* Remove all pending messages */
1280  while (NULL != peer_ctx->pending_messages_head)
1281  {
1283  "Removing unsent %s\n",
1284  peer_ctx->pending_messages_head->type);
1285  /* Cancle pending message, too */
1286  if ( (NULL != peer_ctx->online_check_pending) &&
1287  (0 == memcmp (peer_ctx->pending_messages_head,
1288  peer_ctx->online_check_pending,
1289  sizeof (struct PendingMessage))) )
1290  {
1291  peer_ctx->online_check_pending = NULL;
1292  if (peer_ctx->sub == msub)
1293  {
1295  "# pending online checks",
1296  -1,
1297  GNUNET_NO);
1298  }
1299  }
1301  GNUNET_YES);
1302  }
1303 
1304  /* If we are still waiting for notification whether this peer is online
1305  * cancel the according task */
1306  if (NULL != peer_ctx->online_check_pending)
1307  {
1309  "Removing pending online check for peer %s\n",
1310  GNUNET_i2s (&peer_ctx->peer_id));
1311  // TODO wait until cadet sets mq->cancel_impl
1312  //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
1314  GNUNET_YES);
1315  peer_ctx->online_check_pending = NULL;
1316  }
1317 
1318  if (NULL != peer_ctx->send_channel_ctx)
1319  {
1320  /* This is possibly called from within channel destruction */
1321  peer_ctx->send_channel_ctx->peer_ctx = NULL;
1323  peer_ctx->send_channel_ctx = NULL;
1324  peer_ctx->mq = NULL;
1325  }
1326  if (NULL != peer_ctx->recv_channel_ctx)
1327  {
1328  /* This is possibly called from within channel destruction */
1329  peer_ctx->recv_channel_ctx->peer_ctx = NULL;
1331  peer_ctx->recv_channel_ctx = NULL;
1332  }
1333 
1334  if (GNUNET_YES !=
1336  &peer_ctx->peer_id))
1337  {
1339  "removing peer from peer_ctx->sub->peer_map failed\n");
1340  }
1341  if (peer_ctx->sub == msub)
1342  {
1344  "# known peers",
1346  GNUNET_NO);
1347  }
1348  GNUNET_free (peer_ctx);
1349  return GNUNET_YES;
1350 }
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
int GNUNET_CONTAINER_multipeermap_remove_all(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Remove all entries for the given key from the map.
static void schedule_channel_destruction(struct ChannelCtx *channel_ctx)
Schedule the destruction of a channel for immediately afterwards.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct PeerContext * peer_ctx
The peer context associated with the channel.
#define UNSET_PEER_FLAG(peer_ctx, mask)
Unset flag of given peer context.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
#define LOG(kind,...)
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
const char * type
The message type.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define SET_PEER_FLAG(peer_ctx, mask)
Set a peer flag of given peer context.
We set this bit when we are going to destroy the channel to this peer.
Definition: rps.h:267
unsigned int num_pending_ops
Number of pending operations.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_log(kind,...)
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
List containing all messages that are yet to be send.
struct GNUNET_MQ_Handle * mq
Message queue open to client.
struct ChannelCtx * send_channel_ctx
Channel open to client.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
We set this bit when we know the peer is online.
Definition: rps.h:260
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peermap_clear_iterator()

static int peermap_clear_iterator ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Iterator over hash map entries.

Deletes all contexts of peers.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1363 of file gnunet-service-rps.c.

References destroy_peer(), get_peer_ctx(), GNUNET_YES, and Sub::peer_map.

Referenced by peers_terminate().

1366 {
1367  struct Sub *sub = cls;
1368  (void) value;
1369 
1370  destroy_peer (get_peer_ctx (sub->peer_map, key));
1371  return GNUNET_YES;
1372 }
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static char * value
Value of the record to add/remove.
static int destroy_peer(struct PeerContext *peer_ctx)
Remove peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
One Sub.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_notify_sent_cb()

static void mq_notify_sent_cb ( void *  cls)
static

This is called once a message is sent.

Removes the pending message

Parameters
clstype of the message that was sent

Definition at line 1383 of file gnunet-service-rps.c.

References GNUNET_CONTAINER_multipeermap_contains(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, PendingMessage::peer_ctx, PeerContext::peer_id, remove_pending_message(), PeerContext::sub, and PendingMessage::type.

Referenced by send_message().

1384 {
1385  struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
1387  "%s was sent.\n",
1388  pending_msg->type);
1389  if (pending_msg->peer_ctx->sub == msub)
1390  {
1391  if (0 == strncmp ("PULL REPLY", pending_msg->type, 10))
1392  GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO);
1393  if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12))
1394  GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO);
1395  if (0 == strncmp ("PUSH", pending_msg->type, 4))
1396  GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO);
1397  if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12) &&
1398  NULL != map_single_hop &&
1400  &pending_msg->peer_ctx->peer_id))
1402  "# pull requests sent (multi-hop peer)",
1403  1,
1404  GNUNET_NO);
1405  }
1406  /* Do not cancle message */
1407  remove_pending_message (pending_msg, GNUNET_NO);
1408 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
struct PeerContext * peer_ctx
The corresponding context.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
#define LOG(kind,...)
const char * type
The message type.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
List containing all messages that are yet to be send.
struct GNUNET_CONTAINER_MultiPeerMap * map_single_hop
PeerMap to keep track of connected peers.
struct Sub * sub
The Sub this context belongs to.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_peer_presistently_iterator()

static int store_peer_presistently_iterator ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Iterator function for store_valid_peers.

Implements GNUNET_CONTAINER_PeerMapIterator. Writes single peer to disk.

Parameters
clsthe file handle to write to.
peercurrent peer
valueunused
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1426 of file gnunet-service-rps.c.

References fh, GNUNET_assert, GNUNET_DISK_file_write(), GNUNET_i2s_full(), GNUNET_snprintf(), GNUNET_YES, ret, and size.

Referenced by store_valid_peers().

1429 {
1430  const struct GNUNET_DISK_FileHandle *fh = cls;
1431  char peer_string[128];
1432  int size;
1433  ssize_t ret;
1434  (void) value;
1435 
1436  if (NULL == peer)
1437  {
1438  return GNUNET_YES;
1439  }
1440  size = GNUNET_snprintf (peer_string,
1441  sizeof (peer_string),
1442  "%s\n",
1443  GNUNET_i2s_full (peer));
1444  GNUNET_assert (53 == size);
1445  ret = GNUNET_DISK_file_write (fh,
1446  peer_string,
1447  size);
1448  GNUNET_assert (size == ret);
1449  return GNUNET_YES;
1450 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static int ret
Final status code.
Definition: gnunet-arm.c:89
static char * value
Value of the record to add/remove.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
static int fh
Handle to the unique file.
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_YES
Definition: gnunet_common.h:80
Handle used to access files (and pipes).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_valid_peers()

static void store_valid_peers ( const struct Sub sub)
static

Store the peers currently in #valid_peers to disk.

Parameters
subSub for which to store the valid peers

Definition at line 1459 of file gnunet-service-rps.c.

References fh, Sub::filename_valid_peers, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, LOG, ret, store_peer_presistently_iterator(), and Sub::valid_peers.

Referenced by peers_terminate().

1460 {
1461  struct GNUNET_DISK_FileHandle *fh;
1462  uint32_t number_written_peers;
1463  int ret;
1464 
1465  if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1466  {
1467  return;
1468  }
1469 
1471  if (GNUNET_SYSERR == ret)
1472  {
1474  "Not able to create directory for file `%s'\n",
1475  sub->filename_valid_peers);
1476  GNUNET_break (0);
1477  }
1478  else if (GNUNET_NO == ret)
1479  {
1481  "Directory for file `%s' exists but is not writable for us\n",
1482  sub->filename_valid_peers);
1483  GNUNET_break (0);
1484  }
1490  if (NULL == fh)
1491  {
1493  "Not able to write valid peers to file `%s'\n",
1494  sub->filename_valid_peers);
1495  return;
1496  }
1498  "Writing %u valid peers to disk\n",
1500  number_written_peers =
1503  fh);
1505  GNUNET_assert (number_written_peers ==
1507 }
Create file if it doesn&#39;t exist.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
static int store_peer_presistently_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for store_valid_peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG(kind,...)
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
static int fh
Handle to the unique file.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Open the file for writing.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
Handle used to access files (and pipes).
char * filename_valid_peers
Filename of the file that stores the valid peers persistently.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ s2i_full()

static const struct GNUNET_PeerIdentity* s2i_full ( const char *  string_repr)
static

Convert string representation of peer id to peer id.

Counterpart to GNUNET_i2s_full.

Parameters
string_reprThe string representation of the peer id
Returns
The peer id

Definition at line 1520 of file gnunet-service-rps.c.

References GNUNET_break, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_new, GNUNET_OK, len, LOG, peer, GNUNET_PeerIdentity::public_key, and ret.

Referenced by restore_valid_peers().

1521 {
1522  struct GNUNET_PeerIdentity *peer;
1523  size_t len;
1524  int ret;
1525 
1526  peer = GNUNET_new (struct GNUNET_PeerIdentity);
1527  len = strlen (string_repr);
1528  if (52 > len)
1529  {
1531  "Not able to convert string representation of PeerID to PeerID\n"
1532  "Sting representation: %s (len %lu) - too short\n",
1533  string_repr,
1534  len);
1535  GNUNET_break (0);
1536  }
1537  else if (52 < len)
1538  {
1539  len = 52;
1540  }
1541  ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr,
1542  len,
1543  &peer->public_key);
1544  if (GNUNET_OK != ret)
1545  {
1547  "Not able to convert string representation of PeerID to PeerID\n"
1548  "Sting representation: %s\n",
1549  string_repr);
1550  GNUNET_break (0);
1551  }
1552  return peer;
1553 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG(kind,...)
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:501
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_valid_peers()

static void restore_valid_peers ( const struct Sub sub)
static

Restore the peers on disk to #valid_peers.

Parameters
subSub for which to restore the valid peers

Definition at line 1562 of file gnunet-service-rps.c.

References add_valid_peer(), buf, fh, Sub::filename_valid_peers, GNUNET_assert, GNUNET_CONTAINER_multipeermap_size(), GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s_full(), GNUNET_malloc, GNUNET_OK, GNUNET_strndup, LOG, num_peers, peer, s2i_full(), and Sub::valid_peers.

Referenced by run().

1563 {
1564  off_t file_size;
1565  uint32_t num_peers;
1566  struct GNUNET_DISK_FileHandle *fh;
1567  char *buf;
1568  ssize_t size_read;
1569  char *iter_buf;
1570  char *str_repr;
1571  const struct GNUNET_PeerIdentity *peer;
1572 
1573  if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1574  {
1575  return;
1576  }
1577 
1579  {
1580  return;
1581  }
1585  GNUNET_assert (NULL != fh);
1587  num_peers = file_size / 53;
1588  buf = GNUNET_malloc (file_size);
1589  size_read = GNUNET_DISK_file_read (fh, buf, file_size);
1590  GNUNET_assert (size_read == file_size);
1592  "Restoring %" PRIu32 " peers from file `%s'\n",
1593  num_peers,
1594  sub->filename_valid_peers);
1595  for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1596  {
1597  str_repr = GNUNET_strndup (iter_buf, 53);
1598  peer = s2i_full (str_repr);
1599  GNUNET_free (str_repr);
1600  add_valid_peer (peer, sub->valid_peers);
1602  "Restored valid peer %s from disk\n",
1603  GNUNET_i2s_full (peer));
1604  }
1605  iter_buf = NULL;
1606  GNUNET_free (buf);
1608  "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n",
1609  num_peers,
1611  if (num_peers != GNUNET_CONTAINER_multipeermap_size (sub->valid_peers))
1612  {
1614  "Number of restored peers does not match file size. Have probably duplicates.\n");
1615  }
1618  "Restored %u valid peers from disk\n",
1620 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:669
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:881
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Nobody is allowed to do anything to the file.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define LOG(kind,...)
static const struct GNUNET_PeerIdentity * s2i_full(const char *string_repr)
Convert string representation of peer id to peer id.
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
static char buf[2048]
static int fh
Handle to the unique file.
static int add_valid_peer(const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Add a given peer to valid peers.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static unsigned int num_peers
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
The identity of the host (wraps the signing key of the peer).
int GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:208
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * filename_valid_peers
Filename of the file that stores the valid peers persistently.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peers_terminate()

static void peers_terminate ( struct Sub sub)
static

Delete storage of peers that was created with #initialise_peers ()

Parameters
subSub for which the storage is deleted

Definition at line 1629 of file gnunet-service-rps.c.

References Sub::filename_valid_peers, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_SYSERR, LOG, Sub::peer_map, peermap_clear_iterator(), store_valid_peers(), and Sub::valid_peers.

Referenced by destroy_sub().

1630 {
1631  if (GNUNET_SYSERR ==
1634  sub))
1635  {
1637  "Iteration destroying peers was aborted.\n");
1638  }
1640  sub->peer_map = NULL;
1641  store_valid_peers (sub);
1643  sub->filename_valid_peers = NULL;
1645  sub->valid_peers = NULL;
1646 }
static void store_valid_peers(const struct Sub *sub)
Store the peers currently in #valid_peers to disk.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define LOG(kind,...)
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int peermap_clear_iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
#define GNUNET_free(ptr)
Wrapper around free.
char * filename_valid_peers
Filename of the file that stores the valid peers persistently.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid_peer_iterator()

static int valid_peer_iterator ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Iterator over #valid_peers hash map entries.

Parameters
clsClosure that contains iterator function and closure
peercurrent peer id
valuevalue in the hash map - unused
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1660 of file gnunet-service-rps.c.

References PeersIteratorCls::cls, and PeersIteratorCls::iterator.

Referenced by get_valid_peers().

1663 {
1664  struct PeersIteratorCls *it_cls = cls;
1665  (void) value;
1666 
1667  return it_cls->iterator (it_cls->cls, peer);
1668 }
void * cls
Closure to iterator.
Closure to valid_peer_iterator.
static char * value
Value of the record to add/remove.
PeersIterator iterator
Iterator function.
Here is the caller graph for this function:

◆ get_valid_peers()

static int get_valid_peers ( struct GNUNET_CONTAINER_MultiPeerMap valid_peers,
PeersIterator  iterator,
void *  it_cls 
)
static

Get all currently known, valid peer ids.

Parameters
valid_peersPeer map containing the valid peers in question
iteratorfunction to call on each peer id
it_clsextra argument to iterator
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 1681 of file gnunet-service-rps.c.

References PeersIteratorCls::cls, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_new, iterator(), PeersIteratorCls::iterator, ret, and valid_peer_iterator().

Referenced by run().

1684 {
1685  struct PeersIteratorCls *cls;
1686  int ret;
1687 
1688  cls = GNUNET_new (struct PeersIteratorCls);
1689  cls->iterator = iterator;
1690  cls->cls = it_cls;
1691  ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
1693  cls);
1694  GNUNET_free (cls);
1695  return ret;
1696 }
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
void * cls
Closure to iterator.
Closure to valid_peer_iterator.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
PeersIterator iterator
Iterator function.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int valid_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator over #valid_peers hash map entries.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_peer()

static int insert_peer ( struct Sub sub,
const struct GNUNET_PeerIdentity peer 
)
static

Add peer to known peers.

This function is called on new peer_ids from 'external' sources (client seed, cadet get_peers(), ...)

Parameters
subSub with the peer map that the peer will be added to
peerthe new GNUNET_PeerIdentity
Returns
GNUNET_YES if peer was inserted GNUNET_NO otherwise

Definition at line 1712 of file gnunet-service-rps.c.

References check_peer_known(), create_peer_ctx(), GNUNET_NO, GNUNET_YES, and Sub::peer_map.

Referenced by handle_peer_pull_reply(), and issue_peer_online_check().

1714 {
1715  if (GNUNET_YES == check_peer_known (sub->peer_map, peer))
1716  {
1717  return GNUNET_NO; /* We already know this peer - nothing to do */
1718  }
1719  (void) create_peer_ctx (sub, peer);
1720  return GNUNET_YES;
1721 }
static struct PeerContext * create_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create a new PeerContext and insert it into the peer map.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_flag()

static int check_peer_flag ( const struct GNUNET_CONTAINER_MultiPeerMap peer_map,
const struct GNUNET_PeerIdentity peer,
enum Peers_PeerFlags  flags 
)
static

Check whether flags on a peer are set.

Parameters
peer_mapPeer map that is expected to contain the peer
peerthe peer to check the flag of
flagsthe flags to check
Returns
GNUNET_SYSERR if peer is not known GNUNET_YES if all given flags are set GNUNET_NO otherwise

Definition at line 1736 of file gnunet-service-rps.c.

References check_peer_flag_set, check_peer_known(), get_peer_ctx(), GNUNET_NO, and GNUNET_SYSERR.

Referenced by check_peer_pull_reply(), check_sending_channel_needed(), do_round(), insert_in_view(), issue_peer_online_check(), send_pull_request(), and send_push().

1739 {
1740  struct PeerContext *peer_ctx;
1741 
1742  if (GNUNET_NO == check_peer_known (peer_map, peer))
1743  {
1744  return GNUNET_SYSERR;
1745  }
1746  peer_ctx = get_peer_ctx (peer_map, peer);
1747  return check_peer_flag_set (peer_ctx, flags);
1748 }
#define check_peer_flag_set(peer_ctx, mask)
Get peer flag of given peer context.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
Struct used to keep track of other peer&#39;s status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ issue_peer_online_check()

static int issue_peer_online_check ( struct Sub sub,
const struct GNUNET_PeerIdentity peer 
)
static

Try connecting to a peer to see whether it is online.

If not known yet, insert into known peers

Parameters
subSub which would contain the peer
peerthe peer whose online is to be checked
Returns
GNUNET_YES if the check was issued GNUNET_NO otherwise

Definition at line 1761 of file gnunet-service-rps.c.

References check_peer_flag(), check_peer_online(), get_peer_ctx(), GNUNET_NO, GNUNET_YES, insert_peer(), PeerContext::online_check_pending, Sub::peer_map, and Peers_ONLINE.

Referenced by got_peer(), handle_peer_pull_reply(), insert_in_sampler(), insert_in_view(), and send_push().

1763 {
1764  struct PeerContext *peer_ctx;
1765 
1766  (void) insert_peer (sub, peer); // TODO even needed?
1767  peer_ctx = get_peer_ctx (sub->peer_map, peer);
1768  if ( (GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) &&
1769  (NULL == peer_ctx->online_check_pending) )
1770  {
1771  check_peer_online (peer_ctx);
1772  return GNUNET_YES;
1773  }
1774  return GNUNET_NO;
1775 }
static void check_peer_online(struct PeerContext *peer_ctx)
Issue a check whether peer is online.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
Struct used to keep track of other peer&#39;s status.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
static int insert_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Add peer to known peers.
#define GNUNET_YES
Definition: gnunet_common.h:80
static int check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
Check whether flags on a peer are set.
We set this bit when we know the peer is online.
Definition: rps.h:260
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_removable()

static int check_removable ( const struct PeerContext peer_ctx)
static

Check if peer is removable.

Check if

  • a recv channel exists
  • there are pending messages
  • there is no pending pull reply
Parameters
peer_ctxContext of the peer in question
Returns
GNUNET_YES if peer is removable GNUNET_NO if peer is NOT removable GNUNET_SYSERR if peer is not known

Definition at line 1792 of file gnunet-service-rps.c.

References check_peer_flag_set, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, PeerContext::peer_id, Sub::peer_map, Peers_PULL_REPLY_PENDING, PeerContext::pending_messages_head, PeerContext::recv_channel_ctx, and PeerContext::sub.

Referenced by clean_peer().

1793 {
1795  &peer_ctx->peer_id))
1796  {
1797  return GNUNET_SYSERR;
1798  }
1799 
1800  if ( (NULL != peer_ctx->recv_channel_ctx) ||
1801  (NULL != peer_ctx->pending_messages_head) ||
1803  {
1804  return GNUNET_NO;
1805  }
1806  return GNUNET_YES;
1807 }
#define check_peer_flag_set(peer_ctx, mask)
Get peer flag of given peer context.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
If we are waiting for a reply from that peer (sent a pull request).
Definition: rps.h:251
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_valid()

static int check_peer_valid ( const struct GNUNET_CONTAINER_MultiPeerMap valid_peers,
const struct GNUNET_PeerIdentity peer 
)
static

Check whether peer is actually a peer.

A valid peer is a peer that we know exists eg. we were connected to once.

Parameters
valid_peersPeer map that would contain the peer
peerpeer in question
Returns
GNUNET_YES if peer is valid GNUNET_NO if peer is not valid

Definition at line 1822 of file gnunet-service-rps.c.

References GNUNET_CONTAINER_multipeermap_contains().

Referenced by handle_peer_pull_reply().

1824 {
1825  return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1826 }
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ indicate_sending_intention()

static void indicate_sending_intention ( struct PeerContext peer_ctx)
static

Indicate that we want to send to the other peer.

This establishes a sending channel

Parameters
peer_ctxContext of the target peer

Definition at line 1837 of file gnunet-service-rps.c.

References check_peer_known(), get_channel(), GNUNET_assert, GNUNET_YES, PeerContext::peer_id, Sub::peer_map, and PeerContext::sub.

Referenced by insert_in_view().

1838 {
1840  &peer_ctx->peer_id));
1841  (void) get_channel (peer_ctx);
1842 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
struct GNUNET_CADET_Channel * get_channel(struct PeerContext *peer_ctx)
Get the channel of a peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_send_intention()

static int check_peer_send_intention ( const struct PeerContext peer_ctx)
static

Check whether other peer has the intention to send/opened channel towars us.

Parameters
peer_ctxContext of the peer in question
Returns
GNUNET_YES if peer has the intention to send GNUNET_NO otherwise

Definition at line 1855 of file gnunet-service-rps.c.

References GNUNET_NO, GNUNET_YES, and PeerContext::recv_channel_ctx.

Referenced by clean_peer(), and handle_inbound_channel().

1856 {
1857  if (NULL != peer_ctx->recv_channel_ctx)
1858  {
1859  return GNUNET_YES;
1860  }
1861  return GNUNET_NO;
1862 }
#define GNUNET_NO
Definition: gnunet_common.h:81
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ handle_inbound_channel()

static void* handle_inbound_channel ( void *  cls,
struct GNUNET_CADET_Channel channel,
const struct GNUNET_PeerIdentity initiator 
)
static

Handle the channel a peer opens to us.

Parameters
clsThe closure - Sub
channelThe channel the peer wants to establish
initiatorThe peer's peer ID
Returns
initial channel context for the channel (can be NULL – that's not an error)

Definition at line 1876 of file gnunet-service-rps.c.

References add_channel_ctx(), add_valid_peer(), ChannelCtx::channel, check_peer_send_intention(), create_or_get_peer_ctx(), destroy_channel(), get_peer_ctx(), GNUNET_assert, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_YES, LOG, PeerContext::peer_id, Sub::peer_map, PeerContext::recv_channel_ctx, set_peer_online(), PeerContext::sub, and Sub::valid_peers.

Referenced by new_sub().

1879 {
1880  struct PeerContext *peer_ctx;
1881  struct ChannelCtx *channel_ctx;
1882  struct Sub *sub = cls;
1883 
1885  "New channel was established to us (Peer %s).\n",
1886  GNUNET_i2s (initiator));
1887  GNUNET_assert (NULL != channel); /* according to cadet API */
1888  /* Make sure we 'know' about this peer */
1889  peer_ctx = create_or_get_peer_ctx (sub, initiator);
1890  set_peer_online (peer_ctx);
1891  (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1892  channel_ctx = add_channel_ctx (peer_ctx);
1893  channel_ctx->channel = channel;
1894  /* We only accept one incoming channel per peer */
1896  initiator)))
1897  {
1899  "Already got one receive channel. Destroying old one.\n");
1900  GNUNET_break_op (0);
1901  destroy_channel (peer_ctx->recv_channel_ctx);
1902  peer_ctx->recv_channel_ctx = channel_ctx;
1903  /* return the channel context */
1904  return channel_ctx;
1905  }
1906  peer_ctx->recv_channel_ctx = channel_ctx;
1907  return channel_ctx;
1908 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct ChannelCtx * add_channel_ctx(struct PeerContext *peer_ctx)
Allocate memory for a new channel context and insert it into DLL.
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
#define LOG(kind,...)
Context for a channel.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
struct GNUNET_CADET_Channel * channel
The channel itself.
Struct used to keep track of other peer&#39;s status.
static int add_valid_peer(const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Add a given peer to valid peers.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
One Sub.
static void set_peer_online(struct PeerContext *peer_ctx)
Set the peer flag to living and call the pending operations on this peer.
static struct PeerContext * create_or_get_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create or get a PeerContext.
static int check_peer_send_intention(const struct PeerContext *peer_ctx)
Check whether other peer has the intention to send/opened channel towars us.
static void destroy_channel(struct ChannelCtx *channel_ctx)
Callback for scheduler to destroy a channel.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_sending_channel_exists()

static int check_sending_channel_exists ( const struct PeerContext peer_ctx)
static

Check whether a sending channel towards the given peer exists.

Parameters
peer_ctxContext of the peer in question
Returns
GNUNET_YES if a sending channel towards that peer exists GNUNET_NO otherwise

Definition at line 1920 of file gnunet-service-rps.c.

References check_peer_known(), GNUNET_NO, GNUNET_YES, PeerContext::peer_id, Sub::peer_map, PeerContext::send_channel_ctx, and PeerContext::sub.

Referenced by check_sending_channel_needed().

1921 {
1922  if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1923  &peer_ctx->peer_id))
1924  { /* If no such peer exists, there is no channel */
1925  return GNUNET_NO;
1926  }
1927  if (NULL == peer_ctx->send_channel_ctx)
1928  {
1929  return GNUNET_NO;
1930  }
1931  return GNUNET_YES;
1932 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
struct ChannelCtx * send_channel_ctx
Channel open to client.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_sending_channel()

static int destroy_sending_channel ( struct PeerContext peer_ctx)
static

Destroy the send channel of a peer e.g.

stop indicating a sending intention to another peer

Parameters
peer_ctxContext to the peer
Returns
GNUNET_YES if channel was destroyed GNUNET_NO otherwise

Definition at line 1944 of file gnunet-service-rps.c.

References check_connected(), check_peer_known(), destroy_channel(), GNUNET_NO, GNUNET_YES, PeerContext::peer_id, Sub::peer_map, PeerContext::send_channel_ctx, and PeerContext::sub.

Referenced by clean_peer().

1945 {
1946  if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1947  &peer_ctx->peer_id))
1948  {
1949  return GNUNET_NO;
1950  }
1951  if (NULL != peer_ctx->send_channel_ctx)
1952  {
1953  destroy_channel (peer_ctx->send_channel_ctx);
1954  (void) check_connected (peer_ctx);
1955  return GNUNET_YES;
1956  }
1957  return GNUNET_NO;
1958 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
static int check_connected(struct PeerContext *peer_ctx)
Check whether we have a connection to this peer.
struct ChannelCtx * send_channel_ctx
Channel open to client.
static void destroy_channel(struct ChannelCtx *channel_ctx)
Callback for scheduler to destroy a channel.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_message()

static void send_message ( struct PeerContext peer_ctx,
struct GNUNET_MQ_Envelope ev,
const char *  type 
)
static

Send a message to another peer.

Keeps track about pending messages so they can be properly removed when the peer is destroyed.

Parameters
peer_ctxContext of the peer to which the message is to be sent
evenvelope of the message
typetype of the message

Definition at line 1971 of file gnunet-service-rps.c.

References get_mq(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), insert_pending_message(), mq, mq_notify_sent_cb(), and PeerContext::peer_id.

Referenced by send_pull_reply(), send_pull_request(), and send_push().

1974 {
1975  struct PendingMessage *pending_msg;
1976  struct GNUNET_MQ_Handle *mq;
1977 
1979  "Sending message to %s of type %s\n",
1980  GNUNET_i2s (&peer_ctx->peer_id),
1981  type);
1982  pending_msg = insert_pending_message (peer_ctx, ev, type);
1983  mq = get_mq (peer_ctx);
1986  pending_msg);
1987  GNUNET_MQ_send (mq, ev);
1988 }
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
static void mq_notify_sent_cb(void *cls)
This is called once a message is sent.
static struct PendingMessage * insert_pending_message(struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
Add an envelope to a message passed to mq to list of pending messages.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
static struct GNUNET_MQ_Handle * get_mq(struct PeerContext *peer_ctx)
Get the message queue (GNUNET_MQ_Handle) of a specific peer.
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
List containing all messages that are yet to be send.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_operation()

static int schedule_operation ( struct PeerContext peer_ctx,
const PeerOp  peer_op,
void *  cls 
)
static

Schedule a operation on given peer.

Avoids scheduling an operation twice.

Parameters
peer_ctxContext of the peer for which to schedule the operation
peer_opthe operation to schedule
clsClosure to peer_op
Returns
GNUNET_YES if the operation was scheduled GNUNET_NO otherwise

Definition at line 2003 of file gnunet-service-rps.c.

References check_operation_scheduled(), check_peer_known(), GNUNET_array_append, GNUNET_assert, GNUNET_NO, GNUNET_YES, PeerContext::num_pending_ops, PeerPendingOp::op, PeerPendingOp::op_cls, PeerContext::peer_id, Sub::peer_map, PeerContext::pending_ops, and PeerContext::sub.

Referenced by got_peer(), handle_peer_pull_reply(), and insert_in_view().

2006 {
2007  struct PeerPendingOp pending_op;
2008 
2010  &peer_ctx->peer_id));
2011 
2012  //TODO if ONLINE execute immediately
2013 
2014  if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op))
2015  {
2016  pending_op.op = peer_op;
2017  pending_op.op_cls = cls;
2018  GNUNET_array_append (peer_ctx->pending_ops,
2019  peer_ctx->num_pending_ops,
2020  pending_op);
2021  return GNUNET_YES;
2022  }
2023  return GNUNET_NO;
2024 }
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
static int check_operation_scheduled(const struct PeerContext *peer_ctx, const PeerOp peer_op)
Check whether function of type PeerOp was already scheduled.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
unsigned int num_pending_ops
Number of pending operations.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Sub * sub
The Sub this context belongs to.
Pending operation on peer consisting of callback and closure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_peer_list()

static void print_peer_list ( struct GNUNET_PeerIdentity list,
unsigned int  len 
)
static

Print peerlist to log.

Definition at line 2125 of file gnunet-service-rps.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), len, and LOG.

Referenced by handle_client_seed().

2127 {
2128  unsigned int i;
2129 
2131  "Printing peer list of length %u at %p:\n",
2132  len,
2133  list);
2134  for (i = 0 ; i < len ; i++)
2135  {
2137  "%u. peer: %s\n",
2138  i, GNUNET_i2s (&list[i]));
2139  }
2140 }
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rem_from_list()

static void rem_from_list ( struct GNUNET_PeerIdentity **  peer_list,
unsigned int *  list_size,
const struct GNUNET_PeerIdentity peer 
)
static

Remove peer from list.

Definition at line 2147 of file gnunet-service-rps.c.

References GNUNET_array_grow, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, insert_in_view_op(), LOG, and peer.

Referenced by do_round().

2150 {
2151  unsigned int i;
2152  struct GNUNET_PeerIdentity *tmp;
2153 
2154  tmp = *peer_list;
2155 
2157  "Removing peer %s from list at %p\n",
2158  GNUNET_i2s (peer),
2159  tmp);
2160 
2161  for ( i = 0 ; i < *list_size ; i++ )
2162  {
2163  if (0 == GNUNET_memcmp (&tmp[i], peer))
2164  {
2165  if (i < *list_size -1)
2166  { /* Not at the last entry -- shift peers left */
2167  memmove (&tmp[i], &tmp[i +1],
2168  ((*list_size) - i -1) * sizeof (struct GNUNET_PeerIdentity));
2169  }
2170  /* Remove last entry (should be now useless PeerID) */
2171  GNUNET_array_grow (tmp, *list_size, (*list_size) -1);
2172  }
2173  }
2174  *peer_list = tmp;
2175 }
#define LOG(kind,...)
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
The identity of the host (wraps the signing key of the peer).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_in_view_op()

static void insert_in_view_op ( void *  cls,
const struct GNUNET_PeerIdentity peer 
)
static

Insert PeerID in #view.

Called once we know a peer is online. Implements PeerOp

Returns
GNUNET_OK if peer was actually inserted GNUNET_NO if peer was not inserted

Called once we know a peer is online. Implements PeerOp

Parameters
clsClosure - Sub with view to insert peer into
peerthe peer to insert

Definition at line 2565 of file gnunet-service-rps.c.

References clients_notify_stream_peer(), GNUNET_OK, and insert_in_view().

Referenced by got_peer(), insert_in_view(), and rem_from_list().

2567 {
2568  struct Sub *sub = cls;
2569  int inserted;
2570 
2571  inserted = insert_in_view (sub, peer);
2572  if (GNUNET_OK == inserted)
2573  {
2574  clients_notify_stream_peer (sub, 1, peer);
2575  }
2576 }
static int insert_in_view(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void clients_notify_stream_peer(const struct Sub *sub, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
sends updates to clients that are interested
One Sub.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_in_view()

static int insert_in_view ( struct Sub sub,
const struct GNUNET_PeerIdentity peer 
)
static

Insert PeerID in #view.

Called once we know a peer is online.

Parameters
subSub in with the view to insert in
peerthe peer to insert
Returns
GNUNET_OK if peer was actually inserted GNUNET_NO if peer was not inserted

Definition at line 2203 of file gnunet-service-rps.c.

References check_peer_flag(), get_peer_ctx(), GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_SYSERR, indicate_sending_intention(), insert_in_view_op(), issue_peer_online_check(), Sub::peer_map, Peers_ONLINE, ret, schedule_operation(), PeerContext::sub, Sub::view, View_put(), and View_size().

Referenced by do_round(), hist_update(), and insert_in_view_op().

2205 {
2206  struct PeerContext *peer_ctx;
2207  int online;
2208  int ret;
2209 
2210  online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE);
2211  peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed?
2212  if ( (GNUNET_NO == online) ||
2213  (GNUNET_SYSERR == online) ) /* peer is not even known */
2214  {
2215  (void) issue_peer_online_check (sub, peer);
2216  (void) schedule_operation (peer_ctx, insert_in_view_op, sub);
2217  return GNUNET_NO;
2218  }
2219  /* Open channel towards peer to keep connection open */
2220  indicate_sending_intention (peer_ctx);
2221  ret = View_put (sub->view, peer);
2222  if (peer_ctx->sub == msub)
2223  {
2225  "view size",
2226  View_size (peer_ctx->sub->view),
2227  GNUNET_NO);
2228  }
2229  return ret;
2230 }
static int schedule_operation(struct PeerContext *peer_ctx, const PeerOp peer_op, void *cls)
Schedule a operation on given peer.
static void insert_in_view_op(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct Sub * msub
Main Sub.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static void indicate_sending_intention(struct PeerContext *peer_ctx)
Indicate that we want to send to the other peer.
int View_put(struct View *view, const struct GNUNET_PeerIdentity *peer)
Insert peer into the view.
Struct used to keep track of other peer&#39;s status.
static int issue_peer_online_check(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Try connecting to a peer to see whether it is online.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
unsigned int View_size(const struct View *view)
Get the size of the view.
struct Sub * sub
The Sub this context belongs to.
struct View * view
The view.
static int check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
Check whether flags on a peer are set.
We set this bit when we know the peer is online.
Definition: rps.h:260
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_view()

static void send_view ( const struct ClientContext cli_ctx,
const struct GNUNET_PeerIdentity view_array,
uint64_t  view_size 
)
static

Send view to client.

Parameters
cli_ctxthe context of the client
view_arraythe peerids of the view as array (can be empty)
view_sizethe size of the view array (can be 0)

Definition at line 2241 of file gnunet-service-rps.c.

References GNUNET_memcpy, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), ClientContext::mq, msub, GNUNET_RPS_CS_DEBUG_ViewReply::num_peers, ClientContext::sub, Sub::view, View_get_as_array(), and View_size().

Referenced by clients_notify_view_update(), and handle_client_view_request().

2244 {
2245  struct GNUNET_MQ_Envelope *ev;
2246  struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg;
2247  struct Sub *sub;
2248 
2249  if (NULL == view_array)
2250  {
2251  if (NULL == cli_ctx->sub) sub = msub;
2252  else sub = cli_ctx->sub;
2253  view_size = View_size (sub->view);
2254  view_array = View_get_as_array (sub->view);
2255  }
2256 
2257  ev = GNUNET_MQ_msg_extra (out_msg,
2258  view_size * sizeof (struct GNUNET_PeerIdentity),
2260  out_msg->num_peers = htonl (view_size);
2261 
2262  GNUNET_memcpy (&out_msg[1],
2263  view_array,
2264  view_size * sizeof (struct GNUNET_PeerIdentity));
2265  GNUNET_MQ_send (cli_ctx->mq, ev);
2266 }
Message from service to client containing current update of view.
Definition: rps.h:186
struct Sub * sub
The Sub this context belongs to.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
static struct Sub * msub
Main Sub.
struct GNUNET_MQ_Handle * mq
The message queue to communicate with the client.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
#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
#define GNUNET_memcpy(dst, src, n)
One Sub.
The identity of the host (wraps the signing key of the peer).
unsigned int View_size(const struct View *view)
Get the size of the view.
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 View * view
The view.
uint64_t num_peers
Number of peers in the view.
Definition: rps.h:201
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_stream_peers()

static void send_stream_peers ( const struct ClientContext cli_ctx,
uint64_t  num_peers,
const struct GNUNET_PeerIdentity peers 
)
static

Send peer from biased stream to client.

TODO merge with send_view, parameterise

Parameters
cli_ctxthe context of the client
view_arraythe peerids of the view as array (can be empty)
view_sizethe size of the view array (can be 0)

Definition at line 2279 of file gnunet-service-rps.c.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), ClientContext::mq, and GNUNET_RPS_CS_DEBUG_StreamReply::num_peers.

Referenced by clients_notify_stream_peer().

2282 {
2283  struct GNUNET_MQ_Envelope *ev;
2284  struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg;
2285 
2286  GNUNET_assert (NULL != peers);
2287 
2288  ev = GNUNET_MQ_msg_extra (out_msg,
2289  num_peers * sizeof (struct GNUNET_PeerIdentity),
2291  out_msg->num_peers = htonl (num_peers);
2292 
2293  GNUNET_memcpy (&out_msg[1],
2294  peers,
2295  num_peers * sizeof (struct GNUNET_PeerIdentity));
2296  GNUNET_MQ_send (cli_ctx->mq, ev);
2297 }
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_Handle * mq
The message queue to communicate with the client.
#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
uint64_t num_peers
Number of peers.
Definition: rps.h:230
#define GNUNET_memcpy(dst, src, n)
Message from service to client containing peer from biased stream.
Definition: rps.h:220
static unsigned int num_peers
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clients_notify_view_update()

static void clients_notify_view_update ( const struct Sub sub)
static

sends updates to clients that are interested

Parameters
subSub for which to notify clients

Definition at line 2306 of file gnunet-service-rps.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, ClientContext::next, num_peers, send_view(), Sub::view, View_get_as_array(), View_size(), and ClientContext::view_updates_left.

Referenced by do_round(), and hist_update().

2307 {
2308  struct ClientContext *cli_ctx_iter;
2309  uint64_t num_peers;
2310  const struct GNUNET_PeerIdentity *view_array;
2311 
2312  num_peers = View_size (sub->view);
2313  view_array = View_get_as_array(sub->view);
2314  /* check size of view is small enough */
2315  if (GNUNET_MAX_MESSAGE_SIZE < num_peers)
2316  {
2318  "View is too big to send\n");
2319  return;
2320  }
2321 
2322  for (cli_ctx_iter = cli_ctx_head;
2323  NULL != cli_ctx_iter;
2324  cli_ctx_iter = cli_ctx_iter->next)
2325  {
2326  if (1 < cli_ctx_iter->view_updates_left)
2327  {
2328  /* Client wants to receive limited amount of updates */
2329  cli_ctx_iter->view_updates_left -= 1;
2330  } else if (1 == cli_ctx_iter->view_updates_left)
2331  {
2332  /* Last update of view for client */
2333  cli_ctx_iter->view_updates_left = -1;
2334  } else if (0 > cli_ctx_iter->view_updates_left) {
2335  /* Client is not interested in updates */
2336  continue;
2337  }
2338  /* else _updates_left == 0 - infinite amount of updates */
2339 
2340  /* send view */
2341  send_view (cli_ctx_iter, view_array, num_peers);
2342  }
2343 }
Struct used to store the context of a connected client.
struct ClientContext * next
DLL.
static void send_view(const struct ClientContext *cli_ctx, const struct GNUNET_PeerIdentity *view_array, uint64_t view_size)
Send view to client.
int64_t view_updates_left
How many updates this client expects to receive.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
static unsigned int num_peers
#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).
#define GNUNET_log(kind,...)
unsigned int View_size(const struct View *view)
Get the size of the view.
struct ClientContext * cli_ctx_head
DLL with all clients currently connected to us.
struct View * view
The view.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clients_notify_stream_peer()

static void clients_notify_stream_peer ( const struct Sub sub,
uint64_t  num_peers,
const struct GNUNET_PeerIdentity peers 
)
static

sends updates to clients that are interested

Parameters
num_peersNumber of peers to send
peersthe array of peers to send

Definition at line 2353 of file gnunet-service-rps.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, LOG, ClientContext::next, send_stream_peers(), ClientContext::stream_update, and ClientContext::sub.

Referenced by do_round(), hist_update(), and insert_in_view_op().

2357 {
2358  struct ClientContext *cli_ctx_iter;
2359 
2361  "Got peer (%s) from biased stream - update all clients\n",
2362  GNUNET_i2s (peers));
2363 
2364  for (cli_ctx_iter = cli_ctx_head;
2365  NULL != cli_ctx_iter;
2366  cli_ctx_iter = cli_ctx_iter->next)
2367  {
2368  if (GNUNET_YES == cli_ctx_iter->stream_update &&
2369  (sub == cli_ctx_iter->sub || sub == msub))
2370  {
2371  send_stream_peers (cli_ctx_iter, num_peers, peers);
2372  }
2373  }
2374 }
Struct used to store the context of a connected client.
struct ClientContext * next
DLL.
struct Sub * sub
The Sub this context belongs to.
static struct Sub * msub
Main Sub.
int8_t stream_update
Whether this client wants to receive stream updates.
static void send_stream_peers(const struct ClientContext *cli_ctx, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Send peer from biased stream to client.
#define LOG(kind,...)
static unsigned int num_peers
struct ClientContext * cli_ctx_head
DLL with all clients currently connected to us.
#define GNUNET_YES
Definition: gnunet_common.h:80
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hist_update()

static void hist_update ( const struct GNUNET_PeerIdentity ids,
uint32_t  num_peers,
void *  cls 
)
static

Put random peer from sampler into the view as history update.

Parameters
idsArray of Peers to insert into view
num_peersNumber of peers to insert
clsClosure - The Sub for which this is to be done

Definition at line 2385 of file gnunet-service-rps.c.

References check_peer_known(), clients_notify_stream_peer(), clients_notify_view_update(), GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s_full(), GNUNET_OK, GNUNET_YES, insert_in_view(), LOG, num_peers, Sub::peer_map, and to_file.

Referenced by do_round().

2388 {
2389  unsigned int i;
2390  struct Sub *sub = cls;
2391 
2392  for (i = 0; i < num_peers; i++)
2393  {
2394  int inserted;
2395  if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i]))
2396  {
2398  "Peer in history update not known!\n");
2399  continue;
2400  }
2401  inserted = insert_in_view (sub, &ids[i]);
2402  if (GNUNET_OK == inserted)
2403  {
2404  clients_notify_stream_peer (sub, 1, &ids[i]);
2405  }
2406 #ifdef TO_FILE_FULL
2407  to_file (sub->file_name_view_log,
2408  "+%s\t(hist)",
2409  GNUNET_i2s_full (ids));
2410 #endif /* TO_FILE_FULL */