From 529515d1d173e6850c86230106cbfc36e1b9bf97 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 6 May 2016 13:29:10 -0700 Subject: Changes to how new-style binary network configs are detected, and a new-style binary serialized meta-data representation. --- node/NetworkConfig.hpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'node/NetworkConfig.hpp') diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 15778aed..a03c1faf 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -25,6 +25,7 @@ #include #include +#include #include "../include/ZeroTierOne.h" @@ -40,13 +41,6 @@ #include #endif -/** - * First byte of V2 binary-serialized network configs - * - * This will never begin a Dictionary, so it serves to distinguish. - */ -#define ZT_NETWORKCONFIG_V2_MARKER_BYTE 0x00 - /** * Flag: allow passive bridging (experimental) */ @@ -68,9 +62,9 @@ #define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE 0x0000020000000000ULL /** - * This device is allowed to send packets from any Ethernet MAC, including ZeroTier-reserved ones + * An anchor is a device that is willing to be one and has been online/stable for a long time on this network */ -#define ZT_NETWORKCONFIG_SPECIALIST_TYPE_IMPOSTOR 0x0000040000000000ULL +#define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR 0x0000040000000000ULL namespace ZeroTier { @@ -302,6 +296,19 @@ public: return r; } + /** + * @return ZeroTier addresses of "anchor" devices on this network + */ + inline std::vector
anchors() const + { + std::vector
r; + for(unsigned int i=0;i<_specialistCount;++i) { + if ((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0) + r.push_back(Address(_specialists[i])); + } + return r; + } + /** * Look up a static physical address for a given ZeroTier address * @@ -321,6 +328,8 @@ public: } /** + * This gets network preferred relays with their static physical address if one is defined + * * @return Network-preferred relays for this network (if none, only roots will be used) */ inline std::vector relays() const @@ -393,9 +402,7 @@ public: template inline void serialize(Buffer &b) const { - b.append((uint8_t)ZT_NETWORKCONFIG_V2_MARKER_BYTE); - - b.append((uint16_t)0); // version + b.append((uint16_t)1); // version b.append((uint64_t)_nwid); b.append((uint64_t)_timestamp); @@ -517,9 +524,7 @@ public: unsigned int p = startAt; - if (b[p++] != ZT_NETWORKCONFIG_V2_MARKER_BYTE) - throw std::invalid_argument("unrecognized format"); - if (b.template at(p) != 0) + if (b.template at(p) != 1) throw std::invalid_argument("unrecognized version"); p += 2; @@ -532,9 +537,8 @@ public: _type = (ZT_VirtualNetworkType)b[p++]; unsigned int nl = (unsigned int)b[p++]; - if (nl > ZT_MAX_NETWORK_SHORT_NAME_LENGTH) - nl = ZT_MAX_NETWORK_SHORT_NAME_LENGTH; - memcpy(_name,b.field(p,nl),nl); + memcpy(_name,b.field(p,nl),std::max(nl,(unsigned int)ZT_MAX_NETWORK_SHORT_NAME_LENGTH)); + p += nl; // _name will always be null terminated since field size is ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1 _specialistCount = (unsigned int)b.template at(p); p += 2; -- cgit v1.2.3