Esempio n. 1
0
/********************************************************
 * main
 ********************************************************/
int main(int argc , char *argv[])
{
	server1();
	//server2();

	return 0;
}
void SelectServerScene::onLButtonDown(int x, int y)
{
	if(x > 139 && x < (139+138)) // ABADDON Button
	{
		if(y > 176 && y < (176+19))
		{
			selectServerFocus = ABADDON;
			server1();
		}
	}

	if(x > 131 && x < (139+157)) // APOCALYPSE Button
	{
		if(y > 204 && y < (204+19))
		{
			selectServerFocus = APOCALYPSE;
			server2();
		}
	}

	if(x > 256 && x < (256+76)) // Cancel Button
	{
		if(y > 282 && y < (282+20))
		{
			cancel();
		}
	}
}
int main ()
{
   std::atomic <uint16_t> response_count (0);

   paxos::server::callback_type callback =
      [& response_count](int64_t, std::string const & workload) -> std::string
      {
         ++response_count;

         return "bar";
      };

   paxos::configuration configuration;
   configuration.set_strategy_factory (new test_strategy_factory (configuration.durable_storage ()));

   paxos::server server1 ("127.0.0.1", 1337, callback);
   paxos::server server2 ("127.0.0.1", 1338, callback);
   paxos::server server3 ("127.0.0.1", 1339, callback, configuration);
   paxos::client client;

   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   /*!
     This would be retried and shouldn't cause any troubles.
    */
   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   PAXOS_ASSERT_EQ (response_count, 2);

   PAXOS_INFO ("test succeeded");   
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
  /*
    client1: nodeID B -> msg state
    server1: b nodeID msg N -> msg keys
    client2: state msg N -> keys
  */
  if (argc < 2) {
    fprintf(stderr, "I need arguments. Read source for more info.\n");
    return 1;
  }

  curve25519_init();
  if (!strcmp(argv[1], "client1")) {
    return client1(argc, argv);
  } else if (!strcmp(argv[1], "server1")) {
    return server1(argc, argv);
  } else if (!strcmp(argv[1], "client2")) {
    return client2(argc, argv);
  } else {
    fprintf(stderr, "What's a %s?\n", argv[1]);
    return 1;
  }
}
void SelectServerScene::server2()
{
#ifdef DEF_SELECTSERVER
	SoundBank::manager.play("E14");
	Game::getInstance().changeScene(new LoginScene(DEF_SERVER_NAME2));
#else
	server1();
#endif
}
void SelectServerScene::onKeyDown(SDLKey Sym, SDLMod Mod, Uint16 Unicode)
{
	if(Sym == SDLK_ESCAPE)
	{
		Game::getInstance().changeScene(new MenuScene);
	}

	if(Sym == SDLK_RETURN)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			server1();
			break;
		case APOCALYPSE:
			server2();
			break;
		case CANCEL:
			cancel();
			break;
		}
	}

	if(Sym == SDLK_UP)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			selectServerFocus = CANCEL;
			break;
		case APOCALYPSE:
			selectServerFocus = ABADDON;
			break;
		case CANCEL:
			selectServerFocus = APOCALYPSE;
			break;
		}
	}

	if(Sym == SDLK_DOWN || Sym == SDLK_TAB)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			selectServerFocus = APOCALYPSE;
			break;
		case APOCALYPSE:
			selectServerFocus = CANCEL;
			break;
		case CANCEL:
			selectServerFocus = ABADDON;
			break;
		}
	}
}
Esempio n. 7
0
int main ()
{
   paxos::configuration configuration1;
   paxos::configuration configuration2;
   paxos::configuration configuration3;

   configuration1.durable_storage ().set_history_size (5);
   configuration2.durable_storage ().set_history_size (5);
   configuration3.durable_storage ().set_history_size (5);

   paxos::server::callback_type callback = 
      [](
         int64_t                promise_id,
         std::string const &    workload) -> std::string
      {
         return "bar";
      };

   paxos::client client;
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);
   paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);
   
   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   {
      paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
      server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
    
      /*!
        Issue 10 calls, so we can verify that the lowest proposal id is in fact 10.
       */
      for (size_t i = 0; i < 15; ++i)
      {
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
      }

      PAXOS_ASSERT_EQ (configuration1.durable_storage ().lowest_proposal_id (), 11);
      PAXOS_ASSERT_EQ (configuration2.durable_storage ().lowest_proposal_id (), 11);
      PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 11);
   }
   
   /*!
     Now, since one host in our quorum is currently down, logs should *not* be cleaned
     up further than the proposal that has been previously accepted by that host.
    */

   for (size_t i = 0; i < 30; ++i)
   {
      PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   }

   PAXOS_ASSERT_GE (configuration1.durable_storage ().lowest_proposal_id (), 15);
   PAXOS_ASSERT_GE (configuration2.durable_storage ().lowest_proposal_id (), 15);
   PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 11);

   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   {
      /*!
        And after our server is back online, the history can be cleared again.
       */

      paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
      server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
    
      for (size_t i = 0; i < 15; ++i)
      {
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
      }

      PAXOS_ASSERT_EQ (configuration1.durable_storage ().lowest_proposal_id (), 56);
      PAXOS_ASSERT_EQ (configuration2.durable_storage ().lowest_proposal_id (), 56);
      PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 56);
   }


   
   PAXOS_INFO ("test succeeded");
}
Esempio n. 8
0
int main ()
{
   std::map <int64_t, uint16_t> responses;

   /*!
     Synchronizes access to responses
    */
   boost::mutex mutex;

   paxos::configuration configuration1;
   paxos::configuration configuration2;
   paxos::configuration configuration3;

   /*!
     Note that the configuration objects below outlive the server objects declared later in
     the test, thus providing semi-durable storage.
    */
   configuration1.set_durable_storage (
      new paxos::durable::heap ());
   configuration2.set_durable_storage (
      new paxos::durable::heap ());
   configuration3.set_durable_storage (
      new paxos::durable::heap ());

   paxos::server::callback_type callback = 
      [& responses,
       & mutex](
         int64_t                promise_id,
         std::string const &    workload) -> std::string
      {
         boost::mutex::scoped_lock lock (mutex);

         if (responses.find (promise_id) == responses.end ())
         {
            responses[promise_id] = 1;
         }
         else
         {
            responses[promise_id]++;
         }

         PAXOS_ASSERT (responses[promise_id] <= 3);

         return "bar";
      };

   paxos::client client;
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   {
      paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);

      server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

      {
         paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);

         server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

         {
            paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);

            server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

            PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
            PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
            PAXOS_ASSERT_EQ (all_responses_equal (responses, 3), true);
         }



         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
         PAXOS_ASSERT_EQ (all_responses_equal (responses, 3), false);
      }

      PAXOS_ASSERT_THROW (client.send ("foo").get (), paxos::exception::no_majority);
   }

   /*!
     Note that we're re-adding servers in reverse order here; this is to ensure that
     server3 doesn't become our leader while it's lagging behind.
    */
   paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
   server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   
   PAXOS_ASSERT_THROW (client.send ("foo").get (), paxos::exception::no_majority);

   paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");

   paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);
   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});


   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   do
   {
      PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");   
      
   } while (all_responses_equal (responses, 3) == false);

   PAXOS_INFO ("test succeeded");
}