PIROptimizer.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef DEF_PIROPTIM
  18. #define DEF_PITOPTIM
  19. #include <iostream>
  20. #include <sstream>
  21. #include <string>
  22. #include <map>
  23. #include "crypto/HomomorphicCryptoFactory_internal.hpp"
  24. #include "pir/optim/OptimService.hpp"
  25. #include "apps/server/PIRServer.hpp"
  26. #include "pir/PIROptimizerCommand.hpp"
  27. #define COMMAND_AND_CONTROL_PORT 1235
  28. #define MEGA_BYTE 1000000
  29. #define MAX_D 10
  30. using boost::asio::ip::tcp;
  31. typedef boost::shared_ptr<boost::asio::ip::tcp::socket> socket_ptr;
  32. class PIROptimizer
  33. {
  34. private:
  35. std::vector<std::string> abs1bitCacheLines;
  36. boost::asio::io_service io_service;
  37. PIRParameters pirParameters;
  38. uint64_t fileCount;
  39. uint64_t maxFileBytesize;
  40. string pir;
  41. string filePath;
  42. void serve();
  43. double getAbs1PlaintextTime(HomomorphicCrypto* crypto_ptr, GenericPIRReplyGenerator* generator_ptr);
  44. double getPrecompute1PlaintextTime(HomomorphicCrypto* crypto_ptr, GenericPIRReplyGenerator* generator_ptr);
  45. void sendDatabaseInfos(boost::asio::ip::tcp::socket& s);
  46. public:
  47. PIROptimizer(DBHandler *db);
  48. ~PIROptimizer();
  49. void speedTest(boost::asio::ip::tcp::socket& s);
  50. void controlAndCommand(boost::asio::ip::tcp::socket& s);
  51. unsigned int sendAbsAndPrecomputeCaches(boost::asio::ip::tcp::socket& s);
  52. double launcheAbs1BitBench();
  53. void processCommand(socket_ptr s, size_t& cmd);
  54. void optimize();
  55. void prepareOptimData();
  56. std::string computeOptimData(const std::string& crypto_name);
  57. };
  58. #endif