Main changes are:
* remove unused variables.
* use unsigned int for the index in xbt_dynar_foreach.
MSG_launch_application(deployment_file);
MSG_launch_application(deployment_file);
- msg_error_t res = MSG_main();
#ifndef BITTORRENT_BITTORRENT_H_
#define BITTORRENT_BITTORRENT_H_
#ifndef BITTORRENT_BITTORRENT_H_
#define BITTORRENT_BITTORRENT_H_
-//TODO: Let users change this
-/*
- * File transfered data
- */
-static int FILE_SIZE = 5120;
-static int FILE_PIECE_SIZE = 512;
-static int FILE_PIECES = 10;
-
-static int PIECES_BLOCKS = 5;
-static int BLOCKS_REQUESTED = 2;
-static int PIECE_COMM_SIZE = 1;
/**
* Information message size
*/
#define MESSAGE_SIZE 1
/**
* Information message size
*/
#define MESSAGE_SIZE 1
-
-
-#define MAILBOX_SIZE 40 /* Size of mailboxes */
+/**
+ * Size of mailboxes
+ */
+#define MAILBOX_SIZE 40
/**
* Mailbox used to communicate with the tracker.
*/
/**
* Mailbox used to communicate with the tracker.
*/
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peers, "Messages specific for the peers");
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peers, "Messages specific for the peers");
+//TODO: Let users change this
+/*
+ * File transfered data
+ */
+static int FILE_SIZE = 5120;
+static int FILE_PIECES = 10;
+static int PIECES_BLOCKS = 5;
+static int BLOCKS_REQUESTED = 2;
msg_error_t status = MSG_comm_wait(comm_received, GET_PEERS_TIMEOUT);
if (status == MSG_OK) {
tracker_task_data_t data = MSG_task_get_data(task_received);
msg_error_t status = MSG_comm_wait(comm_received, GET_PEERS_TIMEOUT);
if (status == MSG_OK) {
tracker_task_data_t data = MSG_task_get_data(task_received);
+ unsigned i;
+ int peer_id;
//Add the peers the tracker gave us to our peer list.
xbt_dynar_foreach(data->peers, i, peer_id) {
if (peer_id != peer->id)
//Add the peers the tracker gave us to our peer list.
xbt_dynar_foreach(data->peers, i, peer_id) {
if (peer_id != peer->id)
if (piece_complete(peer, message->index)) {
peer->pieces_requested--;
//Removing the piece from our piece list
if (piece_complete(peer, message->index)) {
peer->pieces_requested--;
//Removing the piece from our piece list
- int piece_index = -1, i, piece;
+ unsigned i;
+ int piece_index = -1, piece;
xbt_dynar_foreach(peer->current_pieces, i, piece) {
if (piece == message->index) {
piece_index = i;
xbt_dynar_foreach(peer->current_pieces, i, piece) {
if (piece == message->index) {
piece_index = i;
MSG_comm_destroy(peer->comm_received);
peer->comm_received = NULL;
if (status == MSG_OK) {
MSG_comm_destroy(peer->comm_received);
peer->comm_received = NULL;
if (status == MSG_OK) {
- message_t message = MSG_task_get_data(peer->task_received);
+ MSG_task_get_data(peer->task_received);
handle_message(peer, peer->task_received);
if (peer->current_piece != -1) {
finished = 1;
handle_message(peer, peer->task_received);
if (peer->current_piece != -1) {
finished = 1;
}
xbt_dynar_push_as(peer->current_pieces, int, peer->current_piece);
XBT_DEBUG("New interested piece: %d", peer->current_piece);
}
xbt_dynar_push_as(peer->current_pieces, int, peer->current_piece);
XBT_DEBUG("New interested piece: %d", peer->current_piece);
- xbt_assert((peer->current_piece >= 0
- && peer->current_piece < FILE_PIECES,
- "Peer want to retrieve a piece that doesn't exist."));
+ xbt_assert((peer->current_piece >= 0 && peer->current_piece < FILE_PIECES),
+ "Peer want to retrieve a piece that doesn't exist.");
{
//update the current round
peer->round = (peer->round + 1) % 3;
{
//update the current round
peer->round = (peer->round + 1) % 3;
char *key;
connection_t peer_choosed = NULL;
//remove a peer from the list
char *key;
connection_t peer_choosed = NULL;
//remove a peer from the list
char *key;
xbt_dict_cursor_t cursor;
connection_t connection;
char *key;
xbt_dict_cursor_t cursor;
connection_t connection;
- int interested, cpt, piece;
+ unsigned cpt;
+ int interested, piece;
xbt_dict_foreach(peer->peers, cursor, key, connection) {
interested = 0;
if (connection->am_interested) {
xbt_dict_foreach(peer->peers, cursor, key, connection) {
interested = 0;
if (connection->am_interested) {
*/
void send_requests_to_peer(peer_t peer, connection_t remote_peer)
{
*/
void send_requests_to_peer(peer_t peer, connection_t remote_peer)
{
- int i, piece, block_index, block_length;
+ unsigned i;
+ int piece, block_index, block_length;
xbt_dynar_foreach(peer->current_pieces, i, piece) {
if (remote_peer->bitfield && remote_peer->bitfield[piece] == '1') {
block_index = get_first_block(peer, piece);
xbt_dynar_foreach(peer->current_pieces, i, piece) {
if (remote_peer->bitfield && remote_peer->bitfield[piece] == '1') {
block_index = get_first_block(peer, piece);
int in_current_pieces(peer_t peer, int piece)
{
int in_current_pieces(peer_t peer, int piece)
{
- int is_in = 0, i, peer_piece;
+ unsigned i;
+ int is_in = 0, peer_piece;
xbt_dynar_foreach(peer->current_pieces, i, peer_piece) {
if (peer_piece == piece) {
is_in = 1;
xbt_dynar_foreach(peer->current_pieces, i, peer_piece) {
if (peer_piece == piece) {
is_in = 1;
*/
int tracker(int argc, char *argv[])
{
*/
int tracker(int argc, char *argv[])
{
- int i, key_elm;
- char *key;
- void *data_p;
RngStream stream = RngStream_CreateStream("tracker");
RngStream stream = RngStream_CreateStream("tracker");
xbt_dynar_push_as(peers_list, int, data->peer_id);
}
//Sending peers to the peer
xbt_dynar_push_as(peers_list, int, data->peer_id);
}
//Sending peers to the peer
- int nb_peers = 0, next_peer;
int peers_length = xbt_dynar_length(peers_list);
for (i = 0; i < MAXIMUM_PAIRS && i < peers_length; i++) {
do {
int peers_length = xbt_dynar_length(peers_list);
for (i = 0; i < MAXIMUM_PAIRS && i < peers_length; i++) {
do {
*/
int is_in_list(xbt_dynar_t peers, int id)
{
*/
int is_in_list(xbt_dynar_t peers, int id)
{
xbt_dynar_foreach(peers, i, elm) {
if (elm == id) {
return 1;
xbt_dynar_foreach(peers, i, elm) {
if (elm == id) {
return 1;