1 /* Copyright (c) 2012-2021. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef BITTORRENT_BITTORRENT_HPP_
8 #define BITTORRENT_BITTORRENT_HPP_
10 #include <simgrid/s4u.hpp>
11 #include <xbt/random.hpp>
13 constexpr char TRACKER_MAILBOX[] = "tracker_mailbox";
14 /** Max number of peers sent by the tracker to clients */
15 constexpr int MAXIMUM_PEERS = 50;
16 /** Interval of time where the peer should send a request to the tracker */
17 constexpr int TRACKER_QUERY_INTERVAL = 1000;
18 /** Communication size for a task to the tracker */
19 constexpr unsigned TRACKER_COMM_SIZE = 1;
20 constexpr double GET_PEERS_TIMEOUT = 10000.0;
21 /** Number of peers that can be unchocked at a given time */
22 constexpr int MAX_UNCHOKED_PEERS = 4;
23 /** Interval between each update of the choked peers */
24 constexpr int UPDATE_CHOKED_INTERVAL = 30;
26 /** Types of messages exchanged between two peers. */
27 enum class MessageType { HANDSHAKE, CHOKE, UNCHOKE, INTERESTED, NOTINTERESTED, HAVE, BITFIELD, REQUEST, PIECE, CANCEL };
33 simgrid::s4u::Mailbox* return_mailbox;
34 unsigned int bitfield = 0U;
38 Message(MessageType type, int peer_id, simgrid::s4u::Mailbox* return_mailbox)
39 : type(type), peer_id(peer_id), return_mailbox(return_mailbox){};
40 Message(MessageType type, int peer_id, unsigned int bitfield, simgrid::s4u::Mailbox* return_mailbox)
41 : type(type), peer_id(peer_id), return_mailbox(return_mailbox), bitfield(bitfield){};
42 Message(MessageType type, int peer_id, simgrid::s4u::Mailbox* return_mailbox, int piece, int block_index,
46 , return_mailbox(return_mailbox)
48 , block_index(block_index)
49 , block_length(block_length){};
50 Message(MessageType type, int peer_id, simgrid::s4u::Mailbox* return_mailbox, int piece)
51 : type(type), peer_id(peer_id), return_mailbox(return_mailbox), piece(piece){};
54 #endif /* BITTORRENT_BITTORRENT_HPP_ */