/** * @file include/server/UDPConnection.h * @brief The UDP connection class * @copyright 2015 Dual Inventive Technology Centre B.V. * * UDP Connection contains information about the UDP connection */ #ifndef INCLUDE_SERVER_UDPCONNECTION_H_ #define INCLUDE_SERVER_UDPCONNECTION_H_ #include #include #include #include #include #include class UDPConnection { public: /** * constructor for UDP connection * @param address The socket address * @param ip The UDP IP address * @param port The UDP port */ UDPConnection(const std::shared_ptr &address, const std::string &ip, uint16_t port); /** * returns an unique key for this connection that can be used in a std::map * @param ip The IP of the connection * @param port The port of the connection * @return the unique key as format : */ static std::string getUniqueKey(const std::string &ip, uint16_t port); /** * Returns the socket address * @return The sockaddr_in UDP address */ std::shared_ptr getAddress(); /** * Returns the connection information in the format: * `":"` * @return the connection information in format `":"` */ std::string getPeer(); /** * Returns the IP of this connection * @return the IP of this connection */ std::string getIP(); /** * Returns the port of this connection * @return the port of this connection */ uint16_t getPort(); /** * DI-Net timestamp when the last incoming data was seen. */ uint64_t lastReadTime(void); /** * Update the internal readTime. Call this every time a new message is received. */ void updateReadTime(void); /** * Adds a new Device UID to this connection * @param deviceUid The device UID to add */ void addDeviceUid(const std::string &deviceUid); /** * Returns all the known device UIDs on this connection * @return A set with all the known device UIDs on this connection */ std::set getDeviceUids(void); private: std::shared_ptr __address; /**< peer address*/ std::string __peerIp; /**< peer IP address*/ uint16_t __peerPort; /**< peer port number*/ std::atomic __lastReadTime; /**< time of the last read*/ std::set __deviceUids; /**< device unique Identifiers */ mutable std::shared_timed_mutex __deviceUidsMu; /**< device unique Identifiers */ }; #endif // INCLUDE_SERVER_UDPCONNECTION_H_