From b4b067bf12489a0b3e701515959f81ca96a29240 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 4 May 2015 18:34:30 -0700 Subject: So we need to keep track of external surface per reporter, since some NATs assign different external IPs for each external destination. Keeping just one known surface could create a race condition. --- node/SelfAwareness.hpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'node/SelfAwareness.hpp') diff --git a/node/SelfAwareness.hpp b/node/SelfAwareness.hpp index 2eb9b59f..4780fa5b 100644 --- a/node/SelfAwareness.hpp +++ b/node/SelfAwareness.hpp @@ -28,6 +28,8 @@ #ifndef ZT_SELFAWARENESS_HPP #define ZT_SELFAWARENESS_HPP +#include + #include "InetAddress.hpp" #include "Address.hpp" #include "Mutex.hpp" @@ -52,13 +54,41 @@ public: * @param reporterPhysicalAddress Physical address that reporting peer seems to have * @param myPhysicalAddress Physical address that peer says we have * @param trusted True if this peer is trusted as an authority to inform us of external address changes + * @param now Current time + */ + void iam(const Address &reporter,const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,bool trusted,uint64_t now); + + /** + * Clean up database periodically + * + * @param now Current time */ - void iam(const Address &reporter,const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,bool trusted); + void clean(uint64_t now); private: + struct PhySurfaceKey + { + Address reporter; + InetAddress::IpScope scope; + + PhySurfaceKey() : reporter(),scope(InetAddress::IP_SCOPE_NONE) {} + PhySurfaceKey(const Address &r,InetAddress::IpScope s) : reporter(r),scope(s) {} + inline bool operator<(const PhySurfaceKey &k) const throw() { return ((reporter < k.reporter) ? true : ((reporter == k.reporter) ? ((int)scope < (int)k.scope) : false)); } + inline bool operator==(const PhySurfaceKey &k) const throw() { return ((reporter == k.reporter)&&(scope == k.scope)); } + }; + struct PhySurfaceEntry + { + InetAddress mySurface; + uint64_t ts; + + PhySurfaceEntry() : mySurface(),ts(0) {} + PhySurfaceEntry(const InetAddress &a,const uint64_t t) : mySurface(a),ts(t) {} + }; + const RuntimeEnvironment *RR; - Mutex _lock; - InetAddress _lastPhysicalAddress[5]; // 5 == the number of address classes we care about, see InetAddress.hpp and SelfAwareness.cpp + + std::map< PhySurfaceKey,PhySurfaceEntry > _phy; + Mutex _phy_m; }; } // namespace ZeroTier -- cgit v1.2.3