Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bebc397d1514320ff7275581ce1be1e67fe4dcce
[simgrid.git] / examples / s4u / app-bittorrent / s4u_tracker.hpp
1 /* Copyright (c) 2012-2014, 2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef BITTORRENT_TRACKER_HPP_
8 #define BITTORRENT_TRACKER_HPP_
9
10 #include "s4u_bittorrent.hpp"
11 #include <set>
12
13 class TrackerQuery {
14   int peer_id; // peer id
15   simgrid::s4u::MailboxPtr return_mailbox;
16 public:
17   explicit TrackerQuery(int peer_id, simgrid::s4u::MailboxPtr return_mailbox)
18       : peer_id(peer_id), return_mailbox(return_mailbox){};
19   ~TrackerQuery() = default;
20   int getPeerId() { return peer_id; }
21   simgrid::s4u::MailboxPtr getReturnMailbox() { return return_mailbox; }
22 };
23
24 class TrackerAnswer {
25   // int interval; // how often the peer should contact the tracker (unused for now)
26   std::set<int>* peers; // the peer list the peer has asked for.
27 public:
28   explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ { peers = new std::set<int>; }
29   TrackerAnswer(const TrackerAnswer&)                               = delete;
30   ~TrackerAnswer() { delete peers; };
31   void addPeer(int peer) { peers->insert(peer); }
32   std::set<int>* getPeers() { return peers; }
33 };
34
35 class Tracker {
36   double deadline;
37   RngStream stream;
38   simgrid::s4u::MailboxPtr mailbox;
39   std::set<int> known_peers;
40
41 public:
42   explicit Tracker(std::vector<std::string> args);
43   void operator()();
44 };
45
46 #endif /* BITTORRENT_TRACKER_HPP */