Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Remove custom destructors for examples/s4u/.
[simgrid.git] / examples / s4u / app-bittorrent / s4u-tracker.hpp
1 /* Copyright (c) 2012-2019. 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::Mailbox* return_mailbox;
16
17 public:
18   explicit TrackerQuery(int peer_id, simgrid::s4u::Mailbox* return_mailbox)
19       : peer_id(peer_id), return_mailbox(return_mailbox){};
20   int getPeerId() { return peer_id; }
21   simgrid::s4u::Mailbox* 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)*/ {}
29   void addPeer(int peer) { peers.insert(peer); }
30   const std::set<int>& getPeers() { return peers; }
31 };
32
33 class Tracker {
34   double deadline;
35   RngStream stream;
36   simgrid::s4u::Mailbox* mailbox;
37   std::set<int> known_peers;
38
39 public:
40   explicit Tracker(std::vector<std::string> args);
41   void operator()();
42 };
43
44 #endif /* BITTORRENT_TRACKER_HPP */