diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-21 14:12:00 -0400 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-21 14:12:00 -0400 |
| commit | 5e71e07f5940056f1fb5124dcdfeb71a313b9854 (patch) | |
| tree | 9febb5fb17066bde3107e7aeeadddf47624c4386 /node/Topology.cpp | |
| parent | 40e4f39181519a7eade4954f9ecb92b84ffb4866 (diff) | |
| download | infinitytier-5e71e07f5940056f1fb5124dcdfeb71a313b9854.tar.gz infinitytier-5e71e07f5940056f1fb5124dcdfeb71a313b9854.zip | |
Add persistent identity caching for use on supernodes. Activate by just making an iddb.d directory in the ZeroTier home folder. Also clean up some obsolete cruft from makefiles.
Diffstat (limited to 'node/Topology.cpp')
| -rw-r--r-- | node/Topology.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/node/Topology.cpp b/node/Topology.cpp index 18432f25..6efde33e 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -35,10 +35,12 @@ namespace ZeroTier { -Topology::Topology(const RuntimeEnvironment *renv) : +Topology::Topology(const RuntimeEnvironment *renv,bool enablePermanentIdCaching) : _r(renv), _amSupernode(false) { + if (enablePermanentIdCaching) + _idCacheBase = (_r->homePath + ZT_PATH_SEPARATOR_S + "iddb.d"); _loadPeers(); } @@ -83,6 +85,7 @@ SharedPtr<Peer> Topology::addPeer(const SharedPtr<Peer> &peer) Mutex::Lock _l(_activePeers_m); SharedPtr<Peer> p(_activePeers.insert(std::pair< Address,SharedPtr<Peer> >(peer->address(),peer)).first->second); p->setLastUsed(now); + saveIdentity(p->identity()); return p; } @@ -102,6 +105,32 @@ SharedPtr<Peer> Topology::getPeer(const Address &zta) return SharedPtr<Peer>(); } +Identity Topology::getIdentity(const Address &zta) +{ + SharedPtr<Peer> p(getPeer(zta)); + if (p) + return p->identity(); + if (_idCacheBase.length()) { + std::string idcPath(_idCacheBase + ZT_PATH_SEPARATOR_S + zta.toString()); + std::string ids; + if (Utils::readFile(idcPath.c_str(),ids)) { + try { + return Identity(ids); + } catch ( ... ) {} // ignore invalid IDs + } + } + return Identity(); +} + +void Topology::saveIdentity(const Identity &id) +{ + if ((id)&&(_idCacheBase.length())) { + std::string idcPath(_idCacheBase + ZT_PATH_SEPARATOR_S + id.address().toString()); + if (!Utils::fileExists(idcPath.c_str())) + Utils::writeFile(idcPath.c_str(),id.toString(false)); + } +} + SharedPtr<Peer> Topology::getBestSupernode(const Address *avoid,unsigned int avoidCount,bool strictAvoid) const { SharedPtr<Peer> bestSupernode; @@ -244,6 +273,7 @@ void Topology::_loadPeers() SharedPtr<Peer> p(new Peer()); ptr += p->deserialize(buf,ptr); _activePeers[p->address()] = p; + saveIdentity(p->identity()); } if (ptr) { memmove(buf.data(),buf.data() + ptr,buf.size() - ptr); |
