From be6b61b1bc7e207144faf99a2aeda874ff3a0055 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 14 Aug 2014 18:06:18 -0400 Subject: [PATCH] Accept supernode dictionaries in Topology, also fix (unused) field name in one of these. --- node/Topology.cpp | 22 ++++++++++++++++++++++ node/Topology.hpp | 11 +++++++++++ root-topology/supernodes/9d219039f3 | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/node/Topology.cpp b/node/Topology.cpp index d74179fec..4fae1372e 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -30,6 +30,7 @@ #include "Topology.hpp" #include "NodeConfig.hpp" #include "CMWC4096.hpp" +#include "Dictionary.hpp" #define ZT_PEER_WRITE_BUF_SIZE 131072 @@ -75,6 +76,27 @@ void Topology::setSupernodes(const std::map< Identity,std::vector< std::pairidentity) != _supernodes.end()); } +void Topology::setSupernodes(const Dictionary &sn) +{ + std::map< Identity,std::vector< std::pair > > m; + for(Dictionary::const_iterator d(sn.begin());d!=sn.end();++d) { + if ((d->first.length() == ZT_ADDRESS_LENGTH_HEX)&&(d->second.length() > 0)) { + try { + Dictionary snspec(d->second); + std::vector< std::pair > &a = m[Identity(snspec.get("id"))]; + std::string udp(snspec.get("udp",std::string())); + if (udp.length() > 0) + a.push_back(std::pair(InetAddress(udp),false)); + std::string tcp(snspec.get("tcp",std::string())); + a.push_back(std::pair(InetAddress(tcp),true)); + } catch ( ... ) { + LOG("supernode list contained invalid entry for: %s",d->first.c_str()); + } + } + } + this->setSupernodes(m); +} + SharedPtr Topology::addPeer(const SharedPtr &peer) { if (peer->address() == _r->identity.address()) { diff --git a/node/Topology.hpp b/node/Topology.hpp index 0585ad1fa..375112084 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -48,6 +48,7 @@ namespace ZeroTier { class RuntimeEnvironment; +class Dictionary; /** * Database of network topology @@ -65,6 +66,16 @@ public: */ void setSupernodes(const std::map< Identity,std::vector< std::pair > > &sn); + /** + * Set up supernodes for this network + * + * This performs no signature verification of any kind. The caller must + * check the signature of the root topology dictionary first. + * + * @param sn Supernodes dictionary from root-topology + */ + void setSupernodes(const Dictionary &sn); + /** * Add a peer to database * diff --git a/root-topology/supernodes/9d219039f3 b/root-topology/supernodes/9d219039f3 index 5b21cf629..1602f35e4 100644 --- a/root-topology/supernodes/9d219039f3 +++ b/root-topology/supernodes/9d219039f3 @@ -2,4 +2,4 @@ id=9d219039f3:0:01f0922a98e3b34ebcbff333269dc265d7a020aab69d72be4d4acc9c8c929478 udp=128.199.197.217/9993 tcp=128.199.197.217/443 desc=Singapore -hn=mi-go.zerotier.com +dns=mi-go.zerotier.com