Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enum class in examples/s4u/app-bittorrent/.
[simgrid.git] / examples / s4u / app-bittorrent / s4u-peer.hpp
index 9b912bb..a9ea46b 100644 (file)
@@ -31,6 +31,7 @@ public:
 class Peer {
   int id;
   double deadline;
+  simgrid::xbt::random::XbtRandom random;
   simgrid::s4u::Mailbox* mailbox_;
   std::unordered_map<int, Connection> connected_peers;
   std::set<Connection*> active_peers; // active peers list
@@ -51,9 +52,9 @@ public:
   Peer& operator=(const Peer&) = delete;
   void operator()();
 
-  std::string getStatus();
-  bool hasFinished();
-  int nbInterestedPeers();
+  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);
@@ -61,24 +62,24 @@ public:
   void updateChokedPeers();
 
   bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
-  bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece)
+  bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) const
   {
     return hasNotPiece(piece) && remote_peer->hasPiece(piece);
   }
-  bool hasCompletedPiece(unsigned int piece);
-  unsigned int countPieces(unsigned int bitfield);
+  bool hasCompletedPiece(unsigned int piece) const;
+  unsigned int countPieces(unsigned int bitfield) const;
   /** Check that a piece is not currently being download by the peer. */
   bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
-  int partiallyDownloadedPiece(const Connection* remote_peer);
+  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);
-  int getFirstMissingBlockFrom(int piece);
+  int getFirstMissingBlockFrom(int piece) const;
   int selectPieceToDownload(const Connection* remote_peer);
   void requestNewPieceTo(Connection* remote_peer);
 
   bool getPeersFromTracker();
-  void sendMessage(simgrid::s4u::Mailbox* mailbox, e_message_type type, uint64_t size);
+  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();