PIRSession.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_PIRSESSION
  18. #define DEF_PIRSESSION
  19. #include <vector>
  20. #include <iostream>
  21. #include <dirent.h>
  22. #include <boost/asio.hpp>
  23. #include <boost/thread.hpp>
  24. #include <boost/shared_ptr.hpp>
  25. #include <boost/algorithm/string.hpp>
  26. #include "pir/dbhandlers/DBHandler.hpp"
  27. #include "pir/PIRParameters.hpp"
  28. #include "pir/replyGenerator/PIRReplyGeneratorFactory.hpp"
  29. #include "crypto/HomomorphicCryptoFactory_internal.hpp"
  30. #include "pir/PIRParametersExchangeMethods.hpp"
  31. #include "pir/GlobalConstant.hpp"
  32. #include "pir/shared_queue.hpp"
  33. #define DEFAULT_DIR_NAME "db/"
  34. #define MAX_ATTEMPT 10
  35. #define DEFAULT_PORT 1234
  36. #define RED "\033[31m"
  37. #define BOLD "\033[1;30m"
  38. #define ORANGE "\033[33m"
  39. #define RESET_COLOR "\033[m"
  40. using boost::asio::ip::tcp;
  41. struct session_option_t {
  42. bool driven_mode;
  43. bool keep_database;
  44. bool got_preimported_database;
  45. imported_database_t data;
  46. };
  47. class PIRSession : public boost::enable_shared_from_this<PIRSession>
  48. {
  49. private:
  50. DBHandler *dbhandler;
  51. tcp::socket sessionSocket;
  52. boost::thread upThread, downThread;
  53. bool handmadeExceptionRaised;
  54. bool finished;
  55. PIRParameters pirParam;
  56. CryptographicSystem* cryptoMethod;
  57. GenericPIRReplyGenerator* generator;
  58. uint64_t maxFileBytesize; // La taille totale de la base de donnée en octets
  59. void serveForever();
  60. void rcvCryptoParams(bool paramsandkey);
  61. void sendCryptoParams();
  62. void sendPIRParamsExchangeMethod(short exchange_method);
  63. void rcvPirParams();
  64. void sendPirParams();
  65. void sendCatalog();
  66. void recieveKey();
  67. void startProcessQuery ();
  68. void startProcessResult(session_option_t session_option);
  69. bool rcvIsClient();
  70. void downloadWorker();
  71. void uploadWorker();
  72. imported_database_t savedDatabase;
  73. bool no_pipeline_mode;
  74. public:
  75. typedef boost::shared_ptr<PIRSession> pointer;
  76. static pointer create(boost::asio::io_service& ios);
  77. PIRSession(boost::asio::io_service& ios);
  78. ~PIRSession();
  79. void setDBHandler(DBHandler *db);
  80. void writeErrorMessage(string, string);
  81. void writeWarningMessage(string, string);
  82. void exitWithErrorMessage(string, string);
  83. bool isFinished();
  84. tcp::socket& getSessionSocket();
  85. bool start(session_option_t session_option);
  86. PIRParameters getPIRParams();
  87. void setPIRParams(PIRParameters pir_parameters);
  88. imported_database_t getSavedDatabase();
  89. void no_pipeline(bool b);
  90. };
  91. #endif