diff --git a/Common/CacheManager.cpp b/Common/CacheManager.cpp index 7915d1b..713624c 100644 --- a/Common/CacheManager.cpp +++ b/Common/CacheManager.cpp @@ -91,6 +91,11 @@ CRepeaterData* CCacheManager::findRepeater(const wxString& repeater) } void CCacheManager::updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, const wxString& timestamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) +{ + updateUser(user, repeater, gateway, address, G2_DV_PORT, true, timestamp, protocol, addrLock, protoLock); +} + +void CCacheManager::updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, const wxString& timestamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { wxMutexLocker locker(m_mutex); @@ -103,10 +108,15 @@ void CCacheManager::updateUser(const wxString& user, const wxString& repeater, c if (!repeater7.IsSameAs(gateway7)) m_repeaterCache.update(repeater, gateway); - m_gatewayCache.update(gateway, address, protocol, addrLock, protoLock); + updateGateway(gateway, address, g2Port, ignoreG2Port, protocol, addrLock, protoLock); } void CCacheManager::updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) +{ + updateRepeater(repeater, gateway, address, G2_DV_PORT, true, protocol, addrLock, protoLock); +} + +void CCacheManager::updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { wxMutexLocker locker(m_mutex); @@ -117,12 +127,24 @@ void CCacheManager::updateRepeater(const wxString& repeater, const wxString& gat if (!repeater7.IsSameAs(gateway7)) m_repeaterCache.update(repeater, gateway); - m_gatewayCache.update(gateway, address, protocol, addrLock, protoLock); + updateGateway(gateway, address, g2Port, ignoreG2Port, protocol, addrLock, protoLock); } void CCacheManager::updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) +{ + updateGateway(gateway, address, G2_DV_PORT, true, protocol, addrLock, protoLock); +} + +void CCacheManager::updateGateway(const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { wxMutexLocker locker(m_mutex); - m_gatewayCache.update(gateway, address, protocol, addrLock, protoLock); + m_gatewayCache.update(gateway, address, g2Port, ignoreG2Port, protocol, addrLock, protoLock); +} + +void CCacheManager::updateGatewayG2(const wxString& gateway, const wxString& address, unsigned int g2Port) +{ + CGatewayRecord* gr = m_gatewayCache.find(gateway); + DSTAR_PROTOCOL protocol = gr != NULL? gr->getProtocol() : DP_UNKNOWN; + updateGateway(gateway, address, g2Port, false, protocol, false, false); } diff --git a/Common/CacheManager.h b/Common/CacheManager.h index e8d669b..80d29b1 100644 --- a/Common/CacheManager.h +++ b/Common/CacheManager.h @@ -146,9 +146,14 @@ public: void updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, const wxString& timeStamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); void updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); - void updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); + void updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol,bool addrLock, bool protoLock); + void updateGatewayG2(const wxString& gateway, const wxString& address, unsigned int g2Port); private: + void updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, const wxString& timeStamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); + void updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); + void updateGateway(const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol,bool addrLock, bool protoLock); + wxMutex m_mutex; CUserCache m_userCache; CGatewayCache m_gatewayCache; diff --git a/Common/GatewayCache.cpp b/Common/GatewayCache.cpp index b029d7c..17ffc5b 100644 --- a/Common/GatewayCache.cpp +++ b/Common/GatewayCache.cpp @@ -36,7 +36,7 @@ CGatewayRecord* CGatewayCache::find(const wxString& gateway) return m_cache[gateway]; } -void CGatewayCache::update(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) +void CGatewayCache::update(const wxString& gateway, const wxString& address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { CGatewayRecord* rec = m_cache[gateway]; @@ -45,10 +45,10 @@ void CGatewayCache::update(const wxString& gateway, const wxString& address, DST if (rec == NULL) // A brand new record is needed - m_cache[gateway] = new CGatewayRecord(gateway, addr_in, protocol, addrLock, protoLock); + m_cache[gateway] = new CGatewayRecord(gateway, addr_in, g2Port, protocol, addrLock, protoLock); else // Update an existing record - rec->setData(addr_in, protocol, addrLock, protoLock); + rec->setData(addr_in, g2Port, ignoreG2Port, protocol, addrLock, protoLock); } unsigned int CGatewayCache::getCount() const diff --git a/Common/GatewayCache.h b/Common/GatewayCache.h index fe79cd6..4140d24 100644 --- a/Common/GatewayCache.h +++ b/Common/GatewayCache.h @@ -35,9 +35,10 @@ class CGatewayRecord { public: - CGatewayRecord(const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) : + CGatewayRecord(const wxString& gateway, in_addr address, unsigned int g2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) : m_gateway(gateway), m_address(address), + m_g2Port(g2Port), m_protocol(DP_UNKNOWN), m_addrLock(addrLock), m_protoLock(false) @@ -63,8 +64,16 @@ public: return m_protocol; } - void setData(in_addr address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) + unsigned int g2Port() const { + return m_g2Port; + } + + void setData(in_addr address, unsigned int g2Port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) + { + if(!ignoreG2Port) + m_g2Port = g2Port; + if (!m_addrLock) { m_address = address; m_addrLock = addrLock; @@ -80,10 +89,9 @@ public: private: wxString m_gateway; - in_addr m_address; - + in_addr m_address; //the incoming G2 port, usually the default one unless the calling hotspot is behind a NAT, therefore keep track of it and use it to answer back instead of the default one - unsigned int m_G2Port; + unsigned int m_g2Port; DSTAR_PROTOCOL m_protocol; bool m_addrLock; bool m_protoLock; @@ -98,7 +106,7 @@ public: CGatewayRecord* find(const wxString& gateway); - void update(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); + void update(const wxString& gateway, const wxString& address, unsigned int g2port, bool ignoreG2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); unsigned int getCount() const;