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