X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b8df87e176f27b25534f27d7e240defa32ca35bc..61c32216a808376a5dbcf1fe166c14b6f7456af4:/examples/s4u/app-bittorrent/s4u-bittorrent.hpp diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp index 56222d145d..b2113cac89 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp @@ -10,38 +10,33 @@ #include #include -#define MAILBOX_SIZE 40 -#define TRACKER_MAILBOX "tracker_mailbox" +constexpr char TRACKER_MAILBOX[] = "tracker_mailbox"; /** Max number of peers sent by the tracker to clients */ -#define MAXIMUM_PEERS 50 +constexpr int MAXIMUM_PEERS = 50; /** Interval of time where the peer should send a request to the tracker */ -#define TRACKER_QUERY_INTERVAL 1000 +constexpr int TRACKER_QUERY_INTERVAL = 1000; /** Communication size for a task to the tracker */ -#define TRACKER_COMM_SIZE 1 -#define GET_PEERS_TIMEOUT 10000 -#define TIMEOUT_MESSAGE 10 -#define TRACKER_RECEIVE_TIMEOUT 10 +constexpr unsigned TRACKER_COMM_SIZE = 1; +constexpr double GET_PEERS_TIMEOUT = 10000.0; /** Number of peers that can be unchocked at a given time */ -#define MAX_UNCHOKED_PEERS 4 +constexpr int MAX_UNCHOKED_PEERS = 4; /** Interval between each update of the choked peers */ -#define UPDATE_CHOKED_INTERVAL 30 -/** Number of pieces the peer asks for simultaneously */ -#define MAX_PIECES 1 +constexpr int UPDATE_CHOKED_INTERVAL = 30; /** Message sizes * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective * http://hal.inria.fr/inria-00000156/en */ -#define MESSAGE_HANDSHAKE_SIZE 68 -#define MESSAGE_CHOKE_SIZE 5 -#define MESSAGE_UNCHOKE_SIZE 5 -#define MESSAGE_INTERESTED_SIZE 5 -#define MESSAGE_NOTINTERESTED_SIZE 5 -#define MESSAGE_HAVE_SIZE 9 -#define MESSAGE_BITFIELD_SIZE 5 -#define MESSAGE_REQUEST_SIZE 17 -#define MESSAGE_PIECE_SIZE 13 -#define MESSAGE_CANCEL_SIZE 17 +constexpr unsigned MESSAGE_HANDSHAKE_SIZE = 68; +constexpr unsigned MESSAGE_CHOKE_SIZE = 5; +constexpr unsigned MESSAGE_UNCHOKE_SIZE = 5; +constexpr unsigned MESSAGE_INTERESTED_SIZE = 5; +constexpr unsigned MESSAGE_NOTINTERESTED_SIZE = 5; +constexpr unsigned MESSAGE_HAVE_SIZE = 9; +constexpr unsigned MESSAGE_BITFIELD_SIZE = 5; +constexpr unsigned MESSAGE_REQUEST_SIZE = 17; +constexpr unsigned MESSAGE_PIECE_SIZE = 13; +constexpr unsigned MESSAGE_CANCEL_SIZE = 17; /** Types of messages exchanged between two peers. */ enum e_message_type { @@ -61,16 +56,16 @@ class Message { public: e_message_type type; int peer_id; - simgrid::s4u::MailboxPtr return_mailbox; + simgrid::s4u::Mailbox* return_mailbox; unsigned int bitfield = 0U; int piece = 0; int block_index = 0; int block_length = 0; - Message(e_message_type type, int peer_id, simgrid::s4u::MailboxPtr return_mailbox) + Message(e_message_type type, int peer_id, simgrid::s4u::Mailbox* return_mailbox) : type(type), peer_id(peer_id), return_mailbox(return_mailbox){}; - Message(e_message_type type, int peer_id, unsigned int bitfield, simgrid::s4u::MailboxPtr return_mailbox) + Message(e_message_type type, int peer_id, unsigned int bitfield, simgrid::s4u::Mailbox* return_mailbox) : type(type), peer_id(peer_id), return_mailbox(return_mailbox), bitfield(bitfield){}; - Message(e_message_type type, int peer_id, simgrid::s4u::MailboxPtr return_mailbox, int piece, int block_index, + Message(e_message_type type, int peer_id, simgrid::s4u::Mailbox* return_mailbox, int piece, int block_index, int block_length) : type(type) , peer_id(peer_id) @@ -78,13 +73,13 @@ public: , piece(piece) , block_index(block_index) , block_length(block_length){}; - Message(e_message_type type, int peer_id, simgrid::s4u::MailboxPtr return_mailbox, int piece) + Message(e_message_type type, int peer_id, simgrid::s4u::Mailbox* return_mailbox, int piece) : type(type), peer_id(peer_id), return_mailbox(return_mailbox), piece(piece){}; - ~Message() = default; }; class HostBittorrent { - RngStream stream_; + std::unique_ptr::type, std::function> stream_ = { + nullptr, [](RngStream stream) { RngStream_DeleteStream(&stream); }}; simgrid::s4u::Host* host = nullptr; public: @@ -93,12 +88,12 @@ public: explicit HostBittorrent(simgrid::s4u::Host* ptr) : host(ptr) { std::string descr = std::string("RngSream<") + host->get_cname() + ">"; - stream_ = RngStream_CreateStream(descr.c_str()); + stream_.reset(RngStream_CreateStream(descr.c_str())); } + HostBittorrent(const HostBittorrent&) = delete; + HostBittorrent& operator=(const HostBittorrent&) = delete; - ~HostBittorrent() { RngStream_DeleteStream(&stream_); }; - - RngStream getStream() { return stream_; }; + RngStream getStream() { return stream_.get(); }; }; #endif /* BITTORRENT_BITTORRENT_HPP_ */