summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-08-14 18:06:18 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-08-14 18:06:18 -0400
commitbe6b61b1bc7e207144faf99a2aeda874ff3a0055 (patch)
treee8e7c5d6276ce3ed41e85cf3b0de9cbe53dc2f3e /node
parentf8d4611d15b18bf505de9ca82d74f5102fc57024 (diff)
downloadinfinitytier-be6b61b1bc7e207144faf99a2aeda874ff3a0055.tar.gz
infinitytier-be6b61b1bc7e207144faf99a2aeda874ff3a0055.zip
Accept supernode dictionaries in Topology, also fix (unused) field name in one of these.
Diffstat (limited to 'node')
-rw-r--r--node/Topology.cpp22
-rw-r--r--node/Topology.hpp11
2 files changed, 33 insertions, 0 deletions
diff --git a/node/Topology.cpp b/node/Topology.cpp
index d74179fe..4fae1372 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::pair<Ine
_amSupernode = (_supernodes.find(_r->identity) != _supernodes.end());
}
+void Topology::setSupernodes(const Dictionary &sn)
+{
+ std::map< Identity,std::vector< std::pair<InetAddress,bool> > > 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<InetAddress,bool> > &a = m[Identity(snspec.get("id"))];
+ std::string udp(snspec.get("udp",std::string()));
+ if (udp.length() > 0)
+ a.push_back(std::pair<InetAddress,bool>(InetAddress(udp),false));
+ std::string tcp(snspec.get("tcp",std::string()));
+ a.push_back(std::pair<InetAddress,bool>(InetAddress(tcp),true));
+ } catch ( ... ) {
+ LOG("supernode list contained invalid entry for: %s",d->first.c_str());
+ }
+ }
+ }
+ this->setSupernodes(m);
+}
+
SharedPtr<Peer> Topology::addPeer(const SharedPtr<Peer> &peer)
{
if (peer->address() == _r->identity.address()) {
diff --git a/node/Topology.hpp b/node/Topology.hpp
index 0585ad1f..37511208 100644
--- a/node/Topology.hpp
+++ b/node/Topology.hpp
@@ -48,6 +48,7 @@
namespace ZeroTier {
class RuntimeEnvironment;
+class Dictionary;
/**
* Database of network topology
@@ -66,6 +67,16 @@ public:
void setSupernodes(const std::map< Identity,std::vector< std::pair<InetAddress,bool> > > &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
*
* This will not replace existing peers. In that case the existing peer