msg = args[1];
mbox = args[2];
}
- void operator()() /* This is the main code of the actor */
+ void operator()() const /* This is the main code of the actor */
{
XBT_INFO("Hello s4u, I have something to send");
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mbox);
XBT_INFO("Exiting now (done sleeping or got killed).");
});
}
- void operator()()
+ void operator()() const
{
XBT_INFO("Hello! I go to sleep.");
simgrid::s4u::this_actor::sleep_for(10);
public:
explicit yielder(std::vector<std::string> args) { number_of_yields = std::stod(args[1]); }
- void operator()()
+ void operator()() const
{
for (int i = 0; i < number_of_yields; i++)
simgrid::s4u::this_actor::yield();
}
}
-std::string Peer::getStatus()
+std::string Peer::getStatus() const
{
std::string res;
for (unsigned i = 0; i < FILE_PIECES; i++)
return res;
}
-bool Peer::hasFinished()
+bool Peer::hasFinished() const
{
return bitfield_ == (1U << FILE_PIECES) - 1U;
}
pieces_count[i]++;
}
-unsigned int Peer::countPieces(unsigned int bitfield)
+unsigned int Peer::countPieces(unsigned int bitfield) const
{
unsigned int count = 0U;
unsigned int n = bitfield;
return count;
}
-int Peer::nbInterestedPeers()
+int Peer::nbInterestedPeers() const
{
int nb = 0;
for (auto const& kv : connected_peers)
bitfield_blocks |= (1ULL << static_cast<unsigned int>(piece * PIECES_BLOCKS + i));
}
-bool Peer::hasCompletedPiece(unsigned int piece)
+bool Peer::hasCompletedPiece(unsigned int piece) const
{
for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
return true;
}
-int Peer::getFirstMissingBlockFrom(int piece)
+int Peer::getFirstMissingBlockFrom(int piece) const
{
for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
}
/** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
-int Peer::partiallyDownloadedPiece(const Connection* remote_peer)
+int Peer::partiallyDownloadedPiece(const Connection* remote_peer) const
{
for (unsigned int i = 0; i < FILE_PIECES; i++)
if (remotePeerHasMissingPiece(remote_peer, i) && isNotDownloadingPiece(i) && getFirstMissingBlockFrom(i) > 0)
Peer& operator=(const Peer&) = delete;
void operator()();
- std::string getStatus();
- bool hasFinished();
- int nbInterestedPeers();
+ std::string getStatus() const;
+ bool hasFinished() const;
+ int nbInterestedPeers() const;
bool isInterestedBy(const Connection* remote_peer) const;
bool isInterestedByFree(const Connection* remote_peer) const;
void updateActivePeersSet(Connection* remote_peer);
void updateChokedPeers();
bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
- bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece)
+ bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) const
{
return hasNotPiece(piece) && remote_peer->hasPiece(piece);
}
- bool hasCompletedPiece(unsigned int piece);
- unsigned int countPieces(unsigned int bitfield);
+ bool hasCompletedPiece(unsigned int piece) const;
+ unsigned int countPieces(unsigned int bitfield) const;
/** Check that a piece is not currently being download by the peer. */
bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
- int partiallyDownloadedPiece(const Connection* remote_peer);
+ int partiallyDownloadedPiece(const Connection* remote_peer) const;
void updatePiecesCountFromBitfield(unsigned int bitfield);
void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
void updateBitfieldBlocks(int piece, int block_index, int block_length);
- int getFirstMissingBlockFrom(int piece);
+ int getFirstMissingBlockFrom(int piece) const;
int selectPieceToDownload(const Connection* remote_peer);
void requestNewPieceTo(Connection* remote_peer);
public:
explicit TrackerQuery(int peer_id, simgrid::s4u::Mailbox* return_mailbox)
: peer_id(peer_id), return_mailbox(return_mailbox){};
- int getPeerId() { return peer_id; }
- simgrid::s4u::Mailbox* getReturnMailbox() { return return_mailbox; }
+ int getPeerId() const { return peer_id; }
+ simgrid::s4u::Mailbox* getReturnMailbox() const { return return_mailbox; }
};
class TrackerAnswer {
public:
explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ {}
void addPeer(int peer) { peers.insert(peer); }
- const std::set<int>& getPeers() { return peers; }
+ const std::set<int>& getPeers() const { return peers; }
};
class Tracker {
msg_size = std::stod(args[2]);
receivers_count = std::stol(args[3]);
}
- void operator()()
+ void operator()() const
{
// sphinx-doc: init-begin (this line helps the doc to build; ignore it)
/* Vector in which we store all ongoing communications */
msg_size = std::stod(args[2]);
receivers_count = std::stol(args[3]);
}
- void operator()()
+ void operator()() const
{
/* Vector in which we store all ongoing communications */
std::vector<simgrid::s4u::CommPtr> pending_comms;
}
/* Notifies a remote node that its predecessor may have changed. */
-void Node::remoteNotify(int notify_id, int predecessor_candidate_id)
+void Node::remoteNotify(int notify_id, int predecessor_candidate_id) const
{
ChordMessage* message = new ChordMessage(NOTIFY);
message->request_id = predecessor_candidate_id;
int remoteFindSuccessor(int ask_to, int id);
void notify(int predecessor_candidate_id);
- void remoteNotify(int notify_id, int predecessor_candidate_id);
+ void remoteNotify(int notify_id, int predecessor_candidate_id) const;
void stabilize();
void handleMessage(ChordMessage* message);
namespace kademlia {
/** @brief Prints a answer_t, for debugging purposes */
-void Answer::print()
+void Answer::print() const
{
XBT_INFO("Searching %08x, size %zu", destination_id_, nodes_.size());
unsigned int i = 0;
unsigned int getDestinationId() const { return destination_id_; }
size_t getSize() const { return nodes_.size(); }
const std::vector<std::pair<unsigned int, unsigned int>>& getNodes() const { return nodes_; }
- void print();
+ void print() const;
unsigned int merge(const Answer* a);
void trim();
bool destinationFound() const;
* @param id node we are querying
* @param destination node we are trying to find.
*/
-void Node::sendFindNode(unsigned int id, unsigned int destination)
+void Node::sendFindNode(unsigned int id, unsigned int destination) const
{
/* Gets the mailbox to send to */
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
* Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
* nodes
*/
-unsigned int Node::sendFindNodeToBest(const Answer* node_list)
+unsigned int Node::sendFindNodeToBest(const Answer* node_list) const
{
unsigned int i = 0;
unsigned int j = 0;
msg->answer_to_->put_init(answer, 1)->detach(kademlia::destroy);
}
-void Node::displaySuccessRate()
+void Node::displaySuccessRate() const
{
XBT_INFO("%u/%u FIND_NODE have succeeded", find_node_success, find_node_success + find_node_failed);
}
explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {}
Node(const Node&) = delete;
Node& operator=(const Node&) = delete;
- unsigned int getId() { return id_; }
+ unsigned int getId() const { return id_; }
bool join(unsigned int known_id);
- void sendFindNode(unsigned int id, unsigned int destination);
- unsigned int sendFindNodeToBest(const Answer* node_list);
+ void sendFindNode(unsigned int id, unsigned int destination) const;
+ unsigned int sendFindNodeToBest(const Answer* node_list) const;
void routingTableUpdate(unsigned int id);
Answer* findClosest(unsigned int destination_id);
bool findNode(unsigned int id_to_find, bool count_in_stats);
void randomLookup();
void handleFindNode(const Message* msg);
- void displaySuccessRate();
+ void displaySuccessRate() const;
};
} // namespace kademlia
// identifier functions
*/
class SingleCore {
public:
- bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
+ bool operator()(const simgrid::s4u::Host* host) const { return host->get_core_count() == 1; }
};
/* This functor is a bit more complex, as it saves the current state when created.
class MyHost {
public:
- void show_info(std::vector<simgrid::s4u::Disk*> const& disks)
+ void show_info(std::vector<simgrid::s4u::Disk*> const& disks) const
{
XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->get_cname());
}
}
- void operator()()
+ void operator()() const
{
std::vector<simgrid::s4u::Disk*> const& disks = simgrid::s4u::Host::current()->get_disks();
simgrid::xbt::replay_runner(actor_name, trace_filename);
}
- void operator()()
+ void operator()() const
{
// Nothing to do here
}
simgrid::xbt::replay_runner(actor_name, nullptr);
}
- void operator()()
+ void operator()() const
{
// Nothing to do here
}
class Receiver {
public:
- void operator()()
+ void operator()() const
{
XBT_INFO("Starting.");
auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
class Suspender {
public:
- void operator()()
+ void operator()() const
{
XBT_INFO("Suspend the receiver...");
receiver->suspend();