summaryrefslogtreecommitdiff
path: root/node/SelfAwareness.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-04 18:34:30 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-04 18:34:30 -0700
commitb4b067bf12489a0b3e701515959f81ca96a29240 (patch)
tree09896a57fc2edba22d9da2851d272cab56809c08 /node/SelfAwareness.hpp
parent625ddf41a75e73e3613453e1166de19a756d7e7f (diff)
downloadinfinitytier-b4b067bf12489a0b3e701515959f81ca96a29240.tar.gz
infinitytier-b4b067bf12489a0b3e701515959f81ca96a29240.zip
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.
Diffstat (limited to 'node/SelfAwareness.hpp')
-rw-r--r--node/SelfAwareness.hpp36
1 files changed, 33 insertions, 3 deletions
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 <map>
+
#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