Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check argc.
[simgrid.git] / examples / s4u / app-bittorrent / s4u-peer.hpp
index b71ae28d6f5ea20e51e79c57821306e1b6b4df04..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,6 +62,10 @@ 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. */