Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rewrite bittorrent example in s4u
[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   int uploaded;   // how much the peer has already uploaded
17   int downloaded; // how much the peer has downloaded
18   int left;       // how much the peer has left
19 public:
20   explicit TrackerQuery(int peer_id, simgrid::s4u::MailboxPtr return_mailbox, int uploaded, int downloaded, int left)
21       : peer_id(peer_id), return_mailbox(return_mailbox), uploaded(uploaded), downloaded(downloaded), left(left){};
22   ~TrackerQuery() = default;
23   int getPeerId() { return peer_id; }
24   simgrid::s4u::MailboxPtr getReturnMailbox() { return return_mailbox; }
25 };
26
27 class TrackerAnswer {
28   int interval;         // how often the peer should contact the tracker (unused for now)
29   std::set<int>* peers; // the peer list the peer has asked for.
30 public:
31   explicit TrackerAnswer(int interval) : interval(interval) { peers = new std::set<int>; }
32   ~TrackerAnswer() { delete peers; };
33   void addPeer(int peer) { peers->insert(peer); }
34   std::set<int>* getPeers() { return peers; }
35 };
36
37 class Tracker {
38   double deadline;
39   RngStream stream;
40   simgrid::s4u::MailboxPtr mailbox;
41   std::set<int> known_peers;
42
43 public:
44   explicit Tracker(std::vector<std::string> args);
45   void operator()();
46 };
47
48 #endif /* BITTORRENT_TRACKER_HPP */