-/* Copyright (c) 2012-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2020. 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. */
return count;
}
-int peer_has_not_piece(peer_t peer, unsigned int piece)
+int peer_has_not_piece(const s_peer_t* peer, unsigned int piece)
{
return !(peer->bitfield & 1U << piece);
}
/** Check that a piece is not currently being download by the peer. */
-int peer_is_not_downloading_piece(peer_t peer, unsigned int piece)
+int peer_is_not_downloading_piece(const s_peer_t* peer, unsigned int piece)
{
return !(peer->current_pieces & 1U << piece);
}
/** @brief Retrieves the peer list from the tracker
* @param peer current peer data
*/
-int get_peers_data(peer_t peer)
+int get_peers_data(const s_peer_t* peer)
{
int success = 0;
double timeout = MSG_get_clock() + GET_PEERS_TIMEOUT;
return bitfield == (1U << FILE_PIECES) - 1U;
}
-int nb_interested_peers(peer_t peer)
+int nb_interested_peers(const s_peer_t* peer)
{
xbt_dict_cursor_t cursor = NULL;
char* key;
return nb;
}
-void update_active_peers_set(peer_t peer, connection_t remote_peer)
+void update_active_peers_set(const s_peer_t* peer, connection_t remote_peer)
{
if ((remote_peer->interested != 0) && (remote_peer->choked_upload == 0)) {
// add in the active peers set
* @param peer peer we want to update the list
* @param bitfield bitfield
*/
-void update_pieces_count_from_bitfield(peer_t peer, unsigned int bitfield)
+void update_pieces_count_from_bitfield(const s_peer_t* peer, unsigned int bitfield)
{
for (int i = 0; i < FILE_PIECES; i++) {
if (bitfield & (1U << i)) {
* @param remote_peer: information about the connection
* @return the piece to download if possible. -1 otherwise
*/
-int select_piece_to_download(peer_t peer, connection_t remote_peer)
+int select_piece_to_download(const s_peer_t* peer, const s_connection_t* remote_peer)
{
int piece = partially_downloaded_piece(peer, remote_peer);
// strict priority policy
/** @brief Update "interested" state of peers: send "not interested" to peers that don't have any more pieces we want.
* @param peer our peer data
*/
-void update_interested_after_receive(peer_t peer)
+void update_interested_after_receive(const s_peer_t* peer)
{
char* key;
xbt_dict_cursor_t cursor;
}
/** Returns if a peer has completed the download of a piece */
-int piece_complete(peer_t peer, int index)
+int piece_complete(const s_peer_t* peer, int index)
{
for (int i = 0; i < PIECES_BLOCKS; i++) {
if (!(peer->bitfield_blocks & 1ULL << (index * PIECES_BLOCKS + i))) {
}
/** Returns the first block that a peer doesn't have in a piece. If the peer has all blocks of the piece, returns -1. */
-int get_first_block(peer_t peer, int piece)
+int get_first_block(const s_peer_t* peer, int piece)
{
for (int i = 0; i < PIECES_BLOCKS; i++) {
if (!(peer->bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i))) {
}
/** Indicates if the remote peer has a piece not stored by the local peer */
-int is_interested(peer_t peer, connection_t remote_peer)
+int is_interested(const s_peer_t* peer, const s_connection_t* remote_peer)
{
return remote_peer->bitfield & (peer->bitfield ^ ((1 << FILE_PIECES) - 1));
}
/** Indicates if the remote peer has a piece not stored by the local peer nor requested by the local peer */
-int is_interested_and_free(peer_t peer, connection_t remote_peer)
+int is_interested_and_free(const s_peer_t* peer, const s_connection_t* remote_peer)
{
for (int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i)) {
}
/** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
-int partially_downloaded_piece(peer_t peer, connection_t remote_peer)
+int partially_downloaded_piece(const s_peer_t* peer, const s_connection_t* remote_peer)
{
for (int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i) &&
* @param peer peer
* @param remote_peer peer data to the peer we want to send the request
*/
-void send_request_to_peer(peer_t peer, connection_t remote_peer, int piece)
+void send_request_to_peer(const s_peer_t* peer, connection_t remote_peer, int piece)
{
remote_peer->current_piece = piece;
xbt_assert(connection_has_piece(remote_peer, piece));
* @param peer peer data
* @param mailbox destination mailbox
*/
-void send_interested(peer_t peer, const char* mailbox)
+void send_interested(const s_peer_t* peer, const char* mailbox)
{
msg_task_t task = task_message_new(MESSAGE_INTERESTED, peer->hostname, peer->mailbox, peer->id,
task_message_size(MESSAGE_INTERESTED));
* @param peer peer data
* @param mailbox destination mailbox
*/
-void send_notinterested(peer_t peer, const char* mailbox)
+void send_notinterested(const s_peer_t* peer, const char* mailbox)
{
msg_task_t task = task_message_new(MESSAGE_NOTINTERESTED, peer->hostname, peer->mailbox, peer->id,
task_message_size(MESSAGE_NOTINTERESTED));
/** @brief Send a handshake message to all the peers the peer has.
* @param peer peer data
*/
-void send_handshake_all(peer_t peer)
+void send_handshake_all(const s_peer_t* peer)
{
connection_t remote_peer;
xbt_dict_cursor_t cursor = NULL;
* @param peer peer data
* @param mailbox mailbox where to we send the message
*/
-void send_handshake(peer_t peer, const char* mailbox)
+void send_handshake(const s_peer_t* peer, const char* mailbox)
{
XBT_DEBUG("Sending a HANDSHAKE to %s", mailbox);
msg_task_t task = task_message_new(MESSAGE_HANDSHAKE, peer->hostname, peer->mailbox, peer->id,
}
/** Send a "choked" message to a peer. */
-void send_choked(peer_t peer, const char* mailbox)
+void send_choked(const s_peer_t* peer, const char* mailbox)
{
XBT_DEBUG("Sending a CHOKE to %s", mailbox);
msg_task_t task =
}
/** Send a "unchoked" message to a peer */
-void send_unchoked(peer_t peer, const char* mailbox)
+void send_unchoked(const s_peer_t* peer, const char* mailbox)
{
XBT_DEBUG("Sending a UNCHOKE to %s", mailbox);
msg_task_t task =
}
/** Send a "HAVE" message to all peers we are connected to */
-void send_have(peer_t peer, int piece)
+void send_have(const s_peer_t* peer, int piece)
{
XBT_DEBUG("Sending HAVE message to all my peers");
connection_t remote_peer;
/** @brief Send a bitfield message to all the peers the peer has.
* @param peer peer data
*/
-void send_bitfield(peer_t peer, const char* mailbox)
+void send_bitfield(const s_peer_t* peer, const char* mailbox)
{
XBT_DEBUG("Sending a BITFIELD to %s", mailbox);
msg_task_t task = task_message_bitfield_new(peer->hostname, peer->mailbox, peer->id, peer->bitfield, FILE_PIECES);
}
/** Send a "request" message to a pair, containing a request for a piece */
-void send_request(peer_t peer, const char* mailbox, int piece, int block_index, int block_length)
+void send_request(const s_peer_t* peer, const char* mailbox, int piece, int block_index, int block_length)
{
XBT_DEBUG("Sending a REQUEST to %s for piece %d (%d,%d)", mailbox, piece, block_index, block_length);
msg_task_t task = task_message_request_new(peer->hostname, peer->mailbox, peer->id, piece, block_index, block_length);
}
/** Send a "piece" message to a pair, containing a piece of the file */
-void send_piece(peer_t peer, const char* mailbox, int piece, int block_index, int block_length)
+void send_piece(const s_peer_t* peer, const char* mailbox, int piece, int block_index, int block_length)
{
XBT_DEBUG("Sending the PIECE %d (%d,%d) to %s", piece, block_index, block_length, mailbox);
xbt_assert(piece >= 0, "Tried to send a piece that doesn't exist.");