/** @brief Handles an incoming received task */
void handle_task(node_t node, msg_task_t task)
{
- task_data_t data = MSG_task_get_data(task);
+ const_task_data_t data = MSG_task_get_data(task);
xbt_assert((data != NULL), "Received NULL data");
//Adding/updating the guy to our routing table
node_routing_table_update(node, data->sender_id);
*/
void node_routing_table_update(const_node_t node, unsigned int id)
{
- routing_table_t table = node->table;
+ const_routing_table_t table = node->table;
//retrieval of the bucket in which the should be
- bucket_t bucket = routing_table_find_bucket(table, id);
+ const_bucket_t bucket = routing_table_find_bucket(table, id);
//check if the id is already in the bucket.
unsigned int id_pos = bucket_find_id(bucket, id);
int i;
answer_t answer = answer_init(destination_id);
/* We find the corresponding bucket for the id */
- bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
+ const_bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
int bucket_id = bucket->id;
xbt_assert((bucket_id <= IDENTIFIER_SIZE), "Bucket found has a wrong identifier");
/* So, we copy the contents of the bucket unsigned into our result dynar */
for (i = 1; answer->size < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
/* We check the previous buckets */
if (bucket_id - i >= 0) {
- bucket_t bucket_p = &node->table->buckets[bucket_id - i];
+ const_bucket_t bucket_p = &node->table->buckets[bucket_id - i];
answer_add_bucket(bucket_p, answer);
}
/* We check the next buckets */
if (bucket_id + i <= IDENTIFIER_SIZE) {
- bucket_t bucket_n = &node->table->buckets[bucket_id + i];
+ const_bucket_t bucket_n = &node->table->buckets[bucket_id + i];
answer_add_bucket(bucket_n, answer);
}
}
}
/* Find the next node to forward a message to */
-static int routing_next(node_t node, int dest) {
+static int routing_next(const_node_t node, int dest)
+{
int closest = closest_in_namespace_set(node, dest);
if (closest!=-1)
return closest;
sg_host_data_set(host, attr);
}
-static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax)
+static xbt_dynar_t get_ready_tasks(const_xbt_dynar_t dax)
{
unsigned int i;
xbt_dynar_t ready_tasks;
* @param remote_peer: information about the connection
* @return the piece to download if possible. -1 otherwise
*/
-int Peer::selectPieceToDownload(Connection* remote_peer)
+int Peer::selectPieceToDownload(const Connection* remote_peer)
{
int piece = partiallyDownloadedPiece(remote_peer);
// strict priority policy
}
/** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
-int Peer::partiallyDownloadedPiece(Connection* remote_peer)
+int Peer::partiallyDownloadedPiece(const Connection* remote_peer)
{
for (unsigned int i = 0; i < FILE_PIECES; i++)
if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i) && getFirstMissingBlockFrom(i) > 0)
unsigned int countPieces(unsigned int bitfield);
/** 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(Connection* remote_peer);
+ int partiallyDownloadedPiece(const Connection* remote_peer);
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 selectPieceToDownload(Connection* remote_peer);
+ int selectPieceToDownload(const Connection* remote_peer);
void requestNewPieceTo(Connection* remote_peer);
bool getPeersFromTracker();
XBT_DEBUG("Received an answer from the node I know.");
got_answer = true;
// retrieve the node list and ping them.
- Message* msg = static_cast<Message*>(received_msg);
+ const Message* msg = static_cast<Message*>(received_msg);
node_list = msg->answer_;
if (node_list) {
for (auto contact : node_list->nodes)
receive_comm = mailbox->get_async(&received_msg);
if (receive_comm->test()) {
- Message* msg = static_cast<Message*>(received_msg);
+ const Message* msg = static_cast<Message*>(received_msg);
// Check if what we have received is what we are looking for.
if (msg->answer_ && msg->answer_->getDestinationId() == id_to_find) {
routingTableUpdate(msg->sender_id_);
if (node->receive_comm->test()) {
// There has been a message, we need to handle it !
- kademlia::Message* msg = static_cast<kademlia::Message*>(node->received_msg);
+ const kademlia::Message* msg = static_cast<kademlia::Message*>(node->received_msg);
if (msg) {
node->handleFindNode(msg);
delete msg->answer_;
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls, jint pid)
{
- msg_process_t process = MSG_process_from_PID(pid);
+ auto const* process = MSG_process_from_PID(pid);
if (not process) {
jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast<int>(pid)));
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) {
- msg_process_t process;
-
msg_task_t task = jtask_to_native(jtask, env);
if (not task) {
return nullptr;
}
- process = MSG_task_get_sender(task);
+ auto const* process = MSG_task_get_sender(task);
if (process == nullptr) {
return nullptr;
}
}
/* initialize graph indexes in nodes after graph has been built */
- xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_);
+ const_xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_);
xbt_dynar_foreach (nodes, cursor, node) {
GraphNodeData* data = static_cast<GraphNodeData*>(xbt_graph_node_get_data(node));