+ peers = (struct GNUNET_PeerIdentity *) &msg[1];
+ mal_type = ntohl (in_msg->type);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Now acting malicious type %" PRIu32 "\n",
+ mal_type);
+
+ if (1 == mal_type)
+ { /* Try to maximise representation */
+ /* Add other malicious peers to those we already know */
+
+ num_mal_peers_sent = ntohl (in_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);
+ 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_SCHEDULER_cancel (do_round_task);
+ do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
+ }
+
+ else if (2 == mal_type)
+ { /* Try to partition the network */
+ /* Add other malicious peers to those we already know */
+ num_mal_peers_sent = ntohl (in_msg->num_peers) - 1;
+ num_mal_peers_old = num_mal_peers;
+ GNUNET_array_grow (mal_peers,
+ num_mal_peers,
+ num_mal_peers + num_mal_peers_sent);
+ 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 */
+ memcpy (&attacked_peer,
+ &peers[num_mal_peers_sent],
+ sizeof (struct GNUNET_PeerIdentity));
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Attacked peer is %s\n",
+ GNUNET_i2s (&attacked_peer));
+
+ /* Substitute do_round () with do_mal_round () */
+ GNUNET_SCHEDULER_cancel (do_round_task);
+ do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
+ }
+ else if (0 == mal_type)
+ { /* Stop acting malicious */
+ num_mal_peers = 0;
+ GNUNET_free (mal_peers);
+
+ /* Substitute do_mal_round () with do_round () */
+ GNUNET_SCHEDULER_cancel (do_round_task);
+ do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
+ }
+ else
+ {
+ GNUNET_break (0);
+ }
+}
+
+
+/**
+ * Send out PUSHes and PULLs maliciously.
+ *
+ * This is executed regylary.
+ */
+static void
+do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ uint32_t num_pushes;
+ uint32_t i;
+ struct GNUNET_TIME_Relative time_next_round;
+ struct AttackedPeer *tmp_att_peer;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n");
+
+ /* Do malicious actions */
+ if (1 == mal_type)
+ { /* Try to maximise representation */
+
+ /* The maximum of pushes we're going to send this round */
+ num_pushes = min (min (push_limit,
+ num_attacked_peers),
+ GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE);
+
+ /* 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 (&att_peer_index->peer_id);
+ }
+
+ /* Send PULLs to some peers to learn about additional peers to attack */
+ 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 (&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.
+ */
+ send_push (&attacked_peer);
+ }
+
+
+ /* Schedule next round */
+ time_next_round = compute_rand_delay (round_interval, 2);
+
+ //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round, NULL);
+ do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_mal_round, NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");