diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/rps | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/rps')
24 files changed, 7246 insertions, 7039 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index a963476cf..03b96f264 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c @@ -25,7 +25,7 @@ * for one message from each peer. */ #include "platform.h" -//#include "rps_test_lib.h" +// #include "rps_test_lib.h" #include "gnunet_util_lib.h" #include "gnunet_testbed_service.h" @@ -74,7 +74,8 @@ static unsigned int mal_type = 0; */ static struct GNUNET_TESTBED_Peer **testbed_peers; -enum STAT_TYPE { +enum STAT_TYPE +{ STAT_TYPE_ROUNDS, /* 0 */ STAT_TYPE_BLOCKS, /* 1 */ STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ @@ -110,7 +111,7 @@ enum STAT_TYPE { STAT_TYPE_MAX, /* 32 */ }; -static char* stat_type_strings[] = { +static char*stat_type_strings[] = { "# rounds", "# rounds blocked", "# rounds blocked - too many pushes", @@ -145,7 +146,8 @@ static char* stat_type_strings[] = { "view size aim", }; -struct STATcls { +struct STATcls +{ struct RPSPeer *rps_peer; enum STAT_TYPE stat_type; }; @@ -158,200 +160,214 @@ struct STATcls { * * @return corresponding enum */ -enum STAT_TYPE stat_str_2_type(const char *stat_str) +enum STAT_TYPE stat_str_2_type (const char *stat_str) { - if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) - { - return STAT_TYPE_BLOCKS_NO_PULL; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) - { - return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) - { - return STAT_TYPE_BLOCKS_MANY_PUSH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) - { - return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) - { - return STAT_TYPE_BLOCKS_NO_PUSH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_BLOCKS]))) - { - return STAT_TYPE_BLOCKS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ROUNDS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ROUNDS]))) - { - return STAT_TYPE_ROUNDS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) - { - return STAT_TYPE_ISSUED_PUSH_SEND; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) - { - return STAT_TYPE_ISSUED_PUSH_SEND_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) - { - return STAT_TYPE_ISSUED_PULL_REQ; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) - { - return STAT_TYPE_ISSUED_PULL_REQ_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], - stat_str, - strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) - { - return STAT_TYPE_ISSUED_PULL_REP; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], - stat_str, - strlen(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) - { - return STAT_TYPE_SENT_PUSH_SEND; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ], - stat_str, - strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) - { - return STAT_TYPE_SENT_PULL_REQ; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) - { - return STAT_TYPE_SENT_PULL_REQ_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REP], - stat_str, - strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) - { - return STAT_TYPE_SENT_PULL_REP; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) - { - return STAT_TYPE_RECV_PUSH_SEND; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) - { - return STAT_TYPE_RECV_PUSH_SEND_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) - { - return STAT_TYPE_RECV_PULL_REQ; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) - { - return STAT_TYPE_RECV_PULL_REQ_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) - { - return STAT_TYPE_RECV_PULL_REP; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], - stat_str, - strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) - { - return STAT_TYPE_RECV_PULL_REP_MH; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE], - stat_str, - strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE]))) - { - return STAT_TYPE_VIEW_SIZE; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_KNOWN_PEERS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) - { - return STAT_TYPE_KNOWN_PEERS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_VALID_PEERS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_VALID_PEERS]))) - { - return STAT_TYPE_VALID_PEERS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_LEARND_PEERS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_LEARND_PEERS]))) - { - return STAT_TYPE_LEARND_PEERS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], - stat_str, - strlen(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) - { - return STAT_TYPE_PENDING_ONLINE_CHECKS; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], - stat_str, - strlen(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) - { - return STAT_TYPE_UNREQUESTED_PULL_REPLIES; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], - stat_str, - strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) - { - return STAT_TYPE_PEERS_IN_PUSH_MAP; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], - stat_str, - strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) - { - return STAT_TYPE_PEERS_IN_PULL_MAP; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], - stat_str, - strlen(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) - { - return STAT_TYPE_PEERS_IN_VIEW; - } - else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], - stat_str, - strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) - { - return STAT_TYPE_VIEW_SIZE_AIM; - } + if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], + stat_str, + strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) + { + return STAT_TYPE_BLOCKS_NO_PULL; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) + { + return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) + { + return STAT_TYPE_BLOCKS_MANY_PUSH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) + { + return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], + stat_str, + strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) + { + return STAT_TYPE_BLOCKS_NO_PUSH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS], + stat_str, + strlen (stat_type_strings[STAT_TYPE_BLOCKS]))) + { + return STAT_TYPE_BLOCKS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS], + stat_str, + strlen (stat_type_strings[STAT_TYPE_ROUNDS]))) + { + return STAT_TYPE_ROUNDS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) + { + return STAT_TYPE_ISSUED_PUSH_SEND; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) + { + return STAT_TYPE_ISSUED_PUSH_SEND_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], + stat_str, + strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) + { + return STAT_TYPE_ISSUED_PULL_REQ; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) + { + return STAT_TYPE_ISSUED_PULL_REQ_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], + stat_str, + strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) + { + return STAT_TYPE_ISSUED_PULL_REP; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], + stat_str, + strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) + { + return STAT_TYPE_SENT_PUSH_SEND; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ], + stat_str, + strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) + { + return STAT_TYPE_SENT_PULL_REQ; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) + { + return STAT_TYPE_SENT_PULL_REQ_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP], + stat_str, + strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) + { + return STAT_TYPE_SENT_PULL_REP; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], + stat_str, + strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) + { + return STAT_TYPE_RECV_PUSH_SEND; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) + { + return STAT_TYPE_RECV_PUSH_SEND_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ], + stat_str, + strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) + { + return STAT_TYPE_RECV_PULL_REQ; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) + { + return STAT_TYPE_RECV_PULL_REQ_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP], + stat_str, + strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) + { + return STAT_TYPE_RECV_PULL_REP; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) + { + return STAT_TYPE_RECV_PULL_REP_MH; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE], + stat_str, + strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE]))) + { + return STAT_TYPE_VIEW_SIZE; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_KNOWN_PEERS], + stat_str, + strlen (stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) + { + return STAT_TYPE_KNOWN_PEERS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_VALID_PEERS], + stat_str, + strlen (stat_type_strings[STAT_TYPE_VALID_PEERS]))) + { + return STAT_TYPE_VALID_PEERS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_LEARND_PEERS], + stat_str, + strlen (stat_type_strings[STAT_TYPE_LEARND_PEERS]))) + { + return STAT_TYPE_LEARND_PEERS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) + { + return STAT_TYPE_PENDING_ONLINE_CHECKS; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) + { + return STAT_TYPE_UNREQUESTED_PULL_REPLIES; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) + { + return STAT_TYPE_PEERS_IN_PUSH_MAP; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], + stat_str, + strlen ( + stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) + { + return STAT_TYPE_PEERS_IN_PULL_MAP; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], + stat_str, + strlen (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) + { + return STAT_TYPE_PEERS_IN_VIEW; + } + else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], + stat_str, + strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) + { + return STAT_TYPE_VIEW_SIZE_AIM; + } return STAT_TYPE_MAX; } @@ -359,7 +375,8 @@ enum STAT_TYPE stat_str_2_type(const char *stat_str) /** * @brief Indicates whether peer should go off- or online */ -enum PEER_ONLINE_DELTA { +enum PEER_ONLINE_DELTA +{ /** * @brief Indicates peer going online */ @@ -373,7 +390,8 @@ enum PEER_ONLINE_DELTA { /** * Operation map entry */ -struct OpListEntry { +struct OpListEntry +{ /** * DLL next ptr */ @@ -415,7 +433,8 @@ static struct OpListEntry *oplist_tail; /** * A pending reply: A request was sent and the reply is pending. */ -struct PendingReply { +struct PendingReply +{ /** * DLL next,prev ptr */ @@ -437,7 +456,8 @@ struct PendingReply { /** * A pending request: A request was not made yet but is scheduled for later. */ -struct PendingRequest { +struct PendingRequest +{ /** * DLL next,prev ptr */ @@ -459,7 +479,8 @@ struct PendingRequest { /** * Information we track for each peer. */ -struct RPSPeer { +struct RPSPeer +{ /** * Index of the peer. */ @@ -483,7 +504,7 @@ struct RPSPeer { /** * A request handle to check for an request */ - //struct GNUNET_RPS_Request_Handle *req_handle; + // struct GNUNET_RPS_Request_Handle *req_handle; /** * Peer on- or offline? @@ -685,7 +706,8 @@ typedef int (*EvaluationCallback) (void); /** * @brief Do we have Churn? */ -enum OPTION_CHURN { +enum OPTION_CHURN +{ /** * @brief If we have churn this is set */ @@ -699,7 +721,8 @@ enum OPTION_CHURN { /** * @brief Is it ok to quit the test before the timeout? */ -enum OPTION_QUICK_QUIT { +enum OPTION_QUICK_QUIT +{ /** * @brief It is ok for the test to quit before the timeout triggers */ @@ -714,7 +737,8 @@ enum OPTION_QUICK_QUIT { /** * @brief Do we collect statistics at the end? */ -enum OPTION_COLLECT_STATISTICS { +enum OPTION_COLLECT_STATISTICS +{ /** * @brief We collect statistics at the end */ @@ -729,7 +753,8 @@ enum OPTION_COLLECT_STATISTICS { /** * @brief Do we collect views during run? */ -enum OPTION_COLLECT_VIEW { +enum OPTION_COLLECT_VIEW +{ /** * @brief We collect view during run */ @@ -744,7 +769,8 @@ enum OPTION_COLLECT_VIEW { /** * Structure to define a single test */ -struct SingleTestRun { +struct SingleTestRun +{ /** * Name of the test */ @@ -831,7 +857,7 @@ static int in_shutdown; * Append arguments to file */ static void -tofile_(const char *file_name, const char *line) +tofile_ (const char *file_name, const char *line) { struct GNUNET_DISK_FileHandle *f; /* char output_buffer[512]; */ @@ -839,20 +865,20 @@ tofile_(const char *file_name, const char *line) /* int size; */ size_t size2; - if (NULL == (f = GNUNET_DISK_file_open(file_name, - GNUNET_DISK_OPEN_APPEND | - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ))) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Not able to open file %s\n", - file_name); - return; - } + if (NULL == (f = GNUNET_DISK_file_open (file_name, + GNUNET_DISK_OPEN_APPEND + | GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Not able to open file %s\n", + file_name); + return; + } /* size = GNUNET_snprintf (output_buffer, sizeof (output_buffer), "%llu %s\n", @@ -866,43 +892,43 @@ tofile_(const char *file_name, const char *line) return; } */ - size = strlen(line) * sizeof(char); + size = strlen (line) * sizeof(char); - size2 = GNUNET_DISK_file_write(f, line, size); + size2 = GNUNET_DISK_file_write (f, line, size); if (size != size2) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to write to file! (Size: %lu, size2: %lu)\n", + size, + size2); + if (GNUNET_YES != GNUNET_DISK_file_close (f)) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to write to file! (Size: %lu, size2: %lu)\n", - size, - size2); - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - } - return; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); } + return; + } - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - } + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); + } } /** * This function is used to facilitate writing important information to disk */ #define tofile(file_name, ...) do { \ - char tmp_buf[512]; \ - int size; \ - size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ - if (0 > size) \ + char tmp_buf[512]; \ + int size; \ + size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ + if (0 > size) \ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ "Failed to create tmp_buf\n"); \ - else \ + else \ tofile_ (file_name, tmp_buf); \ - } while (0); +} while (0); /** @@ -929,7 +955,7 @@ tofile_(const char *file_name, const char *line) * Test the success of a single test */ static int -evaluate(void) +evaluate (void) { unsigned int i; int tmp_ok; @@ -937,16 +963,16 @@ evaluate(void) tmp_ok = 1; for (i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer [%s] received %u of %u expected peer_ids: %i\n", - i, - GNUNET_i2s(rps_peers[i].peer_id), - rps_peers[i].num_recv_ids, - rps_peers[i].num_ids_to_request, - (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); - tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer [%s] received %u of %u expected peer_ids: %i\n", + i, + GNUNET_i2s (rps_peers[i].peer_id), + rps_peers[i].num_recv_ids, + rps_peers[i].num_ids_to_request, + (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); + tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); + } return tmp_ok ? 0 : 1; } @@ -955,12 +981,12 @@ evaluate(void) * Creates an oplist entry and adds it to the oplist DLL */ static struct OpListEntry * -make_oplist_entry() +make_oplist_entry () { struct OpListEntry *entry; - entry = GNUNET_new(struct OpListEntry); - GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); + entry = GNUNET_new (struct OpListEntry); + GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); return entry; } @@ -974,15 +1000,15 @@ make_oplist_entry() * @return #GNUNET_YES if so * #GNUNET_NO otherwise */ -static int check_statistics_collect_completed_single_peer( +static int check_statistics_collect_completed_single_peer ( const struct RPSPeer *rps_peer) { if (cur_test_run.stat_collect_flags != - (cur_test_run.stat_collect_flags & - rps_peer->stat_collected_flags)) - { - return GNUNET_NO; - } + (cur_test_run.stat_collect_flags + & rps_peer->stat_collected_flags)) + { + return GNUNET_NO; + } return GNUNET_YES; } /** @@ -992,153 +1018,155 @@ static int check_statistics_collect_completed_single_peer( * @return #GNUNET_YES if so * #GNUNET_NO otherwise */ -static int check_statistics_collect_completed() +static int check_statistics_collect_completed () { uint32_t i; for (i = 0; i < num_peers; i++) - { - if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "At least Peer %" PRIu32 " did not yet receive all statistics values\n", - i); - return GNUNET_NO; - } + { + if (GNUNET_NO == check_statistics_collect_completed_single_peer ( + &rps_peers[i])) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "At least Peer %" PRIu32 + " did not yet receive all statistics values\n", + i); + return GNUNET_NO; } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "All peers received their statistics values\n"); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers received their statistics values\n"); return GNUNET_YES; } static void -rps_disconnect_adapter(void *cls, - void *op_result); +rps_disconnect_adapter (void *cls, + void *op_result); static void -cancel_pending_req(struct PendingRequest *pending_req) +cancel_pending_req (struct PendingRequest *pending_req) { struct RPSPeer *rps_peer; rps_peer = pending_req->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); rps_peer->num_pending_reqs--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling pending rps get request\n"); - GNUNET_SCHEDULER_cancel(pending_req->request_task); - GNUNET_free(pending_req); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling pending rps get request\n"); + GNUNET_SCHEDULER_cancel (pending_req->request_task); + GNUNET_free (pending_req); } static void -cancel_request(struct PendingReply *pending_rep) +cancel_request (struct PendingReply *pending_rep) { struct RPSPeer *rps_peer; rps_peer = pending_rep->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling rps get reply\n"); - GNUNET_assert(NULL != pending_rep->req_handle); - GNUNET_RPS_request_single_info_cancel(pending_rep->req_handle); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling rps get reply\n"); + GNUNET_assert (NULL != pending_rep->req_handle); + GNUNET_RPS_request_single_info_cancel (pending_rep->req_handle); pending_rep->req_handle = NULL; - GNUNET_free(pending_rep); + GNUNET_free (pending_rep); pending_rep = NULL; } void -clean_peer(unsigned peer_index) +clean_peer (unsigned peer_index) { struct PendingRequest *pending_req; while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) - { - cancel_pending_req(pending_req); - } + { + cancel_pending_req (pending_req); + } pending_req = rps_peers[peer_index].pending_req_head; - rps_disconnect_adapter(&rps_peers[peer_index], - &rps_peers[peer_index].rps_handle); + rps_disconnect_adapter (&rps_peers[peer_index], + &rps_peers[peer_index].rps_handle); for (unsigned stat_type = STAT_TYPE_ROUNDS; stat_type < STAT_TYPE_MAX; stat_type++) + { + if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) { - if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "(%u) did not yet receive stat value for `%s'\n", - rps_peers[peer_index].index, - stat_type_strings[stat_type]); - GNUNET_STATISTICS_get_cancel( - rps_peers[peer_index].h_stat_get[stat_type]); - } + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "(%u) did not yet receive stat value for `%s'\n", + rps_peers[peer_index].index, + stat_type_strings[stat_type]); + GNUNET_STATISTICS_get_cancel ( + rps_peers[peer_index].h_stat_get[stat_type]); } + } if (NULL != rps_peers[peer_index].op) - { - GNUNET_TESTBED_operation_done(rps_peers[peer_index].op); - rps_peers[peer_index].op = NULL; - } + { + GNUNET_TESTBED_operation_done (rps_peers[peer_index].op); + rps_peers[peer_index].op = NULL; + } } /** * Task run on timeout to shut everything down. */ static void -shutdown_op(void *cls) +shutdown_op (void *cls) { unsigned int i; struct OpListEntry *entry; - (void)cls; + (void) cls; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Shutdown task scheduled, going down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Shutdown task scheduled, going down.\n"); in_shutdown = GNUNET_YES; if (NULL != shutdown_task) - { - GNUNET_SCHEDULER_cancel(shutdown_task); - shutdown_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (shutdown_task); + shutdown_task = NULL; + } if (NULL != post_test_task) - { - GNUNET_SCHEDULER_cancel(post_test_task); - post_test_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (post_test_task); + post_test_task = NULL; + } if (NULL != churn_task) - { - GNUNET_SCHEDULER_cancel(churn_task); - churn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (churn_task); + churn_task = NULL; + } entry = oplist_head; while (NULL != (entry = oplist_head)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Operation still pending on shutdown (%u)\n", - entry->index); - GNUNET_TESTBED_operation_done(entry->op); - GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); - GNUNET_free(entry); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Operation still pending on shutdown (%u)\n", + entry->index); + GNUNET_TESTBED_operation_done (entry->op); + GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); + GNUNET_free (entry); + } for (i = 0; i < num_peers; i++) - { - clean_peer(i); - } - close_all_files(); + { + clean_peer (i); + } + close_all_files (); } static void -trigger_shutdown(void *cls) +trigger_shutdown (void *cls) { - (void)cls; + (void) cls; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Shutdown was triggerd by timeout, going down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Shutdown was triggerd by timeout, going down.\n"); shutdown_task = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } @@ -1146,47 +1174,48 @@ trigger_shutdown(void *cls) * Task run after #duration to collect statistics and potentially shut down. */ static void -post_test_op(void *cls) +post_test_op (void *cls) { unsigned int i; - (void)cls; + (void) cls; post_test_task = NULL; post_test = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Executing post test op.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing post test op.\n"); if (NULL != churn_task) - { - GNUNET_SCHEDULER_cancel(churn_task); - churn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (churn_task); + churn_task = NULL; + } for (i = 0; i < num_peers; i++) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing post test op. (peer %" PRIu32 ")\n", + rps_peers[i].index); + if (NULL != rps_peers[i].op) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Executing post test op. (peer %" PRIu32 ")\n", - rps_peers[i].index); - if (NULL != rps_peers[i].op) - { - GNUNET_TESTBED_operation_done(rps_peers[i].op); - rps_peers[i].op = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelled testbed operation\n"); - } - if (NULL != cur_test_run.post_test) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); - cur_test_run.post_test(&rps_peers[i]); - } + GNUNET_TESTBED_operation_done (rps_peers[i].op); + rps_peers[i].op = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelled testbed operation\n"); } - /* If we do not collect statistics, shut down directly */ - if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || - GNUNET_YES == check_statistics_collect_completed()) + if (NULL != cur_test_run.post_test) { - GNUNET_SCHEDULER_cancel(shutdown_task); - shutdown_task = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", + i); + cur_test_run.post_test (&rps_peers[i]); } + } + /* If we do not collect statistics, shut down directly */ + if ((NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics)|| + (GNUNET_YES == check_statistics_collect_completed ()) ) + { + GNUNET_SCHEDULER_cancel (shutdown_task); + shutdown_task = NULL; + GNUNET_SCHEDULER_shutdown (); + } } @@ -1194,22 +1223,22 @@ post_test_op(void *cls) * Seed peers. */ static void -seed_peers(void *cls) +seed_peers (void *cls) { struct RPSPeer *peer = cls; unsigned int amount; unsigned int i; // TODO if malicious don't seed mal peers - amount = round(.5 * num_peers); + amount = round (.5 * num_peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); for (i = 0; i < amount; i++) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", - i, - GNUNET_i2s(&rps_peer_ids[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", + i, + GNUNET_i2s (&rps_peer_ids[i])); - GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); + GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); } @@ -1217,48 +1246,48 @@ seed_peers(void *cls) * Get the id of peer i. */ void -info_cb(void *cb_cls, - struct GNUNET_TESTBED_Operation *op, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) +info_cb (void *cb_cls, + struct GNUNET_TESTBED_Operation *op, + const struct GNUNET_TESTBED_PeerInformation *pinfo, + const char *emsg) { - struct OpListEntry *entry = (struct OpListEntry *)cb_cls; + struct OpListEntry *entry = (struct OpListEntry *) cb_cls; - (void)op; + (void) op; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - if (NULL == pinfo || NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); - GNUNET_TESTBED_operation_done(entry->op); - return; - } + if ((NULL == pinfo)||(NULL != emsg)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); + GNUNET_TESTBED_operation_done (entry->op); + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u is %s\n", - entry->index, - GNUNET_i2s(pinfo->result.id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u is %s\n", + entry->index, + GNUNET_i2s (pinfo->result.id)); rps_peer_ids[entry->index] = *(pinfo->result.id); rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put(peer_map, - &rps_peer_ids[entry->index], - &rps_peers[entry->index], - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - tofile("/tmp/rps/peer_ids", - "%u\t%s\n", - entry->index, - GNUNET_i2s_full(&rps_peer_ids[entry->index])); - - GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); - GNUNET_TESTBED_operation_done(entry->op); - GNUNET_free(entry); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put (peer_map, + &rps_peer_ids[entry->index], + &rps_peers[entry->index], + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + tofile ("/tmp/rps/peer_ids", + "%u\t%s\n", + entry->index, + GNUNET_i2s_full (&rps_peer_ids[entry->index])); + + GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); + GNUNET_TESTBED_operation_done (entry->op); + GNUNET_free (entry); } @@ -1272,39 +1301,39 @@ info_cb(void *cb_cls, * operation has executed successfully. */ static void -rps_connect_complete_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +rps_connect_complete_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct RPSPeer *rps_peer = cls; struct GNUNET_RPS_Handle *rps = ca_result; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } rps_peer->rps_handle = rps; rps_peer->online = GNUNET_YES; num_peers_online++; - GNUNET_assert(op == rps_peer->op); + GNUNET_assert (op == rps_peer->op); if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to RPS service: %s\n", - emsg); - ok = 1; - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to RPS service: %s\n", + emsg); + ok = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Started client successfully (%u)\n", - rps_peer->index); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Started client successfully (%u)\n", + rps_peer->index); - cur_test_run.main_test(rps_peer); + cur_test_run.main_test (rps_peer); } @@ -1319,15 +1348,15 @@ rps_connect_complete_cb(void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -rps_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +rps_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_RPS_Handle *h; - h = GNUNET_RPS_connect(cfg); + h = GNUNET_RPS_connect (cfg); if (NULL != cur_test_run.pre_test) - cur_test_run.pre_test(cls, h); + cur_test_run.pre_test (cls, h); return h; } @@ -1342,12 +1371,12 @@ rps_connect_adapter(void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -stat_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +stat_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct RPSPeer *peer = cls; - peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); + peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); return peer->stats_h; } @@ -1358,17 +1387,17 @@ stat_connect_adapter(void *cls, * @param op_result service handle returned from the connect adapter */ static void -stat_disconnect_adapter(void *cls, void *op_result) +stat_disconnect_adapter (void *cls, void *op_result) { struct RPSPeer *peer = cls; - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel // (peer->stats_h, "core", "# peers connected", // stat_iterator, peer)); - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel // (peer->stats_h, "nse", "# peers connected", // stat_iterator, peer)); - GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); + GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); peer->stats_h = NULL; } @@ -1383,26 +1412,26 @@ stat_disconnect_adapter(void *cls, void *op_result) * operation has executed successfully. */ static void -stat_complete_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +stat_complete_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { - //struct GNUNET_STATISTICS_Handle *sh = ca_result; - //struct RPSPeer *peer = (struct RPSPeer *) cls; - (void)cls; - (void)op; - (void)ca_result; + // struct GNUNET_STATISTICS_Handle *sh = ca_result; + // struct RPSPeer *peer = (struct RPSPeer *) cls; + (void) cls; + (void) op; + (void) ca_result; if (NULL != emsg) - { - GNUNET_break(0); - return; - } - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch + { + GNUNET_break (0); + return; + } + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch // (sh, "core", "# peers connected", // stat_iterator, peer)); - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch // (sh, "nse", "# peers connected", // stat_iterator, peer)); } @@ -1416,31 +1445,31 @@ stat_complete_cb(void *cls, * @param op_result service handle returned from the connect adapter */ static void -rps_disconnect_adapter(void *cls, - void *op_result) +rps_disconnect_adapter (void *cls, + void *op_result) { struct RPSPeer *peer = cls; struct GNUNET_RPS_Handle *h = op_result; struct PendingReply *pending_rep; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "disconnect_adapter (%u)\n", - peer->index); - GNUNET_assert(NULL != peer); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "disconnect_adapter (%u)\n", + peer->index); + GNUNET_assert (NULL != peer); if (NULL != peer->rps_handle) + { + while (NULL != (pending_rep = peer->pending_rep_head)) + { + cancel_request (pending_rep); + } + GNUNET_assert (h == peer->rps_handle); + if (NULL != h) { - while (NULL != (pending_rep = peer->pending_rep_head)) - { - cancel_request(pending_rep); - } - GNUNET_assert(h == peer->rps_handle); - if (NULL != h) - { - GNUNET_RPS_disconnect(h); - h = NULL; - } - peer->rps_handle = NULL; + GNUNET_RPS_disconnect (h); + h = NULL; } + peer->rps_handle = NULL; + } } @@ -1456,88 +1485,88 @@ rps_disconnect_adapter(void *cls, * @param recv_peers the received peers */ static void -default_reply_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +default_reply_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { struct RPSPeer *rps_peer; - struct PendingReply *pending_rep = (struct PendingReply *)cls; + struct PendingReply *pending_rep = (struct PendingReply *) cls; unsigned int i; rps_peer = pending_rep->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "[%s] got %" PRIu64 " peers:\n", - GNUNET_i2s(rps_peer->peer_id), - n); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "[%s] got %" PRIu64 " peers:\n", + GNUNET_i2s (rps_peer->peer_id), + n); for (i = 0; i < n; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u: %s\n", - i, - GNUNET_i2s(&recv_peers[i])); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u: %s\n", + i, + GNUNET_i2s (&recv_peers[i])); - rps_peer->num_recv_ids++; - } + rps_peer->num_recv_ids++; + } if (GNUNET_YES != post_test) return; if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return; - if (0 == evaluate()) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Test succeeded before end of duration\n"); - if (NULL != post_test_task) - GNUNET_SCHEDULER_cancel(post_test_task); - post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); - GNUNET_assert(NULL != post_test_task); - } + if (0 == evaluate ()) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test succeeded before end of duration\n"); + if (NULL != post_test_task) + GNUNET_SCHEDULER_cancel (post_test_task); + post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); + GNUNET_assert (NULL != post_test_task); + } } static void -profiler_reply_handle_info(void *cls, - const struct GNUNET_PeerIdentity *recv_peer, - double probability, - uint32_t num_observed); +profiler_reply_handle_info (void *cls, + const struct GNUNET_PeerIdentity *recv_peer, + double probability, + uint32_t num_observed); /** * Request random peers. */ static void -request_peers(void *cls) +request_peers (void *cls) { struct PendingRequest *pending_req = cls; struct RPSPeer *rps_peer; struct PendingReply *pending_rep; rps_peer = pending_req->rps_peer; - GNUNET_assert(1 <= rps_peer->num_pending_reqs); - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); + GNUNET_assert (1 <= rps_peer->num_pending_reqs); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); rps_peer->num_pending_reqs--; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) return; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting one peer\n"); - pending_rep = GNUNET_new(struct PendingReply); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting one peer\n"); + pending_rep = GNUNET_new (struct PendingReply); pending_rep->rps_peer = rps_peer; - //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, + // pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, // 1, // cur_test_run.reply_handle, // pending_rep); - pending_rep->req_handle = GNUNET_RPS_request_peer_info(rps_peer->rps_handle, - profiler_reply_handle_info, - pending_rep); - GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + pending_rep->req_handle = GNUNET_RPS_request_peer_info (rps_peer->rps_handle, + profiler_reply_handle_info, + pending_rep); + GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps++; } @@ -1547,45 +1576,45 @@ request_peers(void *cls) * issued, nor replied */ void -schedule_missing_requests(struct RPSPeer *rps_peer) +schedule_missing_requests (struct RPSPeer *rps_peer) { unsigned int i; struct PendingRequest *pending_req; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling %u - %u missing requests\n", - rps_peer->num_ids_to_request, - rps_peer->num_pending_reqs + rps_peer->num_pending_reps); - GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= - rps_peer->num_ids_to_request); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling %u - %u missing requests\n", + rps_peer->num_ids_to_request, + rps_peer->num_pending_reqs + rps_peer->num_pending_reps); + GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= + rps_peer->num_ids_to_request); for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; i < rps_peer->num_ids_to_request; i++) - { - pending_req = GNUNET_new(struct PendingRequest); - pending_req->rps_peer = rps_peer; - pending_req->request_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - cur_test_run.request_interval * i), - request_peers, - pending_req); - GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); - rps_peer->num_pending_reqs++; - } + { + pending_req = GNUNET_new (struct PendingRequest); + pending_req->rps_peer = rps_peer; + pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + cur_test_run.request_interval * i), + request_peers, + pending_req); + GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); + rps_peer->num_pending_reqs++; + } } void -cancel_pending_req_rep(struct RPSPeer *rps_peer) +cancel_pending_req_rep (struct RPSPeer *rps_peer) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling all (pending) requests.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling all (pending) requests.\n"); while (NULL != rps_peer->pending_req_head) - cancel_pending_req(rps_peer->pending_req_head); - GNUNET_assert(0 == rps_peer->num_pending_reqs); + cancel_pending_req (rps_peer->pending_req_head); + GNUNET_assert (0 == rps_peer->num_pending_reqs); while (NULL != rps_peer->pending_rep_head) - cancel_request(rps_peer->pending_rep_head); - GNUNET_assert(0 == rps_peer->num_pending_reps); + cancel_request (rps_peer->pending_rep_head); + GNUNET_assert (0 == rps_peer->num_pending_reps); } /*********************************** @@ -1595,9 +1624,9 @@ cancel_pending_req_rep(struct RPSPeer *rps_peer) /** * Initialise only non-mal RPSPeers */ -static void mal_init_peer(struct RPSPeer *rps_peer) +static void mal_init_peer (struct RPSPeer *rps_peer) { - if (rps_peer->index >= round(portion * num_peers)) + if (rps_peer->index >= round (portion * num_peers)) rps_peer->num_ids_to_request = 1; } @@ -1611,51 +1640,53 @@ static void mal_init_peer(struct RPSPeer *rps_peer) * @param h the handle to the service */ static void -mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) +mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) { #if ENABLE_MALICIOUS uint32_t num_mal_peers; - GNUNET_assert((1 >= portion) && - (0 < portion)); - num_mal_peers = round(portion * num_peers); + GNUNET_assert ((1 >= portion) && + (0 < portion)); + num_mal_peers = round (portion * num_peers); if (rps_peer->index < num_mal_peers) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", - rps_peer->index, - GNUNET_i2s(rps_peer->peer_id), - num_mal_peers); - - GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, - rps_peer_ids, target_peer); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer [%s] of %" PRIu32 + " malicious peers turning malicious\n", + rps_peer->index, + GNUNET_i2s (rps_peer->peer_id), + num_mal_peers); + + GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, + rps_peer_ids, target_peer); + } #endif /* ENABLE_MALICIOUS */ } static void -mal_cb(struct RPSPeer *rps_peer) +mal_cb (struct RPSPeer *rps_peer) { uint32_t num_mal_peers; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } #if ENABLE_MALICIOUS - GNUNET_assert((1 >= portion) && - (0 < portion)); - num_mal_peers = round(portion * num_peers); + GNUNET_assert ((1 >= portion) && + (0 < portion)); + num_mal_peers = round (portion * num_peers); if (rps_peer->index >= num_mal_peers) - { /* It's useless to ask a malicious peer about a random sample - + { /* It's useless to ask a malicious peer about a random sample - it's not sampling */ - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), - seed_peers, rps_peer); - schedule_missing_requests(rps_peer); - } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, 2), + seed_peers, rps_peer); + schedule_missing_requests (rps_peer); + } #endif /* ENABLE_MALICIOUS */ } @@ -1664,7 +1695,7 @@ mal_cb(struct RPSPeer *rps_peer) ***********************************/ static void -churn(void *cls); +churn (void *cls); /** * @brief Starts churn @@ -1678,30 +1709,30 @@ churn(void *cls); * @param rps_peer The peer it's called for */ static void -churn_test_cb(struct RPSPeer *rps_peer) +churn_test_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } /* Start churn */ - if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting churn task\n"); - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - churn, - NULL); - } + if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting churn task\n"); + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + churn, + NULL); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Not starting churn task\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Not starting churn task\n"); + } - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /*********************************** @@ -1716,83 +1747,84 @@ churn_test_cb(struct RPSPeer *rps_peer) * @param emsg NULL on success; otherwise an error description */ static void -churn_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +churn_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { // FIXME struct OpListEntry *entry = cls; - (void)op; + (void) op; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - GNUNET_TESTBED_operation_done(entry->op); + GNUNET_TESTBED_operation_done (entry->op); if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_assert(0 != entry->delta); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to start/stop RPS at a peer\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (0 != entry->delta); num_peers_online += entry->delta; if (PEER_GO_OFFLINE == entry->delta) - { /* Peer hopefully just went offline */ - if (GNUNET_YES != rps_peers[entry->index].online) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "peer %s was expected to go offline but is still marked as online\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - GNUNET_break(0); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "peer %s probably went offline as expected\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - } - rps_peers[entry->index].online = GNUNET_NO; + { /* Peer hopefully just went offline */ + if (GNUNET_YES != rps_peers[entry->index].online) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "peer %s was expected to go offline but is still marked as online\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + GNUNET_break (0); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "peer %s probably went offline as expected\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); } + rps_peers[entry->index].online = GNUNET_NO; + } else if (PEER_GO_ONLINE < entry->delta) - { /* Peer hopefully just went online */ - if (GNUNET_NO != rps_peers[entry->index].online) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "peer %s was expected to go online but is still marked as offline\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - GNUNET_break(0); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "peer %s probably went online as expected\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - if (NULL != cur_test_run.pre_test) - { - cur_test_run.pre_test(&rps_peers[entry->index], - rps_peers[entry->index].rps_handle); - schedule_missing_requests(&rps_peers[entry->index]); - } - } - rps_peers[entry->index].online = GNUNET_YES; - } + { /* Peer hopefully just went online */ + if (GNUNET_NO != rps_peers[entry->index].online) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "peer %s was expected to go online but is still marked as offline\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + GNUNET_break (0); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "peer %s probably went online as expected\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + if (NULL != cur_test_run.pre_test) + { + cur_test_run.pre_test (&rps_peers[entry->index], + rps_peers[entry->index].rps_handle); + schedule_missing_requests (&rps_peers[entry->index]); + } + } + rps_peers[entry->index].online = GNUNET_YES; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Invalid value for delta: %i\n", entry->delta); - GNUNET_break(0); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid value for delta: %i\n", entry->delta); + GNUNET_break (0); + } - GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); + GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); rps_peers[entry->index].entry_op_manage = NULL; - GNUNET_free(entry); - //if (num_peers_in_round[current_round] == peers_running) + GNUNET_free (entry); + // if (num_peers_in_round[current_round] == peers_running) // run_round (); } @@ -1805,52 +1837,53 @@ churn_cb(void *cls, * @param prob_go_on_off the probability of the action */ static void -manage_service_wrapper(unsigned int i, unsigned int j, - enum PEER_ONLINE_DELTA delta, - double prob_go_on_off) +manage_service_wrapper (unsigned int i, unsigned int j, + enum PEER_ONLINE_DELTA delta, + double prob_go_on_off) { struct OpListEntry *entry = NULL; uint32_t prob; /* make sure that management operation is not already scheduled */ if (NULL != rps_peers[j].entry_op_manage) - { - return; - } + { + return; + } - prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. selected peer (%u: %s) is %s.\n", - i, - j, - GNUNET_i2s(rps_peers[j].peer_id), - (PEER_GO_ONLINE == delta) ? "online" : "offline"); + prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. selected peer (%u: %s) is %s.\n", + i, + j, + GNUNET_i2s (rps_peers[j].peer_id), + (PEER_GO_ONLINE == delta) ? "online" : "offline"); if (prob < prob_go_on_off * UINT32_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s goes %s\n", - GNUNET_i2s(rps_peers[j].peer_id), - (PEER_GO_OFFLINE == delta) ? "offline" : "online"); - - if (PEER_GO_OFFLINE == delta) - cancel_pending_req_rep(&rps_peers[j]); - entry = make_oplist_entry(); - entry->delta = delta; - entry->index = j; - entry->op = GNUNET_TESTBED_peer_manage_service(NULL, - testbed_peers[j], - "rps", - &churn_cb, - entry, - (PEER_GO_OFFLINE == delta) ? 0 : 1); - rps_peers[j].entry_op_manage = entry; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s goes %s\n", + GNUNET_i2s (rps_peers[j].peer_id), + (PEER_GO_OFFLINE == delta) ? "offline" : "online"); + + if (PEER_GO_OFFLINE == delta) + cancel_pending_req_rep (&rps_peers[j]); + entry = make_oplist_entry (); + entry->delta = delta; + entry->index = j; + entry->op = GNUNET_TESTBED_peer_manage_service (NULL, + testbed_peers[j], + "rps", + &churn_cb, + entry, + (PEER_GO_OFFLINE == delta) ? + 0 : 1); + rps_peers[j].entry_op_manage = entry; + } } static void -churn(void *cls) +churn (void *cls) { unsigned int i; unsigned int j; @@ -1860,61 +1893,61 @@ churn(void *cls) double portion_go_online; double portion_go_offline; - (void)cls; + (void) cls; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Churn function executing\n"); + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Churn function executing\n"); churn_task = NULL; /* Should be invalid by now */ /* Compute the probability for an online peer to go offline * this round */ portion_online = num_peers_online * 1.0 / num_peers; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion online: %f\n", - portion_online); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion online: %f\n", + portion_online); portion_go_online = ((1 - portion_online) * .5 * .66); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion that should go online: %f\n", - portion_go_online); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion that should go online: %f\n", + portion_go_online); portion_go_offline = (portion_online + portion_go_online) - .75; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion that probably goes offline: %f\n", - portion_go_offline); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion that probably goes offline: %f\n", + portion_go_offline); prob_go_offline = portion_go_offline / (portion_online * .5); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Probability of a selected online peer to go offline: %f\n", - prob_go_offline); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Probability of a selected online peer to go offline: %f\n", + prob_go_offline); - permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, - (unsigned int)num_peers); + permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, + (unsigned int) num_peers); /* Go over 50% randomly chosen peers */ for (i = 0; i < .5 * num_peers; i++) + { + j = permut[i]; + + /* If online, shut down with certain probability */ + if (GNUNET_YES == rps_peers[j].online) { - j = permut[i]; - - /* If online, shut down with certain probability */ - if (GNUNET_YES == rps_peers[j].online) - { - manage_service_wrapper(i, j, -1, prob_go_offline); - } - - /* If offline, restart with certain probability */ - else if (GNUNET_NO == rps_peers[j].online) - { - manage_service_wrapper(i, j, 1, 0.66); - } + manage_service_wrapper (i, j, -1, prob_go_offline); } - GNUNET_free(permut); + /* If offline, restart with certain probability */ + else if (GNUNET_NO == rps_peers[j].online) + { + manage_service_wrapper (i, j, 1, 0.66); + } + } - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), + GNUNET_free (permut); + + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), churn, NULL); } @@ -1923,11 +1956,11 @@ churn(void *cls) /** * Initialise given RPSPeer */ -static void profiler_init_peer(struct RPSPeer *rps_peer) +static void profiler_init_peer (struct RPSPeer *rps_peer) { rps_peer->num_ids_to_request = cur_test_run.num_requests; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", - rps_peer->num_ids_to_request); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", + rps_peer->num_ids_to_request); } @@ -1939,9 +1972,9 @@ static void profiler_init_peer(struct RPSPeer *rps_peer) * @param recv_peers the received peers */ static void -profiler_reply_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +profiler_reply_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { struct RPSPeer *rps_peer; struct RPSPeer *rcv_rps_peer; @@ -1954,53 +1987,53 @@ profiler_reply_handle(void *cls, char *file_name_dhr = file_name_dhr_buf; char *file_name_dhru = file_name_dhru_buf; unsigned int i; - struct PendingReply *pending_rep = (struct PendingReply *)cls; + struct PendingReply *pending_rep = (struct PendingReply *) cls; pending_rep->req_handle = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); rps_peer = pending_rep->rps_peer; - (void)GNUNET_asprintf(&file_name, - "/tmp/rps/received_ids-%u", - rps_peer->index); - - (void)GNUNET_asprintf(&file_name_dh, - "/tmp/rps/diehard_input-%u", - rps_peer->index); - (void)GNUNET_asprintf(&file_name_dhr, - "/tmp/rps/diehard_input_raw-%u", - rps_peer->index); - (void)GNUNET_asprintf(&file_name_dhru, - "/tmp/rps/diehard_input_raw_aligned-%u", - rps_peer->index); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "[%s] got %" PRIu64 " peers:\n", - GNUNET_i2s(rps_peer->peer_id), - n); + (void) GNUNET_asprintf (&file_name, + "/tmp/rps/received_ids-%u", + rps_peer->index); + + (void) GNUNET_asprintf (&file_name_dh, + "/tmp/rps/diehard_input-%u", + rps_peer->index); + (void) GNUNET_asprintf (&file_name_dhr, + "/tmp/rps/diehard_input_raw-%u", + rps_peer->index); + (void) GNUNET_asprintf (&file_name_dhru, + "/tmp/rps/diehard_input_raw_aligned-%u", + rps_peer->index); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "[%s] got %" PRIu64 " peers:\n", + GNUNET_i2s (rps_peer->peer_id), + n); for (i = 0; i < n; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u: %s\n", - i, - GNUNET_i2s(&recv_peers[i])); - tofile(file_name, - "%s\n", - GNUNET_i2s_full(&recv_peers[i])); - rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); - GNUNET_assert(NULL != rcv_rps_peer); - tofile(file_name_dh, - "%" PRIu32 "\n", - (uint32_t)rcv_rps_peer->index); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u: %s\n", + i, + GNUNET_i2s (&recv_peers[i])); + tofile (file_name, + "%s\n", + GNUNET_i2s_full (&recv_peers[i])); + rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); + GNUNET_assert (NULL != rcv_rps_peer); + tofile (file_name_dh, + "%" PRIu32 "\n", + (uint32_t) rcv_rps_peer->index); #ifdef TO_FILE - to_file_raw(file_name_dhr, - (char *)&rcv_rps_peer->index, - sizeof(uint32_t)); - to_file_raw_unaligned(file_name_dhru, - (char *)&rcv_rps_peer->index, - sizeof(uint32_t), - bits_needed); + to_file_raw (file_name_dhr, + (char *) &rcv_rps_peer->index, + sizeof(uint32_t)); + to_file_raw_unaligned (file_name_dhru, + (char *) &rcv_rps_peer->index, + sizeof(uint32_t), + bits_needed); #endif /* TO_FILE */ - } - default_reply_handle(cls, n, recv_peers); + } + default_reply_handle (cls, n, recv_peers); } @@ -2012,10 +2045,10 @@ profiler_reply_handle(void *cls, * @param recv_peers the received peers */ static void -profiler_reply_handle_info(void *cls, - const struct GNUNET_PeerIdentity *recv_peer, - double probability, - uint32_t num_observed) +profiler_reply_handle_info (void *cls, + const struct GNUNET_PeerIdentity *recv_peer, + double probability, + uint32_t num_observed) { struct RPSPeer *rps_peer; struct RPSPeer *rcv_rps_peer; @@ -2028,82 +2061,82 @@ profiler_reply_handle_info(void *cls, char *file_name_dhr = file_name_dhr_buf; char *file_name_dhru = file_name_dhru_buf; unsigned int i; - struct PendingReply *pending_rep = (struct PendingReply *)cls; + struct PendingReply *pending_rep = (struct PendingReply *) cls; pending_rep->req_handle = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); rps_peer = pending_rep->rps_peer; - (void)GNUNET_asprintf(&file_name, - "/tmp/rps/received_ids-%u", - rps_peer->index); - - (void)GNUNET_asprintf(&file_name_dh, - "/tmp/rps/diehard_input-%u", - rps_peer->index); - (void)GNUNET_asprintf(&file_name_dhr, - "/tmp/rps/diehard_input_raw-%u", - rps_peer->index); - (void)GNUNET_asprintf(&file_name_dhru, - "/tmp/rps/diehard_input_raw_aligned-%u", - rps_peer->index); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "[%s] got peer with info:\n", - GNUNET_i2s(rps_peer->peer_id)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - " %s\n", - GNUNET_i2s(recv_peer)); - tofile(file_name, - "%s %d %" PRIu32 " \n", - GNUNET_i2s_full(recv_peer), - probability, - num_observed); - rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, recv_peer); - GNUNET_assert(NULL != rcv_rps_peer); - tofile(file_name_dh, - "%" PRIu32 "\n", - (uint32_t)rcv_rps_peer->index); + (void) GNUNET_asprintf (&file_name, + "/tmp/rps/received_ids-%u", + rps_peer->index); + + (void) GNUNET_asprintf (&file_name_dh, + "/tmp/rps/diehard_input-%u", + rps_peer->index); + (void) GNUNET_asprintf (&file_name_dhr, + "/tmp/rps/diehard_input_raw-%u", + rps_peer->index); + (void) GNUNET_asprintf (&file_name_dhru, + "/tmp/rps/diehard_input_raw_aligned-%u", + rps_peer->index); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "[%s] got peer with info:\n", + GNUNET_i2s (rps_peer->peer_id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + " %s\n", + GNUNET_i2s (recv_peer)); + tofile (file_name, + "%s %d %" PRIu32 " \n", + GNUNET_i2s_full (recv_peer), + probability, + num_observed); + rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, recv_peer); + GNUNET_assert (NULL != rcv_rps_peer); + tofile (file_name_dh, + "%" PRIu32 "\n", + (uint32_t) rcv_rps_peer->index); #ifdef TO_FILE - to_file_raw(file_name_dhr, - (char *)&rcv_rps_peer->index, - sizeof(uint32_t)); - to_file_raw_unaligned(file_name_dhru, - (char *)&rcv_rps_peer->index, - sizeof(uint32_t), - bits_needed); + to_file_raw (file_name_dhr, + (char *) &rcv_rps_peer->index, + sizeof(uint32_t)); + to_file_raw_unaligned (file_name_dhru, + (char *) &rcv_rps_peer->index, + sizeof(uint32_t), + bits_needed); #endif /* TO_FILE */ - default_reply_handle(cls, 1, recv_peer); + default_reply_handle (cls, 1, recv_peer); } static void -profiler_cb(struct RPSPeer *rps_peer) +profiler_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } /* Start churn */ - if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting churn task\n"); - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - churn, - NULL); - } + if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting churn task\n"); + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + churn, + NULL); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Not starting churn task\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Not starting churn task\n"); + } /* Only request peer ids at one peer. * (It's the before-last because last one is target of the focussed attack.) */ if (0 < rps_peer->num_ids_to_request) - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /** @@ -2116,29 +2149,29 @@ profiler_cb(struct RPSPeer *rps_peer) * #GNUNET_SYSERR to abort iteration with error! */ static int -file_name_cb(void *cls, const char *filename) +file_name_cb (void *cls, const char *filename) { - if (NULL != strstr(filename, "sampler_el")) + if (NULL != strstr (filename, "sampler_el")) + { + struct RPS_SamplerElement *s_elem; + struct GNUNET_CRYPTO_AuthKey auth_key; + const char *key_char; + uint32_t i; + (void) cls; + + key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ + tofile (filename, "--------------------------\n"); + + auth_key = string_to_auth_key (key_char); + s_elem = RPS_sampler_elem_create (); + RPS_sampler_elem_set (s_elem, auth_key); + + for (i = 0; i < num_peers; i++) { - struct RPS_SamplerElement *s_elem; - struct GNUNET_CRYPTO_AuthKey auth_key; - const char *key_char; - uint32_t i; - (void)cls; - - key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ - tofile(filename, "--------------------------\n"); - - auth_key = string_to_auth_key(key_char); - s_elem = RPS_sampler_elem_create(); - RPS_sampler_elem_set(s_elem, auth_key); - - for (i = 0; i < num_peers; i++) - { - RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]); - } - RPS_sampler_elem_destroy(s_elem); + RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); } + RPS_sampler_elem_destroy (s_elem); + } return GNUNET_OK; } @@ -2148,17 +2181,17 @@ file_name_cb(void *cls, const char *filename) * Compute all perfect samples. */ static int -profiler_eval(void) +profiler_eval (void) { #ifdef TO_FILE /* Compute perfect sample for each sampler element */ - if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); - } + if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); + } #endif /* TO_FILE */ - return evaluate(); + return evaluate (); } @@ -2169,40 +2202,40 @@ profiler_eval(void) * * @return */ -static int is_in_view(uint32_t a, uint32_t b) +static int is_in_view (uint32_t a, uint32_t b) { uint32_t i; for (i = 0; i < rps_peers[a].cur_view_count; i++) + { + if (0 == memcmp (rps_peers[b].peer_id, + &rps_peers[a].cur_view[i], + sizeof(struct GNUNET_PeerIdentity))) { - if (0 == memcmp(rps_peers[b].peer_id, - &rps_peers[a].cur_view[i], - sizeof(struct GNUNET_PeerIdentity))) - { - return GNUNET_YES; - } + return GNUNET_YES; } + } return GNUNET_NO; } -static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) +static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) { uint32_t i; for (i = 0; i < num_peers; i++) - { - if (0 == memcmp(pid, - rps_peers[i].peer_id, - sizeof(struct GNUNET_PeerIdentity))) - { - return i; - } - } - //return 0; /* Should not happen - make compiler happy */ - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "No known _PeerIdentity %s!\n", - GNUNET_i2s_full(pid)); - GNUNET_assert(0); + { + if (0 == memcmp (pid, + rps_peers[i].peer_id, + sizeof(struct GNUNET_PeerIdentity))) + { + return i; + } + } + // return 0; /* Should not happen - make compiler happy */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No known _PeerIdentity %s!\n", + GNUNET_i2s_full (pid)); + GNUNET_assert (0); } /** @@ -2213,20 +2246,20 @@ static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) * * @return */ -static uint32_t count_containing_views(uint32_t a, uint32_t b) +static uint32_t count_containing_views (uint32_t a, uint32_t b) { uint32_t i; uint32_t peer_idx; uint32_t count = 0; for (i = 0; i < rps_peers[a].cur_view_count; i++) + { + peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); + if (GNUNET_YES == is_in_view (peer_idx, b)) { - peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); - if (GNUNET_YES == is_in_view(peer_idx, b)) - { - count++; - } + count++; } + } return count; } @@ -2236,13 +2269,13 @@ static uint32_t count_containing_views(uint32_t a, uint32_t b) * * @param peer_idx index of the peer that is about to sample */ -static void compute_probabilities(uint32_t peer_idx) +static void compute_probabilities (uint32_t peer_idx) { - //double probs[num_peers] = { 0 }; + // double probs[num_peers] = { 0 }; double probs[num_peers]; double probs_hist[num_peers]; /* Probability respecting the history */ size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char); - char *probs_as_str = GNUNET_malloc(probs_as_str_size); + char *probs_as_str = GNUNET_malloc (probs_as_str_size); char *probs_as_str_cpy; uint32_t i; double prob_push; @@ -2254,143 +2287,144 @@ static void compute_probabilities(uint32_t peer_idx) double sum_non_zero_prob = 0; double sum_non_zero_prob_hist = 0; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Computing probabilities for peer %" PRIu32 "\n", peer_idx); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Computing probabilities for peer %" PRIu32 "\n", peer_idx); /* Firstly without knowledge of old views */ for (i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\tfor peer %" PRIu32 ":\n", i); - view_size = rps_peers[i].cur_view_count; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tview_size: %" PRIu32 "\n", view_size); - /* For peer i the probability of being sampled is - * evenly distributed among all possibly observed peers. */ - /* We could have observed a peer in three cases: - * 1. peer sent a push - * 2. peer was contained in a pull reply - * 3. peer was in history (sampler) - ignored for now */ - /* 1. Probability of having received a push from peer i */ - if ((GNUNET_YES == is_in_view(i, peer_idx)) && - (1 <= (0.45 * view_size))) - { - if (0 == binom(view_size, 0.45 * view_size)) - prob_push = 0; - else - { - prob_push = 1.0 * binom(0.45 * view_size, 1) - / - binom(view_size, 0.45 * view_size); - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", - peer_idx, - i, - prob_push); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", - binom(view_size, 0.45 * view_size), - binom(0.45 * view_size, 1)); - } - else - { - prob_push = 0; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", - peer_idx, - i); - } - /* 2. Probability of peer i being contained in pulls */ - view_size = rps_peers[peer_idx].cur_view_count; - cont_views = count_containing_views(peer_idx, i); - number_of_being_in_pull_events = - (binom(view_size, 0.45 * view_size) - - binom(view_size - cont_views, 0.45 * view_size)); - if (0 != number_of_being_in_pull_events) - { - prob_pull = number_of_being_in_pull_events - / - (1.0 * binom(view_size, 0.45 * view_size)); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\tfor peer %" PRIu32 ":\n", i); + view_size = rps_peers[i].cur_view_count; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tview_size: %" PRIu32 "\n", view_size); + /* For peer i the probability of being sampled is + * evenly distributed among all possibly observed peers. */ + /* We could have observed a peer in three cases: + * 1. peer sent a push + * 2. peer was contained in a pull reply + * 3. peer was in history (sampler) - ignored for now */ + /* 1. Probability of having received a push from peer i */ + if ((GNUNET_YES == is_in_view (i, peer_idx)) && + (1 <= (0.45 * view_size))) + { + if (0 == binom (view_size, 0.45 * view_size)) + prob_push = 0; else - { - prob_pull = 0; - } - probs[i] = prob_push + prob_pull - (prob_push * prob_pull); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 - " peers in its view who know %" PRIu32 " prob: %f\n", - peer_idx, - cont_views, - view_size, - i, - prob_pull); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations: %" PRIu32 "\n", - binom(view_size, 0.45 * view_size)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations without %" PRIu32 - ": %" PRIu32 "\n", - i, - binom(view_size - cont_views, 0.45 * view_size)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations with %" PRIu32 - ": %" PRIu32 "\n", - i, - number_of_being_in_pull_events); - - probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; - rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; - - sum_non_zero_prob += probs[i]; - sum_non_zero_prob_hist += probs_hist[i]; - } + { + prob_push = 1.0 * binom (0.45 * view_size, 1) + / + binom (view_size, 0.45 * view_size); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", + peer_idx, + i, + prob_push); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tposs choices from view: %" PRIu32 ", containing i: %" + PRIu32 "\n", + binom (view_size, 0.45 * view_size), + binom (0.45 * view_size, 1)); + } + else + { + prob_push = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", + peer_idx, + i); + } + /* 2. Probability of peer i being contained in pulls */ + view_size = rps_peers[peer_idx].cur_view_count; + cont_views = count_containing_views (peer_idx, i); + number_of_being_in_pull_events = + (binom (view_size, 0.45 * view_size) + - binom (view_size - cont_views, 0.45 * view_size)); + if (0 != number_of_being_in_pull_events) + { + prob_pull = number_of_being_in_pull_events + / + (1.0 * binom (view_size, 0.45 * view_size)); + } + else + { + prob_pull = 0; + } + probs[i] = prob_push + prob_pull - (prob_push * prob_pull); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 + " peers in its view who know %" PRIu32 " prob: %f\n", + peer_idx, + cont_views, + view_size, + i, + prob_pull); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations: %" PRIu32 "\n", + binom (view_size, 0.45 * view_size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations without %" PRIu32 + ": %" PRIu32 "\n", + i, + binom (view_size - cont_views, 0.45 * view_size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations with %" PRIu32 + ": %" PRIu32 "\n", + i, + number_of_being_in_pull_events); + + probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; + rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; + + sum_non_zero_prob += probs[i]; + sum_non_zero_prob_hist += probs_hist[i]; + } /* normalize */ if (0 != sum_non_zero_prob) + { + for (i = 0; i < num_peers; i++) { - for (i = 0; i < num_peers; i++) - { - probs[i] = probs[i] * (1.0 / sum_non_zero_prob); - } + probs[i] = probs[i] * (1.0 / sum_non_zero_prob); } + } if (0 != sum_non_zero_prob_hist) + { + for (i = 0; i < num_peers; i++) { - for (i = 0; i < num_peers; i++) - { - probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); - } + probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); } + } /* str repr */ for (i = 0; i < num_peers; i++) - { - probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); - tmp = GNUNET_snprintf(probs_as_str, - probs_as_str_size, - "%s %7.6f", probs_as_str_cpy, probs[i]); - GNUNET_free(probs_as_str_cpy); - GNUNET_assert(0 <= tmp); - } - - to_file_w_len(rps_peers[peer_idx].file_name_probs, - probs_as_str_size, - probs_as_str); + { + probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); + tmp = GNUNET_snprintf (probs_as_str, + probs_as_str_size, + "%s %7.6f", probs_as_str_cpy, probs[i]); + GNUNET_free (probs_as_str_cpy); + GNUNET_assert (0 <= tmp); + } + + to_file_w_len (rps_peers[peer_idx].file_name_probs, + probs_as_str_size, + probs_as_str); probs_as_str[0] = '\0'; for (i = 0; i < num_peers; i++) - { - probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); - tmp = GNUNET_snprintf(probs_as_str, - probs_as_str_size, - "%s %7.6f", probs_as_str_cpy, probs_hist[i]); - GNUNET_free(probs_as_str_cpy); - GNUNET_assert(0 <= tmp); - } - - to_file_w_len(rps_peers[peer_idx].file_name_probs_hist, - probs_as_str_size, - probs_as_str); - GNUNET_free(probs_as_str); + { + probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); + tmp = GNUNET_snprintf (probs_as_str, + probs_as_str_size, + "%s %7.6f", probs_as_str_cpy, probs_hist[i]); + GNUNET_free (probs_as_str_cpy); + GNUNET_assert (0 <= tmp); + } + + to_file_w_len (rps_peers[peer_idx].file_name_probs_hist, + probs_as_str_size, + probs_as_str); + GNUNET_free (probs_as_str); } /** @@ -2402,295 +2436,300 @@ static void compute_probabilities(uint32_t peer_idx) * * @return the number of occurrences */ -static uint32_t count_peer_in_views_2(uint32_t peer_idx) +static uint32_t count_peer_in_views_2 (uint32_t peer_idx) { uint32_t i, j; uint32_t count = 0; for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ - { - for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ - { - if (0 == memcmp(rps_peers[peer_idx].peer_id, - &rps_peers[i].cur_view[j], - sizeof(struct GNUNET_PeerIdentity))) - { - count++; - break; - } - } - } + { + for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ + { + if (0 == memcmp (rps_peers[peer_idx].peer_id, + &rps_peers[i].cur_view[j], + sizeof(struct GNUNET_PeerIdentity))) + { + count++; + break; + } + } + } rps_peers[peer_idx].count_in_views = count; return count; } -static uint32_t cumulated_view_sizes() +static uint32_t cumulated_view_sizes () { uint32_t i; view_sizes = 0; for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ - { - view_sizes += rps_peers[i].cur_view_count; - } + { + view_sizes += rps_peers[i].cur_view_count; + } return view_sizes; } -static void count_peer_in_views(uint32_t *count_peers) +static void count_peer_in_views (uint32_t *count_peers) { uint32_t i, j; for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ + { + for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ { - for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ - { - if (0 == memcmp(rps_peers[i].peer_id, - &rps_peers[i].cur_view[j], - sizeof(struct GNUNET_PeerIdentity))) - { - count_peers[i]++; - } - } + if (0 == memcmp (rps_peers[i].peer_id, + &rps_peers[i].cur_view[j], + sizeof(struct GNUNET_PeerIdentity))) + { + count_peers[i]++; + } } + } } -void compute_diversity() +void compute_diversity () { uint32_t i; /* ith entry represents the numer of occurrences in other peer's views */ - uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t); + uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); uint32_t views_total_size; double expected; /* deviation from expected number of peers */ - double *deviation = GNUNET_new_array(num_peers, double); + double *deviation = GNUNET_new_array (num_peers, double); views_total_size = 0; expected = 0; /* For each peer count its representation in other peer's views*/ for (i = 0; i < num_peers; i++) /* Peer to count */ - { - views_total_size += rps_peers[i].cur_view_count; - count_peer_in_views(count_peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n", - i, - GNUNET_i2s(rps_peers[i].peer_id), - count_peers[i]); - } - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "size of all views combined: %" PRIu32 "\n", - views_total_size); - expected = ((double)1 / num_peers) * views_total_size; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Expected number of occurrences of each peer in all views: %f\n", - expected); + { + views_total_size += rps_peers[i].cur_view_count; + count_peer_in_views (count_peers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 + "\n", + i, + GNUNET_i2s (rps_peers[i].peer_id), + count_peers[i]); + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "size of all views combined: %" PRIu32 "\n", + views_total_size); + expected = ((double) 1 / num_peers) * views_total_size; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Expected number of occurrences of each peer in all views: %f\n", + expected); for (i = 0; i < num_peers; i++) /* Peer to count */ - { - deviation[i] = expected - count_peers[i]; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Deviation from expectation: %f\n", deviation[i]); - } - GNUNET_free(count_peers); - GNUNET_free(deviation); + { + deviation[i] = expected - count_peers[i]; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Deviation from expectation: %f\n", deviation[i]); + } + GNUNET_free (count_peers); + GNUNET_free (deviation); } -void print_view_sizes() +void print_view_sizes () { uint32_t i; for (i = 0; i < num_peers; i++) /* Peer to count */ - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", - i, - GNUNET_i2s(rps_peers[i].peer_id), - rps_peers[i].cur_view_count); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", + i, + GNUNET_i2s (rps_peers[i].peer_id), + rps_peers[i].cur_view_count); + } } -void all_views_updated_cb() +void all_views_updated_cb () { - compute_diversity(); - print_view_sizes(); + compute_diversity (); + print_view_sizes (); } -void view_update_cb(void *cls, - uint64_t view_size, - const struct GNUNET_PeerIdentity *peers) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "View was updated (%" PRIu64 ")\n", view_size); - struct RPSPeer *rps_peer = (struct RPSPeer *)cls; - to_file("/tmp/rps/view_sizes.txt", - "%" PRIu64 " %" PRIu32 "", - rps_peer->index, - view_size); +void view_update_cb (void *cls, + uint64_t view_size, + const struct GNUNET_PeerIdentity *peers) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "View was updated (%" PRIu64 ")\n", view_size); + struct RPSPeer *rps_peer = (struct RPSPeer *) cls; + to_file ("/tmp/rps/view_sizes.txt", + "%" PRIu64 " %" PRIu32 "", + rps_peer->index, + view_size); for (uint64_t i = 0; i < view_size; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t%s\n", GNUNET_i2s(&peers[i])); - } - GNUNET_array_grow(rps_peer->cur_view, - rps_peer->cur_view_count, - view_size); - //*rps_peer->cur_view = *peers; - GNUNET_memcpy(rps_peer->cur_view, - peers, - view_size * sizeof(struct GNUNET_PeerIdentity)); - to_file("/tmp/rps/count_in_views.txt", - "%" PRIu64 " %" PRIu32 "", - rps_peer->index, - count_peer_in_views_2(rps_peer->index)); - cumulated_view_sizes(); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t%s\n", GNUNET_i2s (&peers[i])); + } + GNUNET_array_grow (rps_peer->cur_view, + rps_peer->cur_view_count, + view_size); + // *rps_peer->cur_view = *peers; + GNUNET_memcpy (rps_peer->cur_view, + peers, + view_size * sizeof(struct GNUNET_PeerIdentity)); + to_file ("/tmp/rps/count_in_views.txt", + "%" PRIu64 " %" PRIu32 "", + rps_peer->index, + count_peer_in_views_2 (rps_peer->index)); + cumulated_view_sizes (); if (0 != view_size) - { - to_file("/tmp/rps/repr.txt", - "%" PRIu64 /* index */ - " %" PRIu32 /* occurrence in views */ - " %" PRIu32 /* view sizes */ - " %f" /* fraction of repr in views */ - " %f" /* average view size */ - " %f" /* prob of occurrence in view slot */ - " %f" "", /* exp frac of repr in views */ - rps_peer->index, - count_peer_in_views_2(rps_peer->index), - view_sizes, - count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ - view_sizes / (view_size * 1.0), /* average view size */ - 1.0 / view_size, /* prob of occurrence in view slot */ - (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ - ); - } - compute_probabilities(rps_peer->index); - all_views_updated_cb(); + { + to_file ("/tmp/rps/repr.txt", + "%" PRIu64 /* index */ + " %" PRIu32 /* occurrence in views */ + " %" PRIu32 /* view sizes */ + " %f" /* fraction of repr in views */ + " %f" /* average view size */ + " %f" /* prob of occurrence in view slot */ + " %f" "", /* exp frac of repr in views */ + rps_peer->index, + count_peer_in_views_2 (rps_peer->index), + view_sizes, + count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ + view_sizes / (view_size * 1.0), /* average view size */ + 1.0 / view_size, /* prob of occurrence in view slot */ + (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ + ); + } + compute_probabilities (rps_peer->index); + all_views_updated_cb (); } static void -pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) +pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) { rps_peer->file_name_probs = - store_prefix_file_name(rps_peer->index, "probs"); + store_prefix_file_name (rps_peer->index, "probs"); rps_peer->file_name_probs_hist = - store_prefix_file_name(rps_peer->index, "probs_hist"); - GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer); + store_prefix_file_name (rps_peer->index, "probs_hist"); + GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); } -void write_final_stats(void) +void write_final_stats (void) { uint64_t sums[STAT_TYPE_MAX] = { 0 }; for (uint32_t i = 0; i < num_peers; i++) - { - to_file("/tmp/rps/final_stats.csv", - "%" PRIu32 ", " /* index */ - "%s, %" /* id */ - PRIu64 ", %" /* rounds */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ - PRIu64 ", %" /* view size */ - PRIu64 ", %" /* known peers */ - PRIu64 ", %" /* valid peers */ - PRIu64 ", %" /* learned peers */ - PRIu64 ", %" /* pending online checks */ - PRIu64 ", %" /* unrequested pull replies */ - PRIu64 ", %" /* peers in push map */ - PRIu64 ", %" /* peers in pull map */ - PRIu64 ", %" /* peers in view */ - PRIu64 "\n" /* view size aim */, - i, - GNUNET_i2s(rps_peers[i].peer_id), - rps_peers[i].stats[STAT_TYPE_ROUNDS], - rps_peers[i].stats[STAT_TYPE_BLOCKS], - rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], - rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], - rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], - rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], - rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], - rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], - rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], - rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], - rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], - rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], - rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], - rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], - rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], - rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], - rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], - rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], - rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], - rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], - rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], - rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], - rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], - rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], - rps_peers[i].stats[STAT_TYPE_VALID_PEERS], - rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], - rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], - rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], - rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], - rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], - rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], - rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); - for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; - stat_type < STAT_TYPE_MAX; - stat_type++) - { - sums[stat_type] += rps_peers[i].stats[stat_type]; - } - } - to_file("/tmp/rps/final_stats.dat", - "SUM %" - PRIu64 " %" /* rounds */ - PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ - PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ - PRIu64 ", %" /* view size */ - PRIu64 ", %" /* known peers */ - PRIu64 ", %" /* valid peers */ - PRIu64 ", %" /* learned peers */ - PRIu64 ", %" /* pending online checks */ - PRIu64 ", %" /* unrequested pull replies */ - PRIu64 ", %" /* peers in push map */ - PRIu64 ", %" /* peers in pull map */ - PRIu64 ", %" /* peers in view */ - PRIu64 "\n" /* view size aim */, - sums[STAT_TYPE_ROUNDS], - sums[STAT_TYPE_BLOCKS], - sums[STAT_TYPE_BLOCKS_MANY_PUSH], - sums[STAT_TYPE_BLOCKS_NO_PUSH], - sums[STAT_TYPE_BLOCKS_NO_PULL], - sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], - sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], - sums[STAT_TYPE_ISSUED_PUSH_SEND], - sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], - sums[STAT_TYPE_ISSUED_PULL_REQ], - sums[STAT_TYPE_ISSUED_PULL_REQ_MH], - sums[STAT_TYPE_ISSUED_PULL_REP], - sums[STAT_TYPE_SENT_PUSH_SEND], - sums[STAT_TYPE_SENT_PULL_REQ], - sums[STAT_TYPE_SENT_PULL_REQ_MH], - sums[STAT_TYPE_SENT_PULL_REP], - sums[STAT_TYPE_RECV_PUSH_SEND], - sums[STAT_TYPE_RECV_PUSH_SEND_MH], - sums[STAT_TYPE_RECV_PULL_REQ], - sums[STAT_TYPE_RECV_PULL_REQ_MH], - sums[STAT_TYPE_RECV_PULL_REP], - sums[STAT_TYPE_RECV_PULL_REP_MH], - sums[STAT_TYPE_VIEW_SIZE], - sums[STAT_TYPE_KNOWN_PEERS], - sums[STAT_TYPE_VALID_PEERS], - sums[STAT_TYPE_LEARND_PEERS], - sums[STAT_TYPE_PENDING_ONLINE_CHECKS], - sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], - sums[STAT_TYPE_PEERS_IN_PUSH_MAP], - sums[STAT_TYPE_PEERS_IN_PULL_MAP], - sums[STAT_TYPE_PEERS_IN_VIEW], - sums[STAT_TYPE_VIEW_SIZE_AIM]); + { + to_file ("/tmp/rps/final_stats.csv", + "%" PRIu32 ", " /* index */ + "%s, %" /* id */ + PRIu64 ", %" /* rounds */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" + PRIu64 ", %" /* blocking */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" + PRIu64 ", %" /* recv */ + PRIu64 ", %" /* view size */ + PRIu64 ", %" /* known peers */ + PRIu64 ", %" /* valid peers */ + PRIu64 ", %" /* learned peers */ + PRIu64 ", %" /* pending online checks */ + PRIu64 ", %" /* unrequested pull replies */ + PRIu64 ", %" /* peers in push map */ + PRIu64 ", %" /* peers in pull map */ + PRIu64 ", %" /* peers in view */ + PRIu64 "\n" /* view size aim */, + i, + GNUNET_i2s (rps_peers[i].peer_id), + rps_peers[i].stats[STAT_TYPE_ROUNDS], + rps_peers[i].stats[STAT_TYPE_BLOCKS], + rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], + rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], + rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], + rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], + rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], + rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], + rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], + rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], + rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], + rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], + rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], + rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], + rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], + rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], + rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], + rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], + rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], + rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], + rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], + rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], + rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], + rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], + rps_peers[i].stats[STAT_TYPE_VALID_PEERS], + rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], + rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], + rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], + rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], + rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], + rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], + rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); + for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; + stat_type < STAT_TYPE_MAX; + stat_type++) + { + sums[stat_type] += rps_peers[i].stats[stat_type]; + } + } + to_file ("/tmp/rps/final_stats.dat", + "SUM %" + PRIu64 " %" /* rounds */ + PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 + " %" /* blocking */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ + PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" + PRIu64 ", %" /* recv */ + PRIu64 ", %" /* view size */ + PRIu64 ", %" /* known peers */ + PRIu64 ", %" /* valid peers */ + PRIu64 ", %" /* learned peers */ + PRIu64 ", %" /* pending online checks */ + PRIu64 ", %" /* unrequested pull replies */ + PRIu64 ", %" /* peers in push map */ + PRIu64 ", %" /* peers in pull map */ + PRIu64 ", %" /* peers in view */ + PRIu64 "\n" /* view size aim */, + sums[STAT_TYPE_ROUNDS], + sums[STAT_TYPE_BLOCKS], + sums[STAT_TYPE_BLOCKS_MANY_PUSH], + sums[STAT_TYPE_BLOCKS_NO_PUSH], + sums[STAT_TYPE_BLOCKS_NO_PULL], + sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], + sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], + sums[STAT_TYPE_ISSUED_PUSH_SEND], + sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], + sums[STAT_TYPE_ISSUED_PULL_REQ], + sums[STAT_TYPE_ISSUED_PULL_REQ_MH], + sums[STAT_TYPE_ISSUED_PULL_REP], + sums[STAT_TYPE_SENT_PUSH_SEND], + sums[STAT_TYPE_SENT_PULL_REQ], + sums[STAT_TYPE_SENT_PULL_REQ_MH], + sums[STAT_TYPE_SENT_PULL_REP], + sums[STAT_TYPE_RECV_PUSH_SEND], + sums[STAT_TYPE_RECV_PUSH_SEND_MH], + sums[STAT_TYPE_RECV_PULL_REQ], + sums[STAT_TYPE_RECV_PULL_REQ_MH], + sums[STAT_TYPE_RECV_PULL_REP], + sums[STAT_TYPE_RECV_PULL_REP_MH], + sums[STAT_TYPE_VIEW_SIZE], + sums[STAT_TYPE_KNOWN_PEERS], + sums[STAT_TYPE_VALID_PEERS], + sums[STAT_TYPE_LEARND_PEERS], + sums[STAT_TYPE_PENDING_ONLINE_CHECKS], + sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], + sums[STAT_TYPE_PEERS_IN_PUSH_MAP], + sums[STAT_TYPE_PEERS_IN_PULL_MAP], + sums[STAT_TYPE_PEERS_IN_VIEW], + sums[STAT_TYPE_VIEW_SIZE_AIM]); } /** @@ -2705,47 +2744,48 @@ void write_final_stats(void) * successfully obtained, #GNUNET_SYSERR if not. */ void -post_test_shutdown_ready_cb(void *cls, - int success) +post_test_shutdown_ready_cb (void *cls, + int success) { - struct STATcls *stat_cls = (struct STATcls *)cls; + struct STATcls *stat_cls = (struct STATcls *) cls; struct RPSPeer *rps_peer = stat_cls->rps_peer; rps_peer->h_stat_get[stat_cls->stat_type] = NULL; if (GNUNET_OK == success) - { - /* set flag that we we got the value */ - rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); - } + { + /* set flag that we we got the value */ + rps_peer->stat_collected_flags |= BIT (stat_cls->stat_type); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Peer %u did not receive statistics value\n", - rps_peer->index); - GNUNET_free(stat_cls); - GNUNET_break(0); - return; - } - - if (NULL != rps_peer->stat_op && - GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer)) - { - GNUNET_TESTBED_operation_done(rps_peer->stat_op); - } - - write_final_stats(); - if (GNUNET_YES == check_statistics_collect_completed()) - { - //write_final_stats (); - GNUNET_free(stat_cls); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Shutting down\n"); - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peer %u did not receive statistics value\n", + rps_peer->index); + GNUNET_free (stat_cls); + GNUNET_break (0); + return; + } + + if ((NULL != rps_peer->stat_op)&& + (GNUNET_YES == check_statistics_collect_completed_single_peer ( + rps_peer)) ) + { + GNUNET_TESTBED_operation_done (rps_peer->stat_op); + } + + write_final_stats (); + if (GNUNET_YES == check_statistics_collect_completed ()) + { + // write_final_stats (); + GNUNET_free (stat_cls); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutting down\n"); + GNUNET_SCHEDULER_shutdown (); + } else - { - GNUNET_free(stat_cls); - } + { + GNUNET_free (stat_cls); + } } /** @@ -2759,76 +2799,76 @@ post_test_shutdown_ready_cb(void *cls, * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration */ int -stat_iterator(void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - const struct STATcls *stat_cls = (const struct STATcls *)cls; - struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer; +stat_iterator (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) +{ + const struct STATcls *stat_cls = (const struct STATcls *) cls; + struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; enum STAT_TYPE stat_type; - (void)subsystem; - (void)is_persistent; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Got stat value: %s - %" PRIu64 " (%u)\n", - name, - value, - rps_peer->index); - to_file(rps_peer->file_name_stats, - "%s: %" PRIu64 "\n", - name, - value); - stat_type = stat_str_2_type(name); - GNUNET_assert(STAT_TYPE_ROUNDS <= stat_type && - STAT_TYPE_MAX > stat_type); + (void) subsystem; + (void) is_persistent; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got stat value: %s - %" PRIu64 " (%u)\n", + name, + value, + rps_peer->index); + to_file (rps_peer->file_name_stats, + "%s: %" PRIu64 "\n", + name, + value); + stat_type = stat_str_2_type (name); + GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type && + STAT_TYPE_MAX > stat_type); rps_peer->stats[stat_type] = value; return GNUNET_OK; } void -post_profiler(struct RPSPeer *rps_peer) +post_profiler (struct RPSPeer *rps_peer) { if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) - { - return; - } + { + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Going to request statistic values with mask 0x%" PRIx32 "\n", - cur_test_run.stat_collect_flags); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Going to request statistic values with mask 0x%" PRIx32 "\n", + cur_test_run.stat_collect_flags); struct STATcls *stat_cls; uint32_t stat_type; for (stat_type = STAT_TYPE_ROUNDS; stat_type < STAT_TYPE_MAX; stat_type++) - { - if (BIT(stat_type) & cur_test_run.stat_collect_flags) - { - stat_cls = GNUNET_malloc(sizeof(struct STATcls)); - stat_cls->rps_peer = rps_peer; - stat_cls->stat_type = stat_type; - rps_peer->file_name_stats = - store_prefix_file_name(rps_peer->peer_id, "stats"); - rps_peer->h_stat_get[stat_type] = - GNUNET_STATISTICS_get(rps_peer->stats_h, - "rps", - stat_type_strings [stat_type], - post_test_shutdown_ready_cb, - stat_iterator, - (struct STATcls *)stat_cls); - GNUNET_assert(NULL != rps_peer->h_stat_get); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requested statistics for %s (peer %" PRIu32 ")\n", - stat_type_strings [stat_type], - rps_peer->index); - } - } - GNUNET_free(rps_peer->eval_probs_cache); + { + if (BIT (stat_type) & cur_test_run.stat_collect_flags) + { + stat_cls = GNUNET_malloc (sizeof(struct STATcls)); + stat_cls->rps_peer = rps_peer; + stat_cls->stat_type = stat_type; + rps_peer->file_name_stats = + store_prefix_file_name (rps_peer->peer_id, "stats"); + rps_peer->h_stat_get[stat_type] = + GNUNET_STATISTICS_get (rps_peer->stats_h, + "rps", + stat_type_strings [stat_type], + post_test_shutdown_ready_cb, + stat_iterator, + (struct STATcls *) stat_cls); + GNUNET_assert (NULL != rps_peer->h_stat_get); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requested statistics for %s (peer %" PRIu32 ")\n", + stat_type_strings [stat_type], + rps_peer->index); + } + } + GNUNET_free (rps_peer->eval_probs_cache); } @@ -2850,100 +2890,104 @@ post_profiler(struct RPSPeer *rps_peer) * failed */ static void -test_run(void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int n_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +test_run (void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int n_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int i; struct OpListEntry *entry; - (void)cls; - (void)h; - (void)links_failed; + (void) cls; + (void) h; + (void) links_failed; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); /* Check whether we timed out */ - if (n_peers != num_peers || - NULL == peers || - 0 == links_succeeded) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); - ok = 1; - GNUNET_SCHEDULER_shutdown(); - return; - } + if ((n_peers != num_peers)|| + (NULL == peers) || + (0 == links_succeeded) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Going down due to args (eg. timeout)\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", + num_peers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", + links_succeeded); + ok = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } /* Initialize peers */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); testbed_peers = peers; num_peers_online = 0; for (i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); - entry = make_oplist_entry(); - entry->index = i; - rps_peers[i].index = i; - if (NULL != cur_test_run.init_peer) - cur_test_run.init_peer(&rps_peers[i]); - if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) - { - rps_peers->cur_view_count = 0; - rps_peers->cur_view = NULL; - } - entry->op = GNUNET_TESTBED_peer_get_information(peers[i], - GNUNET_TESTBED_PIT_IDENTITY, - &info_cb, - entry); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); + entry = make_oplist_entry (); + entry->index = i; + rps_peers[i].index = i; + if (NULL != cur_test_run.init_peer) + cur_test_run.init_peer (&rps_peers[i]); + if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) + { + rps_peers->cur_view_count = 0; + rps_peers->cur_view = NULL; + } + entry->op = GNUNET_TESTBED_peer_get_information (peers[i], + GNUNET_TESTBED_PIT_IDENTITY, + &info_cb, + entry); + } /* Bring peers up */ - GNUNET_assert(num_peers == n_peers); + GNUNET_assert (num_peers == n_peers); for (i = 0; i < n_peers; i++) - { - rps_peers[i].index = i; - rps_peers[i].op = - GNUNET_TESTBED_service_connect(&rps_peers[i], - peers[i], - "rps", - &rps_connect_complete_cb, - &rps_peers[i], - &rps_connect_adapter, - &rps_disconnect_adapter, - &rps_peers[i]); - /* Connect all peers to statistics service */ - if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Connecting to statistics service\n"); - rps_peers[i].stat_op = - GNUNET_TESTBED_service_connect(NULL, - peers[i], - "statistics", - stat_complete_cb, - &rps_peers[i], - &stat_connect_adapter, - &stat_disconnect_adapter, - &rps_peers[i]); - } - } + { + rps_peers[i].index = i; + rps_peers[i].op = + GNUNET_TESTBED_service_connect (&rps_peers[i], + peers[i], + "rps", + &rps_connect_complete_cb, + &rps_peers[i], + &rps_connect_adapter, + &rps_disconnect_adapter, + &rps_peers[i]); + /* Connect all peers to statistics service */ + if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to statistics service\n"); + rps_peers[i].stat_op = + GNUNET_TESTBED_service_connect (NULL, + peers[i], + "statistics", + stat_complete_cb, + &rps_peers[i], + &stat_connect_adapter, + &stat_disconnect_adapter, + &rps_peers[i]); + } + } if (NULL != churn_task) - GNUNET_SCHEDULER_cancel(churn_task); - post_test_task = GNUNET_SCHEDULER_add_delayed(duration, &post_test_op, NULL); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us / 1000000); - shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, - &trigger_shutdown, - NULL); - GNUNET_SCHEDULER_add_shutdown(shutdown_op, NULL); + GNUNET_SCHEDULER_cancel (churn_task); + post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", + timeout.rel_value_us / 1000000); + shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, + &trigger_shutdown, + NULL); + GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); } @@ -2954,26 +2998,26 @@ test_run(void *cls, * @param argv unused */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - //int ret_value; - (void)cls; - (void)args; - (void)cfgfile; + // int ret_value; + (void) cls; + (void) args; + (void) cfgfile; /* Defaults for tests */ churn_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); cur_test_run.name = "test-rps-profiler"; if (0 == num_peers) num_peers = 10; mal_type = 3; cur_test_run.init_peer = profiler_init_peer; - //cur_test_run.pre_test = mal_pre; + // cur_test_run.pre_test = mal_pre; cur_test_run.pre_test = pre_profiler; cur_test_run.main_test = profiler_cb; cur_test_run.reply_handle = profiler_reply_handle; @@ -2982,104 +3026,105 @@ run(void *cls, cur_test_run.request_interval = 2; if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; - //cur_test_run.have_churn = HAVE_CHURN; + // cur_test_run.have_churn = HAVE_CHURN; cur_test_run.have_churn = HAVE_NO_CHURN; cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; cur_test_run.have_collect_statistics = COLLECT_STATISTICS; - cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | - BIT(STAT_TYPE_BLOCKS) | - BIT(STAT_TYPE_BLOCKS_MANY_PUSH) | - BIT(STAT_TYPE_BLOCKS_NO_PUSH) | - BIT(STAT_TYPE_BLOCKS_NO_PULL) | - BIT(STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) | - BIT(STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) | - BIT(STAT_TYPE_ISSUED_PUSH_SEND) | - BIT(STAT_TYPE_ISSUED_PUSH_SEND_MH) | - BIT(STAT_TYPE_ISSUED_PULL_REQ) | - BIT(STAT_TYPE_ISSUED_PULL_REQ_MH) | - BIT(STAT_TYPE_ISSUED_PULL_REP) | - BIT(STAT_TYPE_SENT_PUSH_SEND) | - BIT(STAT_TYPE_SENT_PULL_REQ) | - BIT(STAT_TYPE_SENT_PULL_REQ_MH) | - BIT(STAT_TYPE_SENT_PULL_REP) | - BIT(STAT_TYPE_RECV_PUSH_SEND) | - BIT(STAT_TYPE_RECV_PUSH_SEND_MH) | - BIT(STAT_TYPE_RECV_PULL_REQ) | - BIT(STAT_TYPE_RECV_PULL_REQ_MH) | - BIT(STAT_TYPE_RECV_PULL_REP) | - BIT(STAT_TYPE_RECV_PULL_REP_MH) | - BIT(STAT_TYPE_VIEW_SIZE) | - BIT(STAT_TYPE_KNOWN_PEERS) | - BIT(STAT_TYPE_VALID_PEERS) | - BIT(STAT_TYPE_LEARND_PEERS) | - BIT(STAT_TYPE_PENDING_ONLINE_CHECKS) | - BIT(STAT_TYPE_UNREQUESTED_PULL_REPLIES) | - BIT(STAT_TYPE_PEERS_IN_PUSH_MAP) | - BIT(STAT_TYPE_PEERS_IN_PULL_MAP) | - BIT(STAT_TYPE_PEERS_IN_VIEW) | - BIT(STAT_TYPE_VIEW_SIZE_AIM); + cur_test_run.stat_collect_flags = BIT (STAT_TYPE_ROUNDS) + | BIT (STAT_TYPE_BLOCKS) + | BIT (STAT_TYPE_BLOCKS_MANY_PUSH) + | BIT (STAT_TYPE_BLOCKS_NO_PUSH) + | BIT (STAT_TYPE_BLOCKS_NO_PULL) + | BIT (STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) + | BIT (STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) + | BIT (STAT_TYPE_ISSUED_PUSH_SEND) + | BIT (STAT_TYPE_ISSUED_PUSH_SEND_MH) + | BIT (STAT_TYPE_ISSUED_PULL_REQ) + | BIT (STAT_TYPE_ISSUED_PULL_REQ_MH) + | BIT (STAT_TYPE_ISSUED_PULL_REP) + | BIT (STAT_TYPE_SENT_PUSH_SEND) + | BIT (STAT_TYPE_SENT_PULL_REQ) + | BIT (STAT_TYPE_SENT_PULL_REQ_MH) + | BIT (STAT_TYPE_SENT_PULL_REP) + | BIT (STAT_TYPE_RECV_PUSH_SEND) + | BIT (STAT_TYPE_RECV_PUSH_SEND_MH) + | BIT (STAT_TYPE_RECV_PULL_REQ) + | BIT (STAT_TYPE_RECV_PULL_REQ_MH) + | BIT (STAT_TYPE_RECV_PULL_REP) + | BIT (STAT_TYPE_RECV_PULL_REP_MH) + | BIT (STAT_TYPE_VIEW_SIZE) + | BIT (STAT_TYPE_KNOWN_PEERS) + | BIT (STAT_TYPE_VALID_PEERS) + | BIT (STAT_TYPE_LEARND_PEERS) + | BIT (STAT_TYPE_PENDING_ONLINE_CHECKS) + | BIT (STAT_TYPE_UNREQUESTED_PULL_REPLIES) + | BIT (STAT_TYPE_PEERS_IN_PUSH_MAP) + | BIT (STAT_TYPE_PEERS_IN_PULL_MAP) + | BIT (STAT_TYPE_PEERS_IN_VIEW) + | BIT (STAT_TYPE_VIEW_SIZE_AIM); cur_test_run.have_collect_view = COLLECT_VIEW; /* 'Clean' directory */ - (void)GNUNET_DISK_directory_remove("/tmp/rps/"); - GNUNET_DISK_directory_create("/tmp/rps/"); + (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); + GNUNET_DISK_directory_create ("/tmp/rps/"); if (0 == duration.rel_value_us) + { + if (0 == timeout.rel_value_us) { - if (0 == timeout.rel_value_us) - { - duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90); - timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - (90 * 1.2) + - (0.01 * num_peers)); - } - else - { - duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - (timeout.rel_value_us / 1000000) - * 0.75); - } + duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + (90 * 1.2) + + (0.01 * num_peers)); } - else + else { - if (0 == timeout.rel_value_us) - { - timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - ((duration.rel_value_us / 1000000) - * 1.2) + (0.01 * num_peers)); - } + duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + (timeout.rel_value_us / 1000000) + * 0.75); } - GNUNET_assert(duration.rel_value_us < timeout.rel_value_us); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "duration is %lus\n", - duration.rel_value_us / 1000000); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "timeout is %lus\n", - timeout.rel_value_us / 1000000); + } + else + { + if (0 == timeout.rel_value_us) + { + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + ((duration.rel_value_us + / 1000000) + * 1.2) + (0.01 * num_peers)); + } + } + GNUNET_assert (duration.rel_value_us < timeout.rel_value_us); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "duration is %lus\n", + duration.rel_value_us / 1000000); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "timeout is %lus\n", + timeout.rel_value_us / 1000000); /* Compute number of bits for representing largest peer id */ for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) ; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Need %u bits to represent %" PRIu32 " peers\n", - bits_needed, - num_peers); - - rps_peers = GNUNET_new_array(num_peers, struct RPSPeer); - peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO); - rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Need %u bits to represent %" PRIu32 " peers\n", + bits_needed, + num_peers); + + rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); + peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); + rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); if ((2 == mal_type) || (3 == mal_type)) target_peer = &rps_peer_ids[num_peers - 2]; ok = 1; - GNUNET_TESTBED_run(NULL, - cfg, - num_peers, - 0, /* event mask */ - NULL, - NULL, - &test_run, - NULL); + GNUNET_TESTBED_run (NULL, + cfg, + num_peers, + 0, /* event mask */ + NULL, + NULL, + &test_run, + NULL); } /** @@ -3090,69 +3135,72 @@ run(void *cls, * @return 0 on success */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { int ret_value; struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint('n', - "num-peers", - "COUNT", - gettext_noop("number of peers to start"), - &num_peers), - GNUNET_GETOPT_option_relative_time('d', - "duration", - "DURATION", - gettext_noop("duration of the profiling"), - &duration), - GNUNET_GETOPT_option_relative_time('t', - "timeout", - "TIMEOUT", - gettext_noop("timeout for the profiling"), - &timeout), - GNUNET_GETOPT_option_uint('r', - "num-requests", - "COUNT", - gettext_noop("number of PeerIDs to request"), - &cur_test_run.num_requests), + GNUNET_GETOPT_option_uint ('n', + "num-peers", + "COUNT", + gettext_noop ("number of peers to start"), + &num_peers), + GNUNET_GETOPT_option_relative_time ('d', + "duration", + "DURATION", + gettext_noop ( + "duration of the profiling"), + &duration), + GNUNET_GETOPT_option_relative_time ('t', + "timeout", + "TIMEOUT", + gettext_noop ( + "timeout for the profiling"), + &timeout), + GNUNET_GETOPT_option_uint ('r', + "num-requests", + "COUNT", + gettext_noop ("number of PeerIDs to request"), + &cur_test_run.num_requests), GNUNET_GETOPT_OPTION_END }; - unsetenv("XDG_DATA_HOME"); - unsetenv("XDG_CONFIG_HOME"); - //if (GNUNET_OK != + unsetenv ("XDG_DATA_HOME"); + unsetenv ("XDG_CONFIG_HOME"); + // if (GNUNET_OK != // GNUNET_STRINGS_get_utf8_args (argc, argv, // &argc, &argv)) // return 2; ret_value = 0; if (GNUNET_OK != - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-rps-profiler", - gettext_noop("Measure quality and performance of the RPS service."), - options, - &run, - NULL)) - { - ret_value = 1; - } + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-rps-profiler", + gettext_noop ( + "Measure quality and performance of the RPS service."), + options, + &run, + NULL)) + { + ret_value = 1; + } if (0 != ret_value) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Test did not run successfully!\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Test did not run successfully!\n"); + } else - { - ret_value = cur_test_run.eval_cb(); - if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) - { - GNUNET_array_grow(rps_peers->cur_view, - rps_peers->cur_view_count, - 0); - } - GNUNET_free(rps_peers); - GNUNET_free(rps_peer_ids); - GNUNET_CONTAINER_multipeermap_destroy(peer_map); - } + { + ret_value = cur_test_run.eval_cb (); + if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) + { + GNUNET_array_grow (rps_peers->cur_view, + rps_peers->cur_view_count, + 0); + } + GNUNET_free (rps_peers); + GNUNET_free (rps_peer_ids); + GNUNET_CONTAINER_multipeermap_destroy (peer_map); + } return ret_value; } diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c index 84043341b..6c1c96cc9 100644 --- a/src/rps/gnunet-rps.c +++ b/src/rps/gnunet-rps.c @@ -68,13 +68,13 @@ static uint64_t num_view_updates; * @param cls NULL */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { - (void)cls; + (void) cls; if (NULL != req_handle) - GNUNET_RPS_request_cancel(req_handle); - GNUNET_RPS_disconnect(rps_handle); + GNUNET_RPS_request_cancel (req_handle); + GNUNET_RPS_disconnect (rps_handle); } @@ -87,23 +87,23 @@ do_shutdown(void *cls) * @param recv_peers the received peers */ static void -reply_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +reply_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { uint64_t i; - (void)cls; + (void) cls; req_handle = NULL; for (i = 0; i < n; i++) - { - fprintf(stdout, "%s\n", - GNUNET_i2s_full(&recv_peers[i])); - } + { + fprintf (stdout, "%s\n", + GNUNET_i2s_full (&recv_peers[i])); + } ret = 0; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } /** @@ -114,34 +114,34 @@ reply_handle(void *cls, * @param recv_peers the received peers */ static void -view_update_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +view_update_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { uint64_t i; - (void)cls; + (void) cls; if (0 == n) - { - fprintf(stdout, "Empty view\n"); - } + { + fprintf (stdout, "Empty view\n"); + } req_handle = NULL; for (i = 0; i < n; i++) - { - fprintf(stdout, "%s\n", - GNUNET_i2s_full(&recv_peers[i])); - } + { + fprintf (stdout, "%s\n", + GNUNET_i2s_full (&recv_peers[i])); + } if (1 == num_view_updates) - { - ret = 0; - GNUNET_SCHEDULER_shutdown(); - } + { + ret = 0; + GNUNET_SCHEDULER_shutdown (); + } else if (1 < num_view_updates) - { - num_view_updates--; - } + { + num_view_updates--; + } } @@ -152,24 +152,24 @@ view_update_handle(void *cls, * @param recv_peers the received peers */ static void -stream_input_handle(void *cls, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *recv_peers) +stream_input_handle (void *cls, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *recv_peers) { uint64_t i; - (void)cls; + (void) cls; if (0 == num_peers) - { - fprintf(stdout, "No peer was returned\n"); - } + { + fprintf (stdout, "No peer was returned\n"); + } req_handle = NULL; for (i = 0; i < num_peers; i++) - { - fprintf(stdout, "%s\n", - GNUNET_i2s_full(&recv_peers[i])); - } + { + fprintf (stdout, "%s\n", + GNUNET_i2s_full (&recv_peers[i])); + } } @@ -182,69 +182,71 @@ stream_input_handle(void *cls, * @param cfg configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { static uint64_t num_peers; static struct GNUNET_PeerIdentity zero_pid; - (void)cls; - (void)cfgfile; + (void) cls; + (void) cfgfile; - rps_handle = GNUNET_RPS_connect(cfg); + rps_handle = GNUNET_RPS_connect (cfg); if (NULL == rps_handle) - { - fprintf(stderr, "Failed to connect to the rps service\n"); - return; - } - - if ((0 == memcmp(&zero_pid, &peer_id, sizeof(peer_id))) && - (!view_update) && - (!stream_input)) - { /* Request n PeerIDs */ + { + fprintf (stderr, "Failed to connect to the rps service\n"); + return; + } + + if ((0 == memcmp (&zero_pid, &peer_id, sizeof(peer_id))) && + (! view_update) && + (! stream_input)) + { /* Request n PeerIDs */ /* If number was specified use it, else request single peer. */ - if (NULL == args[0] || - 0 == sscanf(args[0], "%lu", &num_peers)) - { - num_peers = 1; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting %" PRIu64 " PeerIDs\n", num_peers); - req_handle = GNUNET_RPS_request_peers(rps_handle, num_peers, reply_handle, NULL); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + if ((NULL == args[0]) || + (0 == sscanf (args[0], "%lu", &num_peers)) ) + { + num_peers = 1; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting %" PRIu64 " PeerIDs\n", num_peers); + req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, + NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + } else if (view_update) + { + /* Get updates of view */ + if ((NULL == args[0]) || + (0 == sscanf (args[0], "%lu", &num_view_updates)) ) { - /* Get updates of view */ - if (NULL == args[0] || - 0 == sscanf(args[0], "%lu", &num_view_updates)) - { - num_view_updates = 0; - } - GNUNET_RPS_view_request(rps_handle, num_view_updates, view_update_handle, NULL); - if (0 != num_view_updates) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting %" PRIu64 " view updates\n", num_view_updates); - else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting continuous view updates\n"); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + num_view_updates = 0; } + GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle, + NULL); + if (0 != num_view_updates) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting %" PRIu64 " view updates\n", num_view_updates); + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting continuous view updates\n"); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + } else if (stream_input) - { - /* Get updates of view */ - GNUNET_RPS_stream_request(rps_handle, stream_input_handle, NULL); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); - } + { + /* Get updates of view */ + GNUNET_RPS_stream_request (rps_handle, stream_input_handle, NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + } else - { /* Seed PeerID */ - GNUNET_RPS_seed_ids(rps_handle, 1, &peer_id); - fprintf(stdout, "Seeded PeerID %s\n", GNUNET_i2s_full(&peer_id)); - ret = 0; - GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); - } + { /* Seed PeerID */ + GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id); + fprintf (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id)); + ret = 0; + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + } } /** @@ -255,34 +257,35 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { const char helpstr[] = "Get random GNUnet peers. If none is specified a single is requested."; struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_base32_auto('s', - "seed", - "PEER_ID", - gettext_noop("Seed a PeerID"), - &peer_id), - GNUNET_GETOPT_option_flag('V', - "view", - gettext_noop("Get updates of view (0 for infinite updates)"), - &view_update), - GNUNET_GETOPT_option_flag('S', - "stream", - gettext_noop("Get peers from biased stream"), - &stream_input), + GNUNET_GETOPT_option_base32_auto ('s', + "seed", + "PEER_ID", + gettext_noop ("Seed a PeerID"), + &peer_id), + GNUNET_GETOPT_option_flag ('V', + "view", + gettext_noop ( + "Get updates of view (0 for infinite updates)"), + &view_update), + GNUNET_GETOPT_option_flag ('S', + "stream", + gettext_noop ("Get peers from biased stream"), + &stream_input), GNUNET_GETOPT_OPTION_END }; return (GNUNET_OK == - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-rps [NUMBER_OF_PEERS]", - gettext_noop - (helpstr), - options, &run, NULL)) ? ret : 1; + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-rps [NUMBER_OF_PEERS]", + gettext_noop + (helpstr), + options, &run, NULL)) ? ret : 1; } /* end of gnunet-rps.c */ diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 32f3103ed..66ffd173a 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -41,7 +41,7 @@ #include <inttypes.h> #include <string.h> -#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) // TODO check for overflows @@ -92,7 +92,8 @@ * When an operation cannot be executed right now this struct is used to store * the callback and closure for later execution. */ -struct PeerPendingOp { +struct PeerPendingOp +{ /** * Callback */ @@ -110,7 +111,8 @@ struct PeerPendingOp { * This is used to keep track of all messages that have not been sent yet. When * a peer is to be removed the pending messages can be removed properly. */ -struct PendingMessage { +struct PendingMessage +{ /** * DLL next, prev */ @@ -146,7 +148,8 @@ struct ChannelCtx; * status about the channels, the pending operations on this peer and some flags * about the status of the peer itself. (online, valid, ...) */ -struct PeerContext { +struct PeerContext +{ /** * The Sub this context belongs to. */ @@ -221,7 +224,8 @@ struct PeerContext { /** * @brief Closure to #valid_peer_iterator */ -struct PeersIteratorCls { +struct PeersIteratorCls +{ /** * Iterator function */ @@ -236,7 +240,8 @@ struct PeersIteratorCls { /** * @brief Context for a channel */ -struct ChannelCtx { +struct ChannelCtx +{ /** * @brief The channel itself */ @@ -261,7 +266,8 @@ struct ChannelCtx { /** * If type is 2 This struct is used to store the attacked peers in a DLL */ -struct AttackedPeer { +struct AttackedPeer +{ /** * DLL */ @@ -296,7 +302,8 @@ struct AttackedPeer { * Essentially one instance of brahms that only connects to other instances * with the same (secret) value. */ -struct Sub { +struct Sub +{ /** * @brief Hash of the shared value that defines Subs. */ @@ -588,10 +595,10 @@ static const uint32_t num_valid_peers_max = UINT32_MAX; static void -do_round(void *cls); +do_round (void *cls); static void -do_mal_round(void *cls); +do_mal_round (void *cls); /** @@ -603,16 +610,16 @@ do_mal_round(void *cls); * @return the #PeerContext */ static struct PeerContext * -get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, - const struct GNUNET_PeerIdentity *peer) +get_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, + const struct GNUNET_PeerIdentity *peer) { struct PeerContext *ctx; int ret; - ret = GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); - GNUNET_assert(GNUNET_YES == ret); - ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); - GNUNET_assert(NULL != ctx); + ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); + GNUNET_assert (GNUNET_YES == ret); + ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); + GNUNET_assert (NULL != ctx); return ctx; } @@ -628,17 +635,17 @@ get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, * #GNUNET_NO if peer is not knwon */ static int -check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, - const struct GNUNET_PeerIdentity *peer) +check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, + const struct GNUNET_PeerIdentity *peer) { if (NULL != peer_map) - { - return GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); - } + { + return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); + } else - { - return GNUNET_NO; - } + { + return GNUNET_NO; + } } @@ -651,27 +658,27 @@ check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, * @return the #PeerContext */ static struct PeerContext * -create_peer_ctx(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +create_peer_ctx (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { struct PeerContext *ctx; int ret; - GNUNET_assert(GNUNET_NO == check_peer_known(sub->peer_map, peer)); + GNUNET_assert (GNUNET_NO == check_peer_known (sub->peer_map, peer)); - ctx = GNUNET_new(struct PeerContext); + ctx = GNUNET_new (struct PeerContext); ctx->peer_id = *peer; ctx->sub = sub; - ret = GNUNET_CONTAINER_multipeermap_put(sub->peer_map, peer, ctx, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); - GNUNET_assert(GNUNET_OK == ret); + ret = GNUNET_CONTAINER_multipeermap_put (sub->peer_map, peer, ctx, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_assert (GNUNET_OK == ret); if (sub == msub) - { - GNUNET_STATISTICS_set(stats, - "# known peers", - GNUNET_CONTAINER_multipeermap_size(sub->peer_map), - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "# known peers", + GNUNET_CONTAINER_multipeermap_size (sub->peer_map), + GNUNET_NO); + } return ctx; } @@ -685,14 +692,14 @@ create_peer_ctx(struct Sub *sub, * @return the context */ static struct PeerContext * -create_or_get_peer_ctx(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +create_or_get_peer_ctx (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { - if (GNUNET_NO == check_peer_known(sub->peer_map, peer)) - { - return create_peer_ctx(sub, peer); - } - return get_peer_ctx(sub->peer_map, peer); + if (GNUNET_NO == check_peer_known (sub->peer_map, peer)) + { + return create_peer_ctx (sub, peer); + } + return get_peer_ctx (sub->peer_map, peer); } @@ -707,25 +714,25 @@ create_or_get_peer_ctx(struct Sub *sub, * #GNUNET_NO otherwise */ static int -check_connected(struct PeerContext *peer_ctx) +check_connected (struct PeerContext *peer_ctx) { /* If we don't know about this peer we don't know whether it's online */ - if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - return GNUNET_NO; - } + if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + return GNUNET_NO; + } /* Get the context */ - peer_ctx = get_peer_ctx(peer_ctx->sub->peer_map, &peer_ctx->peer_id); + peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id); /* If we have no channel to this peer we don't know whether it's online */ if ((NULL == peer_ctx->send_channel_ctx) && (NULL == peer_ctx->recv_channel_ctx)) - { - UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); - return GNUNET_NO; - } + { + UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); + return GNUNET_NO; + } /* Otherwise (if we have a channel, we know that it's online */ - SET_PEER_FLAG(peer_ctx, Peers_ONLINE); + SET_PEER_FLAG (peer_ctx, Peers_ONLINE); return GNUNET_YES; } @@ -733,7 +740,8 @@ check_connected(struct PeerContext *peer_ctx) /** * @brief The closure to #get_rand_peer_iterator. */ -struct GetRandPeerIteratorCls { +struct GetRandPeerIteratorCls +{ /** * @brief The index of the peer to return. * Will be decreased until 0. @@ -764,19 +772,19 @@ struct GetRandPeerIteratorCls { * #GNUNET_NO if not. */ static int -get_rand_peer_iterator(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +get_rand_peer_iterator (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct GetRandPeerIteratorCls *iterator_cls = cls; - (void)value; + (void) value; if (0 >= iterator_cls->index) - { - iterator_cls->peer = peer; - return GNUNET_NO; - } + { + iterator_cls->peer = peer; + return GNUNET_NO; + } iterator_cls->index--; return GNUNET_YES; } @@ -791,19 +799,20 @@ get_rand_peer_iterator(void *cls, * @return a random peer */ static const struct GNUNET_PeerIdentity * -get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) +get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) { struct GetRandPeerIteratorCls *iterator_cls; const struct GNUNET_PeerIdentity *ret; - iterator_cls = GNUNET_new(struct GetRandPeerIteratorCls); - iterator_cls->index = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - GNUNET_CONTAINER_multipeermap_size(valid_peers)); - (void)GNUNET_CONTAINER_multipeermap_iterate(valid_peers, - get_rand_peer_iterator, - iterator_cls); + iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls); + iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + GNUNET_CONTAINER_multipeermap_size ( + valid_peers)); + (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers, + get_rand_peer_iterator, + iterator_cls); ret = iterator_cls->peer; - GNUNET_free(iterator_cls); + GNUNET_free (iterator_cls); return ret; } @@ -820,8 +829,8 @@ get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) * #GNUNET_NO otherwise */ static int -add_valid_peer(const struct GNUNET_PeerIdentity *peer, - struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) +add_valid_peer (const struct GNUNET_PeerIdentity *peer, + struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) { const struct GNUNET_PeerIdentity *rand_peer; int ret; @@ -829,26 +838,26 @@ add_valid_peer(const struct GNUNET_PeerIdentity *peer, ret = GNUNET_YES; /* Remove random peers until there is space for a new one */ while (num_valid_peers_max <= - GNUNET_CONTAINER_multipeermap_size(valid_peers)) - { - rand_peer = get_random_peer_from_peermap(valid_peers); - GNUNET_CONTAINER_multipeermap_remove_all(valid_peers, rand_peer); - ret = GNUNET_NO; - } - (void)GNUNET_CONTAINER_multipeermap_put(valid_peers, peer, NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_multipeermap_size (valid_peers)) + { + rand_peer = get_random_peer_from_peermap (valid_peers); + GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer); + ret = GNUNET_NO; + } + (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); if (valid_peers == msub->valid_peers) - { - GNUNET_STATISTICS_set(stats, - "# valid peers", - GNUNET_CONTAINER_multipeermap_size(valid_peers), - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "# valid peers", + GNUNET_CONTAINER_multipeermap_size (valid_peers), + GNUNET_NO); + } return ret; } static void -remove_pending_message(struct PendingMessage *pending_msg, int cancel); +remove_pending_message (struct PendingMessage *pending_msg, int cancel); /** * @brief Set the peer flag to living and @@ -859,62 +868,62 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel); * @param peer_ctx the #PeerContext of the peer to set online */ static void -set_peer_online(struct PeerContext *peer_ctx) +set_peer_online (struct PeerContext *peer_ctx) { struct GNUNET_PeerIdentity *peer; unsigned int i; peer = &peer_ctx->peer_id; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer %s is online and valid, calling %i pending operations on it\n", - GNUNET_i2s(peer), - peer_ctx->num_pending_ops); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer %s is online and valid, calling %i pending operations on it\n", + GNUNET_i2s (peer), + peer_ctx->num_pending_ops); if (NULL != peer_ctx->online_check_pending) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Removing pending online check for peer %s\n", - GNUNET_i2s(&peer_ctx->peer_id)); - // TODO wait until cadet sets mq->cancel_impl - //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); - remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); - peer_ctx->online_check_pending = NULL; - } - - SET_PEER_FLAG(peer_ctx, Peers_ONLINE); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Removing pending online check for peer %s\n", + GNUNET_i2s (&peer_ctx->peer_id)); + // TODO wait until cadet sets mq->cancel_impl + // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); + remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); + peer_ctx->online_check_pending = NULL; + } + + SET_PEER_FLAG (peer_ctx, Peers_ONLINE); /* Call pending operations */ for (i = 0; i < peer_ctx->num_pending_ops; i++) - { - peer_ctx->pending_ops[i].op(peer_ctx->pending_ops[i].op_cls, peer); - } - GNUNET_array_grow(peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); + { + peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer); + } + GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); } static void -cleanup_destroyed_channel(void *cls, - const struct GNUNET_CADET_Channel *channel); +cleanup_destroyed_channel (void *cls, + const struct GNUNET_CADET_Channel *channel); /* Declaration of handlers */ static void -handle_peer_check(void *cls, - const struct GNUNET_MessageHeader *msg); +handle_peer_check (void *cls, + const struct GNUNET_MessageHeader *msg); static void -handle_peer_push(void *cls, - const struct GNUNET_MessageHeader *msg); +handle_peer_push (void *cls, + const struct GNUNET_MessageHeader *msg); static void -handle_peer_pull_request(void *cls, - const struct GNUNET_MessageHeader *msg); +handle_peer_pull_request (void *cls, + const struct GNUNET_MessageHeader *msg); static int -check_peer_pull_reply(void *cls, - const struct GNUNET_RPS_P2P_PullReplyMessage *msg); +check_peer_pull_reply (void *cls, + const struct GNUNET_RPS_P2P_PullReplyMessage *msg); static void -handle_peer_pull_reply(void *cls, - const struct GNUNET_RPS_P2P_PullReplyMessage *msg); +handle_peer_pull_reply (void *cls, + const struct GNUNET_RPS_P2P_PullReplyMessage *msg); /* End declaration of handlers */ @@ -926,11 +935,11 @@ handle_peer_pull_reply(void *cls, * @return The channel context */ static struct ChannelCtx * -add_channel_ctx(struct PeerContext *peer_ctx) +add_channel_ctx (struct PeerContext *peer_ctx) { struct ChannelCtx *channel_ctx; - channel_ctx = GNUNET_new(struct ChannelCtx); + channel_ctx = GNUNET_new (struct ChannelCtx); channel_ctx->peer_ctx = peer_ctx; return channel_ctx; } @@ -942,29 +951,29 @@ add_channel_ctx(struct PeerContext *peer_ctx) * @param channel_ctx The channel context. */ static void -remove_channel_ctx(struct ChannelCtx *channel_ctx) +remove_channel_ctx (struct ChannelCtx *channel_ctx) { struct PeerContext *peer_ctx = channel_ctx->peer_ctx; if (NULL != channel_ctx->destruction_task) - { - GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); - channel_ctx->destruction_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); + channel_ctx->destruction_task = NULL; + } - GNUNET_free(channel_ctx); + GNUNET_free (channel_ctx); if (NULL == peer_ctx) return; if (channel_ctx == peer_ctx->send_channel_ctx) - { - peer_ctx->send_channel_ctx = NULL; - peer_ctx->mq = NULL; - } + { + peer_ctx->send_channel_ctx = NULL; + peer_ctx->mq = NULL; + } else if (channel_ctx == peer_ctx->recv_channel_ctx) - { - peer_ctx->recv_channel_ctx = NULL; - } + { + peer_ctx->recv_channel_ctx = NULL; + } } @@ -975,47 +984,47 @@ remove_channel_ctx(struct ChannelCtx *channel_ctx) * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx */ struct GNUNET_CADET_Channel * -get_channel(struct PeerContext *peer_ctx) +get_channel (struct PeerContext *peer_ctx) { /* There exists a copy-paste-clone in run() */ struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_fixed_size(peer_check, - GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size(peer_push, - GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size(peer_pull_request, - GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size(peer_pull_reply, - GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, - struct GNUNET_RPS_P2P_PullReplyMessage, - NULL), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_fixed_size (peer_check, + GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (peer_push, + GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (peer_pull_request, + GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (peer_pull_reply, + GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, + struct GNUNET_RPS_P2P_PullReplyMessage, + NULL), + GNUNET_MQ_handler_end () }; if (NULL == peer_ctx->send_channel_ctx) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Trying to establish channel to peer %s\n", - GNUNET_i2s(&peer_ctx->peer_id)); - peer_ctx->send_channel_ctx = add_channel_ctx(peer_ctx); - peer_ctx->send_channel_ctx->channel = - GNUNET_CADET_channel_create(cadet_handle, - peer_ctx->send_channel_ctx, /* context */ - &peer_ctx->peer_id, - &peer_ctx->sub->hash, - NULL, /* WindowSize handler */ - &cleanup_destroyed_channel, /* Disconnect handler */ - cadet_handlers); - } - GNUNET_assert(NULL != peer_ctx->send_channel_ctx); - GNUNET_assert(NULL != peer_ctx->send_channel_ctx->channel); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to establish channel to peer %s\n", + GNUNET_i2s (&peer_ctx->peer_id)); + peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); + peer_ctx->send_channel_ctx->channel = + GNUNET_CADET_channel_create (cadet_handle, + peer_ctx->send_channel_ctx, /* context */ + &peer_ctx->peer_id, + &peer_ctx->sub->hash, + NULL, /* WindowSize handler */ + &cleanup_destroyed_channel, /* Disconnect handler */ + cadet_handlers); + } + GNUNET_assert (NULL != peer_ctx->send_channel_ctx); + GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); return peer_ctx->send_channel_ctx->channel; } @@ -1030,12 +1039,12 @@ get_channel(struct PeerContext *peer_ctx) * @return the #GNUNET_MQ_Handle */ static struct GNUNET_MQ_Handle * -get_mq(struct PeerContext *peer_ctx) +get_mq (struct PeerContext *peer_ctx) { if (NULL == peer_ctx->mq) - { - peer_ctx->mq = GNUNET_CADET_get_mq(get_channel(peer_ctx)); - } + { + peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx)); + } return peer_ctx->mq; } @@ -1048,19 +1057,19 @@ get_mq(struct PeerContext *peer_ctx) * @return pointer to pending message */ static struct PendingMessage * -insert_pending_message(struct PeerContext *peer_ctx, - struct GNUNET_MQ_Envelope *ev, - const char *type) +insert_pending_message (struct PeerContext *peer_ctx, + struct GNUNET_MQ_Envelope *ev, + const char *type) { struct PendingMessage *pending_msg; - pending_msg = GNUNET_new(struct PendingMessage); + pending_msg = GNUNET_new (struct PendingMessage); pending_msg->ev = ev; pending_msg->peer_ctx = peer_ctx; pending_msg->type = type; - GNUNET_CONTAINER_DLL_insert(peer_ctx->pending_messages_head, - peer_ctx->pending_messages_tail, - pending_msg); + GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head, + peer_ctx->pending_messages_tail, + pending_msg); return pending_msg; } @@ -1072,23 +1081,23 @@ insert_pending_message(struct PeerContext *peer_ctx, * @param cancel whether to cancel the pending message, too */ static void -remove_pending_message(struct PendingMessage *pending_msg, int cancel) +remove_pending_message (struct PendingMessage *pending_msg, int cancel) { struct PeerContext *peer_ctx; - (void)cancel; + (void) cancel; peer_ctx = pending_msg->peer_ctx; - GNUNET_assert(NULL != peer_ctx); - GNUNET_CONTAINER_DLL_remove(peer_ctx->pending_messages_head, - peer_ctx->pending_messages_tail, - pending_msg); + GNUNET_assert (NULL != peer_ctx); + GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head, + peer_ctx->pending_messages_tail, + pending_msg); // TODO wait for the cadet implementation of message cancellation - //if (GNUNET_YES == cancel) - //{ + // if (GNUNET_YES == cancel) + // { // GNUNET_MQ_send_cancel (pending_msg->ev); - //} - GNUNET_free(pending_msg); + // } + GNUNET_free (pending_msg); } @@ -1099,20 +1108,20 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel) * @param cls #PeerContext of peer with pending online check */ static void -mq_online_check_successful(void *cls) +mq_online_check_successful (void *cls) { struct PeerContext *peer_ctx = cls; if (NULL != peer_ctx->online_check_pending) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Online check for peer %s was successfull\n", - GNUNET_i2s(&peer_ctx->peer_id)); - remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); - peer_ctx->online_check_pending = NULL; - set_peer_online(peer_ctx); - (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Online check for peer %s was successfull\n", + GNUNET_i2s (&peer_ctx->peer_id)); + remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); + peer_ctx->online_check_pending = NULL; + set_peer_online (peer_ctx); + (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); + } } /** @@ -1121,30 +1130,30 @@ mq_online_check_successful(void *cls) * @param peer_ctx the context of the peer */ static void -check_peer_online(struct PeerContext *peer_ctx) +check_peer_online (struct PeerContext *peer_ctx) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Get informed about peer %s getting online\n", - GNUNET_i2s(&peer_ctx->peer_id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Get informed about peer %s getting online\n", + GNUNET_i2s (&peer_ctx->peer_id)); struct GNUNET_MQ_Handle *mq; struct GNUNET_MQ_Envelope *ev; - ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); peer_ctx->online_check_pending = - insert_pending_message(peer_ctx, ev, "Check online"); - mq = get_mq(peer_ctx); - GNUNET_MQ_notify_sent(ev, - mq_online_check_successful, - peer_ctx); - GNUNET_MQ_send(mq, ev); + insert_pending_message (peer_ctx, ev, "Check online"); + mq = get_mq (peer_ctx); + GNUNET_MQ_notify_sent (ev, + mq_online_check_successful, + peer_ctx); + GNUNET_MQ_send (mq, ev); if (peer_ctx->sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# pending online checks", - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (stats, + "# pending online checks", + 1, + GNUNET_NO); + } } @@ -1161,8 +1170,8 @@ check_peer_online(struct PeerContext *peer_ctx) * #GNUNET_NO otherwise */ static int -check_operation_scheduled(const struct PeerContext *peer_ctx, - const PeerOp peer_op) +check_operation_scheduled (const struct PeerContext *peer_ctx, + const PeerOp peer_op) { unsigned int i; @@ -1179,20 +1188,20 @@ check_operation_scheduled(const struct PeerContext *peer_ctx, * @param cls Context of the channel */ static void -destroy_channel(struct ChannelCtx *channel_ctx) +destroy_channel (struct ChannelCtx *channel_ctx) { struct GNUNET_CADET_Channel *channel; if (NULL != channel_ctx->destruction_task) - { - GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); - channel_ctx->destruction_task = NULL; - } - GNUNET_assert(channel_ctx->channel != NULL); + { + GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); + channel_ctx->destruction_task = NULL; + } + GNUNET_assert (channel_ctx->channel != NULL); channel = channel_ctx->channel; channel_ctx->channel = NULL; - GNUNET_CADET_channel_destroy(channel); - remove_channel_ctx(channel_ctx); + GNUNET_CADET_channel_destroy (channel); + remove_channel_ctx (channel_ctx); } @@ -1204,12 +1213,12 @@ destroy_channel(struct ChannelCtx *channel_ctx) * @param cls */ static void -destroy_channel_cb(void *cls) +destroy_channel_cb (void *cls) { struct ChannelCtx *channel_ctx = cls; channel_ctx->destruction_task = NULL; - destroy_channel(channel_ctx); + destroy_channel (channel_ctx); } @@ -1224,15 +1233,15 @@ destroy_channel_cb(void *cls) * @param channel_ctx channel to be destroyed. */ static void -schedule_channel_destruction(struct ChannelCtx *channel_ctx) +schedule_channel_destruction (struct ChannelCtx *channel_ctx) { - GNUNET_assert(NULL == - channel_ctx->destruction_task); - GNUNET_assert(NULL != - channel_ctx->channel); + GNUNET_assert (NULL == + channel_ctx->destruction_task); + GNUNET_assert (NULL != + channel_ctx->channel); channel_ctx->destruction_task = - GNUNET_SCHEDULER_add_now(&destroy_channel_cb, - channel_ctx); + GNUNET_SCHEDULER_add_now (&destroy_channel_cb, + channel_ctx); } @@ -1250,98 +1259,99 @@ schedule_channel_destruction(struct ChannelCtx *channel_ctx) * #GNUNET_NO otherwise */ static int -destroy_peer(struct PeerContext *peer_ctx) +destroy_peer (struct PeerContext *peer_ctx) { - GNUNET_assert(NULL != peer_ctx); - GNUNET_assert(NULL != peer_ctx->sub->peer_map); + GNUNET_assert (NULL != peer_ctx); + GNUNET_assert (NULL != peer_ctx->sub->peer_map); if (GNUNET_NO == - GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - return GNUNET_NO; - } - SET_PEER_FLAG(peer_ctx, Peers_TO_DESTROY); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to remove peer %s\n", - GNUNET_i2s(&peer_ctx->peer_id)); - UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); + GNUNET_CONTAINER_multipeermap_contains (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + return GNUNET_NO; + } + SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to remove peer %s\n", + GNUNET_i2s (&peer_ctx->peer_id)); + UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); /* Clear list of pending operations */ // TODO this probably leaks memory // ('only' the cls to the function. Not sure what to do with it) - GNUNET_array_grow(peer_ctx->pending_ops, - peer_ctx->num_pending_ops, - 0); + GNUNET_array_grow (peer_ctx->pending_ops, + peer_ctx->num_pending_ops, + 0); /* Remove all pending messages */ while (NULL != peer_ctx->pending_messages_head) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Removing unsent %s\n", + peer_ctx->pending_messages_head->type); + /* Cancle pending message, too */ + if ((NULL != peer_ctx->online_check_pending) && + (0 == memcmp (peer_ctx->pending_messages_head, + peer_ctx->online_check_pending, + sizeof(struct PendingMessage)))) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Removing unsent %s\n", - peer_ctx->pending_messages_head->type); - /* Cancle pending message, too */ - if ((NULL != peer_ctx->online_check_pending) && - (0 == memcmp(peer_ctx->pending_messages_head, - peer_ctx->online_check_pending, - sizeof(struct PendingMessage)))) - { - peer_ctx->online_check_pending = NULL; - if (peer_ctx->sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# pending online checks", - -1, - GNUNET_NO); - } - } - remove_pending_message(peer_ctx->pending_messages_head, - GNUNET_YES); - } + peer_ctx->online_check_pending = NULL; + if (peer_ctx->sub == msub) + { + GNUNET_STATISTICS_update (stats, + "# pending online checks", + -1, + GNUNET_NO); + } + } + remove_pending_message (peer_ctx->pending_messages_head, + GNUNET_YES); + } /* If we are still waiting for notification whether this peer is online * cancel the according task */ if (NULL != peer_ctx->online_check_pending) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Removing pending online check for peer %s\n", - GNUNET_i2s(&peer_ctx->peer_id)); - // TODO wait until cadet sets mq->cancel_impl - //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); - remove_pending_message(peer_ctx->online_check_pending, - GNUNET_YES); - peer_ctx->online_check_pending = NULL; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Removing pending online check for peer %s\n", + GNUNET_i2s (&peer_ctx->peer_id)); + // TODO wait until cadet sets mq->cancel_impl + // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); + remove_pending_message (peer_ctx->online_check_pending, + GNUNET_YES); + peer_ctx->online_check_pending = NULL; + } if (NULL != peer_ctx->send_channel_ctx) - { - /* This is possibly called from within channel destruction */ - peer_ctx->send_channel_ctx->peer_ctx = NULL; - schedule_channel_destruction(peer_ctx->send_channel_ctx); - peer_ctx->send_channel_ctx = NULL; - peer_ctx->mq = NULL; - } + { + /* This is possibly called from within channel destruction */ + peer_ctx->send_channel_ctx->peer_ctx = NULL; + schedule_channel_destruction (peer_ctx->send_channel_ctx); + peer_ctx->send_channel_ctx = NULL; + peer_ctx->mq = NULL; + } if (NULL != peer_ctx->recv_channel_ctx) - { - /* This is possibly called from within channel destruction */ - peer_ctx->recv_channel_ctx->peer_ctx = NULL; - schedule_channel_destruction(peer_ctx->recv_channel_ctx); - peer_ctx->recv_channel_ctx = NULL; - } + { + /* This is possibly called from within channel destruction */ + peer_ctx->recv_channel_ctx->peer_ctx = NULL; + schedule_channel_destruction (peer_ctx->recv_channel_ctx); + peer_ctx->recv_channel_ctx = NULL; + } if (GNUNET_YES != - GNUNET_CONTAINER_multipeermap_remove_all(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "removing peer from peer_ctx->sub->peer_map failed\n"); - } + GNUNET_CONTAINER_multipeermap_remove_all (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "removing peer from peer_ctx->sub->peer_map failed\n"); + } if (peer_ctx->sub == msub) - { - GNUNET_STATISTICS_set(stats, - "# known peers", - GNUNET_CONTAINER_multipeermap_size(peer_ctx->sub->peer_map), - GNUNET_NO); - } - GNUNET_free(peer_ctx); + { + GNUNET_STATISTICS_set (stats, + "# known peers", + GNUNET_CONTAINER_multipeermap_size ( + peer_ctx->sub->peer_map), + GNUNET_NO); + } + GNUNET_free (peer_ctx); return GNUNET_YES; } @@ -1356,15 +1366,15 @@ destroy_peer(struct PeerContext *peer_ctx) * #GNUNET_NO if not. */ static int -peermap_clear_iterator(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +peermap_clear_iterator (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Sub *sub = cls; - (void)value; + (void) value; - destroy_peer(get_peer_ctx(sub->peer_map, key)); + destroy_peer (get_peer_ctx (sub->peer_map, key)); return GNUNET_YES; } @@ -1377,32 +1387,33 @@ peermap_clear_iterator(void *cls, * @param cls type of the message that was sent */ static void -mq_notify_sent_cb(void *cls) +mq_notify_sent_cb (void *cls) { - struct PendingMessage *pending_msg = (struct PendingMessage *)cls; + struct PendingMessage *pending_msg = (struct PendingMessage *) cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%s was sent.\n", - pending_msg->type); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%s was sent.\n", + pending_msg->type); if (pending_msg->peer_ctx->sub == msub) - { - if (0 == strncmp("PULL REPLY", pending_msg->type, 10)) - GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO); - if (0 == strncmp("PULL REQUEST", pending_msg->type, 12)) - GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); - if (0 == strncmp("PUSH", pending_msg->type, 4)) - GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); - if (0 == strncmp("PULL REQUEST", pending_msg->type, 12) && - NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - &pending_msg->peer_ctx->peer_id)) - GNUNET_STATISTICS_update(stats, - "# pull requests sent (multi-hop peer)", - 1, - GNUNET_NO); - } + { + if (0 == strncmp ("PULL REPLY", pending_msg->type, 10)) + GNUNET_STATISTICS_update (stats, "# pull replys sent", 1, GNUNET_NO); + if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) + GNUNET_STATISTICS_update (stats, "# pull requests sent", 1, GNUNET_NO); + if (0 == strncmp ("PUSH", pending_msg->type, 4)) + GNUNET_STATISTICS_update (stats, "# pushes sent", 1, GNUNET_NO); + if ((0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) && + (NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + &pending_msg-> + peer_ctx->peer_id)) ) + GNUNET_STATISTICS_update (stats, + "# pull requests sent (multi-hop peer)", + 1, + GNUNET_NO); + } /* Do not cancle message */ - remove_pending_message(pending_msg, GNUNET_NO); + remove_pending_message (pending_msg, GNUNET_NO); } @@ -1421,30 +1432,30 @@ mq_notify_sent_cb(void *cls) * #GNUNET_NO if not. */ static int -store_peer_presistently_iterator(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +store_peer_presistently_iterator (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { const struct GNUNET_DISK_FileHandle *fh = cls; char peer_string[128]; int size; ssize_t ret; - (void)value; + (void) value; if (NULL == peer) - { - return GNUNET_YES; - } - size = GNUNET_snprintf(peer_string, - sizeof(peer_string), - "%s\n", - GNUNET_i2s_full(peer)); - GNUNET_assert(53 == size); - ret = GNUNET_DISK_file_write(fh, - peer_string, - size); - GNUNET_assert(size == ret); + { + return GNUNET_YES; + } + size = GNUNET_snprintf (peer_string, + sizeof(peer_string), + "%s\n", + GNUNET_i2s_full (peer)); + GNUNET_assert (53 == size); + ret = GNUNET_DISK_file_write (fh, + peer_string, + size); + GNUNET_assert (size == ret); return GNUNET_YES; } @@ -1455,54 +1466,54 @@ store_peer_presistently_iterator(void *cls, * @param sub Sub for which to store the valid peers */ static void -store_valid_peers(const struct Sub *sub) +store_valid_peers (const struct Sub *sub) { struct GNUNET_DISK_FileHandle *fh; uint32_t number_written_peers; int ret; - if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) - { - return; - } + if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) + { + return; + } - ret = GNUNET_DISK_directory_create_for_file(sub->filename_valid_peers); + ret = GNUNET_DISK_directory_create_for_file (sub->filename_valid_peers); if (GNUNET_SYSERR == ret) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to create directory for file `%s'\n", - sub->filename_valid_peers); - GNUNET_break(0); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to create directory for file `%s'\n", + sub->filename_valid_peers); + GNUNET_break (0); + } else if (GNUNET_NO == ret) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Directory for file `%s' exists but is not writable for us\n", - sub->filename_valid_peers); - GNUNET_break(0); - } - fh = GNUNET_DISK_file_open(sub->filename_valid_peers, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Directory for file `%s' exists but is not writable for us\n", + sub->filename_valid_peers); + GNUNET_break (0); + } + fh = GNUNET_DISK_file_open (sub->filename_valid_peers, + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == fh) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to write valid peers to file `%s'\n", - sub->filename_valid_peers); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Writing %u valid peers to disk\n", - GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to write valid peers to file `%s'\n", + sub->filename_valid_peers); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Writing %u valid peers to disk\n", + GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); number_written_peers = - GNUNET_CONTAINER_multipeermap_iterate(sub->valid_peers, - store_peer_presistently_iterator, - fh); - GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); - GNUNET_assert(number_written_peers == - GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); + GNUNET_CONTAINER_multipeermap_iterate (sub->valid_peers, + store_peer_presistently_iterator, + fh); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); + GNUNET_assert (number_written_peers == + GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); } @@ -1516,38 +1527,38 @@ store_valid_peers(const struct Sub *sub) * @return The peer id */ static const struct GNUNET_PeerIdentity * -s2i_full(const char *string_repr) +s2i_full (const char *string_repr) { struct GNUNET_PeerIdentity *peer; size_t len; int ret; - peer = GNUNET_new(struct GNUNET_PeerIdentity); - len = strlen(string_repr); + peer = GNUNET_new (struct GNUNET_PeerIdentity); + len = strlen (string_repr); if (52 > len) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to convert string representation of PeerID to PeerID\n" - "Sting representation: %s (len %lu) - too short\n", - string_repr, - len); - GNUNET_break(0); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to convert string representation of PeerID to PeerID\n" + "Sting representation: %s (len %lu) - too short\n", + string_repr, + len); + GNUNET_break (0); + } else if (52 < len) - { - len = 52; - } - ret = GNUNET_CRYPTO_eddsa_public_key_from_string(string_repr, - len, - &peer->public_key); + { + len = 52; + } + ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr, + len, + &peer->public_key); if (GNUNET_OK != ret) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to convert string representation of PeerID to PeerID\n" - "Sting representation: %s\n", - string_repr); - GNUNET_break(0); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to convert string representation of PeerID to PeerID\n" + "Sting representation: %s\n", + string_repr); + GNUNET_break (0); + } return peer; } @@ -1558,7 +1569,7 @@ s2i_full(const char *string_repr) * @param sub Sub for which to restore the valid peers */ static void -restore_valid_peers(const struct Sub *sub) +restore_valid_peers (const struct Sub *sub) { off_t file_size; uint32_t num_peers; @@ -1569,53 +1580,53 @@ restore_valid_peers(const struct Sub *sub) char *str_repr; const struct GNUNET_PeerIdentity *peer; - if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) - { - return; - } + if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) + { + return; + } - if (GNUNET_OK != GNUNET_DISK_file_test(sub->filename_valid_peers)) - { - return; - } - fh = GNUNET_DISK_file_open(sub->filename_valid_peers, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - GNUNET_assert(NULL != fh); - GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_handle_size(fh, &file_size)); + if (GNUNET_OK != GNUNET_DISK_file_test (sub->filename_valid_peers)) + { + return; + } + fh = GNUNET_DISK_file_open (sub->filename_valid_peers, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); + GNUNET_assert (NULL != fh); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size)); num_peers = file_size / 53; - buf = GNUNET_malloc(file_size); - size_read = GNUNET_DISK_file_read(fh, buf, file_size); - GNUNET_assert(size_read == file_size); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Restoring %" PRIu32 " peers from file `%s'\n", - num_peers, - sub->filename_valid_peers); + buf = GNUNET_malloc (file_size); + size_read = GNUNET_DISK_file_read (fh, buf, file_size); + GNUNET_assert (size_read == file_size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Restoring %" PRIu32 " peers from file `%s'\n", + num_peers, + sub->filename_valid_peers); for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) - { - str_repr = GNUNET_strndup(iter_buf, 53); - peer = s2i_full(str_repr); - GNUNET_free(str_repr); - add_valid_peer(peer, sub->valid_peers); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Restored valid peer %s from disk\n", - GNUNET_i2s_full(peer)); - } + { + str_repr = GNUNET_strndup (iter_buf, 53); + peer = s2i_full (str_repr); + GNUNET_free (str_repr); + add_valid_peer (peer, sub->valid_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Restored valid peer %s from disk\n", + GNUNET_i2s_full (peer)); + } iter_buf = NULL; - GNUNET_free(buf); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", - num_peers, - GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); - if (num_peers != GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Number of restored peers does not match file size. Have probably duplicates.\n"); - } - GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Restored %u valid peers from disk\n", - GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); + GNUNET_free (buf); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", + num_peers, + GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); + if (num_peers != GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Number of restored peers does not match file size. Have probably duplicates.\n"); + } + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Restored %u valid peers from disk\n", + GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); } @@ -1625,22 +1636,22 @@ restore_valid_peers(const struct Sub *sub) * @param sub Sub for which the storage is deleted */ static void -peers_terminate(struct Sub *sub) +peers_terminate (struct Sub *sub) { if (GNUNET_SYSERR == - GNUNET_CONTAINER_multipeermap_iterate(sub->peer_map, - &peermap_clear_iterator, - sub)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Iteration destroying peers was aborted.\n"); - } - GNUNET_CONTAINER_multipeermap_destroy(sub->peer_map); + GNUNET_CONTAINER_multipeermap_iterate (sub->peer_map, + &peermap_clear_iterator, + sub)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Iteration destroying peers was aborted.\n"); + } + GNUNET_CONTAINER_multipeermap_destroy (sub->peer_map); sub->peer_map = NULL; - store_valid_peers(sub); - GNUNET_free(sub->filename_valid_peers); + store_valid_peers (sub); + GNUNET_free (sub->filename_valid_peers); sub->filename_valid_peers = NULL; - GNUNET_CONTAINER_multipeermap_destroy(sub->valid_peers); + GNUNET_CONTAINER_multipeermap_destroy (sub->valid_peers); sub->valid_peers = NULL; } @@ -1656,15 +1667,15 @@ peers_terminate(struct Sub *sub) * #GNUNET_NO if not. */ static int -valid_peer_iterator(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +valid_peer_iterator (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct PeersIteratorCls *it_cls = cls; - (void)value; + (void) value; - return it_cls->iterator(it_cls->cls, peer); + return it_cls->iterator (it_cls->cls, peer); } @@ -1678,20 +1689,20 @@ valid_peer_iterator(void *cls, * #GNUNET_SYSERR if it aborted iteration */ static int -get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, - PeersIterator iterator, - void *it_cls) +get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, + PeersIterator iterator, + void *it_cls) { struct PeersIteratorCls *cls; int ret; - cls = GNUNET_new(struct PeersIteratorCls); + cls = GNUNET_new (struct PeersIteratorCls); cls->iterator = iterator; cls->cls = it_cls; - ret = GNUNET_CONTAINER_multipeermap_iterate(valid_peers, - valid_peer_iterator, - cls); - GNUNET_free(cls); + ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers, + valid_peer_iterator, + cls); + GNUNET_free (cls); return ret; } @@ -1709,14 +1720,14 @@ get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, * #GNUNET_NO otherwise */ static int -insert_peer(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +insert_peer (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { - if (GNUNET_YES == check_peer_known(sub->peer_map, peer)) - { - return GNUNET_NO; /* We already know this peer - nothing to do */ - } - (void)create_peer_ctx(sub, peer); + if (GNUNET_YES == check_peer_known (sub->peer_map, peer)) + { + return GNUNET_NO; /* We already know this peer - nothing to do */ + } + (void) create_peer_ctx (sub, peer); return GNUNET_YES; } @@ -1733,18 +1744,18 @@ insert_peer(struct Sub *sub, * #GNUNET_NO otherwise */ static int -check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, - const struct GNUNET_PeerIdentity *peer, - enum Peers_PeerFlags flags) +check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, + const struct GNUNET_PeerIdentity *peer, + enum Peers_PeerFlags flags) { struct PeerContext *peer_ctx; - if (GNUNET_NO == check_peer_known(peer_map, peer)) - { - return GNUNET_SYSERR; - } - peer_ctx = get_peer_ctx(peer_map, peer); - return check_peer_flag_set(peer_ctx, flags); + if (GNUNET_NO == check_peer_known (peer_map, peer)) + { + return GNUNET_SYSERR; + } + peer_ctx = get_peer_ctx (peer_map, peer); + return check_peer_flag_set (peer_ctx, flags); } /** @@ -1758,19 +1769,19 @@ check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, * #GNUNET_NO otherwise */ static int -issue_peer_online_check(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +issue_peer_online_check (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { struct PeerContext *peer_ctx; - (void)insert_peer(sub, peer); // TODO even needed? - peer_ctx = get_peer_ctx(sub->peer_map, peer); - if ((GNUNET_NO == check_peer_flag(sub->peer_map, peer, Peers_ONLINE)) && + (void) insert_peer (sub, peer); // TODO even needed? + peer_ctx = get_peer_ctx (sub->peer_map, peer); + if ((GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) && (NULL == peer_ctx->online_check_pending)) - { - check_peer_online(peer_ctx); - return GNUNET_YES; - } + { + check_peer_online (peer_ctx); + return GNUNET_YES; + } return GNUNET_NO; } @@ -1789,20 +1800,21 @@ issue_peer_online_check(struct Sub *sub, * #GNUNET_SYSERR if peer is not known */ static int -check_removable(const struct PeerContext *peer_ctx) +check_removable (const struct PeerContext *peer_ctx) { - if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - return GNUNET_SYSERR; - } + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains ( + peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + return GNUNET_SYSERR; + } if ((NULL != peer_ctx->recv_channel_ctx) || (NULL != peer_ctx->pending_messages_head) || - (GNUNET_YES == check_peer_flag_set(peer_ctx, Peers_PULL_REPLY_PENDING))) - { - return GNUNET_NO; - } + (GNUNET_YES == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING))) + { + return GNUNET_NO; + } return GNUNET_YES; } @@ -1819,10 +1831,10 @@ check_removable(const struct PeerContext *peer_ctx) * #GNUNET_NO if peer is not valid */ static int -check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, - const struct GNUNET_PeerIdentity *peer) +check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, + const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multipeermap_contains(valid_peers, peer); + return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); } @@ -1834,11 +1846,11 @@ check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, * @param peer_ctx Context of the target peer */ static void -indicate_sending_intention(struct PeerContext *peer_ctx) +indicate_sending_intention (struct PeerContext *peer_ctx) { - GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)); - (void)get_channel(peer_ctx); + GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)); + (void) get_channel (peer_ctx); } @@ -1852,12 +1864,12 @@ indicate_sending_intention(struct PeerContext *peer_ctx) * #GNUNET_NO otherwise */ static int -check_peer_send_intention(const struct PeerContext *peer_ctx) +check_peer_send_intention (const struct PeerContext *peer_ctx) { if (NULL != peer_ctx->recv_channel_ctx) - { - return GNUNET_YES; - } + { + return GNUNET_YES; + } return GNUNET_NO; } @@ -1873,36 +1885,36 @@ check_peer_send_intention(const struct PeerContext *peer_ctx) * (can be NULL -- that's not an error) */ static void * -handle_inbound_channel(void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator) +handle_inbound_channel (void *cls, + struct GNUNET_CADET_Channel *channel, + const struct GNUNET_PeerIdentity *initiator) { struct PeerContext *peer_ctx; struct ChannelCtx *channel_ctx; struct Sub *sub = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New channel was established to us (Peer %s).\n", - GNUNET_i2s(initiator)); - GNUNET_assert(NULL != channel); /* according to cadet API */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New channel was established to us (Peer %s).\n", + GNUNET_i2s (initiator)); + GNUNET_assert (NULL != channel); /* according to cadet API */ /* Make sure we 'know' about this peer */ - peer_ctx = create_or_get_peer_ctx(sub, initiator); - set_peer_online(peer_ctx); - (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); - channel_ctx = add_channel_ctx(peer_ctx); + peer_ctx = create_or_get_peer_ctx (sub, initiator); + set_peer_online (peer_ctx); + (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); + channel_ctx = add_channel_ctx (peer_ctx); channel_ctx->channel = channel; /* We only accept one incoming channel per peer */ - if (GNUNET_YES == check_peer_send_intention(get_peer_ctx(sub->peer_map, - initiator))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Already got one receive channel. Destroying old one.\n"); - GNUNET_break_op(0); - destroy_channel(peer_ctx->recv_channel_ctx); - peer_ctx->recv_channel_ctx = channel_ctx; - /* return the channel context */ - return channel_ctx; - } + if (GNUNET_YES == check_peer_send_intention (get_peer_ctx (sub->peer_map, + initiator))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Already got one receive channel. Destroying old one.\n"); + GNUNET_break_op (0); + destroy_channel (peer_ctx->recv_channel_ctx); + peer_ctx->recv_channel_ctx = channel_ctx; + /* return the channel context */ + return channel_ctx; + } peer_ctx->recv_channel_ctx = channel_ctx; return channel_ctx; } @@ -1917,17 +1929,17 @@ handle_inbound_channel(void *cls, * #GNUNET_NO otherwise */ static int -check_sending_channel_exists(const struct PeerContext *peer_ctx) +check_sending_channel_exists (const struct PeerContext *peer_ctx) { - if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { /* If no such peer exists, there is no channel */ - return GNUNET_NO; - } + if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { /* If no such peer exists, there is no channel */ + return GNUNET_NO; + } if (NULL == peer_ctx->send_channel_ctx) - { - return GNUNET_NO; - } + { + return GNUNET_NO; + } return GNUNET_YES; } @@ -1941,19 +1953,19 @@ check_sending_channel_exists(const struct PeerContext *peer_ctx) * #GNUNET_NO otherwise */ static int -destroy_sending_channel(struct PeerContext *peer_ctx) +destroy_sending_channel (struct PeerContext *peer_ctx) { - if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - return GNUNET_NO; - } + if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + return GNUNET_NO; + } if (NULL != peer_ctx->send_channel_ctx) - { - destroy_channel(peer_ctx->send_channel_ctx); - (void)check_connected(peer_ctx); - return GNUNET_YES; - } + { + destroy_channel (peer_ctx->send_channel_ctx); + (void) check_connected (peer_ctx); + return GNUNET_YES; + } return GNUNET_NO; } @@ -1968,23 +1980,23 @@ destroy_sending_channel(struct PeerContext *peer_ctx) * @param type type of the message */ static void -send_message(struct PeerContext *peer_ctx, - struct GNUNET_MQ_Envelope *ev, - const char *type) +send_message (struct PeerContext *peer_ctx, + struct GNUNET_MQ_Envelope *ev, + const char *type) { struct PendingMessage *pending_msg; struct GNUNET_MQ_Handle *mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending message to %s of type %s\n", - GNUNET_i2s(&peer_ctx->peer_id), - type); - pending_msg = insert_pending_message(peer_ctx, ev, type); - mq = get_mq(peer_ctx); - GNUNET_MQ_notify_sent(ev, - mq_notify_sent_cb, - pending_msg); - GNUNET_MQ_send(mq, ev); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending message to %s of type %s\n", + GNUNET_i2s (&peer_ctx->peer_id), + type); + pending_msg = insert_pending_message (peer_ctx, ev, type); + mq = get_mq (peer_ctx); + GNUNET_MQ_notify_sent (ev, + mq_notify_sent_cb, + pending_msg); + GNUNET_MQ_send (mq, ev); } /** @@ -2000,26 +2012,26 @@ send_message(struct PeerContext *peer_ctx, * #GNUNET_NO otherwise */ static int -schedule_operation(struct PeerContext *peer_ctx, - const PeerOp peer_op, - void *cls) +schedule_operation (struct PeerContext *peer_ctx, + const PeerOp peer_op, + void *cls) { struct PeerPendingOp pending_op; - GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)); + GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)); - //TODO if ONLINE execute immediately + // TODO if ONLINE execute immediately - if (GNUNET_NO == check_operation_scheduled(peer_ctx, peer_op)) - { - pending_op.op = peer_op; - pending_op.op_cls = cls; - GNUNET_array_append(peer_ctx->pending_ops, - peer_ctx->num_pending_ops, - pending_op); - return GNUNET_YES; - } + if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op)) + { + pending_op.op = peer_op; + pending_op.op_cls = cls; + GNUNET_array_append (peer_ctx->pending_ops, + peer_ctx->num_pending_ops, + pending_op); + return GNUNET_YES; + } return GNUNET_NO; } @@ -2036,7 +2048,8 @@ schedule_operation(struct PeerContext *peer_ctx, * Closure used to pass the client and the id to the callback * that replies to a client's request */ -struct ReplyCls { +struct ReplyCls +{ /** * DLL */ @@ -2063,7 +2076,8 @@ struct ReplyCls { /** * Struct used to store the context of a connected client. */ -struct ClientContext { +struct ClientContext +{ /** * DLL */ @@ -2120,21 +2134,21 @@ struct ClientContext *cli_ctx_tail; * Print peerlist to log. */ static void -print_peer_list(struct GNUNET_PeerIdentity *list, - unsigned int len) +print_peer_list (struct GNUNET_PeerIdentity *list, + unsigned int len) { unsigned int i; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Printing peer list of length %u at %p:\n", - len, - list); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Printing peer list of length %u at %p:\n", + len, + list); for (i = 0; i < len; i++) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer: %s\n", - i, GNUNET_i2s(&list[i])); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer: %s\n", + i, GNUNET_i2s (&list[i])); + } } @@ -2142,33 +2156,33 @@ print_peer_list(struct GNUNET_PeerIdentity *list, * Remove peer from list. */ static void -rem_from_list(struct GNUNET_PeerIdentity **peer_list, - unsigned int *list_size, - const struct GNUNET_PeerIdentity *peer) +rem_from_list (struct GNUNET_PeerIdentity **peer_list, + unsigned int *list_size, + const struct GNUNET_PeerIdentity *peer) { unsigned int i; struct GNUNET_PeerIdentity *tmp; tmp = *peer_list; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Removing peer %s from list at %p\n", - GNUNET_i2s(peer), - tmp); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Removing peer %s from list at %p\n", + GNUNET_i2s (peer), + tmp); for (i = 0; i < *list_size; i++) + { + if (0 == GNUNET_memcmp (&tmp[i], peer)) { - if (0 == GNUNET_memcmp(&tmp[i], peer)) - { - if (i < *list_size - 1) - { /* Not at the last entry -- shift peers left */ - memmove(&tmp[i], &tmp[i + 1], - ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); - } - /* Remove last entry (should be now useless PeerID) */ - GNUNET_array_grow(tmp, *list_size, (*list_size) - 1); - } - } + if (i < *list_size - 1) + { /* Not at the last entry -- shift peers left */ + memmove (&tmp[i], &tmp[i + 1], + ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); + } + /* Remove last entry (should be now useless PeerID) */ + GNUNET_array_grow (tmp, *list_size, (*list_size) - 1); + } + } *peer_list = tmp; } @@ -2183,8 +2197,8 @@ rem_from_list(struct GNUNET_PeerIdentity **peer_list, * GNUNET_NO if peer was not inserted */ static void -insert_in_view_op(void *cls, - const struct GNUNET_PeerIdentity *peer); +insert_in_view_op (void *cls, + const struct GNUNET_PeerIdentity *peer); /** * Insert PeerID in #view @@ -2198,32 +2212,32 @@ insert_in_view_op(void *cls, * GNUNET_NO if peer was not inserted */ static int -insert_in_view(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +insert_in_view (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { struct PeerContext *peer_ctx; int online; int ret; - online = check_peer_flag(sub->peer_map, peer, Peers_ONLINE); - peer_ctx = get_peer_ctx(sub->peer_map, peer); // TODO indirection needed? + online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE); + peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed? if ((GNUNET_NO == online) || (GNUNET_SYSERR == online)) /* peer is not even known */ - { - (void)issue_peer_online_check(sub, peer); - (void)schedule_operation(peer_ctx, insert_in_view_op, sub); - return GNUNET_NO; - } + { + (void) issue_peer_online_check (sub, peer); + (void) schedule_operation (peer_ctx, insert_in_view_op, sub); + return GNUNET_NO; + } /* Open channel towards peer to keep connection open */ - indicate_sending_intention(peer_ctx); - ret = View_put(sub->view, peer); + indicate_sending_intention (peer_ctx); + ret = View_put (sub->view, peer); if (peer_ctx->sub == msub) - { - GNUNET_STATISTICS_set(stats, - "view size", - View_size(peer_ctx->sub->view), - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "view size", + View_size (peer_ctx->sub->view), + GNUNET_NO); + } return ret; } @@ -2236,33 +2250,33 @@ insert_in_view(struct Sub *sub, * @param view_size the size of the view array (can be 0) */ static void -send_view(const struct ClientContext *cli_ctx, - const struct GNUNET_PeerIdentity *view_array, - uint64_t view_size) +send_view (const struct ClientContext *cli_ctx, + const struct GNUNET_PeerIdentity *view_array, + uint64_t view_size) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; struct Sub *sub; if (NULL == view_array) - { - if (NULL == cli_ctx->sub) - sub = msub; - else - sub = cli_ctx->sub; - view_size = View_size(sub->view); - view_array = View_get_as_array(sub->view); - } - - ev = GNUNET_MQ_msg_extra(out_msg, - view_size * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); - out_msg->num_peers = htonl(view_size); - - GNUNET_memcpy(&out_msg[1], - view_array, - view_size * sizeof(struct GNUNET_PeerIdentity)); - GNUNET_MQ_send(cli_ctx->mq, ev); + { + if (NULL == cli_ctx->sub) + sub = msub; + else + sub = cli_ctx->sub; + view_size = View_size (sub->view); + view_array = View_get_as_array (sub->view); + } + + ev = GNUNET_MQ_msg_extra (out_msg, + view_size * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); + out_msg->num_peers = htonl (view_size); + + GNUNET_memcpy (&out_msg[1], + view_array, + view_size * sizeof(struct GNUNET_PeerIdentity)); + GNUNET_MQ_send (cli_ctx->mq, ev); } @@ -2276,24 +2290,24 @@ send_view(const struct ClientContext *cli_ctx, * @param view_size the size of the view array (can be 0) */ static void -send_stream_peers(const struct ClientContext *cli_ctx, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *peers) +send_stream_peers (const struct ClientContext *cli_ctx, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *peers) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; - GNUNET_assert(NULL != peers); + GNUNET_assert (NULL != peers); - ev = GNUNET_MQ_msg_extra(out_msg, - num_peers * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); - out_msg->num_peers = htonl(num_peers); + ev = GNUNET_MQ_msg_extra (out_msg, + num_peers * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); + out_msg->num_peers = htonl (num_peers); - GNUNET_memcpy(&out_msg[1], - peers, - num_peers * sizeof(struct GNUNET_PeerIdentity)); - GNUNET_MQ_send(cli_ctx->mq, ev); + GNUNET_memcpy (&out_msg[1], + peers, + num_peers * sizeof(struct GNUNET_PeerIdentity)); + GNUNET_MQ_send (cli_ctx->mq, ev); } @@ -2303,46 +2317,46 @@ send_stream_peers(const struct ClientContext *cli_ctx, * @param sub Sub for which to notify clients */ static void -clients_notify_view_update(const struct Sub *sub) +clients_notify_view_update (const struct Sub *sub) { struct ClientContext *cli_ctx_iter; uint64_t num_peers; const struct GNUNET_PeerIdentity *view_array; - num_peers = View_size(sub->view); - view_array = View_get_as_array(sub->view); + num_peers = View_size (sub->view); + view_array = View_get_as_array (sub->view); /* check size of view is small enough */ if (GNUNET_MAX_MESSAGE_SIZE < num_peers) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "View is too big to send\n"); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "View is too big to send\n"); + return; + } for (cli_ctx_iter = cli_ctx_head; NULL != cli_ctx_iter; cli_ctx_iter = cli_ctx_iter->next) + { + if (1 < cli_ctx_iter->view_updates_left) { - if (1 < cli_ctx_iter->view_updates_left) - { - /* Client wants to receive limited amount of updates */ - cli_ctx_iter->view_updates_left -= 1; - } - else if (1 == cli_ctx_iter->view_updates_left) - { - /* Last update of view for client */ - cli_ctx_iter->view_updates_left = -1; - } - else if (0 > cli_ctx_iter->view_updates_left) - { - /* Client is not interested in updates */ - continue; - } - /* else _updates_left == 0 - infinite amount of updates */ - - /* send view */ - send_view(cli_ctx_iter, view_array, num_peers); + /* Client wants to receive limited amount of updates */ + cli_ctx_iter->view_updates_left -= 1; } + else if (1 == cli_ctx_iter->view_updates_left) + { + /* Last update of view for client */ + cli_ctx_iter->view_updates_left = -1; + } + else if (0 > cli_ctx_iter->view_updates_left) + { + /* Client is not interested in updates */ + continue; + } + /* else _updates_left == 0 - infinite amount of updates */ + + /* send view */ + send_view (cli_ctx_iter, view_array, num_peers); + } } @@ -2353,27 +2367,27 @@ clients_notify_view_update(const struct Sub *sub) * @param peers the array of peers to send */ static void -clients_notify_stream_peer(const struct Sub *sub, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *peers) +clients_notify_stream_peer (const struct Sub *sub, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *peers) // TODO enum StreamPeerSource) { struct ClientContext *cli_ctx_iter; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got peer (%s) from biased stream - update all clients\n", - GNUNET_i2s(peers)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got peer (%s) from biased stream - update all clients\n", + GNUNET_i2s (peers)); for (cli_ctx_iter = cli_ctx_head; NULL != cli_ctx_iter; cli_ctx_iter = cli_ctx_iter->next) + { + if ((GNUNET_YES == cli_ctx_iter->stream_update) && + ((sub == cli_ctx_iter->sub) ||(sub == msub) )) { - if (GNUNET_YES == cli_ctx_iter->stream_update && - (sub == cli_ctx_iter->sub || sub == msub)) - { - send_stream_peers(cli_ctx_iter, num_peers, peers); - } + send_stream_peers (cli_ctx_iter, num_peers, peers); } + } } @@ -2385,34 +2399,34 @@ clients_notify_stream_peer(const struct Sub *sub, * @param cls Closure - The Sub for which this is to be done */ static void -hist_update(const struct GNUNET_PeerIdentity *ids, - uint32_t num_peers, - void *cls) +hist_update (const struct GNUNET_PeerIdentity *ids, + uint32_t num_peers, + void *cls) { unsigned int i; struct Sub *sub = cls; for (i = 0; i < num_peers; i++) + { + int inserted; + if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i])) { - int inserted; - if (GNUNET_YES != check_peer_known(sub->peer_map, &ids[i])) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Peer in history update not known!\n"); - continue; - } - inserted = insert_in_view(sub, &ids[i]); - if (GNUNET_OK == inserted) - { - clients_notify_stream_peer(sub, 1, &ids[i]); - } + LOG (GNUNET_ERROR_TYPE_WARNING, + "Peer in history update not known!\n"); + continue; + } + inserted = insert_in_view (sub, &ids[i]); + if (GNUNET_OK == inserted) + { + clients_notify_stream_peer (sub, 1, &ids[i]); + } #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "+%s\t(hist)", - GNUNET_i2s_full(ids)); + to_file (sub->file_name_view_log, + "+%s\t(hist)", + GNUNET_i2s_full (ids)); #endif /* TO_FILE_FULL */ - } - clients_notify_view_update(sub); + } + clients_notify_view_update (sub); } @@ -2426,22 +2440,22 @@ hist_update(const struct GNUNET_PeerIdentity *ids, * @param new_size New size to which to resize */ static void -resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) +resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size) { unsigned int sampler_size; // TODO statistics // TODO respect the min, max - sampler_size = RPS_sampler_get_size(sampler); + sampler_size = RPS_sampler_get_size (sampler); if (sampler_size > new_size * 4) - { /* Shrinking */ - RPS_sampler_resize(sampler, sampler_size / 2); - } + { /* Shrinking */ + RPS_sampler_resize (sampler, sampler_size / 2); + } else if (sampler_size < new_size) - { /* Growing */ - RPS_sampler_resize(sampler, sampler_size * 2); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); + { /* Growing */ + RPS_sampler_resize (sampler, sampler_size * 2); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); } @@ -2453,33 +2467,33 @@ resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) * @param peer_map the peermap to use as set */ static void -add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, - unsigned int num_peers, - struct GNUNET_CONTAINER_MultiPeerMap *peer_map) +add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, + unsigned int num_peers, + struct GNUNET_CONTAINER_MultiPeerMap *peer_map) { unsigned int i; if (NULL == peer_map) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Trying to add peers to non-existing peermap.\n"); - return; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Trying to add peers to non-existing peermap.\n"); + return; + } for (i = 0; i < num_peers; i++) + { + GNUNET_CONTAINER_multipeermap_put (peer_map, + &peer_array[i], + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + if (msub->peer_map == peer_map) { - GNUNET_CONTAINER_multipeermap_put(peer_map, - &peer_array[i], - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - if (msub->peer_map == peer_map) - { - GNUNET_STATISTICS_set(stats, - "# known peers", - GNUNET_CONTAINER_multipeermap_size(peer_map), - GNUNET_NO); - } + GNUNET_STATISTICS_set (stats, + "# known peers", + GNUNET_CONTAINER_multipeermap_size (peer_map), + GNUNET_NO); } + } } @@ -2491,17 +2505,17 @@ add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, * @param num_peer_ids the number of peers to send to @a peer_id */ static void -send_pull_reply(struct PeerContext *peer_ctx, - const struct GNUNET_PeerIdentity *peer_ids, - unsigned int num_peer_ids) +send_pull_reply (struct PeerContext *peer_ctx, + const struct GNUNET_PeerIdentity *peer_ids, + unsigned int num_peer_ids) { uint32_t send_size; struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; /* Compute actual size */ - send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) + - num_peer_ids * sizeof(struct GNUNET_PeerIdentity); + send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) + + num_peer_ids * sizeof(struct GNUNET_PeerIdentity); if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) /* Compute number of peers to send @@ -2509,28 +2523,28 @@ send_pull_reply(struct PeerContext *peer_ctx, // TODO select random ones via permutation // or even better: do good protocol design send_size = - (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / - sizeof(struct GNUNET_PeerIdentity); + (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE + - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) + / sizeof(struct GNUNET_PeerIdentity); else send_size = num_peer_ids; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send PULL REPLY with %u peers to %s\n", - send_size, GNUNET_i2s(&peer_ctx->peer_id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send PULL REPLY with %u peers to %s\n", + send_size, GNUNET_i2s (&peer_ctx->peer_id)); - ev = GNUNET_MQ_msg_extra(out_msg, - send_size * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); - out_msg->num_peers = htonl(send_size); - GNUNET_memcpy(&out_msg[1], peer_ids, - send_size * sizeof(struct GNUNET_PeerIdentity)); + ev = GNUNET_MQ_msg_extra (out_msg, + send_size * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); + out_msg->num_peers = htonl (send_size); + GNUNET_memcpy (&out_msg[1], peer_ids, + send_size * sizeof(struct GNUNET_PeerIdentity)); - send_message(peer_ctx, ev, "PULL REPLY"); + send_message (peer_ctx, ev, "PULL REPLY"); if (peer_ctx->sub == msub) - { - GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); - } + { + GNUNET_STATISTICS_update (stats, "# pull reply send issued", 1, GNUNET_NO); + } // TODO check with send intention: as send_channel is used/opened we indicate // a sending intention without intending it. // -> clean peer afterwards? @@ -2547,12 +2561,12 @@ send_pull_reply(struct PeerContext *peer_ctx, * @param peer Peer to insert */ static void -insert_in_pull_map(void *cls, - const struct GNUNET_PeerIdentity *peer) +insert_in_pull_map (void *cls, + const struct GNUNET_PeerIdentity *peer) { struct Sub *sub = cls; - CustomPeerMap_put(sub->pull_map, peer); + CustomPeerMap_put (sub->pull_map, peer); } @@ -2566,17 +2580,17 @@ insert_in_pull_map(void *cls, * @param peer the peer to insert */ static void -insert_in_view_op(void *cls, - const struct GNUNET_PeerIdentity *peer) +insert_in_view_op (void *cls, + const struct GNUNET_PeerIdentity *peer) { struct Sub *sub = cls; int inserted; - inserted = insert_in_view(sub, peer); + inserted = insert_in_view (sub, peer); if (GNUNET_OK == inserted) - { - clients_notify_stream_peer(sub, 1, peer); - } + { + clients_notify_stream_peer (sub, 1, peer); + } } @@ -2588,30 +2602,30 @@ insert_in_view_op(void *cls, * @param peer Peer to insert */ static void -insert_in_sampler(void *cls, - const struct GNUNET_PeerIdentity *peer) +insert_in_sampler (void *cls, + const struct GNUNET_PeerIdentity *peer) { struct Sub *sub = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updating samplers with peer %s from insert_in_sampler()\n", - GNUNET_i2s(peer)); - RPS_sampler_update(sub->sampler, peer); - if (0 < RPS_sampler_count_id(sub->sampler, peer)) - { - /* Make sure we 'know' about this peer */ - (void)issue_peer_online_check(sub, peer); - /* Establish a channel towards that peer to indicate we are going to send - * messages to it */ - //indicate_sending_intention (peer); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updating samplers with peer %s from insert_in_sampler()\n", + GNUNET_i2s (peer)); + RPS_sampler_update (sub->sampler, peer); + if (0 < RPS_sampler_count_id (sub->sampler, peer)) + { + /* Make sure we 'know' about this peer */ + (void) issue_peer_online_check (sub, peer); + /* Establish a channel towards that peer to indicate we are going to send + * messages to it */ + // indicate_sending_intention (peer); + } if (sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# observed peers in gossip", - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (stats, + "# observed peers in gossip", + 1, + GNUNET_NO); + } #ifdef TO_FILE sub->num_observed_peers++; GNUNET_CONTAINER_multipeermap_put @@ -2620,17 +2634,17 @@ insert_in_sampler(void *cls, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); uint32_t num_observed_unique_peers = - GNUNET_CONTAINER_multipeermap_size(sub->observed_unique_peers); - GNUNET_STATISTICS_set(stats, - "# unique peers in gossip", - num_observed_unique_peers, - GNUNET_NO); + GNUNET_CONTAINER_multipeermap_size (sub->observed_unique_peers); + GNUNET_STATISTICS_set (stats, + "# unique peers in gossip", + num_observed_unique_peers, + GNUNET_NO); #ifdef TO_FILE_FULL - to_file(sub->file_name_observed_log, - "%" PRIu32 " %" PRIu32 " %f\n", - sub->num_observed_peers, - num_observed_unique_peers, - 1.0 * num_observed_unique_peers / sub->num_observed_peers) + to_file (sub->file_name_observed_log, + "%" PRIu32 " %" PRIu32 " %f\n", + sub->num_observed_peers, + num_observed_unique_peers, + 1.0 * num_observed_unique_peers / sub->num_observed_peers) #endif /* TO_FILE_FULL */ #endif /* TO_FILE */ } @@ -2647,24 +2661,24 @@ insert_in_sampler(void *cls, * @param peer peer to insert/peer received */ static void -got_peer(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +got_peer (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { /* If we did not know this peer already, insert it into sampler and view */ - if (GNUNET_YES == issue_peer_online_check(sub, peer)) - { - schedule_operation(get_peer_ctx(sub->peer_map, peer), - &insert_in_sampler, sub); - schedule_operation(get_peer_ctx(sub->peer_map, peer), - &insert_in_view_op, sub); - } + if (GNUNET_YES == issue_peer_online_check (sub, peer)) + { + schedule_operation (get_peer_ctx (sub->peer_map, peer), + &insert_in_sampler, sub); + schedule_operation (get_peer_ctx (sub->peer_map, peer), + &insert_in_view_op, sub); + } if (sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# learnd peers", - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (stats, + "# learnd peers", + 1, + GNUNET_NO); + } } @@ -2676,32 +2690,32 @@ got_peer(struct Sub *sub, * GNUNET_NO otherwise */ static int -check_sending_channel_needed(const struct PeerContext *peer_ctx) +check_sending_channel_needed (const struct PeerContext *peer_ctx) { /* struct GNUNET_CADET_Channel *channel; */ - if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, - &peer_ctx->peer_id)) - { - return GNUNET_NO; - } - if (GNUNET_YES == check_sending_channel_exists(peer_ctx)) - { - if ((0 < RPS_sampler_count_id(peer_ctx->sub->sampler, - &peer_ctx->peer_id)) || - (GNUNET_YES == View_contains_peer(peer_ctx->sub->view, - &peer_ctx->peer_id)) || - (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->push_map, - &peer_ctx->peer_id)) || - (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->pull_map, - &peer_ctx->peer_id)) || - (GNUNET_YES == check_peer_flag(peer_ctx->sub->peer_map, - &peer_ctx->peer_id, - Peers_PULL_REPLY_PENDING))) - { /* If we want to keep the connection to peer open */ - return GNUNET_YES; - } - return GNUNET_NO; + if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, + &peer_ctx->peer_id)) + { + return GNUNET_NO; + } + if (GNUNET_YES == check_sending_channel_exists (peer_ctx)) + { + if ((0 < RPS_sampler_count_id (peer_ctx->sub->sampler, + &peer_ctx->peer_id)) || + (GNUNET_YES == View_contains_peer (peer_ctx->sub->view, + &peer_ctx->peer_id)) || + (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->push_map, + &peer_ctx->peer_id)) || + (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->pull_map, + &peer_ctx->peer_id)) || + (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map, + &peer_ctx->peer_id, + Peers_PULL_REPLY_PENDING))) + { /* If we want to keep the connection to peer open */ + return GNUNET_YES; } + return GNUNET_NO; + } return GNUNET_NO; } @@ -2714,26 +2728,26 @@ check_sending_channel_needed(const struct PeerContext *peer_ctx) * @param peer the peer to remove */ static void -remove_peer(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +remove_peer (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { - (void)View_remove_peer(sub->view, - peer); - CustomPeerMap_remove_peer(sub->pull_map, - peer); - CustomPeerMap_remove_peer(sub->push_map, - peer); - RPS_sampler_reinitialise_by_value(sub->sampler, - peer); + (void) View_remove_peer (sub->view, + peer); + CustomPeerMap_remove_peer (sub->pull_map, + peer); + CustomPeerMap_remove_peer (sub->push_map, + peer); + RPS_sampler_reinitialise_by_value (sub->sampler, + peer); /* We want to destroy the peer now. * Sometimes, it just seems that it's already been removed from the peer_map, * so check the peer_map first. */ - if (GNUNET_YES == check_peer_known(sub->peer_map, - peer)) - { - destroy_peer(get_peer_ctx(sub->peer_map, + if (GNUNET_YES == check_peer_known (sub->peer_map, + peer)) + { + destroy_peer (get_peer_ctx (sub->peer_map, peer)); - } + } } @@ -2746,49 +2760,49 @@ remove_peer(struct Sub *sub, * @param peer the peer whose data is about to be cleaned */ static void -clean_peer(struct Sub *sub, - const struct GNUNET_PeerIdentity *peer) +clean_peer (struct Sub *sub, + const struct GNUNET_PeerIdentity *peer) { - if (GNUNET_NO == check_sending_channel_needed(get_peer_ctx(sub->peer_map, - peer))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to remove send channel to peer %s\n", - GNUNET_i2s(peer)); + if (GNUNET_NO == check_sending_channel_needed (get_peer_ctx (sub->peer_map, + peer))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to remove send channel to peer %s\n", + GNUNET_i2s (peer)); #if ENABLE_MALICIOUS - if (0 != GNUNET_memcmp(&attacked_peer, - peer)) - (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, - peer)); + if (0 != GNUNET_memcmp (&attacked_peer, + peer)) + (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, + peer)); #else /* ENABLE_MALICIOUS */ - (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, - peer)); + (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, + peer)); #endif /* ENABLE_MALICIOUS */ - } - - if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(sub->peer_map, - peer)) - { - /* Peer was already removed by callback on destroyed channel */ - LOG(GNUNET_ERROR_TYPE_WARNING, - "Peer was removed from our knowledge during cleanup\n"); - return; - } - - if ((GNUNET_NO == check_peer_send_intention(get_peer_ctx(sub->peer_map, - peer))) && - (GNUNET_NO == View_contains_peer(sub->view, peer)) && - (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && - (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && - (0 == RPS_sampler_count_id(sub->sampler, peer)) && - (GNUNET_YES == check_removable(get_peer_ctx(sub->peer_map, peer)))) - { /* We can safely remove this peer */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to remove peer %s\n", - GNUNET_i2s(peer)); - remove_peer(sub, peer); - return; - } + } + + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (sub->peer_map, + peer)) + { + /* Peer was already removed by callback on destroyed channel */ + LOG (GNUNET_ERROR_TYPE_WARNING, + "Peer was removed from our knowledge during cleanup\n"); + return; + } + + if ((GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map, + peer))) && + (GNUNET_NO == View_contains_peer (sub->view, peer)) && + (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && + (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && + (0 == RPS_sampler_count_id (sub->sampler, peer)) && + (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer)))) + { /* We can safely remove this peer */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to remove peer %s\n", + GNUNET_i2s (peer)); + remove_peer (sub, peer); + return; + } } @@ -2804,22 +2818,22 @@ clean_peer(struct Sub *sub, * @param channel The channel being closed */ static void -cleanup_destroyed_channel(void *cls, - const struct GNUNET_CADET_Channel *channel) +cleanup_destroyed_channel (void *cls, + const struct GNUNET_CADET_Channel *channel) { struct ChannelCtx *channel_ctx = cls; struct PeerContext *peer_ctx = channel_ctx->peer_ctx; - (void)channel; + (void) channel; channel_ctx->channel = NULL; - remove_channel_ctx(channel_ctx); - if (NULL != peer_ctx && - peer_ctx->send_channel_ctx == channel_ctx && - GNUNET_YES == check_sending_channel_needed(channel_ctx->peer_ctx)) - { - remove_peer(peer_ctx->sub, &peer_ctx->peer_id); - } + remove_channel_ctx (channel_ctx); + if ((NULL != peer_ctx)&& + (peer_ctx->send_channel_ctx == channel_ctx) && + (GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) ) + { + remove_peer (peer_ctx->sub, &peer_ctx->peer_id); + } } /*********************************************************************** @@ -2843,119 +2857,119 @@ cleanup_destroyed_channel(void *cls, * @return Sub */ struct Sub * -new_sub(const struct GNUNET_HashCode *hash, - uint32_t sampler_size, - struct GNUNET_TIME_Relative round_interval) +new_sub (const struct GNUNET_HashCode *hash, + uint32_t sampler_size, + struct GNUNET_TIME_Relative round_interval) { struct Sub *sub; - sub = GNUNET_new(struct Sub); + sub = GNUNET_new (struct Sub); /* With the hash generated from the secret value this service only connects * to rps instances that share the value */ struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_fixed_size(peer_check, - GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size(peer_push, - GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size(peer_pull_request, - GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size(peer_pull_reply, - GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, - struct GNUNET_RPS_P2P_PullReplyMessage, - NULL), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_fixed_size (peer_check, + GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (peer_push, + GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (peer_pull_request, + GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (peer_pull_reply, + GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, + struct GNUNET_RPS_P2P_PullReplyMessage, + NULL), + GNUNET_MQ_handler_end () }; sub->hash = *hash; sub->cadet_port = - GNUNET_CADET_open_port(cadet_handle, - &sub->hash, - &handle_inbound_channel, /* Connect handler */ - sub, /* cls */ - NULL, /* WindowSize handler */ - &cleanup_destroyed_channel, /* Disconnect handler */ - cadet_handlers); + GNUNET_CADET_open_port (cadet_handle, + &sub->hash, + &handle_inbound_channel, /* Connect handler */ + sub, /* cls */ + NULL, /* WindowSize handler */ + &cleanup_destroyed_channel, /* Disconnect handler */ + cadet_handlers); if (NULL == sub->cadet_port) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Cadet port `%s' is already in use.\n", - GNUNET_APPLICATION_PORT_RPS); - GNUNET_assert(0); - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Cadet port `%s' is already in use.\n", + GNUNET_APPLICATION_PORT_RPS); + GNUNET_assert (0); + } /* Set up general data structure to keep track about peers */ - sub->valid_peers = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); + sub->valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(cfg, - "rps", - "FILENAME_VALID_PEERS", - &sub->filename_valid_peers)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "rps", - "FILENAME_VALID_PEERS"); - } - if (0 != strncmp("DISABLE", sub->filename_valid_peers, 7)) - { - char *tmp_filename_valid_peers; - char str_hash[105]; - - GNUNET_snprintf(str_hash, - sizeof(str_hash), - GNUNET_h2s_full(hash)); - tmp_filename_valid_peers = sub->filename_valid_peers; - GNUNET_asprintf(&sub->filename_valid_peers, - "%s%s", - tmp_filename_valid_peers, - str_hash); - GNUNET_free(tmp_filename_valid_peers); - } - sub->peer_map = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); + GNUNET_CONFIGURATION_get_value_filename (cfg, + "rps", + "FILENAME_VALID_PEERS", + &sub->filename_valid_peers)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "rps", + "FILENAME_VALID_PEERS"); + } + if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7)) + { + char *tmp_filename_valid_peers; + char str_hash[105]; + + GNUNET_snprintf (str_hash, + sizeof(str_hash), + GNUNET_h2s_full (hash)); + tmp_filename_valid_peers = sub->filename_valid_peers; + GNUNET_asprintf (&sub->filename_valid_peers, + "%s%s", + tmp_filename_valid_peers, + str_hash); + GNUNET_free (tmp_filename_valid_peers); + } + sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); /* Set up the sampler */ sub->sampler_size_est_min = sampler_size; sub->sampler_size_est_need = sampler_size;; - LOG(GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); - GNUNET_assert(0 != round_interval.rel_value_us); + LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); + GNUNET_assert (0 != round_interval.rel_value_us); sub->round_interval = round_interval; - sub->sampler = RPS_sampler_init(sampler_size, - round_interval); + sub->sampler = RPS_sampler_init (sampler_size, + round_interval); /* Logging of internals */ #ifdef TO_FILE_FULL - sub->file_name_view_log = store_prefix_file_name(&own_identity, "view"); + sub->file_name_view_log = store_prefix_file_name (&own_identity, "view"); #endif /* TO_FILE_FULL */ #ifdef TO_FILE #ifdef TO_FILE_FULL - sub->file_name_observed_log = store_prefix_file_name(&own_identity, - "observed"); + sub->file_name_observed_log = store_prefix_file_name (&own_identity, + "observed"); #endif /* TO_FILE_FULL */ sub->num_observed_peers = 0; - sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create(1, - GNUNET_NO); + sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, + GNUNET_NO); #endif /* TO_FILE */ /* Set up data structures for gossip */ - sub->push_map = CustomPeerMap_create(4); - sub->pull_map = CustomPeerMap_create(4); + sub->push_map = CustomPeerMap_create (4); + sub->pull_map = CustomPeerMap_create (4); sub->view_size_est_min = sampler_size;; - sub->view = View_create(sub->view_size_est_min); + sub->view = View_create (sub->view_size_est_min); if (sub == msub) - { - GNUNET_STATISTICS_set(stats, - "view size aim", - sub->view_size_est_min, - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "view size aim", + sub->view_size_est_min, + GNUNET_NO); + } /* Start executing rounds */ - sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); + sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); return sub; } @@ -2971,36 +2985,36 @@ new_sub(const struct GNUNET_HashCode *hash, * @param file_name file to dump into */ static void -write_histogram_to_file(const uint32_t hist_array[], - const char *file_name) +write_histogram_to_file (const uint32_t hist_array[], + const char *file_name) { char collect_str[SIZE_DUMP_FILE + 1] = ""; char *recv_str_iter; char *file_name_full; recv_str_iter = collect_str; - file_name_full = store_prefix_file_name(&own_identity, - file_name); + file_name_full = store_prefix_file_name (&own_identity, + file_name); for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) - { - char collect_str_tmp[8]; - - GNUNET_snprintf(collect_str_tmp, - sizeof(collect_str_tmp), - "%" PRIu32 "\n", - hist_array[i]); - recv_str_iter = stpncpy(recv_str_iter, - collect_str_tmp, - 6); - } - (void)stpcpy(recv_str_iter, - "\n"); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Writing push stats to disk\n"); - to_file_w_len(file_name_full, - SIZE_DUMP_FILE, - collect_str); - GNUNET_free(file_name_full); + { + char collect_str_tmp[8]; + + GNUNET_snprintf (collect_str_tmp, + sizeof(collect_str_tmp), + "%" PRIu32 "\n", + hist_array[i]); + recv_str_iter = stpncpy (recv_str_iter, + collect_str_tmp, + 6); + } + (void) stpcpy (recv_str_iter, + "\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Writing push stats to disk\n"); + to_file_w_len (file_name_full, + SIZE_DUMP_FILE, + collect_str); + GNUNET_free (file_name_full); } #endif /* TO_FILE */ @@ -3011,56 +3025,56 @@ write_histogram_to_file(const uint32_t hist_array[], * @param sub Sub to destroy */ static void -destroy_sub(struct Sub *sub) +destroy_sub (struct Sub *sub) { - GNUNET_assert(NULL != sub); - GNUNET_assert(NULL != sub->do_round_task); - GNUNET_SCHEDULER_cancel(sub->do_round_task); + GNUNET_assert (NULL != sub); + GNUNET_assert (NULL != sub->do_round_task); + GNUNET_SCHEDULER_cancel (sub->do_round_task); sub->do_round_task = NULL; /* Disconnect from cadet */ - GNUNET_CADET_close_port(sub->cadet_port); + GNUNET_CADET_close_port (sub->cadet_port); sub->cadet_port = NULL; /* Clean up data structures for peers */ - RPS_sampler_destroy(sub->sampler); + RPS_sampler_destroy (sub->sampler); sub->sampler = NULL; - View_destroy(sub->view); + View_destroy (sub->view); sub->view = NULL; - CustomPeerMap_destroy(sub->push_map); + CustomPeerMap_destroy (sub->push_map); sub->push_map = NULL; - CustomPeerMap_destroy(sub->pull_map); + CustomPeerMap_destroy (sub->pull_map); sub->pull_map = NULL; - peers_terminate(sub); + peers_terminate (sub); /* Free leftover data structures */ #ifdef TO_FILE_FULL - GNUNET_free(sub->file_name_view_log); + GNUNET_free (sub->file_name_view_log); sub->file_name_view_log = NULL; #endif /* TO_FILE_FULL */ #ifdef TO_FILE #ifdef TO_FILE_FULL - GNUNET_free(sub->file_name_observed_log); + GNUNET_free (sub->file_name_observed_log); sub->file_name_observed_log = NULL; #endif /* TO_FILE_FULL */ /* Write push frequencies to disk */ - write_histogram_to_file(sub->push_recv, - "push_recv"); + write_histogram_to_file (sub->push_recv, + "push_recv"); /* Write push deltas to disk */ - write_histogram_to_file(sub->push_delta, - "push_delta"); + write_histogram_to_file (sub->push_delta, + "push_delta"); /* Write pull delays to disk */ - write_histogram_to_file(sub->pull_delays, - "pull_delays"); + write_histogram_to_file (sub->pull_delays, + "pull_delays"); - GNUNET_CONTAINER_multipeermap_destroy(sub->observed_unique_peers); + GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers); sub->observed_unique_peers = NULL; #endif /* TO_FILE */ - GNUNET_free(sub); + GNUNET_free (sub); } @@ -3080,13 +3094,13 @@ destroy_sub(struct Sub *sub) * @param my_identity - unused */ void -core_init(void *cls, - const struct GNUNET_PeerIdentity *my_identity) +core_init (void *cls, + const struct GNUNET_PeerIdentity *my_identity) { - (void)cls; - (void)my_identity; + (void) cls; + (void) my_identity; - map_single_hop = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); + map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); } @@ -3099,18 +3113,18 @@ core_init(void *cls, * @return closure given to #core_disconnects as peer_cls */ void * -core_connects(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +core_connects (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { - (void)cls; - (void)mq; - - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put(map_single_hop, - peer, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + (void) cls; + (void) mq; + + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put (map_single_hop, + peer, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return NULL; } @@ -3124,14 +3138,14 @@ core_connects(void *cls, * @param peer_cls closure given in #core_connects - unused */ void -core_disconnects(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *peer_cls) +core_disconnects (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *peer_cls) { - (void)cls; - (void)peer_cls; + (void) cls; + (void) peer_cls; - GNUNET_CONTAINER_multipeermap_remove_all(map_single_hop, peer); + GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer); } /*********************************************************************** @@ -3145,18 +3159,18 @@ core_disconnects(void *cls, * @param cli_ctx Context to destroy */ static void -destroy_cli_ctx(struct ClientContext *cli_ctx) +destroy_cli_ctx (struct ClientContext *cli_ctx) { - GNUNET_assert(NULL != cli_ctx); - GNUNET_CONTAINER_DLL_remove(cli_ctx_head, - cli_ctx_tail, - cli_ctx); + GNUNET_assert (NULL != cli_ctx); + GNUNET_CONTAINER_DLL_remove (cli_ctx_head, + cli_ctx_tail, + cli_ctx); if (NULL != cli_ctx->sub) - { - destroy_sub(cli_ctx->sub); - cli_ctx->sub = NULL; - } - GNUNET_free(cli_ctx); + { + destroy_sub (cli_ctx->sub); + cli_ctx->sub = NULL; + } + GNUNET_free (cli_ctx); } @@ -3168,44 +3182,44 @@ destroy_cli_ctx(struct ClientContext *cli_ctx) * @param std_dev standard deviation for the estimate */ static void -adapt_sizes(struct Sub *sub, double logestimate, double std_dev) +adapt_sizes (struct Sub *sub, double logestimate, double std_dev) { double estimate; - //double scale; // TODO this might go gloabal/config + // double scale; // TODO this might go gloabal/config - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", - logestimate, std_dev, RPS_sampler_get_size(sub->sampler)); - //scale = .01; - estimate = GNUNET_NSE_log_estimate_to_n(logestimate); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", + logestimate, std_dev, RPS_sampler_get_size (sub->sampler)); + // scale = .01; + estimate = GNUNET_NSE_log_estimate_to_n (logestimate); // GNUNET_NSE_log_estimate_to_n (logestimate); - estimate = pow(estimate, 1.0 / 3); + estimate = pow (estimate, 1.0 / 3); // TODO add if std_dev is a number // estimate += (std_dev * scale); - if (sub->view_size_est_min < ceil(estimate)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); - sub->sampler_size_est_need = estimate; - sub->view_size_est_need = estimate; - } + if (sub->view_size_est_min < ceil (estimate)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); + sub->sampler_size_est_need = estimate; + sub->view_size_est_need = estimate; + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); - //sub->sampler_size_est_need = sub->view_size_est_min; - sub->view_size_est_need = sub->view_size_est_min; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); + // sub->sampler_size_est_need = sub->view_size_est_min; + sub->view_size_est_need = sub->view_size_est_min; + } if (sub == msub) - { - GNUNET_STATISTICS_set(stats, - "view size aim", - sub->view_size_est_need, - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "view size aim", + sub->view_size_est_need, + GNUNET_NO); + } /* If the NSE has changed adapt the lists accordingly */ - resize_wrapper(sub->sampler, sub->sampler_size_est_need); - View_change_len(sub->view, sub->view_size_est_need); + resize_wrapper (sub->sampler, sub->sampler_size_est_need); + View_change_len (sub->view, sub->view_size_est_need); } @@ -3223,24 +3237,24 @@ adapt_sizes(struct Sub *sub, double logestimate, double std_dev) * @param std_dev standard deviation for the estimate */ static void -nse_callback(void *cls, - struct GNUNET_TIME_Absolute timestamp, - double logestimate, double std_dev) +nse_callback (void *cls, + struct GNUNET_TIME_Absolute timestamp, + double logestimate, double std_dev) { - (void)cls; - (void)timestamp; + (void) cls; + (void) timestamp; struct ClientContext *cli_ctx_iter; - adapt_sizes(msub, logestimate, std_dev); + adapt_sizes (msub, logestimate, std_dev); for (cli_ctx_iter = cli_ctx_head; NULL != cli_ctx_iter; cli_ctx_iter = cli_ctx_iter->next) + { + if (NULL != cli_ctx_iter->sub) { - if (NULL != cli_ctx_iter->sub) - { - adapt_sizes(cli_ctx_iter->sub, logestimate, std_dev); - } + adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev); } + } } @@ -3254,24 +3268,24 @@ nse_callback(void *cls, * #GNUNET_SYSERR otherwise */ static int -check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) +check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) { struct ClientContext *cli_ctx = cls; - uint16_t msize = ntohs(msg->header.size); - uint32_t num_peers = ntohl(msg->num_peers); + uint16_t msize = ntohs (msg->header.size); + uint32_t num_peers = ntohl (msg->num_peers); msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage); if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "message says it sends %" PRIu32 " peers, have space for %lu peers\n", - ntohl(msg->num_peers), - (msize / sizeof(struct GNUNET_PeerIdentity))); - GNUNET_break(0); - GNUNET_SERVICE_client_drop(cli_ctx->client); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "message says it sends %" PRIu32 " peers, have space for %lu peers\n", + ntohl (msg->num_peers), + (msize / sizeof(struct GNUNET_PeerIdentity))); + GNUNET_break (0); + GNUNET_SERVICE_client_drop (cli_ctx->client); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -3283,34 +3297,34 @@ check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) * @param message the actual message */ static void -handle_client_seed(void *cls, - const struct GNUNET_RPS_CS_SeedMessage *msg) +handle_client_seed (void *cls, + const struct GNUNET_RPS_CS_SeedMessage *msg) { struct ClientContext *cli_ctx = cls; struct GNUNET_PeerIdentity *peers; uint32_t num_peers; uint32_t i; - num_peers = ntohl(msg->num_peers); - peers = (struct GNUNET_PeerIdentity *)&msg[1]; + num_peers = ntohl (msg->num_peers); + peers = (struct GNUNET_PeerIdentity *) &msg[1]; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client seeded peers:\n"); - print_peer_list(peers, num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client seeded peers:\n"); + print_peer_list (peers, num_peers); for (i = 0; i < num_peers; i++) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updating samplers with seed %" PRIu32 ": %s\n", - i, - GNUNET_i2s(&peers[i])); - - if (NULL != msub) - got_peer(msub, &peers[i]); /* Condition needed? */ - if (NULL != cli_ctx->sub) - got_peer(cli_ctx->sub, &peers[i]); - } - GNUNET_SERVICE_client_continue(cli_ctx->client); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updating samplers with seed %" PRIu32 ": %s\n", + i, + GNUNET_i2s (&peers[i])); + + if (NULL != msub) + got_peer (msub, &peers[i]); /* Condition needed? */ + if (NULL != cli_ctx->sub) + got_peer (cli_ctx->sub, &peers[i]); + } + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3322,22 +3336,22 @@ handle_client_seed(void *cls, * receive */ static void -handle_client_view_request(void *cls, - const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) +handle_client_view_request (void *cls, + const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) { struct ClientContext *cli_ctx = cls; uint64_t num_updates; - num_updates = ntohl(msg->num_updates); + num_updates = ntohl (msg->num_updates); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client requested %" PRIu64 " updates of view.\n", - num_updates); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client requested %" PRIu64 " updates of view.\n", + num_updates); - GNUNET_assert(NULL != cli_ctx); + GNUNET_assert (NULL != cli_ctx); cli_ctx->view_updates_left = num_updates; - send_view(cli_ctx, NULL, 0); - GNUNET_SERVICE_client_continue(cli_ctx->client); + send_view (cli_ctx, NULL, 0); + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3348,23 +3362,23 @@ handle_client_view_request(void *cls, * @param msg Unused */ static void -handle_client_view_cancel(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_client_view_cancel (void *cls, + const struct GNUNET_MessageHeader *msg) { struct ClientContext *cli_ctx = cls; - (void)msg; + (void) msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client does not want to receive updates of view any more.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client does not want to receive updates of view any more.\n"); - GNUNET_assert(NULL != cli_ctx); + GNUNET_assert (NULL != cli_ctx); cli_ctx->view_updates_left = 0; - GNUNET_SERVICE_client_continue(cli_ctx->client); + GNUNET_SERVICE_client_continue (cli_ctx->client); if (GNUNET_YES == cli_ctx->stream_update) - { - destroy_cli_ctx(cli_ctx); - } + { + destroy_cli_ctx (cli_ctx); + } } @@ -3375,19 +3389,20 @@ handle_client_view_cancel(void *cls, * @param message unused */ static void -handle_client_stream_request(void *cls, - const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg) +handle_client_stream_request (void *cls, + const struct + GNUNET_RPS_CS_DEBUG_StreamRequest *msg) { struct ClientContext *cli_ctx = cls; - (void)msg; + (void) msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client requested peers from biased stream.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client requested peers from biased stream.\n"); cli_ctx->stream_update = GNUNET_YES; - GNUNET_assert(NULL != cli_ctx); - GNUNET_SERVICE_client_continue(cli_ctx->client); + GNUNET_assert (NULL != cli_ctx); + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3398,19 +3413,19 @@ handle_client_stream_request(void *cls, * @param msg unused */ static void -handle_client_stream_cancel(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_client_stream_cancel (void *cls, + const struct GNUNET_MessageHeader *msg) { struct ClientContext *cli_ctx = cls; - (void)msg; + (void) msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client canceled receiving peers from biased stream.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client canceled receiving peers from biased stream.\n"); cli_ctx->stream_update = GNUNET_NO; - GNUNET_assert(NULL != cli_ctx); - GNUNET_SERVICE_client_continue(cli_ctx->client); + GNUNET_assert (NULL != cli_ctx); + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3421,25 +3436,26 @@ handle_client_stream_cancel(void *cls, * @param msg Message containing the necessary information */ static void -handle_client_start_sub(void *cls, - const struct GNUNET_RPS_CS_SubStartMessage *msg) +handle_client_start_sub (void *cls, + const struct GNUNET_RPS_CS_SubStartMessage *msg) { struct ClientContext *cli_ctx = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); - if (NULL != cli_ctx->sub && - 0 != memcmp(&cli_ctx->sub->hash, - &msg->hash, - sizeof(struct GNUNET_HashCode))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, "Already have a Sub with different share for this client. Remove old one, add new.\n"); - destroy_sub(cli_ctx->sub); - cli_ctx->sub = NULL; - } - cli_ctx->sub = new_sub(&msg->hash, - msub->sampler_size_est_min, // TODO make api input? - GNUNET_TIME_relative_ntoh(msg->round_interval)); - GNUNET_SERVICE_client_continue(cli_ctx->client); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); + if ((NULL != cli_ctx->sub)&& + (0 != memcmp (&cli_ctx->sub->hash, + &msg->hash, + sizeof(struct GNUNET_HashCode))) ) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Already have a Sub with different share for this client. Remove old one, add new.\n"); + destroy_sub (cli_ctx->sub); + cli_ctx->sub = NULL; + } + cli_ctx->sub = new_sub (&msg->hash, + msub->sampler_size_est_min, // TODO make api input? + GNUNET_TIME_relative_ntoh (msg->round_interval)); + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3450,19 +3466,21 @@ handle_client_start_sub(void *cls, * @param msg Message containing the hash that identifies the Sub */ static void -handle_client_stop_sub(void *cls, - const struct GNUNET_RPS_CS_SubStopMessage *msg) +handle_client_stop_sub (void *cls, + const struct GNUNET_RPS_CS_SubStopMessage *msg) { struct ClientContext *cli_ctx = cls; - GNUNET_assert(NULL != cli_ctx->sub); - if (0 != memcmp(&cli_ctx->sub->hash, &msg->hash, sizeof(struct GNUNET_HashCode))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, "Share of current sub and request differ!\n"); - } - destroy_sub(cli_ctx->sub); + GNUNET_assert (NULL != cli_ctx->sub); + if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof(struct + GNUNET_HashCode))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Share of current sub and request differ!\n"); + } + destroy_sub (cli_ctx->sub); cli_ctx->sub = NULL; - GNUNET_SERVICE_client_continue(cli_ctx->client); + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -3476,25 +3494,25 @@ handle_client_stop_sub(void *cls, * @param msg Message - unused */ static void -handle_peer_check(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_peer_check (void *cls, + const struct GNUNET_MessageHeader *msg) { const struct ChannelCtx *channel_ctx = cls; const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; - (void)msg; + (void) msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received CHECK_LIVE (%s)\n", GNUNET_i2s(peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); if (channel_ctx->peer_ctx->sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# pending online checks", - -1, - GNUNET_NO); - } - - GNUNET_CADET_receive_done(channel_ctx->channel); + { + GNUNET_STATISTICS_update (stats, + "# pending online checks", + -1, + GNUNET_NO); + } + + GNUNET_CADET_receive_done (channel_ctx->channel); } @@ -3508,70 +3526,70 @@ handle_peer_check(void *cls, * @param msg Message - unused */ static void -handle_peer_push(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_peer_push (void *cls, + const struct GNUNET_MessageHeader *msg) { const struct ChannelCtx *channel_ctx = cls; const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; - (void)msg; + (void) msg; // (check the proof of work (?)) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received PUSH (%s)\n", - GNUNET_i2s(peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received PUSH (%s)\n", + GNUNET_i2s (peer)); if (channel_ctx->peer_ctx->sub == msub) + { + GNUNET_STATISTICS_update (stats, "# push message received", 1, GNUNET_NO); + if ((NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + peer))) { - GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO); - if (NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - peer)) - { - GNUNET_STATISTICS_update(stats, - "# push message received (multi-hop peer)", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# push message received (multi-hop peer)", + 1, + GNUNET_NO); } + } #if ENABLE_MALICIOUS struct AttackedPeer *tmp_att_peer; if ((1 == mal_type) || (3 == mal_type)) - { /* Try to maximise representation */ - tmp_att_peer = GNUNET_new(struct AttackedPeer); - tmp_att_peer->peer_id = *peer; - if (NULL == att_peer_set) - att_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); - if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, - peer)) - { - GNUNET_CONTAINER_DLL_insert(att_peers_head, - att_peers_tail, - tmp_att_peer); - add_peer_array_to_set(peer, 1, att_peer_set); - } - else - { - GNUNET_free(tmp_att_peer); - } + { /* Try to maximise representation */ + tmp_att_peer = GNUNET_new (struct AttackedPeer); + tmp_att_peer->peer_id = *peer; + if (NULL == att_peer_set) + att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, + peer)) + { + GNUNET_CONTAINER_DLL_insert (att_peers_head, + att_peers_tail, + tmp_att_peer); + add_peer_array_to_set (peer, 1, att_peer_set); } + else + { + GNUNET_free (tmp_att_peer); + } + } else if (2 == mal_type) - { - /* We attack one single well-known peer - simply ignore */ - } + { + /* We attack one single well-known peer - simply ignore */ + } #endif /* ENABLE_MALICIOUS */ /* Add the sending peer to the push_map */ - CustomPeerMap_put(channel_ctx->peer_ctx->sub->push_map, peer); + CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer); - GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, - &channel_ctx->peer_ctx->peer_id)); - GNUNET_CADET_receive_done(channel_ctx->channel); + GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, + &channel_ctx->peer_ctx->peer_id)); + GNUNET_CADET_receive_done (channel_ctx->channel); } @@ -3584,57 +3602,58 @@ handle_peer_push(void *cls, * @param msg Message - unused */ static void -handle_peer_pull_request(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_peer_pull_request (void *cls, + const struct GNUNET_MessageHeader *msg) { const struct ChannelCtx *channel_ctx = cls; struct PeerContext *peer_ctx = channel_ctx->peer_ctx; const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; const struct GNUNET_PeerIdentity *view_array; - (void)msg; + (void) msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s(peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s ( + peer)); if (peer_ctx->sub == msub) + { + GNUNET_STATISTICS_update (stats, + "# pull request message received", + 1, + GNUNET_NO); + if ((NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + &peer_ctx->peer_id))) { - GNUNET_STATISTICS_update(stats, - "# pull request message received", - 1, - GNUNET_NO); - if (NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - &peer_ctx->peer_id)) - { - GNUNET_STATISTICS_update(stats, - "# pull request message received (multi-hop peer)", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# pull request message received (multi-hop peer)", + 1, + GNUNET_NO); } + } #if ENABLE_MALICIOUS - if (1 == mal_type - || 3 == mal_type) - { /* Try to maximise representation */ - send_pull_reply(peer_ctx, mal_peers, num_mal_peers); - } + if ((1 == mal_type) + ||(3 == mal_type)) + { /* Try to maximise representation */ + send_pull_reply (peer_ctx, mal_peers, num_mal_peers); + } else if (2 == mal_type) - { /* Try to partition network */ - if (0 == GNUNET_memcmp(&attacked_peer, peer)) - { - send_pull_reply(peer_ctx, mal_peers, num_mal_peers); - } + { /* Try to partition network */ + if (0 == GNUNET_memcmp (&attacked_peer, peer)) + { + send_pull_reply (peer_ctx, mal_peers, num_mal_peers); } + } #endif /* ENABLE_MALICIOUS */ - GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, - &channel_ctx->peer_ctx->peer_id)); - GNUNET_CADET_receive_done(channel_ctx->channel); - view_array = View_get_as_array(channel_ctx->peer_ctx->sub->view); - send_pull_reply(peer_ctx, - view_array, - View_size(channel_ctx->peer_ctx->sub->view)); + GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, + &channel_ctx->peer_ctx->peer_id)); + GNUNET_CADET_receive_done (channel_ctx->channel); + view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view); + send_pull_reply (peer_ctx, + view_array, + View_size (channel_ctx->peer_ctx->sub->view)); } @@ -3646,45 +3665,47 @@ handle_peer_pull_request(void *cls, * @param msg Message containing the replied peers */ static int -check_peer_pull_reply(void *cls, - const struct GNUNET_RPS_P2P_PullReplyMessage *msg) +check_peer_pull_reply (void *cls, + const struct GNUNET_RPS_P2P_PullReplyMessage *msg) { struct ChannelCtx *channel_ctx = cls; struct PeerContext *sender_ctx = channel_ctx->peer_ctx; - if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs(msg->header.size)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - - if ((ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / - sizeof(struct GNUNET_PeerIdentity) != ntohl(msg->num_peers)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "message says it sends %" PRIu32 " peers, have space for %lu peers\n", - ntohl(msg->num_peers), - (ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / - sizeof(struct GNUNET_PeerIdentity)); - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - - if (GNUNET_YES != check_peer_flag(sender_ctx->sub->peer_map, - &sender_ctx->peer_id, - Peers_PULL_REPLY_PENDING)) + if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + if ((ntohs (msg->header.size) - sizeof(struct + GNUNET_RPS_P2P_PullReplyMessage)) + / sizeof(struct GNUNET_PeerIdentity) != ntohl (msg->num_peers)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "message says it sends %" PRIu32 " peers, have space for %lu peers\n", + ntohl (msg->num_peers), + (ntohs (msg->header.size) - sizeof(struct + GNUNET_RPS_P2P_PullReplyMessage)) + / sizeof(struct GNUNET_PeerIdentity)); + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map, + &sender_ctx->peer_id, + Peers_PULL_REPLY_PENDING)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Received a pull reply from a peer (%s) we didn't request one from!\n", + GNUNET_i2s (&sender_ctx->peer_id)); + if (sender_ctx->sub == msub) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Received a pull reply from a peer (%s) we didn't request one from!\n", - GNUNET_i2s(&sender_ctx->peer_id)); - if (sender_ctx->sub == msub) - { - GNUNET_STATISTICS_update(stats, - "# unrequested pull replies", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# unrequested pull replies", + 1, + GNUNET_NO); } + } return GNUNET_OK; } @@ -3696,8 +3717,8 @@ check_peer_pull_reply(void *cls, * @param msg The message header */ static void -handle_peer_pull_reply(void *cls, - const struct GNUNET_RPS_P2P_PullReplyMessage *msg) +handle_peer_pull_reply (void *cls, + const struct GNUNET_RPS_P2P_PullReplyMessage *msg) { const struct ChannelCtx *channel_ctx = cls; const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; @@ -3710,94 +3731,96 @@ handle_peer_pull_reply(void *cls, #endif /* ENABLE_MALICIOUS */ sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s(sender)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s ( + sender)); if (channel_ctx->peer_ctx->sub == msub) + { + GNUNET_STATISTICS_update (stats, + "# pull reply messages received", + 1, + GNUNET_NO); + if ((NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + &channel_ctx-> + peer_ctx->peer_id)) ) { - GNUNET_STATISTICS_update(stats, - "# pull reply messages received", - 1, - GNUNET_NO); - if (NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - &channel_ctx->peer_ctx->peer_id)) - { - GNUNET_STATISTICS_update(stats, - "# pull reply messages received (multi-hop peer)", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# pull reply messages received (multi-hop peer)", + 1, + GNUNET_NO); } + } #if ENABLE_MALICIOUS // We shouldn't even receive pull replies as we're not sending if (2 == mal_type) - { - } + { + } #endif /* ENABLE_MALICIOUS */ /* Do actual logic */ - peers = (const struct GNUNET_PeerIdentity *)&msg[1]; + peers = (const struct GNUNET_PeerIdentity *) &msg[1]; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "PULL REPLY received, got following %u peers:\n", - ntohl(msg->num_peers)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "PULL REPLY received, got following %u peers:\n", + ntohl (msg->num_peers)); - for (i = 0; i < ntohl(msg->num_peers); i++) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%u. %s\n", - i, - GNUNET_i2s(&peers[i])); + for (i = 0; i < ntohl (msg->num_peers); i++) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%u. %s\n", + i, + GNUNET_i2s (&peers[i])); #if ENABLE_MALICIOUS - if ((NULL != att_peer_set) && - (1 == mal_type || 3 == mal_type)) - { /* Add attacked peer to local list */ + if ((NULL != att_peer_set) && + ((1 == mal_type) ||(3 == mal_type) )) + { /* Add attacked peer to local list */ // TODO check if we sent a request and this was the first reply - if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, - &peers[i]) - && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mal_peer_set, - &peers[i])) - { - tmp_att_peer = GNUNET_new(struct AttackedPeer); - tmp_att_peer->peer_id = peers[i]; - GNUNET_CONTAINER_DLL_insert(att_peers_head, - att_peers_tail, - tmp_att_peer); - add_peer_array_to_set(&peers[i], 1, att_peer_set); - } - continue; - } + if ((GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, + &peers[i])) + &&(GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, + &peers[i])) ) + { + tmp_att_peer = GNUNET_new (struct AttackedPeer); + tmp_att_peer->peer_id = peers[i]; + GNUNET_CONTAINER_DLL_insert (att_peers_head, + att_peers_tail, + tmp_att_peer); + add_peer_array_to_set (&peers[i], 1, att_peer_set); + } + continue; + } #endif /* ENABLE_MALICIOUS */ - /* Make sure we 'know' about this peer */ - (void)insert_peer(channel_ctx->peer_ctx->sub, + /* Make sure we 'know' about this peer */ + (void) insert_peer (channel_ctx->peer_ctx->sub, &peers[i]); - if (GNUNET_YES == check_peer_valid(channel_ctx->peer_ctx->sub->valid_peers, - &peers[i])) - { - CustomPeerMap_put(channel_ctx->peer_ctx->sub->pull_map, - &peers[i]); - } - else - { - schedule_operation(channel_ctx->peer_ctx, - insert_in_pull_map, - channel_ctx->peer_ctx->sub); /* cls */ - (void)issue_peer_online_check(channel_ctx->peer_ctx->sub, - &peers[i]); - } + if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers, + &peers[i])) + { + CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map, + &peers[i]); } - - UNSET_PEER_FLAG(get_peer_ctx(channel_ctx->peer_ctx->sub->peer_map, - sender), - Peers_PULL_REPLY_PENDING); - clean_peer(channel_ctx->peer_ctx->sub, - sender); - - GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, - sender)); - GNUNET_CADET_receive_done(channel_ctx->channel); + else + { + schedule_operation (channel_ctx->peer_ctx, + insert_in_pull_map, + channel_ctx->peer_ctx->sub); /* cls */ + (void) issue_peer_online_check (channel_ctx->peer_ctx->sub, + &peers[i]); + } + } + + UNSET_PEER_FLAG (get_peer_ctx (channel_ctx->peer_ctx->sub->peer_map, + sender), + Peers_PULL_REPLY_PENDING); + clean_peer (channel_ctx->peer_ctx->sub, + sender); + + GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, + sender)); + GNUNET_CADET_receive_done (channel_ctx->channel); } @@ -3812,8 +3835,8 @@ handle_peer_pull_reply(void *cls, * @param spread the inverse amount of deviation from the mean */ static struct GNUNET_TIME_Relative -compute_rand_delay(struct GNUNET_TIME_Relative mean, - unsigned int spread) +compute_rand_delay (struct GNUNET_TIME_Relative mean, + unsigned int spread) { struct GNUNET_TIME_Relative half_interval; struct GNUNET_TIME_Relative ret; @@ -3821,30 +3844,32 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean, unsigned int max_rand_delay; if (0 == spread) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not accepting spread of 0\n"); - GNUNET_break(0); - GNUNET_assert(0); - } - GNUNET_assert(0 != mean.rel_value_us); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not accepting spread of 0\n"); + GNUNET_break (0); + GNUNET_assert (0); + } + GNUNET_assert (0 != mean.rel_value_us); /* Compute random time value between spread * mean and spread * mean */ - half_interval = GNUNET_TIME_relative_divide(mean, spread); + half_interval = GNUNET_TIME_relative_divide (mean, spread); - max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2 / spread); + max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us + / mean.rel_value_us * (2 / spread); /** * Compute random value between (0 and 1) * round_interval * via multiplying round_interval with a 'fraction' (0 to value)/value */ - rand_delay = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); - ret = GNUNET_TIME_relative_saturating_multiply(mean, rand_delay); - ret = GNUNET_TIME_relative_divide(ret, max_rand_delay); - ret = GNUNET_TIME_relative_add(ret, half_interval); + rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + max_rand_delay); + ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay); + ret = GNUNET_TIME_relative_divide (ret, max_rand_delay); + ret = GNUNET_TIME_relative_add (ret, half_interval); if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Returning FOREVER_REL\n"); + LOG (GNUNET_ERROR_TYPE_WARNING, + "Returning FOREVER_REL\n"); return ret; } @@ -3856,41 +3881,41 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean, * @param peer_ctx Context to the peer to send request to */ static void -send_pull_request(struct PeerContext *peer_ctx) +send_pull_request (struct PeerContext *peer_ctx) { struct GNUNET_MQ_Envelope *ev; - GNUNET_assert(GNUNET_NO == check_peer_flag(peer_ctx->sub->peer_map, - &peer_ctx->peer_id, - Peers_PULL_REPLY_PENDING)); - SET_PEER_FLAG(peer_ctx, - Peers_PULL_REPLY_PENDING); + GNUNET_assert (GNUNET_NO == check_peer_flag (peer_ctx->sub->peer_map, + &peer_ctx->peer_id, + Peers_PULL_REPLY_PENDING)); + SET_PEER_FLAG (peer_ctx, + Peers_PULL_REPLY_PENDING); peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send PULL REQUEST to peer %s.\n", - GNUNET_i2s(&peer_ctx->peer_id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send PULL REQUEST to peer %s.\n", + GNUNET_i2s (&peer_ctx->peer_id)); - ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); - send_message(peer_ctx, - ev, - "PULL REQUEST"); + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); + send_message (peer_ctx, + ev, + "PULL REQUEST"); if (peer_ctx->sub) + { + GNUNET_STATISTICS_update (stats, + "# pull request send issued", + 1, + GNUNET_NO); + if ((NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + &peer_ctx->peer_id))) { - GNUNET_STATISTICS_update(stats, - "# pull request send issued", - 1, - GNUNET_NO); - if (NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - &peer_ctx->peer_id)) - { - GNUNET_STATISTICS_update(stats, - "# pull request send issued (multi-hop peer)", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# pull request send issued (multi-hop peer)", + 1, + GNUNET_NO); } + } } @@ -3900,32 +3925,32 @@ send_pull_request(struct PeerContext *peer_ctx) * @param peer_ctx Context of peer to send push to */ static void -send_push(struct PeerContext *peer_ctx) +send_push (struct PeerContext *peer_ctx) { struct GNUNET_MQ_Envelope *ev; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send PUSH to peer %s.\n", - GNUNET_i2s(&peer_ctx->peer_id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send PUSH to peer %s.\n", + GNUNET_i2s (&peer_ctx->peer_id)); - ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); - send_message(peer_ctx, ev, "PUSH"); + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); + send_message (peer_ctx, ev, "PUSH"); if (peer_ctx->sub) + { + GNUNET_STATISTICS_update (stats, + "# push send issued", + 1, + GNUNET_NO); + if ((NULL != map_single_hop) && + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, + &peer_ctx->peer_id))) { - GNUNET_STATISTICS_update(stats, - "# push send issued", - 1, - GNUNET_NO); - if (NULL != map_single_hop && - GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, - &peer_ctx->peer_id)) - { - GNUNET_STATISTICS_update(stats, - "# push send issued (multi-hop peer)", - 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (stats, + "# push send issued (multi-hop peer)", + 1, + GNUNET_NO); } + } } @@ -3941,25 +3966,25 @@ send_push(struct PeerContext *peer_ctx) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_client_act_malicious(void *cls, - const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) +check_client_act_malicious (void *cls, + const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) { struct ClientContext *cli_ctx = cls; - uint16_t msize = ntohs(msg->header.size); - uint32_t num_peers = ntohl(msg->num_peers); + uint16_t msize = ntohs (msg->header.size); + uint32_t num_peers = ntohl (msg->num_peers); msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage); if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "message says it sends %" PRIu32 " peers, have space for %lu peers\n", - ntohl(msg->num_peers), - (msize / sizeof(struct GNUNET_PeerIdentity))); - GNUNET_break(0); - GNUNET_SERVICE_client_drop(cli_ctx->client); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "message says it sends %" PRIu32 " peers, have space for %lu peers\n", + ntohl (msg->num_peers), + (msize / sizeof(struct GNUNET_PeerIdentity))); + GNUNET_break (0); + GNUNET_SERVICE_client_drop (cli_ctx->client); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -3971,8 +3996,9 @@ check_client_act_malicious(void *cls, * @param msg The message header */ static void -handle_client_act_malicious(void *cls, - const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) +handle_client_act_malicious (void *cls, + const struct + GNUNET_RPS_CS_ActMaliciousMessage *msg) { struct ClientContext *cli_ctx = cls; struct GNUNET_PeerIdentity *peers; @@ -3983,100 +4009,100 @@ handle_client_act_malicious(void *cls, if (NULL == sub) sub = msub; /* Do actual logic */ - peers = (struct GNUNET_PeerIdentity *)&msg[1]; - mal_type = ntohl(msg->type); + peers = (struct GNUNET_PeerIdentity *) &msg[1]; + mal_type = ntohl (msg->type); if (NULL == mal_peer_set) - mal_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); + mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", - mal_type, - ntohl(msg->num_peers)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", + mal_type, + ntohl (msg->num_peers)); if (1 == mal_type) - { /* Try to maximise representation */ + { /* Try to maximise representation */ /* Add other malicious peers to those we already know */ - num_mal_peers_sent = ntohl(msg->num_peers); - num_mal_peers_old = num_mal_peers; - GNUNET_array_grow(mal_peers, - num_mal_peers, - num_mal_peers + num_mal_peers_sent); - GNUNET_memcpy(&mal_peers[num_mal_peers_old], - peers, - num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); - - /* Add all mal peers to mal_peer_set */ - add_peer_array_to_set(&mal_peers[num_mal_peers_old], - num_mal_peers_sent, - mal_peer_set); - - /* Substitute do_round () with do_mal_round () */ - GNUNET_assert(NULL != sub->do_round_task); - GNUNET_SCHEDULER_cancel(sub->do_round_task); - sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); - } + num_mal_peers_sent = ntohl (msg->num_peers); + num_mal_peers_old = num_mal_peers; + GNUNET_array_grow (mal_peers, + num_mal_peers, + num_mal_peers + num_mal_peers_sent); + GNUNET_memcpy (&mal_peers[num_mal_peers_old], + peers, + num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); + + /* Add all mal peers to mal_peer_set */ + add_peer_array_to_set (&mal_peers[num_mal_peers_old], + num_mal_peers_sent, + mal_peer_set); + + /* Substitute do_round () with do_mal_round () */ + GNUNET_assert (NULL != sub->do_round_task); + GNUNET_SCHEDULER_cancel (sub->do_round_task); + sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); + } else if ((2 == mal_type) || (3 == mal_type)) - { /* Try to partition the network */ + { /* Try to partition the network */ /* Add other malicious peers to those we already know */ - num_mal_peers_sent = ntohl(msg->num_peers) - 1; - num_mal_peers_old = num_mal_peers; - GNUNET_assert(GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); - GNUNET_array_grow(mal_peers, - num_mal_peers, - num_mal_peers + num_mal_peers_sent); - if (NULL != mal_peers && - 0 != num_mal_peers) - { - GNUNET_memcpy(&mal_peers[num_mal_peers_old], - peers, - num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); - - /* Add all mal peers to mal_peer_set */ - add_peer_array_to_set(&mal_peers[num_mal_peers_old], - num_mal_peers_sent, - mal_peer_set); - } - - /* Store the one attacked peer */ - GNUNET_memcpy(&attacked_peer, - &msg->attacked_peer, - sizeof(struct GNUNET_PeerIdentity)); - /* Set the flag of the attacked peer to valid to avoid problems */ - if (GNUNET_NO == check_peer_known(sub->peer_map, &attacked_peer)) - { - (void)issue_peer_online_check(sub, &attacked_peer); - } - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Attacked peer is %s\n", - GNUNET_i2s(&attacked_peer)); - - /* Substitute do_round () with do_mal_round () */ - if (NULL != sub->do_round_task) - { - /* Probably in shutdown */ - GNUNET_SCHEDULER_cancel(sub->do_round_task); - sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); - } + num_mal_peers_sent = ntohl (msg->num_peers) - 1; + num_mal_peers_old = num_mal_peers; + GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); + GNUNET_array_grow (mal_peers, + num_mal_peers, + num_mal_peers + num_mal_peers_sent); + if ((NULL != mal_peers) && + (0 != num_mal_peers) ) + { + GNUNET_memcpy (&mal_peers[num_mal_peers_old], + peers, + num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); + + /* Add all mal peers to mal_peer_set */ + add_peer_array_to_set (&mal_peers[num_mal_peers_old], + num_mal_peers_sent, + mal_peer_set); } - else if (0 == mal_type) - { /* Stop acting malicious */ - GNUNET_array_grow(mal_peers, num_mal_peers, 0); - /* Substitute do_mal_round () with do_round () */ - GNUNET_SCHEDULER_cancel(sub->do_round_task); - sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); + /* Store the one attacked peer */ + GNUNET_memcpy (&attacked_peer, + &msg->attacked_peer, + sizeof(struct GNUNET_PeerIdentity)); + /* Set the flag of the attacked peer to valid to avoid problems */ + if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer)) + { + (void) issue_peer_online_check (sub, &attacked_peer); } - else + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Attacked peer is %s\n", + GNUNET_i2s (&attacked_peer)); + + /* Substitute do_round () with do_mal_round () */ + if (NULL != sub->do_round_task) { - GNUNET_break(0); - GNUNET_SERVICE_client_continue(cli_ctx->client); + /* Probably in shutdown */ + GNUNET_SCHEDULER_cancel (sub->do_round_task); + sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); } - GNUNET_SERVICE_client_continue(cli_ctx->client); + } + else if (0 == mal_type) + { /* Stop acting malicious */ + GNUNET_array_grow (mal_peers, num_mal_peers, 0); + + /* Substitute do_mal_round () with do_round () */ + GNUNET_SCHEDULER_cancel (sub->do_round_task); + sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); + } + else + { + GNUNET_break (0); + GNUNET_SERVICE_client_continue (cli_ctx->client); + } + GNUNET_SERVICE_client_continue (cli_ctx->client); } @@ -4088,7 +4114,7 @@ handle_client_act_malicious(void *cls, * @param cls Closure - Sub */ static void -do_mal_round(void *cls) +do_mal_round (void *cls) { uint32_t num_pushes; uint32_t i; @@ -4096,119 +4122,119 @@ do_mal_round(void *cls) struct AttackedPeer *tmp_att_peer; struct Sub *sub = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to execute next round maliciously type %" PRIu32 ".\n", - mal_type); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to execute next round maliciously type %" PRIu32 ".\n", + mal_type); sub->do_round_task = NULL; - GNUNET_assert(mal_type <= 3); + GNUNET_assert (mal_type <= 3); /* Do malicious actions */ if (1 == mal_type) - { /* Try to maximise representation */ + { /* Try to maximise representation */ /* The maximum of pushes we're going to send this round */ - num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit, + num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit, num_attacked_peers), - GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send %" PRIu32 " pushes\n", - num_pushes); - - /* Send PUSHes to attacked peers */ - for (i = 0; i < num_pushes; i++) - { - if (att_peers_tail == att_peer_index) - att_peer_index = att_peers_head; - else - att_peer_index = att_peer_index->next; - - send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); - } - - /* Send PULLs to some peers to learn about additional peers to attack */ - tmp_att_peer = att_peer_index; - for (i = 0; i < num_pushes * alpha; i++) - { - if (att_peers_tail == tmp_att_peer) - tmp_att_peer = att_peers_head; - else - att_peer_index = tmp_att_peer->next; - - send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); - } + GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send %" PRIu32 " pushes\n", + num_pushes); + + /* Send PUSHes to attacked peers */ + for (i = 0; i < num_pushes; i++) + { + if (att_peers_tail == att_peer_index) + att_peer_index = att_peers_head; + else + att_peer_index = att_peer_index->next; + + send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); + } + + /* Send PULLs to some peers to learn about additional peers to attack */ + tmp_att_peer = att_peer_index; + for (i = 0; i < num_pushes * alpha; i++) + { + if (att_peers_tail == tmp_att_peer) + tmp_att_peer = att_peers_head; + else + att_peer_index = tmp_att_peer->next; + + send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); } + } else if (2 == mal_type) - { /** + { /** * Try to partition the network * Send as many pushes to the attacked peer as possible * That is one push per round as it will ignore more. */ - (void)issue_peer_online_check(sub, &attacked_peer); - if (GNUNET_YES == check_peer_flag(sub->peer_map, - &attacked_peer, - Peers_ONLINE)) - send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); - } + (void) issue_peer_online_check (sub, &attacked_peer); + if (GNUNET_YES == check_peer_flag (sub->peer_map, + &attacked_peer, + Peers_ONLINE)) + send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); + } if (3 == mal_type) - { /* Combined attack */ + { /* Combined attack */ /* Send PUSH to attacked peers */ - if (GNUNET_YES == check_peer_known(sub->peer_map, &attacked_peer)) - { - (void)issue_peer_online_check(sub, &attacked_peer); - if (GNUNET_YES == check_peer_flag(sub->peer_map, - &attacked_peer, - Peers_ONLINE)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Goding to send push to attacked peer (%s)\n", - GNUNET_i2s(&attacked_peer)); - send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); - } - } - (void)issue_peer_online_check(sub, &attacked_peer); - - /* The maximum of pushes we're going to send this round */ - num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit - 1, + if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer)) + { + (void) issue_peer_online_check (sub, &attacked_peer); + if (GNUNET_YES == check_peer_flag (sub->peer_map, + &attacked_peer, + Peers_ONLINE)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Goding to send push to attacked peer (%s)\n", + GNUNET_i2s (&attacked_peer)); + send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); + } + } + (void) issue_peer_online_check (sub, &attacked_peer); + + /* The maximum of pushes we're going to send this round */ + num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, num_attacked_peers), - GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send %" PRIu32 " pushes\n", - num_pushes); - - for (i = 0; i < num_pushes; i++) - { - if (att_peers_tail == att_peer_index) - att_peer_index = att_peers_head; - else - att_peer_index = att_peer_index->next; - - send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); - } - - /* Send PULLs to some peers to learn about additional peers to attack */ - tmp_att_peer = att_peer_index; - for (i = 0; i < num_pushes * alpha; i++) - { - if (att_peers_tail == tmp_att_peer) - tmp_att_peer = att_peers_head; - else - att_peer_index = tmp_att_peer->next; - - send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); - } + GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send %" PRIu32 " pushes\n", + num_pushes); + + for (i = 0; i < num_pushes; i++) + { + if (att_peers_tail == att_peer_index) + att_peer_index = att_peers_head; + else + att_peer_index = att_peer_index->next; + + send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); } + /* Send PULLs to some peers to learn about additional peers to attack */ + tmp_att_peer = att_peer_index; + for (i = 0; i < num_pushes * alpha; i++) + { + if (att_peers_tail == tmp_att_peer) + tmp_att_peer = att_peers_head; + else + att_peer_index = tmp_att_peer->next; + + send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); + } + } + /* Schedule next round */ - time_next_round = compute_rand_delay(sub->round_interval, 2); + time_next_round = compute_rand_delay (sub->round_interval, 2); - GNUNET_assert(NULL == sub->do_round_task); - sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, - &do_mal_round, sub); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); + GNUNET_assert (NULL == sub->do_round_task); + sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, + &do_mal_round, sub); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); } #endif /* ENABLE_MALICIOUS */ @@ -4221,7 +4247,7 @@ do_mal_round(void *cls) * @param cls Closure - Sub */ static void -do_round(void *cls) +do_round (void *cls) { unsigned int i; const struct GNUNET_PeerIdentity *view_array; @@ -4235,308 +4261,327 @@ do_round(void *cls) struct Sub *sub = cls; sub->num_rounds++; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to execute next round.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to execute next round.\n"); if (sub == msub) - { - GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO); - } + { + GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO); + } sub->do_round_task = NULL; #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "___ new round ___"); + to_file (sub->file_name_view_log, + "___ new round ___"); #endif /* TO_FILE_FULL */ - view_array = View_get_as_array(sub->view); - for (i = 0; i < View_size(sub->view); i++) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "\t%s\n", GNUNET_i2s(&view_array[i])); + view_array = View_get_as_array (sub->view); + for (i = 0; i < View_size (sub->view); i++) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "\t%s\n", GNUNET_i2s (&view_array[i])); #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "=%s\t(do round)", - GNUNET_i2s_full(&view_array[i])); + to_file (sub->file_name_view_log, + "=%s\t(do round)", + GNUNET_i2s_full (&view_array[i])); #endif /* TO_FILE_FULL */ - } + } /* Send pushes and pull requests */ - if (0 < View_size(sub->view)) + if (0 < View_size (sub->view)) + { + permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, + View_size (sub->view)); + + /* Send PUSHes */ + a_peers = ceil (alpha * View_size (sub->view)); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send pushes to %u (ceil (%f * %u)) peers.\n", + a_peers, alpha, View_size (sub->view)); + for (i = 0; i < a_peers; i++) { - permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, - View_size(sub->view)); - - /* Send PUSHes */ - a_peers = ceil(alpha * View_size(sub->view)); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send pushes to %u (ceil (%f * %u)) peers.\n", - a_peers, alpha, View_size(sub->view)); - for (i = 0; i < a_peers; i++) - { - peer = view_array[permut[i]]; - // FIXME if this fails schedule/loop this for later - send_push(get_peer_ctx(sub->peer_map, &peer)); - } - - /* Send PULL requests */ - b_peers = ceil(beta * View_size(sub->view)); - first_border = a_peers; - second_border = a_peers + b_peers; - if (second_border > View_size(sub->view)) - { - first_border = View_size(sub->view) - b_peers; - second_border = View_size(sub->view); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Going to send pulls to %u (ceil (%f * %u)) peers.\n", - b_peers, beta, View_size(sub->view)); - for (i = first_border; i < second_border; i++) - { - peer = view_array[permut[i]]; - if (GNUNET_NO == check_peer_flag(sub->peer_map, - &peer, - Peers_PULL_REPLY_PENDING)) - { // FIXME if this fails schedule/loop this for later - send_pull_request(get_peer_ctx(sub->peer_map, &peer)); - } - } - - GNUNET_free(permut); - permut = NULL; + peer = view_array[permut[i]]; + // FIXME if this fails schedule/loop this for later + send_push (get_peer_ctx (sub->peer_map, &peer)); } + /* Send PULL requests */ + b_peers = ceil (beta * View_size (sub->view)); + first_border = a_peers; + second_border = a_peers + b_peers; + if (second_border > View_size (sub->view)) + { + first_border = View_size (sub->view) - b_peers; + second_border = View_size (sub->view); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Going to send pulls to %u (ceil (%f * %u)) peers.\n", + b_peers, beta, View_size (sub->view)); + for (i = first_border; i < second_border; i++) + { + peer = view_array[permut[i]]; + if (GNUNET_NO == check_peer_flag (sub->peer_map, + &peer, + Peers_PULL_REPLY_PENDING)) + { // FIXME if this fails schedule/loop this for later + send_pull_request (get_peer_ctx (sub->peer_map, &peer)); + } + } + + GNUNET_free (permut); + permut = NULL; + } + /* Update view */ /* TODO see how many peers are in push-/pull- list! */ - if ((CustomPeerMap_size(sub->push_map) <= alpha * sub->view_size_est_need) && - (0 < CustomPeerMap_size(sub->push_map)) && - (0 < CustomPeerMap_size(sub->pull_map))) - { /* If conditions for update are fulfilled, update */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); - - uint32_t final_size; - uint32_t peers_to_clean_size; - struct GNUNET_PeerIdentity *peers_to_clean; - - peers_to_clean = NULL; - peers_to_clean_size = 0; - GNUNET_array_grow(peers_to_clean, - peers_to_clean_size, - View_size(sub->view)); - GNUNET_memcpy(peers_to_clean, - view_array, - View_size(sub->view) * sizeof(struct GNUNET_PeerIdentity)); - - /* Seems like recreating is the easiest way of emptying the peermap */ - View_clear(sub->view); + if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) && + (0 < CustomPeerMap_size (sub->push_map)) && + (0 < CustomPeerMap_size (sub->pull_map))) + { /* If conditions for update are fulfilled, update */ + LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); + + uint32_t final_size; + uint32_t peers_to_clean_size; + struct GNUNET_PeerIdentity *peers_to_clean; + + peers_to_clean = NULL; + peers_to_clean_size = 0; + GNUNET_array_grow (peers_to_clean, + peers_to_clean_size, + View_size (sub->view)); + GNUNET_memcpy (peers_to_clean, + view_array, + View_size (sub->view) * sizeof(struct GNUNET_PeerIdentity)); + + /* Seems like recreating is the easiest way of emptying the peermap */ + View_clear (sub->view); #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "--- emptied ---"); + to_file (sub->file_name_view_log, + "--- emptied ---"); #endif /* TO_FILE_FULL */ - first_border = GNUNET_MIN(ceil(alpha * sub->view_size_est_need), - CustomPeerMap_size(sub->push_map)); - second_border = first_border + - GNUNET_MIN(floor(beta * sub->view_size_est_need), - CustomPeerMap_size(sub->pull_map)); - final_size = second_border + - ceil((1 - (alpha + beta)) * sub->view_size_est_need); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" PRIu32 "\n", - first_border, - second_border, - final_size); - - /* Update view with peers received through PUSHes */ - permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, - CustomPeerMap_size(sub->push_map)); - for (i = 0; i < first_border; i++) - { - int inserted; - inserted = insert_in_view(sub, - CustomPeerMap_get_peer_by_index(sub->push_map, - permut[i])); - if (GNUNET_OK == inserted) - { - clients_notify_stream_peer(sub, - 1, - CustomPeerMap_get_peer_by_index(sub->push_map, permut[i])); - } + first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need), + CustomPeerMap_size (sub->push_map)); + second_border = first_border + + GNUNET_MIN (floor (beta * sub->view_size_est_need), + CustomPeerMap_size (sub->pull_map)); + final_size = second_border + + ceil ((1 - (alpha + beta)) * sub->view_size_est_need); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" + PRIu32 "\n", + first_border, + second_border, + final_size); + + /* Update view with peers received through PUSHes */ + permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, + CustomPeerMap_size (sub->push_map)); + for (i = 0; i < first_border; i++) + { + int inserted; + inserted = insert_in_view (sub, + CustomPeerMap_get_peer_by_index (sub->push_map, + permut[i])); + if (GNUNET_OK == inserted) + { + clients_notify_stream_peer (sub, + 1, + CustomPeerMap_get_peer_by_index ( + sub->push_map, permut[i])); + } #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "+%s\t(push list)", - GNUNET_i2s_full(&view_array[i])); + to_file (sub->file_name_view_log, + "+%s\t(push list)", + GNUNET_i2s_full (&view_array[i])); #endif /* TO_FILE_FULL */ // TODO change the peer_flags accordingly - } - GNUNET_free(permut); - permut = NULL; - - /* Update view with peers received through PULLs */ - permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, - CustomPeerMap_size(sub->pull_map)); - for (i = first_border; i < second_border; i++) - { - int inserted; - inserted = insert_in_view(sub, - CustomPeerMap_get_peer_by_index(sub->pull_map, - permut[i - first_border])); - if (GNUNET_OK == inserted) - { - clients_notify_stream_peer(sub, - 1, - CustomPeerMap_get_peer_by_index(sub->pull_map, - permut[i - first_border])); - } + } + GNUNET_free (permut); + permut = NULL; + + /* Update view with peers received through PULLs */ + permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, + CustomPeerMap_size (sub->pull_map)); + for (i = first_border; i < second_border; i++) + { + int inserted; + inserted = insert_in_view (sub, + CustomPeerMap_get_peer_by_index (sub->pull_map, + permut[i + - + first_border + ])); + if (GNUNET_OK == inserted) + { + clients_notify_stream_peer (sub, + 1, + CustomPeerMap_get_peer_by_index ( + sub->pull_map, + permut[i + - first_border])); + } #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "+%s\t(pull list)", - GNUNET_i2s_full(&view_array[i])); + to_file (sub->file_name_view_log, + "+%s\t(pull list)", + GNUNET_i2s_full (&view_array[i])); #endif /* TO_FILE_FULL */ // TODO change the peer_flags accordingly - } - GNUNET_free(permut); - permut = NULL; - - /* Update view with peers from history */ - RPS_sampler_get_n_rand_peers(sub->sampler, - final_size - second_border, - hist_update, - sub); - // TODO change the peer_flags accordingly - - for (i = 0; i < View_size(sub->view); i++) - rem_from_list(&peers_to_clean, &peers_to_clean_size, &view_array[i]); - - /* Clean peers that were removed from the view */ - for (i = 0; i < peers_to_clean_size; i++) - { + } + GNUNET_free (permut); + permut = NULL; + + /* Update view with peers from history */ + RPS_sampler_get_n_rand_peers (sub->sampler, + final_size - second_border, + hist_update, + sub); + // TODO change the peer_flags accordingly + + for (i = 0; i < View_size (sub->view); i++) + rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]); + + /* Clean peers that were removed from the view */ + for (i = 0; i < peers_to_clean_size; i++) + { #ifdef TO_FILE_FULL - to_file(sub->file_name_view_log, - "-%s", - GNUNET_i2s_full(&peers_to_clean[i])); + to_file (sub->file_name_view_log, + "-%s", + GNUNET_i2s_full (&peers_to_clean[i])); #endif /* TO_FILE_FULL */ - clean_peer(sub, &peers_to_clean[i]); - } - - GNUNET_array_grow(peers_to_clean, peers_to_clean_size, 0); - clients_notify_view_update(sub); + clean_peer (sub, &peers_to_clean[i]); } + + GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); + clients_notify_view_update (sub); + } else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); + if (sub == msub) { - LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); - if (sub == msub) - { - GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); - if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && - !(0 >= CustomPeerMap_size(sub->pull_map))) - GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); - if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && - (0 >= CustomPeerMap_size(sub->pull_map))) - GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); - if (0 >= CustomPeerMap_size(sub->push_map) && - !(0 >= CustomPeerMap_size(sub->pull_map))) - GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); - if (0 >= CustomPeerMap_size(sub->push_map) && - (0 >= CustomPeerMap_size(sub->pull_map))) - GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); - if (0 >= CustomPeerMap_size(sub->pull_map) && - CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && - 0 >= CustomPeerMap_size(sub->push_map)) - GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); - } - } + GNUNET_STATISTICS_update (stats, "# rounds blocked", 1, GNUNET_NO); + if ((CustomPeerMap_size (sub->push_map) > alpha + * sub->view_size_est_need) && + ! (0 >= CustomPeerMap_size (sub->pull_map))) + GNUNET_STATISTICS_update (stats, "# rounds blocked - too many pushes", + 1, GNUNET_NO); + if ((CustomPeerMap_size (sub->push_map) > alpha + * sub->view_size_est_need) && + (0 >= CustomPeerMap_size (sub->pull_map))) + GNUNET_STATISTICS_update (stats, + "# rounds blocked - too many pushes, no pull replies", + 1, GNUNET_NO); + if ((0 >= CustomPeerMap_size (sub->push_map)) && + ! (0 >= CustomPeerMap_size (sub->pull_map))) + GNUNET_STATISTICS_update (stats, "# rounds blocked - no pushes", 1, + GNUNET_NO); + if ((0 >= CustomPeerMap_size (sub->push_map)) && + (0 >= CustomPeerMap_size (sub->pull_map))) + GNUNET_STATISTICS_update (stats, + "# rounds blocked - no pushes, no pull replies", + 1, GNUNET_NO); + if ((0 >= CustomPeerMap_size (sub->pull_map)) && + (CustomPeerMap_size (sub->push_map) > alpha + * sub->view_size_est_need) && + (0 >= CustomPeerMap_size (sub->push_map)) ) + GNUNET_STATISTICS_update (stats, "# rounds blocked - no pull replies", + 1, GNUNET_NO); + } + } // TODO independent of that also get some peers from CADET_get_peers()? - if (CustomPeerMap_size(sub->push_map) < HISTOGRAM_FILE_SLOTS) - { - sub->push_recv[CustomPeerMap_size(sub->push_map)]++; - } + if (CustomPeerMap_size (sub->push_map) < HISTOGRAM_FILE_SLOTS) + { + sub->push_recv[CustomPeerMap_size (sub->push_map)]++; + } else - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Push map size too big for histogram (%u, %u)\n", - CustomPeerMap_size(sub->push_map), - HISTOGRAM_FILE_SLOTS); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Push map size too big for histogram (%u, %u)\n", + CustomPeerMap_size (sub->push_map), + HISTOGRAM_FILE_SLOTS); + } // FIXME check bounds of histogram - sub->push_delta[(int32_t)(CustomPeerMap_size(sub->push_map) - - (alpha * sub->view_size_est_need)) + - (HISTOGRAM_FILE_SLOTS / 2)]++; + sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map) + - (alpha * sub->view_size_est_need)) + + (HISTOGRAM_FILE_SLOTS / 2)]++; if (sub == msub) - { - GNUNET_STATISTICS_set(stats, - "# peers in push map at end of round", - CustomPeerMap_size(sub->push_map), - GNUNET_NO); - GNUNET_STATISTICS_set(stats, - "# peers in pull map at end of round", - CustomPeerMap_size(sub->pull_map), - GNUNET_NO); - GNUNET_STATISTICS_set(stats, - "# peers in view at end of round", - View_size(sub->view), - GNUNET_NO); - GNUNET_STATISTICS_set(stats, - "# expected pushes", - alpha * sub->view_size_est_need, - GNUNET_NO); - GNUNET_STATISTICS_set(stats, - "delta expected - received pushes", - CustomPeerMap_size(sub->push_map) - (alpha * sub->view_size_est_need), - GNUNET_NO); - } - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", - CustomPeerMap_size(sub->push_map), - CustomPeerMap_size(sub->pull_map), - alpha, - View_size(sub->view), - alpha * View_size(sub->view)); + { + GNUNET_STATISTICS_set (stats, + "# peers in push map at end of round", + CustomPeerMap_size (sub->push_map), + GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# peers in pull map at end of round", + CustomPeerMap_size (sub->pull_map), + GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# peers in view at end of round", + View_size (sub->view), + GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# expected pushes", + alpha * sub->view_size_est_need, + GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "delta expected - received pushes", + CustomPeerMap_size (sub->push_map) - (alpha + * sub-> + view_size_est_need), + GNUNET_NO); + } + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", + CustomPeerMap_size (sub->push_map), + CustomPeerMap_size (sub->pull_map), + alpha, + View_size (sub->view), + alpha * View_size (sub->view)); /* Update samplers */ - for (i = 0; i < CustomPeerMap_size(sub->push_map); i++) - { - update_peer = CustomPeerMap_get_peer_by_index(sub->push_map, i); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updating with peer %s from push list\n", - GNUNET_i2s(update_peer)); - insert_in_sampler(sub, update_peer); - clean_peer(sub, update_peer); /* This cleans only if it is not in the view */ - } - - for (i = 0; i < CustomPeerMap_size(sub->pull_map); i++) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updating with peer %s from pull list\n", - GNUNET_i2s(CustomPeerMap_get_peer_by_index(sub->pull_map, i))); - insert_in_sampler(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); - /* This cleans only if it is not in the view */ - clean_peer(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); - } + for (i = 0; i < CustomPeerMap_size (sub->push_map); i++) + { + update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updating with peer %s from push list\n", + GNUNET_i2s (update_peer)); + insert_in_sampler (sub, update_peer); + clean_peer (sub, update_peer); /* This cleans only if it is not in the view */ + } + + for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updating with peer %s from pull list\n", + GNUNET_i2s (CustomPeerMap_get_peer_by_index (sub->pull_map, i))); + insert_in_sampler (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); + /* This cleans only if it is not in the view */ + clean_peer (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); + } /* Empty push/pull lists */ - CustomPeerMap_clear(sub->push_map); - CustomPeerMap_clear(sub->pull_map); + CustomPeerMap_clear (sub->push_map); + CustomPeerMap_clear (sub->pull_map); if (sub == msub) - { - GNUNET_STATISTICS_set(stats, - "view size", - View_size(sub->view), - GNUNET_NO); - } + { + GNUNET_STATISTICS_set (stats, + "view size", + View_size (sub->view), + GNUNET_NO); + } struct GNUNET_TIME_Relative time_next_round; - time_next_round = compute_rand_delay(sub->round_interval, 2); + time_next_round = compute_rand_delay (sub->round_interval, 2); /* Schedule next round */ - sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, - &do_round, sub); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); + sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, + &do_round, sub); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); } @@ -4556,26 +4601,26 @@ do_round(void *cls) * (0 = unknown, 1 = ourselves, 2 = neighbor) */ void -init_peer_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - int tunnel, /* "Do we have a tunnel towards this peer?" */ - unsigned int n_paths, /* "Number of known paths towards this peer" */ - unsigned int best_path) /* "How long is the best path? +init_peer_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + int tunnel, /* "Do we have a tunnel towards this peer?" */ + unsigned int n_paths, /* "Number of known paths towards this peer" */ + unsigned int best_path) /* "How long is the best path? * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ { struct Sub *sub = cls; - (void)tunnel; - (void)n_paths; - (void)best_path; + (void) tunnel; + (void) n_paths; + (void) best_path; if (NULL != peer) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got peer_id %s from cadet\n", - GNUNET_i2s(peer)); - got_peer(sub, peer); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got peer_id %s from cadet\n", + GNUNET_i2s (peer)); + got_peer (sub, peer); + } } @@ -4591,18 +4636,18 @@ init_peer_cb(void *cls, * #GNUNET_NO if not. */ static int -valid_peers_iterator(void *cls, - const struct GNUNET_PeerIdentity *peer) +valid_peers_iterator (void *cls, + const struct GNUNET_PeerIdentity *peer) { struct Sub *sub = cls; if (NULL != peer) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got stored, valid peer %s\n", - GNUNET_i2s(peer)); - got_peer(sub, peer); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got stored, valid peer %s\n", + GNUNET_i2s (peer)); + got_peer (sub, peer); + } return GNUNET_YES; } @@ -4616,23 +4661,23 @@ valid_peers_iterator(void *cls, * @param error message */ void -process_peerinfo_peers(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) +process_peerinfo_peers (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct Sub *sub = cls; - (void)hello; - (void)err_msg; + (void) hello; + (void) err_msg; if (NULL != peer) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got peer_id %s from peerinfo\n", - GNUNET_i2s(peer)); - got_peer(sub, peer); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got peer_id %s from peerinfo\n", + GNUNET_i2s (peer)); + got_peer (sub, peer); + } } @@ -4642,69 +4687,69 @@ process_peerinfo_peers(void *cls, * @param cls Closure - unused */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { - (void)cls; + (void) cls; struct ClientContext *client_ctx; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "RPS service is going down\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "RPS service is going down\n"); /* Clean all clients */ for (client_ctx = cli_ctx_head; NULL != cli_ctx_head; client_ctx = cli_ctx_head) - { - destroy_cli_ctx(client_ctx); - } + { + destroy_cli_ctx (client_ctx); + } if (NULL != msub) - { - destroy_sub(msub); - msub = NULL; - } + { + destroy_sub (msub); + msub = NULL; + } /* Disconnect from other services */ - GNUNET_PEERINFO_notify_cancel(peerinfo_notify_handle); - GNUNET_PEERINFO_disconnect(peerinfo_handle); + GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); + GNUNET_PEERINFO_disconnect (peerinfo_handle); peerinfo_handle = NULL; - GNUNET_NSE_disconnect(nse); + GNUNET_NSE_disconnect (nse); if (NULL != map_single_hop) - { - /* core_init was called - core was initialised */ - /* disconnect first, so no callback tries to access missing peermap */ - GNUNET_CORE_disconnect(core_handle); - core_handle = NULL; - GNUNET_CONTAINER_multipeermap_destroy(map_single_hop); - map_single_hop = NULL; - } + { + /* core_init was called - core was initialised */ + /* disconnect first, so no callback tries to access missing peermap */ + GNUNET_CORE_disconnect (core_handle); + core_handle = NULL; + GNUNET_CONTAINER_multipeermap_destroy (map_single_hop); + map_single_hop = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy(stats, - GNUNET_NO); - stats = NULL; - } - GNUNET_CADET_disconnect(cadet_handle); + { + GNUNET_STATISTICS_destroy (stats, + GNUNET_NO); + stats = NULL; + } + GNUNET_CADET_disconnect (cadet_handle); cadet_handle = NULL; #if ENABLE_MALICIOUS struct AttackedPeer *tmp_att_peer; - GNUNET_array_grow(mal_peers, - num_mal_peers, - 0); + GNUNET_array_grow (mal_peers, + num_mal_peers, + 0); if (NULL != mal_peer_set) - GNUNET_CONTAINER_multipeermap_destroy(mal_peer_set); + GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); if (NULL != att_peer_set) - GNUNET_CONTAINER_multipeermap_destroy(att_peer_set); + GNUNET_CONTAINER_multipeermap_destroy (att_peer_set); while (NULL != att_peers_head) - { - tmp_att_peer = att_peers_head; - GNUNET_CONTAINER_DLL_remove(att_peers_head, - att_peers_tail, - tmp_att_peer); - GNUNET_free(tmp_att_peer); - } + { + tmp_att_peer = att_peers_head; + GNUNET_CONTAINER_DLL_remove (att_peers_head, + att_peers_tail, + tmp_att_peer); + GNUNET_free (tmp_att_peer); + } #endif /* ENABLE_MALICIOUS */ - close_all_files(); + close_all_files (); } @@ -4717,26 +4762,26 @@ shutdown_task(void *cls) * @return @a client */ static void * -client_connect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct ClientContext *cli_ctx; - (void)cls; + (void) cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client connected\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client connected\n"); if (NULL == client) return client; /* Server was destroyed before a client connected. Shutting down */ - cli_ctx = GNUNET_new(struct ClientContext); + cli_ctx = GNUNET_new (struct ClientContext); cli_ctx->mq = mq; cli_ctx->view_updates_left = -1; cli_ctx->stream_update = GNUNET_NO; cli_ctx->client = client; - GNUNET_CONTAINER_DLL_insert(cli_ctx_head, - cli_ctx_tail, - cli_ctx); + GNUNET_CONTAINER_DLL_insert (cli_ctx_head, + cli_ctx_tail, + cli_ctx); return cli_ctx; } @@ -4748,25 +4793,25 @@ client_connect_cb(void *cls, * @param internal_cls should be equal to @a c */ static void -client_disconnect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - void *internal_cls) +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) { struct ClientContext *cli_ctx = internal_cls; - (void)cls; - GNUNET_assert(client == cli_ctx->client); + (void) cls; + GNUNET_assert (client == cli_ctx->client); if (NULL == client) - {/* shutdown task - destroy all clients */ - while (NULL != cli_ctx_head) - destroy_cli_ctx(cli_ctx_head); - } + { /* shutdown task - destroy all clients */ + while (NULL != cli_ctx_head) + destroy_cli_ctx (cli_ctx_head); + } else - { /* destroy this client */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected. Destroy its context.\n"); - destroy_cli_ctx(cli_ctx); - } + { /* destroy this client */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client disconnected. Destroy its context.\n"); + destroy_cli_ctx (cli_ctx); + } } @@ -4778,68 +4823,68 @@ client_disconnect_cb(void *cls, * @param service the initialized service */ static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { struct GNUNET_TIME_Relative round_interval; long long unsigned int sampler_size; char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; struct GNUNET_HashCode hash; - (void)cls; - (void)service; + (void) cls; + (void) service; - GNUNET_log_setup("rps", - GNUNET_error_type_to_string(GNUNET_ERROR_TYPE_DEBUG), - NULL); + GNUNET_log_setup ("rps", + GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), + NULL); cfg = c; /* Get own ID */ - GNUNET_CRYPTO_get_peer_identity(cfg, - &own_identity); // TODO check return value - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "STARTING SERVICE (rps) for peer [%s]\n", - GNUNET_i2s(&own_identity)); + GNUNET_CRYPTO_get_peer_identity (cfg, + &own_identity); // TODO check return value + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "STARTING SERVICE (rps) for peer [%s]\n", + GNUNET_i2s (&own_identity)); #if ENABLE_MALICIOUS - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Malicious execution compiled in.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Malicious execution compiled in.\n"); #endif /* ENABLE_MALICIOUS */ /* Get time interval from the configuration */ if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time(cfg, - "RPS", - "ROUNDINTERVAL", - &round_interval)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "RPS", "ROUNDINTERVAL"); - GNUNET_SCHEDULER_shutdown(); - return; - } + GNUNET_CONFIGURATION_get_value_time (cfg, + "RPS", + "ROUNDINTERVAL", + &round_interval)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "RPS", "ROUNDINTERVAL"); + GNUNET_SCHEDULER_shutdown (); + return; + } /* Get initial size of sampler/view from the configuration */ if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(cfg, - "RPS", - "MINSIZE", - &sampler_size)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "RPS", "MINSIZE"); - GNUNET_SCHEDULER_shutdown(); - return; - } + GNUNET_CONFIGURATION_get_value_number (cfg, + "RPS", + "MINSIZE", + &sampler_size)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "RPS", "MINSIZE"); + GNUNET_SCHEDULER_shutdown (); + return; + } - cadet_handle = GNUNET_CADET_connect(cfg); - GNUNET_assert(NULL != cadet_handle); - core_handle = GNUNET_CORE_connect(cfg, - NULL, /* cls */ - core_init, /* init */ - core_connects, /* connects */ - core_disconnects, /* disconnects */ - NULL); /* handlers */ - GNUNET_assert(NULL != core_handle); + cadet_handle = GNUNET_CADET_connect (cfg); + GNUNET_assert (NULL != cadet_handle); + core_handle = GNUNET_CORE_connect (cfg, + NULL, /* cls */ + core_init, /* init */ + core_connects, /* connects */ + core_disconnects, /* disconnects */ + NULL); /* handlers */ + GNUNET_assert (NULL != core_handle); alpha = 0.45; @@ -4847,35 +4892,35 @@ run(void *cls, /* Set up main Sub */ - GNUNET_CRYPTO_hash(hash_port_string, - strlen(hash_port_string), - &hash); - msub = new_sub(&hash, - sampler_size, /* Will be overwritten by config */ - round_interval); + GNUNET_CRYPTO_hash (hash_port_string, + strlen (hash_port_string), + &hash); + msub = new_sub (&hash, + sampler_size, /* Will be overwritten by config */ + round_interval); - peerinfo_handle = GNUNET_PEERINFO_connect(cfg); + peerinfo_handle = GNUNET_PEERINFO_connect (cfg); /* connect to NSE */ - nse = GNUNET_NSE_connect(cfg, nse_callback, NULL); + nse = GNUNET_NSE_connect (cfg, nse_callback, NULL); - //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); - //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); + // LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); + // GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); // TODO send push/pull to each of those peers? - LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); - restore_valid_peers(msub); - get_valid_peers(msub->valid_peers, valid_peers_iterator, msub); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); + restore_valid_peers (msub); + get_valid_peers (msub->valid_peers, valid_peers_iterator, msub); - peerinfo_notify_handle = GNUNET_PEERINFO_notify(cfg, - GNUNET_NO, - process_peerinfo_peers, - msub); + peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, + GNUNET_NO, + process_peerinfo_peers, + msub); - LOG(GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); + LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); - stats = GNUNET_STATISTICS_create("rps", cfg); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + stats = GNUNET_STATISTICS_create ("rps", cfg); } @@ -4889,40 +4934,40 @@ GNUNET_SERVICE_MAIN &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_var_size (client_seed, + GNUNET_MESSAGE_TYPE_RPS_CS_SEED, + struct GNUNET_RPS_CS_SeedMessage, + NULL), #if ENABLE_MALICIOUS - GNUNET_MQ_hd_var_size(client_act_malicious, - GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, - struct GNUNET_RPS_CS_ActMaliciousMessage, - NULL), + GNUNET_MQ_hd_var_size (client_act_malicious, + GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, + struct GNUNET_RPS_CS_ActMaliciousMessage, + NULL), #endif /* ENABLE_MALICIOUS */ - 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()); + 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 ()); /* end of gnunet-service-rps.c */ diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index b842bc0a5..8fcfc5558 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c @@ -28,7 +28,7 @@ #include "gnunet-service-rps_custommap.h" #include <inttypes.h> -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-peers", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-peers", __VA_ARGS__) /** @@ -54,7 +54,8 @@ * - contain continous indices 0 <= i < len * - not contain duplicate peers */ -struct CustomPeerMap { +struct CustomPeerMap +{ /** * Multihashmap to be able to access a random index */ @@ -75,14 +76,14 @@ struct CustomPeerMap { * @return the newly created custom peer map */ struct CustomPeerMap * -CustomPeerMap_create(unsigned int len) +CustomPeerMap_create (unsigned int len) { struct CustomPeerMap *c_peer_map; - c_peer_map = GNUNET_new(struct CustomPeerMap); - c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create(len); - c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create(len, - GNUNET_NO); + c_peer_map = GNUNET_new (struct CustomPeerMap); + c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create (len); + c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create (len, + GNUNET_NO); return c_peer_map; } @@ -94,11 +95,11 @@ CustomPeerMap_create(unsigned int len) * @return size of the map */ unsigned int -CustomPeerMap_size(const struct CustomPeerMap *c_peer_map) +CustomPeerMap_size (const struct CustomPeerMap *c_peer_map) { - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); - return GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map); + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); + return GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map); } /** @@ -111,39 +112,40 @@ CustomPeerMap_size(const struct CustomPeerMap *c_peer_map) * GNUNET_NO if map did contain peer previously */ int -CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer) +CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer) { uint32_t *index; struct GNUNET_PeerIdentity *p; - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); - if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, - peer)) - { - /* Need to store the index of the peer in the peermap to be able to remove - * it properly */ - index = GNUNET_new(uint32_t); - *index = CustomPeerMap_size(c_peer_map); - p = GNUNET_new(struct GNUNET_PeerIdentity); - *p = *peer; - GNUNET_assert(p != peer); - GNUNET_assert(0 == memcmp(p, + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); + if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map, + peer)) + { + /* Need to store the index of the peer in the peermap to be able to remove + * it properly */ + index = GNUNET_new (uint32_t); + *index = CustomPeerMap_size (c_peer_map); + p = GNUNET_new (struct GNUNET_PeerIdentity); + *p = *peer; + GNUNET_assert (p != peer); + GNUNET_assert (0 == memcmp (p, peer, sizeof(struct GNUNET_PeerIdentity))); - GNUNET_CONTAINER_multipeermap_put(c_peer_map->peer_map, - p, - index, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, - *index, - p, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); - return GNUNET_OK; - } + GNUNET_CONTAINER_multipeermap_put (c_peer_map->peer_map, + p, + index, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, + *index, + p, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size ( + c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); + return GNUNET_OK; + } return GNUNET_NO; } @@ -157,10 +159,10 @@ CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, * GNUNET_NO otherwise */ int -CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer) +CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, peer); + return GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map, peer); } /** @@ -172,13 +174,13 @@ CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, * @return the index */ static uint32_t * -CustomPeerMap_get_index_pointer(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer) +CustomPeerMap_get_index_pointer (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer) { uint32_t *index; - GNUNET_assert(GNUNET_YES == CustomPeerMap_contains_peer(c_peer_map, peer)); - index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, peer); + GNUNET_assert (GNUNET_YES == CustomPeerMap_contains_peer (c_peer_map, peer)); + index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, peer); return index; } @@ -192,52 +194,52 @@ CustomPeerMap_get_index_pointer(const struct CustomPeerMap *c_peer_map, * GNUNET_NO if map does not contain peer */ int -CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer) +CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer) { uint32_t *index; struct GNUNET_PeerIdentity *p; uint32_t *last_index; struct GNUNET_PeerIdentity *last_p; - if (GNUNET_NO == CustomPeerMap_contains_peer(c_peer_map, - peer)) - { - return GNUNET_NO; - } - index = CustomPeerMap_get_index_pointer(c_peer_map, - peer); - GNUNET_assert(*index < CustomPeerMap_size(c_peer_map)); + if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map, + peer)) + { + return GNUNET_NO; + } + index = CustomPeerMap_get_index_pointer (c_peer_map, + peer); + GNUNET_assert (*index < CustomPeerMap_size (c_peer_map)); /* Need to get the pointer stored in the hashmap to free it */ - p = GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, - *index); - GNUNET_assert(NULL != p); - GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, - *index); + p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, + *index); + GNUNET_assert (NULL != p); + GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, + *index); // TODO wrong peerid? - GNUNET_CONTAINER_multipeermap_remove_all(c_peer_map->peer_map, - peer); - if (*index != CustomPeerMap_size(c_peer_map)) - { /* fill 'gap' with peer at last index */ - last_p = - GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, - CustomPeerMap_size(c_peer_map)); - GNUNET_assert(NULL != last_p); - last_index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, - last_p); - GNUNET_assert(NULL != last_index); - GNUNET_assert(CustomPeerMap_size(c_peer_map) == *last_index); - GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, - *index, last_p, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); - GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, - *last_index); - *last_index = *index; - } - GNUNET_free(index); - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); - GNUNET_free(p); + GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, + peer); + if (*index != CustomPeerMap_size (c_peer_map)) + { /* fill 'gap' with peer at last index */ + last_p = + GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, + CustomPeerMap_size (c_peer_map)); + GNUNET_assert (NULL != last_p); + last_index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, + last_p); + GNUNET_assert (NULL != last_index); + GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); + GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, + *index, last_p, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, + *last_index); + *last_index = *index; + } + GNUNET_free (index); + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); + GNUNET_free (p); return GNUNET_OK; } @@ -251,14 +253,14 @@ CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, * if this index is not known, return NULL */ struct GNUNET_PeerIdentity * -CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, - uint32_t index) +CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, + uint32_t index) { if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) - { - return GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, index); - } + GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index)) + { + return GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, index); + } return NULL; } @@ -272,30 +274,30 @@ CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, * GNUNET_NO if map does not contain (index of) peer */ int -CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, - uint32_t index) +CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, + uint32_t index) { uint32_t *index_p; struct GNUNET_PeerIdentity *peer; - if (index >= CustomPeerMap_size(c_peer_map)) - { - return GNUNET_NO; - } - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); + if (index >= CustomPeerMap_size (c_peer_map)) + { + return GNUNET_NO; + } + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); if (GNUNET_NO == - GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) - { - return GNUNET_NO; - } - peer = CustomPeerMap_get_peer_by_index(c_peer_map, index); - GNUNET_assert(NULL != peer); - index_p = CustomPeerMap_get_index_pointer(c_peer_map, peer); - GNUNET_assert(index == *index_p); - CustomPeerMap_remove_peer(c_peer_map, peer); - GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == - GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); + GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index)) + { + return GNUNET_NO; + } + peer = CustomPeerMap_get_peer_by_index (c_peer_map, index); + GNUNET_assert (NULL != peer); + index_p = CustomPeerMap_get_index_pointer (c_peer_map, peer); + GNUNET_assert (index == *index_p); + CustomPeerMap_remove_peer (c_peer_map, peer); + GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == + GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); return GNUNET_OK; } @@ -307,18 +309,21 @@ CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, * @return size of the map */ void -CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map) +CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map) { - while (0 < CustomPeerMap_size(c_peer_map)) - { - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, - CustomPeerMap_size(c_peer_map) - 1)); - GNUNET_assert(GNUNET_OK == - CustomPeerMap_remove_peer_by_index(c_peer_map, - CustomPeerMap_size(c_peer_map) - 1)); - } - GNUNET_assert(0 == CustomPeerMap_size(c_peer_map)); + while (0 < CustomPeerMap_size (c_peer_map)) + { + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_contains ( + c_peer_map->hash_map, + CustomPeerMap_size ( + c_peer_map) - 1)); + GNUNET_assert (GNUNET_OK == + CustomPeerMap_remove_peer_by_index (c_peer_map, + CustomPeerMap_size ( + c_peer_map) - 1)); + } + GNUNET_assert (0 == CustomPeerMap_size (c_peer_map)); } /** @@ -327,12 +332,12 @@ CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map) * @param c_peer_map the map to destroy */ void -CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map) +CustomPeerMap_destroy (struct CustomPeerMap *c_peer_map) { - CustomPeerMap_clear(c_peer_map); - GNUNET_CONTAINER_multihashmap32_destroy(c_peer_map->hash_map); - GNUNET_CONTAINER_multipeermap_destroy(c_peer_map->peer_map); - GNUNET_free(c_peer_map); + CustomPeerMap_clear (c_peer_map); + GNUNET_CONTAINER_multihashmap32_destroy (c_peer_map->hash_map); + GNUNET_CONTAINER_multipeermap_destroy (c_peer_map->peer_map); + GNUNET_free (c_peer_map); } /* end of gnunet-service-rps_custommap.c */ diff --git a/src/rps/gnunet-service-rps_custommap.h b/src/rps/gnunet-service-rps_custommap.h index 210ab56c6..15591b67a 100644 --- a/src/rps/gnunet-service-rps_custommap.h +++ b/src/rps/gnunet-service-rps_custommap.h @@ -61,7 +61,7 @@ struct CustomPeerMap; * @return the newly created custom peer map */ struct CustomPeerMap * -CustomPeerMap_create(unsigned int len); +CustomPeerMap_create (unsigned int len); /** * Get the size of the custom peer map @@ -71,7 +71,7 @@ CustomPeerMap_create(unsigned int len); * @return size of the map */ unsigned int -CustomPeerMap_size(const struct CustomPeerMap *c_peer_map); +CustomPeerMap_size (const struct CustomPeerMap *c_peer_map); /** * Insert peer into the custom peer map @@ -83,8 +83,8 @@ CustomPeerMap_size(const struct CustomPeerMap *c_peer_map); * GNUNET_NO if map did contain peer previously */ int -CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer); +CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer); /** * Check whether custom peer map contains a peer @@ -96,8 +96,8 @@ CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, * GNUNET_NO otherwise */ int -CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer); +CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer); /** * Remove peer from custom peer map @@ -109,8 +109,8 @@ CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, * GNUNET_NO if map does not contain peer */ int -CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, - const struct GNUNET_PeerIdentity *peer); +CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, + const struct GNUNET_PeerIdentity *peer); /** * Get a peer by index @@ -122,8 +122,8 @@ CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, * if this index is not known, return NULL */ struct GNUNET_PeerIdentity * -CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, - uint32_t index); +CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, + uint32_t index); /** * Remove peer from custom peer map by index @@ -135,8 +135,8 @@ CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, * GNUNET_NO if map does not contain (index of) peer */ int -CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, - uint32_t index); +CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, + uint32_t index); /** * Clear the custom peer map @@ -146,7 +146,7 @@ CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, * @return size of the map */ void -CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map); +CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map); /** * Destroy peermap. @@ -154,6 +154,6 @@ CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map); * @param c_peer_map the map to destroy */ void -CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map); +CustomPeerMap_destroy (struct CustomPeerMap *c_peer_map); /* end of gnunet-service-rps_custommap.h */ diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index a3f778979..7573fd4eb 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c @@ -37,7 +37,7 @@ #include "rps-test_util.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler", __VA_ARGS__) // multiple 'clients'? @@ -68,7 +68,8 @@ typedef void * * Meant to be an entry in an DLL. */ -struct SamplerNotifyUpdateCTX { +struct SamplerNotifyUpdateCTX +{ /** * @brief The Callback to call on updates */ @@ -106,13 +107,14 @@ typedef void * Only used internally */ static void -sampler_get_rand_peer(void *cls); +sampler_get_rand_peer (void *cls); /** * Closure to _get_n_rand_peers_ready_cb() */ -struct RPS_SamplerRequestHandle { +struct RPS_SamplerRequestHandle +{ /** * DLL */ @@ -159,7 +161,7 @@ struct RPS_SamplerRequestHandle { ///** // * Global sampler variable. // */ -//struct RPS_Sampler *sampler; +// struct RPS_Sampler *sampler; /** @@ -175,7 +177,7 @@ static size_t max_size; /** * The size the extended sampler elements currently have. */ -//static size_t extra_size; +// static size_t extra_size; /** * Inedex to the sampler element that is the next to be returned @@ -191,8 +193,8 @@ static uint32_t client_get_index; * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * -RPS_sampler_init(size_t init_size, - struct GNUNET_TIME_Relative max_round_interval) +RPS_sampler_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval) { struct RPS_Sampler *sampler; @@ -200,17 +202,17 @@ RPS_sampler_init(size_t init_size, min_size = 10; // TODO make input to _samplers_init() max_size = 1000; // TODO make input to _samplers_init() - sampler = GNUNET_new(struct RPS_Sampler); + sampler = GNUNET_new (struct RPS_Sampler); sampler->max_round_interval = max_round_interval; sampler->get_peers = sampler_get_rand_peer; - //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); - //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); - RPS_sampler_resize(sampler, init_size); + // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); + // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); + RPS_sampler_resize (sampler, init_size); client_get_index = 0; - //GNUNET_assert (init_size == sampler->sampler_size); + // GNUNET_assert (init_size == sampler->sampler_size); return sampler; } @@ -222,7 +224,7 @@ RPS_sampler_init(size_t init_size, * Only used internally */ static void -sampler_get_rand_peer(void *cls) +sampler_get_rand_peer (void *cls) { struct GetPeerCls *gpc = cls; uint32_t r_index; @@ -236,28 +238,29 @@ sampler_get_rand_peer(void *cls) * Choose the r_index of the peer we want to return * at random from the interval of the gossip list */ - r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, - sampler->sampler_size); + r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, + sampler->sampler_size); if (EMPTY == sampler->sampler_elements[r_index]->is_empty) - { - //LOG (GNUNET_ERROR_TYPE_DEBUG, - // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); - - gpc->notify_ctx = - sampler_notify_on_update(sampler, - &sampler_get_rand_peer, - gpc); - return; - } - - GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, - gpc->req_handle->gpc_tail, - gpc); + { + // LOG (GNUNET_ERROR_TYPE_DEBUG, + // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); + + gpc->notify_ctx = + sampler_notify_on_update (sampler, + &sampler_get_rand_peer, + gpc); + return; + } + + GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, + gpc->req_handle->gpc_tail, + gpc); *gpc->id = sampler->sampler_elements[r_index]->peer_id; - gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); + gpc->cont (gpc->cont_cls, gpc->id, 0, + sampler->sampler_elements[r_index]->num_peers); - GNUNET_free(gpc); + GNUNET_free (gpc); } diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index 8bccb8431..f3a8c9763 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h @@ -48,7 +48,7 @@ struct RPS_SamplerRequestHandle; * @return the size of the sampler */ unsigned int -RPS_sampler_get_size(struct RPS_Sampler *sampler); +RPS_sampler_get_size (struct RPS_Sampler *sampler); /** @@ -58,7 +58,7 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler); * @param new_size the new size of the sampler (not 0) */ void -RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); +RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); /** @@ -69,8 +69,8 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * -RPS_sampler_init(size_t init_size, - struct GNUNET_TIME_Relative max_round_interval); +RPS_sampler_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval); /** @@ -80,8 +80,8 @@ RPS_sampler_init(size_t init_size, * @param id the PeerID that is put in the sampler */ void -RPS_sampler_update(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_update (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -100,8 +100,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler, * @param id the id of the samplers to update. */ void -RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -119,10 +119,10 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, * @param num_peers the number of peers requested */ 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); +RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, + uint32_t num_peers, + RPS_sampler_n_rand_peers_ready_cb cb, + void *cls); /** * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb. @@ -130,7 +130,7 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, * @param req_handle the handle to the request */ void -RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); +RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); /** @@ -142,8 +142,8 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); * @return the number of occurrences of id. */ uint32_t -RPS_sampler_count_id(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_count_id (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -152,7 +152,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler, * @param sampler the sampler to destroy. */ void -RPS_sampler_destroy(struct RPS_Sampler *sampler); +RPS_sampler_destroy (struct RPS_Sampler *sampler); #endif /* end of gnunet-service-rps.c */ diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c index 6d5305f03..17b3be6d2 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.c +++ b/src/rps/gnunet-service-rps_sampler_elem.c @@ -32,7 +32,7 @@ #include "rps-test_util.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler_elem", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler_elem", __VA_ARGS__) /*********************************************************************** @@ -47,18 +47,18 @@ * @param sampler_el The sampler element to (re-) initialise */ void -RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem) +RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem) { sampler_elem->is_empty = EMPTY; // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()... - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_STRONG, - &(sampler_elem->auth_key.key), - GNUNET_CRYPTO_HASH_LENGTH); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, + &(sampler_elem->auth_key.key), + GNUNET_CRYPTO_HASH_LENGTH); sampler_elem->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; - sampler_elem->birth = GNUNET_TIME_absolute_get(); + sampler_elem->birth = GNUNET_TIME_absolute_get (); sampler_elem->num_peers = 0; sampler_elem->num_change = 0; } @@ -73,13 +73,13 @@ RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem) * @return a newly created RPS_SamplerElement which currently holds no id. */ struct RPS_SamplerElement * -RPS_sampler_elem_create(void) +RPS_sampler_elem_create (void) { struct RPS_SamplerElement *s; - s = GNUNET_new(struct RPS_SamplerElement); + s = GNUNET_new (struct RPS_SamplerElement); - RPS_sampler_elem_reinit(s); + RPS_sampler_elem_reinit (s); return s; } @@ -91,9 +91,9 @@ RPS_sampler_elem_create(void) * @param sampler_elem the element to destroy */ void -RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem) +RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem) { - GNUNET_free(sampler_elem); + GNUNET_free (sampler_elem); } @@ -104,50 +104,51 @@ RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem) * @param new_ID The PeerID to update with */ void -RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, - const struct GNUNET_PeerIdentity *new_ID) +RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, + const struct GNUNET_PeerIdentity *new_ID) { struct GNUNET_HashCode other_hash; sampler_elem->num_peers++; - if (0 == GNUNET_memcmp(new_ID, &(sampler_elem->peer_id))) + if (0 == GNUNET_memcmp (new_ID, &(sampler_elem->peer_id))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", + GNUNET_i2s (&(sampler_elem->peer_id))); + } + else + { + GNUNET_CRYPTO_hmac (&sampler_elem->auth_key, + new_ID, + sizeof(struct GNUNET_PeerIdentity), + &other_hash); + + if (EMPTY == sampler_elem->is_empty) { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", - GNUNET_i2s(&(sampler_elem->peer_id))); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got PeerID %s; Simply accepting (was empty previously).\n", + GNUNET_i2s (new_ID)); + sampler_elem->peer_id = *new_ID; + sampler_elem->peer_id_hash = other_hash; + + sampler_elem->num_change++; } - else + else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash, + &sampler_elem->peer_id_hash)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", + GNUNET_i2s (&sampler_elem->peer_id)); + sampler_elem->peer_id = *new_ID; + sampler_elem->peer_id_hash = other_hash; + + sampler_elem->num_change++; + } + else { - GNUNET_CRYPTO_hmac(&sampler_elem->auth_key, - new_ID, - sizeof(struct GNUNET_PeerIdentity), - &other_hash); - - if (EMPTY == sampler_elem->is_empty) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got PeerID %s; Simply accepting (was empty previously).\n", - GNUNET_i2s(new_ID)); - sampler_elem->peer_id = *new_ID; - sampler_elem->peer_id_hash = other_hash; - - sampler_elem->num_change++; - } - else if (0 > GNUNET_CRYPTO_hash_cmp(&other_hash, &sampler_elem->peer_id_hash)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", - GNUNET_i2s(&sampler_elem->peer_id)); - sampler_elem->peer_id = *new_ID; - sampler_elem->peer_id_hash = other_hash; - - sampler_elem->num_change++; - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n", - GNUNET_i2s(&sampler_elem->peer_id)); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n", + GNUNET_i2s (&sampler_elem->peer_id)); } + } sampler_elem->is_empty = NOT_EMPTY; } @@ -158,8 +159,8 @@ RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, * @param auth_key the key to use */ void -RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, - struct GNUNET_CRYPTO_AuthKey auth_key) +RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem, + struct GNUNET_CRYPTO_AuthKey auth_key) { sampler_elem->auth_key = auth_key; } diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h index c22b7413c..98959a88f 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.h +++ b/src/rps/gnunet-service-rps_sampler_elem.h @@ -37,7 +37,8 @@ /** * Used to indicate whether a sampler element is empty. */ -enum RPS_SamplerEmpty { +enum RPS_SamplerEmpty +{ NOT_EMPTY = 0x0, EMPTY = 0x1 }; @@ -45,7 +46,8 @@ enum RPS_SamplerEmpty { /** * A sampler element sampling one PeerID at a time. */ -struct RPS_SamplerElement { +struct RPS_SamplerElement +{ /** * Min-wise linear permutation used by this sampler. * @@ -102,7 +104,7 @@ struct RPS_SamplerElement { * @param sampler_el The sampler element to (re-) initialise */ void -RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem); +RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem); /** @@ -114,7 +116,7 @@ RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem); * @return a newly created RPS_SamplerElement which currently holds no id. */ struct RPS_SamplerElement * -RPS_sampler_elem_create(void); +RPS_sampler_elem_create (void); /** @@ -123,7 +125,7 @@ RPS_sampler_elem_create(void); * @param sampler_elem the element to destroy */ void -RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem); +RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem); /** @@ -133,8 +135,8 @@ RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem); * @param new_ID The PeerID to update with */ void -RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, - const struct GNUNET_PeerIdentity *new_ID); +RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, + const struct GNUNET_PeerIdentity *new_ID); /** * Set the min-wise independent function of the given sampler element. @@ -143,8 +145,8 @@ RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, * @param auth_key the key to use */ void -RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, - struct GNUNET_CRYPTO_AuthKey auth_key); +RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem, + struct GNUNET_CRYPTO_AuthKey auth_key); #endif /* RPS_SAMPLER_ELEM_H */ diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c index bedd2ae6c..5de7c84dc 100644 --- a/src/rps/gnunet-service-rps_view.c +++ b/src/rps/gnunet-service-rps_view.c @@ -28,7 +28,8 @@ #include "gnunet-service-rps_view.h" #include <inttypes.h> -struct View { +struct View +{ /** * Array containing the peers */ @@ -53,15 +54,15 @@ struct View { * @return The newly created view */ struct View * -View_create(uint32_t len) +View_create (uint32_t len) { struct View *view; - view = GNUNET_new(struct View); + view = GNUNET_new (struct View); view->length = len; - view->array = GNUNET_new_array(len, struct GNUNET_PeerIdentity); + view->array = GNUNET_new_array (len, struct GNUNET_PeerIdentity); view->mpm = - GNUNET_CONTAINER_multipeermap_create(len, GNUNET_NO); /* might even be + GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO); /* might even be * set to _YES */ return view; } @@ -76,38 +77,38 @@ View_create(uint32_t len) * @param len the (maximum) length for the view */ void -View_change_len(struct View *view, - uint32_t len) +View_change_len (struct View *view, + uint32_t len) { uint32_t i; uint32_t *index; - if (GNUNET_CONTAINER_multipeermap_size(view->mpm) < len) - { /* Simply shrink */ + if (GNUNET_CONTAINER_multipeermap_size (view->mpm) < len) + { /* Simply shrink */ /* We might simply clear and free the left over space */ - GNUNET_array_grow(view->array, view->length, len); - } + GNUNET_array_grow (view->array, view->length, len); + } else /* We have to remove elements */ + { + /* TODO find a way to preserve indices */ + for (i = 0; i < len; i++) + { + index = GNUNET_CONTAINER_multipeermap_get (view->mpm, &view->array[i]); + GNUNET_assert (NULL != index); + GNUNET_free (index); + } + GNUNET_array_grow (view->array, view->length, len); + GNUNET_CONTAINER_multipeermap_destroy (view->mpm); + view->mpm = GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO); + for (i = 0; i < len; i++) { - /* TODO find a way to preserve indices */ - for (i = 0; i < len; i++) - { - index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); - GNUNET_assert(NULL != index); - GNUNET_free(index); - } - GNUNET_array_grow(view->array, view->length, len); - GNUNET_CONTAINER_multipeermap_destroy(view->mpm); - view->mpm = GNUNET_CONTAINER_multipeermap_create(len, GNUNET_NO); - for (i = 0; i < len; i++) - { - index = GNUNET_new(uint32_t); - *index = i; - GNUNET_CONTAINER_multipeermap_put(view->mpm, &view->array[i], index, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - } + index = GNUNET_new (uint32_t); + *index = i; + GNUNET_CONTAINER_multipeermap_put (view->mpm, &view->array[i], index, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); } - GNUNET_assert(view->length == len); + } + GNUNET_assert (view->length == len); } @@ -118,7 +119,7 @@ View_change_len(struct View *view, * @return the view in array representation */ const struct GNUNET_PeerIdentity * -View_get_as_array(const struct View *view) +View_get_as_array (const struct View *view) { return view->array; } @@ -131,9 +132,9 @@ View_get_as_array(const struct View *view) * @return current number of actually contained peers */ unsigned int -View_size(const struct View *view) +View_size (const struct View *view) { - return GNUNET_CONTAINER_multipeermap_size(view->mpm); + return GNUNET_CONTAINER_multipeermap_size (view->mpm); } @@ -147,25 +148,25 @@ View_size(const struct View *view) * GNUNET_NO if peer was not inserted */ int -View_put(struct View *view, - const struct GNUNET_PeerIdentity *peer) +View_put (struct View *view, + const struct GNUNET_PeerIdentity *peer) { uint32_t *index; - if ((view->length <= View_size(view)) || /* If array is 'full' */ - (GNUNET_YES == View_contains_peer(view, peer))) - { - return GNUNET_NO; - } + if ((view->length <= View_size (view)) || /* If array is 'full' */ + (GNUNET_YES == View_contains_peer (view, peer))) + { + return GNUNET_NO; + } else - { - index = GNUNET_new(uint32_t); - *index = (uint32_t)View_size(view); - view->array[*index] = *peer; - GNUNET_CONTAINER_multipeermap_put(view->mpm, peer, index, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - return GNUNET_OK; - } + { + index = GNUNET_new (uint32_t); + *index = (uint32_t) View_size (view); + view->array[*index] = *peer; + GNUNET_CONTAINER_multipeermap_put (view->mpm, peer, index, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + return GNUNET_OK; + } } @@ -179,10 +180,10 @@ View_put(struct View *view, * GNUNET_NO otherwise */ int -View_contains_peer(const struct View *view, - const struct GNUNET_PeerIdentity *peer) +View_contains_peer (const struct View *view, + const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multipeermap_contains(view->mpm, peer); + return GNUNET_CONTAINER_multipeermap_contains (view->mpm, peer); } @@ -196,32 +197,32 @@ View_contains_peer(const struct View *view, * GNUNET_NO if view does not contain peer */ int -View_remove_peer(struct View *view, - const struct GNUNET_PeerIdentity *peer) +View_remove_peer (struct View *view, + const struct GNUNET_PeerIdentity *peer) { uint32_t *index; uint32_t *swap_index; uint32_t last_index; - if (GNUNET_NO == View_contains_peer(view, peer)) - { - return GNUNET_NO; - } - index = GNUNET_CONTAINER_multipeermap_get(view->mpm, peer); - GNUNET_assert(NULL != index); - last_index = View_size(view) - 1; + if (GNUNET_NO == View_contains_peer (view, peer)) + { + return GNUNET_NO; + } + index = GNUNET_CONTAINER_multipeermap_get (view->mpm, peer); + GNUNET_assert (NULL != index); + last_index = View_size (view) - 1; if (*index < last_index) - { /* Fill the 'gap' in the array with the last peer */ - view->array[*index] = view->array[last_index]; - GNUNET_assert(GNUNET_YES == View_contains_peer(view, + { /* Fill the 'gap' in the array with the last peer */ + view->array[*index] = view->array[last_index]; + GNUNET_assert (GNUNET_YES == View_contains_peer (view, &view->array[last_index])); - swap_index = GNUNET_CONTAINER_multipeermap_get(view->mpm, - &view->array[last_index]); - GNUNET_assert(NULL != swap_index); - *swap_index = *index; - GNUNET_free(index); - } - GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, peer); + swap_index = GNUNET_CONTAINER_multipeermap_get (view->mpm, + &view->array[last_index]); + GNUNET_assert (NULL != swap_index); + *swap_index = *index; + GNUNET_free (index); + } + GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, peer); return GNUNET_OK; } @@ -236,17 +237,17 @@ View_remove_peer(struct View *view, * NULL if this index is not known */ const struct GNUNET_PeerIdentity * -View_get_peer_by_index(const struct View *view, - uint32_t index) +View_get_peer_by_index (const struct View *view, + uint32_t index) { - if (index < GNUNET_CONTAINER_multipeermap_size(view->mpm)) - { - return &view->array[index]; - } + if (index < GNUNET_CONTAINER_multipeermap_size (view->mpm)) + { + return &view->array[index]; + } else - { - return NULL; - } + { + return NULL; + } } @@ -256,20 +257,21 @@ View_get_peer_by_index(const struct View *view, * @param view The view to clear */ void -View_clear(struct View *view) +View_clear (struct View *view) { - for (uint32_t i = 0; 0 < View_size(view); i++) - { /* Need to free indices stored at peers */ - uint32_t *index; - - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains(view->mpm, &view->array[i])); - index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); - GNUNET_assert(NULL != index); - GNUNET_free(index); - GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, &view->array[i]); - } - GNUNET_assert(0 == View_size(view)); + for (uint32_t i = 0; 0 < View_size (view); i++) + { /* Need to free indices stored at peers */ + uint32_t *index; + + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_contains (view->mpm, + &view->array[i])); + index = GNUNET_CONTAINER_multipeermap_get (view->mpm, &view->array[i]); + GNUNET_assert (NULL != index); + GNUNET_free (index); + GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, &view->array[i]); + } + GNUNET_assert (0 == View_size (view)); } @@ -279,13 +281,13 @@ View_clear(struct View *view) * @param view the view to destroy */ void -View_destroy(struct View *view) +View_destroy (struct View *view) { - View_clear(view); - GNUNET_free(view->array); + View_clear (view); + GNUNET_free (view->array); view->array = NULL; - GNUNET_CONTAINER_multipeermap_destroy(view->mpm); - GNUNET_free(view); + GNUNET_CONTAINER_multipeermap_destroy (view->mpm); + GNUNET_free (view); } /* end of gnunet-service-rps_view.c */ diff --git a/src/rps/gnunet-service-rps_view.h b/src/rps/gnunet-service-rps_view.h index 0ceed5432..4d42272c1 100644 --- a/src/rps/gnunet-service-rps_view.h +++ b/src/rps/gnunet-service-rps_view.h @@ -35,7 +35,7 @@ struct View; * @return The newly created view */ struct View * -View_create(unsigned int len); +View_create (unsigned int len); /** @@ -47,8 +47,8 @@ View_create(unsigned int len); * @param len the (maximum) length for the view */ void -View_change_len(struct View *view, - unsigned int len); +View_change_len (struct View *view, + unsigned int len); /** * Get the view as an array @@ -56,7 +56,7 @@ View_change_len(struct View *view, * @return the view in array representation */ const struct GNUNET_PeerIdentity * -View_get_as_array(const struct View *view); +View_get_as_array (const struct View *view); /** @@ -66,7 +66,7 @@ View_get_as_array(const struct View *view); * @return current number of actually contained peers */ unsigned int -View_size(const struct View *view); +View_size (const struct View *view); /** @@ -79,8 +79,8 @@ View_size(const struct View *view); * GNUNET_NO if peer was not inserted */ int -View_put(struct View *view, - const struct GNUNET_PeerIdentity *peer); +View_put (struct View *view, + const struct GNUNET_PeerIdentity *peer); /** @@ -93,8 +93,8 @@ View_put(struct View *view, * GNUNET_NO otherwise */ int -View_contains_peer(const struct View *view, - const struct GNUNET_PeerIdentity *peer); +View_contains_peer (const struct View *view, + const struct GNUNET_PeerIdentity *peer); /** @@ -107,8 +107,8 @@ View_contains_peer(const struct View *view, * GNUNET_NO if view does not contain peer */ int -View_remove_peer(struct View *view, - const struct GNUNET_PeerIdentity *peer); +View_remove_peer (struct View *view, + const struct GNUNET_PeerIdentity *peer); /** @@ -121,8 +121,8 @@ View_remove_peer(struct View *view, * NULL if this index is not known */ const struct GNUNET_PeerIdentity * -View_get_peer_by_index(const struct View *view, - uint32_t index); +View_get_peer_by_index (const struct View *view, + uint32_t index); /** @@ -131,7 +131,7 @@ View_get_peer_by_index(const struct View *view, * @param view The view to clear */ void -View_clear(struct View *view); +View_clear (struct View *view); /** @@ -140,6 +140,6 @@ View_clear(struct View *view); * @param view the view to destroy */ void -View_destroy(struct View *view); +View_destroy (struct View *view); /* end of gnunet-service-rps_view.h */ diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c index b4ac5f6f8..5ab854e01 100644 --- a/src/rps/rps-sampler_client.c +++ b/src/rps/rps-sampler_client.c @@ -37,7 +37,7 @@ #include "rps-test_util.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler", __VA_ARGS__) // multiple 'clients'? @@ -68,7 +68,8 @@ typedef void * * Meant to be an entry in an DLL. */ -struct SamplerNotifyUpdateCTX { +struct SamplerNotifyUpdateCTX +{ /** * @brief The Callback to call on updates */ @@ -106,13 +107,14 @@ typedef void * corrsponding peer to the client. */ static void -sampler_mod_get_rand_peer(void *cls); +sampler_mod_get_rand_peer (void *cls); /** * Closure to _get_n_rand_peers_ready_cb() */ -struct RPS_SamplerRequestHandle { +struct RPS_SamplerRequestHandle +{ /** * DLL */ @@ -160,7 +162,8 @@ struct RPS_SamplerRequestHandle { /** * Closure to _get_rand_peer_info() */ -struct RPS_SamplerRequestHandleSingleInfo { +struct RPS_SamplerRequestHandleSingleInfo +{ /** * DLL */ @@ -198,7 +201,7 @@ struct RPS_SamplerRequestHandleSingleInfo { ///** // * Global sampler variable. // */ -//struct RPS_Sampler *sampler; +// struct RPS_Sampler *sampler; /** @@ -214,7 +217,7 @@ static size_t max_size; /** * The size the extended sampler elements currently have. */ -//static size_t extra_size; +// static size_t extra_size; /** * Inedex to the sampler element that is the next to be returned @@ -230,8 +233,8 @@ static uint32_t client_get_index; * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * -RPS_sampler_mod_init(size_t init_size, - struct GNUNET_TIME_Relative max_round_interval) +RPS_sampler_mod_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval) { struct RPS_Sampler *sampler; @@ -239,17 +242,17 @@ RPS_sampler_mod_init(size_t init_size, min_size = 10; // TODO make input to _samplers_init() max_size = 1000; // TODO make input to _samplers_init() - sampler = GNUNET_new(struct RPS_Sampler); + sampler = GNUNET_new (struct RPS_Sampler); sampler->max_round_interval = max_round_interval; sampler->get_peers = sampler_mod_get_rand_peer; - //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); - //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); + // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); + // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); client_get_index = 0; - //GNUNET_assert (init_size == sampler->sampler_size); + // GNUNET_assert (init_size == sampler->sampler_size); - RPS_sampler_resize(sampler, init_size); + RPS_sampler_resize (sampler, init_size); return sampler; } @@ -271,22 +274,22 @@ RPS_sampler_mod_init(size_t init_size, * @return The estimated probability */ static double -prob_observed_n_peers(uint32_t num_peers_estim, - uint32_t num_peers_observed, - double deficiency_factor) +prob_observed_n_peers (uint32_t num_peers_estim, + uint32_t num_peers_observed, + double deficiency_factor) { uint32_t num_peers = num_peers_estim * (1 / deficiency_factor); uint64_t sum = 0; for (uint32_t i = 0; i < num_peers; i++) - { - uint64_t a = pow(-1, num_peers - i); - uint64_t b = binom(num_peers, i); - uint64_t c = pow(i, num_peers_observed); - sum += a * b * c; - } - - return sum / (double)pow(num_peers, num_peers_observed); + { + uint64_t a = pow (-1, num_peers - i); + uint64_t b = binom (num_peers, i); + uint64_t c = pow (i, num_peers_observed); + sum += a * b * c; + } + + return sum / (double) pow (num_peers, num_peers_observed); } @@ -296,7 +299,7 @@ prob_observed_n_peers(uint32_t num_peers_estim, * This reinitialises the queried sampler element. */ static void -sampler_mod_get_rand_peer(void *cls) +sampler_mod_get_rand_peer (void *cls) { struct GetPeerCls *gpc = cls; struct RPS_SamplerElement *s_elem; @@ -307,86 +310,88 @@ sampler_mod_get_rand_peer(void *cls) gpc->get_peer_task = NULL; gpc->notify_ctx = NULL; - GNUNET_assert((NULL != gpc->req_handle) || - (NULL != gpc->req_single_info_handle)); + GNUNET_assert ((NULL != gpc->req_handle) || + (NULL != gpc->req_single_info_handle)); if (NULL != gpc->req_handle) sampler = gpc->req_handle->sampler; else sampler = gpc->req_single_info_handle->sampler; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); /* Cycle the #client_get_index one step further */ client_get_index = (client_get_index + 1) % sampler->sampler_size; s_elem = sampler->sampler_elements[client_get_index]; *gpc->id = s_elem->peer_id; - GNUNET_assert(NULL != s_elem); + GNUNET_assert (NULL != s_elem); if (EMPTY == s_elem->is_empty) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sampler_mod element empty, rescheduling.\n"); - GNUNET_assert(NULL == gpc->notify_ctx); - gpc->notify_ctx = - sampler_notify_on_update(sampler, - &sampler_mod_get_rand_peer, - gpc); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sampler_mod element empty, rescheduling.\n"); + GNUNET_assert (NULL == gpc->notify_ctx); + gpc->notify_ctx = + sampler_notify_on_update (sampler, + &sampler_mod_get_rand_peer, + gpc); + return; + } /* Check whether we may use this sampler to give it back to the client */ - if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) - { - // TODO remove this condition at least for the client sampler - last_request_diff = - GNUNET_TIME_absolute_get_difference(s_elem->last_client_request, - GNUNET_TIME_absolute_get()); - /* We're not going to give it back now if it was - * already requested by a client this round */ - if (last_request_diff.rel_value_us < sampler->max_round_interval.rel_value_us) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Last client request on this sampler was less than max round interval ago -- scheduling for later\n"); - ///* How many time remains untile the next round has started? */ - //inv_last_request_diff = - // GNUNET_TIME_absolute_get_difference (last_request_diff, - // sampler->max_round_interval); - // add a little delay - /* Schedule it one round later */ - GNUNET_assert(NULL == gpc->notify_ctx); - gpc->notify_ctx = - sampler_notify_on_update(sampler, - &sampler_mod_get_rand_peer, - gpc); - return; - } - } - if (2 > s_elem->num_peers) + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + s_elem->last_client_request.abs_value_us) + { + // TODO remove this condition at least for the client sampler + last_request_diff = + GNUNET_TIME_absolute_get_difference (s_elem->last_client_request, + GNUNET_TIME_absolute_get ()); + /* We're not going to give it back now if it was + * already requested by a client this round */ + if (last_request_diff.rel_value_us < + sampler->max_round_interval.rel_value_us) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "This s_elem saw less than two peers -- scheduling for later\n"); - GNUNET_assert(NULL == gpc->notify_ctx); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Last client request on this sampler was less than max round interval ago -- scheduling for later\n"); + ///* How many time remains untile the next round has started? */ + // inv_last_request_diff = + // GNUNET_TIME_absolute_get_difference (last_request_diff, + // sampler->max_round_interval); + // add a little delay + /* Schedule it one round later */ + GNUNET_assert (NULL == gpc->notify_ctx); gpc->notify_ctx = - sampler_notify_on_update(sampler, - &sampler_mod_get_rand_peer, - gpc); + sampler_notify_on_update (sampler, + &sampler_mod_get_rand_peer, + gpc); return; } + } + if (2 > s_elem->num_peers) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "This s_elem saw less than two peers -- scheduling for later\n"); + GNUNET_assert (NULL == gpc->notify_ctx); + gpc->notify_ctx = + sampler_notify_on_update (sampler, + &sampler_mod_get_rand_peer, + gpc); + return; + } /* compute probability */ /* Currently disabled due to numerical limitations */ - //prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, + // prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, // s_elem->num_peers, // sampler->deficiency_factor); - //LOG (GNUNET_ERROR_TYPE_DEBUG, + // LOG (GNUNET_ERROR_TYPE_DEBUG, // "Computed sample - prob %f, %" PRIu32 " peers, n: %" PRIu32 ", roh: %f\n", // prob_observed_n, // s_elem->num_peers, // sampler->num_peers_estim, // sampler->deficiency_factor); ///* check if probability is above desired */ - //if (prob_observed_n < sampler->desired_probability) - //{ + // if (prob_observed_n < sampler->desired_probability) + // { // LOG (GNUNET_ERROR_TYPE_DEBUG, // "Probability of having observed all peers (%f) too small ( < %f).\n", // prob_observed_n, @@ -397,7 +402,7 @@ sampler_mod_get_rand_peer(void *cls) // &sampler_mod_get_rand_peer, // gpc); // return; - //} + // } /* More reasons to wait could be added here */ // GNUNET_STATISTICS_set (stats, @@ -410,25 +415,24 @@ sampler_mod_get_rand_peer(void *cls) // GNUNET_NO); num_observed = s_elem->num_peers; - RPS_sampler_elem_reinit(s_elem); - s_elem->last_client_request = GNUNET_TIME_absolute_get(); + RPS_sampler_elem_reinit (s_elem); + s_elem->last_client_request = GNUNET_TIME_absolute_get (); if (NULL != gpc->req_handle) - { - GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, - gpc->req_handle->gpc_tail, - gpc); - } + { + GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, + gpc->req_handle->gpc_tail, + gpc); + } else - { - GNUNET_CONTAINER_DLL_remove(gpc->req_single_info_handle->gpc_head, - gpc->req_single_info_handle->gpc_tail, - gpc); - } - gpc->cont(gpc->cont_cls, gpc->id, prob_observed_n, num_observed); - GNUNET_free(gpc); + { + GNUNET_CONTAINER_DLL_remove (gpc->req_single_info_handle->gpc_head, + gpc->req_single_info_handle->gpc_tail, + gpc); + } + gpc->cont (gpc->cont_cls, gpc->id, prob_observed_n, num_observed); + GNUNET_free (gpc); } /* end of gnunet-service-rps.c */ - diff --git a/src/rps/rps-sampler_client.h b/src/rps/rps-sampler_client.h index db8087795..e6b808650 100644 --- a/src/rps/rps-sampler_client.h +++ b/src/rps/rps-sampler_client.h @@ -53,7 +53,7 @@ struct RPS_SamplerRequestHandleSingleInfo; * @return the size of the sampler */ unsigned int -RPS_sampler_get_size(struct RPS_Sampler *sampler); +RPS_sampler_get_size (struct RPS_Sampler *sampler); /** @@ -63,7 +63,7 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler); * @param new_size the new size of the sampler (not 0) */ void -RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); +RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); /** @@ -74,8 +74,8 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * -RPS_sampler_mod_init(size_t init_size, - struct GNUNET_TIME_Relative max_round_interval); +RPS_sampler_mod_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval); /** @@ -85,8 +85,8 @@ RPS_sampler_mod_init(size_t init_size, * @param id the PeerID that is put in the sampler */ void -RPS_sampler_update(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_update (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -99,8 +99,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler, * @param id the id of the samplers to update. */ void -RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -116,10 +116,10 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, * @param num_peers the number of peers requested */ 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); +RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, + uint32_t num_peers, + RPS_sampler_n_rand_peers_ready_cb cb, + void *cls); /** @@ -128,7 +128,7 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, * @param req_handle the handle to the request */ void -RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); +RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); /** @@ -140,8 +140,8 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); * @return the number of occurrences of id. */ uint32_t -RPS_sampler_count_id(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_count_id (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -150,7 +150,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler, * @param sampler the sampler to destroy. */ void -RPS_sampler_destroy(struct RPS_Sampler *sampler); +RPS_sampler_destroy (struct RPS_Sampler *sampler); #endif /* RPS_SAMPLER_CLIENT_H */ /* end of gnunet-service-rps.c */ diff --git a/src/rps/rps-sampler_common.c b/src/rps/rps-sampler_common.c index 48fa121b7..ab8c65f17 100644 --- a/src/rps/rps-sampler_common.c +++ b/src/rps/rps-sampler_common.c @@ -35,14 +35,15 @@ #include "rps-test_util.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler_common", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler_common", __VA_ARGS__) /** * @brief Context for a callback. Contains callback and closure. * * Meant to be an entry in an DLL. */ -struct SamplerNotifyUpdateCTX { +struct SamplerNotifyUpdateCTX +{ /** * @brief The Callback to call on updates */ @@ -68,7 +69,8 @@ struct SamplerNotifyUpdateCTX { /** * Closure to _get_n_rand_peers_ready_cb() */ -struct RPS_SamplerRequestHandle { +struct RPS_SamplerRequestHandle +{ /** * DLL */ @@ -116,7 +118,8 @@ struct RPS_SamplerRequestHandle { /** * Closure to _get_rand_peer_info() */ -struct RPS_SamplerRequestHandleSingleInfo { +struct RPS_SamplerRequestHandleSingleInfo +{ /** * DLL */ @@ -163,8 +166,8 @@ struct RPS_SamplerRequestHandleSingleInfo { * @param num_peers The estimated value */ void -RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, - uint32_t num_peers) +RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, + uint32_t num_peers) { sampler->num_peers_estim = num_peers; } @@ -181,8 +184,8 @@ RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, * @param desired_probability */ void -RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, - double desired_probability) +RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, + double desired_probability) { sampler->desired_probability = desired_probability; } @@ -198,8 +201,8 @@ RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, * @param desired_probability */ void -RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, - double deficiency_factor) +RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, + double deficiency_factor) { sampler->deficiency_factor = deficiency_factor; } @@ -216,20 +219,20 @@ RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, * @return The context containing callback and closure */ struct SamplerNotifyUpdateCTX * -sampler_notify_on_update(struct RPS_Sampler *sampler, - SamplerNotifyUpdateCB notify_cb, - void *cls) +sampler_notify_on_update (struct RPS_Sampler *sampler, + SamplerNotifyUpdateCB notify_cb, + void *cls) { struct SamplerNotifyUpdateCTX *notify_ctx; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Inserting new context for notification\n"); - notify_ctx = GNUNET_new(struct SamplerNotifyUpdateCTX); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Inserting new context for notification\n"); + notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX); notify_ctx->notify_cb = notify_cb; notify_ctx->cls = cls; - GNUNET_CONTAINER_DLL_insert(sampler->notify_ctx_head, - sampler->notify_ctx_tail, - notify_ctx); + GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head, + sampler->notify_ctx_tail, + notify_ctx); return notify_ctx; } @@ -241,7 +244,7 @@ sampler_notify_on_update(struct RPS_Sampler *sampler, * @return the size of the sampler */ unsigned int -RPS_sampler_get_size(struct RPS_Sampler *sampler) +RPS_sampler_get_size (struct RPS_Sampler *sampler) { return sampler->sampler_size; } @@ -256,13 +259,13 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler) * @param sampler The sampler the updates are waiting for */ static void -notify_update(struct RPS_Sampler *sampler) +notify_update (struct RPS_Sampler *sampler) { struct SamplerNotifyUpdateCTX *tmp_notify_head; struct SamplerNotifyUpdateCTX *tmp_notify_tail; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Calling callbacks waiting for update notification.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Calling callbacks waiting for update notification.\n"); tmp_notify_head = sampler->notify_ctx_head; tmp_notify_tail = sampler->notify_ctx_tail; sampler->notify_ctx_head = NULL; @@ -270,14 +273,14 @@ notify_update(struct RPS_Sampler *sampler) for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head; NULL != tmp_notify_head; notify_iter = tmp_notify_head) - { - GNUNET_assert(NULL != notify_iter->notify_cb); - GNUNET_CONTAINER_DLL_remove(tmp_notify_head, - tmp_notify_tail, - notify_iter); - notify_iter->notify_cb(notify_iter->cls); - GNUNET_free(notify_iter); - } + { + GNUNET_assert (NULL != notify_iter->notify_cb); + GNUNET_CONTAINER_DLL_remove (tmp_notify_head, + tmp_notify_tail, + notify_iter); + notify_iter->notify_cb (notify_iter->cls); + GNUNET_free (notify_iter); + } } @@ -288,15 +291,15 @@ notify_update(struct RPS_Sampler *sampler) * @param id the PeerID that is put in the sampler */ void -RPS_sampler_update(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id) +RPS_sampler_update (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id) { for (uint32_t i = 0; i < sampler->sampler_size; i++) - { - RPS_sampler_elem_next(sampler->sampler_elements[i], - id); - } - notify_update(sampler); + { + RPS_sampler_elem_next (sampler->sampler_elements[i], + id); + } + notify_update (sampler); } @@ -315,20 +318,20 @@ RPS_sampler_update(struct RPS_Sampler *sampler, * @param id the id of the sampler elements to update. */ void -RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id) +RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id) { uint32_t i; for (i = 0; i < sampler->sampler_size; i++) + { + if (0 == GNUNET_memcmp (id, + &(sampler->sampler_elements[i]->peer_id))) { - if (0 == GNUNET_memcmp(id, - &(sampler->sampler_elements[i]->peer_id))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); - RPS_sampler_elem_reinit(sampler->sampler_elements[i]); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); + RPS_sampler_elem_reinit (sampler->sampler_elements[i]); } + } } @@ -341,19 +344,19 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, * @return the number of occurrences of id. */ uint32_t -RPS_sampler_count_id(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id) +RPS_sampler_count_id (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id) { uint32_t count; uint32_t i; count = 0; for (i = 0; i < sampler->sampler_size; i++) - { - if (0 == GNUNET_memcmp(&sampler->sampler_elements[i]->peer_id, id) - && EMPTY != sampler->sampler_elements[i]->is_empty) - count++; - } + { + if ((0 == GNUNET_memcmp (&sampler->sampler_elements[i]->peer_id, id)) + &&(EMPTY != sampler->sampler_elements[i]->is_empty) ) + count++; + } return count; } @@ -365,7 +368,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler, * @param new_size the new size of the sampler */ static void -sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) +sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) { unsigned int old_size; uint32_t i; @@ -375,47 +378,47 @@ sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) old_size = sampler->sampler_size; if (old_size > new_size) - { /* Shrinking */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Shrinking sampler %d -> %d\n", - old_size, - new_size); - - for (i = new_size; i < old_size; i++) - { - RPS_sampler_elem_destroy(sampler->sampler_elements[i]); - } - - GNUNET_array_grow(sampler->sampler_elements, - sampler->sampler_size, - new_size); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "sampler->sampler_elements now points to %p\n", - sampler->sampler_elements); + { /* Shrinking */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Shrinking sampler %d -> %d\n", + old_size, + new_size); + + for (i = new_size; i < old_size; i++) + { + RPS_sampler_elem_destroy (sampler->sampler_elements[i]); } + + GNUNET_array_grow (sampler->sampler_elements, + sampler->sampler_size, + new_size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "sampler->sampler_elements now points to %p\n", + sampler->sampler_elements); + } else if (old_size < new_size) - { /* Growing */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Growing sampler %d -> %d\n", - old_size, - new_size); - - GNUNET_array_grow(sampler->sampler_elements, - sampler->sampler_size, - new_size); - - for (i = old_size; i < new_size; i++) - { /* Add new sampler elements */ - sampler->sampler_elements[i] = RPS_sampler_elem_create(); - } + { /* Growing */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Growing sampler %d -> %d\n", + old_size, + new_size); + + GNUNET_array_grow (sampler->sampler_elements, + sampler->sampler_size, + new_size); + + for (i = old_size; i < new_size; i++) + { /* Add new sampler elements */ + sampler->sampler_elements[i] = RPS_sampler_elem_create (); } + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n"); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n"); + return; + } - GNUNET_assert(sampler->sampler_size == new_size); + GNUNET_assert (sampler->sampler_size == new_size); } @@ -426,10 +429,10 @@ sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) * @param new_size the new size of the sampler */ void -RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) +RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) { - GNUNET_assert(0 < new_size); - sampler_resize(sampler, new_size); + GNUNET_assert (0 < new_size); + sampler_resize (sampler, new_size); } @@ -440,9 +443,9 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) * @param new_size the new size of the sampler */ static void -sampler_empty(struct RPS_Sampler *sampler) +sampler_empty (struct RPS_Sampler *sampler) { - sampler_resize(sampler, 0); + sampler_resize (sampler, 0); } @@ -459,48 +462,48 @@ sampler_empty(struct RPS_Sampler *sampler) * @param num_observed How many ids this sampler has observed */ static void -check_n_peers_ready(void *cls, - const struct GNUNET_PeerIdentity *id, - double probability, - uint32_t num_observed) +check_n_peers_ready (void *cls, + const struct GNUNET_PeerIdentity *id, + double probability, + uint32_t num_observed) { struct RPS_SamplerRequestHandle *req_handle = cls; - (void)id; + (void) id; RPS_sampler_n_rand_peers_ready_cb tmp_cb; struct GNUNET_PeerIdentity *peers; uint32_t num_peers; void *cb_cls; - (void)probability; - (void)num_observed; + (void) probability; + (void) num_observed; req_handle->cur_num_peers++; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got %" PRIX32 ". of %" PRIX32 " peers\n", - req_handle->cur_num_peers, req_handle->num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got %" PRIX32 ". of %" PRIX32 " peers\n", + req_handle->cur_num_peers, req_handle->num_peers); if (req_handle->num_peers == req_handle->cur_num_peers) - { /* All peers are ready -- return those to the client */ - GNUNET_assert(NULL != req_handle->callback); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "returning %" PRIX32 " peers to the client\n", - req_handle->num_peers); - - /* Copy pointers and peers temporarily as they - * might be deleted from within the callback */ - tmp_cb = req_handle->callback; - num_peers = req_handle->num_peers; - peers = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); - GNUNET_memcpy(peers, - req_handle->ids, - num_peers * sizeof(struct GNUNET_PeerIdentity)); - cb_cls = req_handle->cls; - RPS_sampler_request_cancel(req_handle); - req_handle = NULL; - tmp_cb(peers, num_peers, cb_cls); - GNUNET_free(peers); - } + { /* All peers are ready -- return those to the client */ + GNUNET_assert (NULL != req_handle->callback); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "returning %" PRIX32 " peers to the client\n", + req_handle->num_peers); + + /* Copy pointers and peers temporarily as they + * might be deleted from within the callback */ + tmp_cb = req_handle->callback; + num_peers = req_handle->num_peers; + peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); + GNUNET_memcpy (peers, + req_handle->ids, + num_peers * sizeof(struct GNUNET_PeerIdentity)); + cb_cls = req_handle->cls; + RPS_sampler_request_cancel (req_handle); + req_handle = NULL; + tmp_cb (peers, num_peers, cb_cls); + GNUNET_free (peers); + } } @@ -515,40 +518,40 @@ check_n_peers_ready(void *cls, * @param num_observed How many ids this sampler has observed */ static void -check_peer_info_ready(void *cls, - const struct GNUNET_PeerIdentity *id, - double probability, - uint32_t num_observed) +check_peer_info_ready (void *cls, + const struct GNUNET_PeerIdentity *id, + double probability, + uint32_t num_observed) { struct RPS_SamplerRequestHandleSingleInfo *req_handle = cls; - (void)id; + (void) id; RPS_sampler_sinlge_info_ready_cb tmp_cb; struct GNUNET_PeerIdentity *peer; void *cb_cls; - (void)probability; - (void)num_observed; + (void) probability; + (void) num_observed; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got single peer with additional info\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got single peer with additional info\n"); - GNUNET_assert(NULL != req_handle->callback); + GNUNET_assert (NULL != req_handle->callback); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "returning single peer with info to the client\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "returning single peer with info to the client\n"); /* Copy pointers and peers temporarily as they * might be deleted from within the callback */ tmp_cb = req_handle->callback; - peer = GNUNET_new(struct GNUNET_PeerIdentity); - GNUNET_memcpy(peer, - req_handle->id, - sizeof(struct GNUNET_PeerIdentity)); + peer = GNUNET_new (struct GNUNET_PeerIdentity); + GNUNET_memcpy (peer, + req_handle->id, + sizeof(struct GNUNET_PeerIdentity)); cb_cls = req_handle->cls; - RPS_sampler_request_single_info_cancel(req_handle); + RPS_sampler_request_single_info_cancel (req_handle); req_handle = NULL; - tmp_cb(peer, cb_cls, probability, num_observed); - GNUNET_free(peer); + tmp_cb (peer, cb_cls, probability, num_observed); + GNUNET_free (peer); } @@ -565,50 +568,50 @@ check_peer_info_ready(void *cls, * @param num_peers the number of peers requested */ 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) +RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, + uint32_t num_peers, + RPS_sampler_n_rand_peers_ready_cb cb, + void *cls) { uint32_t i; struct RPS_SamplerRequestHandle *req_handle; struct GetPeerCls *gpc; - GNUNET_assert(0 != sampler->sampler_size); + GNUNET_assert (0 != sampler->sampler_size); if (0 == num_peers) return NULL; // TODO check if we have too much (distinct) sampled peers - req_handle = GNUNET_new(struct RPS_SamplerRequestHandle); + req_handle = GNUNET_new (struct RPS_SamplerRequestHandle); req_handle->num_peers = num_peers; req_handle->cur_num_peers = 0; - req_handle->ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); + req_handle->ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); req_handle->sampler = sampler; req_handle->callback = cb; req_handle->cls = cls; - GNUNET_CONTAINER_DLL_insert(sampler->req_handle_head, - sampler->req_handle_tail, - req_handle); + GNUNET_CONTAINER_DLL_insert (sampler->req_handle_head, + sampler->req_handle_tail, + req_handle); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling requests for %" PRIu32 " peers\n", num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling requests for %" PRIu32 " peers\n", num_peers); for (i = 0; i < num_peers; i++) - { - gpc = GNUNET_new(struct GetPeerCls); - gpc->req_handle = req_handle; - gpc->req_single_info_handle = NULL; - gpc->cont = check_n_peers_ready; - gpc->cont_cls = req_handle; - gpc->id = &req_handle->ids[i]; - - GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, - req_handle->gpc_tail, - gpc); - // maybe add a little delay - gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, - gpc); - } + { + gpc = GNUNET_new (struct GetPeerCls); + gpc->req_handle = req_handle; + gpc->req_single_info_handle = NULL; + gpc->cont = check_n_peers_ready; + gpc->cont_cls = req_handle; + gpc->id = &req_handle->ids[i]; + + GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head, + req_handle->gpc_tail, + gpc); + // maybe add a little delay + gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, + gpc); + } return req_handle; } @@ -621,38 +624,38 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, * @param cls closure given to @a cb */ struct RPS_SamplerRequestHandleSingleInfo * -RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, - RPS_sampler_sinlge_info_ready_cb cb, - void *cls) +RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, + RPS_sampler_sinlge_info_ready_cb cb, + void *cls) { struct RPS_SamplerRequestHandleSingleInfo *req_handle; struct GetPeerCls *gpc; - GNUNET_assert(0 != sampler->sampler_size); + GNUNET_assert (0 != sampler->sampler_size); // TODO check if we have too much (distinct) sampled peers - req_handle = GNUNET_new(struct RPS_SamplerRequestHandleSingleInfo); - req_handle->id = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); + req_handle = GNUNET_new (struct RPS_SamplerRequestHandleSingleInfo); + req_handle->id = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)); req_handle->sampler = sampler; req_handle->callback = cb; req_handle->cls = cls; - GNUNET_CONTAINER_DLL_insert(sampler->req_handle_single_head, - sampler->req_handle_single_tail, - req_handle); + GNUNET_CONTAINER_DLL_insert (sampler->req_handle_single_head, + sampler->req_handle_single_tail, + req_handle); - gpc = GNUNET_new(struct GetPeerCls); + gpc = GNUNET_new (struct GetPeerCls); gpc->req_handle = NULL; gpc->req_single_info_handle = req_handle; gpc->cont = check_peer_info_ready; gpc->cont_cls = req_handle; gpc->id = req_handle->id; - GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, - req_handle->gpc_tail, - gpc); + GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head, + req_handle->gpc_tail, + gpc); // maybe add a little delay - gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, - gpc); + gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, + gpc); return req_handle; } @@ -663,35 +666,35 @@ RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, * @param req_handle the handle to the request */ void -RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle) +RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) { struct GetPeerCls *i; while (NULL != (i = req_handle->gpc_head)) + { + GNUNET_CONTAINER_DLL_remove (req_handle->gpc_head, + req_handle->gpc_tail, + i); + if (NULL != i->get_peer_task) + { + GNUNET_SCHEDULER_cancel (i->get_peer_task); + } + if (NULL != i->notify_ctx) { - GNUNET_CONTAINER_DLL_remove(req_handle->gpc_head, - req_handle->gpc_tail, - i); - if (NULL != i->get_peer_task) - { - GNUNET_SCHEDULER_cancel(i->get_peer_task); - } - if (NULL != i->notify_ctx) - { - GNUNET_CONTAINER_DLL_remove(req_handle->sampler->notify_ctx_head, - req_handle->sampler->notify_ctx_tail, - i->notify_ctx); - GNUNET_free(i->notify_ctx); - i->notify_ctx = NULL; - } - GNUNET_free(i); + GNUNET_CONTAINER_DLL_remove (req_handle->sampler->notify_ctx_head, + req_handle->sampler->notify_ctx_tail, + i->notify_ctx); + GNUNET_free (i->notify_ctx); + i->notify_ctx = NULL; } - GNUNET_free(req_handle->ids); + GNUNET_free (i); + } + GNUNET_free (req_handle->ids); req_handle->ids = NULL; - GNUNET_CONTAINER_DLL_remove(req_handle->sampler->req_handle_head, - req_handle->sampler->req_handle_tail, - req_handle); - GNUNET_free(req_handle); + GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, + req_handle->sampler->req_handle_tail, + req_handle); + GNUNET_free (req_handle); } @@ -701,36 +704,40 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle) * @param req_handle the handle to the request */ void -RPS_sampler_request_single_info_cancel( +RPS_sampler_request_single_info_cancel ( struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle) { struct GetPeerCls *i; while (NULL != (i = req_single_info_handle->gpc_head)) + { + GNUNET_CONTAINER_DLL_remove (req_single_info_handle->gpc_head, + req_single_info_handle->gpc_tail, + i); + if (NULL != i->get_peer_task) + { + GNUNET_SCHEDULER_cancel (i->get_peer_task); + } + if (NULL != i->notify_ctx) { - GNUNET_CONTAINER_DLL_remove(req_single_info_handle->gpc_head, - req_single_info_handle->gpc_tail, - i); - if (NULL != i->get_peer_task) - { - GNUNET_SCHEDULER_cancel(i->get_peer_task); - } - if (NULL != i->notify_ctx) - { - GNUNET_CONTAINER_DLL_remove(req_single_info_handle->sampler->notify_ctx_head, - req_single_info_handle->sampler->notify_ctx_tail, - i->notify_ctx); - GNUNET_free(i->notify_ctx); - i->notify_ctx = NULL; - } - GNUNET_free(i); + GNUNET_CONTAINER_DLL_remove ( + req_single_info_handle->sampler->notify_ctx_head, + req_single_info_handle->sampler-> + notify_ctx_tail, + i->notify_ctx); + GNUNET_free (i->notify_ctx); + i->notify_ctx = NULL; } - GNUNET_free(req_single_info_handle->id); + GNUNET_free (i); + } + GNUNET_free (req_single_info_handle->id); req_single_info_handle->id = NULL; - GNUNET_CONTAINER_DLL_remove(req_single_info_handle->sampler->req_handle_single_head, - req_single_info_handle->sampler->req_handle_single_tail, - req_single_info_handle); - GNUNET_free(req_single_info_handle); + GNUNET_CONTAINER_DLL_remove ( + req_single_info_handle->sampler->req_handle_single_head, + req_single_info_handle->sampler-> + req_handle_single_tail, + req_single_info_handle); + GNUNET_free (req_single_info_handle); } @@ -738,19 +745,19 @@ RPS_sampler_request_single_info_cancel( * Cleans the sampler. */ void -RPS_sampler_destroy(struct RPS_Sampler *sampler) +RPS_sampler_destroy (struct RPS_Sampler *sampler) { if (NULL != sampler->req_handle_head) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "There are still pending requests. Going to remove them.\n"); + while (NULL != sampler->req_handle_head) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "There are still pending requests. Going to remove them.\n"); - while (NULL != sampler->req_handle_head) - { - RPS_sampler_request_cancel(sampler->req_handle_head); - } + RPS_sampler_request_cancel (sampler->req_handle_head); } - sampler_empty(sampler); - GNUNET_free(sampler); + } + sampler_empty (sampler); + GNUNET_free (sampler); } diff --git a/src/rps/rps-sampler_common.h b/src/rps/rps-sampler_common.h index 4a45c0193..72202dc93 100644 --- a/src/rps/rps-sampler_common.h +++ b/src/rps/rps-sampler_common.h @@ -103,7 +103,8 @@ typedef void /** * Closure for #sampler_mod_get_rand_peer() and #sampler_get_rand_peer */ -struct GetPeerCls { +struct GetPeerCls +{ /** * DLL */ @@ -150,12 +151,13 @@ struct GetPeerCls { /** * Sampler with its own array of SamplerElements */ -struct RPS_Sampler { +struct RPS_Sampler +{ /** * Number of sampler elements we hold. */ unsigned int sampler_size; - //size_t size; + // size_t size; /** * All sampler elements in one array. @@ -220,8 +222,8 @@ struct RPS_Sampler { * @param num_peers The estimated value */ void -RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, - uint32_t num_peers); +RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, + uint32_t num_peers); /** @@ -235,8 +237,8 @@ RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, * @param desired_probability */ void -RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, - double desired_probability); +RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, + double desired_probability); /** @@ -249,8 +251,8 @@ RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, * @param desired_probability */ void -RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, - double deficiency_factor); +RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, + double deficiency_factor); /** @@ -264,9 +266,9 @@ RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, * @return The context containing callback and closure */ struct SamplerNotifyUpdateCTX * -sampler_notify_on_update(struct RPS_Sampler *sampler, - SamplerNotifyUpdateCB notify_cb, - void *cls); +sampler_notify_on_update (struct RPS_Sampler *sampler, + SamplerNotifyUpdateCB notify_cb, + void *cls); /** @@ -276,8 +278,8 @@ sampler_notify_on_update(struct RPS_Sampler *sampler, * @param id the PeerID that is put in the sampler */ void -RPS_sampler_update(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_update (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -289,8 +291,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler, * @param id the id of the sampler elements to update. */ void -RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -300,7 +302,7 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, * @return the size of the sampler */ unsigned int -RPS_sampler_get_size(struct RPS_Sampler *sampler); +RPS_sampler_get_size (struct RPS_Sampler *sampler); /** @@ -310,7 +312,7 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler); * @param new_size the new size of the sampler */ void -RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); +RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); /** @@ -328,10 +330,10 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); * @param num_peers the number of peers requested */ 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); +RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, + uint32_t num_peers, + RPS_sampler_n_rand_peers_ready_cb cb, + void *cls); /** @@ -342,9 +344,9 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, * @param cls closure given to @a cb */ struct RPS_SamplerRequestHandleSingleInfo * -RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, - RPS_sampler_sinlge_info_ready_cb cb, - void *cls); +RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, + RPS_sampler_sinlge_info_ready_cb cb, + void *cls); /** @@ -356,8 +358,8 @@ RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, * @return the number of occurrences of id. */ uint32_t -RPS_sampler_count_id(struct RPS_Sampler *sampler, - const struct GNUNET_PeerIdentity *id); +RPS_sampler_count_id (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -366,7 +368,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler, * @param req_handle the handle to the request */ void -RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); +RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); /** @@ -375,7 +377,7 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); * @param req_handle the handle to the request */ void -RPS_sampler_request_single_info_cancel( +RPS_sampler_request_single_info_cancel ( struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle); @@ -383,7 +385,7 @@ RPS_sampler_request_single_info_cancel( * Cleans the sampler. */ void -RPS_sampler_destroy(struct RPS_Sampler *sampler); +RPS_sampler_destroy (struct RPS_Sampler *sampler); #endif /* RPS_SAMPLER_COMMON_H */ /* end of rps-sampler_common.h */ diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 8680494f8..66f93d86f 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c @@ -32,7 +32,7 @@ #include <inttypes.h> -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-test_util", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-test_util", __VA_ARGS__) #define B2B_PAT "%c%c%c%c%c%c%c%c" #define B2B(byte) \ @@ -72,43 +72,43 @@ static struct GNUNET_CONTAINER_MultiHashMap *open_files; * @return File handle */ struct GNUNET_DISK_FileHandle * -get_file_handle(const char *name) +get_file_handle (const char *name) { struct GNUNET_HashCode hash; struct GNUNET_DISK_FileHandle *fh; if (NULL == open_files) - { - open_files = GNUNET_CONTAINER_multihashmap_create(16, - GNUNET_NO); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created map of open files.\n"); - } - GNUNET_CRYPTO_hash(name, - strlen(name), - &hash); - if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get(open_files, - &hash))) + { + open_files = GNUNET_CONTAINER_multihashmap_create (16, + GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created map of open files.\n"); + } + GNUNET_CRYPTO_hash (name, + strlen (name), + &hash); + if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get (open_files, + &hash))) return fh; - fh = GNUNET_DISK_file_open(name, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_APPEND, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ); + fh = GNUNET_DISK_file_open (name, + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE + | GNUNET_DISK_OPEN_APPEND, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ); if (NULL == fh) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Opening file `%s' failed.\n", - name); - GNUNET_assert(0); - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put(open_files, - &hash, - fh, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Opening file `%s' failed.\n", + name); + GNUNET_assert (0); + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put (open_files, + &hash, + fh, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return fh; } @@ -127,18 +127,18 @@ get_file_handle(const char *name) * #GNUNET_NO if not. */ int -close_files_iter(void *cls, - const struct GNUNET_HashCode *key, - void *value) +close_files_iter (void *cls, + const struct GNUNET_HashCode *key, + void *value) { - (void)cls; - (void)key; + (void) cls; + (void) key; struct GNUNET_DISK_FileHandle *fh = value; if (NULL != fh) - { - GNUNET_DISK_file_close(fh); - } + { + GNUNET_DISK_file_close (fh); + } return GNUNET_YES; } @@ -149,14 +149,14 @@ close_files_iter(void *cls, * @return Success of iterating over files */ int -close_all_files() +close_all_files () { int ret; - ret = GNUNET_CONTAINER_multihashmap_iterate(open_files, - close_files_iter, - NULL); - GNUNET_CONTAINER_multihashmap_destroy(open_files); + ret = GNUNET_CONTAINER_multihashmap_iterate (open_files, + close_files_iter, + NULL); + GNUNET_CONTAINER_multihashmap_destroy (open_files); open_files = NULL; return ret; } @@ -164,58 +164,58 @@ close_all_files() void -to_file_raw(const char *file_name, const char *buf, size_t size_buf) +to_file_raw (const char *file_name, const char *buf, size_t size_buf) { struct GNUNET_DISK_FileHandle *f; size_t size_written; - if (NULL == (f = GNUNET_DISK_file_open(file_name, - GNUNET_DISK_OPEN_APPEND | - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to open file %s\n", - file_name); - return; - } - - size_written = GNUNET_DISK_file_write(f, buf, size_buf); + if (NULL == (f = GNUNET_DISK_file_open (file_name, + GNUNET_DISK_OPEN_APPEND + | GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to open file %s\n", + file_name); + return; + } + + size_written = GNUNET_DISK_file_write (f, buf, size_buf); if (size_buf != size_written) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to write to file! (Size: %u, size_written: %u)\n", - size_buf, - size_written); - - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - - return; - } - LOG(GNUNET_ERROR_TYPE_WARNING, - "Wrote %u bytes raw.\n", - size_written); - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to write to file! (Size: %u, size_written: %u)\n", + size_buf, + size_written); + + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); + + return; + } + LOG (GNUNET_ERROR_TYPE_WARNING, + "Wrote %u bytes raw.\n", + size_written); + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); } void -to_file_raw_unaligned(const char *file_name, - const char *buf, - size_t size_buf, - unsigned bits_needed) +to_file_raw_unaligned (const char *file_name, + const char *buf, + size_t size_buf, + unsigned bits_needed) { // TODO endianness! - GNUNET_assert(size_buf >= (bits_needed / 8)); - //if (0 == num_bits_buf_unaligned) - //{ + GNUNET_assert (size_buf >= (bits_needed / 8)); + // if (0 == num_bits_buf_unaligned) + // { // if (0 == (bits_needed % 8)) // { // to_file_raw (file_name, buf, size_buf); @@ -225,9 +225,9 @@ to_file_raw_unaligned(const char *file_name, // buf_unaligned = buf[size_buf - 1]; // num_bits_buf_unaligned = bits_needed % 8; // return; - //} - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Was asked to write %u bits\n", bits_needed); + // } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Was asked to write %u bits\n", bits_needed); char buf_write[size_buf + 1]; const unsigned bytes_iter = (0 != bits_needed % 8 ? @@ -235,145 +235,145 @@ to_file_raw_unaligned(const char *file_name, bits_needed / 8); // TODO what if no iteration happens? unsigned size_buf_write = 0; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "num_bits_buf_unaligned: %u\n", - num_bits_buf_unaligned); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", - size_buf, - bits_needed, - bytes_iter); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "num_bits_buf_unaligned: %u\n", + num_bits_buf_unaligned); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", + size_buf, + bits_needed, + bytes_iter); buf_write[0] = buf_unaligned; /* Iterate over input bytes */ for (unsigned i = 0; i < bytes_iter; i++) + { + /* Number of bits needed in this iteration - 8 for all except last iter */ + unsigned num_bits_needed_iter; + /* Mask for bits to actually use */ + unsigned mask_bits_needed_iter; + char byte_input; + /* Number of bits needed to align unaligned byte */ + unsigned num_bits_to_align; + /* Number of bits that are to be moved */ + unsigned num_bits_to_move; + /* Mask for bytes to be moved */ + char mask_input_to_move; + /* Masked bits to be moved */ + char bits_to_move; + /* The amount of bits needed to fit the bits to shift to the nearest spot */ + unsigned distance_shift_bits; + /* Shifted bits on the move */ + char bits_moving; + /* (unaligned) byte being filled with bits */ + char byte_to_fill; + /* mask for needed bits of the input byte that have not been moved */ + char mask_input_leftover; + /* needed bits of the input byte that have not been moved */ + char byte_input_leftover; + unsigned num_bits_leftover; + // unsigned num_bits_discard; + char byte_unaligned_new; + + if ((bits_needed - (i * 8)) <= 8) + { + /* last iteration */ + num_bits_needed_iter = bits_needed - (i * 8); + } + else + { + num_bits_needed_iter = 8; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits needed in this iteration: %u\n", + num_bits_needed_iter); + mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask needed bits (current iter): "B2B_PAT "\n", + B2B (mask_bits_needed_iter)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Unaligned byte: "B2B_PAT " (%u bits)\n", + B2B (buf_unaligned), + num_bits_buf_unaligned); + byte_input = buf[i]; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "next whole input byte: "B2B_PAT "\n", + B2B (byte_input)); + byte_input &= mask_bits_needed_iter; + num_bits_to_align = 8 - num_bits_buf_unaligned; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "input byte, needed bits: "B2B_PAT "\n", + B2B (byte_input)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits needed to align unaligned bit: %u\n", + num_bits_to_align); + num_bits_to_move = GNUNET_MIN (num_bits_to_align, num_bits_needed_iter); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits of new byte to move: %u\n", + num_bits_to_move); + mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask of bits of new byte to take for moving: "B2B_PAT "\n", + B2B (mask_input_to_move)); + bits_to_move = byte_input & mask_input_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "masked bits of new byte to take for moving: "B2B_PAT "\n", + B2B (bits_to_move)); + distance_shift_bits = num_bits_buf_unaligned; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "distance needed to shift bits to their correct spot: %u\n", + distance_shift_bits); + bits_moving = bits_to_move << distance_shift_bits; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "shifted, masked bits of new byte being moved: "B2B_PAT "\n", + B2B (bits_moving)); + byte_to_fill = buf_unaligned | bits_moving; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "byte being filled: "B2B_PAT "\n", + B2B (byte_to_fill)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "pending bytes: %u\n", + num_bits_buf_unaligned + num_bits_needed_iter); + if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) { - /* Number of bits needed in this iteration - 8 for all except last iter */ - unsigned num_bits_needed_iter; - /* Mask for bits to actually use */ - unsigned mask_bits_needed_iter; - char byte_input; - /* Number of bits needed to align unaligned byte */ - unsigned num_bits_to_align; - /* Number of bits that are to be moved */ - unsigned num_bits_to_move; - /* Mask for bytes to be moved */ - char mask_input_to_move; - /* Masked bits to be moved */ - char bits_to_move; - /* The amount of bits needed to fit the bits to shift to the nearest spot */ - unsigned distance_shift_bits; - /* Shifted bits on the move */ - char bits_moving; - /* (unaligned) byte being filled with bits */ - char byte_to_fill; - /* mask for needed bits of the input byte that have not been moved */ - char mask_input_leftover; - /* needed bits of the input byte that have not been moved */ - char byte_input_leftover; - unsigned num_bits_leftover; - //unsigned num_bits_discard; - char byte_unaligned_new; - - if ((bits_needed - (i * 8)) <= 8) - { - /* last iteration */ - num_bits_needed_iter = bits_needed - (i * 8); - } - else - { - num_bits_needed_iter = 8; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits needed in this iteration: %u\n", - num_bits_needed_iter); - mask_bits_needed_iter = ((char)1 << num_bits_needed_iter) - 1; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask needed bits (current iter): "B2B_PAT "\n", - B2B(mask_bits_needed_iter)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Unaligned byte: "B2B_PAT " (%u bits)\n", - B2B(buf_unaligned), - num_bits_buf_unaligned); - byte_input = buf[i]; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "next whole input byte: "B2B_PAT "\n", - B2B(byte_input)); - byte_input &= mask_bits_needed_iter; - num_bits_to_align = 8 - num_bits_buf_unaligned; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "input byte, needed bits: "B2B_PAT "\n", - B2B(byte_input)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits needed to align unaligned bit: %u\n", - num_bits_to_align); - num_bits_to_move = GNUNET_MIN(num_bits_to_align, num_bits_needed_iter); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits of new byte to move: %u\n", - num_bits_to_move); - mask_input_to_move = ((char)1 << num_bits_to_move) - 1; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask of bits of new byte to take for moving: "B2B_PAT "\n", - B2B(mask_input_to_move)); - bits_to_move = byte_input & mask_input_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "masked bits of new byte to take for moving: "B2B_PAT "\n", - B2B(bits_to_move)); - distance_shift_bits = num_bits_buf_unaligned; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "distance needed to shift bits to their correct spot: %u\n", - distance_shift_bits); - bits_moving = bits_to_move << distance_shift_bits; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "shifted, masked bits of new byte being moved: "B2B_PAT "\n", - B2B(bits_moving)); - byte_to_fill = buf_unaligned | bits_moving; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "byte being filled: "B2B_PAT "\n", - B2B(byte_to_fill)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "pending bytes: %u\n", - num_bits_buf_unaligned + num_bits_needed_iter); - if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) - { - /* buf_unaligned was aligned by filling - * -> can be written to storage */ - buf_write[i] = byte_to_fill; - size_buf_write++; - - /* store the leftover, unaligned bits in buffer */ - mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask of leftover bits of new byte: "B2B_PAT "\n", - B2B(mask_input_leftover)); - byte_input_leftover = byte_input & mask_input_leftover; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "masked, leftover bits of new byte: "B2B_PAT "\n", - B2B(byte_input_leftover)); - num_bits_leftover = num_bits_needed_iter - num_bits_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of unaligned bits left: %u\n", - num_bits_leftover); - //num_bits_discard = 8 - num_bits_needed_iter; - byte_unaligned_new = byte_input_leftover >> num_bits_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "new unaligned byte: "B2B_PAT "\n", - B2B(byte_unaligned_new)); - buf_unaligned = byte_unaligned_new; - num_bits_buf_unaligned = num_bits_leftover % 8; - } - else - { - /* unaligned buffer still unaligned but 'fuller' */ - buf_unaligned = byte_to_fill; - num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; - } + /* buf_unaligned was aligned by filling + * -> can be written to storage */ + buf_write[i] = byte_to_fill; + size_buf_write++; + + /* store the leftover, unaligned bits in buffer */ + mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask of leftover bits of new byte: "B2B_PAT "\n", + B2B (mask_input_leftover)); + byte_input_leftover = byte_input & mask_input_leftover; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "masked, leftover bits of new byte: "B2B_PAT "\n", + B2B (byte_input_leftover)); + num_bits_leftover = num_bits_needed_iter - num_bits_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of unaligned bits left: %u\n", + num_bits_leftover); + // num_bits_discard = 8 - num_bits_needed_iter; + byte_unaligned_new = byte_input_leftover >> num_bits_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "new unaligned byte: "B2B_PAT "\n", + B2B (byte_unaligned_new)); + buf_unaligned = byte_unaligned_new; + num_bits_buf_unaligned = num_bits_leftover % 8; } - to_file_raw(file_name, buf_write, size_buf_write); - LOG(GNUNET_ERROR_TYPE_DEBUG, "\n"); + else + { + /* unaligned buffer still unaligned but 'fuller' */ + buf_unaligned = byte_to_fill; + num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; + } + } + to_file_raw (file_name, buf_write, size_buf_write); + LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); } char * -auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) +auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) { int size; size_t name_buf_size; @@ -383,33 +383,33 @@ auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) size_t keylen = (sizeof(struct GNUNET_CRYPTO_AuthKey)) * 8; name_buf_size = 512 * sizeof(char); - name_buf = GNUNET_malloc(name_buf_size); + name_buf = GNUNET_malloc (name_buf_size); if (keylen % 5 > 0) keylen += 5 - keylen % 5; keylen /= 5; - buf = GNUNET_malloc(keylen + 1); + buf = GNUNET_malloc (keylen + 1); - end = GNUNET_STRINGS_data_to_string(&(auth_key.key), - sizeof(struct GNUNET_CRYPTO_AuthKey), - buf, - keylen); + end = GNUNET_STRINGS_data_to_string (&(auth_key.key), + sizeof(struct GNUNET_CRYPTO_AuthKey), + buf, + keylen); if (NULL == end) - { - GNUNET_free(buf); - GNUNET_break(0); - } + { + GNUNET_free (buf); + GNUNET_break (0); + } else - { - *end = '\0'; - } + { + *end = '\0'; + } - size = GNUNET_snprintf(name_buf, name_buf_size, "sampler_el-%s", buf); + size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf); if (0 > size) - LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); + LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); - GNUNET_free(buf); + GNUNET_free (buf); return name_buf; } @@ -418,18 +418,18 @@ auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) struct GNUNET_CRYPTO_AuthKey -string_to_auth_key(const char *str) +string_to_auth_key (const char *str) { struct GNUNET_CRYPTO_AuthKey auth_key; if (GNUNET_OK != - GNUNET_STRINGS_string_to_data(str, - strlen(str), - &auth_key.key, - sizeof(struct GNUNET_CRYPTO_AuthKey))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); - } + GNUNET_STRINGS_string_to_data (str, + strlen (str), + &auth_key.key, + sizeof(struct GNUNET_CRYPTO_AuthKey))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); + } return auth_key; } @@ -442,60 +442,60 @@ string_to_auth_key(const char *str) * #GNUNET_SYSERR on failure */ static int -ensure_folder_exist(void) +ensure_folder_exist (void) { if (GNUNET_OK != - GNUNET_DISK_directory_create("/tmp/rps")) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Could not create directory `/tmp/rps'\n"); - return GNUNET_SYSERR; - } + GNUNET_DISK_directory_create ("/tmp/rps")) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Could not create directory `/tmp/rps'\n"); + return GNUNET_SYSERR; + } return GNUNET_YES; } char * -store_prefix_file_name(const unsigned int index, - const char *prefix) +store_prefix_file_name (const unsigned int index, + const char *prefix) { int len_file_name; int out_size; char *file_name; char index_str[64]; - if (GNUNET_SYSERR == ensure_folder_exist()) + if (GNUNET_SYSERR == ensure_folder_exist ()) return NULL; - out_size = GNUNET_snprintf(index_str, - 64, - "%u", - index); - if (64 < out_size || - 0 > out_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to write string to buffer (size: %i, out_size: %i)\n", - 64, - out_size); - } - len_file_name = (strlen(prefix) + - strlen(index_str) + - 11) + out_size = GNUNET_snprintf (index_str, + 64, + "%u", + index); + if ((64 < out_size)|| + (0 > out_size) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to write string to buffer (size: %i, out_size: %i)\n", + 64, + out_size); + } + len_file_name = (strlen (prefix) + + strlen (index_str) + + 11) * sizeof(char); - file_name = GNUNET_malloc(len_file_name); - out_size = GNUNET_snprintf(file_name, - len_file_name, - "/tmp/rps/%s-%s", - prefix, - index_str); - if (len_file_name < out_size || - 0 > out_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to write string to buffer (size: %i, out_size: %i)\n", - len_file_name, - out_size); - } + file_name = GNUNET_malloc (len_file_name); + out_size = GNUNET_snprintf (file_name, + len_file_name, + "/tmp/rps/%s-%s", + prefix, + index_str); + if ((len_file_name < out_size)|| + (0 > out_size) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to write string to buffer (size: %i, out_size: %i)\n", + len_file_name, + out_size); + } return file_name; } @@ -507,13 +507,13 @@ store_prefix_file_name(const unsigned int index, * * @return Factorial of @a x */ -uint32_t fac(uint32_t x) +uint32_t fac (uint32_t x) { if (1 >= x) - { - return x; - } - return x * fac(x - 1); + { + return x; + } + return x * fac (x - 1); } /** @@ -524,18 +524,18 @@ uint32_t fac(uint32_t x) * * @return Binomial coefficient of @a n and @a k */ -uint32_t binom(uint32_t n, uint32_t k) +uint32_t binom (uint32_t n, uint32_t k) { - //GNUNET_assert (n >= k); + // GNUNET_assert (n >= k); if (k > n) return 0; /* if (0 > n) return 0; - always false */ /* if (0 > k) return 0; - always false */ if (0 == k) return 1; - return fac(n) + return fac (n) / - fac(k) * fac(n - k); + fac (k) * fac (n - k); } diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index f978059c3..2f11f0105 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h @@ -32,10 +32,10 @@ char * -auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key); +auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); struct GNUNET_CRYPTO_AuthKey -string_to_auth_key(const char *str); +string_to_auth_key (const char *str); /** @@ -48,7 +48,7 @@ string_to_auth_key(const char *str); * @return File handle */ struct GNUNET_DISK_FileHandle * -get_file_handle(const char *name); +get_file_handle (const char *name); /** * @brief Close all files that were opened with #get_file_handle @@ -56,62 +56,69 @@ get_file_handle(const char *name); * @return Success of iterating over files */ int -close_all_files(); +close_all_files (); /** * This function is used to facilitate writing important information to disk */ #ifdef TO_FILE #define to_file(file_name, ...) do { \ - char tmp_buf[512] = ""; \ - int size; \ - if (NULL == file_name) break; \ - size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ - if (0 > size) \ - { \ - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ - "Failed to create tmp_buf\n"); \ - break; \ - } \ - (void)strncat(tmp_buf, "\n", 512); \ - GNUNET_DISK_file_write(get_file_handle(file_name), \ - tmp_buf, \ - strnlen(tmp_buf, 512)); \ - } while (0); + char tmp_buf[512] = ""; \ + int size; \ + if (NULL == file_name) break; \ + size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ + if (0 > size) \ + { \ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ + "Failed to create tmp_buf\n"); \ + break; \ + } \ + (void) strncat (tmp_buf, "\n", 512); \ + GNUNET_DISK_file_write (get_file_handle (file_name), \ + tmp_buf, \ + strnlen (tmp_buf, 512)); \ +} while (0); #define to_file_w_len(file_name, len, ...) do { char tmp_buf [len]; \ int size; \ - memset(tmp_buf, 0, len); \ - size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ + memset (tmp_buf, 0, len); \ + size = GNUNET_snprintf (tmp_buf, \ + sizeof( \ + tmp_buf), \ + __VA_ARGS__); \ if (0 > size) \ - { \ - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ - "Failed to create tmp_buf\n"); \ - break; \ - } \ - (void)strncat(tmp_buf, "\n", len); \ - GNUNET_DISK_file_write(get_file_handle(file_name), \ - tmp_buf, \ - strnlen(tmp_buf, len)); \ - } while (0); + { \ + GNUNET_log ( \ + GNUNET_ERROR_TYPE_WARNING, \ + "Failed to create tmp_buf\n"); \ + break; \ + } \ + (void) strncat (tmp_buf, "\n", \ + len); \ + GNUNET_DISK_file_write ( \ + get_file_handle (file_name), \ + tmp_buf, \ + strnlen ( \ + tmp_buf, len)); \ +} while (0); #else /* TO_FILE */ # define to_file(file_name, ...) # define to_file_w_len(file_name, len, ...) #endif /* TO_FILE */ char * -store_prefix_file_name(const unsigned int index, - const char *prefix); +store_prefix_file_name (const unsigned int index, + const char *prefix); void -to_file_raw(const char *file_name, const char *buf, size_t size_buf); +to_file_raw (const char *file_name, const char *buf, size_t size_buf); void -to_file_raw_unaligned(const char *file_name, - const char *buf, - size_t size_buf, - unsigned bits_needed); +to_file_raw_unaligned (const char *file_name, + const char *buf, + size_t size_buf, + unsigned bits_needed); /** @@ -121,7 +128,7 @@ to_file_raw_unaligned(const char *file_name, * * @return Factorial of @a x */ -uint32_t fac(uint32_t x); +uint32_t fac (uint32_t x); /** @@ -132,7 +139,7 @@ uint32_t fac(uint32_t x); * * @return Binomial coefficient of @a n and @a k */ -uint32_t binom(uint32_t n, uint32_t k); +uint32_t binom (uint32_t n, uint32_t k); #endif /* RPS_TEST_UTIL_H */ /* end of gnunet-service-rps.c */ diff --git a/src/rps/rps.h b/src/rps/rps.h index dee6162be..32e5d07af 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h @@ -40,7 +40,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * P2P Message to send PeerIDs to other peer. */ -struct GNUNET_RPS_P2P_PullReplyMessage { +struct GNUNET_RPS_P2P_PullReplyMessage +{ /** * Header including size and type in NBO */ @@ -63,7 +64,8 @@ struct GNUNET_RPS_P2P_PullReplyMessage { /** * Message from client to service with seed of peers. */ -struct GNUNET_RPS_CS_SeedMessage { +struct GNUNET_RPS_CS_SeedMessage +{ /** * Header including size and type in NBO */ @@ -81,7 +83,8 @@ struct GNUNET_RPS_CS_SeedMessage { /** * Message from client to service to turn service malicious. */ -struct GNUNET_RPS_CS_ActMaliciousMessage { +struct GNUNET_RPS_CS_ActMaliciousMessage +{ /** * Header including size and type in NBO */ @@ -116,7 +119,8 @@ struct GNUNET_RPS_CS_ActMaliciousMessage { /** * Message from client to service telling it to start a new sub */ -struct GNUNET_RPS_CS_SubStartMessage { +struct GNUNET_RPS_CS_SubStartMessage +{ /** * Header including size and type in NBO */ @@ -142,7 +146,8 @@ struct GNUNET_RPS_CS_SubStartMessage { /** * Message from client to service telling it to stop a new sub */ -struct GNUNET_RPS_CS_SubStopMessage { +struct GNUNET_RPS_CS_SubStopMessage +{ /** * Header including size and type in NBO */ @@ -161,7 +166,8 @@ struct GNUNET_RPS_CS_SubStopMessage { * Message from client to service indicating that * clients wants to get updates of the view */ -struct GNUNET_RPS_CS_DEBUG_ViewRequest { +struct GNUNET_RPS_CS_DEBUG_ViewRequest +{ /** * Header including size and type in NBO */ @@ -177,7 +183,8 @@ struct GNUNET_RPS_CS_DEBUG_ViewRequest { /** * Message from service to client containing current update of view */ -struct GNUNET_RPS_CS_DEBUG_ViewReply { +struct GNUNET_RPS_CS_DEBUG_ViewReply +{ /** * Header including size and type in NBO */ @@ -199,7 +206,8 @@ struct GNUNET_RPS_CS_DEBUG_ViewReply { * Message from client to service indicating that * clients wants to get stream of biased peers */ -struct GNUNET_RPS_CS_DEBUG_StreamRequest { +struct GNUNET_RPS_CS_DEBUG_StreamRequest +{ /** * Header including size and type in NBO */ @@ -209,7 +217,8 @@ struct GNUNET_RPS_CS_DEBUG_StreamRequest { /** * Message from service to client containing peer from biased stream */ -struct GNUNET_RPS_CS_DEBUG_StreamReply { +struct GNUNET_RPS_CS_DEBUG_StreamReply +{ /** * Header including size and type in NBO */ @@ -234,7 +243,8 @@ GNUNET_NETWORK_STRUCT_END /** * Different flags indicating the status of another peer. */ -enum Peers_PeerFlags { +enum Peers_PeerFlags +{ /** * If we are waiting for a reply from that peer (sent a pull request). */ @@ -263,7 +273,8 @@ enum Peers_PeerFlags { * This is needed in order to know what to do with a channel when it's * destroyed. */ -enum Peers_ChannelFlags { +enum Peers_ChannelFlags +{ /** * We destroyed the channel because the other peer established a second one. */ @@ -285,7 +296,8 @@ enum Peers_ChannelFlags { /** * @brief The role of a channel. Sending or receiving. */ -enum Peers_ChannelRole { +enum Peers_ChannelRole +{ /** * Channel is used for sending */ @@ -303,7 +315,7 @@ enum Peers_ChannelRole { * @param cls closure * @param peer peer to execute function on */ -typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); +typedef void (*PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); /** * @brief Iterator over valid peers. @@ -323,4 +335,3 @@ typedef int * Handle to the statistics service. */ extern struct GNUNET_STATISTICS_Handle *stats; - diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 2b54297c3..19cbdcf8a 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c @@ -33,12 +33,13 @@ #include <inttypes.h> -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-api", __VA_ARGS__) /** * Handle for a request to get peers from biased stream of ids */ -struct GNUNET_RPS_StreamRequestHandle { +struct GNUNET_RPS_StreamRequestHandle +{ /** * The client issuing the request. */ @@ -74,7 +75,8 @@ struct GNUNET_RPS_StreamRequestHandle { /** * Handler to handle requests from a client. */ -struct GNUNET_RPS_Handle { +struct GNUNET_RPS_Handle +{ /** * The handle to the client configuration. */ @@ -154,7 +156,8 @@ struct GNUNET_RPS_Handle { /** * Handler for a single request from a client. */ -struct GNUNET_RPS_Request_Handle { +struct GNUNET_RPS_Request_Handle +{ /** * The client issuing the request. */ @@ -206,7 +209,8 @@ struct GNUNET_RPS_Request_Handle { /** * Handler for a single request from a client. */ -struct GNUNET_RPS_Request_Handle_Single_Info { +struct GNUNET_RPS_Request_Handle_Single_Info +{ /** * The client issuing the request. */ @@ -254,7 +258,8 @@ struct GNUNET_RPS_Request_Handle_Single_Info { * Struct used to pack the callback, its closure (provided by the caller) * and the connection handler to the service to pass it to a callback function. */ -struct cb_cls_pack { +struct cb_cls_pack +{ /** * Callback provided by the client */ @@ -296,19 +301,19 @@ static uint64_t srh_callback_num_peers; * @return The handle to the stream request */ static struct GNUNET_RPS_StreamRequestHandle * -new_stream_request(struct GNUNET_RPS_Handle *rps_handle, - GNUNET_RPS_NotifyReadyCB ready_cb, - void *cls) +new_stream_request (struct GNUNET_RPS_Handle *rps_handle, + GNUNET_RPS_NotifyReadyCB ready_cb, + void *cls) { struct GNUNET_RPS_StreamRequestHandle *srh; - srh = GNUNET_new(struct GNUNET_RPS_StreamRequestHandle); + srh = GNUNET_new (struct GNUNET_RPS_StreamRequestHandle); srh->rps_handle = rps_handle; srh->ready_cb = ready_cb; srh->ready_cb_cls = cls; - GNUNET_CONTAINER_DLL_insert(rps_handle->stream_requests_head, - rps_handle->stream_requests_tail, - srh); + GNUNET_CONTAINER_DLL_insert (rps_handle->stream_requests_head, + rps_handle->stream_requests_tail, + srh); return srh; } @@ -320,20 +325,20 @@ new_stream_request(struct GNUNET_RPS_Handle *rps_handle, * @param srh The request to be removed */ static void -remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh) +remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh) { struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle; - GNUNET_assert(NULL != srh); + GNUNET_assert (NULL != srh); if (NULL != srh->callback_task) - { - GNUNET_SCHEDULER_cancel(srh->callback_task); - srh->callback_task = NULL; - } - GNUNET_CONTAINER_DLL_remove(rps_handle->stream_requests_head, - rps_handle->stream_requests_tail, - srh); - GNUNET_free(srh); + { + GNUNET_SCHEDULER_cancel (srh->callback_task); + srh->callback_task = NULL; + } + GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head, + rps_handle->stream_requests_tail, + srh); + GNUNET_free (srh); } @@ -347,17 +352,17 @@ remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh) * @param cls The #GNUNET_RPS_Request_Handle */ static void -peers_ready_cb(const struct GNUNET_PeerIdentity *peers, - uint32_t num_peers, - void *cls) +peers_ready_cb (const struct GNUNET_PeerIdentity *peers, + uint32_t num_peers, + void *cls) { struct GNUNET_RPS_Request_Handle *rh = cls; rh->sampler_rh = NULL; - rh->ready_cb(rh->ready_cb_cls, - num_peers, - peers); - GNUNET_RPS_request_cancel(rh); + rh->ready_cb (rh->ready_cb_cls, + num_peers, + peers); + GNUNET_RPS_request_cancel (rh); } @@ -373,19 +378,19 @@ peers_ready_cb(const struct GNUNET_PeerIdentity *peers, * @param num_observed Number of observed IDs */ static void -peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers, - void *cls, - double probability, - uint32_t num_observed) +peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers, + void *cls, + double probability, + uint32_t num_observed) { struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls; rh->sampler_rh = NULL; - rh->ready_cb(rh->ready_cb_cls, - peers, - probability, - num_observed); - GNUNET_RPS_request_single_info_cancel(rh); + rh->ready_cb (rh->ready_cb_cls, + peers, + probability, + num_observed); + GNUNET_RPS_request_single_info_cancel (rh); } @@ -398,19 +403,19 @@ peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers, * @param peers The array of @a num_peers that have been returned */ static void -collect_peers_cb(void *cls, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *peers) +collect_peers_cb (void *cls, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *peers) { struct GNUNET_RPS_Request_Handle *rh = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service sent %" PRIu64 " peers from stream\n", - num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service sent %" PRIu64 " peers from stream\n", + num_peers); for (uint64_t i = 0; i < num_peers; i++) - { - RPS_sampler_update(rh->sampler, &peers[i]); - } + { + RPS_sampler_update (rh->sampler, &peers[i]); + } } @@ -425,19 +430,19 @@ collect_peers_cb(void *cls, * @param peers The array of @a num_peers that have been returned */ static void -collect_peers_info_cb(void *cls, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *peers) +collect_peers_info_cb (void *cls, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *peers) { struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service sent %" PRIu64 " peers from stream\n", - num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service sent %" PRIu64 " peers from stream\n", + num_peers); for (uint64_t i = 0; i < num_peers; i++) - { - RPS_sampler_update(rhs->sampler, &peers[i]); - } + { + RPS_sampler_update (rhs->sampler, &peers[i]); + } } @@ -453,37 +458,37 @@ collect_peers_info_cb(void *cls, * @param ready_cb the callback called when the peers are available */ void -GNUNET_RPS_view_request(struct GNUNET_RPS_Handle *rps_handle, - uint32_t num_updates, - GNUNET_RPS_NotifyReadyCB view_update_cb, - void *cls) +GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle, + uint32_t num_updates, + GNUNET_RPS_NotifyReadyCB view_update_cb, + void *cls) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client requests %" PRIu32 " view updates\n", - num_updates); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client requests %" PRIu32 " view updates\n", + num_updates); rps_handle->view_update_cb = view_update_cb; rps_handle->view_update_cls = cls; - ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); - msg->num_updates = htonl(num_updates); - GNUNET_MQ_send(rps_handle->mq, ev); + ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); + msg->num_updates = htonl (num_updates); + GNUNET_MQ_send (rps_handle->mq, ev); } void -GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle) +GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle) { struct GNUNET_MQ_Envelope *ev; - GNUNET_assert(NULL != rps_handle->view_update_cb); + GNUNET_assert (NULL != rps_handle->view_update_cb); rps_handle->view_update_cb = NULL; - ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL); - GNUNET_MQ_send(rps_handle->mq, ev); + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL); + GNUNET_MQ_send (rps_handle->mq, ev); } @@ -495,21 +500,21 @@ GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle) * @param ready_cb the callback called when the peers are available */ struct GNUNET_RPS_StreamRequestHandle * -GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle, - GNUNET_RPS_NotifyReadyCB stream_input_cb, - void *cls) +GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle, + GNUNET_RPS_NotifyReadyCB stream_input_cb, + void *cls) { struct GNUNET_RPS_StreamRequestHandle *srh; struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg; - srh = new_stream_request(rps_handle, - stream_input_cb, - cls); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n"); + srh = new_stream_request (rps_handle, + stream_input_cb, + cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n"); - ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST); - GNUNET_MQ_send(rps_handle->mq, ev); + ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST); + GNUNET_MQ_send (rps_handle->mq, ev); return srh; } @@ -523,21 +528,21 @@ GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle, * @return #GNUNET_OK if @a msg is well-formed */ static int -check_view_update(void *cls, - const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) +check_view_update (void *cls, + const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) { - uint16_t msize = ntohs(msg->header.size); - uint32_t num_peers = ntohl(msg->num_peers); + uint16_t msize = ntohs (msg->header.size); + uint32_t num_peers = ntohl (msg->num_peers); - (void)cls; + (void) cls; msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_ViewReply); if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -550,21 +555,21 @@ check_view_update(void *cls, * @param msg the message */ static void -handle_view_update(void *cls, - const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) +handle_view_update (void *cls, + const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) { struct GNUNET_RPS_Handle *h = cls; struct GNUNET_PeerIdentity *peers; /* Give the peers back */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New view of %" PRIu32 " peers:\n", - ntohl(msg->num_peers)); - - peers = (struct GNUNET_PeerIdentity *)&msg[1]; - GNUNET_assert(NULL != h); - GNUNET_assert(NULL != h->view_update_cb); - h->view_update_cb(h->view_update_cls, ntohl(msg->num_peers), peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New view of %" PRIu32 " peers:\n", + ntohl (msg->num_peers)); + + peers = (struct GNUNET_PeerIdentity *) &msg[1]; + GNUNET_assert (NULL != h); + GNUNET_assert (NULL != h->view_update_cb); + h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers); } @@ -575,12 +580,12 @@ handle_view_update(void *cls, * @param rps_handle The handle representing the service to the client */ static void -cancel_stream(struct GNUNET_RPS_Handle *rps_handle) +cancel_stream (struct GNUNET_RPS_Handle *rps_handle) { struct GNUNET_MQ_Envelope *ev; - ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL); - GNUNET_MQ_send(rps_handle->mq, ev); + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL); + GNUNET_MQ_send (rps_handle->mq, ev); } @@ -590,14 +595,14 @@ cancel_stream(struct GNUNET_RPS_Handle *rps_handle) * @param srh The request handle to cancel */ void -GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh) +GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh) { struct GNUNET_RPS_Handle *rps_handle; rps_handle = srh->rps_handle; - remove_stream_request(srh); + remove_stream_request (srh); if (NULL == rps_handle->stream_requests_head) - cancel_stream(rps_handle); + cancel_stream (rps_handle); } @@ -612,21 +617,21 @@ GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh) * @param msg the message */ static int -check_stream_input(void *cls, - const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) +check_stream_input (void *cls, + const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) { - uint16_t msize = ntohs(msg->header.size); - uint32_t num_peers = ntohl(msg->num_peers); + uint16_t msize = ntohs (msg->header.size); + uint32_t num_peers = ntohl (msg->num_peers); - (void)cls; + (void) cls; msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply); if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -637,14 +642,14 @@ check_stream_input(void *cls, * @param cls Stream request handle */ static void -srh_callback_scheduled(void *cls) +srh_callback_scheduled (void *cls) { struct GNUNET_RPS_StreamRequestHandle *srh = cls; srh->callback_task = NULL; - srh->ready_cb(srh->ready_cb_cls, - srh_callback_num_peers, - srh_callback_peers); + srh->ready_cb (srh->ready_cb_cls, + srh_callback_num_peers, + srh_callback_peers); } @@ -657,45 +662,45 @@ srh_callback_scheduled(void *cls) * @param msg the message */ static void -handle_stream_input(void *cls, - const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) +handle_stream_input (void *cls, + const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) { struct GNUNET_RPS_Handle *h = cls; - //const struct GNUNET_PeerIdentity *peers; + // const struct GNUNET_PeerIdentity *peers; uint64_t num_peers; struct GNUNET_RPS_StreamRequestHandle *srh_iter; struct GNUNET_RPS_StreamRequestHandle *srh_next; - //peers = (struct GNUNET_PeerIdentity *) &msg[1]; - num_peers = ntohl(msg->num_peers); + // peers = (struct GNUNET_PeerIdentity *) &msg[1]; + num_peers = ntohl (msg->num_peers); srh_callback_num_peers = num_peers; - GNUNET_free_non_null(srh_callback_peers); - srh_callback_peers = GNUNET_new_array(num_peers, - struct GNUNET_PeerIdentity); - GNUNET_memcpy(srh_callback_peers, - &msg[1], - num_peers * sizeof(struct GNUNET_PeerIdentity)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received %" PRIu64 " peer(s) from stream input.\n", - num_peers); + GNUNET_free_non_null (srh_callback_peers); + srh_callback_peers = GNUNET_new_array (num_peers, + struct GNUNET_PeerIdentity); + GNUNET_memcpy (srh_callback_peers, + &msg[1], + num_peers * sizeof(struct GNUNET_PeerIdentity)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received %" PRIu64 " peer(s) from stream input.\n", + num_peers); for (srh_iter = h->stream_requests_head; NULL != srh_iter; srh_iter = srh_next) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); - /* Store next pointer - srh might be removed/freed in callback */ - srh_next = srh_iter->next; - if (NULL != srh_iter->callback_task) - GNUNET_SCHEDULER_cancel(srh_iter->callback_task); - srh_iter->callback_task = - GNUNET_SCHEDULER_add_now(&srh_callback_scheduled, - srh_iter); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); + /* Store next pointer - srh might be removed/freed in callback */ + srh_next = srh_iter->next; + if (NULL != srh_iter->callback_task) + GNUNET_SCHEDULER_cancel (srh_iter->callback_task); + srh_iter->callback_task = + GNUNET_SCHEDULER_add_now (&srh_callback_scheduled, + srh_iter); + } if (NULL == h->stream_requests_head) - { - cancel_stream(h); - } + { + cancel_stream (h); + } } @@ -703,7 +708,7 @@ handle_stream_input(void *cls, * Reconnect to the service */ static void -reconnect(struct GNUNET_RPS_Handle *h); +reconnect (struct GNUNET_RPS_Handle *h); /** @@ -716,19 +721,20 @@ reconnect(struct GNUNET_RPS_Handle *h); * @param error error code without specyfied meaning */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_RPS_Handle *h = cls; - //TODO LOG - LOG(GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\ + // TODO LOG + LOG (GNUNET_ERROR_TYPE_WARNING, + "Problem with message queue. error: %i\n\ 1: READ,\n\ 2: WRITE,\n\ 4: TIMEOUT\n", - // TODO: write GNUNET_MQ_strerror (error) - error); - reconnect(h); + // TODO: write GNUNET_MQ_strerror (error) + error); + reconnect (h); /* Resend all pending request as the service destroyed its knowledge * about them */ } @@ -742,16 +748,16 @@ mq_error_handler(void *cls, * @param hash[out] Pointer to the location in which the hash will be stored. */ static void -hash_from_share_val(const char *share_val, - struct GNUNET_HashCode *hash) +hash_from_share_val (const char *share_val, + struct GNUNET_HashCode *hash) { - GNUNET_CRYPTO_kdf(hash, - sizeof(struct GNUNET_HashCode), - "rps", - strlen("rps"), - share_val, - strlen(share_val), - NULL, 0); + GNUNET_CRYPTO_kdf (hash, + sizeof(struct GNUNET_HashCode), + "rps", + strlen ("rps"), + share_val, + strlen (share_val), + NULL, 0); } @@ -767,30 +773,32 @@ hash_from_share_val(const char *share_val, * @param std_dev the standard distribution */ static void -nse_cb(void *cls, - struct GNUNET_TIME_Absolute timestamp, - double logestimate, - double std_dev) +nse_cb (void *cls, + struct GNUNET_TIME_Absolute timestamp, + double logestimate, + double std_dev) { struct GNUNET_RPS_Handle *h = cls; - (void)timestamp; - (void)std_dev; + (void) timestamp; + (void) std_dev; for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; NULL != rh_iter && NULL != rh_iter->next; rh_iter = rh_iter->next) - { - RPS_sampler_update_with_nw_size(rh_iter->sampler, - GNUNET_NSE_log_estimate_to_n(logestimate)); - } + { + RPS_sampler_update_with_nw_size (rh_iter->sampler, + GNUNET_NSE_log_estimate_to_n ( + logestimate)); + } for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; NULL != rhs_iter && NULL != rhs_iter->next; rhs_iter = rhs_iter->next) - { - RPS_sampler_update_with_nw_size(rhs_iter->sampler, - GNUNET_NSE_log_estimate_to_n(logestimate)); - } + { + RPS_sampler_update_with_nw_size (rhs_iter->sampler, + GNUNET_NSE_log_estimate_to_n ( + logestimate)); + } } @@ -798,30 +806,30 @@ nse_cb(void *cls, * Reconnect to the service */ static void -reconnect(struct GNUNET_RPS_Handle *h) +reconnect (struct GNUNET_RPS_Handle *h) { struct GNUNET_MQ_MessageHandler mq_handlers[] = { - GNUNET_MQ_hd_var_size(view_update, - GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, - struct GNUNET_RPS_CS_DEBUG_ViewReply, - h), - GNUNET_MQ_hd_var_size(stream_input, - GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, - struct GNUNET_RPS_CS_DEBUG_StreamReply, - h), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_var_size (view_update, + GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, + struct GNUNET_RPS_CS_DEBUG_ViewReply, + h), + GNUNET_MQ_hd_var_size (stream_input, + GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, + struct GNUNET_RPS_CS_DEBUG_StreamReply, + h), + GNUNET_MQ_handler_end () }; if (NULL != h->mq) - GNUNET_MQ_destroy(h->mq); - h->mq = GNUNET_CLIENT_connect(h->cfg, - "rps", - mq_handlers, - &mq_error_handler, - h); + GNUNET_MQ_destroy (h->mq); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "rps", + mq_handlers, + &mq_error_handler, + h); if (NULL != h->nse) - GNUNET_NSE_disconnect(h->nse); - h->nse = GNUNET_NSE_connect(h->cfg, &nse_cb, h); + GNUNET_NSE_disconnect (h->nse); + h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h); } @@ -832,56 +840,56 @@ reconnect(struct GNUNET_RPS_Handle *h) * @return a handle to the service, NULL on error */ struct GNUNET_RPS_Handle * -GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_RPS_Handle *h; - h = GNUNET_new(struct GNUNET_RPS_Handle); + h = GNUNET_new (struct GNUNET_RPS_Handle); h->cfg = cfg; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_float(cfg, - "RPS", - "DESIRED_PROBABILITY", - &h->desired_probability)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "RPS", "DESIRED_PROBABILITY"); - GNUNET_free(h); - return NULL; - } - if (0 > h->desired_probability || - 1 < h->desired_probability) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "The desired probability must be in the interval [0;1]\n"); - GNUNET_free(h); - return NULL; - } + GNUNET_CONFIGURATION_get_value_float (cfg, + "RPS", + "DESIRED_PROBABILITY", + &h->desired_probability)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "RPS", "DESIRED_PROBABILITY"); + GNUNET_free (h); + return NULL; + } + if ((0 > h->desired_probability)|| + (1 < h->desired_probability) ) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "The desired probability must be in the interval [0;1]\n"); + GNUNET_free (h); + return NULL; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_float(cfg, - "RPS", - "DEFICIENCY_FACTOR", - &h->deficiency_factor)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "RPS", "DEFICIENCY_FACTOR"); - GNUNET_free(h); - return NULL; - } - if (0 > h->desired_probability || - 1 < h->desired_probability) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "The deficiency factor must be in the interval [0;1]\n"); - GNUNET_free(h); - return NULL; - } - reconnect(h); + GNUNET_CONFIGURATION_get_value_float (cfg, + "RPS", + "DEFICIENCY_FACTOR", + &h->deficiency_factor)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "RPS", "DEFICIENCY_FACTOR"); + GNUNET_free (h); + return NULL; + } + if ((0 > h->desired_probability)|| + (1 < h->desired_probability) ) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "The deficiency factor must be in the interval [0;1]\n"); + GNUNET_free (h); + return NULL; + } + reconnect (h); if (NULL == h->mq) - { - GNUNET_free(h); - return NULL; - } + { + GNUNET_free (h); + return NULL; + } return h; } @@ -893,19 +901,19 @@ GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) * @param shared_value The shared value that defines the members of the sub (-gorup) */ void -GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, - const char *shared_value) +GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h, + const char *shared_value) { struct GNUNET_RPS_CS_SubStartMessage *msg; struct GNUNET_MQ_Envelope *ev; - ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START); - hash_from_share_val(shared_value, &msg->hash); - msg->round_interval = GNUNET_TIME_relative_hton( // TODO read from config! - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)); - GNUNET_assert(0 != msg->round_interval.rel_value_us__); + ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START); + hash_from_share_val (shared_value, &msg->hash); + msg->round_interval = GNUNET_TIME_relative_hton ( // TODO read from config! + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)); + GNUNET_assert (0 != msg->round_interval.rel_value_us__); - GNUNET_MQ_send(h->mq, ev); + GNUNET_MQ_send (h->mq, ev); } @@ -916,16 +924,16 @@ GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, * @param shared_value The shared value that defines the members of the sub (-gorup) */ void -GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, - const char *shared_value) +GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h, + const char *shared_value) { struct GNUNET_RPS_CS_SubStopMessage *msg; struct GNUNET_MQ_Envelope *ev; - ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP); - hash_from_share_val(shared_value, &msg->hash); + ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP); + hash_from_share_val (shared_value, &msg->hash); - GNUNET_MQ_send(h->mq, ev); + GNUNET_MQ_send (h->mq, ev); } @@ -939,37 +947,37 @@ GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, * @return a handle to cancel this request */ struct GNUNET_RPS_Request_Handle * -GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle, - uint32_t num_req_peers, - GNUNET_RPS_NotifyReadyCB ready_cb, - void *cls) +GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, + uint32_t num_req_peers, + GNUNET_RPS_NotifyReadyCB ready_cb, + void *cls) { struct GNUNET_RPS_Request_Handle *rh; - LOG(GNUNET_ERROR_TYPE_INFO, - "Client requested %" PRIu32 " peers\n", - num_req_peers); - rh = GNUNET_new(struct GNUNET_RPS_Request_Handle); + LOG (GNUNET_ERROR_TYPE_INFO, + "Client requested %" PRIu32 " peers\n", + num_req_peers); + rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); rh->rps_handle = rps_handle; rh->num_requests = num_req_peers; - rh->sampler = RPS_sampler_mod_init(num_req_peers, - GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff - RPS_sampler_set_desired_probability(rh->sampler, - rps_handle->desired_probability); - RPS_sampler_set_deficiency_factor(rh->sampler, - rps_handle->deficiency_factor); - rh->sampler_rh = RPS_sampler_get_n_rand_peers(rh->sampler, - num_req_peers, - peers_ready_cb, - rh); - rh->srh = GNUNET_RPS_stream_request(rps_handle, - collect_peers_cb, - rh); /* cls */ + rh->sampler = RPS_sampler_mod_init (num_req_peers, + GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff + RPS_sampler_set_desired_probability (rh->sampler, + rps_handle->desired_probability); + RPS_sampler_set_deficiency_factor (rh->sampler, + rps_handle->deficiency_factor); + rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler, + num_req_peers, + peers_ready_cb, + rh); + rh->srh = GNUNET_RPS_stream_request (rps_handle, + collect_peers_cb, + rh); /* cls */ rh->ready_cb = ready_cb; rh->ready_cb_cls = cls; - GNUNET_CONTAINER_DLL_insert(rps_handle->rh_head, - rps_handle->rh_tail, - rh); + GNUNET_CONTAINER_DLL_insert (rps_handle->rh_head, + rps_handle->rh_tail, + rh); return rh; } @@ -984,34 +992,34 @@ GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle, * @return a handle to cancel this request */ struct GNUNET_RPS_Request_Handle_Single_Info * -GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle, - GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, - void *cls) +GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle, + GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, + void *cls) { struct GNUNET_RPS_Request_Handle_Single_Info *rhs; uint32_t num_req_peers = 1; - LOG(GNUNET_ERROR_TYPE_INFO, - "Client requested peer with additional info\n"); - rhs = GNUNET_new(struct GNUNET_RPS_Request_Handle_Single_Info); + LOG (GNUNET_ERROR_TYPE_INFO, + "Client requested peer with additional info\n"); + rhs = GNUNET_new (struct GNUNET_RPS_Request_Handle_Single_Info); rhs->rps_handle = rps_handle; - rhs->sampler = RPS_sampler_mod_init(num_req_peers, - GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff - RPS_sampler_set_desired_probability(rhs->sampler, - rps_handle->desired_probability); - RPS_sampler_set_deficiency_factor(rhs->sampler, - rps_handle->deficiency_factor); - rhs->sampler_rh = RPS_sampler_get_rand_peer_info(rhs->sampler, - peer_info_ready_cb, - rhs); - rhs->srh = GNUNET_RPS_stream_request(rps_handle, - collect_peers_info_cb, - rhs); /* cls */ + rhs->sampler = RPS_sampler_mod_init (num_req_peers, + GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff + RPS_sampler_set_desired_probability (rhs->sampler, + rps_handle->desired_probability); + RPS_sampler_set_deficiency_factor (rhs->sampler, + rps_handle->deficiency_factor); + rhs->sampler_rh = RPS_sampler_get_rand_peer_info (rhs->sampler, + peer_info_ready_cb, + rhs); + rhs->srh = GNUNET_RPS_stream_request (rps_handle, + collect_peers_info_cb, + rhs); /* cls */ rhs->ready_cb = ready_cb; rhs->ready_cb_cls = cls; - GNUNET_CONTAINER_DLL_insert(rps_handle->rhs_head, - rps_handle->rhs_tail, - rhs); + GNUNET_CONTAINER_DLL_insert (rps_handle->rhs_head, + rps_handle->rhs_tail, + rhs); return rhs; } @@ -1025,9 +1033,9 @@ GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle, * @param ids the ids of the peers seeded */ void -GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, - uint32_t n, - const struct GNUNET_PeerIdentity *ids) +GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, + uint32_t n, + const struct GNUNET_PeerIdentity *ids) { size_t size_needed; uint32_t num_peers_max; @@ -1035,52 +1043,53 @@ GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_SeedMessage *msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client wants to seed %" PRIu32 " peers:\n", - n); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client wants to seed %" PRIu32 " peers:\n", + n); for (unsigned int i = 0; i < n; i++) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer: %s\n", - i, - GNUNET_i2s(&ids[i])); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer: %s\n", + i, + GNUNET_i2s (&ids[i])); /* The actual size the message occupies */ - size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + - n * sizeof(struct GNUNET_PeerIdentity); + size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + + n * sizeof(struct GNUNET_PeerIdentity); /* The number of peers that fits in one message together with * the respective header */ - num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - - sizeof(struct GNUNET_RPS_CS_SeedMessage)) / - sizeof(struct GNUNET_PeerIdentity); + num_peers_max = (GNUNET_MAX_MESSAGE_SIZE + - sizeof(struct GNUNET_RPS_CS_SeedMessage)) + / sizeof(struct GNUNET_PeerIdentity); tmp_peer_pointer = ids; while (GNUNET_MAX_MESSAGE_SIZE < size_needed) - { - ev = GNUNET_MQ_msg_extra(msg, - num_peers_max * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_CS_SEED); - msg->num_peers = htonl(num_peers_max); - GNUNET_memcpy(&msg[1], - tmp_peer_pointer, - num_peers_max * sizeof(struct GNUNET_PeerIdentity)); - GNUNET_MQ_send(h->mq, - ev); - n -= num_peers_max; - size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + - n * sizeof(struct GNUNET_PeerIdentity); - /* Set pointer to beginning of next block of num_peers_max peers */ - tmp_peer_pointer = &ids[num_peers_max]; - } - - ev = GNUNET_MQ_msg_extra(msg, - n * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_CS_SEED); - msg->num_peers = htonl(n); - GNUNET_memcpy(&msg[1], - tmp_peer_pointer, - n * sizeof(struct GNUNET_PeerIdentity)); - GNUNET_MQ_send(h->mq, - ev); + { + ev = GNUNET_MQ_msg_extra (msg, + num_peers_max * sizeof(struct + GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_CS_SEED); + msg->num_peers = htonl (num_peers_max); + GNUNET_memcpy (&msg[1], + tmp_peer_pointer, + num_peers_max * sizeof(struct GNUNET_PeerIdentity)); + GNUNET_MQ_send (h->mq, + ev); + n -= num_peers_max; + size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + + n * sizeof(struct GNUNET_PeerIdentity); + /* Set pointer to beginning of next block of num_peers_max peers */ + tmp_peer_pointer = &ids[num_peers_max]; + } + + ev = GNUNET_MQ_msg_extra (msg, + n * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_CS_SEED); + msg->num_peers = htonl (n); + GNUNET_memcpy (&msg[1], + tmp_peer_pointer, + n * sizeof(struct GNUNET_PeerIdentity)); + GNUNET_MQ_send (h->mq, + ev); } @@ -1100,11 +1109,11 @@ GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, * peer to be isolated from the rest */ void -GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h, - uint32_t type, - uint32_t num_peers, - const struct GNUNET_PeerIdentity *peer_ids, - const struct GNUNET_PeerIdentity *target_peer) +GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, + uint32_t type, + uint32_t num_peers, + const struct GNUNET_PeerIdentity *peer_ids, + const struct GNUNET_PeerIdentity *target_peer) { size_t size_needed; uint32_t num_peers_max; @@ -1114,65 +1123,68 @@ GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h, unsigned int i; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n", - type, - num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client turns malicious (type %" PRIu32 ") with %" PRIu32 + " other peers:\n", + type, + num_peers); for (i = 0; i < num_peers; i++) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer: %s\n", - i, - GNUNET_i2s(&peer_ids[i])); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer: %s\n", + i, + GNUNET_i2s (&peer_ids[i])); /* The actual size the message would occupy */ - size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + - num_peers * sizeof(struct GNUNET_PeerIdentity); + size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + + num_peers * sizeof(struct GNUNET_PeerIdentity); /* The number of peers that fit in one message together with * the respective header */ - num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - - sizeof(struct GNUNET_RPS_CS_SeedMessage)) / - sizeof(struct GNUNET_PeerIdentity); + num_peers_max = (GNUNET_MAX_MESSAGE_SIZE + - sizeof(struct GNUNET_RPS_CS_SeedMessage)) + / sizeof(struct GNUNET_PeerIdentity); tmp_peer_pointer = peer_ids; while (GNUNET_MAX_MESSAGE_SIZE < size_needed) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n", - num_peers_max); - ev = GNUNET_MQ_msg_extra(msg, - num_peers_max * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); - msg->type = htonl(type); - msg->num_peers = htonl(num_peers_max); - if ((2 == type) || - (3 == type)) - msg->attacked_peer = peer_ids[num_peers]; - GNUNET_memcpy(&msg[1], - tmp_peer_pointer, - num_peers_max * sizeof(struct GNUNET_PeerIdentity)); - - GNUNET_MQ_send(h->mq, ev); - - num_peers -= num_peers_max; - size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + - num_peers * sizeof(struct GNUNET_PeerIdentity); - /* Set pointer to beginning of next block of num_peers_max peers */ - tmp_peer_pointer = &peer_ids[num_peers_max]; - } - - ev = GNUNET_MQ_msg_extra(msg, - num_peers * sizeof(struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); - msg->type = htonl(type); - msg->num_peers = htonl(num_peers); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Too many peers to send at once, sending %" PRIu32 + " (all we can so far)\n", + num_peers_max); + ev = GNUNET_MQ_msg_extra (msg, + num_peers_max * sizeof(struct + GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); + msg->type = htonl (type); + msg->num_peers = htonl (num_peers_max); + if ((2 == type) || + (3 == type)) + msg->attacked_peer = peer_ids[num_peers]; + GNUNET_memcpy (&msg[1], + tmp_peer_pointer, + num_peers_max * sizeof(struct GNUNET_PeerIdentity)); + + GNUNET_MQ_send (h->mq, ev); + + num_peers -= num_peers_max; + size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + + num_peers * sizeof(struct GNUNET_PeerIdentity); + /* Set pointer to beginning of next block of num_peers_max peers */ + tmp_peer_pointer = &peer_ids[num_peers_max]; + } + + ev = GNUNET_MQ_msg_extra (msg, + num_peers * sizeof(struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); + msg->type = htonl (type); + msg->num_peers = htonl (num_peers); if ((2 == type) || (3 == type)) msg->attacked_peer = *target_peer; - GNUNET_memcpy(&msg[1], - tmp_peer_pointer, - num_peers * sizeof(struct GNUNET_PeerIdentity)); + GNUNET_memcpy (&msg[1], + tmp_peer_pointer, + num_peers * sizeof(struct GNUNET_PeerIdentity)); - GNUNET_MQ_send(h->mq, ev); + GNUNET_MQ_send (h->mq, ev); } #endif /* ENABLE_MALICIOUS */ @@ -1183,28 +1195,28 @@ GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h, * @param rh request handle of request to cancle */ void -GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh) +GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) { struct GNUNET_RPS_Handle *h; h = rh->rps_handle; - GNUNET_assert(NULL != rh); - GNUNET_assert(NULL != rh->srh); - GNUNET_assert(h == rh->srh->rps_handle); - GNUNET_RPS_stream_cancel(rh->srh); + GNUNET_assert (NULL != rh); + GNUNET_assert (NULL != rh->srh); + GNUNET_assert (h == rh->srh->rps_handle); + GNUNET_RPS_stream_cancel (rh->srh); rh->srh = NULL; if (NULL == h->stream_requests_head) - cancel_stream(h); + cancel_stream (h); if (NULL != rh->sampler_rh) - { - RPS_sampler_request_cancel(rh->sampler_rh); - } - RPS_sampler_destroy(rh->sampler); + { + RPS_sampler_request_cancel (rh->sampler_rh); + } + RPS_sampler_destroy (rh->sampler); rh->sampler = NULL; - GNUNET_CONTAINER_DLL_remove(h->rh_head, - h->rh_tail, - rh); - GNUNET_free(rh); + GNUNET_CONTAINER_DLL_remove (h->rh_head, + h->rh_tail, + rh); + GNUNET_free (rh); } @@ -1214,29 +1226,29 @@ GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh) * @param rhs request handle of request to cancle */ void -GNUNET_RPS_request_single_info_cancel( +GNUNET_RPS_request_single_info_cancel ( struct GNUNET_RPS_Request_Handle_Single_Info *rhs) { struct GNUNET_RPS_Handle *h; h = rhs->rps_handle; - GNUNET_assert(NULL != rhs); - GNUNET_assert(NULL != rhs->srh); - GNUNET_assert(h == rhs->srh->rps_handle); - GNUNET_RPS_stream_cancel(rhs->srh); + GNUNET_assert (NULL != rhs); + GNUNET_assert (NULL != rhs->srh); + GNUNET_assert (h == rhs->srh->rps_handle); + GNUNET_RPS_stream_cancel (rhs->srh); rhs->srh = NULL; if (NULL == h->stream_requests_head) - cancel_stream(h); + cancel_stream (h); if (NULL != rhs->sampler_rh) - { - RPS_sampler_request_single_info_cancel(rhs->sampler_rh); - } - RPS_sampler_destroy(rhs->sampler); + { + RPS_sampler_request_single_info_cancel (rhs->sampler_rh); + } + RPS_sampler_destroy (rhs->sampler); rhs->sampler = NULL; - GNUNET_CONTAINER_DLL_remove(h->rhs_head, - h->rhs_tail, - rhs); - GNUNET_free(rhs); + GNUNET_CONTAINER_DLL_remove (h->rhs_head, + h->rhs_tail, + rhs); + GNUNET_free (rhs); } @@ -1246,59 +1258,60 @@ GNUNET_RPS_request_single_info_cancel( * @param h the handle to the rps service */ void -GNUNET_RPS_disconnect(struct GNUNET_RPS_Handle *h) +GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) { if (NULL != h->stream_requests_head) + { + struct GNUNET_RPS_StreamRequestHandle *srh_next; + + LOG (GNUNET_ERROR_TYPE_WARNING, + "Still waiting for replies\n"); + for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = + h->stream_requests_head; + NULL != srh_iter; + srh_iter = srh_next) { - struct GNUNET_RPS_StreamRequestHandle *srh_next; - - LOG(GNUNET_ERROR_TYPE_WARNING, - "Still waiting for replies\n"); - for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head; - NULL != srh_iter; - srh_iter = srh_next) - { - srh_next = srh_iter->next; - GNUNET_RPS_stream_cancel(srh_iter); - } + srh_next = srh_iter->next; + GNUNET_RPS_stream_cancel (srh_iter); } + } if (NULL != h->rh_head) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not all requests were cancelled!\n"); + for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; + h->rh_head != NULL; + rh_iter = h->rh_head) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not all requests were cancelled!\n"); - for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; - h->rh_head != NULL; - rh_iter = h->rh_head) - { - GNUNET_RPS_request_cancel(rh_iter); - } + GNUNET_RPS_request_cancel (rh_iter); } + } if (NULL != h->rhs_head) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not all requests were cancelled!\n"); + for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; + h->rhs_head != NULL; + rhs_iter = h->rhs_head) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not all requests were cancelled!\n"); - for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; - h->rhs_head != NULL; - rhs_iter = h->rhs_head) - { - GNUNET_RPS_request_single_info_cancel(rhs_iter); - } + GNUNET_RPS_request_single_info_cancel (rhs_iter); } + } if (NULL != srh_callback_peers) - { - GNUNET_free(srh_callback_peers); - srh_callback_peers = NULL; - } + { + GNUNET_free (srh_callback_peers); + srh_callback_peers = NULL; + } if (NULL != h->view_update_cb) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Still waiting for view updates\n"); - GNUNET_RPS_view_request_cancel(h); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Still waiting for view updates\n"); + GNUNET_RPS_view_request_cancel (h); + } if (NULL != h->nse) - GNUNET_NSE_disconnect(h->nse); - GNUNET_MQ_destroy(h->mq); - GNUNET_free(h); + GNUNET_NSE_disconnect (h->nse); + GNUNET_MQ_destroy (h->mq); + GNUNET_free (h); } diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 6bbb4c6ac..3a01e73ff 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -49,7 +49,7 @@ static uint32_t timeout_s; /** * How long do we run the test? */ -//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) +// #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TIME_Relative timeout; @@ -71,7 +71,8 @@ static struct GNUNET_TESTBED_Peer **testbed_peers; /** * @brief Indicates whether peer should go off- or online */ -enum PEER_ONLINE_DELTA { +enum PEER_ONLINE_DELTA +{ /** * @brief Indicates peer going online */ @@ -85,7 +86,8 @@ enum PEER_ONLINE_DELTA { /** * Operation map entry */ -struct OpListEntry { +struct OpListEntry +{ /** * DLL next ptr */ @@ -127,7 +129,8 @@ static struct OpListEntry *oplist_tail; /** * A pending reply: A request was sent and the reply is pending. */ -struct PendingReply { +struct PendingReply +{ /** * DLL next,prev ptr */ @@ -149,7 +152,8 @@ struct PendingReply { /** * A pending request: A request was not made yet but is scheduled for later. */ -struct PendingRequest { +struct PendingRequest +{ /** * DLL next,prev ptr */ @@ -171,7 +175,8 @@ struct PendingRequest { /** * Information we track for each peer. */ -struct RPSPeer { +struct RPSPeer +{ /** * Index of the peer. */ @@ -200,7 +205,7 @@ struct RPSPeer { /** * A request handle to check for an request */ - //struct GNUNET_RPS_Request_Handle *req_handle; + // struct GNUNET_RPS_Request_Handle *req_handle; /** * Peer on- or offline? @@ -307,7 +312,8 @@ struct RPSPeer { uint64_t num_recv_pull_rep; }; -enum STAT_TYPE { +enum STAT_TYPE +{ STAT_TYPE_ROUNDS = 0x1, /* 1 */ STAT_TYPE_BLOCKS = 0x2, /* 2 */ STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */ @@ -327,7 +333,8 @@ enum STAT_TYPE { STAT_TYPE_MAX = 0x80000000, /* 32 */ }; -struct STATcls { +struct STATcls +{ struct RPSPeer *rps_peer; enum STAT_TYPE stat_type; }; @@ -432,7 +439,8 @@ typedef int (*EvaluationCallback) (void); /** * @brief Do we have Churn? */ -enum OPTION_CHURN { +enum OPTION_CHURN +{ /** * @brief If we have churn this is set */ @@ -446,7 +454,8 @@ enum OPTION_CHURN { /** * @brief Is it ok to quit the test before the timeout? */ -enum OPTION_QUICK_QUIT { +enum OPTION_QUICK_QUIT +{ /** * @brief It is ok for the test to quit before the timeout triggers */ @@ -461,7 +470,8 @@ enum OPTION_QUICK_QUIT { /** * @brief Do we collect statistics at the end? */ -enum OPTION_COLLECT_STATISTICS { +enum OPTION_COLLECT_STATISTICS +{ /** * @brief We collect statistics at the end */ @@ -476,7 +486,8 @@ enum OPTION_COLLECT_STATISTICS { /** * @brief Do we collect views during run? */ -enum OPTION_COLLECT_VIEW { +enum OPTION_COLLECT_VIEW +{ /** * @brief We collect view during run */ @@ -491,7 +502,8 @@ enum OPTION_COLLECT_VIEW { /** * Structure to define a single test */ -struct SingleTestRun { +struct SingleTestRun +{ /** * Name of the test */ @@ -578,7 +590,7 @@ static int in_shutdown; * Append arguments to file */ static void -tofile_(const char *file_name, const char *line) +tofile_ (const char *file_name, const char *line) { struct GNUNET_DISK_FileHandle *f; /* char output_buffer[512]; */ @@ -586,20 +598,20 @@ tofile_(const char *file_name, const char *line) /* int size; */ size_t size2; - if (NULL == (f = GNUNET_DISK_file_open(file_name, - GNUNET_DISK_OPEN_APPEND | - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ))) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Not able to open file %s\n", - file_name); - return; - } + if (NULL == (f = GNUNET_DISK_file_open (file_name, + GNUNET_DISK_OPEN_APPEND + | GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Not able to open file %s\n", + file_name); + return; + } /* size = GNUNET_snprintf (output_buffer, sizeof (output_buffer), "%llu %s\n", @@ -613,43 +625,43 @@ tofile_(const char *file_name, const char *line) return; } */ - size = strlen(line) * sizeof(char); + size = strlen (line) * sizeof(char); - size2 = GNUNET_DISK_file_write(f, line, size); + size2 = GNUNET_DISK_file_write (f, line, size); if (size != size2) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to write to file! (Size: %lu, size2: %lu)\n", + size, + size2); + if (GNUNET_YES != GNUNET_DISK_file_close (f)) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to write to file! (Size: %lu, size2: %lu)\n", - size, - size2); - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - } - return; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); } + return; + } - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - } + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); + } } /** * This function is used to facilitate writing important information to disk */ #define tofile(file_name, ...) do { \ - char tmp_buf[512]; \ - int size; \ - size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ - if (0 > size) \ + char tmp_buf[512]; \ + int size; \ + size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ + if (0 > size) \ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ "Failed to create tmp_buf\n"); \ - else \ + else \ tofile_ (file_name, tmp_buf); \ - } while (0); +} while (0); /** @@ -676,14 +688,14 @@ tofile_(const char *file_name, const char *line) * Task run on timeout to collect statistics and potentially shut down. */ static void -post_test_op(void *cls); +post_test_op (void *cls); /** * Test the success of a single test */ static int -evaluate(void) +evaluate (void) { unsigned int i; int tmp_ok; @@ -691,16 +703,16 @@ evaluate(void) tmp_ok = 1; for (i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer [%s] received %u of %u expected peer_ids: %i\n", - i, - GNUNET_i2s(rps_peers[i].peer_id), - rps_peers[i].num_recv_ids, - rps_peers[i].num_ids_to_request, - (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); - tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer [%s] received %u of %u expected peer_ids: %i\n", + i, + GNUNET_i2s (rps_peers[i].peer_id), + rps_peers[i].num_recv_ids, + rps_peers[i].num_ids_to_request, + (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); + tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); + } return tmp_ok ? 0 : 1; } @@ -709,12 +721,12 @@ evaluate(void) * Creates an oplist entry and adds it to the oplist DLL */ static struct OpListEntry * -make_oplist_entry() +make_oplist_entry () { struct OpListEntry *entry; - entry = GNUNET_new(struct OpListEntry); - GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); + entry = GNUNET_new (struct OpListEntry); + GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); return entry; } @@ -728,15 +740,15 @@ make_oplist_entry() * @return #GNUNET_YES if so * #GNUNET_NO otherwise */ -static int check_statistics_collect_completed_single_peer( +static int check_statistics_collect_completed_single_peer ( const struct RPSPeer *rps_peer) { if (cur_test_run.stat_collect_flags != - (cur_test_run.stat_collect_flags & - rps_peer->stat_collected_flags)) - { - return GNUNET_NO; - } + (cur_test_run.stat_collect_flags + & rps_peer->stat_collected_flags)) + { + return GNUNET_NO; + } return GNUNET_YES; } @@ -748,22 +760,24 @@ static int check_statistics_collect_completed_single_peer( * @return #GNUNET_YES if so * #GNUNET_NO otherwise */ -static int check_statistics_collect_completed() +static int check_statistics_collect_completed () { uint32_t i; for (i = 0; i < num_peers; i++) - { - if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "At least Peer %" PRIu32 " did not yet receive all statistics values\n", - i); - return GNUNET_NO; - } + { + if (GNUNET_NO == check_statistics_collect_completed_single_peer ( + &rps_peers[i])) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "At least Peer %" PRIu32 + " did not yet receive all statistics values\n", + i); + return GNUNET_NO; } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "All peers received their statistics values\n"); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers received their statistics values\n"); return GNUNET_YES; } @@ -772,36 +786,36 @@ static int check_statistics_collect_completed() * Task run on timeout to shut everything down. */ static void -shutdown_op(void *cls) +shutdown_op (void *cls) { unsigned int i; - (void)cls; + (void) cls; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Shutdown task scheduled, going down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Shutdown task scheduled, going down.\n"); in_shutdown = GNUNET_YES; if (NULL != post_test_task) - { - GNUNET_SCHEDULER_cancel(post_test_task); - post_test_op(NULL); - } + { + GNUNET_SCHEDULER_cancel (post_test_task); + post_test_op (NULL); + } if (NULL != churn_task) + { + GNUNET_SCHEDULER_cancel (churn_task); + churn_task = NULL; + } + for (i = 0; i < num_peers; i++) + { + if (NULL != rps_peers[i].rps_handle) { - GNUNET_SCHEDULER_cancel(churn_task); - churn_task = NULL; + GNUNET_RPS_disconnect (rps_peers[i].rps_handle); } - for (i = 0; i < num_peers; i++) + if (NULL != rps_peers[i].op) { - if (NULL != rps_peers[i].rps_handle) - { - GNUNET_RPS_disconnect(rps_peers[i].rps_handle); - } - if (NULL != rps_peers[i].op) - { - GNUNET_TESTBED_operation_done(rps_peers[i].op); - } + GNUNET_TESTBED_operation_done (rps_peers[i].op); } + } } @@ -809,40 +823,41 @@ shutdown_op(void *cls) * Task run on timeout to collect statistics and potentially shut down. */ static void -post_test_op(void *cls) +post_test_op (void *cls) { unsigned int i; - (void)cls; + (void) cls; post_test_task = NULL; post_test = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Post test task scheduled, going down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Post test task scheduled, going down.\n"); if (NULL != churn_task) - { - GNUNET_SCHEDULER_cancel(churn_task); - churn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (churn_task); + churn_task = NULL; + } for (i = 0; i < num_peers; i++) + { + if (NULL != cur_test_run.post_test) { - if (NULL != cur_test_run.post_test) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); - cur_test_run.post_test(&rps_peers[i]); - } - if (NULL != rps_peers[i].op) - { - GNUNET_TESTBED_operation_done(rps_peers[i].op); - rps_peers[i].op = NULL; - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", + i); + cur_test_run.post_test (&rps_peers[i]); } - /* If we do not collect statistics, shut down directly */ - if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || - GNUNET_YES == check_statistics_collect_completed()) + if (NULL != rps_peers[i].op) { - GNUNET_SCHEDULER_shutdown(); + GNUNET_TESTBED_operation_done (rps_peers[i].op); + rps_peers[i].op = NULL; } + } + /* If we do not collect statistics, shut down directly */ + if ((NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics)|| + (GNUNET_YES == check_statistics_collect_completed ()) ) + { + GNUNET_SCHEDULER_shutdown (); + } } @@ -850,29 +865,29 @@ post_test_op(void *cls) * Seed peers. */ static void -seed_peers(void *cls) +seed_peers (void *cls) { struct RPSPeer *peer = cls; unsigned int amount; unsigned int i; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - GNUNET_assert(NULL != peer->rps_handle); + GNUNET_assert (NULL != peer->rps_handle); // TODO if malicious don't seed mal peers - amount = round(.5 * num_peers); + amount = round (.5 * num_peers); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); for (i = 0; i < amount; i++) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", - i, - GNUNET_i2s(&rps_peer_ids[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", + i, + GNUNET_i2s (&rps_peer_ids[i])); - GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); + GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); } @@ -880,7 +895,7 @@ seed_peers(void *cls) * Seed peers. */ static void -seed_peers_big(void *cls) +seed_peers_big (void *cls) { struct RPSPeer *peer = cls; unsigned int seed_msg_size; @@ -889,73 +904,73 @@ seed_peers_big(void *cls) unsigned int i; seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ - num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) / - sizeof(struct GNUNET_PeerIdentity); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peers that fit in one seed msg; %u\n", - num_peers_max); + num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) + / sizeof(struct GNUNET_PeerIdentity); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peers that fit in one seed msg; %u\n", + num_peers_max); amount = num_peers_max + (0.5 * num_peers_max); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Seeding many (%u) peers:\n", - amount); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Seeding many (%u) peers:\n", + amount); struct GNUNET_PeerIdentity ids_to_seed[amount]; for (i = 0; i < amount; i++) - { - ids_to_seed[i] = *peer->peer_id; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", - i, - GNUNET_i2s(&ids_to_seed[i])); - } + { + ids_to_seed[i] = *peer->peer_id; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", + i, + GNUNET_i2s (&ids_to_seed[i])); + } - GNUNET_RPS_seed_ids(peer->rps_handle, amount, ids_to_seed); + GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed); } /** * Get the id of peer i. */ void -info_cb(void *cb_cls, - struct GNUNET_TESTBED_Operation *op, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) +info_cb (void *cb_cls, + struct GNUNET_TESTBED_Operation *op, + const struct GNUNET_TESTBED_PeerInformation *pinfo, + const char *emsg) { - struct OpListEntry *entry = (struct OpListEntry *)cb_cls; + struct OpListEntry *entry = (struct OpListEntry *) cb_cls; - (void)op; + (void) op; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - if (NULL == pinfo || NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); - GNUNET_TESTBED_operation_done(entry->op); - return; - } + if ((NULL == pinfo)||(NULL != emsg)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); + GNUNET_TESTBED_operation_done (entry->op); + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u is %s\n", - entry->index, - GNUNET_i2s(pinfo->result.id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u is %s\n", + entry->index, + GNUNET_i2s (pinfo->result.id)); rps_peer_ids[entry->index] = *(pinfo->result.id); rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put(peer_map, - &rps_peer_ids[entry->index], - &rps_peers[entry->index], - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - tofile("/tmp/rps/peer_ids", - "%u\t%s\n", - entry->index, - GNUNET_i2s_full(&rps_peer_ids[entry->index])); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put (peer_map, + &rps_peer_ids[entry->index], + &rps_peers[entry->index], + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + tofile ("/tmp/rps/peer_ids", + "%u\t%s\n", + entry->index, + GNUNET_i2s_full (&rps_peer_ids[entry->index])); - GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); - GNUNET_TESTBED_operation_done(entry->op); - GNUNET_free(entry); + GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); + GNUNET_TESTBED_operation_done (entry->op); + GNUNET_free (entry); } @@ -969,39 +984,39 @@ info_cb(void *cb_cls, * operation has executed successfully. */ static void -rps_connect_complete_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +rps_connect_complete_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { struct RPSPeer *rps_peer = cls; struct GNUNET_RPS_Handle *rps = ca_result; - GNUNET_assert(NULL != ca_result); + GNUNET_assert (NULL != ca_result); - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } rps_peer->rps_handle = rps; rps_peer->online = GNUNET_YES; num_peers_online++; - GNUNET_assert(op == rps_peer->op); + GNUNET_assert (op == rps_peer->op); if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to RPS service: %s\n", - emsg); - ok = 1; - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to RPS service: %s\n", + emsg); + ok = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); - cur_test_run.main_test(rps_peer); + cur_test_run.main_test (rps_peer); } @@ -1016,17 +1031,17 @@ rps_connect_complete_cb(void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -rps_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +rps_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_RPS_Handle *h; - h = GNUNET_RPS_connect(cfg); - GNUNET_assert(NULL != h); + h = GNUNET_RPS_connect (cfg); + GNUNET_assert (NULL != h); if (NULL != cur_test_run.pre_test) - cur_test_run.pre_test(cls, h); - GNUNET_assert(NULL != h); + cur_test_run.pre_test (cls, h); + GNUNET_assert (NULL != h); return h; } @@ -1041,12 +1056,12 @@ rps_connect_adapter(void *cls, * @return service handle to return in 'op_result', NULL on error */ static void * -stat_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +stat_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct RPSPeer *peer = cls; - peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); + peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); return peer->stats_h; } @@ -1057,17 +1072,17 @@ stat_connect_adapter(void *cls, * @param op_result service handle returned from the connect adapter */ static void -stat_disconnect_adapter(void *cls, void *op_result) +stat_disconnect_adapter (void *cls, void *op_result) { struct RPSPeer *peer = cls; - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel // (peer->stats_h, "core", "# peers connected", // stat_iterator, peer)); - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel // (peer->stats_h, "nse", "# peers connected", // stat_iterator, peer)); - GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); + GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); peer->stats_h = NULL; } @@ -1082,24 +1097,24 @@ stat_disconnect_adapter(void *cls, void *op_result) * operation has executed successfully. */ static void -stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, - void *ca_result, const char *emsg) +stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, + void *ca_result, const char *emsg) { - //struct GNUNET_STATISTICS_Handle *sh = ca_result; - //struct RPSPeer *peer = (struct RPSPeer *) cls; - (void)cls; - (void)op; - (void)ca_result; + // struct GNUNET_STATISTICS_Handle *sh = ca_result; + // struct RPSPeer *peer = (struct RPSPeer *) cls; + (void) cls; + (void) op; + (void) ca_result; if (NULL != emsg) - { - GNUNET_break(0); - return; - } - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch + { + GNUNET_break (0); + return; + } + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch // (sh, "core", "# peers connected", // stat_iterator, peer)); - //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch + // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch // (sh, "nse", "# peers connected", // stat_iterator, peer)); } @@ -1113,19 +1128,19 @@ stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, * @param op_result service handle returned from the connect adapter */ static void -rps_disconnect_adapter(void *cls, - void *op_result) +rps_disconnect_adapter (void *cls, + void *op_result) { struct RPSPeer *peer = cls; struct GNUNET_RPS_Handle *h = op_result; if (NULL != peer->rps_srh) - { - GNUNET_RPS_stream_cancel(peer->rps_srh); - peer->rps_srh = NULL; - } - GNUNET_assert(NULL != peer); - GNUNET_RPS_disconnect(h); + { + GNUNET_RPS_stream_cancel (peer->rps_srh); + peer->rps_srh = NULL; + } + GNUNET_assert (NULL != peer); + GNUNET_RPS_disconnect (h); peer->rps_handle = NULL; } @@ -1136,13 +1151,13 @@ rps_disconnect_adapter(void *cls, // TODO check whether tests can be stopped earlier static int -default_eval_cb(void) +default_eval_cb (void) { - return evaluate(); + return evaluate (); } static int -no_eval(void) +no_eval (void) { return 0; } @@ -1150,7 +1165,7 @@ no_eval(void) /** * Initialise given RPSPeer */ -static void default_init_peer(struct RPSPeer *rps_peer) +static void default_init_peer (struct RPSPeer *rps_peer) { rps_peer->num_ids_to_request = 1; } @@ -1163,122 +1178,122 @@ static void default_init_peer(struct RPSPeer *rps_peer) * @param recv_peers the received peers */ static void -default_reply_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +default_reply_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { struct RPSPeer *rps_peer; - struct PendingReply *pending_rep = (struct PendingReply *)cls; + struct PendingReply *pending_rep = (struct PendingReply *) cls; unsigned int i; rps_peer = pending_rep->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "[%s] got %" PRIu64 " peers:\n", - GNUNET_i2s(rps_peer->peer_id), - n); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "[%s] got %" PRIu64 " peers:\n", + GNUNET_i2s (rps_peer->peer_id), + n); for (i = 0; i < n; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u: %s\n", - i, - GNUNET_i2s(&recv_peers[i])); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u: %s\n", + i, + GNUNET_i2s (&recv_peers[i])); - rps_peer->num_recv_ids++; - } + rps_peer->num_recv_ids++; + } - if (0 == evaluate() && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); - GNUNET_assert(NULL != post_test_task); - GNUNET_SCHEDULER_cancel(post_test_task); - post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); - GNUNET_assert(NULL != post_test_task); - } + if ((0 == evaluate ())&&(HAVE_QUICK_QUIT == cur_test_run.have_quick_quit)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); + GNUNET_assert (NULL != post_test_task); + GNUNET_SCHEDULER_cancel (post_test_task); + post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); + GNUNET_assert (NULL != post_test_task); + } } /** * Request random peers. */ static void -request_peers(void *cls) +request_peers (void *cls) { struct PendingRequest *pending_req = cls; struct RPSPeer *rps_peer; struct PendingReply *pending_rep; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) return; rps_peer = pending_req->rps_peer; - GNUNET_assert(1 <= rps_peer->num_pending_reqs); - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting one peer\n"); - pending_rep = GNUNET_new(struct PendingReply); + GNUNET_assert (1 <= rps_peer->num_pending_reqs); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting one peer\n"); + pending_rep = GNUNET_new (struct PendingReply); pending_rep->rps_peer = rps_peer; - pending_rep->req_handle = GNUNET_RPS_request_peers(rps_peer->rps_handle, - 1, - cur_test_run.reply_handle, - pending_rep); - GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, + 1, + cur_test_run.reply_handle, + pending_rep); + GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps++; rps_peer->num_pending_reqs--; } static void -cancel_pending_req(struct PendingRequest *pending_req) +cancel_pending_req (struct PendingRequest *pending_req) { struct RPSPeer *rps_peer; rps_peer = pending_req->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); rps_peer->num_pending_reqs--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling pending request\n"); - GNUNET_SCHEDULER_cancel(pending_req->request_task); - GNUNET_free(pending_req); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling pending request\n"); + GNUNET_SCHEDULER_cancel (pending_req->request_task); + GNUNET_free (pending_req); } static void -cancel_request(struct PendingReply *pending_rep) +cancel_request (struct PendingReply *pending_rep) { struct RPSPeer *rps_peer; rps_peer = pending_rep->rps_peer; - GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, - rps_peer->pending_rep_tail, - pending_rep); + GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, + rps_peer->pending_rep_tail, + pending_rep); rps_peer->num_pending_reps--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling request\n"); - GNUNET_RPS_request_cancel(pending_rep->req_handle); - GNUNET_free(pending_rep); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling request\n"); + GNUNET_RPS_request_cancel (pending_rep->req_handle); + GNUNET_free (pending_rep); } /** * Cancel a request. */ static void -cancel_request_cb(void *cls) +cancel_request_cb (void *cls) { struct RPSPeer *rps_peer = cls; struct PendingReply *pending_rep; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) return; pending_rep = rps_peer->pending_rep_head; - GNUNET_assert(1 <= rps_peer->num_pending_reps); - cancel_request(pending_rep); + GNUNET_assert (1 <= rps_peer->num_pending_reps); + cancel_request (pending_rep); } @@ -1287,45 +1302,45 @@ cancel_request_cb(void *cls) * issued, nor replied */ void -schedule_missing_requests(struct RPSPeer *rps_peer) +schedule_missing_requests (struct RPSPeer *rps_peer) { unsigned int i; struct PendingRequest *pending_req; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling %u - %u missing requests\n", - rps_peer->num_ids_to_request, - rps_peer->num_pending_reqs + rps_peer->num_pending_reps); - GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= - rps_peer->num_ids_to_request); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling %u - %u missing requests\n", + rps_peer->num_ids_to_request, + rps_peer->num_pending_reqs + rps_peer->num_pending_reps); + GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= + rps_peer->num_ids_to_request); for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; i < rps_peer->num_ids_to_request; i++) - { - pending_req = GNUNET_new(struct PendingRequest); - pending_req->rps_peer = rps_peer; - pending_req->request_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - cur_test_run.request_interval * i), - request_peers, - pending_req); - GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, - rps_peer->pending_req_tail, - pending_req); - rps_peer->num_pending_reqs++; - } + { + pending_req = GNUNET_new (struct PendingRequest); + pending_req->rps_peer = rps_peer; + pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + cur_test_run.request_interval * i), + request_peers, + pending_req); + GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, + rps_peer->pending_req_tail, + pending_req); + rps_peer->num_pending_reqs++; + } } void -cancel_pending_req_rep(struct RPSPeer *rps_peer) +cancel_pending_req_rep (struct RPSPeer *rps_peer) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cancelling all (pending) requests.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cancelling all (pending) requests.\n"); while (NULL != rps_peer->pending_req_head) - cancel_pending_req(rps_peer->pending_req_head); - GNUNET_assert(0 == rps_peer->num_pending_reqs); + cancel_pending_req (rps_peer->pending_req_head); + GNUNET_assert (0 == rps_peer->num_pending_reqs); while (NULL != rps_peer->pending_rep_head) - cancel_request(rps_peer->pending_rep_head); - GNUNET_assert(0 == rps_peer->num_pending_reps); + cancel_request (rps_peer->pending_rep_head); + GNUNET_assert (0 == rps_peer->num_pending_reps); } /*********************************** @@ -1335,9 +1350,9 @@ cancel_pending_req_rep(struct RPSPeer *rps_peer) /** * Initialise only non-mal RPSPeers */ -static void mal_init_peer(struct RPSPeer *rps_peer) +static void mal_init_peer (struct RPSPeer *rps_peer) { - if (rps_peer->index >= round(portion * num_peers)) + if (rps_peer->index >= round (portion * num_peers)) rps_peer->num_ids_to_request = 1; } @@ -1351,51 +1366,53 @@ static void mal_init_peer(struct RPSPeer *rps_peer) * @param h the handle to the service */ static void -mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) +mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) { #if ENABLE_MALICIOUS uint32_t num_mal_peers; - GNUNET_assert((1 >= portion) && - (0 < portion)); - num_mal_peers = round(portion * num_peers); + GNUNET_assert ((1 >= portion) && + (0 < portion)); + num_mal_peers = round (portion * num_peers); if (rps_peer->index < num_mal_peers) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", - rps_peer->index, - GNUNET_i2s(rps_peer->peer_id), - num_mal_peers); - - GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, - rps_peer_ids, target_peer); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer [%s] of %" PRIu32 + " malicious peers turning malicious\n", + rps_peer->index, + GNUNET_i2s (rps_peer->peer_id), + num_mal_peers); + + GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, + rps_peer_ids, target_peer); + } #endif /* ENABLE_MALICIOUS */ } static void -mal_cb(struct RPSPeer *rps_peer) +mal_cb (struct RPSPeer *rps_peer) { uint32_t num_mal_peers; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } #if ENABLE_MALICIOUS - GNUNET_assert((1 >= portion) && - (0 < portion)); - num_mal_peers = round(portion * num_peers); + GNUNET_assert ((1 >= portion) && + (0 < portion)); + num_mal_peers = round (portion * num_peers); if (rps_peer->index >= num_mal_peers) - { /* It's useless to ask a malicious peer about a random sample - + { /* It's useless to ask a malicious peer about a random sample - it's not sampling */ - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), - seed_peers, rps_peer); - schedule_missing_requests(rps_peer); - } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, 2), + seed_peers, rps_peer); + schedule_missing_requests (rps_peer); + } #endif /* ENABLE_MALICIOUS */ } @@ -1404,43 +1421,43 @@ mal_cb(struct RPSPeer *rps_peer) * SINGLE_REQUEST ***********************************/ static void -single_req_cb(struct RPSPeer *rps_peer) +single_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /*********************************** * DELAYED_REQUESTS ***********************************/ static void -delay_req_cb(struct RPSPeer *rps_peer) +delay_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /*********************************** * SEED ***********************************/ static void -seed_cb(struct RPSPeer *rps_peer) +seed_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), seed_peers, rps_peer); } @@ -1448,16 +1465,16 @@ seed_cb(struct RPSPeer *rps_peer) * SEED_BIG ***********************************/ static void -seed_big_cb(struct RPSPeer *rps_peer) +seed_big_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), seed_peers_big, rps_peer); } @@ -1465,9 +1482,9 @@ seed_big_cb(struct RPSPeer *rps_peer) * SINGLE_PEER_SEED ***********************************/ static void -single_peer_seed_cb(struct RPSPeer *rps_peer) +single_peer_seed_cb (struct RPSPeer *rps_peer) { - (void)rps_peer; + (void) rps_peer; // TODO } @@ -1475,36 +1492,36 @@ single_peer_seed_cb(struct RPSPeer *rps_peer) * SEED_REQUEST ***********************************/ static void -seed_req_cb(struct RPSPeer *rps_peer) +seed_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), seed_peers, rps_peer); - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } -//TODO start big mal +// TODO start big mal /*********************************** * REQUEST_CANCEL ***********************************/ static void -req_cancel_cb(struct RPSPeer *rps_peer) +req_cancel_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - schedule_missing_requests(rps_peer); - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - (cur_test_run.request_interval + 1)), + schedule_missing_requests (rps_peer); + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + (cur_test_run.request_interval + 1)), cancel_request_cb, rps_peer); } @@ -1513,7 +1530,7 @@ req_cancel_cb(struct RPSPeer *rps_peer) ***********************************/ static void -churn(void *cls); +churn (void *cls); /** * @brief Starts churn @@ -1527,30 +1544,30 @@ churn(void *cls); * @param rps_peer The peer it's called for */ static void -churn_test_cb(struct RPSPeer *rps_peer) +churn_test_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } /* Start churn */ - if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting churn task\n"); - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - churn, - NULL); - } + if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting churn task\n"); + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + churn, + NULL); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Not starting churn task\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Not starting churn task\n"); + } - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /*********************************** @@ -1558,60 +1575,62 @@ churn_test_cb(struct RPSPeer *rps_peer) ***********************************/ static void -got_stream_peer_cb(void *cls, - uint64_t num_peers, - const struct GNUNET_PeerIdentity *peers) +got_stream_peer_cb (void *cls, + uint64_t num_peers, + const struct GNUNET_PeerIdentity *peers) { const struct RPSPeer *rps_peer = cls; for (uint64_t i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %" PRIu32 " received [%s] from stream.\n", - rps_peer->index, - GNUNET_i2s(&peers[i])); - if (0 != rps_peer->index && - 0 == memcmp(&peers[i], + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %" PRIu32 " received [%s] from stream.\n", + rps_peer->index, + GNUNET_i2s (&peers[i])); + if ((0 != rps_peer->index) && + (0 == memcmp (&peers[i], &rps_peers[0].peer_id, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n"); - ok = 1; - } - else if (0 == rps_peer->index && - 0 != memcmp(&peers[i], + sizeof(struct GNUNET_PeerIdentity)))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received a peer id outside sub\n"); + ok = 1; + } + else if ((0 == rps_peer->index) && + (0 != memcmp (&peers[i], &rps_peers[0].peer_id, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n"); - ok = 1; - } + sizeof(struct GNUNET_PeerIdentity)))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received a peer id outside sub (lonely)\n"); + ok = 1; } + } } static void -sub_post(struct RPSPeer *rps_peer) +sub_post (struct RPSPeer *rps_peer) { if (0 != rps_peer->index) - GNUNET_RPS_sub_stop(rps_peer->rps_handle, "test"); + GNUNET_RPS_sub_stop (rps_peer->rps_handle, "test"); else - GNUNET_RPS_sub_stop(rps_peer->rps_handle, "lonely"); + GNUNET_RPS_sub_stop (rps_peer->rps_handle, "lonely"); } static void -sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) +sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) { - (void)rps_peer; + (void) rps_peer; if (0 != rps_peer->index) - GNUNET_RPS_sub_start(h, "test"); + GNUNET_RPS_sub_start (h, "test"); else - GNUNET_RPS_sub_start(h, "lonely"); /* have a group of one */ - rps_peer->rps_srh = GNUNET_RPS_stream_request(h, - &got_stream_peer_cb, - rps_peer); + GNUNET_RPS_sub_start (h, "lonely"); /* have a group of one */ + rps_peer->rps_srh = GNUNET_RPS_stream_request (h, + &got_stream_peer_cb, + rps_peer); } /*********************************** @@ -1626,82 +1645,83 @@ sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) * @param emsg NULL on success; otherwise an error description */ static void -churn_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +churn_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { - (void)op; + (void) op; // FIXME struct OpListEntry *entry = cls; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } - GNUNET_TESTBED_operation_done(entry->op); + GNUNET_TESTBED_operation_done (entry->op); if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_assert(0 != entry->delta); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to start/stop RPS at a peer\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (0 != entry->delta); num_peers_online += entry->delta; if (PEER_GO_OFFLINE == entry->delta) - { /* Peer hopefully just went offline */ - if (GNUNET_YES != rps_peers[entry->index].online) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "peer %s was expected to go offline but is still marked as online\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - GNUNET_break(0); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "peer %s probably went offline as expected\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - } - rps_peers[entry->index].online = GNUNET_NO; + { /* Peer hopefully just went offline */ + if (GNUNET_YES != rps_peers[entry->index].online) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "peer %s was expected to go offline but is still marked as online\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + GNUNET_break (0); } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "peer %s probably went offline as expected\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + } + rps_peers[entry->index].online = GNUNET_NO; + } else if (PEER_GO_ONLINE < entry->delta) - { /* Peer hopefully just went online */ - if (GNUNET_NO != rps_peers[entry->index].online) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "peer %s was expected to go online but is still marked as offline\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - GNUNET_break(0); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "peer %s probably went online as expected\n", - GNUNET_i2s(rps_peers[entry->index].peer_id)); - if (NULL != cur_test_run.pre_test) - { - cur_test_run.pre_test(&rps_peers[entry->index], - rps_peers[entry->index].rps_handle); - schedule_missing_requests(&rps_peers[entry->index]); - } - } - rps_peers[entry->index].online = GNUNET_YES; - } + { /* Peer hopefully just went online */ + if (GNUNET_NO != rps_peers[entry->index].online) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "peer %s was expected to go online but is still marked as offline\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + GNUNET_break (0); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "peer %s probably went online as expected\n", + GNUNET_i2s (rps_peers[entry->index].peer_id)); + if (NULL != cur_test_run.pre_test) + { + cur_test_run.pre_test (&rps_peers[entry->index], + rps_peers[entry->index].rps_handle); + schedule_missing_requests (&rps_peers[entry->index]); + } + } + rps_peers[entry->index].online = GNUNET_YES; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Invalid value for delta: %i\n", entry->delta); - GNUNET_break(0); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid value for delta: %i\n", entry->delta); + GNUNET_break (0); + } - GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); + GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); rps_peers[entry->index].entry_op_manage = NULL; - GNUNET_free(entry); - //if (num_peers_in_round[current_round] == peers_running) + GNUNET_free (entry); + // if (num_peers_in_round[current_round] == peers_running) // run_round (); } @@ -1714,54 +1734,55 @@ churn_cb(void *cls, * @param prob_go_on_off the probability of the action */ static void -manage_service_wrapper(unsigned int i, unsigned int j, - enum PEER_ONLINE_DELTA delta, - double prob_go_on_off) +manage_service_wrapper (unsigned int i, unsigned int j, + enum PEER_ONLINE_DELTA delta, + double prob_go_on_off) { struct OpListEntry *entry = NULL; uint32_t prob; /* make sure that management operation is not already scheduled */ if (NULL != rps_peers[j].entry_op_manage) - { - return; - } + { + return; + } - prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u. selected peer (%u: %s) is %s.\n", - i, - j, - GNUNET_i2s(rps_peers[j].peer_id), - (PEER_GO_ONLINE == delta) ? "online" : "offline"); + prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. selected peer (%u: %s) is %s.\n", + i, + j, + GNUNET_i2s (rps_peers[j].peer_id), + (PEER_GO_ONLINE == delta) ? "online" : "offline"); if (prob < prob_go_on_off * UINT32_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s goes %s\n", - GNUNET_i2s(rps_peers[j].peer_id), - (PEER_GO_OFFLINE == delta) ? "offline" : "online"); - - if (PEER_GO_OFFLINE == delta) - cancel_pending_req_rep(&rps_peers[j]); - entry = make_oplist_entry(); - entry->delta = delta; - entry->index = j; - entry->op = GNUNET_TESTBED_peer_manage_service(NULL, - testbed_peers[j], - "rps", - &churn_cb, - entry, - (PEER_GO_OFFLINE == delta) ? 0 : 1); - rps_peers[j].entry_op_manage = entry; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s goes %s\n", + GNUNET_i2s (rps_peers[j].peer_id), + (PEER_GO_OFFLINE == delta) ? "offline" : "online"); + + if (PEER_GO_OFFLINE == delta) + cancel_pending_req_rep (&rps_peers[j]); + entry = make_oplist_entry (); + entry->delta = delta; + entry->index = j; + entry->op = GNUNET_TESTBED_peer_manage_service (NULL, + testbed_peers[j], + "rps", + &churn_cb, + entry, + (PEER_GO_OFFLINE == delta) ? + 0 : 1); + rps_peers[j].entry_op_manage = entry; + } } static void -churn(void *cls) +churn (void *cls) { - (void)cls; + (void) cls; unsigned int i; unsigned int j; double portion_online; @@ -1770,59 +1791,59 @@ churn(void *cls) double portion_go_online; double portion_go_offline; - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Churn function executing\n"); + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Churn function executing\n"); churn_task = NULL; /* Should be invalid by now */ /* Compute the probability for an online peer to go offline * this round */ portion_online = num_peers_online * 1.0 / num_peers; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion online: %f\n", - portion_online); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion online: %f\n", + portion_online); portion_go_online = ((1 - portion_online) * .5 * .66); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion that should go online: %f\n", - portion_go_online); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion that should go online: %f\n", + portion_go_online); portion_go_offline = (portion_online + portion_go_online) - .75; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Portion that probably goes offline: %f\n", - portion_go_offline); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Portion that probably goes offline: %f\n", + portion_go_offline); prob_go_offline = portion_go_offline / (portion_online * .5); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Probability of a selected online peer to go offline: %f\n", - prob_go_offline); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Probability of a selected online peer to go offline: %f\n", + prob_go_offline); - permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, - (unsigned int)num_peers); + permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, + (unsigned int) num_peers); /* Go over 50% randomly chosen peers */ for (i = 0; i < .5 * num_peers; i++) + { + j = permut[i]; + + /* If online, shut down with certain probability */ + if (GNUNET_YES == rps_peers[j].online) { - j = permut[i]; - - /* If online, shut down with certain probability */ - if (GNUNET_YES == rps_peers[j].online) - { - manage_service_wrapper(i, j, -1, prob_go_offline); - } - - /* If offline, restart with certain probability */ - else if (GNUNET_NO == rps_peers[j].online) - { - manage_service_wrapper(i, j, 1, 0.66); - } + manage_service_wrapper (i, j, -1, prob_go_offline); } - GNUNET_free(permut); + /* If offline, restart with certain probability */ + else if (GNUNET_NO == rps_peers[j].online) + { + manage_service_wrapper (i, j, 1, 0.66); + } + } + + GNUNET_free (permut); - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), churn, NULL); } @@ -1831,7 +1852,7 @@ churn(void *cls) /** * Initialise given RPSPeer */ -static void profiler_init_peer(struct RPSPeer *rps_peer) +static void profiler_init_peer (struct RPSPeer *rps_peer) { if (num_peers - 1 == rps_peer->index) rps_peer->num_ids_to_request = cur_test_run.num_requests; @@ -1846,72 +1867,72 @@ static void profiler_init_peer(struct RPSPeer *rps_peer) * @param recv_peers the received peers */ static void -profiler_reply_handle(void *cls, - uint64_t n, - const struct GNUNET_PeerIdentity *recv_peers) +profiler_reply_handle (void *cls, + uint64_t n, + const struct GNUNET_PeerIdentity *recv_peers) { struct RPSPeer *rps_peer; struct RPSPeer *rcv_rps_peer; char *file_name; char *file_name_dh; unsigned int i; - struct PendingReply *pending_rep = (struct PendingReply *)cls; + struct PendingReply *pending_rep = (struct PendingReply *) cls; rps_peer = pending_rep->rps_peer; file_name = "/tmp/rps/received_ids"; file_name_dh = "/tmp/rps/diehard_input"; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "[%s] got %" PRIu64 " peers:\n", - GNUNET_i2s(rps_peer->peer_id), - n); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "[%s] got %" PRIu64 " peers:\n", + GNUNET_i2s (rps_peer->peer_id), + n); for (i = 0; i < n; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u: %s\n", - i, - GNUNET_i2s(&recv_peers[i])); - tofile(file_name, - "%s\n", - GNUNET_i2s_full(&recv_peers[i])); - rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); - GNUNET_assert(NULL != rcv_rps_peer); - tofile(file_name_dh, - "%" PRIu32 "\n", - (uint32_t)rcv_rps_peer->index); - } - default_reply_handle(cls, n, recv_peers); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u: %s\n", + i, + GNUNET_i2s (&recv_peers[i])); + tofile (file_name, + "%s\n", + GNUNET_i2s_full (&recv_peers[i])); + rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); + GNUNET_assert (NULL != rcv_rps_peer); + tofile (file_name_dh, + "%" PRIu32 "\n", + (uint32_t) rcv_rps_peer->index); + } + default_reply_handle (cls, n, recv_peers); } static void -profiler_cb(struct RPSPeer *rps_peer) +profiler_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) - { - return; - } + if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test)) + { + return; + } /* Start churn */ - if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting churn task\n"); - churn_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - churn, - NULL); - } + if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting churn task\n"); + churn_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + churn, + NULL); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Not starting churn task\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Not starting churn task\n"); + } /* Only request peer ids at one peer. * (It's the before-last because last one is target of the focussed attack.) */ if (eval_peer == rps_peer) - schedule_missing_requests(rps_peer); + schedule_missing_requests (rps_peer); } /** @@ -1924,30 +1945,30 @@ profiler_cb(struct RPSPeer *rps_peer) * #GNUNET_SYSERR to abort iteration with error! */ int -file_name_cb(void *cls, const char *filename) +file_name_cb (void *cls, const char *filename) { - (void)cls; + (void) cls; - if (NULL != strstr(filename, "sampler_el")) + if (NULL != strstr (filename, "sampler_el")) + { + struct RPS_SamplerElement *s_elem; + struct GNUNET_CRYPTO_AuthKey auth_key; + const char *key_char; + uint32_t i; + + key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ + tofile (filename, "--------------------------\n"); + + auth_key = string_to_auth_key (key_char); + s_elem = RPS_sampler_elem_create (); + RPS_sampler_elem_set (s_elem, auth_key); + + for (i = 0; i < num_peers; i++) { - struct RPS_SamplerElement *s_elem; - struct GNUNET_CRYPTO_AuthKey auth_key; - const char *key_char; - uint32_t i; - - key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ - tofile(filename, "--------------------------\n"); - - auth_key = string_to_auth_key(key_char); - s_elem = RPS_sampler_elem_create(); - RPS_sampler_elem_set(s_elem, auth_key); - - for (i = 0; i < num_peers; i++) - { - RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]); - } - RPS_sampler_elem_destroy(s_elem); + RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); } + RPS_sampler_elem_destroy (s_elem); + } return GNUNET_OK; } @@ -1957,15 +1978,15 @@ file_name_cb(void *cls, const char *filename) * Compute all perfect samples. */ int -profiler_eval(void) +profiler_eval (void) { /* Compute perfect sample for each sampler element */ - if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); - } + if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); + } - return evaluate(); + return evaluate (); } @@ -1977,40 +1998,40 @@ profiler_eval(void) * * @return */ -static int is_in_view(uint32_t a, uint32_t b) +static int is_in_view (uint32_t a, uint32_t b) { uint32_t i; for (i = 0; i < rps_peers[a].cur_view_count; i++) + { + if (0 == memcmp (rps_peers[b].peer_id, + &rps_peers[a].cur_view[i], + sizeof(struct GNUNET_PeerIdentity))) { - if (0 == memcmp(rps_peers[b].peer_id, - &rps_peers[a].cur_view[i], - sizeof(struct GNUNET_PeerIdentity))) - { - return GNUNET_YES; - } + return GNUNET_YES; } + } return GNUNET_NO; } -static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) +static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) { uint32_t i; for (i = 0; i < num_peers; i++) + { + if (0 == memcmp (pid, + rps_peers[i].peer_id, + sizeof(struct GNUNET_PeerIdentity))) { - if (0 == memcmp(pid, - rps_peers[i].peer_id, - sizeof(struct GNUNET_PeerIdentity))) - { - return i; - } + return i; } - //return 0; /* Should not happen - make compiler happy */ - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "No known _PeerIdentity %s!\n", - GNUNET_i2s_full(pid)); - GNUNET_assert(0); + } + // return 0; /* Should not happen - make compiler happy */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No known _PeerIdentity %s!\n", + GNUNET_i2s_full (pid)); + GNUNET_assert (0); } /** @@ -2021,20 +2042,20 @@ static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) * * @return */ -static uint32_t count_containing_views(uint32_t a, uint32_t b) +static uint32_t count_containing_views (uint32_t a, uint32_t b) { uint32_t i; uint32_t peer_idx; uint32_t count = 0; for (i = 0; i < rps_peers[a].cur_view_count; i++) + { + peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); + if (GNUNET_YES == is_in_view (peer_idx, b)) { - peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); - if (GNUNET_YES == is_in_view(peer_idx, b)) - { - count++; - } + count++; } + } return count; } @@ -2044,12 +2065,12 @@ static uint32_t count_containing_views(uint32_t a, uint32_t b) * * @param peer_idx index of the peer that is about to sample */ -static void compute_probabilities(uint32_t peer_idx) +static void compute_probabilities (uint32_t peer_idx) { - //double probs[num_peers] = { 0 }; + // double probs[num_peers] = { 0 }; double probs[num_peers]; size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof(char); - char *probs_as_str = GNUNET_malloc(probs_as_str_size); + char *probs_as_str = GNUNET_malloc (probs_as_str_size); char *probs_as_str_cpy; uint32_t i; double prob_push; @@ -2060,119 +2081,120 @@ static void compute_probabilities(uint32_t peer_idx) int tmp; uint32_t count_non_zero_prob = 0; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Computing probabilities for peer %" PRIu32 "\n", peer_idx); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Computing probabilities for peer %" PRIu32 "\n", peer_idx); /* Firstly without knowledge of old views */ for (i = 0; i < num_peers; i++) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\tfor peer %" PRIu32 ":\n", i); - view_size = rps_peers[i].cur_view_count; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tview_size: %" PRIu32 "\n", view_size); - /* For peer i the probability of being sampled is - * evenly distributed among all possibly observed peers. */ - /* We could have observed a peer in three cases: - * 1. peer sent a push - * 2. peer was contained in a pull reply - * 3. peer was in history (sampler) - ignored for now */ - /* 1. Probability of having received a push from peer i */ - if ((GNUNET_YES == is_in_view(i, peer_idx)) && - (1 <= (0.45 * view_size))) - { - prob_push = 1.0 * binom(0.45 * view_size, 1) - / - binom(view_size, 0.45 * view_size); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", - peer_idx, - i, - prob_push); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", - binom(view_size, 0.45 * view_size), - binom(0.45 * view_size, 1)); - } - else - { - prob_push = 0; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", - peer_idx, - i); - } - /* 2. Probability of peer i being contained in pulls */ - view_size = rps_peers[peer_idx].cur_view_count; - cont_views = count_containing_views(peer_idx, i); - number_of_being_in_pull_events = - (binom(view_size, 0.45 * view_size) - - binom(view_size - cont_views, 0.45 * view_size)); - if (0 != number_of_being_in_pull_events) - { - prob_pull = number_of_being_in_pull_events - / - (1.0 * binom(view_size, 0.45 * view_size)); - } - else - { - prob_pull = 0; - } - probs[i] = prob_push + prob_pull - (prob_push * prob_pull); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 - " peers in its view who know %" PRIu32 " prob: %f\n", - peer_idx, - cont_views, - view_size, - i, - prob_pull); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations: %" PRIu32 "\n", - binom(view_size, 0.45 * view_size)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations without %" PRIu32 - ": %" PRIu32 "\n", - i, - binom(view_size - cont_views, 0.45 * view_size)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "\t\tnumber of possible pull combinations with %" PRIu32 - ": %" PRIu32 "\n", - i, - number_of_being_in_pull_events); - - if (0 != probs[i]) - count_non_zero_prob++; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\tfor peer %" PRIu32 ":\n", i); + view_size = rps_peers[i].cur_view_count; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tview_size: %" PRIu32 "\n", view_size); + /* For peer i the probability of being sampled is + * evenly distributed among all possibly observed peers. */ + /* We could have observed a peer in three cases: + * 1. peer sent a push + * 2. peer was contained in a pull reply + * 3. peer was in history (sampler) - ignored for now */ + /* 1. Probability of having received a push from peer i */ + if ((GNUNET_YES == is_in_view (i, peer_idx)) && + (1 <= (0.45 * view_size))) + { + prob_push = 1.0 * binom (0.45 * view_size, 1) + / + binom (view_size, 0.45 * view_size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", + peer_idx, + i, + prob_push); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tposs choices from view: %" PRIu32 ", containing i: %" + PRIu32 "\n", + binom (view_size, 0.45 * view_size), + binom (0.45 * view_size, 1)); + } + else + { + prob_push = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", + peer_idx, + i); + } + /* 2. Probability of peer i being contained in pulls */ + view_size = rps_peers[peer_idx].cur_view_count; + cont_views = count_containing_views (peer_idx, i); + number_of_being_in_pull_events = + (binom (view_size, 0.45 * view_size) + - binom (view_size - cont_views, 0.45 * view_size)); + if (0 != number_of_being_in_pull_events) + { + prob_pull = number_of_being_in_pull_events + / + (1.0 * binom (view_size, 0.45 * view_size)); + } + else + { + prob_pull = 0; + } + probs[i] = prob_push + prob_pull - (prob_push * prob_pull); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 + " peers in its view who know %" PRIu32 " prob: %f\n", + peer_idx, + cont_views, + view_size, + i, + prob_pull); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations: %" PRIu32 "\n", + binom (view_size, 0.45 * view_size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations without %" PRIu32 + ": %" PRIu32 "\n", + i, + binom (view_size - cont_views, 0.45 * view_size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tnumber of possible pull combinations with %" PRIu32 + ": %" PRIu32 "\n", + i, + number_of_being_in_pull_events); + + if (0 != probs[i]) + count_non_zero_prob++; + } /* normalize */ if (0 != count_non_zero_prob) + { + for (i = 0; i < num_peers; i++) { - for (i = 0; i < num_peers; i++) - { - probs[i] = probs[i] * (1.0 / count_non_zero_prob); - } + probs[i] = probs[i] * (1.0 / count_non_zero_prob); } + } else + { + for (i = 0; i < num_peers; i++) { - for (i = 0; i < num_peers; i++) - { - probs[i] = 0; - } + probs[i] = 0; } + } /* str repr */ for (i = 0; i < num_peers; i++) - { - probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); - tmp = GNUNET_snprintf(probs_as_str, - probs_as_str_size, - "%s %7.6f", probs_as_str_cpy, probs[i]); - GNUNET_free(probs_as_str_cpy); - GNUNET_assert(0 <= tmp); - } + { + probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); + tmp = GNUNET_snprintf (probs_as_str, + probs_as_str_size, + "%s %7.6f", probs_as_str_cpy, probs[i]); + GNUNET_free (probs_as_str_cpy); + GNUNET_assert (0 <= tmp); + } - to_file_w_len(rps_peers[peer_idx].file_name_probs, - probs_as_str_size, - probs_as_str); - GNUNET_free(probs_as_str); + to_file_w_len (rps_peers[peer_idx].file_name_probs, + probs_as_str_size, + probs_as_str); + GNUNET_free (probs_as_str); } /** @@ -2184,212 +2206,214 @@ static void compute_probabilities(uint32_t peer_idx) * * @return the number of occurrences */ -static uint32_t count_peer_in_views_2(uint32_t peer_idx) +static uint32_t count_peer_in_views_2 (uint32_t peer_idx) { uint32_t i, j; uint32_t count = 0; for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ - { - for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ |