44 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 63 #define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) 68 #define check_peer_flag_set(peer_ctx, mask) \ 69 ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO) 74 #define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) 79 #define check_channel_flag_set(channel_flags, mask) \ 80 ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO) 85 #define unset_channel_flag(channel_flags, mask) ((*channel_flags) &= ~(mask)) 273 struct AttackedPeer *next;
274 struct AttackedPeer *prev;
288 #define HISTOGRAM_FILE_SLOTS 32 296 #define SIZE_DUMP_FILE (HISTOGRAM_FILE_SLOTS * 5) + 1 360 char *file_name_view_log;
368 char *file_name_observed_log;
536 static uint32_t num_mal_peers;
542 static struct AttackedPeer *att_peers_head;
543 static struct AttackedPeer *att_peers_tail;
549 static struct AttackedPeer *att_peer_index;
560 static uint32_t num_attacked_peers;
574 static uint32_t push_limit = 10000;
601 do_mal_round (
void *cls);
643 if (NULL != peer_map)
785 if (0 >= iterator_cls->
index)
790 iterator_cls->
index--;
816 ret = iterator_cls->
peer;
881 "Peer %s is online and valid, calling %i pending operations on it\n",
888 "Removing pending online check for peer %s\n",
970 if (NULL == peer_ctx)
1018 "Trying to establish channel to peer %s\n",
1048 if (NULL == peer_ctx->
mq)
1052 return peer_ctx->
mq;
1072 pending_msg->
ev =
ev;
1123 "Online check for peer %s was successfull\n",
1142 "Get informed about peer %s getting online\n",
1156 if (peer_ctx->
sub == msub)
1159 "# pending online checks",
1207 channel = channel_ctx->
channel;
1280 "Going to remove peer %s\n",
1294 "Removing unsent %s\n",
1303 if (peer_ctx->
sub == msub)
1306 "# pending online checks",
1320 "Removing pending online check for peer %s\n",
1335 peer_ctx->
mq = NULL;
1350 "removing peer from peer_ctx->sub->peer_map failed\n");
1352 if (peer_ctx->
sub == msub)
1379 struct Sub *sub = cls;
1405 if (0 == strncmp (
"PULL REPLY", pending_msg->
type, 10))
1407 if (0 == strncmp (
"PULL REQUEST", pending_msg->
type, 12))
1409 if (0 == strncmp (
"PUSH", pending_msg->
type, 4))
1411 if ((0 == strncmp (
"PULL REQUEST", pending_msg->
type, 12)) &&
1412 (NULL != map_single_hop) &&
1417 "# pull requests sent (multi-hop peer)",
1446 char peer_string[128];
1457 sizeof(peer_string),
1478 uint32_t number_written_peers;
1490 "Not able to create directory for file `%s'\n",
1497 "Directory for file `%s' exists but is not writable for us\n",
1509 "Not able to write valid peers to file `%s'\n",
1514 "Writing %u valid peers to disk\n",
1516 number_written_peers =
1543 len = strlen (string_repr);
1547 "Not able to convert string representation of PeerID to PeerID\n" 1548 "Sting representation: %s (len %lu) - too short\n",
1563 "Not able to convert string representation of PeerID to PeerID\n" 1564 "Sting representation: %s\n",
1603 num_peers = file_size / 53;
1608 "Restoring %" PRIu32
" peers from file `%s'\n",
1611 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1618 "Restored valid peer %s from disk\n",
1624 "num_peers: %" PRIu32
", _size (sub->valid_peers): %u\n",
1630 "Number of restored peers does not match file size. Have probably duplicates.\n");
1634 "Restored %u valid peers from disk\n",
1653 "Iteration destroying peers was aborted.\n");
1901 struct Sub *sub = cls;
1904 "New channel was established to us (Peer %s).\n",
1912 channel_ctx->
channel = channel;
1918 "Already got one receive channel. Destroying old one.\n");
1999 "Sending message to %s of type %s\n",
2037 pending_op.
op = peer_op;
2150 "Printing peer list of length %u at %p:\n",
2153 for (i = 0; i <
len; i++)
2167 unsigned int *list_size,
2176 "Removing peer %s from list at %p\n",
2180 for (i = 0; i < *list_size; i++)
2184 if (i < *list_size - 1)
2186 memmove (&tmp[i], &tmp[i + 1],
2241 if (peer_ctx->
sub == msub)
2268 if (NULL == view_array)
2270 if (NULL == cli_ctx->
sub)
2339 "View is too big to send\n");
2343 for (cli_ctx_iter = cli_ctx_head;
2344 NULL != cli_ctx_iter;
2345 cli_ctx_iter = cli_ctx_iter->
next)
2365 send_view (cli_ctx_iter, view_array, num_peers);
2385 "Got peer (%s) from biased stream - update all clients\n",
2388 for (cli_ctx_iter = cli_ctx_head;
2389 NULL != cli_ctx_iter;
2390 cli_ctx_iter = cli_ctx_iter->
next)
2393 ((sub == cli_ctx_iter->
sub) || (sub == msub) ))
2414 struct Sub *sub = cls;
2422 "Peer in history update not known!\n");
2431 to_file (sub->file_name_view_log,
2452 unsigned int sampler_size;
2457 if (sampler_size > new_size * 4)
2461 else if (sampler_size < new_size)
2469 #if ENABLE_MALICIOUS 2484 if (NULL == peer_map)
2487 "Trying to add peers to non-existing peermap.\n");
2519 unsigned int num_peer_ids)
2537 / sizeof(struct GNUNET_PeerIdentity);
2539 send_size = num_peer_ids;
2542 "Going to send PULL REPLY with %u peers to %s\n",
2546 send_size *
sizeof(
struct GNUNET_PeerIdentity),
2550 send_size *
sizeof(
struct GNUNET_PeerIdentity));
2553 if (peer_ctx->
sub == msub)
2576 struct Sub *sub = cls;
2595 struct Sub *sub = cls;
2617 struct Sub *sub = cls;
2620 "Updating samplers with peer %s from insert_in_sampler()\n",
2634 "# observed peers in gossip",
2645 uint32_t num_observed_unique_peers =
2648 "# unique peers in gossip",
2649 num_observed_unique_peers,
2652 to_file (sub->file_name_observed_log,
2653 "%" PRIu32
" %" PRIu32
" %f\n",
2655 num_observed_unique_peers,
2779 "Going to remove send channel to peer %s\n",
2781 #if ENABLE_MALICIOUS 2797 "Peer was removed from our knowledge during cleanup\n");
2810 "Going to remove peer %s\n",
2840 if ((NULL != peer_ctx) &&
2870 uint32_t sampler_size,
2910 "Cadet port `%s' is already in use.\n",
2920 "FILENAME_VALID_PEERS",
2925 "FILENAME_VALID_PEERS");
2929 char *tmp_filename_valid_peers;
2933 sizeof(str_hash),
"%s",
2938 tmp_filename_valid_peers,
3072 sub->file_name_view_log = NULL;
3077 sub->file_name_observed_log = NULL;
3189 if (NULL != cli_ctx->
sub)
3192 cli_ctx->
sub = NULL;
3213 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
3218 estimate = pow (estimate, 1.0 / 3);
3263 double logestimate,
double std_dev)
3270 for (cli_ctx_iter = cli_ctx_head;
3271 NULL != cli_ctx_iter;
3272 cli_ctx_iter = cli_ctx_iter->
next)
3274 if (NULL != cli_ctx_iter->
sub)
3303 "message says it sends %" PRIu32
" peers, have space for %lu peers\n",
3333 "Client seeded peers:\n");
3339 "Updating samplers with seed %" PRIu32
": %s\n",
3345 if (NULL != cli_ctx->
sub)
3364 uint64_t num_updates;
3369 "Client requested %" PRIu64
" updates of view.\n",
3394 "Client does not want to receive updates of view any more.\n");
3422 "Client requested peers from biased stream.\n");
3445 "Client canceled receiving peers from biased stream.\n");
3466 if ((NULL != cli_ctx->
sub) &&
3467 (0 != memcmp (&cli_ctx->
sub->
hash,
3472 "Already have a Sub with different share for this client. Remove old one, add new.\n");
3474 cli_ctx->
sub = NULL;
3496 if (0 != memcmp (&cli_ctx->
sub->
hash, &msg->
hash,
sizeof(
struct 3500 "Share of current sub and request differ!\n");
3503 cli_ctx->
sub = NULL;
3527 "Received CHECK_LIVE (%s)\n",
GNUNET_i2s (peer));
3531 "# pending online checks",
3561 "Received PUSH (%s)\n",
3566 if ((NULL != map_single_hop) &&
3571 "# push message received (multi-hop peer)",
3577 #if ENABLE_MALICIOUS 3578 struct AttackedPeer *tmp_att_peer;
3583 tmp_att_peer =
GNUNET_new (
struct AttackedPeer);
3584 tmp_att_peer->peer_id = *
peer;
3585 if (NULL == att_peer_set)
3593 add_peer_array_to_set (peer, 1, att_peer_set);
3638 if (peer_ctx->
sub == msub)
3641 "# pull request message received",
3644 if ((NULL != map_single_hop) &&
3649 "# pull request message received (multi-hop peer)",
3655 #if ENABLE_MALICIOUS 3701 if ((ntohs (msg->
header.
size) -
sizeof(
struct 3706 "message says it sends %" PRIu32
" peers, have space for %lu peers\n",
3720 "Received a pull reply from a peer (%s) we didn't request one from!\n",
3722 if (sender_ctx->
sub == msub)
3725 "# unrequested pull replies",
3750 #if ENABLE_MALICIOUS 3751 struct AttackedPeer *tmp_att_peer;
3760 "# pull reply messages received",
3763 if ((NULL != map_single_hop) &&
3766 peer_ctx->peer_id)) )
3769 "# pull reply messages received (multi-hop peer)",
3775 #if ENABLE_MALICIOUS 3786 "PULL REPLY received, got following %u peers:\n",
3789 for (i = 0; i < ntohl (msg->
num_peers); i++)
3796 #if ENABLE_MALICIOUS 3797 if ((NULL != att_peer_set) &&
3806 tmp_att_peer =
GNUNET_new (
struct AttackedPeer);
3807 tmp_att_peer->peer_id = peers[i];
3811 add_peer_array_to_set (&peers[i], 1, att_peer_set);
3860 unsigned int spread)
3864 unsigned int rand_delay;
3865 unsigned int max_rand_delay;
3870 "Not accepting spread of 0\n");
3880 / mean.rel_value_us * (2 / spread);
3893 "Returning FOREVER_REL\n");
3917 "Going to send PULL REQUEST to peer %s.\n",
3927 "# pull request send issued",
3930 if ((NULL != map_single_hop) &&
3935 "# pull request send issued (multi-hop peer)",
3954 "Going to send PUSH to peer %s.\n",
3962 "# push send issued",
3965 if ((NULL != map_single_hop) &&
3970 "# push send issued (multi-hop peer)",
3978 #if ENABLE_MALICIOUS 3990 check_client_act_malicious (
void *cls,
3991 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
3994 uint16_t msize = ntohs (msg->header.size);
3995 uint32_t
num_peers = ntohl (msg->num_peers);
3997 msize -=
sizeof(
struct GNUNET_RPS_CS_ActMaliciousMessage);
4002 "message says it sends %" PRIu32
" peers, have space for %lu peers\n",
4003 ntohl (msg->num_peers),
4021 handle_client_act_malicious (
void *cls,
4023 GNUNET_RPS_CS_ActMaliciousMessage *msg)
4027 uint32_t num_mal_peers_sent;
4028 uint32_t num_mal_peers_old;
4029 struct Sub *sub = cli_ctx->
sub;
4036 if (NULL == mal_peer_set)
4040 "Now acting malicious type %" PRIu32
", got %" PRIu32
" peers.\n",
4042 ntohl (msg->num_peers));
4048 num_mal_peers_sent = ntohl (msg->num_peers);
4049 num_mal_peers_old = num_mal_peers;
4052 num_mal_peers + num_mal_peers_sent);
4058 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4073 num_mal_peers_sent = ntohl (msg->num_peers) - 1;
4074 num_mal_peers_old = num_mal_peers;
4078 num_mal_peers + num_mal_peers_sent);
4079 if ((NULL != mal_peers) &&
4080 (0 != num_mal_peers) )
4087 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4094 &msg->attacked_peer,
4103 "Attacked peer is %s\n",
4139 do_mal_round (
void *cls)
4141 uint32_t num_pushes;
4144 struct AttackedPeer *tmp_att_peer;
4145 struct Sub *sub = cls;
4148 "Going to execute next round maliciously type %" PRIu32
".\n",
4157 num_attacked_peers),
4161 "Going to send %" PRIu32
" pushes\n",
4165 for (i = 0; i < num_pushes; i++)
4167 if (att_peers_tail == att_peer_index)
4168 att_peer_index = att_peers_head;
4170 att_peer_index = att_peer_index->next;
4176 tmp_att_peer = att_peer_index;
4177 for (i = 0; i < num_pushes *
alpha; i++)
4179 if (att_peers_tail == tmp_att_peer)
4180 tmp_att_peer = att_peers_head;
4182 att_peer_index = tmp_att_peer->next;
4214 "Goding to send push to attacked peer (%s)\n",
4223 num_attacked_peers),
4227 "Going to send %" PRIu32
" pushes\n",
4230 for (i = 0; i < num_pushes; i++)
4232 if (att_peers_tail == att_peer_index)
4233 att_peer_index = att_peers_head;
4235 att_peer_index = att_peer_index->next;
4241 tmp_att_peer = att_peer_index;
4242 for (i = 0; i < num_pushes *
alpha; i++)
4244 if (att_peers_tail == tmp_att_peer)
4245 tmp_att_peer = att_peers_head;
4247 att_peer_index = tmp_att_peer->next;
4258 &do_mal_round, sub);
4278 unsigned int *permut;
4279 unsigned int a_peers;
4280 unsigned int b_peers;
4281 uint32_t first_border;
4282 uint32_t second_border;
4285 struct Sub *sub = cls;
4289 "Going to execute next round.\n");
4296 to_file (sub->file_name_view_log,
4297 "___ new round ___");
4305 to_file (sub->file_name_view_log,
4313 if (0 < View_size (sub->
view))
4316 View_size (sub->
view));
4319 a_peers = ceil (
alpha * View_size (sub->
view));
4322 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4324 for (i = 0; i < a_peers; i++)
4326 peer = view_array[permut[i]];
4332 b_peers = ceil (
beta * View_size (sub->
view));
4333 first_border = a_peers;
4334 second_border = a_peers + b_peers;
4335 if (second_border > View_size (sub->
view))
4341 "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
4342 b_peers,
beta, View_size (sub->
view));
4343 for (i = first_border; i < second_border; i++)
4345 peer = view_array[permut[i]];
4368 uint32_t final_size;
4369 uint32_t peers_to_clean_size;
4372 peers_to_clean = NULL;
4373 peers_to_clean_size = 0;
4375 peers_to_clean_size,
4376 View_size (sub->
view));
4384 to_file (sub->file_name_view_log,
4390 second_border = first_border
4393 final_size = second_border
4396 "first border: %" PRIu32
", second border: %" PRIu32
", final size: %" 4405 for (i = 0; i < first_border; i++)
4419 to_file (sub->file_name_view_log,
4431 for (i = first_border; i < second_border; i++)
4450 to_file (sub->file_name_view_log,
4461 final_size - second_border,
4467 rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]);
4470 for (i = 0; i < peers_to_clean_size; i++)
4473 to_file (sub->file_name_view_log,
4498 "# rounds blocked - too many pushes, no pull replies",
4507 "# rounds blocked - no pushes, no pull replies",
4525 "Push map size too big for histogram (%u, %u)\n",
4536 "# peers in push map at end of round",
4540 "# peers in pull map at end of round",
4544 "# peers in view at end of round",
4545 View_size (sub->
view),
4548 "# expected pushes",
4552 "delta expected - received pushes",
4555 view_size_est_need),
4560 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n",
4564 View_size (sub->
view),
4572 "Updating with peer %s from push list\n",
4581 "Updating with peer %s from pull list\n",
4597 View_size (sub->
view),
4631 unsigned int n_paths,
4632 unsigned int best_path)
4635 struct Sub *sub = cls;
4644 "Got peer_id %s from cadet\n",
4666 struct Sub *sub = cls;
4671 "Got stored, valid peer %s\n",
4691 const char *err_msg)
4693 struct Sub *sub = cls;
4701 "Got peer_id %s from peerinfo\n",
4720 "RPS service is going down\n");
4723 for (client_ctx = cli_ctx_head;
4738 peerinfo_handle = NULL;
4740 if (NULL != map_single_hop)
4747 map_single_hop = NULL;
4757 cadet_handle = NULL;
4758 #if ENABLE_MALICIOUS 4759 struct AttackedPeer *tmp_att_peer;
4763 if (NULL != mal_peer_set)
4765 if (NULL != att_peer_set)
4767 while (NULL != att_peers_head)
4769 tmp_att_peer = att_peers_head;
4798 "Client connected\n");
4831 while (NULL != cli_ctx_head)
4837 "Client disconnected. Destroy its context.\n");
4856 long long unsigned int sampler_size;
4871 "STARTING SERVICE (rps) for peer [%s]\n",
4873 #if ENABLE_MALICIOUS 4875 "Malicious execution compiled in.\n");
4886 "RPS",
"ROUNDINTERVAL");
4921 strlen (hash_port_string),
4966 #
if ENABLE_MALICIOUS
4968 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS,
4969 struct GNUNET_RPS_CS_ActMaliciousMessage,
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
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.
static void store_valid_peers(const struct Sub *sub)
Store the peers currently in #valid_peers to disk.
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
#define check_peer_flag_set(peer_ctx, mask)
Get peer flag of given peer context.
struct GNUNET_CORE_Handle * core_handle
Handle to CORE.
Struct used to store the context of a connected client.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
static int schedule_operation(struct PeerContext *peer_ctx, const PeerOp peer_op, void *cls)
Schedule a operation on given peer.
Open the file for reading.
static int insert_in_view(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
static void destroy_sub(struct Sub *sub)
Write all numbers in the given array into the given file.
Create file if it doesn't exist.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START
RPS client-service message to start a sub sampler.
Handle to the peerinfo service.
Message from service to client containing current update of view.
A HELLO message is used to exchange information about transports with other peers.
uint32_t num_rounds
Counts the executed rounds.
struct ClientContext * cli_ctx_tail
struct GNUNET_HashCode hash
Hash of the shared value that defines Subs.
struct GNUNET_MessageHeader * msg
Message from client to service indicating that clients wants to get stream of biased peers...
static void handle_peer_pull_reply(void *cls, const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
Handle PULL REPLY message from another peer.
struct ClientContext * next
DLL.
void core_init(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Callback on initialisation of Core.
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.
uint64_t rel_value_us
The actual value.
static int store_peer_presistently_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for store_valid_peers.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
static void cleanup_destroyed_channel(void *cls, const struct GNUNET_CADET_Channel *channel)
This is called when a channel is destroyed.
static void insert_in_sampler(void *cls, const struct GNUNET_PeerIdentity *peer)
Update sampler with given PeerID.
struct GNUNET_MessageHeader header
Header including size and type in NBO.
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 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.
#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.
Context for the core service connection.
static void resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size)
Wrapper around RPS_sampler_resize()
uint32_t num_updates
Number of updates 0 for sending updates until cancellation.
Opaque handle to the service.
struct GNUNET_PeerIdentity * CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, uint32_t index)
Get a peer by index.
void * cls
Closure to iterator.
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Context for the info handler.
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.
void(* PeerOp)(void *cls, const struct GNUNET_PeerIdentity *peer)
Functions of this type can be used to be stored at a peer for later execution.
static void insert_in_view_op(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
static int check_operation_scheduled(const struct PeerContext *peer_ctx, const PeerOp peer_op)
Check whether function of type PeerOp was already scheduled.
Message from client to service indicating that clients wants to get updates of the view...
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
unsigned int sampler_size_est_min
This is the minimum estimate used as sampler size.
P2P Message to send PeerIDs to other peer.
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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
utilities for managing (information about) peers
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.
struct ClientContext * cli_ctx
The client handle to send the reply to.
Peer map to store peers with specialised use-cases (push_list, pull_list, view, ...)
static int destroy_sending_channel(struct PeerContext *peer_ctx)
Destroy the send channel of a peer e.g.
int(* PeersIterator)(void *cls, const struct GNUNET_PeerIdentity *peer)
Iterator over valid peers.
#define GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE
RPS check liveliness message to check liveliness of other peer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP
RPS client-service message to stop a sub sampler.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST
Request updates of the view.
The closure to get_rand_peer_iterator.
Some utils faciliating the view into the internals for the sampler needed for evaluation.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define to_file(file_name,...)
This function is used to facilitate writing important information to disk.
struct GNUNET_CADET_Handle * cadet_handle
Handler to CADET.
static void schedule_channel_destruction(struct ChannelCtx *channel_ctx)
Schedule the destruction of a channel for immediately afterwards.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
static void send_pull_request(struct PeerContext *peer_ctx)
Send single pull request.
int CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether custom peer map contains a peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Closure to valid_peer_iterator.
uint32_t num_peers
Number of PeerIDs sent.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
struct PeerContext * peer_ctx
The peer context associated with the channel.
static const struct GNUNET_PeerIdentity * get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Get a random peer from peer_map.
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
struct PeerContext * peer_ctx
The corresponding context.
unsigned int sampler_size_est_need
The size of sampler we need to be able to satisfy the Brahms protocol's need of random peers...
static void handle_peer_pull_request(void *cls, const struct GNUNET_MessageHeader *msg)
Handle PULL REQUEST request message from another peer.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
void View_change_len(struct View *view, uint32_t len)
Change length of view.
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_SamplerRequestHandle * req_handle
The handle to the request.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PUSH
RPS PUSH message to push own ID to another peer.
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.
static struct ChannelCtx * add_channel_ctx(struct PeerContext *peer_ctx)
Allocate memory for a new channel context and insert it into DLL.
struct RPS_Sampler * sampler
Sampler used for the Brahms protocol itself.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Handle client connecting to the service.
int View_contains_peer(const struct View *view, const struct GNUNET_PeerIdentity *peer)
Check whether view contains a peer.
struct Sub * sub
The Sub this context belongs to.
struct GNUNET_MQ_Envelope * ev
The envelope to the corresponding message.
Nobody is allowed to do anything to the file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
unsigned int RPS_sampler_get_size(struct RPS_Sampler *sampler)
Get the size of the sampler.
static int ret
Return value of the commandline.
struct PendingMessage * next
DLL next, prev.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
static void send_view(const struct ClientContext *cli_ctx, const struct GNUNET_PeerIdentity *view_array, uint64_t view_size)
Send view to client.
#define UNSET_PEER_FLAG(peer_ctx, mask)
Unset flag of given peer context.
static unsigned int mal_type
Portion of malicious peers.
static void check_peer_online(struct PeerContext *peer_ctx)
Issue a check whether peer is online.
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().
static char * peer_id
Option –peer.
struct ClientContext * prev
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Opaque handle to a channel.
Peers_PeerFlags
Different flags indicating the status of another peer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
example IPC messages between RPS API and GNS service
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
uint32_t id
The identifier of the request.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls)
Callback called when a client disconnected from the service.
static struct Sub * msub
Main Sub.
void CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map)
Destroy peermap.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
int64_t view_updates_left
How many updates this client expects to receive.
static void mq_online_check_successful(void *cls)
This is called in response to the first message we sent as a online check.
struct CustomPeerMap * push_map
List to store peers received through pushes temporary.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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).
static int check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
This function is called, when the client seeds peers.
static int get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, PeersIterator iterator, void *it_cls)
Get all currently known, valid peer ids.
struct GNUNET_MQ_Handle * mq
The message queue to communicate with the client.
static void mq_notify_sent_cb(void *cls)
This is called once a message is sent.
int8_t stream_update
Whether this client wants to receive stream updates.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
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.
Closure used to pass the client and the id to the callback that replies to a client's request...
static int check_removable(const struct PeerContext *peer_ctx)
Check if peer is removable.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void destroy_channel_cb(void *cls)
Destroy a cadet channel.
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.
int CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Remove peer from custom peer map.
unsigned int view_size_est_need
This is the estimate used as view size.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
struct CustomPeerMap * CustomPeerMap_create(unsigned int len)
Create an empty peermap.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
unsigned int view_size_est_min
This is the minimum estimate used as view size.
static void print_peer_list(struct GNUNET_PeerIdentity *list, unsigned int len)
Print peerlist to log.
static void indicate_sending_intention(struct PeerContext *peer_ctx)
Indicate that we want to send to the other peer.
Message from client to service with seed of peers.
uint32_t peer_flags
Flags indicating status of peer.
Closure to _get_n_rand_peers_ready_cb()
int View_put(struct View *view, const struct GNUNET_PeerIdentity *peer)
Insert peer into the view.
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
static void restore_valid_peers(const struct Sub *sub)
Restore the peers on disk to #valid_peers.
Handle to a client that is connected to a service.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
struct RPS_Sampler * RPS_sampler_init(size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
Initialise a tuple of sampler elements.
static void handle_client_view_request(void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg)
Handle RPS request from the client.
static void handle_peer_check(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a CHECK_LIVE message from another peer.
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.
uint32_t push_delta[32]
Histogram of deltas between the expected and actual number of received pushes.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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
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 GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
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.
If we are waiting for a reply from that peer (sent a pull request).
int CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Insert peer into the custom peer map.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
wrapper around the "local view"
#define GNUNET_APPLICATION_PORT_RPS
Transfer of blocks for random peer sampling.
uint64_t num_peers
Number of peers.
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incomming MQ-based channels.
static void insert_in_pull_map(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #pull_map.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL
Cancel getting updates of the view.
void * cls
Closure for mv and cb.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
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...
static char * value
Value of the record to add/remove.
static struct GNUNET_PeerIdentity * peer_ids
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
static void peers_terminate(struct Sub *sub)
Delete storage of peers that was created with #initialise_peers ()
void core_disconnects(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Callback for core.
const char * type
The message type.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
static const struct GNUNET_PeerIdentity * s2i_full(const char *string_repr)
Convert string representation of peer id to peer id.
static void adapt_sizes(struct Sub *sub, double logestimate, double std_dev)
Update sizes in sampler and view on estimate update from nse service.
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.
static struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Peermap to get the index of a given peer ID quick.
struct GNUNET_CONTAINER_MultiPeerMap * observed_unique_peers
Multipeermap (ab-) used to count unique peer_ids.
enum GNUNET_GenericReturnValue 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.
void CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map)
Clear the custom peer map.
struct GNUNET_HashCode hash
Length of the shared value represented as string.
struct GNUNET_CADET_Channel * get_channel(struct PeerContext *peer_ctx)
Get the channel of a peer.
struct Sub * new_sub(const struct GNUNET_HashCode *hash, uint32_t sampler_size, struct GNUNET_TIME_Relative round_interval)
Create a new Sub.
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
uint32_t num_observed_peers
Count the observed peers.
struct GNUNET_CADET_Channel * channel
The channel itself.
Message from client to service telling it to stop a new sub.
uint32_t round_pull_req
This is pobably followed by 'statistical' data (when we first saw it, how did we get its ID...
static void handle_peer_push(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a PUSH message from another peer.
struct CustomPeerMap * pull_map
List to store peers received through pulls temporary.
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST
RPS PULL REQUEST message to request the local view of another peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle random peer sampling clients.
struct RPS_SamplerRequestHandle * RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, uint32_t num_peers, RPS_sampler_n_rand_peers_ready_cb cb, void *cls)
Get n random peers out of the sampled peers.
struct View * View_create(uint32_t len)
Create an empty view.
Struct used to keep track of other peer's status.
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...
static int fh
Handle to the unique file.
static void rem_from_list(struct GNUNET_PeerIdentity **peer_list, unsigned int *list_size, const struct GNUNET_PeerIdentity *peer)
Remove peer from list.
Internal representation of the hash map.
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_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED
RPS CS SEED Message for the Client to seed peers into rps.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Message handler for a specific message type.
#define SET_PEER_FLAG(peer_ctx, mask)
Set a peer flag of given peer context.
int close_all_files()
Close all files that were opened with get_file_handle.
static int add_valid_peer(const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Add a given peer to valid peers.
#define GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
Maximum message size that can be sent on CADET.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
Message from service to client containing peer from biased stream.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased stream.
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Message from client to service telling it to start a new sub.
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
static int destroy_peer(struct PeerContext *peer_ctx)
Remove peer.
static struct GNUNET_MQ_Handle * get_mq(struct PeerContext *peer_ctx)
Get the message queue (GNUNET_MQ_Handle) of a specific peer.
Handle for talking with the NSE service.
struct PendingMessage * prev
This is a doubly-linked list.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
static void handle_client_view_cancel(void *cls, const struct GNUNET_MessageHeader *msg)
Handle the cancellation of the view updates.
We set this bit when we are going to destroy the channel to this peer.
unsigned int num_pending_ops
Number of pending operations.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
struct GNUNET_CADET_Port * cadet_port
Port to communicate to other peers.
static unsigned int size
Size of the "table".
struct GNUNET_SERVICE_Client * client
The client handle to send the reply to.
Open the file for writing.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Connect to the core service.
static void handle_client_stop_sub(void *cls, const struct GNUNET_RPS_CS_SubStopMessage *msg)
Destroy the Sub.
static struct GNUNET_PeerIdentity own_identity
Our own identity.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
struct GNUNET_MessageHeader header
Header including size and type in NBO.
static int check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, const struct GNUNET_PeerIdentity *peer)
Check whether peer is actually a peer.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint32_t index
The index of the peer to return.
uint32_t num_peers
Number of peers.
static unsigned int num_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_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
PeersIterator iterator
Iterator function.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint32_t push_recv[32]
This array accumulates the number of received pushes per round.
static void handle_client_start_sub(void *cls, const struct GNUNET_RPS_CS_SubStartMessage *msg)
Create and start a Sub.
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.
unsigned int CustomPeerMap_size(const struct CustomPeerMap *c_peer_map)
Get the size of the custom peer map.
static struct PeerContext * create_or_get_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create or get a PeerContext.
static int check_connected(struct PeerContext *peer_ctx)
Check whether we have a connection to this peer.
Handle to a message queue.
static void clean_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Remove data that is not needed anymore.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST
Request biased input stream.
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.
static void destroy_cli_ctx(struct ClientContext *cli_ctx)
Destroy the context for a (connected) client.
struct GNUNET_TIME_RelativeNBO round_interval
Mean interval between two rounds.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
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.
const struct GNUNET_PeerIdentity * peer
Pointer to peer to return.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
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 ReplyCls * next
DLL.
static struct CadetPeer * peers
Operation to get peer ids.
static void send_push(struct PeerContext *peer_ctx)
Send single push.
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.
static int check_peer_send_intention(const struct PeerContext *peer_ctx)
Check whether other peer has the intention to send/opened channel towars us.
struct GNUNET_MQ_Handle * mq
#define GNUNET_log(kind,...)
void * core_connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Callback for core.
Entry in list of pending tasks.
static struct GNUNET_PEERINFO_Handle * peerinfo_handle
Handler to PEERINFO.
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.
void View_destroy(struct View *view)
Destroy view.
static void handle_client_stream_cancel(void *cls, const struct GNUNET_MessageHeader *msg)
Handles the cancellation of the stream of biased peer ids.
List containing all messages that are yet to be send.
struct GNUNET_MQ_Handle * mq
Message queue open to client.
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...
struct ChannelCtx * send_channel_ctx
Channel open to client.
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.
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
struct ClientContext * cli_ctx_head
DLL with all clients currently connected to us.
int GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host's peer.
void View_clear(struct View *view)
Clear the view.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY
RPS PULL REPLY message which contains the view of the other peer.
static void send_message(struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
Send a message to another peer.
static void handle_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
Handle seed from the client.
static void destroy_channel(struct ChannelCtx *channel_ctx)
Callback for scheduler to destroy a channel.
static int insert_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Add peer to known peers.
void RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Reinitialise all previously initialised sampler elements with the given value.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static int check_sending_channel_exists(const struct PeerContext *peer_ctx)
Check whether a sending channel towards the given peer exists.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
static int valid_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator over #valid_peers hash map entries.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_SCHEDULER_Task * do_round_task
Identifier for the main task that runs periodically.
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.
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
static float beta
Percentage of total peer number in the view to send random PULLs to.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int View_remove_peer(struct View *view, const struct GNUNET_PeerIdentity *peer)
Remove peer from view.
static const uint32_t num_valid_peers_max
Maximum number of valid peers to keep.
static struct GNUNET_NSE_Handle * nse
Handler to NSE.
struct View * view
The view.
uint32_t RPS_sampler_count_id(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Counts how many Samplers currently hold a given PeerID.
static void shutdown_task(void *cls)
Task run during shutdown.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static struct GNUNET_PEERINFO_NotifyContext * peerinfo_notify_handle
Handle for cancellation of iteration over peers.
static void remove_channel_ctx(struct ChannelCtx *channel_ctx)
Free memory and NULL pointers.
struct PendingMessage * pending_messages_tail
static int check_sending_channel_needed(const struct PeerContext *peer_ctx)
Checks if there is a sending channel and if it is needed.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
uint64_t num_peers
Number of peers in the view.
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in ...
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)...
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
static void nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Function called by NSE.
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.
Handle used to access files (and pipes).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
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
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Pending operation on peer consisting of callback and closure.
Sampler with its own array of SamplerElements.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static int list
Set if we should print a list of currently running services.
static int peermap_clear_iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
We set this bit when we know the peer is online.
enum GNUNET_GenericReturnValue 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)...
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
#define GNUNET_free(ptr)
Wrapper around free.
static int valid_peers_iterator(void *cls, const struct GNUNET_PeerIdentity *peer)
Iterator function over stored, valid peers.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
char * filename_valid_peers
Filename of the file that stores the valid peers persistently.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static int get_rand_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for get_random_peer_from_peermap.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
High-quality operations are desired.
struct GNUNET_HashCode hash
Length of the shared value represented as string.