main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "main.hpp"
  18. const std::string kDefault_file_path = "exp/PIRParams.cfg";
  19. int main(int argc, char* argv[])
  20. {
  21. std::cout << std::endl << "########################################################" << std::endl;
  22. std::cout << "# XPIR ... Private Information Retrieval for everyone #" << std::endl;
  23. std::cout << "########################################################" << std::endl << std::endl;
  24. int port = 1234;
  25. bool usedbgenerator = false;
  26. uint64_t dbgenerator_n = 10, dbgenerator_l = 12800000;
  27. int driven = -1;
  28. uint64_t split_value = 1;
  29. std::string pir_params_file_path(kDefault_file_path);
  30. po::options_description od("Available options");
  31. od.add_options()
  32. ("help,h", "help message")
  33. ("driven,z", po::value<std::string>()->implicit_value(pir_params_file_path),"Server-driven mode : configure crypto and PIR parameters using the first client, make them mandatory for other clients and save them into a persistent file.")
  34. ("load_file,L", po::value<std::string>(), "Load PIR parameters from file.")
  35. ("split_file,s", po::value<uint64_t>(&split_value)->default_value(1), "Only use first file in db directory and split it in arg elements.")
  36. ("port,p", po::value<int>(&port)->default_value(1234), "Port used, default")
  37. ("db-generator-files,n", po::value<uint64_t>(&dbgenerator_n)->default_value(10), "Number of files for the DB generator")
  38. ("db-generator-filesize,l", po::value<uint64_t>(&dbgenerator_l)->default_value(12800000), "Size of file for the DB generator")
  39. ("db-generator", "Generate the database instead of reading it from a directory")
  40. ("no-pipeline", "No pipeline mode");
  41. po::variables_map vm;
  42. try
  43. {
  44. po::store(po::parse_command_line(argc, argv, od), vm);
  45. }
  46. catch (const std::exception& ex)
  47. {
  48. std::cout << "Error checking program options: " << ex.what() << std::endl;
  49. std::cout << od << std::endl;
  50. return 1;
  51. }
  52. if (!vm.size())
  53. {
  54. std::cout << "No option specified : " << std::endl;
  55. std::cout << od << std::endl;
  56. }
  57. if (vm.count("help"))
  58. {
  59. std::cout << od << std::endl;
  60. return 0;
  61. }
  62. if (vm.count("driven"))
  63. {
  64. driven = 1;
  65. pir_params_file_path = vm["driven"].as<std::string>();
  66. }
  67. if (vm.count("load_file"))
  68. {
  69. pir_params_file_path = vm["load_file"].as<std::string>();
  70. driven = 0;
  71. }
  72. if (vm.count("split_file"))
  73. {
  74. split_value = vm["split_file"].as<uint64_t>();
  75. }
  76. if (vm.count("db-generator-files"))
  77. {
  78. dbgenerator_n = vm["db-generator-files"].as<uint64_t>();
  79. }
  80. if (vm.count("db-generator-filesize"))
  81. {
  82. dbgenerator_l = vm["db-generator-filesize"].as<uint64_t>();
  83. }
  84. if (vm.count("db-generator"))
  85. {
  86. std::cout << "CLI: DBGenerator requested with params n=" << dbgenerator_n
  87. << " l=" << dbgenerator_l << std::endl;
  88. usedbgenerator = true;
  89. }
  90. try
  91. {
  92. boost::asio::io_service io_service;
  93. boost::asio::signal_set signals(io_service, SIGINT, SIGTERM);
  94. signals.async_wait(
  95. boost::bind(&boost::asio::io_service::stop, &io_service));
  96. PIRServer server(io_service, port, split_value, usedbgenerator, dbgenerator_n, dbgenerator_l);
  97. if (vm.count("no-pipeline"))
  98. {
  99. std::cout << "Main: WARNING no pipeline mode activated" << std::endl;
  100. server.no_pipeline(true);
  101. }
  102. if (driven == 1) server.processDrivenSession(pir_params_file_path);
  103. else if (driven == 0) server.readPIRParamsFromFile(pir_params_file_path);
  104. server.serve();
  105. io_service.run();
  106. cout << "Main: PIRServer has stopped" << endl;
  107. }
  108. catch (std::exception& e)
  109. {
  110. std::cerr << "Exception catched in main.cpp " << e.what() << std::endl;
  111. }
  112. }