PIRClient.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_PIRCLIENT
  18. #define DEF_PIRCLIENT
  19. //#define DEBUG
  20. #include <string>
  21. #include <iostream>
  22. #include <boost/asio.hpp>
  23. #include <boost/thread.hpp>
  24. #include <boost/signals2.hpp>
  25. #include "DESC.hpp"
  26. #include "crypto/NFLLWE.hpp"
  27. #include "pir/queryGen/PIRQueryGenerator_internal.hpp"
  28. #include "pir/PIRParameters.hpp"
  29. #include "pir/replyExtraction/PIRReplyExtraction_internal.hpp"
  30. #include "pir/replyExtraction/PIRReplyWriter.hpp"
  31. #include "apps/optim/PIROptimizer.hpp"
  32. #include "pir/events/WriteEvent.hpp"
  33. #include "pir/events/CatalogEvent.hpp"
  34. #include "pir/events/MessageEvent.hpp"
  35. #include "pir/PIRParametersExchangeMethods.hpp"
  36. #include "pir/GlobalConstant.hpp"
  37. typedef boost::signals2::signal<void (MessageEvent&)> messageListener;
  38. typedef boost::signals2::signal<void (CatalogEvent&)> menuListener;
  39. typedef boost::signals2::signal<void (WriteEvent&)> writeListener;
  40. struct ClientParams
  41. {
  42. // Networking parameters
  43. string server_ip;
  44. int port;
  45. // Interface params
  46. bool autochoice;
  47. bool verboseoptim;
  48. bool dontwrite;
  49. // Dry-run mode
  50. bool dryrunmode;
  51. };
  52. class PIRClientSimple
  53. {
  54. private:
  55. PIRReplyExtraction_internal *replyExt;
  56. ClientParams clientParams;
  57. FixedVars fixedVars;
  58. OptimVars optimum;
  59. HomomorphicCrypto* cryptoMethod;
  60. messageListener messageListeners;
  61. menuListener menuListeners;
  62. writeListener writeListeners;
  63. boost::asio::ip::tcp::socket socket_up;
  64. PIRReplyWriter replyWriter;
  65. PIRParameters pirParams;
  66. DESC catalog;
  67. short exchange_method;
  68. void uploadWorker(PIRQueryGenerator_internal& queryGen);
  69. void downloadWorker(PIRReplyExtraction_internal& replyExt);
  70. void sendPirParams();
  71. void rcvPirParams();
  72. void exitWithErrorMessage(string s1, string s2);
  73. void writeErrorMessage(string funcName, string message);
  74. void writeWarningMessage(string funcName, string message);
  75. bool no_pipeline_mode;
  76. uint64_t chosenElement;
  77. public:
  78. PIRClientSimple( boost::asio::io_service& ios, ClientParams params, FixedVars vars);
  79. ~PIRClientSimple();
  80. void connect();
  81. void chooseFile();
  82. void rcvPIRParamsExchangeMethod();
  83. void processPIRParams();
  84. void downloadCatalog();
  85. void optimize();
  86. void sendCryptoParams(bool paramsandkey);
  87. void rcvCryptoParams();
  88. void processCryptoParams();
  89. void startProcessQuery();
  90. void startProcessResult();
  91. void setChosenElement(uint64_t choice);
  92. void joinAllThreads();
  93. void no_pipeline(bool b);
  94. /*Add Observers*/
  95. boost::signals2::connection addMessageListener(messageListener::slot_function_type subscriber);
  96. boost::signals2::connection addMenuListener(menuListener::slot_function_type subscriber);
  97. boost::signals2::connection addWriteListener(writeListener::slot_function_type subscriber);
  98. };
  99. #endif