bool choked_upload = true; // Indicates if the peer is choked for the current peer
bool choked_download = true; // Indicates if the peer has choked the current peer
bool choked_upload = true; // Indicates if the peer is choked for the current peer
bool choked_download = true; // Indicates if the peer has choked the current peer
- explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::byName(std::to_string(id))){};
- ~Connection() = default;
+ explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){};
- RngStream stream;
- simgrid::s4u::MailboxPtr mailbox_;
- std::unordered_map<int, Connection*> connected_peers;
+ simgrid::xbt::random::XbtRandom random;
+ simgrid::s4u::Mailbox* mailbox_;
+ std::unordered_map<int, Connection> connected_peers;
std::set<Connection*> active_peers; // active peers list
unsigned int bitfield_ = 0; // list of pieces the peer has.
unsigned long long bitfield_blocks = 0; // list of blocks the peer has.
std::set<Connection*> active_peers; // active peers list
unsigned int bitfield_ = 0; // list of pieces the peer has.
unsigned long long bitfield_blocks = 0; // list of blocks the peer has.
unsigned int current_pieces = 0; // current pieces the peer is downloading
double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed.
int round_ = 0; // current round for the chocking algorithm.
simgrid::s4u::CommPtr comm_received = nullptr; // current comm
Message* message = nullptr; // current message being received
unsigned int current_pieces = 0; // current pieces the peer is downloading
double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed.
int round_ = 0; // current round for the chocking algorithm.
simgrid::s4u::CommPtr comm_received = nullptr; // current comm
Message* message = nullptr; // current message being received
- std::string getStatus();
- bool hasFinished();
- int nbInterestedPeers();
- bool isInterestedBy(Connection* remote_peer);
- bool isInterestedByFree(Connection* remote_peer);
+ std::string getStatus() const;
+ bool hasFinished() const;
+ int nbInterestedPeers() const;
+ bool isInterestedBy(const Connection* remote_peer) const;
+ bool isInterestedByFree(const Connection* remote_peer) const;
void updateActivePeersSet(Connection* remote_peer);
void updateInterestedAfterReceive();
void updateChokedPeers();
void updateActivePeersSet(Connection* remote_peer);
void updateInterestedAfterReceive();
void updateChokedPeers();
- bool hasNotPiece(unsigned int piece) { return not(bitfield_ & 1U << piece); }
- bool hasCompletedPiece(unsigned int piece);
- unsigned int countPieces(unsigned int bitfield);
+ bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
+ bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) const
+ {
+ return hasNotPiece(piece) && remote_peer->hasPiece(piece);
+ }
+ bool hasCompletedPiece(unsigned int piece) const;
+ unsigned int countPieces(unsigned int bitfield) const;
- bool isNotDownloadingPiece(unsigned int piece) { return not(current_pieces & 1U << piece); }
- int partiallyDownloadedPiece(Connection* remote_peer);
+ bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
+ int partiallyDownloadedPiece(const Connection* remote_peer) const;
void updatePiecesCountFromBitfield(unsigned int bitfield);
void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
void updateBitfieldBlocks(int piece, int block_index, int block_length);
void updatePiecesCountFromBitfield(unsigned int bitfield);
void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
void updateBitfieldBlocks(int piece, int block_index, int block_length);
- int getFirstMissingBlockFrom(int piece);
- int selectPieceToDownload(Connection* remote_peer);
+ int getFirstMissingBlockFrom(int piece) const;
+ int selectPieceToDownload(const Connection* remote_peer);
- void sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size);
- void sendBitfield(simgrid::s4u::MailboxPtr mailbox);
- void sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length);
+ void sendMessage(simgrid::s4u::Mailbox* mailbox, MessageType type, uint64_t size);
+ void sendBitfield(simgrid::s4u::Mailbox* mailbox);
+ void sendPiece(simgrid::s4u::Mailbox* mailbox, unsigned int piece, int block_index, int block_length);
void sendHandshakeToAllPeers();
void sendHaveToAllPeers(unsigned int piece);
void sendRequestTo(Connection* remote_peer, unsigned int piece);
void sendHandshakeToAllPeers();
void sendHaveToAllPeers(unsigned int piece);
void sendRequestTo(Connection* remote_peer, unsigned int piece);