]> AND Public Git Repository - simgrid.git/blobdiff - examples/s4u/app-bittorrent/s4u-peer.hpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix ns3
[simgrid.git] / examples / s4u / app-bittorrent / s4u-peer.hpp
index 428283007a63360fb1f46bb41564274c916be2d1..0175e26fb79b63a68a616ce88ba72c3ca57b5fef 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2019. The SimGrid Team.
+/* Copyright (c) 2012-2020. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -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
@@ -44,6 +45,7 @@ class Peer {
 
   simgrid::s4u::CommPtr comm_received = nullptr; // current comm
   Message* message                    = nullptr; // current message being received
+
 public:
   explicit Peer(std::vector<std::string> args);
   Peer(const Peer&) = delete;
@@ -60,16 +62,20 @@ public:
   void updateChokedPeers();
 
   bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
+  bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece)
+  {
+    return hasNotPiece(piece) && remote_peer->hasPiece(piece);
+  }
   bool hasCompletedPiece(unsigned int piece);
   unsigned int countPieces(unsigned int bitfield);
   /** 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(Connection* remote_peer);
+  int partiallyDownloadedPiece(const Connection* remote_peer);
   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 selectPieceToDownload(const Connection* remote_peer);
   void requestNewPieceTo(Connection* remote_peer);
 
   bool getPeersFromTracker();