| 6 | #ifndef TGVOIP_MOCK_REFLECTOR |
| 7 | #define TGVOIP_MOCK_REFLECTOR |
| 8 |
| 9 | #include <net/if.h> |
| 10 | #include <netdb.h> |
| 11 | #include <netinet/tcp.h> |
| 12 | #include <pthread.h> |
| 13 | #include <sys/ioctl.h> |
| 14 | #include <sys/socket.h> |
| 15 | #include <unistd.h> |
| 16 |
| 17 | #include <array> |
| 18 | #include <cstdint> |
| 19 | #include <string> |
| 20 | #include <unordered_map> |
| 21 |
| 22 | namespace tgvoip |
| 23 | { |
| 24 |
| 25 | namespace test |
| 26 | { |
| 27 |
| 28 | class MockReflector |
| 29 | { |
| 30 | public: |
| 31 | MockReflector(const std::string& bindAddress, std::uint16_t bindPort); |
| 32 | ~MockReflector(); |
| 33 | void Start(); |
| 34 | void Stop(); |
| 35 | void SetDropAllPackets(bool drop); |
| 36 | static std::array<std::array<std::uint8_t, 16>, 2> GeneratePeerTags(); |
| 37 |
| 38 | private: |
| 39 | struct ClientPair |
| 40 | { |
| 41 | ClientPair(); |
| 42 | sockaddr_in addr0; |
| 43 | sockaddr_in addr1; |
| 44 | }; |
| 45 |
| 46 | std::unordered_map<std::uint64_t, ClientPair> m_clients; // clients are identified by the first half of their peer_tag |
| 47 | pthread_t m_thread; |
| 48 | int m_sfd; |
| 49 |
| 50 | bool m_running = false; |
| 51 | bool m_dropAllPackets = false; |
| 52 |
| 53 | void RunThread(); |
| 54 | }; |
| 55 |
| 56 | } // namespace test |
| 57 |
| 58 | } // namespace tgvoip |
| 59 |
| 60 | #endif // TGVOIP_MOCK_REFLECTOR |
| 61 |