PIRClient.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // Batch-query
  52. int batchSize;
  53. };
  54. class PIRClientSimple
  55. {
  56. private:
  57. PIRReplyExtraction_internal *replyExt;
  58. ClientParams clientParams;
  59. FixedVars fixedVars;
  60. OptimVars optimum;
  61. HomomorphicCrypto* cryptoMethod;
  62. messageListener messageListeners;
  63. menuListener menuListeners;
  64. writeListener writeListeners;
  65. boost::asio::ip::tcp::socket socket_up;
  66. PIRReplyWriter replyWriter;
  67. PIRParameters pirParams;
  68. DESC catalog;
  69. short exchange_method;
  70. void uploadWorker(PIRQueryGenerator_internal& queryGen);
  71. void downloadWorker(PIRReplyExtraction_internal& replyExt);
  72. void sendPirParams();
  73. void rcvPirParams();
  74. void exitWithErrorMessage(string s1, string s2);
  75. void writeErrorMessage(string funcName, string message);
  76. void writeWarningMessage(string funcName, string message);
  77. bool no_pipeline_mode;
  78. uint64_t chosenElement;
  79. public:
  80. PIRClientSimple( boost::asio::io_service& ios, ClientParams params, FixedVars vars);
  81. ~PIRClientSimple();
  82. void connect();
  83. void chooseFile();
  84. void rcvPIRParamsExchangeMethod();
  85. void processPIRParams();
  86. void downloadCatalog();
  87. void optimize();
  88. void sendCryptoParams(bool paramsandkey);
  89. void rcvCryptoParams();
  90. void processCryptoParams();
  91. void startProcessQuery();
  92. void startProcessResult();
  93. void setChosenElement(uint64_t choice);
  94. void joinAllThreads();
  95. void no_pipeline(bool b);
  96. clock_t gq_start, gq_stop, er_start, er_stop, tclock;
  97. /*Add Observers*/
  98. boost::signals2::connection addMessageListener(messageListener::slot_function_type subscriber);
  99. boost::signals2::connection addMenuListener(menuListener::slot_function_type subscriber);
  100. boost::signals2::connection addWriteListener(writeListener::slot_function_type subscriber);
  101. };
  102. #endif