ShannonConnection.h 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef SHANNONCONNECTION_H
  2. #define SHANNONCONNECTION_H
  3. #include <sys/types.h>
  4. #include <cstdint>
  5. #include <memory>
  6. #include <string>
  7. #include <vector>
  8. #include "Packet.h"
  9. #include "PlainConnection.h"
  10. #include "Shannon.h"
  11. #include <mutex>
  12. #include "Utils.h"
  13. #include "Logger.h"
  14. #define MAC_SIZE 4
  15. namespace cspot {
  16. class ShannonConnection {
  17. private:
  18. std::unique_ptr<Shannon> sendCipher;
  19. std::unique_ptr<Shannon> recvCipher;
  20. uint32_t sendNonce = 0;
  21. uint32_t recvNonce = 0;
  22. std::vector<uint8_t> cipherPacket(uint8_t cmd, std::vector<uint8_t>& data);
  23. std::mutex writeMutex;
  24. std::mutex readMutex;
  25. public:
  26. ShannonConnection();
  27. ~ShannonConnection();
  28. void wrapConnection(std::shared_ptr<PlainConnection> conn,
  29. std::vector<uint8_t>& sendKey,
  30. std::vector<uint8_t>& recvKey);
  31. void sendPacket(uint8_t cmd, std::vector<uint8_t>& data);
  32. std::shared_ptr<PlainConnection> conn;
  33. Packet recvPacket();
  34. };
  35. } // namespace cspot
  36. #endif