-/* Copyright (c) 2012-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2019. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "connection.h"
#include "tracker.h"
#include <simgrid/msg.h>
-#include <xbt/RngStream.h>
#include <limits.h>
#include <stdio.h> /* snprintf */
peer->pieces_count = xbt_new0(short, FILE_PIECES);
- peer->stream = (RngStream)MSG_host_get_data(MSG_host_self());
peer->comm_received = NULL;
peer->round = 0;
}
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
- int random_piece_index = RngStream_RandInt(peer->stream, 0, nb_interesting_pieces - 1);
+ int random_piece_index = rand() % nb_interesting_pieces;
int current_index = 0;
for (int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i)) {
}
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
- int random_piece_index = RngStream_RandInt(peer->stream, 0, nb_interesting_pieces - 1);
+ int random_piece_index = rand() % nb_interesting_pieces;
int current_index = 0;
for (int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
}
xbt_assert(nb_min_pieces != 0 || (is_interested_and_free(peer, remote_peer) == 0));
// get a random rarest piece
- int random_rarest_index = RngStream_RandInt(peer->stream, 0, nb_min_pieces - 1);
+ int random_rarest_index = 0;
+ if (nb_min_pieces > 0) {
+ random_rarest_index = rand() % nb_min_pieces;
+ }
for (int i = 0; i < FILE_PIECES; i++) {
if (peer->pieces_count[i] == min && peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i)) {
// remove a peer from the list
xbt_dict_cursor_t cursor = NULL;
xbt_dict_cursor_first(peer->active_peers, &cursor);
- if (xbt_dict_length(peer->active_peers) > 0) {
+ if (!xbt_dict_is_empty(peer->active_peers)) {
key_choked = xbt_dict_cursor_get_key(cursor);
peer_choked = xbt_dict_cursor_get_data(cursor);
}
int j = 0;
do {
// We choose a random peer to unchoke.
- int id_chosen = RngStream_RandInt(peer->stream, 0, xbt_dict_length(peer->peers) - 1);
+ int id_chosen = 0;
+ if (xbt_dict_length(peer->peers) > 0) {
+ id_chosen = rand() % xbt_dict_length(peer->peers);
+ }
int i = 0;
connection_t connection;
xbt_dict_foreach (peer->peers, cursor, key, connection) {
i++;
}
xbt_dict_cursor_free(&cursor);
- if (peer_choosed == NULL)
- THROWF(unknown_error, 0, "A peer should have be selected at this point");
- else if ((peer_choosed->interested == 0) || (peer_choosed->choked_upload == 0))
+ xbt_assert(peer_choosed != NULL, "A peer should have been selected at this point");
+ if ((peer_choosed->interested == 0) || (peer_choosed->choked_upload == 0))
peer_choosed = NULL;
else
XBT_DEBUG("Nothing to do, keep going");