| #include "NetworkSocket.h" |
| 6 |
| 7 | #include <cstdint> |
| 8 | #include <memory> |
| 9 | #include <map> |
| 10 |
| 11 | namespace tgvoip |
| 12 | { |
| 13 |
| 14 | // API compatibility |
| 15 | struct IPv4Address |
| 16 | { |
| 17 | IPv4Address(std::string addr); |
| 18 | std::string addr; |
| 19 | }; |
| 20 | struct IPv6Address |
| 21 | { |
| 22 | IPv6Address(std::string addr); |
| 23 | std::string addr; |
| 24 | }; |
| 25 |
| 26 | class Endpoint |
| 27 | { |
| 28 | friend class VoIPController; |
| 29 | friend class VoIPGroupController; |
| 30 |
| 31 | public: |
| 32 | enum class Type |
| 33 | { |
| 34 | UDP_P2P_INET = 1, |
| 35 | UDP_P2P_LAN, |
| 36 | UDP_RELAY, |
| 37 | TCP_RELAY, |
| 38 | }; |
| 39 |
| 40 | Endpoint(std::int64_t id, std::uint16_t port, const IPv4Address& address, |
| 41 | const IPv6Address& v6address, Type type, const std::uint8_t peerTag[16]); |
| 42 | Endpoint(std::int64_t id, std::uint16_t port, const NetworkAddress& address, |
| 43 | const NetworkAddress& v6address, Type type, const std::uint8_t peerTag[16]); |
| 44 | Endpoint(); |
| 45 | ~Endpoint(); |
| 46 | [[nodiscard]] const NetworkAddress& GetAddress() const; |
| 47 | [[nodiscard]] NetworkAddress& GetAddress(); |
| 48 | [[nodiscard]] bool IsIPv6Only() const; |
| 49 | [[nodiscard]] std::int64_t CleanID() const; |
| 50 |
| 51 | std::int64_t id; |
| 52 | NetworkAddress address; |
| 53 | NetworkAddress v6address; |
| 54 | Type type; |
| 55 | std::uint16_t port; |
| 56 | std::uint8_t peerTag[16]; |
| 57 |
| 58 | private: |
| 59 | HistoricBuffer<double, 6> m_rtts; |
| 60 | HistoricBuffer<double, 4> m_selfRtts; |
| 61 | std::map<std::int64_t, double> m_udpPingTimes; |
| 62 | std::shared_ptr<NetworkSocket> m_socket = nullptr; |
| 63 |
| 64 | double m_averageRTT = 0; |
| 65 | double m_lastPingTime = 0; |
| 66 |
| 67 | std::uint32_t m_lastPingSeq = 0; |
| 68 | int m_udpPongCount = 0; |
| 69 | int m_totalUdpPings = 0; |
| 70 | int m_totalUdpPingReplies = 0; |
| 71 | }; |
| 72 |
| 73 | } // namespace tgvoip |
| 74 |
| 75 | #endif // ENDPOINT_H |
| 76 |