/**
 * FUNCTION NAME: run
 *
 * DESCRIPTION: Main driver function of the Application layer
 */
int Application::run()
{
	int i;
	int timeWhenAllNodesHaveJoined = 0;
	// boolean indicating if all nodes have joined
	bool allNodesJoined = false;
	srand(time(NULL));

	// As time runs along
	for( par->globaltime = 0; par->globaltime < TOTAL_RUNNING_TIME; ++par->globaltime ) {
		// Run the membership protocol
		mp1Run();
		// Fail some nodes
		fail();
	}

	// Clean up
	en->ENcleanup();

	for(i=0;i<=par->EN_GPSZ-1;i++) {
		 mp1[i]->finishUpThisNode();
	}

	return SUCCESS;
}
/**
 * FUNCTION NAME: run
 *
 * DESCRIPTION: Main driver function of the Application layer
 */
int Application::run()
{
    int i;
    int timeWhenAllNodesHaveJoined = 0;
    // boolean indicating if all nodes have joined
    bool allNodesJoined = false;
    srand(time(NULL));

    // As time runs along
    for( par->globaltime = 0; par->globaltime < TOTAL_RUNNING_TIME; ++par->globaltime ) {
        // Run the membership protocol
        mp1Run();

        // Wait for all nodes to join
        if ( par->allNodesJoined == nodeCount && !allNodesJoined ) {
            timeWhenAllNodesHaveJoined = par->getcurrtime();
            allNodesJoined = true;
        }
        if ( par->getcurrtime() > timeWhenAllNodesHaveJoined + 50 ) {
            // Call the KV store functionalities
            mp2Run();
        }
        // Fail some nodes
        //fail();
    }

    // Clean up
    en->ENcleanup();
    en1->ENcleanup();

    for(i=0; i<=par->EN_GPSZ-1; i++) {
        mp1[i]->finishUpThisNode();
    }

    return SUCCESS;
}