+ INFO0("Joining the system");
+ // find my predecessor and successor
+ int pred;
+ int suc = remote_find_predecessor(node, known_id, node->id);
+ do {
+ pred = suc;
+ suc = remote_find_successor(node, pred, pred);
+ } while (!is_in_interval(node->id, pred + 1, suc));
+
+ set_finger(node, 0, suc);
+ set_predecessor(node, pred);
+ remote_notify(node, pred);
+ remote_notify(node, suc);
+ bootstrap(node, suc);
+}
+
+/**
+ * \brief Notifies the current node that a node has just joined the network.
+ * \param node the current node
+ * \param new_node_id id of the new node in the network
+ */
+static void notify(node_t node, int new_node_id)
+{
+ INFO1("A new node %d has joined the network, let's see if it is a neighboor", new_node_id);
+ if (is_in_interval(new_node_id, node->id + 1, node->fingers[0].id - 1)) {
+ // new_node_id is my new successor
+ set_finger(node, 0, new_node_id);
+ bootstrap(node, new_node_id);
+ }
+
+ if (is_in_interval(new_node_id, node->pred_id + 1, node->id - 1)) {
+ // new_node_id is my new predecessor
+ set_predecessor(node, new_node_id);
+ bootstrap(node, new_node_id);
+ }
+}
+
+/**
+ * \brief Notifies a remote node that the current node has just joined
+ * the network.
+ * \param node the current node
+ * \param notify_id id of the remote node to notify
+ */
+static void remote_notify(node_t node, int notify_id)
+{
+ task_data_t req_data = xbt_new0(s_task_data_t, 1);
+ req_data->request_id = node->id;
+ req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
+
+ // send a "Notify" request to notify_id
+ INFO2("Sending a 'Notify' request to %d because I have joined the network with id %d", notify_id, node->id);
+ m_task_t task = MSG_task_create("Notify", 1000, 5000, req_data);
+ char* mailbox = get_mailbox(notify_id);
+ msg_comm_t comm = MSG_task_isend(task, mailbox);
+ xbt_dynar_push(node->comms, &comm);
+ xbt_free(mailbox);
+}
+
+/**
+* \brief Let the current node send queries to fill in its own finger table.
+* \param node the current node
+* \param ask_to_id id of a node to send queries to
+*/
+static void bootstrap(node_t node, int ask_to_id)
+{
+ INFO0("Filling my finger table");
+ int i, pred_id, succ_id;
+ int pow = 1;
+
+ for (i = 0; i < NB_BITS; i++)
+ {
+ pred_id = remote_find_successor(node, ask_to_id, pow);
+ do {
+ succ_id = pred_id;
+ pred_id = remote_find_predecessor(node, pred_id, pred_id);
+ } while (pred_id >= pow);
+
+ pow = pow << 1;
+ set_finger(node, i, succ_id);
+ }