+int nb_interested_peers(peer_t peer)
+{
+ xbt_dict_cursor_t cursor = NULL;
+ char *key;
+ connection_t connection;
+ int nb = 0;
+ xbt_dict_foreach(peer->peers, cursor, key, connection) {
+ if (connection->interested)
+ nb++;
+ }
+ return nb;
+}
+
+/**
+ * Handle pending sends and remove those which are done
+ * @param peer Peer data
+ */
+void handle_pending_sends(peer_t peer)
+{
+ int index;
+
+ while ((index = MSG_comm_testany(peer->pending_sends)) != -1) {
+ msg_comm_t comm_send =
+ xbt_dynar_get_as(peer->pending_sends, index, msg_comm_t);
+ int status = MSG_comm_get_status(comm_send);
+ xbt_dynar_remove_at(peer->pending_sends, index, &comm_send);
+ XBT_DEBUG
+ ("Communication %p is finished with status %d, dynar size is now %lu",
+ comm_send, status, xbt_dynar_length(peer->pending_sends));
+
+ msg_task_t task = MSG_comm_get_task(comm_send);
+ MSG_comm_destroy(comm_send);
+
+ if (status != MSG_OK) {
+ task_message_free(task);
+ }
+ }
+}
+
+void update_active_peers_set(peer_t peer, connection_t remote_peer)
+{
+
+ if (remote_peer->interested && !remote_peer->choked_upload) {
+ //add in the active peers set
+ xbt_dict_set_ext(peer->active_peers, (char *) &remote_peer->id,
+ sizeof(int), remote_peer, NULL);
+ } else {
+ //remove
+ xbt_ex_t e;
+ TRY {
+ xbt_dict_remove_ext(peer->active_peers, (char *) &remote_peer->id,
+ sizeof(int));
+ }
+ CATCH(e) {
+ xbt_ex_free(e);
+ }
+ }
+}
+
+