*/
static struct GNUNET_TIME_Relative request_rate;
-/**
- * Number of history update tasks.
- */
-static uint32_t num_hist_update_tasks;
-
#ifdef ENABLE_MALICIOUS
/**
}
+/**
+ * Insert PeerID in #view
+ *
+ * Called once we know a peer is live.
+ * Implements #PeerOp
+ *
+ * @return GNUNET_OK if peer was actually inserted
+ * GNUNET_NO if peer was not inserted
+ */
+static void
+insert_in_view_op (void *cls,
+ const struct GNUNET_PeerIdentity *peer);
+
+/**
+ * Insert PeerID in #view
+ *
+ * Called once we know a peer is live.
+ *
+ * @return GNUNET_OK if peer was actually inserted
+ * GNUNET_NO if peer was not inserted
+ */
+static int
+insert_in_view (const struct GNUNET_PeerIdentity *peer)
+{
+ int online;
+
+ online = Peers_check_peer_flag (peer, Peers_ONLINE);
+ if ( (GNUNET_NO == online) ||
+ (GNUNET_SYSERR == online) ) /* peer is not even known */
+ {
+ (void) Peers_issue_peer_liveliness_check (peer);
+ (void) Peers_schedule_operation (peer, insert_in_view_op);
+ return GNUNET_NO;
+ }
+ /* Open channel towards peer to keep connection open */
+ Peers_indicate_sending_intention (peer);
+ return View_put (peer);
+}
+
/**
* Put random peer from sampler into the view as history update.
*/
for (i = 0; i < num_peers; i++)
{
- View_put (&ids[i]);
+ (void) insert_in_view (&ids[i]);
to_file (file_name_view_log,
"+%s\t(hist)",
GNUNET_i2s_full (ids));
}
- if (0 < num_hist_update_tasks)
- num_hist_update_tasks--;
}
* Implements #PeerOp
*/
static void
-insert_in_view (void *cls,
+insert_in_view_op (void *cls,
const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_assert (GNUNET_YES == Peers_check_peer_flag (peer, Peers_ONLINE));
- View_put (peer);
+ (void) insert_in_view (peer);
}
if (0 < RPS_sampler_count_id (prot_sampler, peer))
{
/* Make sure we 'know' about this peer */
- (void) Peers_insert_peer_check_liveliness (peer);
+ (void) Peers_issue_peer_liveliness_check (peer);
/* Establish a channel towards that peer to indicate we are going to send
* messages to it */
- Peers_indicate_sending_intention (peer);
- //Peers_issue_peer_liveliness_check (peer);
+ //Peers_indicate_sending_intention (peer);
}
}
got_peer (const struct GNUNET_PeerIdentity *peer)
{
/* If we did not know this peer already, insert it into sampler and view */
- if (GNUNET_YES == Peers_insert_peer_check_liveliness (peer))
+ if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer))
{
Peers_schedule_operation (peer, insert_in_sampler);
- Peers_schedule_operation (peer, insert_in_view);
+ Peers_schedule_operation (peer, insert_in_view_op);
}
}
-
/**
* @brief Checks if there is a sending channel and if it is needed
*
destroy_cli_ctx (struct ClientContext *cli_ctx)
{
GNUNET_assert (NULL != cli_ctx);
+ if (NULL != cli_ctx->mq)
+ {
+ GNUNET_MQ_destroy (cli_ctx->mq);
+ }
if (NULL != cli_ctx->rep_cls_head)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
&peers[i]))
{
/* Make sure we 'know' about this peer */
- (void) Peers_insert_peer_check_liveliness (&peers[i]);
+ (void) Peers_insert_peer (&peers[i]);
if (GNUNET_YES == Peers_check_peer_valid (&peers[i]))
{
else
{
Peers_schedule_operation (&peers[i], insert_in_pull_map);
- Peers_issue_peer_liveliness_check (&peers[i]);
+ (void) Peers_issue_peer_liveliness_check (&peers[i]);
}
}
}
/* Set the flag of the attacked peer to valid to avoid problems */
if (GNUNET_NO == Peers_check_peer_known (&attacked_peer))
{
- Peers_insert_peer_check_liveliness (&attacked_peer);
- Peers_issue_peer_liveliness_check (&attacked_peer);
+ (void) Peers_issue_peer_liveliness_check (&attacked_peer);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
* Send as many pushes to the attacked peer as possible
* That is one push per round as it will ignore more.
*/
- Peers_insert_peer_check_liveliness (&attacked_peer);
+ (void) Peers_issue_peer_liveliness_check (&attacked_peer);
if (GNUNET_YES == Peers_check_peer_valid (&attacked_peer))
send_push (&attacked_peer);
}
/* Send PUSH to attacked peers */
if (GNUNET_YES == Peers_check_peer_known (&attacked_peer))
{
- Peers_insert_peer_check_liveliness (&attacked_peer);
+ (void) Peers_issue_peer_liveliness_check (&attacked_peer);
if (GNUNET_YES == Peers_check_peer_valid (&attacked_peer))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_i2s (&attacked_peer));
send_push (&attacked_peer);
}
- else
- Peers_issue_peer_liveliness_check (&attacked_peer);
}
- else
- Peers_insert_peer_check_liveliness (&attacked_peer);
- Peers_issue_peer_liveliness_check (&attacked_peer);
+ (void) Peers_issue_peer_liveliness_check (&attacked_peer);
/* The maximum of pushes we're going to send this round */
num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
CustomPeerMap_size (push_map));
for (i = 0; i < first_border; i++)
{
- View_put (CustomPeerMap_get_peer_by_index (push_map, permut[i]));
+ (void) insert_in_view (CustomPeerMap_get_peer_by_index (push_map,
+ permut[i]));
to_file (file_name_view_log,
"+%s\t(push list)",
GNUNET_i2s_full (&view_array[i]));
CustomPeerMap_size (pull_map));
for (i = first_border; i < second_border; i++)
{
- View_put (CustomPeerMap_get_peer_by_index (pull_map,
- permut[i - first_border]));
+ (void) insert_in_view (CustomPeerMap_get_peer_by_index (pull_map,
+ permut[i - first_border]));
to_file (file_name_view_log,
"+%s\t(pull list)",
GNUNET_i2s_full (&view_array[i]));
hist_update,
NULL,
final_size - second_border);
- num_hist_update_tasks = final_size - second_border;
// TODO change the peer_flags accordingly
for (i = 0; i < View_size (); i++)
}
}
+/**
+ * @brief Iterator function over stored, valid peers.
+ *
+ * We initialise the sampler with those.
+ *
+ * @param cls the closure
+ * @param peer the peer id
+ * @return #GNUNET_YES if we should continue to
+ * iterate,
+ * #GNUNET_NO if not.
+ */
+static int
+valid_peers_iterator (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ if (NULL != peer)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got stored, valid peer %s\n",
+ GNUNET_i2s (peer));
+ got_peer (peer);
+ }
+ return GNUNET_YES;
+}
+
/**
* Iterator over peers from peerinfo.
CustomPeerMap_destroy (pull_map);
#ifdef ENABLE_MALICIOUS
struct AttackedPeer *tmp_att_peer;
+ GNUNET_free (file_name_view_log);
GNUNET_array_grow (mal_peers, num_mal_peers, 0);
if (NULL != mal_peer_set)
GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set);
pull_map = CustomPeerMap_create (4);
- num_hist_update_tasks = 0;
-
-
LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL);
// TODO send push/pull to each of those peers?
// TODO read stored valid peers from last run
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
+ Peers_get_valid_peers (valid_peers_iterator, NULL);
peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
GNUNET_NO,