X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Frps%2Fgnunet-service-rps.c;h=fd398b863c02fd60f1c8c18ad18850a1387a92eb;hb=200fd67bcca55ad08351719b154516d91443a298;hp=23fdf2af54956e685c9ee7efa07a6a4ed5e61a8e;hpb=4d78632c575a118a2dc4c9194536a86b2fa00f76;p=oweals%2Fgnunet.git diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 23fdf2af5..fd398b863 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -52,6 +52,8 @@ // TODO API request_cancel +// TODO don't pass peermap all the time + // hist_size_init, hist_size_max /** @@ -812,12 +814,6 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, GNUNET_RPS_CADET_PORT, GNUNET_CADET_OPTION_RELIABLE); - // do I have to explicitly put it in the peer_map? - (void) GNUNET_CONTAINER_multipeermap_put - (peer_map, - peer, - peer_ctx, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } return peer_ctx->send_channel; } @@ -859,12 +855,14 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, void check_peer_live (struct PeerContext *peer_ctx) { - (void) get_channel (peer_map, &peer_ctx->peer_id); LOG (GNUNET_ERROR_TYPE_DEBUG, "Get informed about peer %s getting live\n", GNUNET_i2s (&peer_ctx->peer_id)); - if (NULL == peer_ctx->is_live_task) + + if (NULL == peer_ctx->is_live_task && + NULL == peer_ctx->send_channel) { + (void) get_channel (peer_map, &peer_ctx->peer_id); peer_ctx->is_live_task = GNUNET_CADET_notify_transmit_ready (peer_ctx->send_channel, GNUNET_NO, @@ -872,16 +870,13 @@ check_peer_live (struct PeerContext *peer_ctx) sizeof (struct GNUNET_MessageHeader), cadet_ntfy_tmt_rdy_cb, peer_ctx); - (void) GNUNET_CONTAINER_multipeermap_put (peer_map, - &peer_ctx->peer_id, - peer_ctx, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } - else - { + else if (NULL != peer_ctx->is_live_task) LOG (GNUNET_ERROR_TYPE_DEBUG, "Already waiting for notification\n"); - } + else if (NULL != peer_ctx->send_channel) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Already have established channel to peer\n"); } @@ -1564,7 +1559,7 @@ generate_view_array (unsigned int view_size) * Reply with the view of PeerIDs. * * @param cls Closure - * @param channel The channel the PUSH was received over + * @param channel The channel the PULL REQUEST was received over * @param channel_ctx The context associated with this channel * @param msg The message header */ @@ -1683,7 +1678,7 @@ handle_peer_pull_reply (void *cls, #endif /* ENABLE_MALICIOUS */ /* Do actual logic */ - peers = (struct GNUNET_PeerIdentity *) &msg[1]; + peers = (struct GNUNET_PeerIdentity *) &in_msg[1]; LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received, got following %u peers:\n", @@ -1722,9 +1717,7 @@ handle_peer_pull_reply (void *cls, &peers[i])) { peer_ctx = get_peer_ctx (peer_map, &peers[i]); - if (GNUNET_YES == get_peer_flag (peer_ctx, VALID) || - NULL != peer_ctx->send_channel || - NULL != peer_ctx->recv_channel) + if (GNUNET_YES == get_peer_flag (peer_ctx, VALID)) { if (GNUNET_NO == in_arr (pull_list, pull_list_size, &peers[i])) GNUNET_array_append (pull_list, pull_list_size, peers[i]); @@ -1852,8 +1845,7 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); * Turn RPS service to act malicious. * * @param cls Closure - * @param channel The channel the PUSH was received over - * @param channel_ctx The context associated with this channel + * @param client The client that sent the message * @param msg The message header */ static void @@ -1976,8 +1968,10 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) uint32_t i; struct GNUNET_TIME_Relative time_next_round; struct AttackedPeer *tmp_att_peer; + struct PeerContext *peer_ctx; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously type %" PRIu32 ".\n", + mal_type); /* Do malicious actions */ if (1 == mal_type) @@ -2030,6 +2024,18 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (3 == mal_type) { /* Combined attack */ + /* Send PUSH to attacked peers */ + peer_ctx = get_peer_ctx (peer_map, &attacked_peer); + if (GNUNET_YES == get_peer_flag (peer_ctx, VALID)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Goding to send push to attacked peer (%s)\n", + GNUNET_i2s (&attacked_peer)); + send_push (&attacked_peer); + } + else + check_peer_live (peer_ctx); + /* The maximum of pushes we're going to send this round */ num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, num_attacked_peers), @@ -2039,9 +2045,6 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "Going to send %" PRIu32 " pushes\n", num_pushes); - /* Send PUSHes to attacked peers */ - send_push (&attacked_peer); - for (i = 0 ; i < num_pushes ; i++) { if (att_peers_tail == att_peer_index) @@ -2090,7 +2093,10 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned int *permut; unsigned int a_peers; /* Number of peers we send pushes to */ unsigned int b_peers; /* Number of peers we send pull requests to */ + uint32_t first_border; + uint32_t second_border; struct GNUNET_PeerIdentity peer; + struct PeerContext *peer_ctx; LOG (GNUNET_ERROR_TYPE_DEBUG, "Printing view:\n"); @@ -2130,11 +2136,18 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } /* Send PULL requests */ - b_peers = a_peers + floor (beta * view_size); + b_peers = ceil (beta * view_size); + first_border = a_peers; + second_border = a_peers + b_peers; + if (second_border > view_size) + { + first_border = view_size - b_peers; + second_border = view_size; + } LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %u (ceil (%f * %u)) peers.\n", b_peers, beta, view_size); - for (i = a_peers; i < b_peers; i++) + for (i = first_border; i < second_border; i++) { peer = view_array[permut[i]]; peer_ctx = get_peer_ctx (peer_map, &peer); @@ -2159,8 +2172,6 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); - uint32_t first_border; - uint32_t second_border; uint32_t final_size; uint32_t peers_to_clean_size; struct GNUNET_PeerIdentity *peers_to_clean; @@ -2190,7 +2201,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* Update view with peers received through PUSHes */ permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, - pull_list_size); + push_list_size); for (i = 0; i < first_border; i++) { view_array[i] = push_list[permut[i]]; @@ -2372,7 +2383,7 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 0); } - /* If we are still waiting for notification whether this peer is live + /* If we are still waiting for notification whether this peer is live * cancel the according task */ if (NULL != peer_ctx->is_live_task) { @@ -2489,9 +2500,9 @@ shutdown_task (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Size of the peermap: %u\n", GNUNET_CONTAINER_multipeermap_size (peer_map)); - GNUNET_break (0 != GNUNET_CONTAINER_multipeermap_size (peer_map)); - GNUNET_CONTAINER_multipeermap_destroy (peer_map); + GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (peer_map)); GNUNET_CADET_disconnect (cadet_handle); + GNUNET_CONTAINER_multipeermap_destroy (peer_map); GNUNET_CONTAINER_multipeermap_destroy (view); view = NULL; GNUNET_array_grow (push_list, push_list_size, 0); @@ -2722,17 +2733,19 @@ run (void *cls, "ROUNDINTERVAL", &round_interval)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read ROUNDINTERVAL from config\n"); + 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", - "INITSIZE", - (long long unsigned int *) &sampler_size_est_need)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg, "RPS", "INITSIZE", + (long long unsigned int *) &sampler_size_est_need)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "RPS", "INITSIZE"); GNUNET_SCHEDULER_shutdown (); return; }