channel.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. \file channel.h
  3. \author michael.zohner@ec-spride.de
  4. \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
  5. Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. ABY is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef CHANNEL_H_
  18. #define CHANNEL_H_
  19. #include <cstdint>
  20. #include <memory>
  21. #include <mutex>
  22. #include <queue>
  23. class RcvThread;
  24. class SndThread;
  25. struct rcv_ctx;
  26. class CEvent;
  27. class CLock;
  28. class channel {
  29. public:
  30. channel(uint8_t channelid, RcvThread* rcver, SndThread* snder);
  31. ~channel();
  32. void send(uint8_t* buf, uint64_t nbytes);
  33. void blocking_send(CEvent* eventcaller, uint8_t* buf, uint64_t nbytes);
  34. void send_id_len(uint8_t* buf, uint64_t nbytes, uint64_t id, uint64_t len);
  35. void blocking_send_id_len(CEvent* eventcaller, uint8_t* buf, uint64_t nbytes, uint64_t id, uint64_t len);
  36. //buf needs to be freed, data contains the payload
  37. uint8_t* blocking_receive_id_len(uint8_t** data, uint64_t* id, uint64_t* len);
  38. bool queue_empty() const;
  39. uint8_t* blocking_receive();
  40. void blocking_receive(uint8_t* rcvbuf, uint64_t rcvsize);
  41. bool is_alive();
  42. bool data_available();
  43. void signal_end();
  44. void wait_for_fin();
  45. void synchronize_end();
  46. private:
  47. uint8_t m_bChannelID;
  48. RcvThread* m_cRcver;
  49. SndThread* m_cSnder;
  50. std::unique_ptr<CEvent> m_eRcved;
  51. std::unique_ptr<CEvent> m_eFin;
  52. bool m_bSndAlive;
  53. bool m_bRcvAlive;
  54. std::queue<rcv_ctx*>* m_qRcvedBlocks;
  55. std::mutex& m_qRcvedBlocks_mutex_;
  56. };
  57. #endif /* CHANNEL_H_ */