ShannonConnection.h 1020 B

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