2
0

ShannonConnection.h 1.1 KB

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